Skip to content

Commit def7c04

Browse files
committed
Allowed SVFG optimisation to be configurable & fixed reading/writing existing results
The current `SVFGBuilder` optimises the SVFG based on the command-line argument. However, when using SVF as a library, this is inconvenient. This commit changes the builder to use an additional flag to control optimisation behaviour. Moreover, this commit fixes the reading/writing issues for optimised SVFGs. Currently, the writing happens post-optimisation, which causes the reading step to fail due to missing/unexpected nodes. This commit also ensures the *unoptimised SVFG* is written to a file *prior to optimising it*, and reads an unoptimised SVFG from a file and then optimises it. This fixes these crashing issues.
1 parent 93446f6 commit def7c04

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

svf/include/Graphs/SVFGOPT.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,18 @@ class SVFGOPT : public SVFG
8181
keepContextSelfCycle = true;
8282
}
8383

84+
/// Optimised SVFG's aren't written in their optimised form; read full SVFG and optimise it
85+
void readAndOptSVFG(const std::string &filename);
86+
87+
/// Optimised SVFG's shouldn't be written in their optimised form; writes the full SVFG to file before optimising
88+
void buildAndWriteSVFG(const std::string &filename);
89+
8490
protected:
8591
void buildSVFG() override;
8692

93+
/// Separate optimisation function to avoid duplicate code
94+
void optimiseSVFG();
95+
8796
/// Connect SVFG nodes between caller and callee for indirect call sites
8897
//@{
8998
inline void connectAParamAndFParam(const PAGNode* cs_arg, const PAGNode* fun_arg, const CallICFGNode*, CallSiteID csId, SVFGEdgeSetTy& edges) override

svf/include/MSSA/SVFGBuilder.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ class SVFGBuilder
4949
typedef SVFG::SVFGEdgeSetTy SVFGEdgeSet;
5050

5151
/// Constructor
52-
explicit SVFGBuilder(bool _SVFGWithIndCall = false): svfg(nullptr), SVFGWithIndCall(_SVFGWithIndCall) {}
52+
explicit SVFGBuilder(bool _SVFGWithIndCall = false, bool _OptimiseSVFG = false) :
53+
svfg(nullptr), SVFGWithIndCall(_SVFGWithIndCall), OptimiseSVFG(_OptimiseSVFG)
54+
{
55+
}
5356

5457
/// Destructor
5558
virtual ~SVFGBuilder() = default;
@@ -91,6 +94,8 @@ class SVFGBuilder
9194
std::unique_ptr<SVFG> svfg;
9295
/// SVFG with precomputed indirect call edges
9396
bool SVFGWithIndCall;
97+
/// Build optimised version of SVFG
98+
bool OptimiseSVFG;
9499
};
95100

96101
} // End namespace SVF

svf/lib/Graphs/SVFGOPT.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,29 @@ static std::string KeepAllSelfCycle = "all";
4343
static std::string KeepContextSelfCycle = "context";
4444
static std::string KeepNoneSelfCycle = "none";
4545

46+
/// Optimised SVFGs aren't written to file; reads the full SVFG and optimises it
47+
void SVFGOPT::readAndOptSVFG(const std::string &filename)
48+
{
49+
SVFG::readFile(filename);
50+
optimiseSVFG();
51+
}
52+
53+
/// Shouldn't write optimised SVFG to file; writes the built SVFG to file before optimisation
54+
void SVFGOPT::buildAndWriteSVFG(const std::string &filename)
55+
{
56+
SVFG::buildSVFG();
57+
SVFG::writeToFile(filename);
58+
optimiseSVFG();
59+
}
4660

4761
void SVFGOPT::buildSVFG()
4862
{
4963
SVFG::buildSVFG();
64+
optimiseSVFG();
65+
}
5066

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

@@ -62,6 +80,7 @@ void SVFGOPT::buildSVFG()
6280
stat->sfvgOptEnd();
6381

6482
}
83+
6584
/*!
6685
*
6786
*/

svf/lib/MSSA/SVFGBuilder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@ using namespace SVFUtil;
4141

4242
SVFG* SVFGBuilder::buildPTROnlySVFG(BVDataPTAImpl* pta)
4343
{
44-
if(Options::OPTSVFG())
44+
if(Options::OPTSVFG() || this->OptimiseSVFG)
4545
return build(pta, VFG::PTRONLYSVFG_OPT);
4646
else
4747
return build(pta, VFG::PTRONLYSVFG);
4848
}
4949

5050
SVFG* SVFGBuilder::buildFullSVFG(BVDataPTAImpl* pta)
5151
{
52-
return build(pta, VFG::FULLSVFG);
52+
if(Options::OPTSVFG() || this->OptimiseSVFG)
53+
return build(pta, VFG::FULLSVFG_OPT);
54+
else
55+
return build(pta, VFG::FULLSVFG);
5356
}
5457

5558

0 commit comments

Comments
 (0)