blob: 75ffca6d20db117f63790d633e12029fe9aa1795 [file] [log] [blame]
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +00001//===-- llvm-mca.cpp - Machine Code Analyzer -------------------*- C++ -* -===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This utility is a simple driver that allows static performance analysis on
11// machine code similarly to how IACA (Intel Architecture Code Analyzer) works.
12//
13// llvm-mca [options] <file-name>
14// -march <type>
15// -mcpu <cpu>
16// -o <file>
17//
18// The target defaults to the host target.
Andrea Di Biagio93c49d52018-04-25 10:18:25 +000019// The cpu defaults to the 'native' host cpu.
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000020// The output defaults to standard output.
21//
22//===----------------------------------------------------------------------===//
23
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +000024#include "BackendPrinter.h"
Andrea Di Biagioc6590122018-04-09 16:39:52 +000025#include "CodeRegion.h"
Andrea Di Biagio821f6502018-04-10 14:55:14 +000026#include "DispatchStatistics.h"
Andrea Di Biagiodf5d9482018-03-23 19:40:04 +000027#include "InstructionInfoView.h"
Andrea Di Biagiod1569292018-03-26 12:04:53 +000028#include "InstructionTables.h"
Andrea Di Biagio8dabf4f2018-04-03 16:46:23 +000029#include "RegisterFileStatistics.h"
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +000030#include "ResourcePressureView.h"
Andrea Di Biagiof41ad5c2018-04-11 12:12:53 +000031#include "RetireControlUnitStatistics.h"
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000032#include "SchedulerStatistics.h"
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +000033#include "SummaryView.h"
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +000034#include "TimelineView.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000035#include "llvm/MC/MCAsmInfo.h"
36#include "llvm/MC/MCContext.h"
37#include "llvm/MC/MCObjectFileInfo.h"
38#include "llvm/MC/MCParser/MCTargetAsmParser.h"
39#include "llvm/MC/MCRegisterInfo.h"
40#include "llvm/MC/MCStreamer.h"
41#include "llvm/Support/CommandLine.h"
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000042#include "llvm/Support/ErrorOr.h"
43#include "llvm/Support/FileSystem.h"
Andrea Di Biagio641cca32018-04-25 10:27:30 +000044#include "llvm/Support/Host.h"
Rui Ueyama197194b2018-04-13 18:26:06 +000045#include "llvm/Support/InitLLVM.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000046#include "llvm/Support/MemoryBuffer.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000047#include "llvm/Support/SourceMgr.h"
48#include "llvm/Support/TargetRegistry.h"
49#include "llvm/Support/TargetSelect.h"
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000050#include "llvm/Support/ToolOutputFile.h"
Jonas Devlieghere6adef092018-04-18 15:26:51 +000051#include "llvm/Support/WithColor.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000052
53using namespace llvm;
54
Filipe Cabecinhasdef742c2018-04-25 14:39:16 +000055static llvm::cl::OptionCategory ViewOptions("View Options");
Andrea Di Biagio534e1da2018-04-25 11:33:14 +000056
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000057static cl::opt<std::string>
58 InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
59
60static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
61 cl::init("-"),
62 cl::value_desc("filename"));
63
64static cl::opt<std::string>
65 ArchName("march", cl::desc("Target arch to assemble for, "
66 "see -version for available targets"));
67
68static cl::opt<std::string>
69 TripleName("mtriple", cl::desc("Target triple to assemble for, "
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000070 "see -version for available targets"));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000071
72static cl::opt<std::string>
73 MCPU("mcpu",
74 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
Andrea Di Biagio93c49d52018-04-25 10:18:25 +000075 cl::value_desc("cpu-name"), cl::init("native"));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000076
Andrea Di Biagio06268642018-04-24 16:19:08 +000077static cl::opt<int>
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000078 OutputAsmVariant("output-asm-variant",
Andrea Di Biagio06268642018-04-24 16:19:08 +000079 cl::desc("Syntax variant to use for output printing"),
80 cl::init(-1));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000081
82static cl::opt<unsigned> Iterations("iterations",
83 cl::desc("Number of iterations to run"),
84 cl::init(0));
85
86static cl::opt<unsigned> DispatchWidth(
87 "dispatch",
88 cl::desc("Dispatch Width. By default it is set equal to IssueWidth"),
89 cl::init(0));
90
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000091static cl::opt<unsigned>
92 RegisterFileSize("register-file-size",
93 cl::desc("Maximum number of temporary registers which can "
94 "be used for register mappings"),
95 cl::init(0));
96
Andrea Di Biagio29538c62018-03-23 11:33:09 +000097static cl::opt<bool>
Andrea Di Biagio8dabf4f2018-04-03 16:46:23 +000098 PrintRegisterFileStats("register-file-stats",
99 cl::desc("Print register file statistics"),
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000100 cl::cat(ViewOptions), cl::init(false));
Andrea Di Biagio8dabf4f2018-04-03 16:46:23 +0000101
Andrea Di Biagio641cca32018-04-25 10:27:30 +0000102static cl::opt<bool> PrintDispatchStats("dispatch-stats",
103 cl::desc("Print dispatch statistics"),
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000104 cl::cat(ViewOptions), cl::init(false));
Andrea Di Biagio821f6502018-04-10 14:55:14 +0000105
Andrea Di Biagio641cca32018-04-25 10:27:30 +0000106static cl::opt<bool> PrintSchedulerStats("scheduler-stats",
107 cl::desc("Print scheduler statistics"),
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000108 cl::cat(ViewOptions), cl::init(false));
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +0000109
110static cl::opt<bool>
Andrea Di Biagiof41ad5c2018-04-11 12:12:53 +0000111 PrintRetireStats("retire-stats",
Andrea Di Biagio641cca32018-04-25 10:27:30 +0000112 cl::desc("Print retire control unit statistics"),
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000113 cl::cat(ViewOptions), cl::init(false));
Andrea Di Biagiof41ad5c2018-04-11 12:12:53 +0000114
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000115static cl::opt<bool> PrintResourcePressureView(
116 "resource-pressure",
117 cl::desc("Print the resource pressure view (enabled by default)"),
118 cl::cat(ViewOptions), cl::init(true));
Andrea Di Biagio29538c62018-03-23 11:33:09 +0000119
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000120static cl::opt<bool> PrintTimelineView("timeline",
121 cl::desc("Print the timeline view"),
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000122 cl::cat(ViewOptions), cl::init(false));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000123
124static cl::opt<unsigned> TimelineMaxIterations(
125 "timeline-max-iterations",
126 cl::desc("Maximum number of iterations to print in timeline view"),
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000127 cl::cat(ViewOptions), cl::init(0));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000128
129static cl::opt<unsigned> TimelineMaxCycles(
130 "timeline-max-cycles",
131 cl::desc(
132 "Maximum number of cycles in the timeline view. Defaults to 80 cycles"),
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000133 cl::cat(ViewOptions), cl::init(80));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000134
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000135static cl::opt<bool> AssumeNoAlias(
136 "noalias",
137 cl::desc("If set, it assumes that loads and stores do not alias"),
138 cl::init(true));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000139
140static cl::opt<unsigned>
141 LoadQueueSize("lqueue", cl::desc("Size of the load queue"), cl::init(0));
Andrea Di Biagiod1569292018-03-26 12:04:53 +0000142
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000143static cl::opt<unsigned>
144 StoreQueueSize("squeue", cl::desc("Size of the store queue"), cl::init(0));
145
Andrea Di Biagiod1569292018-03-26 12:04:53 +0000146static cl::opt<bool>
147 PrintInstructionTables("instruction-tables",
148 cl::desc("Print instruction tables"),
149 cl::init(false));
150
Andrea Di Biagio450ea7a2018-05-05 15:36:47 +0000151static cl::opt<bool> PrintInstructionInfoView(
152 "instruction-info",
153 cl::desc("Print the instruction info view (enabled by default)"),
154 cl::cat(ViewOptions), cl::init(true));
Andrea Di Biagioff9c1092018-03-26 13:44:54 +0000155
Andrea Di Biagio5c469442018-04-08 15:10:19 +0000156namespace {
157
158const Target *getTarget(const char *ProgName) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000159 TripleName = Triple::normalize(TripleName);
160 if (TripleName.empty())
161 TripleName = Triple::normalize(sys::getDefaultTargetTriple());
162 Triple TheTriple(TripleName);
163
164 // Get the target specific parser.
165 std::string Error;
166 const Target *TheTarget =
167 TargetRegistry::lookupTarget(ArchName, TheTriple, Error);
168 if (!TheTarget) {
169 errs() << ProgName << ": " << Error;
170 return nullptr;
171 }
172
173 // Return the found target.
174 return TheTarget;
175}
176
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000177// A comment consumer that parses strings.
178// The only valid tokens are strings.
179class MCACommentConsumer : public AsmCommentConsumer {
180public:
181 mca::CodeRegions &Regions;
182
183 MCACommentConsumer(mca::CodeRegions &R) : Regions(R) {}
184 void HandleComment(SMLoc Loc, StringRef CommentText) override {
185 // Skip empty comments.
186 StringRef Comment(CommentText);
187 if (Comment.empty())
188 return;
189
190 // Skip spaces and tabs
191 unsigned Position = Comment.find_first_not_of(" \t");
192 if (Position >= Comment.size())
193 // we reached the end of the comment. Bail out.
194 return;
195
196 Comment = Comment.drop_front(Position);
197 if (Comment.consume_front("LLVM-MCA-END")) {
198 Regions.endRegion(Loc);
199 return;
200 }
201
202 // Now try to parse string LLVM-MCA-BEGIN
203 if (!Comment.consume_front("LLVM-MCA-BEGIN"))
204 return;
205
206 // Skip spaces and tabs
207 Position = Comment.find_first_not_of(" \t");
208 if (Position < Comment.size())
Fangrui Songbb082572018-04-09 17:06:57 +0000209 Comment = Comment.drop_front(Position);
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000210 // Use the rest of the string as a descriptor for this code snippet.
211 Regions.beginRegion(Comment, Loc);
212 }
213};
214
Andrea Di Biagio5c469442018-04-08 15:10:19 +0000215int AssembleInput(const char *ProgName, MCAsmParser &Parser,
216 const Target *TheTarget, MCSubtargetInfo &STI,
217 MCInstrInfo &MCII, MCTargetOptions &MCOptions) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000218 std::unique_ptr<MCTargetAsmParser> TAP(
Andrea Di Biagio5c469442018-04-08 15:10:19 +0000219 TheTarget->createMCAsmParser(STI, Parser, MCII, MCOptions));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000220
221 if (!TAP) {
Andrea Di Biagio24fb4fc2018-05-04 13:52:12 +0000222 WithColor::error() << "this target does not support assembly parsing.\n";
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000223 return 1;
224 }
225
Andrea Di Biagio5c469442018-04-08 15:10:19 +0000226 Parser.setTargetParser(*TAP);
227 return Parser.Run(false);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000228}
229
Andrea Di Biagio5c469442018-04-08 15:10:19 +0000230ErrorOr<std::unique_ptr<ToolOutputFile>> getOutputStream() {
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000231 if (OutputFilename == "")
232 OutputFilename = "-";
233 std::error_code EC;
234 auto Out =
235 llvm::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::F_None);
236 if (!EC)
237 return std::move(Out);
238 return EC;
239}
240
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000241class MCStreamerWrapper final : public MCStreamer {
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000242 mca::CodeRegions &Regions;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000243
244public:
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000245 MCStreamerWrapper(MCContext &Context, mca::CodeRegions &R)
246 : MCStreamer(Context), Regions(R) {}
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000247
248 // We only want to intercept the emission of new instructions.
249 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
250 bool /* unused */) override {
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000251 Regions.addInstruction(llvm::make_unique<const MCInst>(Inst));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000252 }
253
254 bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override {
255 return true;
256 }
257
258 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
259 unsigned ByteAlignment) override {}
260 void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
261 uint64_t Size = 0, unsigned ByteAlignment = 0) override {}
262 void EmitGPRel32Value(const MCExpr *Value) override {}
263 void BeginCOFFSymbolDef(const MCSymbol *Symbol) override {}
264 void EmitCOFFSymbolStorageClass(int StorageClass) override {}
265 void EmitCOFFSymbolType(int Type) override {}
266 void EndCOFFSymbolDef() override {}
267
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000268 const std::vector<std::unique_ptr<const MCInst>> &
269 GetInstructionSequence(unsigned Index) const {
270 return Regions.getInstructionSequence(Index);
271 }
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000272};
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000273} // end of anonymous namespace
274
275int main(int argc, char **argv) {
Rui Ueyama197194b2018-04-13 18:26:06 +0000276 InitLLVM X(argc, argv);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000277
278 // Initialize targets and assembly parsers.
279 llvm::InitializeAllTargetInfos();
280 llvm::InitializeAllTargetMCs();
281 llvm::InitializeAllAsmParsers();
282
283 // Enable printing of available targets when flag --version is specified.
284 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
285
286 // Parse flags and initialize target options.
287 cl::ParseCommandLineOptions(argc, argv,
288 "llvm machine code performance analyzer.\n");
289 MCTargetOptions MCOptions;
290 MCOptions.PreserveAsmComments = false;
291
292 // Get the target from the triple. If a triple is not specified, then select
293 // the default triple for the host. If the triple doesn't correspond to any
294 // registered target, then exit with an error message.
295 const char *ProgName = argv[0];
296 const Target *TheTarget = getTarget(ProgName);
297 if (!TheTarget)
298 return 1;
299
300 // GetTarget() may replaced TripleName with a default triple.
301 // For safety, reconstruct the Triple object.
302 Triple TheTriple(TripleName);
303
304 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
305 MemoryBuffer::getFileOrSTDIN(InputFilename);
306 if (std::error_code EC = BufferPtr.getError()) {
Jonas Devlieghere6adef092018-04-18 15:26:51 +0000307 WithColor::error() << InputFilename << ": " << EC.message() << '\n';
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000308 return 1;
309 }
310
311 SourceMgr SrcMgr;
312
313 // Tell SrcMgr about this buffer, which is what the parser will pick up.
314 SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
315
316 std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
317 assert(MRI && "Unable to create target register info!");
318
319 std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TripleName));
320 assert(MAI && "Unable to create target asm info!");
321
322 MCObjectFileInfo MOFI;
323 MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr);
324 MOFI.InitMCObjectFileInfo(TheTriple, /* PIC= */ false, Ctx);
325
326 std::unique_ptr<buffer_ostream> BOS;
Andrea Di Biagiod1569292018-03-26 12:04:53 +0000327
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000328 mca::CodeRegions Regions(SrcMgr);
329 MCStreamerWrapper Str(Ctx, Regions);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000330
331 std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
Andrea Di Biagio93c49d52018-04-25 10:18:25 +0000332
333 if (!MCPU.compare("native"))
334 MCPU = llvm::sys::getHostCPUName();
335
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000336 std::unique_ptr<MCSubtargetInfo> STI(
337 TheTarget->createMCSubtargetInfo(TripleName, MCPU, /* FeaturesStr */ ""));
338 if (!STI->isCPUStringValid(MCPU))
339 return 1;
340
Andrea Di Biagioe9384eb2018-04-30 12:05:34 +0000341 if (!PrintInstructionTables && !STI->getSchedModel().isOutOfOrder()) {
Jonas Devlieghere6adef092018-04-18 15:26:51 +0000342 WithColor::error() << "please specify an out-of-order cpu. '" << MCPU
343 << "' is an in-order cpu.\n";
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000344 return 1;
345 }
346
347 if (!STI->getSchedModel().hasInstrSchedModel()) {
Jonas Devlieghere6adef092018-04-18 15:26:51 +0000348 WithColor::error()
349 << "unable to find instruction-level scheduling information for"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000350 << " target triple '" << TheTriple.normalize() << "' and cpu '" << MCPU
351 << "'.\n";
352
353 if (STI->getSchedModel().InstrItineraries)
Jonas Devlieghere6adef092018-04-18 15:26:51 +0000354 WithColor::note()
355 << "cpu '" << MCPU << "' provides itineraries. However, "
356 << "instruction itineraries are currently unsupported.\n";
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000357 return 1;
358 }
359
Andrea Di Biagio5c469442018-04-08 15:10:19 +0000360 std::unique_ptr<MCAsmParser> P(createMCAsmParser(SrcMgr, Ctx, Str, *MAI));
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000361 MCAsmLexer &Lexer = P->getLexer();
362 MCACommentConsumer CC(Regions);
363 Lexer.setCommentConsumer(&CC);
364
Andrea Di Biagio5c469442018-04-08 15:10:19 +0000365 if (AssembleInput(ProgName, *P, TheTarget, *STI, *MCII, MCOptions))
366 return 1;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000367
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000368 if (Regions.empty()) {
Jonas Devlieghere6adef092018-04-18 15:26:51 +0000369 WithColor::error() << "no assembly instructions found.\n";
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000370 return 1;
371 }
372
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000373 // Now initialize the output file.
374 auto OF = getOutputStream();
375 if (std::error_code EC = OF.getError()) {
Jonas Devlieghere6adef092018-04-18 15:26:51 +0000376 WithColor::error() << EC.message() << '\n';
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000377 return 1;
378 }
379
Andrea Di Biagio06268642018-04-24 16:19:08 +0000380 unsigned AssemblerDialect = P->getAssemblerDialect();
381 if (OutputAsmVariant >= 0)
382 AssemblerDialect = static_cast<unsigned>(OutputAsmVariant);
383 std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
384 Triple(TripleName), AssemblerDialect, *MAI, *MCII, *MRI));
385 if (!IP) {
386 WithColor::error()
387 << "unable to create instruction printer for target triple '"
388 << TheTriple.normalize() << "' with assembly variant "
389 << AssemblerDialect << ".\n";
390 return 1;
391 }
392
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000393 std::unique_ptr<llvm::ToolOutputFile> TOF = std::move(*OF);
394
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000395 const MCSchedModel &SM = STI->getSchedModel();
396
397 unsigned Width = SM.IssueWidth;
398 if (DispatchWidth)
399 Width = DispatchWidth;
400
Andrea Di Biagiob5088da2018-03-23 11:50:43 +0000401 // Create an instruction builder.
Andrea Di Biagio5c469442018-04-08 15:10:19 +0000402 mca::InstrBuilder IB(*STI, *MCII);
Andrea Di Biagiob5088da2018-03-23 11:50:43 +0000403
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000404 // Number each region in the sequence.
405 unsigned RegionIdx = 0;
406 for (const std::unique_ptr<mca::CodeRegion> &Region : Regions) {
407 // Skip empty code regions.
408 if (Region->empty())
409 continue;
Andrea Di Biagioff9c1092018-03-26 13:44:54 +0000410
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000411 // Don't print the header of this region if it is the default region, and
412 // it doesn't have an end location.
413 if (Region->startLoc().isValid() || Region->endLoc().isValid()) {
414 TOF->os() << "\n[" << RegionIdx++ << "] Code Region";
415 StringRef Desc = Region->getDescription();
416 if (!Desc.empty())
417 TOF->os() << " - " << Desc;
418 TOF->os() << "\n\n";
Andrea Di Biagioff9c1092018-03-26 13:44:54 +0000419 }
420
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000421 mca::SourceMgr S(Region->getInstructions(),
422 PrintInstructionTables ? 1 : Iterations);
423
424 if (PrintInstructionTables) {
425 mca::InstructionTables IT(STI->getSchedModel(), IB, S);
426
427 if (PrintInstructionInfoView) {
428 IT.addView(
429 llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, S, *IP));
430 }
431
432 IT.addView(llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, S));
433 IT.run();
434 IT.printReport(TOF->os());
435 continue;
436 }
437
438 mca::Backend B(*STI, *MRI, IB, S, Width, RegisterFileSize, LoadQueueSize,
439 StoreQueueSize, AssumeNoAlias);
440 mca::BackendPrinter Printer(B);
441
442 Printer.addView(llvm::make_unique<mca::SummaryView>(S, Width));
443 if (PrintInstructionInfoView)
444 Printer.addView(
445 llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, S, *IP));
446
Andrea Di Biagio821f6502018-04-10 14:55:14 +0000447 if (PrintDispatchStats)
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +0000448 Printer.addView(llvm::make_unique<mca::DispatchStatistics>());
Andrea Di Biagio821f6502018-04-10 14:55:14 +0000449
Andrea Di Biagiof41ad5c2018-04-11 12:12:53 +0000450 if (PrintSchedulerStats)
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +0000451 Printer.addView(llvm::make_unique<mca::SchedulerStatistics>(*STI));
452
Andrea Di Biagiof41ad5c2018-04-11 12:12:53 +0000453 if (PrintRetireStats)
454 Printer.addView(llvm::make_unique<mca::RetireControlUnitStatistics>());
Andrea Di Biagioc6590122018-04-09 16:39:52 +0000455
456 if (PrintRegisterFileStats)
457 Printer.addView(llvm::make_unique<mca::RegisterFileStatistics>(*STI));
458
459 if (PrintResourcePressureView)
460 Printer.addView(
461 llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, S));
462
463 if (PrintTimelineView) {
464 Printer.addView(llvm::make_unique<mca::TimelineView>(
465 *STI, *IP, S, TimelineMaxIterations, TimelineMaxCycles));
466 }
467
468 B.run();
469 Printer.printReport(TOF->os());
Andrea Di Biagiod1569292018-03-26 12:04:53 +0000470 }
471
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000472 TOF->keep();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000473 return 0;
474}