File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222#include " llvm/Passes/PassBuilder.h"
2323
2424#include " phasar/Utils/EnumFlags.h"
25+ #include " nlohmann/json.hpp"
2526
2627namespace llvm {
2728class Value ;
@@ -61,6 +62,7 @@ class ProjectIRDB {
6162 // Maps an id to its corresponding instruction
6263 std::map<std::size_t , llvm::Instruction *> IDInstructionMapping;
6364 size_t NumberCallsites;
65+ nlohmann::json StatsJson;
6466
6567 void buildIDModuleMapping (llvm::Module *M);
6668
@@ -182,6 +184,8 @@ class ProjectIRDB {
182184
183185 [[nodiscard]] static std::size_t getInstructionID (const llvm::Instruction *I);
184186
187+ void printAsJson (llvm::raw_ostream &OS = llvm::outs()) const ;
188+
185189 void print () const ;
186190
187191 void emitPreprocessedIR (llvm::raw_ostream &OS = llvm::outs(),
Original file line number Diff line number Diff line change 2020#include < set>
2121
2222#include " llvm/IR/PassManager.h"
23+ #include " nlohmann/json.hpp"
2324
2425namespace llvm {
2526class Type ;
@@ -115,6 +116,8 @@ class GeneralStatistics {
115116 */
116117 [[nodiscard]] std::set<const llvm::Instruction *>
117118 getRetResInstructions () const ;
119+ [[nodiscard]] nlohmann::json getAsJson () const ;
120+
118121};
119122
120123/* *
Original file line number Diff line number Diff line change @@ -272,6 +272,16 @@ void AnalysisController::emitRequestedHelperAnalysisResults() {
272272 ICF.printAsJson ();
273273 }
274274 }
275+
276+ if (EmitterOptions & AnalysisControllerEmitterOptions::EmitStatisticAsJson) {
277+ if (!ResultDirectory.empty ()) {
278+ if (auto OFS = openFileStream (" /psr-IrStatistic.json" )) {
279+ IRDB.printAsJson (*OFS);
280+ }
281+ } else {
282+ IRDB.printAsJson ();
283+ }
284+ }
275285}
276286
277287std::unique_ptr<llvm::raw_fd_ostream>
Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ void ProjectIRDB::preprocessModule(llvm::Module *M) {
126126 MPM.run (*M, MAM);
127127 // retrieve data from the GeneralStatisticsAnalysis registered earlier
128128 auto GSPResult = MAM.getResult <GeneralStatisticsAnalysis>(*M);
129+ StatsJson = GSPResult.getAsJson ();
129130 NumberCallsites = GSPResult.getFunctioncalls ();
130131 auto Allocas = GSPResult.getAllocaInstructions ();
131132 AllocaInstructions.insert (Allocas.begin (), Allocas.end ());
@@ -267,6 +268,10 @@ void ProjectIRDB::print() const {
267268 }
268269}
269270
271+ void ProjectIRDB::printAsJson (llvm::raw_ostream &OS) const {
272+ OS << StatsJson.dump ();
273+ }
274+
270275void ProjectIRDB::emitPreprocessedIR (llvm::raw_ostream &OS,
271276 bool ShortenIR) const {
272277 for (const auto &[File, Module] : Modules) {
Original file line number Diff line number Diff line change @@ -216,4 +216,14 @@ GeneralStatistics::getRetResInstructions() const {
216216 return RetResInstructions;
217217}
218218
219+ nlohmann::json GeneralStatistics::getAsJson () const {
220+ nlohmann::json J;
221+ J[" Instructions" ] = getInstructions ();
222+ J[" Functions" ] = Functions;
223+ J[" Alloca Instructions" ] = AllocaInstructions.size ();
224+ J[" Call Sites" ] = CallSites;
225+ J[" Global Variables" ] = Globals;
226+ return J;
227+ }
228+
219229} // namespace psr
You can’t perform that action at this time.
0 commit comments