Skip to content

Commit

Permalink
move icfg building to llvmmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
jumormt committed Oct 9, 2024
1 parent 6ac0415 commit 2af9828
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
5 changes: 5 additions & 0 deletions svf-llvm/include/SVF-LLVM/LLVMModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class LLVMModuleSet
static bool preProcessed;
SymbolTableInfo* symInfo;
SVFModule* svfModule; ///< Borrowed from singleton SVFModule::svfModule
ICFG* icfg;
std::unique_ptr<LLVMContext> owned_ctx;
std::vector<std::unique_ptr<Module>> owned_modules;
std::vector<std::reference_wrapper<Module>> modules;
Expand Down Expand Up @@ -362,6 +363,10 @@ class LLVMModuleSet

ObjTypeInference* getTypeInference();

inline ICFG* getICFG() {
return icfg;
}

private:
/// Create SVFTypes
SVFType* addSVFTypeInfo(const Type* t);
Expand Down
25 changes: 11 additions & 14 deletions svf-llvm/lib/ICFGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,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");
Expand All @@ -251,14 +249,16 @@ InterICFGNode* ICFGBuilder::addInterBlockICFGNode(const Instruction* inst)
else
{
calledFunc = SVFUtil::dyn_cast<SVFFunction>(
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);

Expand Down Expand Up @@ -330,25 +330,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<SVFBasicBlock*>(svfINst->getParent())
->addICFGNode(node);
const_cast<SVFBasicBlock*>(
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<ReturnInst>(inst));
llvmModuleSet()->getSVFBasicBlock(inst->getParent()), SVFUtil::isa<ReturnInst>(inst));
instToBlockNodeMap()[inst] = sNode;
llvmModuleSet()->setValueAttr(inst, sNode);
return sNode;
Expand Down
4 changes: 4 additions & 0 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,6 +167,9 @@ void LLVMModuleSet::build()

createSVFDataStructure();
initSVFFunction();
icfg = new ICFG();
ICFGBuilder icfgbuilder(icfg);
icfgbuilder.build();
}

void LLVMModuleSet::createSVFDataStructure()
Expand Down
5 changes: 1 addition & 4 deletions svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 2af9828

Please sign in to comment.