llvm-mca.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. //===-- llvm-mca.cpp - Machine Code Analyzer -------------------*- 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. //
  9. // This utility is a simple driver that allows static performance analysis on
  10. // machine code similarly to how IACA (Intel Architecture Code Analyzer) works.
  11. //
  12. // llvm-mca [options] <file-name>
  13. // -march <type>
  14. // -mcpu <cpu>
  15. // -o <file>
  16. //
  17. // The target defaults to the host target.
  18. // The cpu defaults to the 'native' host cpu.
  19. // The output defaults to standard output.
  20. //
  21. //===----------------------------------------------------------------------===//
  22. #include "CodeRegion.h"
  23. #include "CodeRegionGenerator.h"
  24. #include "PipelinePrinter.h"
  25. #include "Views/BottleneckAnalysis.h"
  26. #include "Views/DispatchStatistics.h"
  27. #include "Views/InstructionInfoView.h"
  28. #include "Views/RegisterFileStatistics.h"
  29. #include "Views/ResourcePressureView.h"
  30. #include "Views/RetireControlUnitStatistics.h"
  31. #include "Views/SchedulerStatistics.h"
  32. #include "Views/SummaryView.h"
  33. #include "Views/TimelineView.h"
  34. #include "llvm/MC/MCAsmBackend.h"
  35. #include "llvm/MC/MCAsmInfo.h"
  36. #include "llvm/MC/MCCodeEmitter.h"
  37. #include "llvm/MC/MCContext.h"
  38. #include "llvm/MC/MCObjectFileInfo.h"
  39. #include "llvm/MC/MCRegisterInfo.h"
  40. #include "llvm/MC/MCSubtargetInfo.h"
  41. #include "llvm/MC/MCTargetOptionsCommandFlags.h"
  42. #include "llvm/MCA/CodeEmitter.h"
  43. #include "llvm/MCA/Context.h"
  44. #include "llvm/MCA/InstrBuilder.h"
  45. #include "llvm/MCA/Pipeline.h"
  46. #include "llvm/MCA/Stages/EntryStage.h"
  47. #include "llvm/MCA/Stages/InstructionTables.h"
  48. #include "llvm/MCA/Support.h"
  49. #include "llvm/Support/CommandLine.h"
  50. #include "llvm/Support/ErrorHandling.h"
  51. #include "llvm/Support/ErrorOr.h"
  52. #include "llvm/Support/FileSystem.h"
  53. #include "llvm/Support/Host.h"
  54. #include "llvm/Support/InitLLVM.h"
  55. #include "llvm/Support/MemoryBuffer.h"
  56. #include "llvm/Support/SourceMgr.h"
  57. #include "llvm/Support/TargetRegistry.h"
  58. #include "llvm/Support/TargetSelect.h"
  59. #include "llvm/Support/ToolOutputFile.h"
  60. #include "llvm/Support/WithColor.h"
  61. using namespace llvm;
  62. static mc::RegisterMCTargetOptionsFlags MOF;
  63. static cl::OptionCategory ToolOptions("Tool Options");
  64. static cl::OptionCategory ViewOptions("View Options");
  65. static cl::opt<std::string> InputFilename(cl::Positional,
  66. cl::desc("<input file>"),
  67. cl::cat(ToolOptions), cl::init("-"));
  68. static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
  69. cl::init("-"), cl::cat(ToolOptions),
  70. cl::value_desc("filename"));
  71. static cl::opt<std::string>
  72. ArchName("march",
  73. cl::desc("Target architecture. "
  74. "See -version for available targets"),
  75. cl::cat(ToolOptions));
  76. static cl::opt<std::string>
  77. TripleName("mtriple",
  78. cl::desc("Target triple. See -version for available targets"),
  79. cl::cat(ToolOptions));
  80. static cl::opt<std::string>
  81. MCPU("mcpu",
  82. cl::desc("Target a specific cpu type (-mcpu=help for details)"),
  83. cl::value_desc("cpu-name"), cl::cat(ToolOptions), cl::init("native"));
  84. static cl::opt<std::string>
  85. MATTR("mattr",
  86. cl::desc("Additional target features."),
  87. cl::cat(ToolOptions));
  88. static cl::opt<bool>
  89. PrintJson("json",
  90. cl::desc("Print the output in json format"),
  91. cl::cat(ToolOptions), cl::init(false));
  92. static cl::opt<int>
  93. OutputAsmVariant("output-asm-variant",
  94. cl::desc("Syntax variant to use for output printing"),
  95. cl::cat(ToolOptions), cl::init(-1));
  96. static cl::opt<bool>
  97. PrintImmHex("print-imm-hex", cl::cat(ToolOptions), cl::init(false),
  98. cl::desc("Prefer hex format when printing immediate values"));
  99. static cl::opt<unsigned> Iterations("iterations",
  100. cl::desc("Number of iterations to run"),
  101. cl::cat(ToolOptions), cl::init(0));
  102. static cl::opt<unsigned>
  103. DispatchWidth("dispatch", cl::desc("Override the processor dispatch width"),
  104. cl::cat(ToolOptions), cl::init(0));
  105. static cl::opt<unsigned>
  106. RegisterFileSize("register-file-size",
  107. cl::desc("Maximum number of physical registers which can "
  108. "be used for register mappings"),
  109. cl::cat(ToolOptions), cl::init(0));
  110. static cl::opt<unsigned>
  111. MicroOpQueue("micro-op-queue-size", cl::Hidden,
  112. cl::desc("Number of entries in the micro-op queue"),
  113. cl::cat(ToolOptions), cl::init(0));
  114. static cl::opt<unsigned>
  115. DecoderThroughput("decoder-throughput", cl::Hidden,
  116. cl::desc("Maximum throughput from the decoders "
  117. "(instructions per cycle)"),
  118. cl::cat(ToolOptions), cl::init(0));
  119. static cl::opt<bool>
  120. PrintRegisterFileStats("register-file-stats",
  121. cl::desc("Print register file statistics"),
  122. cl::cat(ViewOptions), cl::init(false));
  123. static cl::opt<bool> PrintDispatchStats("dispatch-stats",
  124. cl::desc("Print dispatch statistics"),
  125. cl::cat(ViewOptions), cl::init(false));
  126. static cl::opt<bool>
  127. PrintSummaryView("summary-view", cl::Hidden,
  128. cl::desc("Print summary view (enabled by default)"),
  129. cl::cat(ViewOptions), cl::init(true));
  130. static cl::opt<bool> PrintSchedulerStats("scheduler-stats",
  131. cl::desc("Print scheduler statistics"),
  132. cl::cat(ViewOptions), cl::init(false));
  133. static cl::opt<bool>
  134. PrintRetireStats("retire-stats",
  135. cl::desc("Print retire control unit statistics"),
  136. cl::cat(ViewOptions), cl::init(false));
  137. static cl::opt<bool> PrintResourcePressureView(
  138. "resource-pressure",
  139. cl::desc("Print the resource pressure view (enabled by default)"),
  140. cl::cat(ViewOptions), cl::init(true));
  141. static cl::opt<bool> PrintTimelineView("timeline",
  142. cl::desc("Print the timeline view"),
  143. cl::cat(ViewOptions), cl::init(false));
  144. static cl::opt<unsigned> TimelineMaxIterations(
  145. "timeline-max-iterations",
  146. cl::desc("Maximum number of iterations to print in timeline view"),
  147. cl::cat(ViewOptions), cl::init(0));
  148. static cl::opt<unsigned> TimelineMaxCycles(
  149. "timeline-max-cycles",
  150. cl::desc(
  151. "Maximum number of cycles in the timeline view. Defaults to 80 cycles"),
  152. cl::cat(ViewOptions), cl::init(80));
  153. static cl::opt<bool>
  154. AssumeNoAlias("noalias",
  155. cl::desc("If set, assume that loads and stores do not alias"),
  156. cl::cat(ToolOptions), cl::init(true));
  157. static cl::opt<unsigned> LoadQueueSize("lqueue",
  158. cl::desc("Size of the load queue"),
  159. cl::cat(ToolOptions), cl::init(0));
  160. static cl::opt<unsigned> StoreQueueSize("squeue",
  161. cl::desc("Size of the store queue"),
  162. cl::cat(ToolOptions), cl::init(0));
  163. static cl::opt<bool>
  164. PrintInstructionTables("instruction-tables",
  165. cl::desc("Print instruction tables"),
  166. cl::cat(ToolOptions), cl::init(false));
  167. static cl::opt<bool> PrintInstructionInfoView(
  168. "instruction-info",
  169. cl::desc("Print the instruction info view (enabled by default)"),
  170. cl::cat(ViewOptions), cl::init(true));
  171. static cl::opt<bool> EnableAllStats("all-stats",
  172. cl::desc("Print all hardware statistics"),
  173. cl::cat(ViewOptions), cl::init(false));
  174. static cl::opt<bool>
  175. EnableAllViews("all-views",
  176. cl::desc("Print all views including hardware statistics"),
  177. cl::cat(ViewOptions), cl::init(false));
  178. static cl::opt<bool> EnableBottleneckAnalysis(
  179. "bottleneck-analysis",
  180. cl::desc("Enable bottleneck analysis (disabled by default)"),
  181. cl::cat(ViewOptions), cl::init(false));
  182. static cl::opt<bool> ShowEncoding(
  183. "show-encoding",
  184. cl::desc("Print encoding information in the instruction info view"),
  185. cl::cat(ViewOptions), cl::init(false));
  186. namespace {
  187. const Target *getTarget(const char *ProgName) {
  188. if (TripleName.empty())
  189. TripleName = Triple::normalize(sys::getDefaultTargetTriple());
  190. Triple TheTriple(TripleName);
  191. // Get the target specific parser.
  192. std::string Error;
  193. const Target *TheTarget =
  194. TargetRegistry::lookupTarget(ArchName, TheTriple, Error);
  195. if (!TheTarget) {
  196. errs() << ProgName << ": " << Error;
  197. return nullptr;
  198. }
  199. // Return the found target.
  200. return TheTarget;
  201. }
  202. ErrorOr<std::unique_ptr<ToolOutputFile>> getOutputStream() {
  203. if (OutputFilename == "")
  204. OutputFilename = "-";
  205. std::error_code EC;
  206. auto Out =
  207. std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_Text);
  208. if (!EC)
  209. return std::move(Out);
  210. return EC;
  211. }
  212. } // end of anonymous namespace
  213. static void processOptionImpl(cl::opt<bool> &O, const cl::opt<bool> &Default) {
  214. if (!O.getNumOccurrences() || O.getPosition() < Default.getPosition())
  215. O = Default.getValue();
  216. }
  217. static void processViewOptions() {
  218. if (!EnableAllViews.getNumOccurrences() &&
  219. !EnableAllStats.getNumOccurrences())
  220. return;
  221. if (EnableAllViews.getNumOccurrences()) {
  222. processOptionImpl(PrintSummaryView, EnableAllViews);
  223. processOptionImpl(EnableBottleneckAnalysis, EnableAllViews);
  224. processOptionImpl(PrintResourcePressureView, EnableAllViews);
  225. processOptionImpl(PrintTimelineView, EnableAllViews);
  226. processOptionImpl(PrintInstructionInfoView, EnableAllViews);
  227. }
  228. const cl::opt<bool> &Default =
  229. EnableAllViews.getPosition() < EnableAllStats.getPosition()
  230. ? EnableAllStats
  231. : EnableAllViews;
  232. processOptionImpl(PrintRegisterFileStats, Default);
  233. processOptionImpl(PrintDispatchStats, Default);
  234. processOptionImpl(PrintSchedulerStats, Default);
  235. processOptionImpl(PrintRetireStats, Default);
  236. }
  237. // Returns true on success.
  238. static bool runPipeline(mca::Pipeline &P) {
  239. // Handle pipeline errors here.
  240. Expected<unsigned> Cycles = P.run();
  241. if (!Cycles) {
  242. WithColor::error() << toString(Cycles.takeError());
  243. return false;
  244. }
  245. return true;
  246. }
  247. int main(int argc, char **argv) {
  248. InitLLVM X(argc, argv);
  249. // Initialize targets and assembly parsers.
  250. InitializeAllTargetInfos();
  251. InitializeAllTargetMCs();
  252. InitializeAllAsmParsers();
  253. // Enable printing of available targets when flag --version is specified.
  254. cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
  255. cl::HideUnrelatedOptions({&ToolOptions, &ViewOptions});
  256. // Parse flags and initialize target options.
  257. cl::ParseCommandLineOptions(argc, argv,
  258. "llvm machine code performance analyzer.\n");
  259. // Get the target from the triple. If a triple is not specified, then select
  260. // the default triple for the host. If the triple doesn't correspond to any
  261. // registered target, then exit with an error message.
  262. const char *ProgName = argv[0];
  263. const Target *TheTarget = getTarget(ProgName);
  264. if (!TheTarget)
  265. return 1;
  266. // GetTarget() may replaced TripleName with a default triple.
  267. // For safety, reconstruct the Triple object.
  268. Triple TheTriple(TripleName);
  269. ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
  270. MemoryBuffer::getFileOrSTDIN(InputFilename);
  271. if (std::error_code EC = BufferPtr.getError()) {
  272. WithColor::error() << InputFilename << ": " << EC.message() << '\n';
  273. return 1;
  274. }
  275. // Apply overrides to llvm-mca specific options.
  276. processViewOptions();
  277. if (MCPU == "native")
  278. MCPU = std::string(llvm::sys::getHostCPUName());
  279. std::unique_ptr<MCSubtargetInfo> STI(
  280. TheTarget->createMCSubtargetInfo(TripleName, MCPU, MATTR));
  281. assert(STI && "Unable to create subtarget info!");
  282. if (!STI->isCPUStringValid(MCPU))
  283. return 1;
  284. if (!PrintInstructionTables && !STI->getSchedModel().isOutOfOrder()) {
  285. WithColor::error() << "please specify an out-of-order cpu. '" << MCPU
  286. << "' is an in-order cpu.\n";
  287. return 1;
  288. }
  289. if (!STI->getSchedModel().hasInstrSchedModel()) {
  290. WithColor::error()
  291. << "unable to find instruction-level scheduling information for"
  292. << " target triple '" << TheTriple.normalize() << "' and cpu '" << MCPU
  293. << "'.\n";
  294. if (STI->getSchedModel().InstrItineraries)
  295. WithColor::note()
  296. << "cpu '" << MCPU << "' provides itineraries. However, "
  297. << "instruction itineraries are currently unsupported.\n";
  298. return 1;
  299. }
  300. std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
  301. assert(MRI && "Unable to create target register info!");
  302. MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
  303. std::unique_ptr<MCAsmInfo> MAI(
  304. TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
  305. assert(MAI && "Unable to create target asm info!");
  306. MCObjectFileInfo MOFI;
  307. SourceMgr SrcMgr;
  308. // Tell SrcMgr about this buffer, which is what the parser will pick up.
  309. SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
  310. MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr);
  311. MOFI.InitMCObjectFileInfo(TheTriple, /* PIC= */ false, Ctx);
  312. std::unique_ptr<buffer_ostream> BOS;
  313. std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
  314. assert(MCII && "Unable to create instruction info!");
  315. std::unique_ptr<MCInstrAnalysis> MCIA(
  316. TheTarget->createMCInstrAnalysis(MCII.get()));
  317. // Parse the input and create CodeRegions that llvm-mca can analyze.
  318. mca::AsmCodeRegionGenerator CRG(*TheTarget, SrcMgr, Ctx, *MAI, *STI, *MCII);
  319. Expected<const mca::CodeRegions &> RegionsOrErr = CRG.parseCodeRegions();
  320. if (!RegionsOrErr) {
  321. if (auto Err =
  322. handleErrors(RegionsOrErr.takeError(), [](const StringError &E) {
  323. WithColor::error() << E.getMessage() << '\n';
  324. })) {
  325. // Default case.
  326. WithColor::error() << toString(std::move(Err)) << '\n';
  327. }
  328. return 1;
  329. }
  330. const mca::CodeRegions &Regions = *RegionsOrErr;
  331. // Early exit if errors were found by the code region parsing logic.
  332. if (!Regions.isValid())
  333. return 1;
  334. if (Regions.empty()) {
  335. WithColor::error() << "no assembly instructions found.\n";
  336. return 1;
  337. }
  338. // Now initialize the output file.
  339. auto OF = getOutputStream();
  340. if (std::error_code EC = OF.getError()) {
  341. WithColor::error() << EC.message() << '\n';
  342. return 1;
  343. }
  344. unsigned AssemblerDialect = CRG.getAssemblerDialect();
  345. if (OutputAsmVariant >= 0)
  346. AssemblerDialect = static_cast<unsigned>(OutputAsmVariant);
  347. std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
  348. Triple(TripleName), AssemblerDialect, *MAI, *MCII, *MRI));
  349. if (!IP) {
  350. WithColor::error()
  351. << "unable to create instruction printer for target triple '"
  352. << TheTriple.normalize() << "' with assembly variant "
  353. << AssemblerDialect << ".\n";
  354. return 1;
  355. }
  356. // Set the display preference for hex vs. decimal immediates.
  357. IP->setPrintImmHex(PrintImmHex);
  358. std::unique_ptr<ToolOutputFile> TOF = std::move(*OF);
  359. const MCSchedModel &SM = STI->getSchedModel();
  360. // Create an instruction builder.
  361. mca::InstrBuilder IB(*STI, *MCII, *MRI, MCIA.get());
  362. // Create a context to control ownership of the pipeline hardware.
  363. mca::Context MCA(*MRI, *STI);
  364. mca::PipelineOptions PO(MicroOpQueue, DecoderThroughput, DispatchWidth,
  365. RegisterFileSize, LoadQueueSize, StoreQueueSize,
  366. AssumeNoAlias, EnableBottleneckAnalysis);
  367. // Number each region in the sequence.
  368. unsigned RegionIdx = 0;
  369. std::unique_ptr<MCCodeEmitter> MCE(
  370. TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
  371. assert(MCE && "Unable to create code emitter!");
  372. std::unique_ptr<MCAsmBackend> MAB(TheTarget->createMCAsmBackend(
  373. *STI, *MRI, mc::InitMCTargetOptionsFromFlags()));
  374. assert(MAB && "Unable to create asm backend!");
  375. for (const std::unique_ptr<mca::CodeRegion> &Region : Regions) {
  376. // Skip empty code regions.
  377. if (Region->empty())
  378. continue;
  379. // Don't print the header of this region if it is the default region, and
  380. // it doesn't have an end location.
  381. if (Region->startLoc().isValid() || Region->endLoc().isValid()) {
  382. TOF->os() << "\n[" << RegionIdx++ << "] Code Region";
  383. StringRef Desc = Region->getDescription();
  384. if (!Desc.empty())
  385. TOF->os() << " - " << Desc;
  386. TOF->os() << "\n\n";
  387. }
  388. // Lower the MCInst sequence into an mca::Instruction sequence.
  389. ArrayRef<MCInst> Insts = Region->getInstructions();
  390. mca::CodeEmitter CE(*STI, *MAB, *MCE, Insts);
  391. std::vector<std::unique_ptr<mca::Instruction>> LoweredSequence;
  392. for (const MCInst &MCI : Insts) {
  393. Expected<std::unique_ptr<mca::Instruction>> Inst =
  394. IB.createInstruction(MCI);
  395. if (!Inst) {
  396. if (auto NewE = handleErrors(
  397. Inst.takeError(),
  398. [&IP, &STI](const mca::InstructionError<MCInst> &IE) {
  399. std::string InstructionStr;
  400. raw_string_ostream SS(InstructionStr);
  401. WithColor::error() << IE.Message << '\n';
  402. IP->printInst(&IE.Inst, 0, "", *STI, SS);
  403. SS.flush();
  404. WithColor::note()
  405. << "instruction: " << InstructionStr << '\n';
  406. })) {
  407. // Default case.
  408. WithColor::error() << toString(std::move(NewE));
  409. }
  410. return 1;
  411. }
  412. LoweredSequence.emplace_back(std::move(Inst.get()));
  413. }
  414. mca::SourceMgr S(LoweredSequence, PrintInstructionTables ? 1 : Iterations);
  415. if (PrintInstructionTables) {
  416. // Create a pipeline, stages, and a printer.
  417. auto P = std::make_unique<mca::Pipeline>();
  418. P->appendStage(std::make_unique<mca::EntryStage>(S));
  419. P->appendStage(std::make_unique<mca::InstructionTables>(SM));
  420. mca::PipelinePrinter Printer(*P, mca::View::OK_READABLE);
  421. // Create the views for this pipeline, execute, and emit a report.
  422. if (PrintInstructionInfoView) {
  423. Printer.addView(std::make_unique<mca::InstructionInfoView>(
  424. *STI, *MCII, CE, ShowEncoding, Insts, *IP));
  425. }
  426. Printer.addView(
  427. std::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts));
  428. if (!runPipeline(*P))
  429. return 1;
  430. Printer.printReport(TOF->os());
  431. continue;
  432. }
  433. // Create a basic pipeline simulating an out-of-order backend.
  434. auto P = MCA.createDefaultPipeline(PO, S);
  435. mca::PipelinePrinter Printer(*P, PrintJson ? mca::View::OK_JSON
  436. : mca::View::OK_READABLE);
  437. // When we output JSON, we add a view that contains the instructions
  438. // and CPU resource information.
  439. if (PrintJson)
  440. Printer.addView(
  441. std::make_unique<mca::InstructionView>(*STI, *IP, Insts, MCPU));
  442. if (PrintSummaryView)
  443. Printer.addView(
  444. std::make_unique<mca::SummaryView>(SM, Insts, DispatchWidth));
  445. if (EnableBottleneckAnalysis) {
  446. Printer.addView(std::make_unique<mca::BottleneckAnalysis>(
  447. *STI, *IP, Insts, S.getNumIterations()));
  448. }
  449. if (PrintInstructionInfoView)
  450. Printer.addView(std::make_unique<mca::InstructionInfoView>(
  451. *STI, *MCII, CE, ShowEncoding, Insts, *IP));
  452. if (PrintDispatchStats)
  453. Printer.addView(std::make_unique<mca::DispatchStatistics>());
  454. if (PrintSchedulerStats)
  455. Printer.addView(std::make_unique<mca::SchedulerStatistics>(*STI));
  456. if (PrintRetireStats)
  457. Printer.addView(std::make_unique<mca::RetireControlUnitStatistics>(SM));
  458. if (PrintRegisterFileStats)
  459. Printer.addView(std::make_unique<mca::RegisterFileStatistics>(*STI));
  460. if (PrintResourcePressureView)
  461. Printer.addView(
  462. std::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts));
  463. if (PrintTimelineView) {
  464. unsigned TimelineIterations =
  465. TimelineMaxIterations ? TimelineMaxIterations : 10;
  466. Printer.addView(std::make_unique<mca::TimelineView>(
  467. *STI, *IP, Insts, std::min(TimelineIterations, S.getNumIterations()),
  468. TimelineMaxCycles));
  469. }
  470. if (!runPipeline(*P))
  471. return 1;
  472. Printer.printReport(TOF->os());
  473. // Clear the InstrBuilder internal state in preparation for another round.
  474. IB.clear();
  475. }
  476. TOF->keep();
  477. return 0;
  478. }