Path: blob/main/contrib/llvm-project/llvm/tools/llvm-mca/PipelinePrinter.cpp
35258 views
//===--------------------- PipelinePrinter.cpp ------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8///9/// This file implements the PipelinePrinter interface.10///11//===----------------------------------------------------------------------===//1213#include "PipelinePrinter.h"14#include "CodeRegion.h"15#include "Views/InstructionView.h"1617namespace llvm {18namespace mca {1920void PipelinePrinter::printRegionHeader(llvm::raw_ostream &OS) const {21StringRef RegionName;22if (!Region.getDescription().empty())23RegionName = Region.getDescription();2425OS << "\n[" << RegionIdx << "] Code Region";26if (!RegionName.empty())27OS << " - " << RegionName;28OS << "\n\n";29}3031json::Object PipelinePrinter::getJSONReportRegion() const {32json::Object JO;3334StringRef RegionName = "";35if (!Region.getDescription().empty())36RegionName = Region.getDescription();3738JO.try_emplace("Name", RegionName);39for (const auto &V : Views)40if (V->isSerializable())41JO.try_emplace(V->getNameAsString().str(), V->toJSON());4243return JO;44}4546json::Object PipelinePrinter::getJSONSimulationParameters() const {47json::Object SimParameters({{"-mcpu", STI.getCPU()},48{"-mtriple", STI.getTargetTriple().getTriple()},49{"-march", STI.getTargetTriple().getArchName()}});5051const MCSchedModel &SM = STI.getSchedModel();52if (!SM.isOutOfOrder())53return SimParameters;5455if (PO.RegisterFileSize)56SimParameters.try_emplace("-register-file-size", PO.RegisterFileSize);5758if (!PO.AssumeNoAlias)59SimParameters.try_emplace("-noalias", PO.AssumeNoAlias);6061if (PO.DecodersThroughput)62SimParameters.try_emplace("-decoder-throughput", PO.DecodersThroughput);6364if (PO.MicroOpQueueSize)65SimParameters.try_emplace("-micro-op-queue-size", PO.MicroOpQueueSize);6667if (PO.DispatchWidth)68SimParameters.try_emplace("-dispatch", PO.DispatchWidth);6970if (PO.LoadQueueSize)71SimParameters.try_emplace("-lqueue", PO.LoadQueueSize);7273if (PO.StoreQueueSize)74SimParameters.try_emplace("-squeue", PO.StoreQueueSize);7576return SimParameters;77}7879json::Object PipelinePrinter::getJSONTargetInfo() const {80json::Array Resources;81const MCSchedModel &SM = STI.getSchedModel();82StringRef MCPU = STI.getCPU();8384for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) {85const MCProcResourceDesc &ProcResource = *SM.getProcResource(I);86unsigned NumUnits = ProcResource.NumUnits;87if (ProcResource.SubUnitsIdxBegin || !NumUnits)88continue;8990for (unsigned J = 0; J < NumUnits; ++J) {91std::string ResourceName = ProcResource.Name;92if (NumUnits > 1) {93ResourceName += ".";94ResourceName += J;95}9697Resources.push_back(ResourceName);98}99}100101return json::Object({{"CPUName", MCPU}, {"Resources", std::move(Resources)}});102}103104void PipelinePrinter::printReport(json::Object &JO) const {105if (!RegionIdx) {106JO.try_emplace("TargetInfo", getJSONTargetInfo());107JO.try_emplace("SimulationParameters", getJSONSimulationParameters());108// Construct an array of regions.109JO.try_emplace("CodeRegions", json::Array());110}111112json::Array *Regions = JO.getArray("CodeRegions");113assert(Regions && "This array must exist!");114Regions->push_back(getJSONReportRegion());115}116117void PipelinePrinter::printReport(llvm::raw_ostream &OS) const {118// Don't print the header of this region if it is the default region, and if119// it doesn't have an end location.120if (Region.startLoc().isValid() || Region.endLoc().isValid())121printRegionHeader(OS);122123for (const auto &V : Views)124V->printView(OS);125}126127} // namespace mca128} // namespace llvm129130131