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
49
52{
53 fldIdxVec.push_back(fldIdx);
54 elemIdxVec.push_back(elemIdx);
55 fldIdx2TypeMap[fldIdx] = type;
56}
57
61//{@
63{
65 if(it!=fldIdx2TypeMap.end())
66 return it->second;
67 return nullptr;
68}
69
71{
72 assert(hasLoopInfo(bb) && "loopinfo does not exist (bb not in a loop)");
74 return mapIter->second;
75}
76
78{
79 if (hasLoopInfo(bb))
80 {
81 const LoopBBs blocks = getLoopInfo(bb);
82 if (!blocks.empty())
83 {
84 for (const SVFBasicBlock* block : blocks)
85 {
86 for (const SVFBasicBlock* succ : block->getSuccessors())
87 {
88 if ((std::find(blocks.begin(), blocks.end(), succ)==blocks.end()))
89 exitbbs.push_back(succ);
90 }
91 }
92 }
93 }
94}
95
97{
98 if (bbKey == bbValue)
99 return true;
100
101 // An unreachable node is dominated by anything.
103 {
104 return true;
105 }
106
107 // And dominates nothing.
108 if (isUnreachable(bbKey))
109 {
110 return false;
111 }
112
115 if (mapIter != dtBBsMap.end())
116 {
117 const BBSet & dtBBs = mapIter->second;
118 if (dtBBs.find(bbValue) != dtBBs.end())
119 {
120 return true;
121 }
122 }
123
124 return false;
125}
126
128{
129 if (bbKey == bbValue)
130 return true;
131
132 // An unreachable node is dominated by anything.
134 {
135 return true;
136 }
137
138 // And dominates nothing.
139 if (isUnreachable(bbKey))
140 {
141 return false;
142 }
143
146 if (mapIter != dtBBsMap.end())
147 {
148 const BBSet & dtBBs = mapIter->second;
149 if (dtBBs.find(bbValue) != dtBBs.end())
150 {
151 return true;
152 }
153 }
154 return false;
155}
156
158{
159 assert(A && B && "Pointers are not valid");
160 assert(A->getParent() == B->getParent() &&
161 "Two blocks are not in same function");
162
163 // Use level information to go up the tree until the levels match. Then
164 // continue going up til we arrive at the same node.
165 while (A != B)
166 {
167 // no common PDominator
168 if(A == NULL) return NULL;
169 const auto lvA = getBBPDomLevel().find(A);
170 const auto lvB = getBBPDomLevel().find(B);
171 assert(lvA != getBBPDomLevel().end() && lvB != getBBPDomLevel().end());
172
173 if (lvA->second < lvB->second) std::swap(A, B);
174
175 const auto lvAIdom = getBB2PIdom().find(A);
176 assert(lvAIdom != getBB2PIdom().end());
177 A = lvAIdom->second;
178 }
179
180 return A;
181}
182
184{
185 if (hasLoopInfo(bb))
186 {
187 const LoopBBs& blocks = getLoopInfo(bb);
188 assert(!blocks.empty() && "no available loop info?");
189 return blocks.front() == bb;
190 }
191 return false;
192}
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:70
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:96
bool isLoopHeader(const SVFBasicBlock *bb) const
Definition SVFValue.cpp:183
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
Definition SVFValue.cpp:77
const SVFBasicBlock * findNearestCommonPDominator(const SVFBasicBlock *A, const SVFBasicBlock *B) const
find nearest common post dominator of two basic blocks
Definition SVFValue.cpp:157
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:127
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:62
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
Map< u32_t, const SVFType * > fldIdx2TypeMap
Types of all fields of a struct.
Definition SVFType.h:58
#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