Skip to content

Some fixes in the IterativeIDESolver #782

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

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
40 changes: 21 additions & 19 deletions include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class IterativeIDESolver
return true;
}

auto NewEF = EF.joinWith(std::move(LocalEF));
auto NewEF = Problem.combine(EF, std::move(LocalEF));
assert(NewEF != nullptr);

if (NewEF != EF) {
Expand Down Expand Up @@ -540,7 +540,7 @@ class IterativeIDESolver
return;
}

auto NewEF = EF.joinWith(std::move(LocalEF));
auto NewEF = Problem.combine(EF, std::move(LocalEF));
assert(NewEF != nullptr);

if (NewEF != EF) {
Expand Down Expand Up @@ -622,10 +622,11 @@ class IterativeIDESolver
auto FactId = FactCompressor.getOrInsert(Fact);
auto EF = [&] {
if constexpr (ComputeValues) {
return SourceEF.composeWith(FECache.getNormalEdgeFunction(
auto NEF = FECache.getNormalEdgeFunction(
Problem, AtInstruction, CSFact, Succ, Fact,
combineIds(AtInstructionId, SuccId),
combineIds(PropagatedFactId, FactId)));
combineIds(PropagatedFactId, FactId));
return Problem.extend(SourceEF, std::move(NEF));
} else {
return EdgeFunctionPtrType{};
}
Expand Down Expand Up @@ -694,10 +695,11 @@ class IterativeIDESolver

auto EF = [&] {
if constexpr (ComputeValues) {
return SourceEF.composeWith(FECache.getCallToRetEdgeFunction(
auto CEF = FECache.getCallToRetEdgeFunction(
Problem, AtInstruction, CSFact, RetSite, Fact, Callees /*Vec*/,
combineIds(AtInstructionId, RetSiteId),
combineIds(PropagatedFactId, FactId)));
combineIds(PropagatedFactId, FactId));
return Problem.extend(SourceEF, std::move(CEF));
} else {
return EdgeFunctionPtrType{};
}
Expand Down Expand Up @@ -835,10 +837,11 @@ class IterativeIDESolver

auto CallEF = [&] {
if constexpr (ComputeValues) {
return SourceEF.composeWith(FECache.getCallEdgeFunction(
auto CEF = FECache.getCallEdgeFunction(
Problem, AtInstruction, CSFact, Callee, Fact,
combineIds(AtInstructionId, CalleeId),
combineIds(CSFactId, FactId)));
combineIds(CSFactId, FactId));
return Problem.extend(SourceEF, std::move(CEF));
} else {
return EdgeFunctionPtrType{};
}
Expand Down Expand Up @@ -900,7 +903,7 @@ class IterativeIDESolver
Problem, AtInstruction, CSFact, RetSite, Fact,
combineIds(AtInstructionId, RetSiteId),
combineIds(CSFactId, FactId));
return EF ? SourceEF.composeWith(std::move(EF)) : SourceEF;
return EF ? Problem.extend(SourceEF, std::move(EF)) : SourceEF;
} else {
return EdgeFunctionPtrType{};
}
Expand Down Expand Up @@ -939,8 +942,8 @@ class IterativeIDESolver
Problem, CallSite, Callee, ExitInst, SummaryFact, RetSite,
RetFact, ExitId, combineIds(CSId, RSId),
combineIds(SummaryFactId, RetFactId));
return CallEF.composeWith(Summary.second)
.composeWith(std::move(RetEF));
return Problem.extend(Problem.extend(CallEF, Summary.second),
std::move(RetEF));
} else {
return EdgeFunctionPtrType{};
}
Expand All @@ -954,16 +957,15 @@ class IterativeIDESolver
}

void processInterJobs() {

llvm::errs() << "processInterJobs: " << CallWL.size()
<< " relevant calls\n";
PHASAR_LOG_LEVEL(INFO, "processInterJobs: " << CallWL.size()
<< " relevant calls");

/// Here, no other job is running concurrently, so we save and reset the
/// CallWL, such that we can start concurrent jobs in the loop below
std::vector<uint64_t> RelevantCalls(CallWL.begin(), CallWL.end());

scope_exit FinishedInterCalls = [] {
llvm::errs() << "> end inter calls\n";
PHASAR_LOG_LEVEL(INFO, "> end inter calls");
};

if constexpr (EnableStatistics) {
Expand Down Expand Up @@ -1250,14 +1252,14 @@ class IterativeIDESolver
}

void runGC() {
llvm::errs() << "runGC() with " << CandidateFunctionsForGC.count()
<< " candidates\n";
PHASAR_LOG_LEVEL(INFO, "runGC() with " << CandidateFunctionsForGC.count()
<< " candidates");

size_t NumCollectedFuns = 0;

scope_exit FinishGC = [&NumCollectedFuns] {
llvm::errs() << "> Finished GC run (collected " << NumCollectedFuns
<< " functions)\n";
PHASAR_LOG_LEVEL(INFO, "> Finished GC run (collected " << NumCollectedFuns
<< " functions)");
};

auto FinalCandidates = getCollectableFunctions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,13 @@ class IDEFeatureTaintAnalysis

} // namespace psr

namespace std {
template <> struct hash<psr::IDEFeatureTaintEdgeFact> {
size_t
operator()(const psr::IDEFeatureTaintEdgeFact &EdgeFact) const noexcept {
return hash_value(EdgeFact);
}
};
} // namespace std

#endif // PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEFEATURETAINTANALYSIS_H
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "phasar/DataFlow/IfdsIde/Solver/IDESolver.h"
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"
#include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h"
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMSolverResults.h"
#include "phasar/PhasarLLVM/HelperAnalyses.h"
#include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h"
#include "phasar/PhasarLLVM/SimpleAnalysisConstructor.h"
Expand Down Expand Up @@ -102,8 +101,11 @@ class IDEFeatureTaintAnalysisTest : public ::testing::Test {
// psr::Logger::initializeStderrLogger(SeverityLevel::DEBUG);
// }

IDESolver IIASolver(IIAProblem, &HA->getICFG());
IDESolver IIASolver(&IIAProblem, &HA->getICFG());
// IterativeIDESolver IIASolver(&IIAProblem, &HA->getICFG());
IIASolver.solve();

auto Results = IIASolver.getSolverResults();
// if (PrintDump) {
// // IRDB->emitPreprocessedIR(llvm::outs());
// IIASolver.dumpResults();
Expand All @@ -115,7 +117,7 @@ class IDEFeatureTaintAnalysisTest : public ::testing::Test {
for (const auto &[FunName, SrcLine, VarName, LatticeVal] : GroundTruth) {
const auto *Fun = IRDB->getFunctionDefinition(FunName);
const auto *IRLine = getNthInstruction(Fun, SrcLine);
auto ResultMap = IIASolver.resultsAt(IRLine);
auto ResultMap = Results.resultsAt(IRLine);
assert(IRLine && "Could not retrieve IR line!");
bool FactFound = false;
for (auto &[Fact, Value] : ResultMap) {
Expand All @@ -142,17 +144,17 @@ class IDEFeatureTaintAnalysisTest : public ::testing::Test {
IIASolver.dumpResults(llvm::errs());
llvm::errs()
<< "\n======================================================\n";
printDump(HA->getProjectIRDB(), IIASolver.getSolverResults());
printDump(HA->getProjectIRDB(), Results);
}
}

void TearDown() override {}

// See vara::PhasarTaintAnalysis::taintsForInst
[[nodiscard]] inline std::set<std::string>
taintsForInst(const llvm::Instruction *Inst,
SolverResults<const llvm::Instruction *, const llvm::Value *,
IDEFeatureTaintEdgeFact> SR) {
[[nodiscard]] inline std::set<std::string> taintsForInst(
const llvm::Instruction *Inst,
GenericSolverResults<const llvm::Instruction *, const llvm::Value *,
IDEFeatureTaintEdgeFact> SR) {

if (const auto *Ret = llvm::dyn_cast<llvm::ReturnInst>(Inst)) {
if (Ret->getNumOperands() == 0) {
Expand Down Expand Up @@ -187,10 +189,11 @@ class IDEFeatureTaintAnalysisTest : public ::testing::Test {
return AggregatedTaints;
}

void printDump(const LLVMProjectIRDB &IRDB,
SolverResults<const llvm::Instruction *, const llvm::Value *,
IDEFeatureTaintEdgeFact>
SR) {
void
printDump(const LLVMProjectIRDB &IRDB,
GenericSolverResults<const llvm::Instruction *, const llvm::Value *,
IDEFeatureTaintEdgeFact>
SR) {
const llvm::Function *CurrFun = nullptr;
for (const auto *Inst : IRDB.getAllInstructions()) {
if (CurrFun != Inst->getFunction()) {
Expand Down
Loading