1 //===--------------------- PipelinePrinter.cpp ------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file implements the PipelinePrinter interface.
12 //===----------------------------------------------------------------------===//
14 #include "PipelinePrinter.h"
15 #include "CodeRegion.h"
16 #include "Views/InstructionView.h"
21 void PipelinePrinter::printRegionHeader(llvm::raw_ostream
&OS
) const {
23 if (!Region
.getDescription().empty())
24 RegionName
= Region
.getDescription();
26 OS
<< "\n[" << RegionIdx
<< "] Code Region";
27 if (!RegionName
.empty())
28 OS
<< " - " << RegionName
;
32 json::Object
PipelinePrinter::getJSONReportRegion() const {
35 StringRef RegionName
= "";
36 if (!Region
.getDescription().empty())
37 RegionName
= Region
.getDescription();
39 JO
.try_emplace("Name", RegionName
);
40 for (const auto &V
: Views
)
41 if (V
->isSerializable())
42 JO
.try_emplace(V
->getNameAsString().str(), V
->toJSON());
47 json::Object
PipelinePrinter::getJSONSimulationParameters() const {
48 json::Object
SimParameters({{"-mcpu", STI
.getCPU()},
49 {"-mtriple", STI
.getTargetTriple().getTriple()},
50 {"-march", STI
.getTargetTriple().getArchName()}});
52 const MCSchedModel
&SM
= STI
.getSchedModel();
53 if (!SM
.isOutOfOrder())
56 if (PO
.RegisterFileSize
)
57 SimParameters
.try_emplace("-register-file-size", PO
.RegisterFileSize
);
59 if (!PO
.AssumeNoAlias
)
60 SimParameters
.try_emplace("-noalias", PO
.AssumeNoAlias
);
62 if (PO
.DecodersThroughput
)
63 SimParameters
.try_emplace("-decoder-throughput", PO
.DecodersThroughput
);
65 if (PO
.MicroOpQueueSize
)
66 SimParameters
.try_emplace("-micro-op-queue-size", PO
.MicroOpQueueSize
);
69 SimParameters
.try_emplace("-dispatch", PO
.DispatchWidth
);
72 SimParameters
.try_emplace("-lqueue", PO
.LoadQueueSize
);
74 if (PO
.StoreQueueSize
)
75 SimParameters
.try_emplace("-squeue", PO
.StoreQueueSize
);
80 json::Object
PipelinePrinter::getJSONTargetInfo() const {
81 json::Array Resources
;
82 const MCSchedModel
&SM
= STI
.getSchedModel();
83 StringRef MCPU
= STI
.getCPU();
85 for (unsigned I
= 1, E
= SM
.getNumProcResourceKinds(); I
< E
; ++I
) {
86 const MCProcResourceDesc
&ProcResource
= *SM
.getProcResource(I
);
87 unsigned NumUnits
= ProcResource
.NumUnits
;
88 if (ProcResource
.SubUnitsIdxBegin
|| !NumUnits
)
91 for (unsigned J
= 0; J
< NumUnits
; ++J
) {
92 std::string ResourceName
= ProcResource
.Name
;
98 Resources
.push_back(ResourceName
);
102 return json::Object({{"CPUName", MCPU
}, {"Resources", std::move(Resources
)}});
105 void PipelinePrinter::printReport(json::Object
&JO
) const {
107 JO
.try_emplace("TargetInfo", getJSONTargetInfo());
108 JO
.try_emplace("SimulationParameters", getJSONSimulationParameters());
109 // Construct an array of regions.
110 JO
.try_emplace("CodeRegions", json::Array());
113 json::Array
*Regions
= JO
.getArray("CodeRegions");
114 assert(Regions
&& "This array must exist!");
115 Regions
->push_back(getJSONReportRegion());
118 void PipelinePrinter::printReport(llvm::raw_ostream
&OS
) const {
119 // Don't print the header of this region if it is the default region, and if
120 // it doesn't have an end location.
121 if (Region
.startLoc().isValid() || Region
.endLoc().isValid())
122 printRegionHeader(OS
);
124 for (const auto &V
: Views
)