Skip to content

Commit e909fd2

Browse files
committed
make additional options available to phasar-llvm
1 parent 7b759b1 commit e909fd2

5 files changed

Lines changed: 56 additions & 36 deletions

File tree

include/phasar/Controller/AnalysisController.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class AnalysisController {
6262
std::string ProjectID;
6363
std::string OutDirectory;
6464
boost::filesystem::path ResultDirectory;
65-
[[maybe_unused]] Soundness S;
65+
[[maybe_unused]] Soundness SoundnessLevel;
66+
[[maybe_unused]] bool AutoGlobalSupport;
6667

6768
///
6869
/// \brief The maximum length of the CallStrings used in the InterMonoSolver
@@ -117,7 +118,8 @@ class AnalysisController {
117118
std::vector<DataFlowAnalysisKind> DataFlowAnalyses,
118119
std::vector<std::string> AnalysisConfigs,
119120
PointerAnalysisType PTATy, CallGraphAnalysisType CGTy,
120-
Soundness S, const std::set<std::string> &EntryPoints,
121+
Soundness SoundnessLevel, bool AutoGlobalSupport,
122+
const std::set<std::string> &EntryPoints,
121123
AnalysisStrategy Strategy,
122124
AnalysisControllerEmitterOptions EmitterOptions,
123125
const std::string &ProjectID = "default-phasar-project",

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class LLVMBasedICFG
7474
LLVMPointsToInfo *PT;
7575
std::unique_ptr<Resolver> Res;
7676
llvm::DenseSet<const llvm::Function *> VisitedFunctions;
77-
llvm::SmallPtrSet<llvm::Function *, 2> UserEntryPoints;
77+
std::unordered_set<llvm::Function *> UserEntryPoints;
7878

7979
GlobalCtorTy GlobalCtors;
8080
GlobalDtorTy GlobalDtors;

lib/Controller/AnalysisController.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@ bool needsToEmitPTA(AnalysisControllerEmitterOptions EmitterOptions) {
7777
AnalysisController::AnalysisController(
7878
ProjectIRDB &IRDB, std::vector<DataFlowAnalysisKind> DataFlowAnalyses,
7979
std::vector<std::string> AnalysisConfigs, PointerAnalysisType PTATy,
80-
CallGraphAnalysisType CGTy, Soundness S,
81-
const std::set<std::string> &EntryPoints, AnalysisStrategy Strategy,
82-
AnalysisControllerEmitterOptions EmitterOptions,
80+
CallGraphAnalysisType CGTy, Soundness SoundnessLevel,
81+
bool AutomatedGlobalSupport, const std::set<std::string> &EntryPoints,
82+
AnalysisStrategy Strategy, AnalysisControllerEmitterOptions EmitterOptions,
8383
const std::string &ProjectID, const std::string &OutDirectory)
8484
: IRDB(IRDB), TH(IRDB), PT(IRDB, !needsToEmitPTA(EmitterOptions), PTATy),
85-
ICF(IRDB, CGTy, EntryPoints, &TH, &PT),
85+
ICF(IRDB, CGTy, EntryPoints, &TH, &PT, SoundnessLevel, AutoGlobalSupport),
8686
DataFlowAnalyses(std::move(DataFlowAnalyses)),
8787
AnalysisConfigs(std::move(AnalysisConfigs)), EntryPoints(EntryPoints),
8888
Strategy(Strategy), EmitterOptions(EmitterOptions), ProjectID(ProjectID),
89-
OutDirectory(OutDirectory), S(S) {
89+
OutDirectory(OutDirectory), SoundnessLevel(SoundnessLevel),
90+
AutoGlobalSupport(AutoGlobalSupport) {
9091
if (!OutDirectory.empty()) {
9192
// create directory for results
9293
ResultDirectory = OutDirectory + "/" + ProjectID + "-" + createTimeStamp();

lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,39 +145,43 @@ LLVMBasedICFG::LLVMBasedICFG(ProjectIRDB &IRDB, CallGraphAnalysisType CGType,
145145
this->PT = new LLVMPointsToSet(IRDB);
146146
UserPTInfos = false;
147147
}
148-
149148
if (this->PT == nullptr) {
150149
llvm::report_fatal_error("LLVMPointsToInfo not passed and "
151150
"CallGraphAnalysisType::OTF was not specified.");
152151
}
153-
154-
for (const auto &EntryPoint : EntryPoints) {
155-
auto *F = IRDB.getFunctionDefinition(EntryPoint);
156-
if (F == nullptr) {
157-
llvm::report_fatal_error("Could not retrieve function for entry point");
152+
if (EntryPoints.count("__ALL__")) {
153+
// Handle the special case in which a user wishes to treat all functions as
154+
// entry points.
155+
auto Funs = IRDB.getAllFunctions();
156+
for (const auto *Fun : Funs) {
157+
if (!Fun->isDeclaration() && Fun->hasName()) {
158+
UserEntryPoints.insert(IRDB.getFunctionDefinition(Fun->getName()));
159+
}
160+
}
161+
} else {
162+
for (const auto &EntryPoint : EntryPoints) {
163+
auto *F = IRDB.getFunctionDefinition(EntryPoint);
164+
if (F == nullptr) {
165+
llvm::report_fatal_error("Could not retrieve function for entry point");
166+
}
167+
UserEntryPoints.insert(F);
158168
}
159-
UserEntryPoints.insert(F);
160169
}
161-
162170
if (IncludeGlobals) {
163171
assert(IRDB.getNumberOfModules() == 1 &&
164172
"IncludeGlobals is currently only supported for WPA");
165-
166173
const auto *GlobCtor =
167174
buildCRuntimeGlobalCtorsDtorsModel(*IRDB.getWPAModule());
168-
169175
FunctionWL.push_back(GlobCtor);
170176
} else {
171177
FunctionWL.insert(FunctionWL.end(), UserEntryPoints.begin(),
172178
UserEntryPoints.end());
173179
}
174-
175180
// instantiate the respective resolver type
176181
Res = makeResolver(IRDB, CGType, *this->TH, *this->PT);
177182
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
178183
<< "Starting CallGraphAnalysisType: " << CGType);
179184
VisitedFunctions.reserve(IRDB.getAllFunctions().size());
180-
181185
bool FixpointReached;
182186
do {
183187
FixpointReached = true;
@@ -192,15 +196,13 @@ LLVMBasedICFG::LLVMBasedICFG(ProjectIRDB &IRDB, CallGraphAnalysisType CGType,
192196
}
193197

194198
} while (!FixpointReached);
195-
196199
for (const auto &[IndirectCall, Targets] : IndirectCalls) {
197200
if (Targets == 0) {
198201
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), WARNING)
199202
<< "No callees found for callsite "
200203
<< llvmIRToString(IndirectCall));
201204
}
202205
}
203-
204206
REG_COUNTER("CG Vertices", getNumOfVertices(), PAMM_SEVERITY_LEVEL::Full);
205207
REG_COUNTER("CG Edges", getNumOfEdges(), PAMM_SEVERITY_LEVEL::Full);
206208
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)

tools/phasar-llvm/phasar-llvm.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@
2828

2929
using namespace psr;
3030

31+
namespace std {
32+
33+
std::ostream &operator<<(std::ostream &OS, const std::vector<std::string> &V) {
34+
for (const auto &Str : V) {
35+
OS << Str;
36+
if (Str != V.back()) {
37+
OS << ", ";
38+
}
39+
}
40+
return OS;
41+
}
42+
43+
} // namespace std
44+
45+
namespace {
46+
3147
constexpr char MoreHelp[] =
3248
#include "../phasar-llvm_more_help.txt"
3349
;
@@ -155,6 +171,8 @@ void validateParamAnalysisConfig(const std::vector<std::string> &Configs) {
155171
}
156172
}
157173

174+
} // anonymous namespace
175+
158176
int main(int Argc, const char **Argv) {
159177
// handling the command line parameters
160178
std::string ConfigFile;
@@ -175,14 +193,15 @@ int main(int Argc, const char **Argv) {
175193
// clang-format off
176194
Config.add_options()
177195
("module,m", boost::program_options::value<std::vector<std::string>>()->multitoken()->zero_tokens()->composing()->notifier(&validateParamModule), "Path to the module(s) under analysis")
178-
("entry-points,E", boost::program_options::value<std::vector<std::string>>()->multitoken()->zero_tokens()->composing(), "Set the entry point(s) to be used")
196+
("entry-points,E", boost::program_options::value<std::vector<std::string>>()->multitoken()->zero_tokens()->composing()->default_value(std::vector({std::string("main")})), "Set the entry point(s) to be used; use '__ALL__' to specify all available function definitions as entry points")
179197
("data-flow-analysis,D", boost::program_options::value<std::vector<std::string>>()->multitoken()->zero_tokens()->composing()/*->notifier(&validateParamDataFlowAnalysis)*/, "Set the analysis to be run")
180198
("analysis-strategy", boost::program_options::value<std::string>()->default_value("WPA")->notifier(&validateParamAnalysisStrategy))
181199
("analysis-config", boost::program_options::value<std::vector<std::string>>()->multitoken()->zero_tokens()->composing()->notifier(&validateParamAnalysisConfig), "Set the analysis's configuration (if required)")
182200
("pointer-analysis,P", boost::program_options::value<std::string>()->notifier(&validateParamPointerAnalysis)->default_value("CFLAnders"), "Set the points-to analysis to be used (CFLSteens, CFLAnders). CFLSteens is ~O(N) but inaccurate while CFLAnders O(N^3) but more accurate.")
183201
("call-graph-analysis,C", boost::program_options::value<std::string>()->notifier(&validateParamCallGraphAnalysis)->default_value("OTF"), "Set the call-graph algorithm to be used (NORESOLVE, CHA, RTA, DTA, VTA, OTF)")
184202
("soundness", boost::program_options::value<std::string>()->notifier(&validateSoundnessFlag)->default_value("Soundy"), "Set the soundiness level to be used (Sound, Soundy, Unsound)")
185-
("classhierarchy-analysis,H", "Class-hierarchy analysis")
203+
("auto-globals", boost::program_options::value<bool>()->default_value(true), "Enable automated global support")
204+
("classhierarchy-analysis,H", "Class-hierarchy analysis")
186205
("statistical-analysis,S", "Statistics")
187206
("mwa,M", "Enable Modulewise-program analysis mode")
188207
("printedgerec,R", "Print exploded-super-graph edge recorder")
@@ -358,22 +377,17 @@ int main(int Argc, const char **Argv) {
358377
AnalysisConfigs = PhasarConfig::VariablesMap()["analysis-config"]
359378
.as<std::vector<std::string>>();
360379
}
361-
std::set<std::string> EntryPoints;
362-
if (PhasarConfig::VariablesMap().count("entry-points")) {
363-
auto Entries = vectorToSet(PhasarConfig::VariablesMap()["entry-points"]
364-
.as<std::vector<std::string>>());
365-
EntryPoints.insert(Entries.begin(), Entries.end());
366-
} else {
367-
EntryPoints.insert("main");
368-
}
380+
std::set<std::string> EntryPoints =
381+
vectorToSet(PhasarConfig::VariablesMap()["entry-points"]
382+
.as<std::vector<std::string>>());
369383
// setup pointer algorithm to be used
370384
PointerAnalysisType PTATy = toPointerAnalysisType(
371385
PhasarConfig::VariablesMap()["pointer-analysis"].as<std::string>());
372386
// setup call-graph algorithm to be used
373387
CallGraphAnalysisType CGTy = toCallGraphAnalysisType(
374388
PhasarConfig::VariablesMap()["call-graph-analysis"].as<std::string>());
375389
// setup soudiness level to be used
376-
Soundness S =
390+
Soundness SoundnessLevel =
377391
toSoundness(PhasarConfig::VariablesMap()["soundness"].as<std::string>());
378392
// setup the emitter options to display the computed analysis results
379393
AnalysisControllerEmitterOptions EmitterOptions =
@@ -430,8 +444,9 @@ int main(int Argc, const char **Argv) {
430444
if (PhasarConfig::VariablesMap().count("project-id")) {
431445
ProjectID = PhasarConfig::VariablesMap()["project-id"].as<std::string>();
432446
}
433-
AnalysisController Controller(IRDB, DataFlowAnalyses, AnalysisConfigs, PTATy,
434-
CGTy, S, EntryPoints, Strategy, EmitterOptions,
435-
ProjectID, OutDirectory);
447+
AnalysisController Controller(
448+
IRDB, DataFlowAnalyses, AnalysisConfigs, PTATy, CGTy, SoundnessLevel,
449+
PhasarConfig::VariablesMap()["auto-globals"].as<bool>(), EntryPoints,
450+
Strategy, EmitterOptions, ProjectID, OutDirectory);
436451
return 0;
437452
}

0 commit comments

Comments
 (0)