2018-06-25 18:53:00 +02:00
|
|
|
//===--------------------- PipelinePrinter.cpp ------------------*- C++ -*-===//
|
2018-03-08 14:05:02 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-03-08 14:05:02 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
///
|
2018-06-25 18:53:00 +02:00
|
|
|
/// This file implements the PipelinePrinter interface.
|
2018-03-08 14:05:02 +01:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-06-25 18:53:00 +02:00
|
|
|
#include "PipelinePrinter.h"
|
2021-07-09 23:35:12 +02:00
|
|
|
#include "CodeRegion.h"
|
|
|
|
#include "Views/InstructionView.h"
|
2018-08-24 22:24:53 +02:00
|
|
|
#include "Views/View.h"
|
2018-03-08 14:05:02 +01:00
|
|
|
|
2018-10-30 16:56:08 +01:00
|
|
|
namespace llvm {
|
2018-03-08 14:05:02 +01:00
|
|
|
namespace mca {
|
|
|
|
|
2021-07-09 23:35:12 +02:00
|
|
|
void PipelinePrinter::printRegionHeader(llvm::raw_ostream &OS) const {
|
|
|
|
StringRef RegionName;
|
|
|
|
if (!Region.getDescription().empty())
|
|
|
|
RegionName = Region.getDescription();
|
|
|
|
|
|
|
|
OS << "\n[" << RegionIdx << "] Code Region";
|
|
|
|
if (!RegionName.empty())
|
|
|
|
OS << " - " << RegionName;
|
|
|
|
OS << "\n\n";
|
|
|
|
}
|
|
|
|
|
2021-07-09 17:58:57 +02:00
|
|
|
json::Object PipelinePrinter::getJSONReportRegion() const {
|
2021-07-01 12:49:24 +02:00
|
|
|
json::Object JO;
|
2021-07-09 23:35:12 +02:00
|
|
|
|
2021-07-10 14:50:29 +02:00
|
|
|
StringRef RegionName = "";
|
|
|
|
if (!Region.getDescription().empty())
|
|
|
|
RegionName = Region.getDescription();
|
|
|
|
|
|
|
|
JO.try_emplace("Name", RegionName);
|
2021-07-09 23:35:12 +02:00
|
|
|
for (const auto &V : Views)
|
|
|
|
if (V->isSerializable())
|
2021-07-09 17:58:57 +02:00
|
|
|
JO.try_emplace(V->getNameAsString().str(), V->toJSON());
|
2021-07-09 23:35:12 +02:00
|
|
|
|
2021-07-09 17:58:57 +02:00
|
|
|
return JO;
|
|
|
|
}
|
|
|
|
|
2021-07-16 09:10:50 +02:00
|
|
|
json::Object PipelinePrinter::getJSONSimulationParameters() const {
|
|
|
|
json::Object SimParameters({{"-mcpu", STI.getCPU()},
|
|
|
|
{"-mtriple", STI.getTargetTriple().getTriple()},
|
|
|
|
{"-march", STI.getTargetTriple().getArchName()}});
|
|
|
|
|
|
|
|
const MCSchedModel &SM = STI.getSchedModel();
|
|
|
|
if (!SM.isOutOfOrder())
|
|
|
|
return SimParameters;
|
|
|
|
|
|
|
|
if (PO.RegisterFileSize)
|
|
|
|
SimParameters.try_emplace("-register-file-size", PO.RegisterFileSize);
|
|
|
|
|
|
|
|
if (!PO.AssumeNoAlias)
|
|
|
|
SimParameters.try_emplace("-noalias", PO.AssumeNoAlias);
|
|
|
|
|
|
|
|
if (PO.DecodersThroughput)
|
|
|
|
SimParameters.try_emplace("-decoder-throughput", PO.DecodersThroughput);
|
|
|
|
|
|
|
|
if (PO.MicroOpQueueSize)
|
|
|
|
SimParameters.try_emplace("-micro-op-queue-size", PO.MicroOpQueueSize);
|
|
|
|
|
|
|
|
if (PO.DispatchWidth)
|
|
|
|
SimParameters.try_emplace("-dispatch", PO.DispatchWidth);
|
|
|
|
|
|
|
|
if (PO.LoadQueueSize)
|
|
|
|
SimParameters.try_emplace("-lqueue", PO.LoadQueueSize);
|
|
|
|
|
|
|
|
if (PO.StoreQueueSize)
|
|
|
|
SimParameters.try_emplace("-squeue", PO.StoreQueueSize);
|
|
|
|
|
|
|
|
return SimParameters;
|
|
|
|
}
|
|
|
|
|
2021-07-10 13:27:30 +02:00
|
|
|
json::Object PipelinePrinter::getJSONTargetInfo() const {
|
|
|
|
json::Array Resources;
|
|
|
|
const MCSchedModel &SM = STI.getSchedModel();
|
|
|
|
StringRef MCPU = STI.getCPU();
|
|
|
|
|
|
|
|
for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) {
|
|
|
|
const MCProcResourceDesc &ProcResource = *SM.getProcResource(I);
|
|
|
|
unsigned NumUnits = ProcResource.NumUnits;
|
|
|
|
if (ProcResource.SubUnitsIdxBegin || !NumUnits)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (unsigned J = 0; J < NumUnits; ++J) {
|
|
|
|
std::string ResourceName = ProcResource.Name;
|
|
|
|
if (NumUnits > 1) {
|
2021-07-13 19:07:03 +02:00
|
|
|
ResourceName += ".";
|
2021-07-10 13:27:30 +02:00
|
|
|
ResourceName += J;
|
|
|
|
}
|
|
|
|
|
|
|
|
Resources.push_back(ResourceName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return json::Object({{"CPUName", MCPU}, {"Resources", std::move(Resources)}});
|
|
|
|
}
|
|
|
|
|
2021-07-09 23:35:12 +02:00
|
|
|
void PipelinePrinter::printReport(json::Object &JO) const {
|
2021-07-10 14:50:29 +02:00
|
|
|
if (!RegionIdx) {
|
2021-07-16 09:10:50 +02:00
|
|
|
JO.try_emplace("TargetInfo", getJSONTargetInfo());
|
|
|
|
JO.try_emplace("SimulationParameters", getJSONSimulationParameters());
|
2021-07-10 14:50:29 +02:00
|
|
|
// Construct an array of regions.
|
|
|
|
JO.try_emplace("CodeRegions", json::Array());
|
|
|
|
}
|
2021-07-09 23:35:12 +02:00
|
|
|
|
2021-07-10 14:50:29 +02:00
|
|
|
json::Array *Regions = JO.getArray("CodeRegions");
|
|
|
|
assert(Regions && "This array must exist!");
|
|
|
|
Regions->push_back(getJSONReportRegion());
|
2021-07-09 23:35:12 +02:00
|
|
|
}
|
|
|
|
|
2021-07-09 17:58:57 +02:00
|
|
|
void PipelinePrinter::printReport(llvm::raw_ostream &OS) const {
|
2021-07-09 23:35:12 +02:00
|
|
|
// Don't print the header of this region if it is the default region, and if
|
|
|
|
// it doesn't have an end location.
|
|
|
|
if (Region.startLoc().isValid() || Region.endLoc().isValid())
|
|
|
|
printRegionHeader(OS);
|
|
|
|
|
|
|
|
for (const auto &V : Views)
|
2021-07-09 17:58:57 +02:00
|
|
|
V->printView(OS);
|
2018-03-08 14:05:02 +01:00
|
|
|
}
|
2021-07-09 23:35:12 +02:00
|
|
|
|
|
|
|
} // namespace mca
|
2018-10-30 16:56:08 +01:00
|
|
|
} // namespace llvm
|