PipelinePrinter.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //===--------------------- PipelinePrinter.cpp ------------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. /// \file
  9. ///
  10. /// This file implements the PipelinePrinter interface.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #include "PipelinePrinter.h"
  14. #include "CodeRegion.h"
  15. #include "Views/InstructionView.h"
  16. namespace llvm {
  17. namespace mca {
  18. void PipelinePrinter::printRegionHeader(llvm::raw_ostream &OS) const {
  19. StringRef RegionName;
  20. if (!Region.getDescription().empty())
  21. RegionName = Region.getDescription();
  22. OS << "\n[" << RegionIdx << "] Code Region";
  23. if (!RegionName.empty())
  24. OS << " - " << RegionName;
  25. OS << "\n\n";
  26. }
  27. json::Object PipelinePrinter::getJSONReportRegion() const {
  28. json::Object JO;
  29. StringRef RegionName = "";
  30. if (!Region.getDescription().empty())
  31. RegionName = Region.getDescription();
  32. JO.try_emplace("Name", RegionName);
  33. for (const auto &V : Views)
  34. if (V->isSerializable())
  35. JO.try_emplace(V->getNameAsString().str(), V->toJSON());
  36. return JO;
  37. }
  38. json::Object PipelinePrinter::getJSONSimulationParameters() const {
  39. json::Object SimParameters({{"-mcpu", STI.getCPU()},
  40. {"-mtriple", STI.getTargetTriple().getTriple()},
  41. {"-march", STI.getTargetTriple().getArchName()}});
  42. const MCSchedModel &SM = STI.getSchedModel();
  43. if (!SM.isOutOfOrder())
  44. return SimParameters;
  45. if (PO.RegisterFileSize)
  46. SimParameters.try_emplace("-register-file-size", PO.RegisterFileSize);
  47. if (!PO.AssumeNoAlias)
  48. SimParameters.try_emplace("-noalias", PO.AssumeNoAlias);
  49. if (PO.DecodersThroughput)
  50. SimParameters.try_emplace("-decoder-throughput", PO.DecodersThroughput);
  51. if (PO.MicroOpQueueSize)
  52. SimParameters.try_emplace("-micro-op-queue-size", PO.MicroOpQueueSize);
  53. if (PO.DispatchWidth)
  54. SimParameters.try_emplace("-dispatch", PO.DispatchWidth);
  55. if (PO.LoadQueueSize)
  56. SimParameters.try_emplace("-lqueue", PO.LoadQueueSize);
  57. if (PO.StoreQueueSize)
  58. SimParameters.try_emplace("-squeue", PO.StoreQueueSize);
  59. return SimParameters;
  60. }
  61. json::Object PipelinePrinter::getJSONTargetInfo() const {
  62. json::Array Resources;
  63. const MCSchedModel &SM = STI.getSchedModel();
  64. StringRef MCPU = STI.getCPU();
  65. for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) {
  66. const MCProcResourceDesc &ProcResource = *SM.getProcResource(I);
  67. unsigned NumUnits = ProcResource.NumUnits;
  68. if (ProcResource.SubUnitsIdxBegin || !NumUnits)
  69. continue;
  70. for (unsigned J = 0; J < NumUnits; ++J) {
  71. std::string ResourceName = ProcResource.Name;
  72. if (NumUnits > 1) {
  73. ResourceName += ".";
  74. ResourceName += J;
  75. }
  76. Resources.push_back(ResourceName);
  77. }
  78. }
  79. return json::Object({{"CPUName", MCPU}, {"Resources", std::move(Resources)}});
  80. }
  81. void PipelinePrinter::printReport(json::Object &JO) const {
  82. if (!RegionIdx) {
  83. JO.try_emplace("TargetInfo", getJSONTargetInfo());
  84. JO.try_emplace("SimulationParameters", getJSONSimulationParameters());
  85. // Construct an array of regions.
  86. JO.try_emplace("CodeRegions", json::Array());
  87. }
  88. json::Array *Regions = JO.getArray("CodeRegions");
  89. assert(Regions && "This array must exist!");
  90. Regions->push_back(getJSONReportRegion());
  91. }
  92. void PipelinePrinter::printReport(llvm::raw_ostream &OS) const {
  93. // Don't print the header of this region if it is the default region, and if
  94. // it doesn't have an end location.
  95. if (Region.startLoc().isValid() || Region.endLoc().isValid())
  96. printRegionHeader(OS);
  97. for (const auto &V : Views)
  98. V->printView(OS);
  99. }
  100. } // namespace mca
  101. } // namespace llvm