34 #include "llvm/Analysis/LoopInfo.h"
36 #include "llvm/Transforms/Utils/Mem2Reg.h"
37 #include "llvm/Passes/PassBuilder.h"
42 using namespace SVFUtil;
52 std::vector<const Loop *> loop_stack;
55 for (Module::const_iterator
F = M.begin(), E = M.end();
F != E; ++
F)
59 if (func->isDeclaration())
continue;
62 DT.recalculate(
const_cast<Function&
>(*func));
63 llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop> loopInfo;
64 std::vector<const Loop*> llvmLoops;
66 for (
const auto &loop: loopInfo)
68 loop_stack.push_back(loop);
71 while (!loop_stack.empty())
73 const Loop *loop = loop_stack.
back();
74 loop_stack.pop_back();
75 llvmLoops.push_back(loop);
76 for (
const auto &subloop: loop->getSubLoops())
78 loop_stack.push_back(subloop);
81 buildSVFLoops(icfg, llvmLoops);
92 std::vector<const Loop *> llvmLoops;
103 for (
const auto &llvmLoop: llvmLoops)
109 for (
const auto &BB: llvmLoop->getBlocks())
111 for (
const auto &ins: *BB)
120 for (
const auto &node:
nodes)
125 BasicBlock* header_blk = llvmLoop->getHeader();
130 in_ins = in_ins->getNextNode();
135 if (loop_ids.find(edge->getSrcNode()) == loop_ids.end())
153 if (loop_ids.find(edge->getDstNode()) != loop_ids.end())
164 llvm::SmallVector<BasicBlock*, 8> ExitBlocks;
165 llvmLoop->getExitBlocks(ExitBlocks);
166 for (
const auto& exit_blk: ExitBlocks)
168 assert(!exit_blk->empty() &&
"exit block is empty?");
173 out_ins = out_ins->getNextNode();
177 for (
const auto &edge: out_node->
getInEdges())
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
void addNodeToSVFLoop(const ICFGNode *node, const SVFLoop *loop)
Insert (node, loop) to icfgNodeToSVFLoopVec.
virtual void build(ICFG *icfg)
Start from here.
virtual void buildLLVMLoops(SVFModule *mod, ICFG *icfg)
Build llvm loops based on LoopInfo analysis.
virtual void buildSVFLoops(ICFG *icfg, std::vector< const Loop * > &llvmLoops)
Build SVF loops based on llvm loops.
SVFFunction * getSVFFunction(const Function *fun) const
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
static LLVMModuleSet * getLLVMModuleSet()
static const Option< u32_t > LoopBound
const SVFBasicBlock * back() const
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
void addBackICFGEdge(const ICFGEdge *edge)
void addOutICFGEdge(const ICFGEdge *edge)
void addEntryICFGEdge(const ICFGEdge *edge)
void addInICFGEdge(const ICFGEdge *edge)
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
bool isExtCall(const SVFFunction *fun)
std::ostream & outs()
Overwrite llvm::outs()
llvm::BasicBlock BasicBlock
llvm::Instruction Instruction
llvm::Loop Loop
LLVM Loop.
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
llvm::DominatorTree DominatorTree
LLVM Dominators.
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set