Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFValue.cpp
Go to the documentation of this file.
1#include "SVFIR/SVFValue.h"
2#include "Util/SVFUtil.h"
4
5using namespace SVF;
6using namespace SVFUtil;
7
10{
11 fldIdxVec.push_back(fldIdx);
12 elemIdxVec.push_back(elemIdx);
13 fldIdx2TypeMap[fldIdx] = type;
14}
15
19//{@
21{
23 if(it!=fldIdx2TypeMap.end())
24 return it->second;
25 return nullptr;
26}
27
29{
30 assert(hasLoopInfo(bb) && "loopinfo does not exist (bb not in a loop)");
32 return mapIter->second;
33}
34
36{
37 if (hasLoopInfo(bb))
38 {
39 const LoopBBs blocks = getLoopInfo(bb);
40 if (!blocks.empty())
41 {
42 for (const SVFBasicBlock* block : blocks)
43 {
44 for (const SVFBasicBlock* succ : block->getSuccessors())
45 {
46 if ((std::find(blocks.begin(), blocks.end(), succ)==blocks.end()))
47 exitbbs.push_back(succ);
48 }
49 }
50 }
51 }
52}
53
55{
56 if (bbKey == bbValue)
57 return true;
58
59 // An unreachable node is dominated by anything.
61 {
62 return true;
63 }
64
65 // And dominates nothing.
67 {
68 return false;
69 }
70
73 if (mapIter != dtBBsMap.end())
74 {
75 const BBSet & dtBBs = mapIter->second;
76 if (dtBBs.find(bbValue) != dtBBs.end())
77 {
78 return true;
79 }
80 }
81
82 return false;
83}
84
86{
87 if (bbKey == bbValue)
88 return true;
89
90 // An unreachable node is dominated by anything.
92 {
93 return true;
94 }
95
96 // And dominates nothing.
98 {
99 return false;
100 }
101
104 if (mapIter != dtBBsMap.end())
105 {
106 const BBSet & dtBBs = mapIter->second;
107 if (dtBBs.find(bbValue) != dtBBs.end())
108 {
109 return true;
110 }
111 }
112 return false;
113}
114
116{
117 assert(A && B && "Pointers are not valid");
118 assert(A->getParent() == B->getParent() &&
119 "Two blocks are not in same function");
120
121 // Use level information to go up the tree until the levels match. Then
122 // continue going up til we arrive at the same node.
123 while (A != B)
124 {
125 // no common PDominator
126 if(A == NULL) return NULL;
127 const auto lvA = getBBPDomLevel().find(A);
128 const auto lvB = getBBPDomLevel().find(B);
129 assert(lvA != getBBPDomLevel().end() && lvB != getBBPDomLevel().end());
130
131 if (lvA->second < lvB->second) std::swap(A, B);
132
133 const auto lvAIdom = getBB2PIdom().find(A);
134 assert(lvAIdom != getBB2PIdom().end());
135 A = lvAIdom->second;
136 }
137
138 return A;
139}
140
142{
143 if (hasLoopInfo(bb))
144 {
145 const LoopBBs& blocks = getLoopInfo(bb);
146 assert(!blocks.empty() && "no available loop info?");
147 return blocks.front() == bb;
148 }
149 return false;
150}
151
153 bool declare, bool intrinsic, bool adt, bool varg,
155 : SVFValue(ty, SVFValue::SVFFunc), isDecl(declare), intrinsic(intrinsic),
156 addrTaken(adt), isUncalled(false), isNotRet(false), varArg(varg),
157 funcType(ft), loopAndDom(ld), realDefFun(nullptr), exitBlock(nullptr)
158{
159}
160
162{
163 for(const SVFBasicBlock* bb : allBBs)
164 delete bb;
165 for(const SVFArgument* arg : allArgs)
166 delete arg;
167 delete loopAndDom;
168}
169
171{
172 return allArgs.size();
173}
174
176{
177 assert (idx < allArgs.size() && "getArg() out of range!");
178 return allArgs[idx];
179}
180
182{
183 return varArg;
184}
185
187{
188 assert(hasBasicBlock() && "function does not have any Basicblock, external function?");
189 assert(exitBlock && "must have an exitBlock");
190 return exitBlock;
191}
192
194{
195 assert(!exitBlock && "have already set exit Basicblock!");
196 exitBlock = bb;
197}
198
200 : SVFValue(ty, SVFValue::SVFBB), fun(f)
201{
202}
203
208
213{
214 u32_t i = 0;
215 for (const SVFBasicBlock* SuccBB: succBBs)
216 {
217 if (SuccBB == Succ)
218 return i;
219 i++;
220 }
221 assert(false && "Didn't find successor edge?");
222 return 0;
223}
224
226{
227 u32_t i = 0;
228 for (const SVFBasicBlock* SuccBB: succBBs)
229 {
230 if (SuccBB == Succ)
231 return i;
232 i++;
233 }
234 assert(false && "Didn't find successor edge?");
235 return 0;
236}
237
242{
243 u32_t pos = 0;
244 for (const SVFBasicBlock* PredBB : succbb->getPredecessors())
245 {
246 if(PredBB == this)
247 return pos;
248 ++pos;
249 }
250 assert(false && "Didn't find predecessor edge?");
251 return pos;
252}
254{
255 u32_t pos = 0;
256 for (const SVFBasicBlock* PredBB : succbb->getPredecessors())
257 {
258 if(PredBB == this)
259 return pos;
260 ++pos;
261 }
262 assert(false && "Didn't find predecessor edge?");
263 return pos;
264}
265
267 bool tm, bool isRet, SVFValKind k)
268 : SVFValue(ty, k), bb(b), terminator(tm), ret(isRet)
269{
270}
271
273std::string SVFValue::toString() const
274{
275 assert("SVFValue::toString should be implemented or supported by fronted" && false);
276 abort();
277}
278
280const std::string SVFBaseNode::valueOnlyToString() const
281{
282 assert("SVFBaseNode::valueOnlyToString should be implemented or supported by fronted" && false);
283 abort();
284}
newitem type
Definition cJSON.cpp:2739
#define false
Definition cJSON.cpp:70
const cJSON *const b
Definition cJSON.h:255
const std::string valueOnlyToString() const
Definition LLVMUtil.cpp:746
u32_t getBBPredecessorPos(const SVFBasicBlock *succbb)
Definition SVFValue.cpp:241
std::vector< const SVFBasicBlock * > succBBs
all successor BasicBlocks of this BasicBlock
Definition SVFValue.h:544
u32_t getBBSuccessorPos(const SVFBasicBlock *succbb)
Definition SVFValue.cpp:212
~SVFBasicBlock() override
Definition SVFValue.cpp:204
SVFBasicBlock()=delete
const SVFArgument * getArg(u32_t idx) const
Definition SVFValue.cpp:175
bool varArg
return true if this function never returns
Definition SVFValue.h:316
SVFBasicBlock * exitBlock
all formal arguments of this function
Definition SVFValue.h:322
virtual ~SVFFunction()
Definition SVFValue.cpp:161
std::vector< const SVFArgument * > allArgs
all BasicBlocks of this function
Definition SVFValue.h:321
SVFFunction(void)=delete
bool hasBasicBlock() const
Definition SVFValue.h:415
std::vector< const SVFBasicBlock * > allBBs
the definition of a function across multiple modules
Definition SVFValue.h:320
u32_t arg_size() const
Definition SVFValue.cpp:170
void setExitBlock(SVFBasicBlock *bb)
Definition SVFValue.cpp:193
const SVFBasicBlock * getExitBB() const
Definition SVFValue.cpp:186
bool isVarArg() const
Definition SVFValue.cpp:181
SVFLoopAndDomInfo * loopAndDom
FunctionType, which is different from the type (PointerType) of this SVFFunction.
Definition SVFValue.h:318
SVFInstruction(void)=delete
const Map< const SVFBasicBlock *, BBSet > & getPostDomTreeMap() const
Definition SVFValue.h:108
const LoopBBs & getLoopInfo(const SVFBasicBlock *bb) const
Definition SVFValue.cpp:28
Map< const SVFBasicBlock *, BBSet > & getDomTreeMap()
Definition SVFValue.h:139
std::vector< const SVFBasicBlock * > BBList
Definition SVFValue.h:56
Map< const SVFBasicBlock *, BBSet > dtBBsMap
map a BasicBlock to BasicBlocks it Dominates
Definition SVFValue.h:61
bool dominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition SVFValue.cpp:54
bool isLoopHeader(const SVFBasicBlock *bb) const
Definition SVFValue.cpp:141
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
Definition SVFValue.cpp:35
const SVFBasicBlock * findNearestCommonPDominator(const SVFBasicBlock *A, const SVFBasicBlock *B) const
find nearest common post dominator of two basic blocks
Definition SVFValue.cpp:115
const Map< const SVFBasicBlock *, u32_t > & getBBPDomLevel() const
Definition SVFValue.h:118
const Map< const SVFBasicBlock *, const SVFBasicBlock * > & getBB2PIdom() const
Definition SVFValue.h:128
bool isUnreachable(const SVFBasicBlock *bb) const
Definition SVFValue.h:149
bool hasLoopInfo(const SVFBasicBlock *bb) const
Definition SVFValue.h:85
Set< const SVFBasicBlock * > BBSet
Definition SVFValue.h:55
Map< const SVFBasicBlock *, LoopBBs > bb2LoopMap
map a BasicBlock (if it is in a loop) to all the BasicBlocks in this loop
Definition SVFValue.h:64
bool postDominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition SVFValue.cpp:85
std::string toString() const
Needs to be implemented by a SVF front end.
Definition LLVMUtil.cpp:721
const SVFType * getOriginalElemType(u32_t fldIdx) const
Definition SVFValue.cpp:20
std::vector< u32_t > fldIdxVec
flattened field indices of a struct (ignoring arrays)
Definition SVFType.h:53
std::vector< u32_t > elemIdxVec
Definition SVFType.h:56
void addFldWithType(u32_t fldIdx, const SVFType *type, u32_t elemIdx)
Add field index and element index and their corresponding type.
Definition SVFValue.cpp:9
Map< u32_t, const SVFType * > fldIdx2TypeMap
Types of all fields of a struct.
Definition SVFType.h:58
#define NULL
Definition extapi.c:2
for isBitcode
Definition BasicTypes.h:68
__attribute__((weak)) std
Definition SVFType.cpp:10
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:46