36#include "llvm/Analysis/LoopInfo.h"
38#include "llvm/Transforms/Utils/Mem2Reg.h"
39#include "llvm/Passes/PassBuilder.h"
53 std::vector<const Loop *> loop_stack;
56 for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
60 if (func->isDeclaration())
continue;
64 llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop> loopInfo;
65 std::vector<const Loop*> llvmLoops;
67 for (
const auto &loop: loopInfo)
69 loop_stack.push_back(loop);
72 while (!loop_stack.empty())
74 const Loop *loop = loop_stack.back();
75 loop_stack.pop_back();
76 llvmLoops.push_back(loop);
77 for (
const auto &subloop: loop->getSubLoops())
79 loop_stack.push_back(subloop);
93 std::vector<const Loop *> llvmLoops;
104 for (
const auto &llvmLoop: llvmLoops)
110 for (
const auto &BB: llvmLoop->getBlocks())
112 for (
const auto &ins: *BB)
121 for (
const auto &node:
nodes)
126 BasicBlock* header_blk = llvmLoop->getHeader();
131 in_ins = in_ins->getNextNode();
136 if (loop_ids.find(edge->getSrcNode()) == loop_ids.end())
150 llvm::Instruction &br_ins = header_blk->back();
154 if (loop_ids.find(edge->getDstNode()) != loop_ids.end())
165 llvm::SmallVector<BasicBlock*, 8> ExitBlocks;
166 llvmLoop->getExitBlocks(ExitBlocks);
167 for (
const auto& exit_blk: ExitBlocks)
169 assert(!exit_blk->empty() &&
"exit block is empty?");
170 llvm::Instruction* out_ins = &(*exit_blk->begin());
174 out_ins = out_ins->getNextNode();
178 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(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.
const FunObjVar * getFunObjVar(const Function *fun) const
static LLVMModuleSet * getLLVMModuleSet()
DominatorTree & getDomTree(const Function *fun)
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
static const Option< u32_t > LoopBound
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 FunObjVar *fun)
std::ostream & outs()
Overwrite llvm::outs().
llvm::BasicBlock BasicBlock
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
llvm::Instruction Instruction
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
llvm::Loop Loop
LLVM Loop.