From cbf31f124610220a4789014681f07df2b4e52c12 Mon Sep 17 00:00:00 2001 From: jumormt Date: Mon, 3 Feb 2025 13:32:30 +1100 Subject: [PATCH] remove callgraph --- svf-llvm/include/SVF-LLVM/LLVMModule.h | 13 +- svf-llvm/lib/LLVMModule.cpp | 20 +- svf-llvm/lib/SVFIRBuilder.cpp | 14 +- svf-llvm/lib/SVFIRExtAPI.cpp | 5 +- .../AE/Svfexe/AbstractInterpretation.h | 4 +- svf/include/Graphs/CallGraph.h | 266 ------------------ svf/include/Graphs/PTACallGraph.h | 10 +- svf/include/Graphs/ThreadCallGraph.h | 2 +- svf/include/SVFIR/SVFIR.h | 23 +- svf/include/SVFIR/SVFValue.h | 10 - svf/include/SVFIR/SVFVariables.h | 26 +- svf/include/Util/CallGraphBuilder.h | 2 +- svf/lib/AE/Svfexe/AbstractInterpretation.cpp | 20 +- svf/lib/DDA/ContextDDA.cpp | 2 +- svf/lib/Graphs/CallGraph.cpp | 221 --------------- svf/lib/Graphs/PTACallGraph.cpp | 50 +++- svf/lib/Graphs/ThreadCallGraph.cpp | 12 +- svf/lib/MSSA/MemRegion.cpp | 4 +- svf/lib/MSSA/MemSSA.cpp | 4 +- svf/lib/MSSA/SVFGBuilder.cpp | 4 +- svf/lib/MTA/MTAStat.cpp | 2 +- svf/lib/MTA/TCT.cpp | 4 +- svf/lib/MemoryModel/PointerAnalysis.cpp | 2 +- svf/lib/MemoryModel/PointerAnalysisImpl.cpp | 2 +- svf/lib/SABER/SaberCondAllocator.cpp | 4 +- svf/lib/SVFIR/SVFIR.cpp | 2 +- svf/lib/SVFIR/SVFVariables.cpp | 22 +- svf/lib/Util/CDGBuilder.cpp | 4 +- svf/lib/Util/CallGraphBuilder.cpp | 10 +- svf/lib/Util/SVFStat.cpp | 4 +- svf/lib/Util/SVFUtil.cpp | 10 +- svf/lib/Util/ThreadAPI.cpp | 4 +- 32 files changed, 151 insertions(+), 631 deletions(-) delete mode 100644 svf/include/Graphs/CallGraph.h delete mode 100644 svf/lib/Graphs/CallGraph.cpp diff --git a/svf-llvm/include/SVF-LLVM/LLVMModule.h b/svf-llvm/include/SVF-LLVM/LLVMModule.h index 718a442e59..e547ce4f49 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMModule.h +++ b/svf-llvm/include/SVF-LLVM/LLVMModule.h @@ -55,7 +55,6 @@ class LLVMModuleSet typedef Map GlobalDefToRepMapTy; typedef Map LLVMFun2SVFFunMap; - typedef Map LLVMFun2CallGraphNodeMap; typedef Map LLVMBB2SVFBBMap; typedef Map LLVMInst2SVFInstMap; typedef Map LLVMArgument2SVFArgumentMap; @@ -95,7 +94,6 @@ class LLVMModuleSet GlobalDefToRepMapTy GlobalDefToRepMap; LLVMFun2SVFFunMap LLVMFunc2SVFFunc; ///< Map an LLVM Function to an SVF Function - LLVMFun2CallGraphNodeMap LLVMFunc2CallGraphNode; ///< Map an LLVM Function to an CallGraph Node LLVMBB2SVFBBMap LLVMBB2SVFBB; LLVMInst2SVFInstMap LLVMInst2SVFInst; LLVMArgument2SVFArgumentMap LLVMArgument2SVFArgument; @@ -112,7 +110,7 @@ class LLVMModuleSet InstToBlockNodeMapTy InstToBlockNodeMap; ///< map a basic block to its ICFGNode FunToFunEntryNodeMapTy FunToFunEntryNodeMap; ///< map a function to its FunExitICFGNode FunToFunExitNodeMapTy FunToFunExitNodeMap; ///< map a function to its FunEntryICFGNode - CallGraph* callgraph; + PTACallGraph* callgraph; Map FunToDominatorTree; @@ -218,8 +216,6 @@ class LLVMModuleSet setValueAttr(func,svfFunc); } - void addFunctionMap(const Function* func, CallGraphNode* svfFunc); - // create a SVFBasicBlock according to LLVM BasicBlock, then add it to SVFFunction's BasicBlockGraph inline void addBasicBlock(SVFFunction* fun, const BasicBlock* bb) { @@ -296,13 +292,6 @@ class LLVMModuleSet return it->second; } - inline CallGraphNode* getCallGraphNode(const Function* fun) const - { - LLVMFun2CallGraphNodeMap::const_iterator it = LLVMFunc2CallGraphNode.find(fun); - assert(it!=LLVMFunc2CallGraphNode.end() && "SVF Function not found!"); - return it->second; - } - inline SVFFunction* getSVFFunction(const Function* fun) const { LLVMFun2SVFFunMap::const_iterator it = LLVMFunc2SVFFunc.find(fun); diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index 5c4a719ddc..a22ca6c930 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -41,7 +41,7 @@ #include "SVF-LLVM/ObjTypeInference.h" #include "llvm/Transforms/Utils/Cloning.h" #include "SVF-LLVM/ICFGBuilder.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include "Util/CallGraphBuilder.h" using namespace std; @@ -191,18 +191,6 @@ void LLVMModuleSet::build() CallGraphBuilder callGraphBuilder; callgraph = callGraphBuilder.buildSVFIRCallGraph(svfModule); - for (const auto& func : svfModule->getFunctionSet()) - { - SVFFunction* svffunc = const_cast(func); - svffunc->setCallGraphNode(callgraph->getCallGraphNode(func)); - } - - for (const auto& it : *callgraph) - { - addFunctionMap( - SVFUtil::cast(getLLVMValue(it.second->getFunction())), - it.second); - } } void LLVMModuleSet::createSVFDataStructure() @@ -1294,12 +1282,6 @@ void LLVMModuleSet::dumpSymTable() SVFUtil::outs() << "}\n"; } -void LLVMModuleSet::addFunctionMap(const Function* func, CallGraphNode* svfFunc) -{ - LLVMFunc2CallGraphNode[func] = svfFunc; - addToSVFVar2LLVMValueMap(func, svfFunc); -} - void LLVMModuleSet::setValueAttr(const Value* val, SVFValue* svfvalue) { SVFValue2LLVMValue[svfvalue] = val; diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 3c31a16224..fa8bf225bf 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -38,7 +38,7 @@ #include "SVFIR/SVFModule.h" #include "SVFIR/SVFValue.h" #include "Util/CallGraphBuilder.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include "Util/Options.h" #include "Util/SVFUtil.h" @@ -220,7 +220,7 @@ void SVFIRBuilder::initialiseNodes() if (const Function* func = SVFUtil::dyn_cast(llvmValue)) { - const CallGraphNode* cgn = llvmModuleSet()->getCallGraphNode(func); + const SVFFunction* cgn = llvmModuleSet()->getSVFFunction(func); // add value node representing the function pag->addFunValNode(iter->second, icfgNode, cgn, iter->first->getType()); } @@ -228,7 +228,7 @@ void SVFIRBuilder::initialiseNodes() { pag->addArgValNode( iter->second, argval->getArgNo(), icfgNode, - llvmModuleSet()->getCallGraphNode(argval->getParent()),iter->first->getType()); + llvmModuleSet()->getSVFFunction(argval->getParent()),iter->first->getType()); if (!argval->hasName()) pag->getGNode(iter->second)->setName("arg_" + std::to_string(argval->getArgNo())); } @@ -291,8 +291,8 @@ void SVFIRBuilder::initialiseNodes() // Check if the value is a function and add a function object node if (const Function* func = SVFUtil::dyn_cast(llvmValue)) { - NodeID id = llvmModuleSet()->getObjectNode(llvmModuleSet()->getCallGraphNode(func)->getFunction()); - pag->addFunObjNode(iter->second, pag->getObjTypeInfo(id), llvmModuleSet()->getCallGraphNode(func), iter->first->getType(), icfgNode); + NodeID id = llvmModuleSet()->getObjectNode(llvmModuleSet()->getSVFFunction(func)); + pag->addFunObjNode(iter->second, pag->getObjTypeInfo(id), llvmModuleSet()->getSVFFunction(func), iter->first->getType(), icfgNode); } // Check if the value is a heap object and add a heap object node else if (LLVMUtil::isHeapObj(llvmValue)) @@ -361,7 +361,7 @@ void SVFIRBuilder::initialiseNodes() } DBOUT(DPAGBuild, outs() << "add ret node " << iter->second << "\n"); pag->addRetNode(iter->second, - llvmModuleSet()->getCallGraphNode(SVFUtil::cast(llvmValue)), iter->first->getType(), icfgNode); + llvmModuleSet()->getSVFFunction(SVFUtil::cast(llvmValue)), iter->first->getType(), icfgNode); llvmModuleSet()->addToSVFVar2LLVMValueMap(llvmValue, pag->getGNode(iter->second)); } @@ -379,7 +379,7 @@ void SVFIRBuilder::initialiseNodes() } DBOUT(DPAGBuild, outs() << "add vararg node " << iter->second << "\n"); pag->addVarargNode(iter->second, - llvmModuleSet()->getCallGraphNode(SVFUtil::cast(llvmValue)), iter->first->getType(), icfgNode); + llvmModuleSet()->getSVFFunction(SVFUtil::cast(llvmValue)), iter->first->getType(), icfgNode); llvmModuleSet()->addToSVFVar2LLVMValueMap(llvmValue, pag->getGNode(iter->second)); } diff --git a/svf-llvm/lib/SVFIRExtAPI.cpp b/svf-llvm/lib/SVFIRExtAPI.cpp index 2141c4d0b9..35422270cf 100644 --- a/svf-llvm/lib/SVFIRExtAPI.cpp +++ b/svf-llvm/lib/SVFIRExtAPI.cpp @@ -31,7 +31,7 @@ #include "Util/SVFUtil.h" #include "SVF-LLVM/SymbolTableBuilder.h" #include "SVF-LLVM/ObjTypeInference.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace std; using namespace SVF; @@ -264,8 +264,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle const ValVar* valVar = getForkedFun(callICFGNode); if (const FunValVar* funcValVar = SVFUtil::dyn_cast(valVar)) { - const SVFFunction* forkedFun = funcValVar->getCallGraphNode()->getFunction() - ->getDefFunForMultipleModule(); + const SVFFunction* forkedFun = funcValVar->getFunction()->getDefFunForMultipleModule(); const SVFVar* actualParm = getActualParmAtForkSite(callICFGNode); /// pthread_create has 1 arg. /// apr_thread_create has 2 arg. diff --git a/svf/include/AE/Svfexe/AbstractInterpretation.h b/svf/include/AE/Svfexe/AbstractInterpretation.h index 919b981ae6..a39339fc08 100644 --- a/svf/include/AE/Svfexe/AbstractInterpretation.h +++ b/svf/include/AE/Svfexe/AbstractInterpretation.h @@ -251,8 +251,8 @@ class AbstractInterpretation AEStat* stat; std::vector callSiteStack; - Map funcToWTO; - Set recursiveFuns; + Map funcToWTO; + Set recursiveFuns; AbstractState& getAbsStateFromTrace(const ICFGNode* node) diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h deleted file mode 100644 index 25e6683b84..0000000000 --- a/svf/include/Graphs/CallGraph.h +++ /dev/null @@ -1,266 +0,0 @@ -//===- CallGraph.h -- Call graph representation----------------------------// -// -// SVF: Static Value-Flow Analysis -// -// Copyright (C) <2013-2017> -// - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -// -//===----------------------------------------------------------------------===// - -/* - * CallGraph.h - * - * Created on: Nov 7, 2013 - * Author: Yulei Sui - */ - -#ifndef CALLGRAPH_H_ -#define CALLGRAPH_H_ - -#include "Graphs/GenericGraph.h" -#include "SVFIR/SVFValue.h" -#include "Graphs/ICFG.h" -#include - -namespace SVF -{ - -class CallGraphNode; -class SVFModule; - - -/* - * Call Graph edge representing a calling relation between two functions - * Multiple calls from function A to B are merged into one call edge - * Each call edge has a set of direct callsites and a set of indirect callsites - */ -typedef GenericEdge GenericCallGraphEdgeTy; -class CallGraphEdge : public GenericCallGraphEdgeTy -{ - -public: - typedef Set CallInstSet; - -private: - CallInstSet directCalls; -public: - /// Constructor - CallGraphEdge(CallGraphNode* s, CallGraphNode* d, const CallICFGNode* icfgNode) : - GenericCallGraphEdgeTy(s, d, icfgNode->getId()) - { - } - /// Destructor - virtual ~CallGraphEdge() - { - } - - /// Add direct callsite - //@{ - void addDirectCallSite(const CallICFGNode* call); - //@} - - /// Iterators for direct and indirect callsites - //@{ - inline CallInstSet::const_iterator directCallsBegin() const - { - return directCalls.begin(); - } - inline CallInstSet::const_iterator directCallsEnd() const - { - return directCalls.end(); - } - //@} - - /// ClassOf - //@{ - static inline bool classof(const CallGraphEdge*) - { - return true; - } - //@} - - /// Overloading operator << for dumping ICFG node ID - //@{ - friend OutStream& operator<< (OutStream &o, const CallGraphEdge&edge) - { - o << edge.toString(); - return o; - } - //@} - - virtual const std::string toString() const; - - typedef GenericNode::GEdgeSetTy CallGraphEdgeSet; - -}; - -/* - * Call Graph node representing a function - */ -typedef GenericNode GenericCallGraphNodeTy; -class CallGraphNode : public GenericCallGraphNodeTy -{ -private: - const SVFFunction* fun; - -public: - /// Constructor - CallGraphNode(NodeID i, const SVFFunction* f) : GenericCallGraphNodeTy(i,CallNodeKd), fun(f) - { - } - - inline const std::string &getName() const - { - return fun->getName(); - } - - /// Get function of this call node - inline const SVFFunction* getFunction() const - { - return fun; - } - - - /// Overloading operator << for dumping ICFG node ID - //@{ - friend OutStream& operator<< (OutStream &o, const CallGraphNode&node) - { - o << node.toString(); - return o; - } - //@} - - virtual const std::string toString() const; - - /// Methods for support type inquiry through isa, cast, and dyn_cast: - //@{ - static inline bool classof(const CallGraphNode*) - { - return true; - } - - static inline bool classof(const GenericICFGNodeTy* node) - { - return node->getNodeKind() == CallNodeKd; - } - - static inline bool classof(const SVFBaseNode* node) - { - return node->getNodeKind() == CallNodeKd; - } - //@} -}; - -/*! - * Pointer Analysis Call Graph used internally for various pointer analysis - */ -typedef GenericGraph GenericCallGraphTy; -class CallGraph : public GenericCallGraphTy -{ - friend class PTACallGraph; - -public: - typedef CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet; - typedef Map FunToCallGraphNodeMap; - typedef Map CallInstToCallGraphEdgesMap; - typedef Set FunctionSet; - typedef OrderedMap CallEdgeMap; - -protected: - FunToCallGraphNodeMap funToCallGraphNodeMap; ///< Call Graph node map - CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap; ///< Map a call instruction to its corresponding call edges - - NodeID callGraphNodeNum; - - /// Clean up memory - void destroy(); - - /// Add call graph edge - inline void addEdge(CallGraphEdge* edge) - { - edge->getDstNode()->addIncomingEdge(edge); - edge->getSrcNode()->addOutgoingEdge(edge); - } - - -public: - /// Constructor - CallGraph(); - - void addCallGraphNode(const SVFFunction* fun); - - const CallGraphNode* getCallGraphNode(const std::string& name); - - /// Destructor - virtual ~CallGraph() - { - destroy(); - } - - /// Get call graph node - //@{ - inline CallGraphNode* getCallGraphNode(NodeID id) const - { - return getGNode(id); - } - inline CallGraphNode* getCallGraphNode(const SVFFunction* fun) const - { - FunToCallGraphNodeMap::const_iterator it = funToCallGraphNodeMap.find(fun); - assert(it!=funToCallGraphNodeMap.end() && "call graph node not found!!"); - return it->second; - } - - //@} - - /// Whether we have already created this call graph edge - CallGraphEdge* hasGraphEdge(CallGraphNode* src, CallGraphNode* dst, - const CallICFGNode* callIcfgNode) const; - - /// Add direct call edges - void addDirectCallGraphEdge(const CallICFGNode* call, const SVFFunction* callerFun, const SVFFunction* calleeFun); - /// Dump the graph - void dump(const std::string& filename); - - /// View the graph from the debugger - void view(); -}; - -} // End namespace SVF - -namespace SVF -{ -/* ! - * GenericGraphTraits specializations for generic graph algorithms. - * Provide graph traits for traversing from a constraint node using standard graph traversals. - */ -template<> struct GenericGraphTraits : public GenericGraphTraits* > -{ -}; - -/// Inverse GenericGraphTraits specializations for call graph node, it is used for inverse traversal. -template<> -struct GenericGraphTraits > : public GenericGraphTraits* > > -{ -}; - -template<> struct GenericGraphTraits : public GenericGraphTraits* > -{ - typedef SVF::CallGraphNode*NodeRef; -}; - -} // End namespace llvm - -#endif /* CALLGRAPH_H_ */ diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index 1cbc93351b..7d10ee582a 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -302,7 +302,7 @@ class PTACallGraph : public GenericPTACallGraphTy PTACallGraph(CGEK k = NormCallGraph); /// Copy constructor - PTACallGraph(const CallGraph& other); + PTACallGraph(const PTACallGraph& other); /// Destructor virtual ~PTACallGraph() @@ -351,8 +351,16 @@ class PTACallGraph : public GenericPTACallGraphTy /// Issue a warning if the function which has indirect call sites can not be reached from program entry. void verifyCallGraph(); + /// Add direct call edges + void addDirectCallGraphEdge(const CallICFGNode* call, const SVFFunction* callerFun, const SVFFunction* calleeFun); + + void addCallGraphNode(const SVFFunction* fun); + /// Get call graph node //@{ + + const PTACallGraphNode* getCallGraphNode(const std::string& name); + inline PTACallGraphNode* getCallGraphNode(NodeID id) const { return getGNode(id); diff --git a/svf/include/Graphs/ThreadCallGraph.h b/svf/include/Graphs/ThreadCallGraph.h index ba48e0e9c8..5bef82c2d4 100644 --- a/svf/include/Graphs/ThreadCallGraph.h +++ b/svf/include/Graphs/ThreadCallGraph.h @@ -172,7 +172,7 @@ class ThreadCallGraph: public PTACallGraph typedef Map CallInstToParForEdgesMap; /// Constructor - ThreadCallGraph(const CallGraph& cg); + ThreadCallGraph(const PTACallGraph& cg); ThreadCallGraph(ThreadCallGraph& cg) = delete; diff --git a/svf/include/SVFIR/SVFIR.h b/svf/include/SVFIR/SVFIR.h index 61d8c98c08..4fe0fed5cd 100644 --- a/svf/include/SVFIR/SVFIR.h +++ b/svf/include/SVFIR/SVFIR.h @@ -35,7 +35,6 @@ namespace SVF { class CommonCHGraph; -class CallGraph; /*! * SVF Intermediate representation, representing variables and statements as a Program Assignment Graph (PAG) * Variables as nodes and statements as edges. @@ -62,7 +61,7 @@ class SVFIR : public IRGraph typedef Map CSToArgsListMap; typedef Map CSToRetMap; typedef Map FunToRetMap; - typedef Map FunToFunObjVarMap; + typedef Map FunToFunObjVarMap; typedef Map FunToPAGEdgeSetMap; typedef Map ICFGNode2SVFStmtsMap; typedef Map NodeToNodeMap; @@ -100,7 +99,7 @@ class SVFIR : public IRGraph ICFG* icfg; // ICFG CommonCHGraph* chgraph; // class hierarchy graph CallSiteSet callSiteSet; /// all the callsites of a program - CallGraph* callGraph; /// call graph + PTACallGraph* callGraph; /// call graph static std::unique_ptr pag; ///< Singleton pattern here to enable instance of SVFIR can only be created once. @@ -187,11 +186,11 @@ class SVFIR : public IRGraph } /// Set/Get CG - inline void setCallGraph(CallGraph* c) + inline void setCallGraph(PTACallGraph* c) { callGraph = c; } - inline CallGraph* getCallGraph() + inline PTACallGraph* getCallGraph() { assert(callGraph && "empty CallGraph! Build SVF IR first!"); return callGraph; @@ -331,7 +330,7 @@ class SVFIR : public IRGraph } //@} - inline const FunObjVar* getFunObjVar(const CallGraphNode* node) const + inline const FunObjVar* getFunObjVar(const SVFFunction* node) const { FunToFunObjVarMap::const_iterator it = funToFunObjvarMap.find(node); assert(it != funToFunObjvarMap.end() && "this function doesn't have funobjvar"); @@ -547,13 +546,13 @@ class SVFIR : public IRGraph return addValNode(node); } - NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const CallGraphNode* callGraphNode, const SVFType* type) + NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const SVFFunction* callGraphNode, const SVFType* type) { FunValVar* node = new FunValVar(i, icfgNode, callGraphNode, type); return addValNode(node); } - NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode* icfgNode, const CallGraphNode* callGraphNode, const SVFType* type) + NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode* icfgNode, const SVFFunction* callGraphNode, const SVFType* type) { ArgValVar* node = new ArgValVar(i, argNo, icfgNode, callGraphNode, type); @@ -625,7 +624,7 @@ class SVFIR : public IRGraph return addObjNode(stackObj); } - NodeID addFunObjNode(NodeID id, ObjTypeInfo* ti, const CallGraphNode* callGraphNode, const SVFType* type, const ICFGNode* node) + NodeID addFunObjNode(NodeID id, ObjTypeInfo* ti, const SVFFunction* callGraphNode, const SVFType* type, const ICFGNode* node) { memToFieldsMap[id].set(id); FunObjVar* funObj = new FunObjVar(id, ti, callGraphNode, type, node); @@ -678,13 +677,13 @@ class SVFIR : public IRGraph } /// Add a unique return node for a procedure - inline NodeID addRetNode(NodeID i, const CallGraphNode* callGraphNode, const SVFType* type, const ICFGNode* icn) + inline NodeID addRetNode(NodeID i, const SVFFunction* callGraphNode, const SVFType* type, const ICFGNode* icn) { SVFVar *node = new RetValPN(i, callGraphNode, type, icn); return addRetNode(callGraphNode, node); } /// Add a unique vararg node for a procedure - inline NodeID addVarargNode(NodeID i, const CallGraphNode* val, const SVFType* type, const ICFGNode* n) + inline NodeID addVarargNode(NodeID i, const SVFFunction* val, const SVFType* type, const ICFGNode* n) { SVFVar *node = new VarArgValPN(i, val, type, n); return addNode(node); @@ -758,7 +757,7 @@ class SVFIR : public IRGraph return addNode(node); } /// Add a unique return node for a procedure - inline NodeID addRetNode(const CallGraphNode*, SVFVar *node) + inline NodeID addRetNode(const SVFFunction*, SVFVar *node) { return addNode(node); } diff --git a/svf/include/SVFIR/SVFValue.h b/svf/include/SVFIR/SVFValue.h index f14ce91d8f..2bafe5df87 100644 --- a/svf/include/SVFIR/SVFValue.h +++ b/svf/include/SVFIR/SVFValue.h @@ -320,14 +320,9 @@ class SVFFunction : public SVFValue const SVFFunction* realDefFun; /// the definition of a function across multiple modules std::vector allArgs; /// all formal arguments of this function SVFBasicBlock *exitBlock; /// a 'single' basic block having no successors and containing return instruction in a function - const CallGraphNode *callGraphNode; /// call graph node for this function BasicBlockGraph* bbGraph; /// the basic block graph of this function protected: - inline void setCallGraphNode(CallGraphNode *cgn) - { - callGraphNode = cgn; - } inline void addArgument(const ArgValVar* arg) { @@ -355,11 +350,6 @@ class SVFFunction : public SVFValue SVFFunction(void) = delete; virtual ~SVFFunction(); - inline const CallGraphNode* getCallGraphNode() const - { - return callGraphNode; - } - static inline bool classof(const SVFValue *node) { return node->getKind() == SVFFunc; diff --git a/svf/include/SVFIR/SVFVariables.h b/svf/include/SVFIR/SVFVariables.h index 3a4900c44d..67724bdd14 100644 --- a/svf/include/SVFIR/SVFVariables.h +++ b/svf/include/SVFIR/SVFVariables.h @@ -366,7 +366,7 @@ class ArgValVar: public ValVar friend class SVFIRReader; private: - const CallGraphNode* cgNode; + const SVFFunction* cgNode; u32_t argNo; protected: @@ -399,7 +399,7 @@ class ArgValVar: public ValVar //@} /// Constructor - ArgValVar(NodeID i, u32_t argNo, const ICFGNode* icn, const CallGraphNode* callGraphNode, + ArgValVar(NodeID i, u32_t argNo, const ICFGNode* icn, const SVFFunction* callGraphNode, const SVFType* svfType); /// Return name of a LLVM value @@ -968,7 +968,7 @@ class FunValVar : public ValVar friend class SVFIRWriter; friend class SVFIRReader; private: - const CallGraphNode* callGraphNode; + const SVFFunction* callGraphNode; public: /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -995,13 +995,13 @@ class FunValVar : public ValVar } //@} - inline const CallGraphNode* getCallGraphNode() const + inline virtual const SVFFunction* getFunction() const { return callGraphNode; } /// Constructor - FunValVar(NodeID i, const ICFGNode* icn, const CallGraphNode* cgn, const SVFType* svfType); + FunValVar(NodeID i, const ICFGNode* icn, const SVFFunction* cgn, const SVFType* svfType); virtual bool isPointer() const @@ -1018,7 +1018,7 @@ class FunObjVar : public BaseObjVar friend class SVFIRReader; private: - const CallGraphNode* callGraphNode; + const SVFFunction* callGraphNode; private: /// Constructor to create empty ObjVar (for SVFIRReader/deserialization) @@ -1054,9 +1054,9 @@ class FunObjVar : public BaseObjVar //@} /// Constructor - FunObjVar(NodeID i, ObjTypeInfo* ti, const CallGraphNode* cgNode, const SVFType* svfType, const ICFGNode* node); + FunObjVar(NodeID i, ObjTypeInfo* ti, const SVFFunction* cgNode, const SVFType* svfType, const ICFGNode* node); - inline const CallGraphNode* getCallGraphNode() const + inline const SVFFunction* getCallGraphNode() const { return callGraphNode; } @@ -1782,7 +1782,7 @@ class RetValPN : public ValVar friend class SVFIRReader; private: - const CallGraphNode* callGraphNode; + const SVFFunction* callGraphNode; private: /// Constructor to create empty RetValPN (for SVFIRReader/deserialization) RetValPN(NodeID i) : ValVar(i, RetValNode) {} @@ -1813,9 +1813,9 @@ class RetValPN : public ValVar /// Constructor - RetValPN(NodeID i, const CallGraphNode* node, const SVFType* svfType, const ICFGNode* icn); + RetValPN(NodeID i, const SVFFunction* node, const SVFType* svfType, const ICFGNode* icn); - inline const CallGraphNode* getCallGraphNode() const + inline const SVFFunction* getCallGraphNode() const { return callGraphNode; } @@ -1838,7 +1838,7 @@ class VarArgValPN : public ValVar friend class SVFIRWriter; friend class SVFIRReader; private: - const CallGraphNode* callGraphNode; + const SVFFunction* callGraphNode; private: /// Constructor to create empty VarArgValPN (for SVFIRReader/deserialization) @@ -1869,7 +1869,7 @@ class VarArgValPN : public ValVar //@} /// Constructor - VarArgValPN(NodeID i, const CallGraphNode* node, const SVFType* svfType, const ICFGNode* icn) + VarArgValPN(NodeID i, const SVFFunction* node, const SVFType* svfType, const ICFGNode* icn) : ValVar(i, svfType, icn, VarargValNode), callGraphNode(node) { } diff --git a/svf/include/Util/CallGraphBuilder.h b/svf/include/Util/CallGraphBuilder.h index 337d30e223..c1924aa92d 100644 --- a/svf/include/Util/CallGraphBuilder.h +++ b/svf/include/Util/CallGraphBuilder.h @@ -47,7 +47,7 @@ class CallGraphBuilder CallGraphBuilder()=default; /// Buidl SVFIR callgraoh - CallGraph* buildSVFIRCallGraph(SVFModule* svfModule); + PTACallGraph* buildSVFIRCallGraph(SVFModule* svfModule); /// Buidl PTA callgraoh PTACallGraph* buildPTACallGraph(); diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index c047095a37..7d6f975576 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -30,7 +30,7 @@ #include "SVFIR/SVFIR.h" #include "Util/Options.h" #include "Util/WorkList.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include using namespace SVF; @@ -84,19 +84,19 @@ void AbstractInterpretation::initWTO() // Detect if the call graph has cycles by finding its strongly connected components (SCC) Andersen::CallGraphSCC* callGraphScc = ander->getCallGraphSCC(); callGraphScc->find(); - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); // Iterate through the call graph for (auto it = svfirCallGraph->begin(); it != svfirCallGraph->end(); it++) { // Check if the current function is part of a cycle if (callGraphScc->isInCycle(it->second->getId())) - recursiveFuns.insert(it->second); // Mark the function as recursive + recursiveFuns.insert(it->second->getFunction()); // Mark the function as recursive if (it->second->getFunction()->isDeclaration()) continue; auto* wto = new ICFGWTO(icfg, icfg->getFunEntryICFGNode(it->second->getFunction())); wto->init(); - funcToWTO[it->second] = wto; + funcToWTO[it->second->getFunction()] = wto; } } /// Program entry @@ -107,9 +107,9 @@ void AbstractInterpretation::analyse() handleGlobalNode(); getAbsStateFromTrace( icfg->getGlobalICFGNode())[PAG::getPAG()->getBlkPtr()] = IntervalValue::top(); - if (const CallGraphNode* cgn = svfir->getCallGraph()->getCallGraphNode("main")) + if (const PTACallGraphNode* cgn = svfir->getCallGraph()->getCallGraphNode("main")) { - ICFGWTO* wto = funcToWTO[cgn]; + ICFGWTO* wto = funcToWTO[cgn->getFunction()]; handleWTOComponents(wto->getWTOComponents()); } } @@ -585,7 +585,7 @@ bool AbstractInterpretation::isRecursiveCall(const SVF::CallICFGNode *callNode) if (!callfun) return false; else - return recursiveFuns.find(callfun->getCallGraphNode()) != recursiveFuns.end(); + return recursiveFuns.find(callfun) != recursiveFuns.end(); } void AbstractInterpretation::recursiveCallPass(const SVF::CallICFGNode *callNode) @@ -613,7 +613,7 @@ bool AbstractInterpretation::isDirectCall(const SVF::CallICFGNode *callNode) if (!callfun) return false; else - return funcToWTO.find(callfun->getCallGraphNode()) != funcToWTO.end(); + return funcToWTO.find(callfun) != funcToWTO.end(); } void AbstractInterpretation::directCallFunPass(const SVF::CallICFGNode *callNode) { @@ -623,7 +623,7 @@ void AbstractInterpretation::directCallFunPass(const SVF::CallICFGNode *callNode abstractTrace[callNode] = as; const SVFFunction *callfun =callNode->getCalledFunction(); - ICFGWTO* wto = funcToWTO[callfun->getCallGraphNode()]; + ICFGWTO* wto = funcToWTO[callfun]; handleWTOComponents(wto->getWTOComponents()); callSiteStack.pop_back(); @@ -653,7 +653,7 @@ void AbstractInterpretation::indirectCallFunPass(const SVF::CallICFGNode *callNo SVFVar *func_var = svfir->getGNode(AbstractState::getInternalID(addr)); if(const FunObjVar*funObjVar = SVFUtil::dyn_cast(func_var)) { - const CallGraphNode* callfun = funObjVar->getCallGraphNode(); + const SVFFunction* callfun = funObjVar->getFunction(); callSiteStack.push_back(callNode); abstractTrace[callNode] = as; diff --git a/svf/lib/DDA/ContextDDA.cpp b/svf/lib/DDA/ContextDDA.cpp index 5497c7ecb4..ddabf5a350 100644 --- a/svf/lib/DDA/ContextDDA.cpp +++ b/svf/lib/DDA/ContextDDA.cpp @@ -195,7 +195,7 @@ bool ContextDDA::testIndCallReachability(CxtLocDPItem& dpm, const SVFFunction* c CxtVar funptrVar(dpm.getCondVar().get_cond(), id); CxtLocDPItem funptrDpm = getDPIm(funptrVar,getDefSVFGNode(node)); PointsTo pts = getBVPointsTo(findPT(funptrDpm)); - if(pts.test(getPAG()->getFunObjVar(callee->getCallGraphNode())->getId())) + if(pts.test(getPAG()->getFunObjVar(callee)->getId())) return true; else return false; diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp deleted file mode 100644 index 00ca4d54ee..0000000000 --- a/svf/lib/Graphs/CallGraph.cpp +++ /dev/null @@ -1,221 +0,0 @@ -//===- CallGraph.cpp -- Call graph used internally in SVF------------------// -// -// SVF: Static Value-Flow Analysis -// -// Copyright (C) <2013-2017> -// - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -// -//===----------------------------------------------------------------------===// - - -/* - * CallGraph.cpp - * - * Created on: Nov 7, 2013 - * Author: Yulei Sui - */ - -#include "Graphs/CallGraph.h" -#include "SVFIR/SVFIR.h" -#include "SVFIR/SVFModule.h" -#include "Util/SVFUtil.h" -#include - -using namespace SVF; -using namespace SVFUtil; - - -/// Add direct callsite -//@{ -void CallGraphEdge::addDirectCallSite(const CallICFGNode* call) -{ - assert(call->getCalledFunction() && "not a direct callsite??"); - directCalls.insert(call); -} -//@} - -const std::string CallGraphEdge::toString() const -{ - std::string str; - std::stringstream rawstr(str); - rawstr << "CallICFGNode ID: " << getEdgeKindWithoutMask(); - rawstr << "direct call"; - rawstr << "[" << getDstID() << "<--" << getSrcID() << "]\t"; - return rawstr.str(); -} - -const std::string CallGraphNode::toString() const -{ - std::string str; - std::stringstream rawstr(str); - rawstr << "CallGraphNode ID: " << getId() << " {fun: " << fun->getName() << "}"; - return rawstr.str(); -} - - -/// Constructor -CallGraph::CallGraph() -{ - callGraphNodeNum = 0; -} - - -/*! - * Memory has been cleaned up at GenericGraph - */ -void CallGraph::destroy() -{ -} - -/*! - * Add call graph node - */ -void CallGraph::addCallGraphNode(const SVFFunction* fun) -{ - NodeID id = callGraphNodeNum; - CallGraphNode*callGraphNode = new CallGraphNode(id, fun); - addGNode(id, callGraphNode); - funToCallGraphNodeMap[callGraphNode->getFunction()] = callGraphNode; - callGraphNodeNum++; -} - -/*! - * Whether we have already created this call graph edge - */ -CallGraphEdge* CallGraph::hasGraphEdge(CallGraphNode* src, - CallGraphNode* dst, - const CallICFGNode* callIcfgNode) const -{ - CallGraphEdge edge(src,dst,callIcfgNode); - CallGraphEdge* outEdge = src->hasOutgoingEdge(&edge); - CallGraphEdge* inEdge = dst->hasIncomingEdge(&edge); - if (outEdge && inEdge) - { - assert(outEdge == inEdge && "edges not match"); - return outEdge; - } - else - return nullptr; -} - -/*! - * Add direct call edges - */ -void CallGraph::addDirectCallGraphEdge(const CallICFGNode* cs,const SVFFunction* callerFun, const SVFFunction* calleeFun) -{ - - CallGraphNode* caller = getCallGraphNode(callerFun); - CallGraphNode* callee = getCallGraphNode(calleeFun); - - - if(!hasGraphEdge(caller,callee, cs)) - { - CallGraphEdge* edge = new CallGraphEdge(caller,callee, cs); - edge->addDirectCallSite(cs); - addEdge(edge); - callinstToCallGraphEdgesMap[cs].insert(edge); - } -} - -/*! - * Dump call graph into dot file - */ -void CallGraph::dump(const std::string& filename) -{ - GraphPrinter::WriteGraphToFile(outs(), filename, this); -} - -void CallGraph::view() -{ - SVF::ViewGraph(this, "Call Graph"); -} - -const CallGraphNode* CallGraph::getCallGraphNode(const std::string& name) -{ - for (const auto& item : *this) - { - if (item.second->getName() == name) - return item.second; - } - return nullptr; -} - -namespace SVF -{ - -/*! - * Write value flow graph into dot file for debugging - */ -template<> -struct DOTGraphTraits : public DefaultDOTGraphTraits -{ - - typedef CallGraphNode NodeType; - typedef NodeType::iterator ChildIteratorType; - DOTGraphTraits(bool isSimple = false) : - DefaultDOTGraphTraits(isSimple) - { - } - - /// Return name of the graph - static std::string getGraphName(CallGraph*) - { - return "Call Graph"; - } - /// Return function name; - static std::string getNodeLabel(CallGraphNode*node, CallGraph*) - { - return node->toString(); - } - - static std::string getNodeAttributes(CallGraphNode*node, CallGraph*) - { - const SVFFunction* fun = node->getFunction(); - if (!SVFUtil::isExtCall(fun)) - { - return "shape=box"; - } - else - return "shape=Mrecord"; - } - - template - static std::string getEdgeAttributes(CallGraphNode*, EdgeIter EI, - CallGraph*) - { - - //TODO: mark indirect call of Fork with different color - CallGraphEdge* edge = *(EI.getCurrent()); - assert(edge && "No edge found!!"); - - std::string color = "color=black"; - return color; - } - - template - static std::string getEdgeSourceLabel(NodeType*, EdgeIter EI) - { - CallGraphEdge* edge = *(EI.getCurrent()); - assert(edge && "No edge found!!"); - - std::string str; - std::stringstream rawstr(str); - rawstr << edge->getEdgeKindWithoutMask(); - - return rawstr.str(); - } -}; -} // End namespace llvm diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index 7d24d7644e..8a1524349a 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -29,7 +29,7 @@ */ #include "Graphs/PTACallGraph.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include "SVFIR/SVFIR.h" #include "SVFIR/SVFModule.h" #include "Util/SVFUtil.h" @@ -114,7 +114,7 @@ PTACallGraph::PTACallGraph(CGEK k): kind(k) } /// Copy constructor -PTACallGraph::PTACallGraph(const CallGraph& other) +PTACallGraph::PTACallGraph(const PTACallGraph& other) { callGraphNodeNum = other.getTotalNodeNum(); numOfResolvedIndCallEdge = 0; @@ -123,7 +123,7 @@ PTACallGraph::PTACallGraph(const CallGraph& other) /// copy call graph nodes for (const auto& item : other) { - const CallGraphNode* cgn = item.second; + const PTACallGraphNode* cgn = item.second; PTACallGraphNode* callGraphNode = new PTACallGraphNode(cgn->getId(), cgn->getFunction()); addGNode(cgn->getId(),callGraphNode); funToCallGraphNodeMap[cgn->getFunction()] = callGraphNode; @@ -133,7 +133,7 @@ PTACallGraph::PTACallGraph(const CallGraph& other) for (const auto& item : other.callinstToCallGraphEdgesMap) { const CallICFGNode* cs = item.first; - for (const CallGraphEdge* edge : item.second) + for (const PTACallGraphEdge* edge : item.second) { PTACallGraphNode* src = getCallGraphNode(edge->getSrcID()); PTACallGraphNode* dst = getCallGraphNode(edge->getDstID()); @@ -334,6 +334,48 @@ void PTACallGraph::view() SVF::ViewGraph(this, "Call Graph"); } + +/*! + * Add call graph node + */ +void PTACallGraph::addCallGraphNode(const SVFFunction* fun) +{ + NodeID id = callGraphNodeNum; + PTACallGraphNode*callGraphNode = new PTACallGraphNode(id, fun); + addGNode(id, callGraphNode); + funToCallGraphNodeMap[callGraphNode->getFunction()] = callGraphNode; + callGraphNodeNum++; +} + +const PTACallGraphNode* PTACallGraph::getCallGraphNode(const std::string& name) +{ + for (const auto& item : *this) + { + if (item.second->getName() == name) + return item.second; + } + return nullptr; +} + +/*! + * Add direct call edges + */ +void PTACallGraph::addDirectCallGraphEdge(const CallICFGNode* cs,const SVFFunction* callerFun, const SVFFunction* calleeFun) +{ + + PTACallGraphNode* caller = getCallGraphNode(callerFun); + PTACallGraphNode* callee = getCallGraphNode(calleeFun); + CallSiteID csId = addCallSite(cs, calleeFun); + + if(!hasGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge, csId)) + { + PTACallGraphEdge* edge = new PTACallGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge, csId); + edge->addDirectCallSite(cs); + addEdge(edge); + callinstToCallGraphEdgesMap[cs].insert(edge); + } +} + namespace SVF { diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 0d5d6848e3..0ecf824cb1 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -32,7 +32,7 @@ #include "Util/ThreadAPI.h" #include "SVFIR/SVFIR.h" #include "MemoryModel/PointerAnalysisImpl.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -40,7 +40,7 @@ using namespace SVFUtil; /*! * Constructor */ -ThreadCallGraph::ThreadCallGraph(const CallGraph& cg) : +ThreadCallGraph::ThreadCallGraph(const PTACallGraph& cg) : PTACallGraph(cg), tdAPI(ThreadAPI::getThreadAPI()) { kind = ThdCallGraph; @@ -127,8 +127,8 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) { PTACallGraphNode* caller = getCallGraphNode(cs->getCaller()); - const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)) - ->getCallGraphNode()->getFunction(); + const FunValVar* funValvar = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)); + const SVFFunction* forkee = funValvar->getFunction(); assert(forkee && "callee does not exist"); PTACallGraphNode* callee = getCallGraphNode(forkee->getDefFunForMultipleModule()); CallSiteID csId = addCallSite(cs, callee->getFunction()); @@ -188,9 +188,7 @@ void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet { const SVFFunction* threadRoutineFun = - SVFUtil::dyn_cast(tdAPI->getForkedFun(*it)) - ->getCallGraphNode() - ->getFunction(); + SVFUtil::dyn_cast(tdAPI->getForkedFun(*it))->getFunction(); assert(threadRoutineFun && "thread routine function does not exist"); PTACallGraphNode* threadRoutineFunNode = getCallGraphNode(threadRoutineFun); CallSiteID csId = addCallSite(cs, threadRoutineFun); diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index 1fd173a0c2..6be9a4c36b 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -31,7 +31,7 @@ #include "SVFIR/SVFModule.h" #include "MSSA/MemRegion.h" #include "MSSA/MSSAMuChi.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -174,7 +174,7 @@ SVFIR::SVFStmtList& MRGenerator::getPAGEdgesFromInst(const ICFGNode* node) void MRGenerator::collectModRefForLoadStore() { - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { const SVFFunction& fun = *item.second->getFunction(); diff --git a/svf/lib/MSSA/MemSSA.cpp b/svf/lib/MSSA/MemSSA.cpp index 6e189ad22b..d82be1dddc 100644 --- a/svf/lib/MSSA/MemSSA.cpp +++ b/svf/lib/MSSA/MemSSA.cpp @@ -31,7 +31,7 @@ #include "MSSA/MemPartition.h" #include "MSSA/MemSSA.h" #include "Graphs/SVFGStat.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -576,7 +576,7 @@ u32_t MemSSA::getBBPhiNum() const void MemSSA::dumpMSSA(OutStream& Out) { - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { const SVFFunction* fun = item.second->getFunction(); diff --git a/svf/lib/MSSA/SVFGBuilder.cpp b/svf/lib/MSSA/SVFGBuilder.cpp index 95a181f3c8..c38aa4e366 100644 --- a/svf/lib/MSSA/SVFGBuilder.cpp +++ b/svf/lib/MSSA/SVFGBuilder.cpp @@ -33,7 +33,7 @@ #include "Graphs/SVFG.h" #include "MSSA/SVFGBuilder.h" #include "WPA/Andersen.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; @@ -103,7 +103,7 @@ std::unique_ptr SVFGBuilder::buildMSSA(BVDataPTAImpl* pta, bool ptrOnlyM auto mssa = std::make_unique(pta, ptrOnlyMSSA); - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { diff --git a/svf/lib/MTA/MTAStat.cpp b/svf/lib/MTA/MTAStat.cpp index a5c1b98491..51f07ae3de 100644 --- a/svf/lib/MTA/MTAStat.cpp +++ b/svf/lib/MTA/MTAStat.cpp @@ -33,7 +33,7 @@ #include "MTA/MHP.h" #include "MTA/LockAnalysis.h" #include "Graphs/ThreadCallGraph.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index 752654176e..4911dfd33c 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -31,7 +31,7 @@ #include "Util/Options.h" #include "MTA/TCT.h" #include "MTA/MTA.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include @@ -186,7 +186,7 @@ void TCT::markRelProcs(const SVFFunction* svffun) */ void TCT::collectEntryFunInCallGraph() { - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { const SVFFunction* fun = item.second->getFunction(); diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 6aa63096f1..8243ca8b5b 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -36,7 +36,7 @@ #include "Util/PTAStat.h" #include "Graphs/ThreadCallGraph.h" #include "Graphs/ICFG.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include "Util/CallGraphBuilder.h" #include diff --git a/svf/lib/MemoryModel/PointerAnalysisImpl.cpp b/svf/lib/MemoryModel/PointerAnalysisImpl.cpp index 0bb93092ea..fdaf23c84d 100644 --- a/svf/lib/MemoryModel/PointerAnalysisImpl.cpp +++ b/svf/lib/MemoryModel/PointerAnalysisImpl.cpp @@ -34,7 +34,7 @@ #include #include -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace SVFUtil; diff --git a/svf/lib/SABER/SaberCondAllocator.cpp b/svf/lib/SABER/SaberCondAllocator.cpp index 6a36a74ee2..0bd7e414fc 100644 --- a/svf/lib/SABER/SaberCondAllocator.cpp +++ b/svf/lib/SABER/SaberCondAllocator.cpp @@ -35,7 +35,7 @@ #include #include #include "SVFIR/SVFStatements.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -60,7 +60,7 @@ void SaberCondAllocator::allocate(const SVFModule *M) { DBOUT(DGENERAL, outs() << pasMsg("path condition allocation starts\n")); - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { const SVFFunction *func = (item.second)->getFunction(); diff --git a/svf/lib/SVFIR/SVFIR.cpp b/svf/lib/SVFIR/SVFIR.cpp index 057af188e4..df0cb07643 100644 --- a/svf/lib/SVFIR/SVFIR.cpp +++ b/svf/lib/SVFIR/SVFIR.cpp @@ -29,7 +29,7 @@ #include "Util/Options.h" #include "SVFIR/SVFIR.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace SVFUtil; diff --git a/svf/lib/SVFIR/SVFVariables.cpp b/svf/lib/SVFIR/SVFVariables.cpp index 219e771b66..8b7a8fe311 100644 --- a/svf/lib/SVFIR/SVFVariables.cpp +++ b/svf/lib/SVFIR/SVFVariables.cpp @@ -30,7 +30,7 @@ #include "SVFIR/SVFVariables.h" #include "Util/Options.h" #include "Util/SVFUtil.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -102,7 +102,7 @@ const std::string ObjVar::toString() const } ArgValVar::ArgValVar(NodeID i, u32_t argNo, const ICFGNode* icn, - const SVF::CallGraphNode* callGraphNode, const SVFType* svfType) + const SVF::SVFFunction* callGraphNode, const SVFType* svfType) : ValVar(i, svfType, icn, ArgValNode), cgNode(callGraphNode), argNo(argNo) { @@ -116,12 +116,12 @@ const SVFFunction* ArgValVar::getFunction() const const SVFFunction* ArgValVar::getParent() const { - return cgNode->getFunction(); + return cgNode; } bool ArgValVar::isPointer() const { - return cgNode->getFunction()->getArg(argNo)->getType()->isPointerTy(); + return cgNode->getArg(argNo)->getType()->isPointerTy(); } const std::string ArgValVar::toString() const @@ -157,14 +157,14 @@ const std::string GepValVar::toString() const return rawstr.str(); } -RetValPN::RetValPN(NodeID i, const CallGraphNode* node, const SVFType* svfType, const ICFGNode* icn) +RetValPN::RetValPN(NodeID i, const SVFFunction* node, const SVFType* svfType, const ICFGNode* icn) : ValVar(i, svfType, icn, RetValNode), callGraphNode(node) { } const SVFFunction* RetValPN::getFunction() const { - return callGraphNode->getFunction(); + return callGraphNode; } bool RetValPN::isPointer() const @@ -250,7 +250,7 @@ const std::string StackObjVar::toString() const -FunValVar::FunValVar(NodeID i, const ICFGNode* icn, const CallGraphNode* cgn, const SVFType* svfType) +FunValVar::FunValVar(NodeID i, const ICFGNode* icn, const SVFFunction* cgn, const SVFType* svfType) : ValVar(i, svfType, icn, FunValNode), callGraphNode(cgn) { } @@ -421,7 +421,7 @@ const std::string ConstNullPtrObjVar::toString() const return rawstr.str(); } -FunObjVar::FunObjVar(NodeID i, ObjTypeInfo* ti, const CallGraphNode* cgNode, const SVFType* svfType, const ICFGNode* node) +FunObjVar::FunObjVar(NodeID i, ObjTypeInfo* ti, const SVFFunction* cgNode, const SVFType* svfType, const ICFGNode* node) : BaseObjVar(i, ti, svfType, node, FunObjNode), callGraphNode(cgNode) { } @@ -433,12 +433,12 @@ bool FunObjVar::isPointer() const bool FunObjVar::isIsolatedNode() const { - return callGraphNode->getFunction()->isIntrinsic(); + return callGraphNode->isIntrinsic(); } const SVFFunction* FunObjVar::getFunction() const { - return callGraphNode->getFunction(); + return callGraphNode; } const std::string FunObjVar::toString() const @@ -464,7 +464,7 @@ const std::string RetValPN::toString() const const SVFFunction* VarArgValPN::getFunction() const { - return callGraphNode->getFunction(); + return callGraphNode; } const std::string VarArgValPN::getValueName() const diff --git a/svf/lib/Util/CDGBuilder.cpp b/svf/lib/Util/CDGBuilder.cpp index 96c5b78b62..dd3991a8c5 100644 --- a/svf/lib/Util/CDGBuilder.cpp +++ b/svf/lib/Util/CDGBuilder.cpp @@ -27,7 +27,7 @@ * Author: Xiao Cheng */ #include "Util/CDGBuilder.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -123,7 +123,7 @@ s64_t CDGBuilder::getBBSuccessorBranchID(const SVFBasicBlock *BB, const SVFBasic */ void CDGBuilder::buildControlDependence(const SVFModule *svfgModule) { - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { const SVFFunction *svfFun = (item.second)->getFunction(); diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index 5bda6882b8..76caa49dcc 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -32,15 +32,15 @@ #include "Util/CallGraphBuilder.h" #include "Graphs/ICFG.h" #include "SVFIR/SVFIR.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include "Graphs/ThreadCallGraph.h" using namespace SVF; using namespace SVFUtil; -CallGraph* CallGraphBuilder::buildSVFIRCallGraph(SVFModule* svfModule) +PTACallGraph* CallGraphBuilder::buildSVFIRCallGraph(SVFModule* svfModule) { - CallGraph* callgraph = new CallGraph(); + PTACallGraph* callgraph = new PTACallGraph(); for (const SVFFunction* svfFunc: svfModule->getFunctionSet()) { callgraph->addCallGraphNode(svfFunc); @@ -69,13 +69,13 @@ CallGraph* CallGraphBuilder::buildSVFIRCallGraph(SVFModule* svfModule) PTACallGraph* CallGraphBuilder::buildPTACallGraph() { - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); return new PTACallGraph(*svfirCallGraph); } ThreadCallGraph* CallGraphBuilder::buildThreadCallGraph() { - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); ThreadCallGraph* cg = new ThreadCallGraph(*svfirCallGraph); ThreadAPI* tdAPI = ThreadAPI::getThreadAPI(); diff --git a/svf/lib/Util/SVFStat.cpp b/svf/lib/Util/SVFStat.cpp index cc9aa3d128..a351ec415d 100644 --- a/svf/lib/Util/SVFStat.cpp +++ b/svf/lib/Util/SVFStat.cpp @@ -29,7 +29,7 @@ #include "Util/Options.h" #include "Util/SVFStat.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" using namespace SVF; using namespace std; @@ -223,7 +223,7 @@ void SVFStat::branchStat() { u32_t numOfBB_2Succ = 0; u32_t numOfBB_3Succ = 0; - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { const SVFFunction* func = item.second->getFunction(); diff --git a/svf/lib/Util/SVFUtil.cpp b/svf/lib/Util/SVFUtil.cpp index 76d6c2ade8..e1ac5a38f8 100644 --- a/svf/lib/Util/SVFUtil.cpp +++ b/svf/lib/Util/SVFUtil.cpp @@ -30,7 +30,7 @@ #include "Util/Options.h" #include "Util/SVFUtil.h" #include "MemoryModel/PointsTo.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include /// increase stack size @@ -388,10 +388,10 @@ bool SVFUtil::isProgExitCall(const CallICFGNode* cs) /// Get program entry function from module. const SVFFunction* SVFUtil::getProgFunction(const std::string& funName) { - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - const CallGraphNode*fun = item.second; + const PTACallGraphNode*fun = item.second; if (fun->getName()==funName) return fun->getFunction(); } @@ -401,10 +401,10 @@ const SVFFunction* SVFUtil::getProgFunction(const std::string& funName) /// Get program entry function from module. const SVFFunction* SVFUtil::getProgEntryFunction() { - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - const CallGraphNode*fun = item.second; + const PTACallGraphNode*fun = item.second; if (isProgEntryFunction(fun->getFunction())) return (fun->getFunction()); } diff --git a/svf/lib/Util/ThreadAPI.cpp b/svf/lib/Util/ThreadAPI.cpp index a1fcae3c93..9b9677cebc 100644 --- a/svf/lib/Util/ThreadAPI.cpp +++ b/svf/lib/Util/ThreadAPI.cpp @@ -32,7 +32,7 @@ #include "Util/ThreadAPI.h" #include "Util/SVFUtil.h" -#include "Graphs/CallGraph.h" +#include "Graphs/PTACallGraph.h" #include "SVFIR/SVFIR.h" #include /// std output @@ -270,7 +270,7 @@ void ThreadAPI::performAPIStat(SVFModule* module) statInit(tdAPIStatMap); - CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); + PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { for (SVFFunction::const_iterator bit = (item.second)->getFunction()->begin(), ebit = (item.second)->getFunction()->end(); bit != ebit; ++bit)