Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SVF::LLVMLoopAnalysis Class Reference

#include <LLVMLoopAnalysis.h>

Public Member Functions

 LLVMLoopAnalysis ()=default
 Constructor.
 
virtual ~LLVMLoopAnalysis ()=default
 Destructor.
 
virtual void buildLLVMLoops (ICFG *icfg)
 Build llvm loops based on LoopInfo analysis.
 
virtual void build (ICFG *icfg)
 Start from here.
 
virtual void buildSVFLoops (ICFG *icfg, std::vector< const Loop * > &llvmLoops)
 Build SVF loops based on llvm loops.
 

Detailed Description

Definition at line 38 of file LLVMLoopAnalysis.h.

Constructor & Destructor Documentation

◆ LLVMLoopAnalysis()

SVF::LLVMLoopAnalysis::LLVMLoopAnalysis ( )
default

Constructor.

◆ ~LLVMLoopAnalysis()

virtual SVF::LLVMLoopAnalysis::~LLVMLoopAnalysis ( )
virtualdefault

Destructor.

Member Function Documentation

◆ build()

void LLVMLoopAnalysis::build ( ICFG *  icfg)
virtual

Start from here.

We start from here

Parameters
icfgICFG

Definition at line 91 of file LLVMLoopAnalysis.cpp.

92{
93 std::vector<const Loop *> llvmLoops;
94 buildLLVMLoops(icfg);
95}
virtual void buildLLVMLoops(ICFG *icfg)
Build llvm loops based on LoopInfo analysis.
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ buildLLVMLoops()

void LLVMLoopAnalysis::buildLLVMLoops ( ICFG *  icfg)
virtual

Build llvm loops based on LoopInfo analysis.

Build llvm loops based on LoopInfo analysis

Parameters
modSVF module
llvmLoopsoutput llvm loops

Definition at line 51 of file LLVMLoopAnalysis.cpp.

52{
53 std::vector<const Loop *> loop_stack;
54 for (Module& M : LLVMModuleSet::getLLVMModuleSet()->getLLVMModules())
55 {
56 for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
57 {
58 const Function* func = &*F;
60 if (func->isDeclaration()) continue;
61 // do not analyze external call
62 if (SVFUtil::isExtCall(svffun)) continue;
63 llvm::DominatorTree& DT = LLVMModuleSet::getLLVMModuleSet()->getDomTree(func);
64 llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop> loopInfo;
65 std::vector<const Loop*> llvmLoops;
66 loopInfo.analyze(DT);
67 for (const auto &loop: loopInfo)
68 {
69 loop_stack.push_back(loop);
70 }
71 // pre-order traversal on loop-subloop tree
72 while (!loop_stack.empty())
73 {
74 const Loop *loop = loop_stack.back();
75 loop_stack.pop_back();
76 llvmLoops.push_back(loop);
77 for (const auto &subloop: loop->getSubLoops())
78 {
79 loop_stack.push_back(subloop);
80 }
81 }
83 }
84 }
85}
virtual void buildSVFLoops(ICFG *icfg, std::vector< const Loop * > &llvmLoops)
Build SVF loops based on llvm loops.
const FunObjVar * getFunObjVar(const Function *fun) const
Definition LLVMModule.h:270
static LLVMModuleSet * getLLVMModuleSet()
Definition LLVMModule.h:133
DominatorTree & getDomTree(const Function *fun)
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:526
llvm::Function Function
Definition BasicTypes.h:89
llvm::Module Module
Definition BasicTypes.h:88
llvm::Loop Loop
LLVM Loop.
Definition BasicTypes.h:147

◆ buildSVFLoops()

void LLVMLoopAnalysis::buildSVFLoops ( ICFG *  icfg,
std::vector< const Loop * > &  llvmLoops 
)
virtual

Build SVF loops based on llvm loops.

Build SVF loops based on llvm loops

Parameters
icfgICFG
llvmLoopsinput llvm loops

Definition at line 102 of file LLVMLoopAnalysis.cpp.

103{
104 for (const auto &llvmLoop: llvmLoops)
105 {
106 DBOUT(DPAGBuild, outs() << "loop name: " << llvmLoop->getName().data() << "\n");
107 // count all node id in loop
110 for (const auto &BB: llvmLoop->getBlocks())
111 {
112 for (const auto &ins: *BB)
113 {
115 continue;
116 loop_ids.insert(LLVMModuleSet::getLLVMModuleSet()->getICFGNode(&ins));
117 nodes.insert(LLVMModuleSet::getLLVMModuleSet()->getICFGNode(&ins));
118 }
119 }
121 for (const auto &node: nodes)
122 {
123 icfg->addNodeToSVFLoop(node, svf_loop);
124 }
125 // mark loop header's first inst
126 BasicBlock* header_blk = llvmLoop->getHeader();
127 Instruction* in_ins = &(*header_blk->begin());
128
130 {
131 in_ins = in_ins->getNextNode();
132 }
134 for (const auto &edge: in_node->getInEdges())
135 {
136 if (loop_ids.find(edge->getSrcNode()) == loop_ids.end())
137 {
138 // entry edge
139 svf_loop->addEntryICFGEdge(edge);
140 DBOUT(DPAGBuild, outs() << " entry edge: " << edge->toString() << "\n");
141 }
142 else
143 {
144 // back edge
145 svf_loop->addBackICFGEdge(edge);
146 DBOUT(DPAGBuild, outs() << " back edge: " << edge->toString() << "\n");
147 }
148 }
149 // handle in edge
150 llvm::Instruction &br_ins = header_blk->back();
152 for (const auto &edge: br_node->getOutEdges())
153 {
154 if (loop_ids.find(edge->getDstNode()) != loop_ids.end())
155 {
156 svf_loop->addInICFGEdge(edge);
157 DBOUT(DPAGBuild, outs() << " in edge: " << edge->toString() << "\n");
158 }
159 else
160 {
161 continue;
162 }
163 }
164 // mark loop end's first inst
165 llvm::SmallVector<BasicBlock*, 8> ExitBlocks;
166 llvmLoop->getExitBlocks(ExitBlocks);
167 for (const auto& exit_blk: ExitBlocks)
168 {
169 assert(!exit_blk->empty() && "exit block is empty?");
170 llvm::Instruction* out_ins = &(*exit_blk->begin());
171
173 {
174 out_ins = out_ins->getNextNode();
175 }
176
178 for (const auto &edge: out_node->getInEdges())
179 {
180 svf_loop->addOutICFGEdge(edge);
181 DBOUT(DPAGBuild, outs() << " out edge: " << edge->toString() << "\n");
182 }
183 }
184 }
185}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define DPAGBuild
Definition SVFType.h:584
void addNodeToSVFLoop(const ICFGNode *node, const SVFLoop *loop)
Insert (node, loop) to icfgNodeToSVFLoopVec.
Definition ICFG.h:120
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
static const Option< u32_t > LoopBound
Definition Options.h:233
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
Definition LLVMUtil.cpp:204
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:58
llvm::BasicBlock BasicBlock
Definition BasicTypes.h:90
llvm::Instruction Instruction
Definition BasicTypes.h:91
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)

The documentation for this class was generated from the following files: