Skip to content

Commit 5a9c59f

Browse files
fabianbs96MMoryMartin Mory
authored
Reorder Analysis Dependencies (#530)
* Swap ordering of IDE- and IFDS tabulation problem * Adapt analysis problems to new tabulation problem (WIP) * Continue adapting the IFDS/IDE problems to the new tabulation problem * Complete rewriting * Replace boost::trim with llvm::StringRef::trim * Update myphasartool and re-sync use-phasar-as-library/myphasartool * Vector EntryPoints * pre-commit * pre-commit * make edge function overrides in IFDSTabulationProblem final, consistent with conceptual property, forbidding IFDS problem to override anything related to the edge domain * dummy commit * Revert "dummy commit" This reverts commit edd65ec. Co-authored-by: Martin Mory <mmo@mail.upb.de> Co-authored-by: Martin Mory <linuxfan91@googlemail.com>
1 parent bde38ab commit 5a9c59f

File tree

132 files changed

+1985
-2507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+1985
-2507
lines changed

include/phasar/Controller/AnalysisController.h

Lines changed: 45 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
#ifndef PHASAR_CONTROLLER_ANALYSISCONTROLLER_H
1111
#define PHASAR_CONTROLLER_ANALYSISCONTROLLER_H
1212

13+
#include "phasar/Controller/AnalysisControllerEmitterOptions.h"
1314
#include "phasar/DB/LLVMProjectIRDB.h"
15+
#include "phasar/PhasarLLVM/AnalysisStrategy/HelperAnalyses.h"
1416
#include "phasar/PhasarLLVM/AnalysisStrategy/Strategies.h"
15-
#include "phasar/PhasarLLVM/AnalysisStrategy/WholeProgramAnalysis.h"
1617
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"
17-
#include "phasar/PhasarLLVM/ControlFlow/Resolver/CallGraphAnalysisType.h"
1818
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IFDSIDESolverConfig.h"
1919
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IDESolver.h"
2020
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IFDSSolver.h"
21+
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/SolverResults.h"
2122
#include "phasar/PhasarLLVM/DataFlowSolver/Mono/Solver/InterMonoSolver.h"
2223
#include "phasar/PhasarLLVM/DataFlowSolver/Mono/Solver/IntraMonoSolver.h"
2324
#include "phasar/PhasarLLVM/Pointer/LLVMBasedPointsToAnalysis.h"
@@ -35,31 +36,9 @@
3536

3637
namespace psr {
3738

38-
enum class AnalysisControllerEmitterOptions : uint32_t {
39-
None = 0,
40-
EmitIR = (1 << 0),
41-
EmitRawResults = (1 << 1),
42-
EmitTextReport = (1 << 2),
43-
EmitGraphicalReport = (1 << 3),
44-
EmitESGAsDot = (1 << 4),
45-
EmitTHAsText = (1 << 5),
46-
EmitTHAsDot = (1 << 6),
47-
EmitTHAsJson = (1 << 7),
48-
// EmitCGAsText = (1 << 8),
49-
EmitCGAsDot = (1 << 9),
50-
// EmitCGAsJson = (1 << 10),
51-
EmitPTAAsText = (1 << 11),
52-
EmitPTAAsDot = (1 << 12),
53-
EmitPTAAsJson = (1 << 13),
54-
EmitStatisticsAsJson = (1 << 14),
55-
};
56-
5739
class AnalysisController {
5840
private:
59-
LLVMProjectIRDB &IRDB;
60-
LLVMTypeHierarchy TH;
61-
LLVMPointsToSet PT;
62-
LLVMBasedICFG ICF;
41+
HelperAnalyses &HA;
6342
std::vector<DataFlowAnalysisType> DataFlowAnalyses;
6443
std::vector<std::string> AnalysisConfigs;
6544
std::vector<std::string> EntryPoints;
@@ -69,8 +48,6 @@ class AnalysisController {
6948
std::string ProjectID;
7049
std::filesystem::path ResultDirectory;
7150
IFDSIDESolverConfig SolverConfig;
72-
[[maybe_unused]] Soundness SoundnessLevel;
73-
[[maybe_unused]] bool AutoGlobalSupport;
7451

7552
///
7653
/// \brief The maximum length of the CallStrings used in the InterMonoSolver
@@ -106,79 +83,64 @@ class AnalysisController {
10683
void executeInterMonoSolverTest();
10784
void executeInterMonoTaint();
10885

109-
template <typename AnalysisTy, bool WithConfig = false>
110-
void executeIntraMonoAnalysis() {
111-
executeAnalysis<IntraMonoSolver_P<AnalysisTy>, AnalysisTy, WithConfig>();
86+
template <typename ProblemTy>
87+
void executeIntraMonoAnalysis(ProblemTy &Problem) {
88+
IntraMonoSolver Solver(Problem);
89+
Solver.solve();
90+
emitRequestedDataFlowResults(Solver);
11291
}
11392

114-
template <typename AnalysisTy, bool WithConfig = false>
115-
void executeInterMonoAnalysis() {
116-
executeAnalysis<InterMonoSolver_P<AnalysisTy, 3>, AnalysisTy, WithConfig>();
93+
template <typename ProblemTy>
94+
void executeInterMonoAnalysis(ProblemTy &Problem) {
95+
InterMonoSolver_P<ProblemTy, 3> Solver(Problem);
96+
Solver.solve();
97+
emitRequestedDataFlowResults(Solver);
11798
}
11899

119-
template <typename AnalysisTy, bool WithConfig = false>
120-
void executeIFDSAnalysis() {
121-
executeAnalysis<IFDSSolver_P<AnalysisTy>, AnalysisTy, WithConfig>();
100+
template <typename ProblemTy> void executeIFDSAnalysis(ProblemTy &Problem) {
101+
IFDSSolver Solver(Problem, &HA.getICFG());
102+
Solver.solve();
103+
emitRequestedDataFlowResults(Solver);
122104
}
123105

124-
template <typename AnalysisTy, bool WithConfig = false>
125-
void executeIDEAnalysis() {
126-
executeAnalysis<IDESolver_P<AnalysisTy>, AnalysisTy, WithConfig>();
106+
template <typename ProblemTy> void executeIDEAnalysis(ProblemTy &Problem) {
107+
IDESolver Solver(Problem, &HA.getICFG());
108+
Solver.solve();
109+
emitRequestedDataFlowResults(Solver);
127110
}
128111

129-
template <class Solver_P, typename AnalysisTy, bool WithConfig>
130-
void executeAnalysis() {
131-
if constexpr (WithConfig) {
132-
std::string AnalysisConfigPath =
133-
!AnalysisConfigs.empty() ? AnalysisConfigs[0] : "";
134-
auto Config =
135-
!AnalysisConfigPath.empty()
136-
? TaintConfig(IRDB, parseTaintConfig(AnalysisConfigPath))
137-
: TaintConfig(IRDB);
138-
WholeProgramAnalysis<Solver_P, AnalysisTy> WPA(
139-
SolverConfig, IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
140-
WPA.solve();
141-
emitRequestedDataFlowResults(WPA);
142-
WPA.releaseAllHelperAnalyses();
143-
} else {
144-
WholeProgramAnalysis<Solver_P, AnalysisTy> WPA(
145-
SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
146-
WPA.solve();
147-
emitRequestedDataFlowResults(WPA);
148-
WPA.releaseAllHelperAnalyses();
149-
}
150-
}
112+
TaintConfig makeTaintConfig();
151113

152-
template <typename T> void emitRequestedDataFlowResults(T &WPA) {
114+
template <typename T> void emitRequestedDataFlowResults(T &Solver) {
153115
if (EmitterOptions & AnalysisControllerEmitterOptions::EmitTextReport) {
154116
if (!ResultDirectory.empty()) {
155117
if (auto OFS =
156118
openFileStream(ResultDirectory.string() + "/psr-report.txt")) {
157-
WPA.emitTextReport(*OFS);
119+
Solver.emitTextReport(*OFS);
158120
}
159121
} else {
160-
WPA.emitTextReport(llvm::outs());
122+
Solver.emitTextReport(llvm::outs());
161123
}
162124
}
163125
if (EmitterOptions &
164126
AnalysisControllerEmitterOptions::EmitGraphicalReport) {
165127
if (!ResultDirectory.empty()) {
166128
if (auto OFS =
167129
openFileStream(ResultDirectory.string() + "/psr-report.html")) {
168-
WPA.emitGraphicalReport(*OFS);
130+
Solver.emitGraphicalReport(*OFS);
169131
}
170132
} else {
171-
WPA.emitGraphicalReport(llvm::outs());
133+
Solver.emitGraphicalReport(llvm::outs());
172134
}
173135
}
174136
if (EmitterOptions & AnalysisControllerEmitterOptions::EmitRawResults) {
175137
if (!ResultDirectory.empty()) {
176138
if (auto OFS = openFileStream(ResultDirectory.string() +
177139
"/psr-raw-results.txt")) {
178-
WPA.dumpResults(*OFS);
140+
Solver.dumpResults(*OFS);
179141
}
180142
} else {
181-
WPA.dumpResults(llvm::outs());
143+
Solver.dumpResults(llvm::outs());
182144
}
183145
}
184146
if (EmitterOptions & AnalysisControllerEmitterOptions::EmitESGAsDot) {
@@ -188,18 +150,14 @@ class AnalysisController {
188150
}
189151

190152
public:
191-
AnalysisController(LLVMProjectIRDB &IRDB,
192-
std::vector<DataFlowAnalysisType> DataFlowAnalyses,
193-
std::vector<std::string> AnalysisConfigs,
194-
PointerAnalysisType PTATy, CallGraphAnalysisType CGTy,
195-
Soundness SoundnessLevel, bool AutoGlobalSupport,
196-
std::vector<std::string> EntryPoints,
197-
AnalysisStrategy Strategy,
198-
AnalysisControllerEmitterOptions EmitterOptions,
199-
IFDSIDESolverConfig SolverConfig,
200-
const std::string &ProjectID = "default-phasar-project",
201-
std::filesystem::path OutDirectory = {},
202-
const nlohmann::json &PrecomputedPointsToInfo = {});
153+
explicit AnalysisController(
154+
HelperAnalyses &HA, std::vector<DataFlowAnalysisType> DataFlowAnalyses,
155+
std::vector<std::string> AnalysisConfigs,
156+
std::vector<std::string> EntryPoints, AnalysisStrategy Strategy,
157+
AnalysisControllerEmitterOptions EmitterOptions,
158+
IFDSIDESolverConfig SolverConfig,
159+
const std::string &ProjectID = "default-phasar-project",
160+
const std::string &OutDirectory = "");
203161

204162
~AnalysisController() = default;
205163

@@ -209,6 +167,13 @@ class AnalysisController {
209167
AnalysisController &operator=(const AnalysisController &&) = delete;
210168

211169
void executeAs(AnalysisStrategy Strategy);
170+
171+
static constexpr bool
172+
needsToEmitPTA(AnalysisControllerEmitterOptions EmitterOptions) {
173+
return (EmitterOptions & AnalysisControllerEmitterOptions::EmitPTAAsDot) ||
174+
(EmitterOptions & AnalysisControllerEmitterOptions::EmitPTAAsJson) ||
175+
(EmitterOptions & AnalysisControllerEmitterOptions::EmitPTAAsText);
176+
}
212177
};
213178

214179
} // namespace psr
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/******************************************************************************
2+
* Copyright (c) 2022 Philipp Schubert.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Philipp Schubert and others
8+
*****************************************************************************/
9+
10+
#ifndef PHASAR_CONTROLLER_ANALYSISCONTROLLEREMITTEROPTIONS_H
11+
#define PHASAR_CONTROLLER_ANALYSISCONTROLLEREMITTEROPTIONS_H
12+
13+
namespace psr {
14+
enum class AnalysisControllerEmitterOptions {
15+
None = 0,
16+
EmitIR = (1 << 0),
17+
EmitRawResults = (1 << 1),
18+
EmitTextReport = (1 << 2),
19+
EmitGraphicalReport = (1 << 3),
20+
EmitESGAsDot = (1 << 4),
21+
EmitTHAsText = (1 << 5),
22+
EmitTHAsDot = (1 << 6),
23+
EmitTHAsJson = (1 << 7),
24+
EmitCGAsText = (1 << 8),
25+
EmitCGAsDot = (1 << 9),
26+
EmitCGAsJson = (1 << 10),
27+
EmitPTAAsText = (1 << 11),
28+
EmitPTAAsDot = (1 << 12),
29+
EmitPTAAsJson = (1 << 13),
30+
EmitStatisticsAsText = (1 << 14),
31+
EmitStatisticsAsJson = (1 << 15),
32+
};
33+
} // namespace psr
34+
35+
#endif // PHASAR_CONTROLLER_ANALYSISCONTROLLEREMITTEROPTIONS_H
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/******************************************************************************
2+
* Copyright (c) 2022 Philipp Schubert.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Fabian Schiebel, Philipp Schubert and others
8+
*****************************************************************************/
9+
10+
#ifndef PHASAR_PHASARLLVM_ANALYSISSTRATEGY_HELPERANALYSES_H_
11+
#define PHASAR_PHASARLLVM_ANALYSISSTRATEGY_HELPERANALYSES_H_
12+
13+
#include "phasar/PhasarLLVM/AnalysisStrategy/HelperAnalysisConfig.h"
14+
15+
#include "nlohmann/json.hpp"
16+
17+
#include <memory>
18+
#include <optional>
19+
#include <set>
20+
#include <vector>
21+
22+
namespace psr {
23+
class LLVMProjectIRDB;
24+
class LLVMTypeHierarchy;
25+
class LLVMBasedICFG;
26+
class LLVMPointsToInfo;
27+
28+
class HelperAnalyses { // NOLINT(cppcoreguidelines-special-member-functions)
29+
public:
30+
explicit HelperAnalyses(std::string IRFile,
31+
std::optional<nlohmann::json> PrecomputedPTS,
32+
PointerAnalysisType PTATy, bool AllowLazyPTS,
33+
std::vector<std::string> EntryPoints,
34+
CallGraphAnalysisType CGTy, Soundness SoundnessLevel,
35+
bool AutoGlobalSupport);
36+
37+
explicit HelperAnalyses(std::string IRFile,
38+
std::vector<std::string> EntryPoints,
39+
HelperAnalysisConfig Config = {});
40+
~HelperAnalyses();
41+
42+
LLVMProjectIRDB &getProjectIRDB();
43+
LLVMPointsToInfo &getPointsToInfo();
44+
LLVMTypeHierarchy &getTypeHierarchy();
45+
LLVMBasedICFG &getICFG();
46+
47+
private:
48+
std::unique_ptr<LLVMProjectIRDB> IRDB;
49+
std::unique_ptr<LLVMPointsToInfo> PT;
50+
std::unique_ptr<LLVMTypeHierarchy> TH;
51+
std::unique_ptr<LLVMBasedICFG> ICF;
52+
53+
// IRDB
54+
std::string IRFile;
55+
56+
// PTS
57+
std::optional<nlohmann::json> PrecomputedPTS;
58+
PointerAnalysisType PTATy{};
59+
bool AllowLazyPTS{};
60+
61+
// ICF
62+
std::vector<std::string> EntryPoints;
63+
CallGraphAnalysisType CGTy{};
64+
Soundness SoundnessLevel{};
65+
bool AutoGlobalSupport{};
66+
};
67+
} // namespace psr
68+
69+
#endif // PHASAR_PHASARLLVM_ANALYSISSTRATEGY_HELPERANALYSES_H_
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/******************************************************************************
2+
* Copyright (c) 2022 Philipp Schubert.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Fabian Schiebel and others
8+
*****************************************************************************/
9+
10+
#ifndef PHASAR_PHASARLLVM_ANALYSISSTRATEGY_HELPERANALYSISCONFIG_H
11+
#define PHASAR_PHASARLLVM_ANALYSISSTRATEGY_HELPERANALYSISCONFIG_H
12+
13+
#include "phasar/PhasarLLVM/ControlFlow/Resolver/CallGraphAnalysisType.h"
14+
#include "phasar/PhasarLLVM/Pointer/PointerAnalysisType.h"
15+
16+
#include "nlohmann/json.hpp"
17+
#include "phasar/Utils/Soundness.h"
18+
19+
#include <optional>
20+
21+
namespace psr {
22+
struct HelperAnalysisConfig {
23+
std::optional<nlohmann::json> PrecomputedPTS = std::nullopt;
24+
PointerAnalysisType PTATy = PointerAnalysisType::CFLAnders;
25+
CallGraphAnalysisType CGTy = CallGraphAnalysisType::OTF;
26+
Soundness SoundnessLevel = Soundness::Soundy;
27+
bool AutoGlobalSupport = true;
28+
bool AllowLazyPTS = true;
29+
};
30+
} // namespace psr
31+
32+
#endif // PHASAR_PHASARLLVM_ANALYSISSTRATEGY_HELPERANALYSISCONFIG_H

0 commit comments

Comments
 (0)