Skip to content
Open
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion svf-llvm/include/SVF-LLVM/ICFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class ICFGBuilder
inline void addGlobalICFGNode()
{
icfg->globalBlockNode = new GlobalICFGNode(icfg->totalICFGNode++);
icfg->addICFGNode(icfg->globalBlockNode);
icfg->addGlobalICFGNode(icfg->globalBlockNode);
}

private:
Expand Down
4 changes: 3 additions & 1 deletion svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,9 @@ const Value* SVFIRBuilder::getBaseValueForExtArg(const Value* V)
void SVFIRBuilder::handleIndCall(CallBase* cs)
{
const CallICFGNode* cbn = llvmModuleSet()->getCallICFGNode(cs);
pag->addIndirectCallsites(cbn,llvmModuleSet()->getValueNode(cs->getCalledOperand()));
NodeID indFunPtrId = llvmModuleSet()->getValueNode(cs->getCalledOperand());
const_cast<CallICFGNode*>(cbn)->setIndFunPtr(pag->getGNode(indFunPtrId));
pag->addIndirectCallsites(cbn,indFunPtrId);
}

void SVFIRBuilder::updateCallGraph(CallGraph* callgraph)
Expand Down
6 changes: 4 additions & 2 deletions svf-llvm/tools/WPA/wpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ int main(int argc, char** argv)
// Refers to content of a singleton unique_ptr<SVFIR> in SVFIR.
SVFIR* pag;

if (Options::ReadJson())
if (Options::ReadFromDB())
{
assert(false && "please implement SVFIRReader::read");
SVFIRBuilder builder;
pag = builder.build();
pag->setPagFromTXT("ReadFromDB");
}
else
{
Expand Down
18 changes: 16 additions & 2 deletions svf/include/Graphs/BasicBlockG.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy
friend class FunObjVar;
friend class ICFGBuilder;
friend class ICFG;
friend class GraphDBClient;

public:
typedef std::vector<const ICFGNode*>::const_iterator const_iterator;
Expand Down Expand Up @@ -282,6 +283,16 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy

const std::string toString() const;

const std::vector<const SVFBasicBlock*> getSuccBBs() const
{
return succBBs;
}

const std::vector<const SVFBasicBlock*> getPredBBs() const
{
return predBBs;
}

};


Expand All @@ -293,20 +304,23 @@ class BasicBlockGraph: public GenericBasicBlockGraphTy
NodeID id{0};
public:
/// Constructor
BasicBlockGraph()
BasicBlockGraph(): GenericBasicBlockGraphTy()
{

}


SVFBasicBlock* addBasicBlock(const std::string& bbname)
{
id++;
SVFBasicBlock* bb = new SVFBasicBlock(id, nullptr);
addGNode(id, bb);
bb->setName(bbname);
addBasicBlock(bb);
return bb;
}

void addBasicBlock(SVFBasicBlock* bb);

};
}

Expand Down
11 changes: 11 additions & 0 deletions svf/include/Graphs/CHG.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class CHEdge: public GenericCHEdgeTy
typedef GenericNode<CHNode, CHEdge> GenericCHNodeTy;
class CHNode: public GenericCHNodeTy
{
friend class GraphDBClient;

public:
typedef enum
Expand Down Expand Up @@ -222,6 +223,16 @@ class CHNode: public GenericCHNodeTy
* virtualFunctionVectors = {{Af1, Af2, ...}, {Bg1, Bg2, ...}}
*/
std::vector<FuncVector> virtualFunctionVectors;

protected:
inline size_t getFlags() const
{
return flags;
}
inline void setFlags(size_t f)
{
flags = f;
}
};

/// class hierarchy graph
Expand Down
28 changes: 26 additions & 2 deletions svf/include/Graphs/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ class CallGraphNode : public GenericPTACallGraphNodeTy
{
return node->getNodeKind() == CallNodeKd;
}

std::string sourceLocToDBString() const
{
std::string sourceLoc = "";
if (!getSourceLoc().empty())
{
sourceLoc = ", source_loc: '" + getSourceLoc() + "'";
}
else
{
sourceLoc = ", source_loc: ''";
}
return sourceLoc;
}
//@}
};

Expand All @@ -233,6 +247,8 @@ class CallGraphNode : public GenericPTACallGraphNodeTy
typedef GenericGraph<CallGraphNode, CallGraphEdge> GenericPTACallGraphTy;
class CallGraph : public GenericPTACallGraphTy
{
friend class GraphDBClient;


public:
typedef CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet;
Expand Down Expand Up @@ -281,20 +297,23 @@ class CallGraph : public GenericPTACallGraphTy
if(it == csToIdMap.end())
{
CallSiteID id = totalCallSiteNum++;
csToIdMap.insert(std::make_pair(newCS, id));
idToCSMap.insert(std::make_pair(id, newCS));
addCallSite(cs,callee,id);
return id;
}
return it->second;
}

CallSiteID addCallSite(const CallICFGNode* cs, const FunObjVar* callee, const CallSiteID csid);

/// Add call graph edge
inline void addEdge(CallGraphEdge* edge)
{
edge->getDstNode()->addIncomingEdge(edge);
edge->getSrcNode()->addOutgoingEdge(edge);
}

/// add direct call graph edge from database [only used this function when loading cgEdges from db results]
void addDirectCallGraphEdge(CallGraphEdge* cgEdge);
public:
/// Constructor
CallGraph(CGEK k = NormCallGraph);
Expand Down Expand Up @@ -354,6 +373,8 @@ class CallGraph : public GenericPTACallGraphTy

void addCallGraphNode(const FunObjVar* fun);

void addCallGraphNode(CallGraphNode* cgNode);

/// Get call graph node
//@{

Expand Down Expand Up @@ -406,6 +427,8 @@ class CallGraph : public GenericPTACallGraphTy
/// Whether we have already created this call graph edge
CallGraphEdge* hasGraphEdge(CallGraphNode* src, CallGraphNode* dst,
CallGraphEdge::CEDGEK kind, CallSiteID csId) const;

CallGraphEdge* hasGraphEdge(CallGraphEdge* cgEdge) const;
/// Get call graph edge via nodes
CallGraphEdge* getGraphEdge(CallGraphNode* src, CallGraphNode* dst,
CallGraphEdge::CEDGEK kind, CallSiteID csId);
Expand Down Expand Up @@ -450,6 +473,7 @@ class CallGraph : public GenericPTACallGraphTy
/// Add indirect call edges
//@{
void addIndirectCallGraphEdge(const CallICFGNode* cs,const FunObjVar* callerFun, const FunObjVar* calleeFun);
void addIndirectCallGraphEdge(CallGraphEdge* cgEdge);
//@}

/// Get callsites invoking the callee
Expand Down
24 changes: 17 additions & 7 deletions svf/include/Graphs/ICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ICFG : public GenericICFGTy
{
friend class ICFGBuilder;
friend class ICFGSimplification;
friend class GraphDBClient;

public:

Expand Down Expand Up @@ -198,23 +199,32 @@ class ICFG : public GenericICFGTy
virtual inline FunEntryICFGNode* addFunEntryICFGNode(const FunObjVar* svfFunc)
{
FunEntryICFGNode* sNode = new FunEntryICFGNode(totalICFGNode++,svfFunc);
addICFGNode(sNode);
return FunToFunEntryNodeMap[svfFunc] = sNode;
return addFunEntryICFGNode(sNode);
}

virtual inline FunEntryICFGNode* addFunEntryICFGNode(FunEntryICFGNode* funEntryICFGNode)
{
addICFGNode(funEntryICFGNode);
return FunToFunEntryNodeMap[funEntryICFGNode->getFun()] = funEntryICFGNode;
}

virtual void addGlobalICFGNode(GlobalICFGNode* globalICFGNode);

virtual inline FunExitICFGNode* addFunExitICFGNode(const FunObjVar* svfFunc)
{
FunExitICFGNode* sNode = new FunExitICFGNode(totalICFGNode++, svfFunc);
addICFGNode(sNode);
return FunToFunExitNodeMap[svfFunc] = sNode;
return addFunExitICFGNode(sNode);
}

/// Add a ICFG node
virtual inline void addICFGNode(ICFGNode* node)
virtual inline FunExitICFGNode* addFunExitICFGNode(FunExitICFGNode* funExitICFGNode)
{
addGNode(node->getId(),node);
addICFGNode(funExitICFGNode);
return FunToFunExitNodeMap[funExitICFGNode->getFun()] = funExitICFGNode;
}

/// Add a ICFG node
virtual void addICFGNode(ICFGNode* node);

public:
/// Get a basic block ICFGNode
/// TODO:: need to fix the assertions
Expand Down
1 change: 1 addition & 0 deletions svf/include/Graphs/ICFGEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class IntraCFGEdge : public ICFGEdge
{
friend class ICFG;
friend class SVFIRBuilder;
friend class GraphDBClient;

public:
/// Constructor
Expand Down
86 changes: 86 additions & 0 deletions svf/include/Graphs/ICFGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ class ICFGNode : public GenericICFGNodeTy
}


std::string sourceLocToDBString() const
{
std::string sourceLoc = "";
if (getSourceLoc().empty() == false)
{
sourceLoc = ", source_loc: '" + getSourceLoc() + "'";
}
else
{
sourceLoc = ", source_loc: ''";
}
return sourceLoc;
}

protected:
const FunObjVar* fun;
Expand Down Expand Up @@ -192,6 +205,16 @@ class GlobalICFGNode : public ICFGNode
*/
class IntraICFGNode : public ICFGNode
{
friend class GraphDBClient;

protected:
IntraICFGNode(NodeID id, const SVFBasicBlock* bb, const FunObjVar* funObjVar, bool isReturn): ICFGNode(id, IntraBlock),isRet(isReturn)
{

this->fun = funObjVar;
this->bb = bb;
}

private:
bool isRet;

Expand Down Expand Up @@ -270,6 +293,15 @@ class InterICFGNode : public ICFGNode
*/
class FunEntryICFGNode : public InterICFGNode
{
friend class GraphDBClient;

protected:
FunEntryICFGNode(NodeID id, const FunObjVar* f, SVFBasicBlock* bb)
: InterICFGNode(id, FunEntryBlock)
{
this->fun = f;
this->bb = bb;
}

public:
typedef std::vector<const SVFVar *> FormalParmNodeVec;
Expand Down Expand Up @@ -335,6 +367,15 @@ class FunEntryICFGNode : public InterICFGNode
*/
class FunExitICFGNode : public InterICFGNode
{
friend class GraphDBClient;

protected:
FunExitICFGNode(NodeID id, const FunObjVar* f, SVFBasicBlock* bb, SVFVar* formalRet)
: InterICFGNode(id, FunExitBlock), formalRet(formalRet)
{
this->fun = f;
this->bb = bb;
}

private:
const SVFVar *formalRet;
Expand Down Expand Up @@ -398,6 +439,7 @@ class FunExitICFGNode : public InterICFGNode
*/
class CallICFGNode : public InterICFGNode
{
friend class GraphDBClient;

public:
typedef std::vector<const ValVar *> ActualParmNodeVec;
Expand All @@ -411,6 +453,23 @@ class CallICFGNode : public InterICFGNode
SVFVar* vtabPtr; /// virtual table pointer
s32_t virtualFunIdx; /// virtual function index of the virtual table(s) at a virtual call
std::string funNameOfVcall; /// the function name of this virtual call
const SVFVar* indFunPtr;

/// Constructor to create empty CallICFGNode (for SVFIRReader/deserialization)
CallICFGNode(NodeID id) : InterICFGNode(id, FunCallBlock), ret{} {}

CallICFGNode(NodeID id, const SVFBasicBlock* bb, const SVFType* type,
const FunObjVar* fun, const FunObjVar* cf, const RetICFGNode* ret,
bool iv, bool ivc, s32_t vfi, SVFVar* vtabPtr, const std::string& fnv)
: InterICFGNode(id, FunCallBlock), ret(ret), calledFunc(cf),
isvararg(iv), isVirCallInst(ivc), vtabPtr(vtabPtr),
virtualFunIdx(vfi), funNameOfVcall(fnv)
{
this->fun = fun;
this->bb = bb;
this->type = type;
}


public:
CallICFGNode(NodeID id, const SVFBasicBlock* b, const SVFType* ty,
Expand Down Expand Up @@ -561,6 +620,18 @@ class CallICFGNode : public InterICFGNode
{
return "CallICFGNode: " + ICFGNode::getSourceLoc();
}

inline void setIndFunPtr(const SVFVar* indFun)
{
assert(isIndirectCall() && "not a indirect call?");
indFunPtr = indFun;
}

inline const SVFVar* getIndFunPtr() const
{
assert(isIndirectCall() && "not a indirect call?");
return indFunPtr;
}
};


Expand All @@ -569,6 +640,16 @@ class CallICFGNode : public InterICFGNode
*/
class RetICFGNode : public InterICFGNode
{
friend class GraphDBClient;

protected:
RetICFGNode(NodeID id, const SVFType* type, const SVFBasicBlock* bb, const FunObjVar* funObjVar) :
InterICFGNode(id, FunRetBlock), actualRet(nullptr), callBlockNode(nullptr)
{
this->fun = funObjVar;
this->bb = bb;
this->type = type;
}

private:
const SVFVar *actualRet;
Expand Down Expand Up @@ -599,6 +680,11 @@ class RetICFGNode : public InterICFGNode
actualRet = ar;
}

inline void addCallBlockNodeFromDB(const CallICFGNode* cb)
{
callBlockNode = cb;
}

///Methods for support type inquiry through isa, cast, and dyn_cast:
//@{
static inline bool classof(const RetICFGNode *)
Expand Down
Loading
Loading