Skip to content

Commit

Permalink
Embed MemSSA as unique_ptr in SVFG, restore non-simple svfg dump.
Browse files Browse the repository at this point in the history
Not sure about Saber code, but seems to compile still?

External clients will of course need adjusting,
and unique_ptr does not fight this code's style.
  • Loading branch information
dtzWill committed Apr 25, 2017
1 parent c6a453c commit 49a0464
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 26 deletions.
10 changes: 7 additions & 3 deletions include/MSSA/SVFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SVFG : public GenericSVFGGraphTy {
StorePEToSVFGNodeMap storePEToSVFGNodeMap; ///< map store inst to store SVFGNode
SVFGStat * stat;
SVFGK kind;
MemSSA* mssa;
std::unique_ptr<MemSSA> mssa;
PointerAnalysis* pta;

/// Clean up memory
Expand All @@ -115,7 +115,7 @@ class SVFG : public GenericSVFGGraphTy {
SVFG(SVFGK k = ORIGSVFGK);

/// Start building SVFG
virtual void buildSVFG(MemSSA* m);
virtual void buildSVFG(std::unique_ptr<MemSSA> m);

public:
/// Destructor
Expand All @@ -133,9 +133,13 @@ class SVFG : public GenericSVFGGraphTy {
return PAG::getPAG();
}

inline MemSSA* getMSSA() {
return mssa.get();
};

/// Clear MSSA
inline void clearMSSA() {
mssa = NULL;
mssa.reset();
}

/// Get SVFG kind
Expand Down
2 changes: 1 addition & 1 deletion include/MSSA/SVFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SVFGBuilder {
/// We start from here
virtual bool build(SVFG* graph,BVDataPTAImpl* pta);
/// Can be rewritten by subclasses
virtual void createSVFG(MemSSA* mssa, SVFG* graph);
virtual void createSVFG(std::unique_ptr<MemSSA> mssa, SVFG* graph);
/// Release global SVFG
virtual void releaseMemory(SVFG* graph);
/// Update call graph using pre-analysis points-to results
Expand Down
4 changes: 2 additions & 2 deletions include/MSSA/SVFGOPT.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class SVFGOPT : public SVFG {
return g->getKind() == OPTSVFGK;
}
protected:
virtual inline void buildSVFG(MemSSA* m) {
SVFG::buildSVFG(m);
virtual inline void buildSVFG(std::unique_ptr<MemSSA> m) {
SVFG::buildSVFG(std::move(m));

dump("SVFG_before_opt");

Expand Down
2 changes: 1 addition & 1 deletion include/SABER/SaberSVFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SaberSVFGBuilder : public SVFGBuilder {
}
protected:
/// Re-write create SVFG method
virtual void createSVFG(MemSSA* mssa, SVFG* graph);
virtual void createSVFG(std::unique_ptr<MemSSA> mssa, SVFG* graph);

private:
/// Remove direct value-flow edge to a dereference point for Saber source-sink memory error detection
Expand Down
10 changes: 5 additions & 5 deletions lib/MSSA/SVFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static cl::opt<bool> DumpVFG("dump-svfg", cl::init(false),
/*!
* Constructor
*/
SVFG::SVFG(SVFGK k): totalSVFGNode(0), kind(k),mssa(NULL),pta(NULL) {
SVFG::SVFG(SVFGK k): totalSVFGNode(0), kind(k),pta(NULL) {
stat = new SVFGStat(this);
}

Expand All @@ -53,7 +53,7 @@ SVFG::SVFG(SVFGK k): totalSVFGNode(0), kind(k),mssa(NULL),pta(NULL) {
void SVFG::destroy() {
delete stat;
stat = NULL;
mssa = NULL;
mssa.reset();
pta = NULL;
}

Expand All @@ -66,9 +66,9 @@ void SVFG::destroy() {
* a) between two statements (PAGEdges)
* b) between two memory SSA operators (MSSAPHI MSSAMU and MSSACHI)
*/
void SVFG::buildSVFG(MemSSA* m) {
mssa = m;
pta = m->getPTA();
void SVFG::buildSVFG(std::unique_ptr<MemSSA> m) {
mssa = std::move(m);
pta = mssa->getPTA();
stat->startClk();
DBOUT(DGENERAL, outs() << pasMsg("\tCreate SVFG Top Level Node\n"));

Expand Down
22 changes: 12 additions & 10 deletions lib/MSSA/SVFGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ SVFGOPT* SVFGBuilder::globalSvfg = NULL;
/*!
* Create SVFG
*/
void SVFGBuilder::createSVFG(MemSSA* mssa, SVFG* graph) {
void SVFGBuilder::createSVFG(std::unique_ptr<MemSSA> mssa, SVFG* graph) {
svfg = graph;
svfg->buildSVFG(mssa);
if(mssa->getPTA()->printStat())
svfg->buildSVFG(std::move(mssa));
if(svfg->getMSSA()->getPTA()->printStat())
svfg->performStat();
svfg->dump("FS_SVFG");
}
Expand Down Expand Up @@ -85,7 +85,7 @@ void SVFGBuilder::releaseMemory(SVFG* vfg) {
*/
bool SVFGBuilder::build(SVFG* graph,BVDataPTAImpl* pta) {

MemSSA mssa(pta);
auto mssa = llvm::make_unique<MemSSA>(pta);

DBOUT(DGENERAL, outs() << pasMsg("Build Memory SSA \n"));

Expand All @@ -102,20 +102,22 @@ bool SVFGBuilder::build(SVFG* graph,BVDataPTAImpl* pta) {
dt.recalculate(fun);
df.runOnDT(dt);

mssa.buildMemSSA(fun, &df, &dt);
mssa->buildMemSSA(fun, &df, &dt);
}

mssa.performStat();
mssa.dumpMSSA();
mssa->performStat();
mssa->dumpMSSA();

DBOUT(DGENERAL, outs() << pasMsg("Build Sparse Value-Flow Graph \n"));

createSVFG(&mssa, graph);
createSVFG(std::move(mssa), graph);

if(SVFGWithIndirectCall || SVFGWithIndCall)
updateCallGraph(mssa.getPTA());
updateCallGraph(graph->getMSSA()->getPTA());

releaseMemory(graph);
// Graph will release mssa either on request or
// when it itself is deleted.
// releaseMemory(graph);

return false;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/SABER/SaberSVFGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
using namespace llvm;
using namespace analysisUtil;

void SaberSVFGBuilder::createSVFG(MemSSA* mssa, SVFG* graph) {
void SaberSVFGBuilder::createSVFG(std::unique_ptr<MemSSA> mssa, SVFG* graph) {

svfg = graph;
svfg->buildSVFG(mssa);
BVDataPTAImpl* pta = mssa->getPTA();
svfg->buildSVFG(std::move(mssa));
BVDataPTAImpl* pta = svfg->getMSSA()->getPTA();
DBOUT(DGENERAL, outs() << pasMsg("\tCollect Global Variables\n"));

collectGlobals(pta);
Expand Down
2 changes: 1 addition & 1 deletion lib/WPA/WPAPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void WPAPass::runPointerAnalysis(llvm::Module& module, u32_t kind)
if (anderSVFG) {
SVFGBuilder memSSA(true);
SVFG *svfg = memSSA.buildSVFG((BVDataPTAImpl*)_pta);
svfg->dump("ander_svfg", true /* simple */);
svfg->dump("ander_svfg");
}
}

Expand Down

0 comments on commit 49a0464

Please sign in to comment.