diff options
author | Andrea Di Biagio <andrea.dibiagio@sony.com> | 2021-07-09 22:35:12 +0100 |
---|---|---|
committer | Andrea Di Biagio <andrea.dibiagio@sony.com> | 2021-07-09 22:56:39 +0100 |
commit | 10cb03622325e699d53fbca819e03dca2519f5aa (patch) | |
tree | cc8bc691e060665e5b2873e8ecb5010150ffd64c /llvm/tools/llvm-mca/llvm-mca.cpp | |
parent | f3e6c3f327c278da27e5a3919f22719d128d8cc4 (diff) | |
download | llvm-10cb03622325e699d53fbca819e03dca2519f5aa.zip llvm-10cb03622325e699d53fbca819e03dca2519f5aa.tar.gz llvm-10cb03622325e699d53fbca819e03dca2519f5aa.tar.bz2 |
[llvm-mca] Refactor the logic that prints JSON files.
Moved most of the printing logic into the PipelinePrinter.
This patch also fixes the JSON output when flag -instruction-tables is
specified.
Diffstat (limited to 'llvm/tools/llvm-mca/llvm-mca.cpp')
-rw-r--r-- | llvm/tools/llvm-mca/llvm-mca.cpp | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp index a4c9528..0f1e74b 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -529,16 +529,7 @@ int main(int argc, char **argv) { if (Region->empty()) continue; - // Don't print the header of this region if it is the default region, and - // it doesn't have an end location. - if (!PrintJson && - (Region->startLoc().isValid() || Region->endLoc().isValid())) { - TOF->os() << "\n[" << RegionIdx++ << "] Code Region"; - StringRef Desc = Region->getDescription(); - if (!Desc.empty()) - TOF->os() << " - " << Desc; - TOF->os() << "\n\n"; - } + IB.clear(); // Lower the MCInst sequence into an mca::Instruction sequence. ArrayRef<MCInst> Insts = Region->getInstructions(); @@ -579,7 +570,12 @@ int main(int argc, char **argv) { auto P = std::make_unique<mca::Pipeline>(); P->appendStage(std::make_unique<mca::EntryStage>(S)); P->appendStage(std::make_unique<mca::InstructionTables>(SM)); - mca::PipelinePrinter Printer(*P); + + mca::PipelinePrinter Printer(*P, *Region, RegionIdx, *STI); + if (PrintJson) { + auto IV = std::make_unique<mca::InstructionView>(*STI, *IP, Insts); + Printer.addView(std::move(IV)); + } // Create the views for this pipeline, execute, and emit a report. if (PrintInstructionInfoView) { @@ -593,13 +589,12 @@ int main(int argc, char **argv) { return 1; if (PrintJson) { - JSONOutput.try_emplace(!Region->getDescription().empty() - ? Region->getDescription().str() - : "main", - Printer.getJSONReportRegion()); + Printer.printReport(JSONOutput); } else { Printer.printReport(TOF->os()); } + + ++RegionIdx; continue; } @@ -614,15 +609,13 @@ int main(int argc, char **argv) { // Create a basic pipeline simulating an out-of-order backend. auto P = MCA.createDefaultPipeline(PO, S, *CB); - mca::PipelinePrinter Printer(*P); + + mca::PipelinePrinter Printer(*P, *Region, RegionIdx, *STI); // When we output JSON, we add a view that contains the instructions // and CPU resource information. if (PrintJson) { - auto IV = std::make_unique<mca::InstructionView>(*STI, *IP, Insts, MCPU); - if (JSONOutput.find("Resources") == JSONOutput.end()) { - JSONOutput.try_emplace("Resources", IV->getJSONResources()); - } + auto IV = std::make_unique<mca::InstructionView>(*STI, *IP, Insts); Printer.addView(std::move(IV)); } @@ -672,16 +665,12 @@ int main(int argc, char **argv) { return 1; if (PrintJson) { - JSONOutput.try_emplace(!Region->getDescription().empty() - ? Region->getDescription().str() - : "main", - Printer.getJSONReportRegion()); + Printer.printReport(JSONOutput); } else { Printer.printReport(TOF->os()); } - // Clear the InstrBuilder internal state in preparation for another round. - IB.clear(); + ++RegionIdx; } if (PrintJson) |