Skip to content

Commit

Permalink
Merge pull request #1566 from jumormt/10.7
Browse files Browse the repository at this point in the history
move icfg building to llvmmodule
  • Loading branch information
yuleisui authored Oct 10, 2024
2 parents 6ac0415 + f98501e commit f9929a7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions svf-llvm/include/SVF-LLVM/ICFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class ICFGBuilder
public:
typedef FIFOWorkList<const Instruction*> WorkList;

ICFGBuilder(ICFG* i): icfg(i)
ICFGBuilder(): icfg(new ICFG())
{

}
void build();
ICFG* build();

private:

Expand Down
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
28 changes: 13 additions & 15 deletions svf-llvm/lib/ICFGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -78,6 +78,7 @@ void ICFGBuilder::build()

}
connectGlobalToProgEntry();
return icfg;
}

void ICFGBuilder::checkICFGNodesVisited(const Function* fun)
Expand Down Expand Up @@ -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");
Expand All @@ -251,14 +250,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 +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<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
3 changes: 3 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,8 @@ void LLVMModuleSet::build()

createSVFDataStructure();
initSVFFunction();
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 f9929a7

Please sign in to comment.