Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 1139 #1155

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions svf/include/WPA/Andersen.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class AndersenBase: public WPAConstraintSolver, public BVDataPTAImpl
/// Andersen analysis
virtual void analyze() override;

virtual void analyzeAndWrite(const std::string& filename);

virtual void solveConstraints();

/// Initialize analysis
virtual void initialize() override;

Expand Down
14 changes: 14 additions & 0 deletions svf/include/WPA/FlowSensitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ class FlowSensitive : public WPASVFGFSSolver, public BVDataPTAImpl
return fspta.get();
}

static FlowSensitive* createFSWPA(SVFIR* _pag, const std::string& filename)
{
if (fspta == nullptr)
{
fspta = std::unique_ptr<FlowSensitive>(new FlowSensitive(_pag));
fspta->analyzeAndWrite(filename);
}
return fspta.get();
}

/// Release flow-sensitive pointer analysis
static void releaseFSWPA()
{
Expand All @@ -101,6 +111,10 @@ class FlowSensitive : public WPASVFGFSSolver, public BVDataPTAImpl
/// Flow sensitive analysis
void analyze() override;

virtual void analyzeAndWrite(const std::string& filename);

virtual void solveConstraints();

/// Initialize analysis
void initialize() override;

Expand Down
4 changes: 2 additions & 2 deletions svf/lib/MemoryModel/PointerAnalysisImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void BVDataPTAImpl::writeObjVarToFile(const string& filename)
outs() << " error opening file for writing!\n";
return;
}

// Write BaseNodes insensitivity to file
NodeBS NodeIDs;
for (auto it = pag->begin(), ie = pag->end(); it != ie; ++it)
Expand All @@ -185,14 +185,14 @@ void BVDataPTAImpl::writeObjVarToFile(const string& filename)

f << "------\n";

// Job finish and close file
f.close();
if (f.good())
{
outs() << "\n";
return;
}


}

/*!
Expand Down
68 changes: 47 additions & 21 deletions svf/lib/WPA/Andersen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,9 @@
BVDataPTAImpl::finalize();
}

/*!
* Andersen analysis
*/
void AndersenBase::analyze()
void AndersenBase::solveConstraints()
{
/// Initialization for the Solver
initialize();

bool readResultsFromFile = false;
if(!Options::ReadAnder().empty())
{
readResultsFromFile = this->readFromFile(Options::ReadAnder());
// Finalize the analysis
PointerAnalysis::finalize();
}

if (!Options::WriteAnder().empty())
this->writeObjVarToFile(Options::WriteAnder());

if(!readResultsFromFile)
{
// Start solving constraints
// Start solving constraints
DBOUT(DGENERAL, outs() << SVFUtil::pasMsg("Start Solving Constraints\n"));

bool limitTimerSet = SVFUtil::startAnalysisLimitTimer(Options::AnderTimeLimit());
Expand All @@ -144,9 +125,30 @@
SVFUtil::stopAnalysisLimitTimer(limitTimerSet);

DBOUT(DGENERAL, outs() << SVFUtil::pasMsg("Finish Solving Constraints\n"));
}

/*!
* Andersen analysis
*/
void AndersenBase::analyze()
{
/// Initialization for the Solver
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(!Options::ReadAnder().empty()){
readPtsFromFile(Options::ReadAnder());
}
else{
if(Options::WriteAnder().empty()) {
initialize();
solveConstraints();
finalize();
}
else{
solveAndwritePtsToFile(Options::WriteAnder());
}
}

readPtsFromFile(filename){

initialize();
this->readFromFile(Options::ReadAnder());
PointerAnalysis::finalize();
}

initialize();

bool readResultsFromFile = false;
if(!Options::ReadAnder().empty())
{
readResultsFromFile = this->readFromFile(Options::ReadAnder());
// Finalize the analysis
PointerAnalysis::finalize();
}

if (!Options::WriteAnder().empty())
this->writeObjVarToFile(Options::WriteAnder());

if(!readResultsFromFile)
solveConstraints();

if (!Options::WriteAnder().empty())
{
this->writeToFile(Options::WriteAnder());
Expand All @@ -157,6 +159,30 @@
finalize();
}


void AndersenBase::analyzeAndWrite(const std::string& filename)

Check warning on line 163 in svf/lib/WPA/Andersen.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/Andersen.cpp#L163

Added line #L163 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

analyzeAndWrite => SolveAndWritePtsToFile

SolveAndWritePtsToFile(filename){

initialize();
this->writeObjVarToFile(filename);
solveConstraints();
this->writeToFile(filename);
finalize();

}

{
/// Initialization for the Solver
initialize();

Check warning on line 166 in svf/lib/WPA/Andersen.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/Andersen.cpp#L166

Added line #L166 was not covered by tests

bool readResultsFromFile = false;

if (filename.empty())
this->writeObjVarToFile(filename);

Check warning on line 171 in svf/lib/WPA/Andersen.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/Andersen.cpp#L170-L171

Added lines #L170 - L171 were not covered by tests

if(!readResultsFromFile)
solveConstraints();

Check warning on line 174 in svf/lib/WPA/Andersen.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/Andersen.cpp#L174

Added line #L174 was not covered by tests

if (filename.empty())

Check warning on line 176 in svf/lib/WPA/Andersen.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/Andersen.cpp#L176

Added line #L176 was not covered by tests
{
this->writeToFile(filename);

Check warning on line 178 in svf/lib/WPA/Andersen.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/Andersen.cpp#L178

Added line #L178 was not covered by tests
}

if (!readResultsFromFile)
// Finalize the analysis
finalize();
}

Check warning on line 184 in svf/lib/WPA/Andersen.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/Andersen.cpp#L183-L184

Added lines #L183 - L184 were not covered by tests

void AndersenBase::cleanConsCG(NodeID id)
{
consCG->resetSubs(consCG->getRep(id));
Expand Down
52 changes: 41 additions & 11 deletions svf/lib/WPA/FlowSensitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,8 @@
setGraph(svfg);
//AndersenWaveDiff::releaseAndersenWaveDiff();
}

/*!
* Start analysis
*/
void FlowSensitive::analyze()
void FlowSensitive::solveConstraints()
{
bool limitTimerSet = SVFUtil::startAnalysisLimitTimer(Options::FsTimeLimit());

/// Initialization for the Solver
initialize();

double start = stat->getClk(true);
/// Start solving constraints
DBOUT(DGENERAL, outs() << SVFUtil::pasMsg("Start Solving Constraints\n"));

Expand All @@ -104,6 +94,46 @@
while (updateCallGraph(getIndirectCallsites()));

DBOUT(DGENERAL, outs() << SVFUtil::pasMsg("Finish Solving Constraints\n"));
}

/*!
* Start analysis
*/
void FlowSensitive::analyzeAndWrite(const std::string& filename)

Check warning on line 102 in svf/lib/WPA/FlowSensitive.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/FlowSensitive.cpp#L102

Added line #L102 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add two methods "solveAndwritePtsToFile" and "readPtsFromFile"

{
bool limitTimerSet = SVFUtil::startAnalysisLimitTimer(Options::FsTimeLimit());

Check warning on line 104 in svf/lib/WPA/FlowSensitive.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/FlowSensitive.cpp#L104

Added line #L104 was not covered by tests

/// Initialization for the Solver
initialize();

Check warning on line 107 in svf/lib/WPA/FlowSensitive.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/FlowSensitive.cpp#L107

Added line #L107 was not covered by tests

double start = stat->getClk(true);
writeObjVarToFile(filename);
solveConstraints();

Check warning on line 111 in svf/lib/WPA/FlowSensitive.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/FlowSensitive.cpp#L109-L111

Added lines #L109 - L111 were not covered by tests

// Reset the time-up alarm; analysis is done.
SVFUtil::stopAnalysisLimitTimer(limitTimerSet);

Check warning on line 114 in svf/lib/WPA/FlowSensitive.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/FlowSensitive.cpp#L114

Added line #L114 was not covered by tests

writeToFile(filename);

Check warning on line 116 in svf/lib/WPA/FlowSensitive.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/FlowSensitive.cpp#L116

Added line #L116 was not covered by tests

double end = stat->getClk(true);
solveTime += (end - start) / TIMEINTERVAL;

Check warning on line 119 in svf/lib/WPA/FlowSensitive.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/FlowSensitive.cpp#L118-L119

Added lines #L118 - L119 were not covered by tests

/// finalize the analysis
finalize();
}

Check warning on line 123 in svf/lib/WPA/FlowSensitive.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/WPA/FlowSensitive.cpp#L122-L123

Added lines #L122 - L123 were not covered by tests

/*!
* Start analysis
*/
void FlowSensitive::analyze()
{
bool limitTimerSet = SVFUtil::startAnalysisLimitTimer(Options::FsTimeLimit());

/// Initialization for the Solver
initialize();

double start = stat->getClk(true);
solveConstraints();

// Reset the time-up alarm; analysis is done.
SVFUtil::stopAnalysisLimitTimer(limitTimerSet);
Expand Down
Loading