Skip to content

remove all SVFFunction in svf #1646

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

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b8747ac
copy all fields of SVFFunction into CallGraphNode
Oct 16, 2024
09eda74
Merge remote-tracking branch 'upstream/master' into hwg_1_27
Jan 27, 2025
7c52c5b
fix
Jan 30, 2025
0cdfac1
rm SVFFunction in CFL
Jan 30, 2025
207340e
seperate buildSVFIRCallGraph to two functions
Dec 10, 2024
7823b9f
change ICFGNode::SVFFunction* calledFunc to const CallGraphNode* call…
Dec 10, 2024
82fac47
rm Map<const SVFFunction*, CallGraphNode*> FunToCallGraphNodeMap; in …
Oct 19, 2024
bbf2484
refactoring bool isSourceLikeFun(const CallGraphNode* fun)
Dec 11, 2024
9186c86
refactoring connectCaller2ForkedFunParams(const CallICFGNode* cs, co…
Dec 11, 2024
25f302d
refactoring const SVFFunction* fun; --> CallGraphNode* fun; in PTACa…
Dec 11, 2024
0bb927f
refactoring Map<const SVFFunction*, PTACallGraphNode*> FunToCallGrap…
Dec 11, 2024
81206ea
rename FunToPTACallGraphNodeMap funToPtaCallGraphNodeMap; --> CgNode…
Dec 11, 2024
2536482
refactoring std::pair<const CallICFGNode*, const SVFFunction*> CallSi…
Dec 11, 2024
1969292
refactoring typedef Set<const SVFFunction*> FunctionSet; --> Set<cons…
Dec 11, 2024
c3e5301
Merge branch 'master' into hwg_1_27
Jan 30, 2025
d1faa8a
Merge remote-tracking branch 'upstream/master' into hwg_1_27
Jan 31, 2025
fee8c91
refactoring icfgNode->getFun()->getFunction() --> const CallGraphNode…
Dec 11, 2024
ee85952
refactoring FunToFunEntryNodeMapTy in ICFG,h
Dec 11, 2024
20ec977
refactoring getIndCallSitesInvokingCallee in PTACallGraph.h,h
Dec 11, 2024
6db5bad
refactoring getFunEntryICFGNode in ICFG.h
Dec 11, 2024
2536485
rm SVFFunction in CHG.h
Dec 11, 2024
ffcab19
rm SVFFunction in SVFGNode.h & VFGNode.h
Dec 11, 2024
02cd143
rm SVFFunction in SVFG.h & VFG.h
Dec 11, 2024
c87f0a4
remove SVFFunction in SVFIR.h
Dec 11, 2024
f6c0793
rm SVFFunction in CDGBuilder.h
Dec 11, 2024
3459f67
rm SVFFunction in ThreadCallGraph.h
Dec 11, 2024
6f96b93
rm SVFFunction in FlowDDA and ContextDDA
Dec 11, 2024
c3271c3
rm SVFFunction in TCT.h
Dec 11, 2024
916f506
rm SVFFunction in MemPartition.h & MemRegion.h
Dec 11, 2024
732594d
rm SVFFunction in MemSSA.h MSSAMuChi.h
Dec 11, 2024
08a9d5e
rm SVFFunction in MHP.h
Dec 11, 2024
2cc34cd
rm SVFFunction in SaberCondAllocator.h
Dec 11, 2024
8cabf88
rm SVFFunction in SVFVariables.h & fix CallGraphNode constructor with…
Dec 12, 2024
2370fb6
rm SVFFunction in BasicBlockG.h
Jan 31, 2025
2b9d888
refactor: replace SVFFunction with CallGraphNode in SVFUtil and Threa…
Jan 31, 2025
e96388a
refactor: replace SVFFunction with CallGraphNode in matchArgs and rel…
Jan 31, 2025
626553f
refactor: replace SVFFunction with CallGraphNode in SVFStat branchSta…
Jan 31, 2025
0d6b307
refactor: replace SVFFunction with CallGraphNode in MemRegion, MemSSA…
Jan 31, 2025
c5e3b81
refactor: replace SVFFunction with CallGraphNode in SVFModule, relate…
Jan 31, 2025
4ad1f61
refactor: update SVFFunction references to CallGraphNode in CallGraph
Feb 1, 2025
4b6c780
rm SVFFunction in ExtAPI
Feb 1, 2025
c22415b
rm SVFFunction* getFunction() in CallGraphNode
Feb 1, 2025
1675748
rm const SVFFunction* fun; in CallGraphNode
Feb 1, 2025
b741107
fix
Feb 1, 2025
e43627d
Merge remote-tracking branch 'upstream/master' into hwg_1_27
Feb 1, 2025
64a56db
remove comments
Feb 2, 2025
5205add
callgraph->getPTACallGraphNode(fun)->getId()) --> fun->getId()
Feb 2, 2025
b43fd17
rename getCallNode() -> getCallGraphNode();
Feb 2, 2025
0410a42
rename getCallNode() -> getCallGraphNode();
Feb 2, 2025
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
22 changes: 19 additions & 3 deletions svf-llvm/include/SVF-LLVM/LLVMModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ class LLVMModuleSet
public:

typedef std::vector<const Function*> FunctionSetType;
typedef Map<const Function*, const Function*> FunDeclToDefMapTy;
typedef Map<const Function*, FunctionSetType> FunDefToDeclsMapTy;
typedef Map<const GlobalVariable*, GlobalVariable*> GlobalDefToRepMapTy;

typedef Map<const CallGraphNode*, SVFFunction*> CGN2SVFFunMap;
typedef Map<const Function*, SVFFunction*> LLVMFun2SVFFunMap;
typedef Map<const Function*, CallGraphNode*> LLVMFun2CallGraphNodeMap;
typedef Map<const BasicBlock*, SVFBasicBlock*> LLVMBB2SVFBBMap;
Expand Down Expand Up @@ -113,6 +112,7 @@ class LLVMModuleSet
FunToFunEntryNodeMapTy FunToFunEntryNodeMap; ///< map a function to its FunExitICFGNode
FunToFunExitNodeMapTy FunToFunExitNodeMap; ///< map a function to its FunEntryICFGNode
CallGraph* callgraph;
CGN2SVFFunMap CallGraphNode2SVFFunMap;

Map<const Function*, DominatorTree> FunToDominatorTree;

Expand Down Expand Up @@ -218,7 +218,7 @@ class LLVMModuleSet
setValueAttr(func,svfFunc);
}

void addFunctionMap(const Function* func, CallGraphNode* svfFunc);
void addFunctionMap(const Function* func, CallGraphNode* node);

// create a SVFBasicBlock according to LLVM BasicBlock, then add it to SVFFunction's BasicBlockGraph
inline void addBasicBlock(SVFFunction* fun, const BasicBlock* bb)
Expand Down Expand Up @@ -366,6 +366,22 @@ class LLVMModuleSet
return nullptr;
}

inline const CallGraphNode* getFunctionNode(const std::string& name)
{
Function* fun = nullptr;

for (u32_t i = 0; i < llvmModuleSet->getModuleNum(); ++i)
{
Module* mod = llvmModuleSet->getModule(i);
fun = mod->getFunction(name);
if (fun)
{
return llvmModuleSet->getCallGraphNode(fun);
}
}
return nullptr;
}

ICFGNode* getICFGNode(const Instruction* inst);

bool hasICFGNode(const Instruction* inst);
Expand Down
6 changes: 3 additions & 3 deletions svf-llvm/include/SVF-LLVM/SVFIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
}

/// getReturnNode - Return the node representing the unique return value of a function.
inline NodeID getReturnNode(const SVFFunction *func)
inline NodeID getReturnNode(const CallGraphNode *func)
{
return pag->getReturnNode(func);
}

/// getVarargNode - Return the node representing the unique variadic argument of a function.
inline NodeID getVarargNode(const SVFFunction *func)
inline NodeID getVarargNode(const CallGraphNode *func)
{
return pag->getVarargNode(func);
}
Expand Down Expand Up @@ -234,7 +234,7 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
//@{
virtual const Type *getBaseTypeAndFlattenedFields(const Value *V, std::vector<AccessPath> &fields, const Value* szValue);
virtual void addComplexConsForExt(Value *D, Value *S, const Value* sz);
virtual void handleExtCall(const CallBase* cs, const SVFFunction* svfCallee);
virtual void handleExtCall(const CallBase* cs, const CallGraphNode* svfCallee);
//@}

/// Set current basic block in order to keep track of control flow information
Expand Down
24 changes: 12 additions & 12 deletions svf-llvm/lib/CHGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@
{
for (int i = 0; i < null_ptr_num; ++i)
{
const SVFFunction* fun = virtualFunctions[i];
const CallGraphNode* fun = virtualFunctions[i];
virtualFunctions.insert(virtualFunctions.begin(), fun);
}
}
Expand Down Expand Up @@ -607,15 +607,15 @@
/*
* get all virtual functions in a specific group
*/
set<const SVFFunction*> virtualFunctions;
set<const CallGraphNode*> virtualFunctions;
for (CHGraph::CHNodeSetTy::iterator it = group.begin(),
eit = group.end(); it != eit; ++it)
{
const vector<CHNode::FuncVector> &vecs = (*it)->getVirtualFunctionVectors();
for (vector<CHNode::FuncVector>::const_iterator vit = vecs.begin(),
veit = vecs.end(); vit != veit; ++vit)
{
for (vector<const SVFFunction*>::const_iterator fit = (*vit).begin(),
for (vector<const CallGraphNode*>::const_iterator fit = (*vit).begin(),
feit = (*vit).end(); fit != feit; ++fit)
{
virtualFunctions.insert(*fit);
Expand All @@ -638,15 +638,15 @@
* <~C, C::~C>
* ...
*/
set<pair<string, const SVFFunction*> > fNameSet;
for (set<const SVFFunction*>::iterator fit = virtualFunctions.begin(),
set<pair<string, const CallGraphNode*> > fNameSet;
for (set<const CallGraphNode*>::iterator fit = virtualFunctions.begin(),
feit = virtualFunctions.end(); fit != feit; ++fit)
{
const SVFFunction* f = *fit;
const CallGraphNode* f = *fit;
struct DemangledName dname = demangle(f->getName());
fNameSet.insert(pair<string, const SVFFunction*>(dname.funcName, f));
fNameSet.insert(pair<string, const CallGraphNode*>(dname.funcName, f));
}
for (set<pair<string, const SVFFunction*>>::iterator it = fNameSet.begin(),
for (set<pair<string, const CallGraphNode*>>::iterator it = fNameSet.begin(),
eit = fNameSet.end(); it != eit; ++it)
{
chg->virtualFunctionToIDMap[it->second] = chg->vfID++;
Expand Down Expand Up @@ -742,15 +742,15 @@
{
if (const auto* tf = cppUtil::getThunkTarget(lf))
{
SVFFunction* pFunction =
llvmModuleSet()->getSVFFunction(tf);
CallGraphNode* pFunction =
llvmModuleSet()->getCallGraphNode(tf);

Check warning on line 746 in svf-llvm/lib/CHGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/lib/CHGBuilder.cpp#L746

Added line #L746 was not covered by tests
v.push_back(pFunction);
}
}
else
{
SVFFunction* pFunction =
llvmModuleSet()->getSVFFunction(lf);
CallGraphNode* pFunction =
llvmModuleSet()->getCallGraphNode(lf);
v.push_back(pFunction);
}
}
6 changes: 3 additions & 3 deletions svf-llvm/lib/DCHG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@
*/
if (funName.size() == 0)
{
virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str()));
virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())->getCallGraphNode());

Check warning on line 643 in svf-llvm/lib/DCHG.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/lib/DCHG.cpp#L643

Added line #L643 was not covered by tests
}
else if (funName[0] == '~')
{
Expand All @@ -656,7 +656,7 @@
*/
if (calleeName[0] == '~')
{
virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str()));
virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())->getCallGraphNode());

Check warning on line 659 in svf-llvm/lib/DCHG.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/lib/DCHG.cpp#L659

Added line #L659 was not covered by tests
}
}
else
Expand All @@ -667,7 +667,7 @@
*/
if (funName.compare(calleeName) == 0)
{
virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str()));
virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())->getCallGraphNode());

Check warning on line 670 in svf-llvm/lib/DCHG.cpp

View check run for this annotation

Codecov / codecov/patch

svf-llvm/lib/DCHG.cpp#L670

Added line #L670 was not covered by tests
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions svf-llvm/lib/ICFGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,11 @@ InterICFGNode* ICFGBuilder::addInterBlockICFGNode(const Instruction* inst)
assert(llvmModuleSet()->getCallBlock(inst)==nullptr && "duplicate CallICFGNode");
const CallBase* cb = SVFUtil::dyn_cast<CallBase>(inst);
bool isvcall = cppUtil::isVirtualCallSite(cb);
SVFFunction* calledFunc = nullptr;
const CallGraphNode* calledFunc = nullptr;
auto called_llvmval = cb->getCalledOperand()->stripPointerCasts();
if (const Function* called_llvmfunc = SVFUtil::dyn_cast<Function>(called_llvmval))
{
calledFunc = llvmModuleSet()->getSVFFunction(called_llvmfunc);
}
else
{
calledFunc = SVFUtil::dyn_cast<SVFFunction>(
llvmModuleSet()->getSVFValue(called_llvmval));
calledFunc = llvmModuleSet()->getCallGraphNode(called_llvmfunc);
}

SVFBasicBlock* bb = llvmModuleSet()->getSVFBasicBlock(inst->getParent());
Expand Down Expand Up @@ -282,8 +277,8 @@ void ICFGBuilder::addICFGInterEdges(const Instruction* cs, const Function* calle
/// direct call
if(callee)
{
SVFFunction* svfFun =
llvmModuleSet()->getSVFFunction(callee);
CallGraphNode* svfFun =
llvmModuleSet()->getCallGraphNode(callee);
/// if this is an external function (no function body)
if (SVFUtil::isExtCall(svfFun))
{
Expand Down Expand Up @@ -352,11 +347,11 @@ IntraICFGNode* ICFGBuilder::addIntraBlockICFGNode(const Instruction* inst)
FunEntryICFGNode* ICFGBuilder::addFunEntryBlock(const Function* fun)
{
return llvmModuleSet()->FunToFunEntryNodeMap[fun] =
icfg->addFunEntryICFGNode(llvmModuleSet()->getSVFFunction(fun));
icfg->addFunEntryICFGNode(llvmModuleSet()->getCallGraphNode(fun));
}

inline FunExitICFGNode* ICFGBuilder::addFunExitBlock(const Function* fun)
{
return llvmModuleSet()->FunToFunExitNodeMap[fun] =
icfg->addFunExitICFGNode(llvmModuleSet()->getSVFFunction(fun));
icfg->addFunExitICFGNode(llvmModuleSet()->getCallGraphNode(fun));
}
2 changes: 1 addition & 1 deletion svf-llvm/lib/LLVMLoopAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void LLVMLoopAnalysis::buildLLVMLoops(SVFModule *mod, ICFG* icfg)
for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
{
const Function* func = &*F;
const SVFFunction* svffun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(func);
const CallGraphNode* svffun = LLVMModuleSet::getLLVMModuleSet()->getCallGraphNode(func);
if (func->isDeclaration()) continue;
// do not analyze external call
if (SVFUtil::isExtCall(svffun)) continue;
Expand Down
68 changes: 47 additions & 21 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ LLVMModuleSet::~LLVMModuleSet()
item.second = nullptr;
}

for (auto& item : CallGraphNode2SVFFunMap){
delete item.second;
}


for (auto& item: LLVMArgument2SVFArgument)
{
delete item.second;
Expand Down Expand Up @@ -182,27 +187,39 @@ void LLVMModuleSet::build()
if (Options::SVFMain())
addSVFMain();

CallGraphBuilder callGraphBuilder;
callgraph = callGraphBuilder.createSVFIRCallGraph();

createSVFDataStructure();
initSVFFunction();

for (auto& item : CallGraphNode2SVFFunMap)
{
CallGraphNode* callNode = const_cast<CallGraphNode*>(item.first);
SVFFunction* fun = item.second;
callNode->init(fun->getFunctionType(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many fields in the classs. Need to simplify fields and use methods for flags and some fields

fun->isUncalledFunction(),
!(fun->hasReturn()),
fun->isDeclaration(),
fun->isIntrinsic(),
fun->hasAddressTaken(),
fun->isVarArg(),
fun->getLoopAndDomInfo(),
const_cast<CallGraphNode*>(fun->getDefFunForMultipleModule()->getCallGraphNode()),
const_cast<SVF::BasicBlockGraph*>(fun->getBasicBlockGraph()),
fun->getArgsList(),
fun->hasBasicBlock()? const_cast<SVFBasicBlock*>(fun->getExitBB()) : nullptr
);
}

ICFGBuilder icfgbuilder;
icfg = icfgbuilder.build();

CallGraphBuilder callGraphBuilder;
callgraph = callGraphBuilder.buildSVFIRCallGraph(svfModule);
for (const auto& func : svfModule->getFunctionSet())
{
SVFFunction* svffunc = const_cast<SVFFunction*>(func);
svffunc->setCallGraphNode(callgraph->getCallGraphNode(func));
}

for (const auto& it : *callgraph)
{
addFunctionMap(
SVFUtil::cast<Function>(getLLVMValue(it.second->getFunction())),
it.second);
}

callGraphBuilder.addSVFIRCallGraphEdges(callgraph);


}

void LLVMModuleSet::createSVFDataStructure()
Expand Down Expand Up @@ -242,8 +259,8 @@ void LLVMModuleSet::createSVFDataStructure()
// Store annotations of functions in extapi.bc
for (const auto& pair : ExtFun2Annotations)
{
const SVFFunction* svffun = getSVFFunction(pair.first);
ExtAPI::getExtAPI()->setExtFuncAnnotations(svffun, pair.second);
const CallGraphNode* funNode = getFunctionNode(pair.first);
ExtAPI::getExtAPI()->setExtFuncAnnotations(funNode, pair.second);
}

/// then traverse candidate sets
Expand Down Expand Up @@ -286,10 +303,19 @@ void LLVMModuleSet::createSVFFunction(const Function* func)
getSVFType(func->getFunctionType())),
func->isDeclaration(), LLVMUtil::isIntrinsicFun(func),
func->hasAddressTaken(), func->isVarArg(), new SVFLoopAndDomInfo);
BasicBlockGraph* bbGraph = new BasicBlockGraph(svfFunc);
CallGraphNode* funcNode = callgraph->addCallGraphNode(getSVFType(func->getType()),
SVFUtil::cast<SVFFunctionType>(
getSVFType(func->getFunctionType())),
func->isDeclaration(), LLVMUtil::isIntrinsicFun(func),
func->hasAddressTaken(), func->isVarArg(), nullptr);
svfFunc->setCallGraphNode(funcNode);
BasicBlockGraph* bbGraph = new BasicBlockGraph(funcNode);
svfFunc->setBasicBlockGraph(bbGraph);
svfModule->addFunctionSet(svfFunc);
svfModule->addFunctionSet(funcNode);
addFunctionMap(func, funcNode);
addFunctionMap(func, svfFunc);
CallGraphNode2SVFFunMap[funcNode] = svfFunc;


for (const Argument& arg : func->args())
{
Expand Down Expand Up @@ -339,7 +365,7 @@ void LLVMModuleSet::initSVFFunction()
SVFFunction* svffun = getSVFFunction(&f);
initSVFBasicBlock(&f);

if (!SVFUtil::isExtCall(svffun))
if (!SVFUtil::isExtCall(svffun->getCallGraphNode()))
{
initDomTree(svffun, &f);
}
Expand Down Expand Up @@ -1294,10 +1320,10 @@ void LLVMModuleSet::dumpSymTable()
SVFUtil::outs() << "}\n";
}

void LLVMModuleSet::addFunctionMap(const Function* func, CallGraphNode* svfFunc)
void LLVMModuleSet::addFunctionMap(const Function* func, CallGraphNode* node)
{
LLVMFunc2CallGraphNode[func] = svfFunc;
addToSVFVar2LLVMValueMap(func, svfFunc);
LLVMFunc2CallGraphNode[func] = node;
addToSVFVar2LLVMValueMap(func, node);
}

void LLVMModuleSet::setValueAttr(const Value* val, SVFValue* svfvalue)
Expand Down
Loading
Loading