Skip to content

Commit

Permalink
Fix reading/writing optimised SVFG from/to file; allow building optim…
Browse files Browse the repository at this point in the history
…ised SVFG with SVFGBuilder
  • Loading branch information
Johanmyst committed Jun 18, 2024
1 parent af24636 commit 3fb7a5e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
9 changes: 9 additions & 0 deletions svf/include/Graphs/SVFGOPT.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,18 @@ class SVFGOPT : public SVFG
keepContextSelfCycle = true;
}

/// Optimised SVFGs aren't written to file; reads the full SVFG and optimises it
void readAndOptSVFG(const std::string &filename);

/// Shouldn't write optimised SVFG to file; writes the built SVFG to file before optimisation
void buildAndWriteSVFG(const std::string &filename);

protected:
void buildSVFG() override;

/// Separate function to optimise the SVFG to avoid duplicate code
void optimiseSVFG();

/// Connect SVFG nodes between caller and callee for indirect call sites
//@{
inline void connectAParamAndFParam(const PAGNode* cs_arg, const PAGNode* fun_arg, const CallICFGNode*, CallSiteID csId, SVFGEdgeSetTy& edges) override
Expand Down
5 changes: 4 additions & 1 deletion svf/include/MSSA/SVFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class SVFGBuilder
typedef SVFG::SVFGEdgeSetTy SVFGEdgeSet;

/// Constructor
explicit SVFGBuilder(bool _SVFGWithIndCall = false): svfg(nullptr), SVFGWithIndCall(_SVFGWithIndCall) {}
explicit SVFGBuilder(bool _SVFGWithIndCall = false, bool _OptimiseSVFG = false)
: svfg(nullptr), SVFGWithIndCall(_SVFGWithIndCall), OptimiseSVFG(_OptimiseSVFG) {}

/// Destructor
virtual ~SVFGBuilder() = default;
Expand Down Expand Up @@ -91,6 +92,8 @@ class SVFGBuilder
std::unique_ptr<SVFG> svfg;
/// SVFG with precomputed indirect call edges
bool SVFGWithIndCall;
/// Build optimised version of SVFG
bool OptimiseSVFG;
};

} // End namespace SVF
Expand Down
21 changes: 20 additions & 1 deletion svf/lib/Graphs/SVFGOPT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,30 @@ static std::string KeepAllSelfCycle = "all";
static std::string KeepContextSelfCycle = "context";
static std::string KeepNoneSelfCycle = "none";

/// Optimised SVFGs aren't written to file; reads the full SVFG and optimises it
void SVFGOPT::readAndOptSVFG(const std::string &filename)
{
SVFG::readFile(filename);
optimiseSVFG();
}

/// Shouldn't write optimised SVFG to file; writes the built SVFG to file before optimisation
void SVFGOPT::buildAndWriteSVFG(const std::string &filename)
{
SVFG::buildSVFG();
SVFG::writeToFile(filename);
optimiseSVFG();
}

void SVFGOPT::buildSVFG()
{
SVFG::buildSVFG();
optimiseSVFG();
}

/// Separate function to optimise the SVFG to avoid duplicate code
void SVFGOPT::optimiseSVFG()
{
if(Options::DumpVFG())
dump("SVFG_before_opt");

Expand All @@ -60,8 +79,8 @@ void SVFGOPT::buildSVFG()

handleIntraValueFlow();
stat->sfvgOptEnd();

}

/*!
*
*/
Expand Down
7 changes: 5 additions & 2 deletions svf/lib/MSSA/SVFGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ using namespace SVFUtil;

SVFG* SVFGBuilder::buildPTROnlySVFG(BVDataPTAImpl* pta)
{
if(Options::OPTSVFG())
if(Options::OPTSVFG() || this->OptimiseSVFG)
return build(pta, VFG::PTRONLYSVFG_OPT);
else
return build(pta, VFG::PTRONLYSVFG);
}

SVFG* SVFGBuilder::buildFullSVFG(BVDataPTAImpl* pta)
{
return build(pta, VFG::FULLSVFG);
if(Options::OPTSVFG() || this->OptimiseSVFG)
return build(pta, VFG::FULLSVFG_OPT);
else
return build(pta, VFG::FULLSVFG);
}


Expand Down
2 changes: 1 addition & 1 deletion svf/lib/MemoryModel/PointerAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ PointerAnalysis::PointerAnalysis(SVFIR* p, PTATY ty, bool alias_check) :
OnTheFlyIterBudgetForStat = Options::StatBudget();
print_stat = Options::PStat();
ptaImplTy = BaseImpl;
alias_validation = (alias_check && Options::EnableAliasCheck());
alias_validation = (alias_check || Options::EnableAliasCheck());
}

/*!
Expand Down

0 comments on commit 3fb7a5e

Please sign in to comment.