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/GenericGraph.h"
36
37
38using namespace SVF;
39using namespace SVFUtil;
40
41
43const std::string SVFValue::valueOnlyToString() const
44{
45 assert("SVFBaseNode::valueOnlyToString should be implemented or supported by fronted" && false);
46 abort();
47}
48
50const bool SVFValue::hasLLVMValue() const
51{
52 assert("SVFBaseNode::hasLLVMValue should be implemented or supported by fronted" && false);
53 abort();
54}
55
58{
59 fldIdxVec.push_back(fldIdx);
60 elemIdxVec.push_back(elemIdx);
61 fldIdx2TypeMap[fldIdx] = type;
62}
63
67//{@
69{
71 if(it!=fldIdx2TypeMap.end())
72 return it->second;
73 return nullptr;
74}
75
77{
78 assert(hasLoopInfo(bb) && "loopinfo does not exist (bb not in a loop)");
80 return mapIter->second;
81}
82
84{
85 if (hasLoopInfo(bb))
86 {
87 const LoopBBs blocks = getLoopInfo(bb);
88 if (!blocks.empty())
89 {
90 for (const SVFBasicBlock* block : blocks)
91 {
92 for (const SVFBasicBlock* succ : block->getSuccessors())
93 {
94 if ((std::find(blocks.begin(), blocks.end(), succ)==blocks.end()))
95 exitbbs.push_back(succ);
96 }
97 }
98 }
99 }
100}
101
103{
104 if (bbKey == bbValue)
105 return true;
106
107 // An unreachable node is dominated by anything.
109 {
110 return true;
111 }
112
113 // And dominates nothing.
114 if (isUnreachable(bbKey))
115 {
116 return false;
117 }
118
121 if (mapIter != dtBBsMap.end())
122 {
123 const BBSet & dtBBs = mapIter->second;
124 if (dtBBs.find(bbValue) != dtBBs.end())
125 {
126 return true;
127 }
128 }
129
130 return false;
131}
132
134{
135 if (bbKey == bbValue)
136 return true;
137
138 // An unreachable node is dominated by anything.
140 {
141 return true;
142 }
143
144 // And dominates nothing.
145 if (isUnreachable(bbKey))
146 {
147 return false;
148 }
149
152 if (mapIter != dtBBsMap.end())
153 {
154 const BBSet & dtBBs = mapIter->second;
155 if (dtBBs.find(bbValue) != dtBBs.end())
156 {
157 return true;
158 }
159 }
160 return false;
161}
162
164{
165 assert(A && B && "Pointers are not valid");
166 assert(A->getParent() == B->getParent() &&
167 "Two blocks are not in same function");
168
169 // Use level information to go up the tree until the levels match. Then
170 // continue going up til we arrive at the same node.
171 while (A != B)
172 {
173 // no common PDominator
174 if(A == NULL) return NULL;
175 const auto lvA = getBBPDomLevel().find(A);
176 const auto lvB = getBBPDomLevel().find(B);
177 assert(lvA != getBBPDomLevel().end() && lvB != getBBPDomLevel().end());
178
179 if (lvA->second < lvB->second) std::swap(A, B);
180
181 const auto lvAIdom = getBB2PIdom().find(A);
182 assert(lvAIdom != getBB2PIdom().end());
183 A = lvAIdom->second;
184 }
185
186 return A;
187}
188
190{
191 if (hasLoopInfo(bb))
192 {
193 const LoopBBs& blocks = getLoopInfo(bb);
194 assert(!blocks.empty() && "no available loop info?");
195 return blocks.front() == bb;
196 }
197 return false;
198}
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:76
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:102
bool isLoopHeader(const SVFBasicBlock *bb) const
Definition SVFValue.cpp:189
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
Definition SVFValue.cpp:83
const SVFBasicBlock * findNearestCommonPDominator(const SVFBasicBlock *A, const SVFBasicBlock *B) const
find nearest common post dominator of two basic blocks
Definition SVFValue.cpp:163
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:133
const bool hasLLVMValue() const
Definition LLVMUtil.cpp:754
const std::string valueOnlyToString() const
Definition LLVMUtil.cpp:735
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:68
std::vector< u32_t > fldIdxVec
flattened field indices of a struct (ignoring arrays)
Definition SVFType.h:79
std::vector< u32_t > elemIdxVec
Definition SVFType.h:82
Map< u32_t, const SVFType * > fldIdx2TypeMap
Types of all fields of a struct.
Definition SVFType.h:84
#define NULL
Definition extapi.c:5
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:47