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 4c14a19
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 27 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
2 changes: 1 addition & 1 deletion svf-llvm/include/SVF-LLVM/SVFIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
}

/// Start building SVFIR here
virtual SVFIR* build();
virtual SVFIR* build(ICFG* icfg);

/// Return SVFIR
SVFIR* getPAG() const
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 @@ -50,7 +50,7 @@ using namespace LLVMUtil;
/*!
* Start building SVFIR here
*/
SVFIR* SVFIRBuilder::build()
SVFIR* SVFIRBuilder::build(ICFG* icfg)
{
double startTime = SVFStat::getClk(true);

Expand All @@ -60,9 +60,6 @@ SVFIR* SVFIRBuilder::build()
pag->setModule(svfModule);

// Build ICFG
ICFG* icfg = new ICFG();
ICFGBuilder icfgbuilder(icfg);
icfgbuilder.build();
pag->setICFG(icfg);

// Set icfgnode in memobj
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/AE/ae.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ int main(int argc, char** argv)

SVFModule *svfModule = LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec);
SVFIRBuilder builder(svfModule);
SVFIR* pag = builder.build();
SVFIR* pag = builder.build(LLVMModuleSet::getLLVMModuleSet()->getICFG());
AndersenWaveDiff* ander = AndersenWaveDiff::createAndersenWaveDiff(pag);
CallGraph* callgraph = ander->getCallGraph();
builder.updateCallGraph(callgraph);
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/CFL/cfl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char ** argv)
{
SVFModule* svfModule = LLVMModuleSet::buildSVFModule(moduleNameVec);
SVFIRBuilder builder(svfModule);
svfir = builder.build();
svfir = builder.build(LLVMModuleSet::getLLVMModuleSet()->getICFG());
} // if no dot form CFLGraph is specified, we use svfir from .bc.

// The CFLBase pointer that will be used to run the analysis
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/DDA/dda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char ** argv)

SVFModule* svfModule = LLVMModuleSet::buildSVFModule(moduleNameVec);
SVFIRBuilder builder(svfModule);
SVFIR* pag = builder.build();
SVFIR* pag = builder.build(LLVMModuleSet::getLLVMModuleSet()->getICFG());

DDAPass dda;
dda.runOnModule(pag);
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/Example/svf-ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int main(int argc, char ** argv)

/// Build Program Assignment Graph (SVFIR)
SVFIRBuilder builder(svfModule);
SVFIR* pag = builder.build();
SVFIR* pag = builder.build(LLVMModuleSet::getLLVMModuleSet()->getICFG());

/// Create Andersen's pointer analysis
Andersen* ander = AndersenWaveDiff::createAndersenWaveDiff(pag);
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/LLVM2SVF/llvm2svf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(int argc, char** argv)
SVFModule* svfModule = LLVMModuleSet::buildSVFModule(moduleNameVec);
const std::string jsonPath = replaceExtension(moduleNameVec.front());
// PAG is borrowed from a unique_ptr, so we don't need to delete it.
const SVFIR* pag = SVFIRBuilder(svfModule).build();
const SVFIR* pag = SVFIRBuilder(svfModule).build(LLVMModuleSet::getLLVMModuleSet()->getICFG());

Check warning on line 67 in svf-llvm/tools/LLVM2SVF/llvm2svf.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/tools/LLVM2SVF/llvm2svf.cpp#L67

Added line #L67 was not covered by tests

SVFIRWriter::writeJsonToPath(pag, jsonPath);
SVFUtil::outs() << "SVF IR is written to '" << jsonPath << "'\n";
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/MTA/mta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char ** argv)

SVFModule* svfModule = LLVMModuleSet::buildSVFModule(moduleNameVec);
SVFIRBuilder builder(svfModule);
SVFIR* pag = builder.build();
SVFIR* pag = builder.build(LLVMModuleSet::getLLVMModuleSet()->getICFG());


MTA mta;
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/SABER/saber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char ** argv)

SVFModule* svfModule = LLVMModuleSet::buildSVFModule(moduleNameVec);
SVFIRBuilder builder(svfModule);
SVFIR* pag = builder.build();
SVFIR* pag = builder.build(LLVMModuleSet::getLLVMModuleSet()->getICFG());


std::unique_ptr<LeakChecker> saber;
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/WPA/wpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char** argv)

/// Build SVFIR
SVFIRBuilder builder(svfModule);
pag = builder.build();
pag = builder.build(LLVMModuleSet::getLLVMModuleSet()->getICFG());

}

Expand Down

0 comments on commit 4c14a19

Please sign in to comment.