99
1010#include " phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"
1111
12- #include " phasar/Config/Configuration.h"
1312#include " phasar/ControlFlow/CallGraph.h"
1413#include " phasar/ControlFlow/CallGraphAnalysisType.h"
1514#include " phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h"
2423#include " phasar/Utils/MaybeUniquePtr.h"
2524#include " phasar/Utils/PAMMMacros.h"
2625#include " phasar/Utils/Soundness.h"
27- #include " phasar/Utils/TypeTraits.h"
28- #include " phasar/Utils/Utilities.h"
2926
30- #include " llvm/ADT/STLExtras.h"
3127#include " llvm/ADT/SmallVector.h"
3228#include " llvm/ADT/StringSwitch.h"
3329#include " llvm/IR/Function.h"
3430#include " llvm/IR/Instruction.h"
3531#include " llvm/Support/ErrorHandling.h"
3632
37- #include < cstdint>
3833#include < utility>
3934
4035namespace psr {
4136struct LLVMBasedICFG ::Builder {
4237 LLVMProjectIRDB *IRDB = nullptr ;
43- LLVMAliasInfoRef PT{};
4438 LLVMTypeHierarchy *TH{};
39+ Resolver *Res = nullptr ;
4540 CallGraphBuilder<const llvm::Instruction *, const llvm::Function *>
4641 CGBuilder{};
47- std::unique_ptr<Resolver> Res = nullptr ;
4842 llvm::DenseSet<const llvm::Function *> VisitedFunctions{};
4943 llvm::SmallVector<llvm::Function *, 1 > UserEntryPoints{};
5044
@@ -321,6 +315,28 @@ bool LLVMBasedICFG::Builder::constructDynamicCall(const llvm::Instruction *CS) {
321315 return NewTargetsFound;
322316}
323317
318+ void LLVMBasedICFG::initialize (LLVMProjectIRDB *IRDB, Resolver &CGResolver,
319+ llvm::ArrayRef<std::string> EntryPoints,
320+ LLVMTypeHierarchy *TH, Soundness S,
321+ bool IncludeGlobals) {
322+ Builder B{IRDB, this ->TH .get (), &CGResolver};
323+
324+ B.initEntryPoints (EntryPoints);
325+ B.initGlobalsAndWorkList (this , IncludeGlobals);
326+
327+ PHASAR_LOG_LEVEL_CAT (
328+ INFO, " LLVMBasedICFG" ,
329+ " Starting ICFG construction "
330+ << std::chrono::steady_clock::now ().time_since_epoch ().count ());
331+
332+ this ->CG = B.buildCallGraph (S);
333+
334+ PHASAR_LOG_LEVEL_CAT (
335+ INFO, " LLVMBasedICFG" ,
336+ " Finished ICFG construction "
337+ << std::chrono::steady_clock::now ().time_since_epoch ().count ());
338+ }
339+
324340LLVMBasedICFG::LLVMBasedICFG (LLVMProjectIRDB *IRDB,
325341 CallGraphAnalysisType CGType,
326342 llvm::ArrayRef<std::string> EntryPoints,
@@ -333,29 +349,29 @@ LLVMBasedICFG::LLVMBasedICFG(LLVMProjectIRDB *IRDB,
333349 this ->TH = std::make_unique<LLVMTypeHierarchy>(*IRDB);
334350 }
335351
336- Builder B{IRDB, PT, this ->TH .get ()};
337352 LLVMAliasInfo PTOwn;
338353
339354 if (!PT && CGType == CallGraphAnalysisType::OTF) {
340355 PTOwn = std::make_unique<LLVMAliasSet>(IRDB);
341- B. PT = PTOwn.asRef ();
356+ PT = PTOwn.asRef ();
342357 }
343358
344- B. Res = Resolver::create (CGType, IRDB, this ->TH .get (), this , B. PT );
345- B. initEntryPoints ( EntryPoints);
346- B. initGlobalsAndWorkList ( this , IncludeGlobals);
359+ auto CGRes = Resolver::create (CGType, IRDB, this ->TH .get (), PT);
360+ initialize (IRDB, *CGRes, EntryPoints, TH, S, IncludeGlobals );
361+ }
347362
348- PHASAR_LOG_LEVEL_CAT (
349- INFO, " LLVMBasedICFG" ,
350- " Starting ICFG construction "
351- << std::chrono::steady_clock::now ().time_since_epoch ().count ());
363+ LLVMBasedICFG::LLVMBasedICFG (LLVMProjectIRDB *IRDB, Resolver &CGResolver,
364+ llvm::ArrayRef<std::string> EntryPoints,
365+ LLVMTypeHierarchy *TH, Soundness S,
366+ bool IncludeGlobals)
367+ : IRDB(IRDB), TH(TH) {
368+ assert (IRDB != nullptr );
352369
353- this ->CG = B.buildCallGraph (S);
370+ if (!TH) {
371+ this ->TH = std::make_unique<LLVMTypeHierarchy>(*IRDB);
372+ }
354373
355- PHASAR_LOG_LEVEL_CAT (
356- INFO, " LLVMBasedICFG" ,
357- " Finished ICFG construction "
358- << std::chrono::steady_clock::now ().time_since_epoch ().count ());
374+ initialize (IRDB, CGResolver, EntryPoints, TH, S, IncludeGlobals);
359375}
360376
361377LLVMBasedICFG::LLVMBasedICFG (CallGraph<n_t , f_t > CG, LLVMProjectIRDB *IRDB,
0 commit comments