Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFValue.cpp
Go to the documentation of this file.
1//===- SVFValue.cpp -- Basic types used in SVF-------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * SVFValue.cpp
25 *
26 * Created on: Apr 1, 2014
27 * Author: Yulei Sui
28 * Refactored on: Feb 10, 2025
29 * Author: Xiao Cheng, Yulei Sui
30 */
31
32#include "SVFIR/SVFValue.h"
33#include "Util/SVFUtil.h"
34#include "Graphs/BasicBlockG.h"
35#include "Graphs/GenericGraph.h"
37
38
39using namespace SVF;
40using namespace SVFUtil;
41
42
44const std::string SVFValue::valueOnlyToString() const
45{
46 assert("SVFBaseNode::valueOnlyToString should be implemented or supported by fronted" && false);
47 abort();
48}
49
51const bool SVFValue::hasLLVMValue() const
52{
53 assert("SVFBaseNode::hasLLVMValue should be implemented or supported by fronted" && false);
54 abort();
55}
56
59{
60 fldIdxVec.push_back(fldIdx);
61 elemIdxVec.push_back(elemIdx);
62 fldIdx2TypeMap[fldIdx] = type;
63}
64
68//{@
70{
72 if(it!=fldIdx2TypeMap.end())
73 return it->second;
74 return nullptr;
75}
76
78{
79 assert(hasLoopInfo(bb) && "loopinfo does not exist (bb not in a loop)");
81 return mapIter->second;
82}
83
85{
86 if (hasLoopInfo(bb))
87 {
88 const LoopBBs blocks = getLoopInfo(bb);
89 if (!blocks.empty())
90 {
91 for (const SVFBasicBlock* block : blocks)
92 {
93 for (const SVFBasicBlock* succ : block->getSuccessors())
94 {
95 if ((std::find(blocks.begin(), blocks.end(), succ)==blocks.end()))
96 exitbbs.push_back(succ);
97 }
98 }
99 }
100 }
101}
102
104{
105 if (bbKey == bbValue)
106 return true;
107
108 // An unreachable node is dominated by anything.
110 {
111 return true;
112 }
113
114 // And dominates nothing.
115 if (isUnreachable(bbKey))
116 {
117 return false;
118 }
119
122 if (mapIter != dtBBsMap.end())
123 {
124 const BBSet & dtBBs = mapIter->second;
125 if (dtBBs.find(bbValue) != dtBBs.end())
126 {
127 return true;
128 }
129 }
130
131 return false;
132}
133
135{
136 if (bbKey == bbValue)
137 return true;
138
139 // An unreachable node is dominated by anything.
141 {
142 return true;
143 }
144
145 // And dominates nothing.
146 if (isUnreachable(bbKey))
147 {
148 return false;
149 }
150
153 if (mapIter != dtBBsMap.end())
154 {
155 const BBSet & dtBBs = mapIter->second;
156 if (dtBBs.find(bbValue) != dtBBs.end())
157 {
158 return true;
159 }
160 }
161 return false;
162}
163
165{
166 assert(A && B && "Pointers are not valid");
167 assert(A->getParent() == B->getParent() &&
168 "Two blocks are not in same function");
169
170 // Use level information to go up the tree until the levels match. Then
171 // continue going up til we arrive at the same node.
172 while (A != B)
173 {
174 // no common PDominator
175 if(A == NULL) return NULL;
176 const auto lvA = getBBPDomLevel().find(A);
177 const auto lvB = getBBPDomLevel().find(B);
178 assert(lvA != getBBPDomLevel().end() && lvB != getBBPDomLevel().end());
179
180 if (lvA->second < lvB->second) std::swap(A, B);
181
182 const auto lvAIdom = getBB2PIdom().find(A);
183 assert(lvAIdom != getBB2PIdom().end());
184 A = lvAIdom->second;
185 }
186
187 return A;
188}
189
191{
192 if (hasLoopInfo(bb))
193 {
194 const LoopBBs& blocks = getLoopInfo(bb);
195 assert(!blocks.empty() && "no available loop info?");
196 return blocks.front() == bb;
197 }
198 return false;
199}
unsigned u32_t
Definition CommandLine.h:18
newitem type
Definition cJSON.cpp:2739
const Map< const SVFBasicBlock *, BBSet > & getPostDomTreeMap() const
const LoopBBs & getLoopInfo(const SVFBasicBlock *bb) const
Definition SVFValue.cpp:77
Map< const SVFBasicBlock *, BBSet > & getDomTreeMap()
std::vector< const SVFBasicBlock * > BBList
Map< const SVFBasicBlock *, BBSet > dtBBsMap
map a BasicBlock to BasicBlocks it Dominates
bool dominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition SVFValue.cpp:103
bool isLoopHeader(const SVFBasicBlock *bb) const
Definition SVFValue.cpp:190
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
Definition SVFValue.cpp:84
const SVFBasicBlock * findNearestCommonPDominator(const SVFBasicBlock *A, const SVFBasicBlock *B) const
find nearest common post dominator of two basic blocks
Definition SVFValue.cpp:164
const Map< const SVFBasicBlock *, u32_t > & getBBPDomLevel() const
const Map< const SVFBasicBlock *, const SVFBasicBlock * > & getBB2PIdom() const
bool isUnreachable(const SVFBasicBlock *bb) const
bool hasLoopInfo(const SVFBasicBlock *bb) const
Set< const SVFBasicBlock * > BBSet
Map< const SVFBasicBlock *, LoopBBs > bb2LoopMap
map a BasicBlock (if it is in a loop) to all the BasicBlocks in this loop
bool postDominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition SVFValue.cpp:134
const bool hasLLVMValue() const
Definition LLVMUtil.cpp:760
const std::string valueOnlyToString() const
Definition LLVMUtil.cpp:741
void addFldWithType(u32_t fldIdx, const SVFType *type, u32_t elemIdx)
Add field index and element index and their corresponding type.
const SVFType * getOriginalElemType(u32_t fldIdx) const
Definition SVFValue.cpp:69
std::vector< u32_t > fldIdxVec
flattened field indices of a struct (ignoring arrays)
Definition SVFType.h:77
std::vector< u32_t > elemIdxVec
Definition SVFType.h:80
Map< u32_t, const SVFType * > fldIdx2TypeMap
Types of all fields of a struct.
Definition SVFType.h:82
#define NULL
Definition extapi.c:5
for isBitcode
Definition BasicTypes.h:70
__attribute__((weak)) std
Definition SVFType.cpp:10
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition GeneralType.h:56
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67