10000 move icfg building to llvmmodule by jumormt · Pull Request #1566 · SVF-tools/SVF · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

move icfg building to llvmmodule #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
0