Closed william4code closed 1 year ago
Hi @william4code, when using PhASAR in a LLVM pass I recommend you to use a module-pass. In the run
function you then get a llvm::Module &
as parameter which you can use to instantiate a psr::LLVMProjectIRDB
. Phasar will then not attempt to take ownership over the LLVM module and not add preprocessing metadata to the IR. You also may want to turn off auto-globals support in the LLVMBasedICFG
as it also modifies the IR.
An example invocation may look like this:
llvm::PreservedAnalyses PsrModulePass::run(Module& M, ModuleAnalysisManager& AM) {
std::vector<std::string> EntryPoints = {"main"}; // Or whatever entry-points you need
// -- initialize the helper analyses
psr::LLVMProjectIRDB IRDB(&M);
psr::LLVMTypeHierarchy TH(IRDB);
psr::LLVMAliasSet AS(&IRDB);
psr::LLVMBasedICFG ICF(&IRDB, psr::CallGraphAnalysisType::OTF, EntryPoints, &TH, &AS, psr::Soundness::Soundy, /*AutoGlobals*/false);
// -- optional: perform some data-flow analyses
psr::IDELinearConstantAnalysis LCA(&IRDB, &ICF, EntryPoints);
auto Results = psr::solveIDEProblem(LCA, ICF);
// -- do something with the results
return llvm::PreservedAnalyses::all();
}
Does that answer you question?
Hi @william4code, when using PhASAR in a LLVM pass I recommend you to use a module-pass. In the
run
function you then get allvm::Module &
as parameter which you can use to instantiate apsr::LLVMProjectIRDB
. Phasar will then not attempt to take ownership over the LLVM module and not add preprocessing metadata to the IR. You also may want to turn off auto-globals support in theLLVMBasedICFG
as it also modifies the IR.An example invocation may look like this:
llvm::PreservedAnalyses PsrModulePass::run(Module& M, ModuleAnalysisManager& AM) { std::vector<std::string> EntryPoints = {"main"}; // Or whatever entry-points you need // -- initialize the helper analyses psr::LLVMProjectIRDB IRDB(&M); psr::LLVMTypeHierarchy TH(IRDB); psr::LLVMAliasSet AS(&IRDB); psr::LLVMBasedICFG ICF(&IRDB, psr::CallGraphAnalysisType::OTF, EntryPoints, &TH, &AS, psr::Soundness::Soundy, /*AutoGlobals*/false); // -- optional: perform some data-flow analyses psr::IDELinearConstantAnalysis LCA(&IRDB, &ICF, EntryPoints); auto Results = psr::solveIDEProblem(LCA, ICF); // -- do something with the results return llvm::PreservedAnalyses::all(); }
Does that answer you question?
Thanks for your reply. It seems that you launch a new dataflow analysis for each module when that module is processed by that pass. In my problem, I have already completed the global interprocedure IFDS analysis before the pass. What I need to do is to instrument some instructions to the program so that the dataflow analysis result can help me to monitor the execution. So it seems not appropriate to launch a new dataflow analysis for each module.
What I can image on how to align the instruction object in pass and that in phasar is couting the sequence number of instruction in the block (I can find the right block using function name and block name). But currently I don't know how to control the compiler such that the pass and phasar meet the same version of IR. Do you have some solutions?
Hi @fabianbs96, I think I can solve it. I can generate the big IR file using wllvm, perform dataflow analysis, and then use my pass on that big module directly. In this way, the pass and phasar will meet the same IR version. Thanks.
Hi @william4code, nice that you already have a solution! One other way that I could imagine is to run the analysis (and instrumentation) as part of the LTO pipeline (within lld). There you also have access to the whole-module IR
Hi @william4code, nice that you already have a solution! One other way that I could imagine is to run the analysis (and instrumentation) as part of the LTO pipeline (within lld). There you also have access to the whole-module IR
Thanks. You provide another solution.
Hi, I am trying to write a LLVM pass to implement a module in my project. In the LLVM pass, I need to use the analysis results of phasar. Now I meet some problems.
Anyone can help me?
-William