diff --git a/svf-llvm/include/SVF-LLVM/ICFGBuilder.h b/svf-llvm/include/SVF-LLVM/ICFGBuilder.h index d8ab4b562..3f79ac767 100644 --- a/svf-llvm/include/SVF-LLVM/ICFGBuilder.h +++ b/svf-llvm/include/SVF-LLVM/ICFGBuilder.h @@ -58,11 +58,11 @@ class ICFGBuilder public: typedef FIFOWorkList WorkList; - ICFGBuilder(ICFG* i): icfg(i) + ICFGBuilder(): icfg(new ICFG()) { } - void build(); + ICFG* build(); private: diff --git a/svf-llvm/include/SVF-LLVM/LLVMModule.h b/svf-llvm/include/SVF-LLVM/LLVMModule.h index 04c01d483..de3899784 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMModule.h +++ b/svf-llvm/include/SVF-LLVM/LLVMModule.h @@ -76,6 +76,7 @@ class LLVMModuleSet static bool preProcessed; SymbolTableInfo* symInfo; SVFModule* svfModule; ///< Borrowed from singleton SVFModule::svfModule + ICFG* icfg; std::unique_ptr owned_ctx; std::vector> owned_modules; std::vector> modules; @@ -362,6 +363,10 @@ class LLVMModuleSet ObjTypeInference* getTypeInference(); + inline ICFG* getICFG() { + return icfg; + } + private: /// Create SVFTypes SVFType* addSVFTypeInfo(const Type* t); diff --git a/svf-llvm/lib/ICFGBuilder.cpp b/svf-llvm/lib/ICFGBuilder.cpp index 1b138f485..7ac7d9614 100644 --- a/svf-llvm/lib/ICFGBuilder.cpp +++ b/svf-llvm/lib/ICFGBuilder.cpp @@ -40,7 +40,7 @@ using namespace SVFUtil; /*! * Create ICFG nodes and edges */ -void ICFGBuilder::build() +ICFG* ICFGBuilder::build() { DBOUT(DGENERAL, outs() << pasMsg("\t Building ICFG ...\n")); // Add the unique global ICFGNode at the entry of a program (before the main method). @@ -78,6 +78,7 @@ void ICFGBuilder::build() } connectGlobalToProgEntry(); + return icfg; } void ICFGBuilder::checkICFGNodesVisited(const Function* fun) @@ -235,8 +236,6 @@ void ICFGBuilder::processFunExit(const Function* f) */ InterICFGNode* ICFGBuilder::addInterBlockICFGNode(const Instruction* inst) { - SVFInstruction* svfInst = - llvmModuleSet()->getSVFInstruction(inst); assert(LLVMUtil::isCallSite(inst) && "not a call instruction?"); assert(LLVMUtil::isNonInstricCallSite(inst) && "associating an intrinsic debug instruction with an ICFGNode!"); assert(llvmModuleSet()->getCallBlock(inst)==nullptr && "duplicate CallICFGNode"); @@ -251,14 +250,16 @@ InterICFGNode* ICFGBuilder::addInterBlockICFGNode(const Instruction* inst) else { calledFunc = SVFUtil::dyn_cast( - llvmModuleSet()->getSVFValue(called_llvmval)); + llvmModuleSet()->getSVFValue(called_llvmval)); } + SVFBasicBlock* bb = llvmModuleSet()->getSVFBasicBlock(inst->getParent()); + CallICFGNode* callICFGNode = icfg->addCallICFGNode( - svfInst->getParent(), llvmModuleSet()->getSVFType(inst->getType()), - calledFunc, cb->getFunctionType()->isVarArg(), isvcall, - isvcall ? cppUtil::getVCallIdx(cb) : 0, - isvcall ? cppUtil::getFunNameOfVCallSite(cb) : ""); + bb, llvmModuleSet()->getSVFType(inst->getType()), + calledFunc, cb->getFunctionType()->isVarArg(), isvcall, + isvcall ? cppUtil::getVCallIdx(cb) : 0, + isvcall ? cppUtil::getFunNameOfVCallSite(cb) : ""); csToCallNodeMap()[inst] = callICFGNode; llvmModuleSet()->setValueAttr(inst, callICFGNode); @@ -330,25 +331,22 @@ void ICFGBuilder::connectGlobalToProgEntry() inline ICFGNode* ICFGBuilder::addBlockICFGNode(const Instruction* inst) { ICFGNode* node; - SVFInstruction* svfINst = - llvmModuleSet()->getSVFInstruction(inst); if(LLVMUtil::isNonInstricCallSite(inst)) node = addInterBlockICFGNode(inst); else node = addIntraBlockICFGNode(inst); - const_cast(svfINst->getParent()) - ->addICFGNode(node); + const_cast( + llvmModuleSet()->getSVFBasicBlock(inst->getParent())) + ->addICFGNode(node); return node; } IntraICFGNode* ICFGBuilder::addIntraBlockICFGNode(const Instruction* inst) { - SVFInstruction* svfInst = - llvmModuleSet()->getSVFInstruction(inst); IntraICFGNode* node = llvmModuleSet()->getIntraBlock(inst); assert (node==nullptr && "no IntraICFGNode for this instruction?"); IntraICFGNode* sNode = icfg->addIntraICFGNode( - svfInst->getParent(), SVFUtil::isa(inst)); + llvmModuleSet()->getSVFBasicBlock(inst->getParent()), SVFUtil::isa(inst)); instToBlockNodeMap()[inst] = sNode; llvmModuleSet()->setValueAttr(inst, sNode); return sNode; diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index 5ec3b62d3..d520dc514 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -40,6 +40,7 @@ #include "llvm/Support/FileSystem.h" #include "SVF-LLVM/ObjTypeInference.h" #include "llvm/Transforms/Utils/Cloning.h" +#include "SVF-LLVM/ICFGBuilder.h" using namespace std; using namespace SVF; @@ -166,6 +167,8 @@ void LLVMModuleSet::build() createSVFDataStructure(); initSVFFunction(); + ICFGBuilder icfgbuilder; + icfg = icfgbuilder.build(); } void LLVMModuleSet::createSVFDataStructure() diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 43ca97eb7..66221980f 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -60,10 +60,7 @@ SVFIR* SVFIRBuilder::build() pag->setModule(svfModule); // Build ICFG - ICFG* icfg = new ICFG(); - ICFGBuilder icfgbuilder(icfg); - icfgbuilder.build(); - pag->setICFG(icfg); + pag->setICFG(llvmModuleSet()->getICFG()); // Set icfgnode in memobj for (auto& it : SymbolTableInfo::SymbolInfo()->idToObjMap())