Skip to content

Commit 776600f

Browse files
authored
Some fixes in the IterativeIDESolver (#782)
* Fix the IterativeIDESolver by allowing to analyze problems that override extend() and combine() * Use the logger in the IterativeIDESolver * Make it possible to solve the IDEFeatureTaintAnalysis with the IterativeIDESolver * Fix errors introduced by merge
1 parent 814ae82 commit 776600f

3 files changed

Lines changed: 42 additions & 29 deletions

File tree

include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class IterativeIDESolver
474474
return true;
475475
}
476476

477-
auto NewEF = EF.joinWith(std::move(LocalEF));
477+
auto NewEF = Problem.combine(EF, std::move(LocalEF));
478478
assert(NewEF != nullptr);
479479

480480
if (NewEF != EF) {
@@ -540,7 +540,7 @@ class IterativeIDESolver
540540
return;
541541
}
542542

543-
auto NewEF = EF.joinWith(std::move(LocalEF));
543+
auto NewEF = Problem.combine(EF, std::move(LocalEF));
544544
assert(NewEF != nullptr);
545545

546546
if (NewEF != EF) {
@@ -622,10 +622,11 @@ class IterativeIDESolver
622622
auto FactId = FactCompressor.getOrInsert(Fact);
623623
auto EF = [&] {
624624
if constexpr (ComputeValues) {
625-
return SourceEF.composeWith(FECache.getNormalEdgeFunction(
625+
auto NEF = FECache.getNormalEdgeFunction(
626626
Problem, AtInstruction, CSFact, Succ, Fact,
627627
combineIds(AtInstructionId, SuccId),
628-
combineIds(PropagatedFactId, FactId)));
628+
combineIds(PropagatedFactId, FactId));
629+
return Problem.extend(SourceEF, std::move(NEF));
629630
} else {
630631
return EdgeFunctionPtrType{};
631632
}
@@ -694,10 +695,11 @@ class IterativeIDESolver
694695

695696
auto EF = [&] {
696697
if constexpr (ComputeValues) {
697-
return SourceEF.composeWith(FECache.getCallToRetEdgeFunction(
698+
auto CEF = FECache.getCallToRetEdgeFunction(
698699
Problem, AtInstruction, CSFact, RetSite, Fact, Callees /*Vec*/,
699700
combineIds(AtInstructionId, RetSiteId),
700-
combineIds(PropagatedFactId, FactId)));
701+
combineIds(PropagatedFactId, FactId));
702+
return Problem.extend(SourceEF, std::move(CEF));
701703
} else {
702704
return EdgeFunctionPtrType{};
703705
}
@@ -835,10 +837,11 @@ class IterativeIDESolver
835837

836838
auto CallEF = [&] {
837839
if constexpr (ComputeValues) {
838-
return SourceEF.composeWith(FECache.getCallEdgeFunction(
840+
auto CEF = FECache.getCallEdgeFunction(
839841
Problem, AtInstruction, CSFact, Callee, Fact,
840842
combineIds(AtInstructionId, CalleeId),
841-
combineIds(CSFactId, FactId)));
843+
combineIds(CSFactId, FactId));
844+
return Problem.extend(SourceEF, std::move(CEF));
842845
} else {
843846
return EdgeFunctionPtrType{};
844847
}
@@ -900,7 +903,7 @@ class IterativeIDESolver
900903
Problem, AtInstruction, CSFact, RetSite, Fact,
901904
combineIds(AtInstructionId, RetSiteId),
902905
combineIds(CSFactId, FactId));
903-
return EF ? SourceEF.composeWith(std::move(EF)) : SourceEF;
906+
return EF ? Problem.extend(SourceEF, std::move(EF)) : SourceEF;
904907
} else {
905908
return EdgeFunctionPtrType{};
906909
}
@@ -939,8 +942,8 @@ class IterativeIDESolver
939942
Problem, CallSite, Callee, ExitInst, SummaryFact, RetSite,
940943
RetFact, ExitId, combineIds(CSId, RSId),
941944
combineIds(SummaryFactId, RetFactId));
942-
return CallEF.composeWith(Summary.second)
943-
.composeWith(std::move(RetEF));
945+
return Problem.extend(Problem.extend(CallEF, Summary.second),
946+
std::move(RetEF));
944947
} else {
945948
return EdgeFunctionPtrType{};
946949
}
@@ -954,16 +957,15 @@ class IterativeIDESolver
954957
}
955958

956959
void processInterJobs() {
957-
958-
llvm::errs() << "processInterJobs: " << CallWL.size()
959-
<< " relevant calls\n";
960+
PHASAR_LOG_LEVEL(INFO, "processInterJobs: " << CallWL.size()
961+
<< " relevant calls");
960962

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

965967
scope_exit FinishedInterCalls = [] {
966-
llvm::errs() << "> end inter calls\n";
968+
PHASAR_LOG_LEVEL(INFO, "> end inter calls");
967969
};
968970

969971
if constexpr (EnableStatistics) {
@@ -1250,14 +1252,14 @@ class IterativeIDESolver
12501252
}
12511253

12521254
void runGC() {
1253-
llvm::errs() << "runGC() with " << CandidateFunctionsForGC.count()
1254-
<< " candidates\n";
1255+
PHASAR_LOG_LEVEL(INFO, "runGC() with " << CandidateFunctionsForGC.count()
1256+
<< " candidates");
12551257

12561258
size_t NumCollectedFuns = 0;
12571259

12581260
scope_exit FinishGC = [&NumCollectedFuns] {
1259-
llvm::errs() << "> Finished GC run (collected " << NumCollectedFuns
1260-
<< " functions)\n";
1261+
PHASAR_LOG_LEVEL(INFO, "> Finished GC run (collected " << NumCollectedFuns
1262+
<< " functions)");
12611263
};
12621264

12631265
auto FinalCandidates = getCollectableFunctions();

include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEFeatureTaintAnalysis.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,13 @@ class IDEFeatureTaintAnalysis
374374

375375
} // namespace psr
376376

377+
namespace std {
378+
template <> struct hash<psr::IDEFeatureTaintEdgeFact> {
379+
size_t
380+
operator()(const psr::IDEFeatureTaintEdgeFact &EdgeFact) const noexcept {
381+
return hash_value(EdgeFact);
382+
}
383+
};
384+
} // namespace std
385+
377386
#endif // PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEFEATURETAINTANALYSIS_H

unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEFeatureTaintAnalysisTest.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ class IDEFeatureTaintAnalysisTest : public ::testing::Test {
129129
*HA, EntryPoints, Generator);
130130

131131
IDESolver IIASolver(IIAProblem, &HA->getICFG());
132-
IIASolver.solve();
132+
// IterativeIDESolver IIASolver(&IIAProblem, &HA->getICFG());
133+
auto Results = IIASolver.solve();
133134

134135
// do the comparison
135136
for (const auto &[InstLoc, VarName, ExpectedVal] : GroundTruth) {
@@ -157,7 +158,7 @@ class IDEFeatureTaintAnalysisTest : public ::testing::Test {
157158
IIASolver.dumpResults(llvm::errs());
158159
llvm::errs()
159160
<< "\n======================================================\n";
160-
printDump(HA->getProjectIRDB(), IIASolver.getSolverResults());
161+
printDump(HA->getProjectIRDB(), Results);
161162
}
162163
}
163164

@@ -166,10 +167,10 @@ class IDEFeatureTaintAnalysisTest : public ::testing::Test {
166167
}
167168

168169
// See vara::PhasarTaintAnalysis::taintsForInst
169-
[[nodiscard]] inline TaintSetT
170-
taintsForInst(const llvm::Instruction *Inst,
171-
SolverResults<const llvm::Instruction *, const llvm::Value *,
172-
IDEFeatureTaintEdgeFact> SR) {
170+
[[nodiscard]] inline TaintSetT taintsForInst(
171+
const llvm::Instruction *Inst,
172+
GenericSolverResults<const llvm::Instruction *, const llvm::Value *,
173+
IDEFeatureTaintEdgeFact> SR) {
173174

174175
if (const auto *Ret = llvm::dyn_cast<llvm::ReturnInst>(Inst)) {
175176
if (Ret->getNumOperands() == 0) {
@@ -205,10 +206,11 @@ class IDEFeatureTaintAnalysisTest : public ::testing::Test {
205206
return AggregatedTaints;
206207
}
207208

208-
void printDump(const LLVMProjectIRDB &IRDB,
209-
SolverResults<const llvm::Instruction *, const llvm::Value *,
210-
IDEFeatureTaintEdgeFact>
211-
SR) {
209+
void
210+
printDump(const LLVMProjectIRDB &IRDB,
211+
GenericSolverResults<const llvm::Instruction *, const llvm::Value *,
212+
IDEFeatureTaintEdgeFact>
213+
SR) {
212214
const llvm::Function *CurrFun = nullptr;
213215
for (const auto *Inst : IRDB.getAllInstructions()) {
214216
if (CurrFun != Inst->getFunction()) {

0 commit comments

Comments
 (0)