Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===-- 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 Biagio | 93c49d5 | 2018-04-25 10:18:25 +0000 | [diff] [blame] | 19 | // The cpu defaults to the 'native' host cpu. |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 20 | // The output defaults to standard output. |
| 21 | // |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 24 | #include "CodeRegion.h" |
Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 25 | #include "PipelinePrinter.h" |
Matt Davis | 271ce76 | 2018-08-27 17:16:32 +0000 | [diff] [blame] | 26 | #include "Stages/FetchStage.h" |
| 27 | #include "Stages/InstructionTables.h" |
Matt Davis | 10aa09f | 2018-08-24 20:24:53 +0000 | [diff] [blame] | 28 | #include "Views/DispatchStatistics.h" |
| 29 | #include "Views/InstructionInfoView.h" |
| 30 | #include "Views/RegisterFileStatistics.h" |
| 31 | #include "Views/ResourcePressureView.h" |
| 32 | #include "Views/RetireControlUnitStatistics.h" |
| 33 | #include "Views/SchedulerStatistics.h" |
| 34 | #include "Views/SummaryView.h" |
| 35 | #include "Views/TimelineView.h" |
Matt Davis | 271ce76 | 2018-08-27 17:16:32 +0000 | [diff] [blame] | 36 | #include "include/Context.h" |
| 37 | #include "include/Pipeline.h" |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 38 | #include "include/Support.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 39 | #include "llvm/MC/MCAsmInfo.h" |
| 40 | #include "llvm/MC/MCContext.h" |
| 41 | #include "llvm/MC/MCObjectFileInfo.h" |
| 42 | #include "llvm/MC/MCParser/MCTargetAsmParser.h" |
| 43 | #include "llvm/MC/MCRegisterInfo.h" |
| 44 | #include "llvm/MC/MCStreamer.h" |
| 45 | #include "llvm/Support/CommandLine.h" |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 46 | #include "llvm/Support/ErrorHandling.h" |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 47 | #include "llvm/Support/ErrorOr.h" |
| 48 | #include "llvm/Support/FileSystem.h" |
Andrea Di Biagio | 641cca3 | 2018-04-25 10:27:30 +0000 | [diff] [blame] | 49 | #include "llvm/Support/Host.h" |
Rui Ueyama | 197194b | 2018-04-13 18:26:06 +0000 | [diff] [blame] | 50 | #include "llvm/Support/InitLLVM.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 51 | #include "llvm/Support/MemoryBuffer.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 52 | #include "llvm/Support/SourceMgr.h" |
| 53 | #include "llvm/Support/TargetRegistry.h" |
| 54 | #include "llvm/Support/TargetSelect.h" |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 55 | #include "llvm/Support/ToolOutputFile.h" |
Jonas Devlieghere | 6adef09 | 2018-04-18 15:26:51 +0000 | [diff] [blame] | 56 | #include "llvm/Support/WithColor.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 57 | |
| 58 | using namespace llvm; |
| 59 | |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 60 | static cl::OptionCategory ToolOptions("Tool Options"); |
| 61 | static cl::OptionCategory ViewOptions("View Options"); |
Andrea Di Biagio | 534e1da | 2018-04-25 11:33:14 +0000 | [diff] [blame] | 62 | |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 63 | static cl::opt<std::string> InputFilename(cl::Positional, |
| 64 | cl::desc("<input file>"), |
| 65 | cl::cat(ToolOptions), cl::init("-")); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 66 | |
| 67 | static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"), |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 68 | cl::init("-"), cl::cat(ToolOptions), |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 69 | cl::value_desc("filename")); |
| 70 | |
| 71 | static cl::opt<std::string> |
Matt Davis | 9e64a4c | 2018-10-31 17:47:25 +0000 | [diff] [blame^] | 72 | ArchName("march", cl::desc("Target architecture. " |
| 73 | "See -version for available targets"), |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 74 | cl::cat(ToolOptions)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 75 | |
| 76 | static cl::opt<std::string> |
Andrea Di Biagio | 01b9fd6 | 2018-10-22 15:36:15 +0000 | [diff] [blame] | 77 | TripleName("mtriple", |
Matt Davis | 9e64a4c | 2018-10-31 17:47:25 +0000 | [diff] [blame^] | 78 | cl::desc("Target triple. See -version for available targets"), |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 79 | cl::cat(ToolOptions)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 80 | |
| 81 | static cl::opt<std::string> |
| 82 | MCPU("mcpu", |
| 83 | cl::desc("Target a specific cpu type (-mcpu=help for details)"), |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 84 | cl::value_desc("cpu-name"), cl::cat(ToolOptions), cl::init("native")); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 85 | |
Andrea Di Biagio | 0626864 | 2018-04-24 16:19:08 +0000 | [diff] [blame] | 86 | static cl::opt<int> |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 87 | OutputAsmVariant("output-asm-variant", |
Andrea Di Biagio | 0626864 | 2018-04-24 16:19:08 +0000 | [diff] [blame] | 88 | cl::desc("Syntax variant to use for output printing"), |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 89 | cl::cat(ToolOptions), cl::init(-1)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 90 | |
| 91 | static cl::opt<unsigned> Iterations("iterations", |
| 92 | cl::desc("Number of iterations to run"), |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 93 | cl::cat(ToolOptions), cl::init(0)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 94 | |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 95 | static cl::opt<unsigned> |
| 96 | DispatchWidth("dispatch", cl::desc("Override the processor dispatch width"), |
| 97 | cl::cat(ToolOptions), cl::init(0)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 98 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 99 | static cl::opt<unsigned> |
| 100 | RegisterFileSize("register-file-size", |
Matt Davis | 5ceaa98 | 2018-07-31 20:05:08 +0000 | [diff] [blame] | 101 | cl::desc("Maximum number of physical registers which can " |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 102 | "be used for register mappings"), |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 103 | cl::cat(ToolOptions), cl::init(0)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 104 | |
Andrea Di Biagio | 29538c6 | 2018-03-23 11:33:09 +0000 | [diff] [blame] | 105 | static cl::opt<bool> |
Andrea Di Biagio | 8dabf4f | 2018-04-03 16:46:23 +0000 | [diff] [blame] | 106 | PrintRegisterFileStats("register-file-stats", |
| 107 | cl::desc("Print register file statistics"), |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 108 | cl::cat(ViewOptions), cl::init(false)); |
Andrea Di Biagio | 8dabf4f | 2018-04-03 16:46:23 +0000 | [diff] [blame] | 109 | |
Andrea Di Biagio | 641cca3 | 2018-04-25 10:27:30 +0000 | [diff] [blame] | 110 | static cl::opt<bool> PrintDispatchStats("dispatch-stats", |
| 111 | cl::desc("Print dispatch statistics"), |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 112 | cl::cat(ViewOptions), cl::init(false)); |
Andrea Di Biagio | 821f650 | 2018-04-10 14:55:14 +0000 | [diff] [blame] | 113 | |
Roman Lebedev | 9ddf128 | 2018-06-15 14:01:43 +0000 | [diff] [blame] | 114 | static cl::opt<bool> |
| 115 | PrintSummaryView("summary-view", cl::Hidden, |
| 116 | cl::desc("Print summary view (enabled by default)"), |
| 117 | cl::cat(ViewOptions), cl::init(true)); |
| 118 | |
Andrea Di Biagio | 641cca3 | 2018-04-25 10:27:30 +0000 | [diff] [blame] | 119 | static cl::opt<bool> PrintSchedulerStats("scheduler-stats", |
| 120 | cl::desc("Print scheduler statistics"), |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 121 | cl::cat(ViewOptions), cl::init(false)); |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 122 | |
| 123 | static cl::opt<bool> |
Andrea Di Biagio | f41ad5c | 2018-04-11 12:12:53 +0000 | [diff] [blame] | 124 | PrintRetireStats("retire-stats", |
Andrea Di Biagio | 641cca3 | 2018-04-25 10:27:30 +0000 | [diff] [blame] | 125 | cl::desc("Print retire control unit statistics"), |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 126 | cl::cat(ViewOptions), cl::init(false)); |
Andrea Di Biagio | f41ad5c | 2018-04-11 12:12:53 +0000 | [diff] [blame] | 127 | |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 128 | static cl::opt<bool> PrintResourcePressureView( |
| 129 | "resource-pressure", |
| 130 | cl::desc("Print the resource pressure view (enabled by default)"), |
| 131 | cl::cat(ViewOptions), cl::init(true)); |
Andrea Di Biagio | 29538c6 | 2018-03-23 11:33:09 +0000 | [diff] [blame] | 132 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 133 | static cl::opt<bool> PrintTimelineView("timeline", |
| 134 | cl::desc("Print the timeline view"), |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 135 | cl::cat(ViewOptions), cl::init(false)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 136 | |
| 137 | static cl::opt<unsigned> TimelineMaxIterations( |
| 138 | "timeline-max-iterations", |
| 139 | cl::desc("Maximum number of iterations to print in timeline view"), |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 140 | cl::cat(ViewOptions), cl::init(0)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 141 | |
| 142 | static cl::opt<unsigned> TimelineMaxCycles( |
| 143 | "timeline-max-cycles", |
| 144 | cl::desc( |
| 145 | "Maximum number of cycles in the timeline view. Defaults to 80 cycles"), |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 146 | cl::cat(ViewOptions), cl::init(80)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 147 | |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 148 | static cl::opt<bool> |
| 149 | AssumeNoAlias("noalias", |
| 150 | cl::desc("If set, assume that loads and stores do not alias"), |
| 151 | cl::cat(ToolOptions), cl::init(true)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 152 | |
| 153 | static cl::opt<unsigned> |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 154 | LoadQueueSize("lqueue", |
| 155 | cl::desc("Size of the load queue (unbound by default)"), |
| 156 | cl::cat(ToolOptions), cl::init(0)); |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 157 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 158 | static cl::opt<unsigned> |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 159 | StoreQueueSize("squeue", |
| 160 | cl::desc("Size of the store queue (unbound by default)"), |
| 161 | cl::cat(ToolOptions), cl::init(0)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 162 | |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 163 | static cl::opt<bool> |
| 164 | PrintInstructionTables("instruction-tables", |
| 165 | cl::desc("Print instruction tables"), |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 166 | cl::cat(ToolOptions), cl::init(false)); |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 167 | |
Andrea Di Biagio | 450ea7a | 2018-05-05 15:36:47 +0000 | [diff] [blame] | 168 | static cl::opt<bool> PrintInstructionInfoView( |
| 169 | "instruction-info", |
| 170 | cl::desc("Print the instruction info view (enabled by default)"), |
| 171 | cl::cat(ViewOptions), cl::init(true)); |
Andrea Di Biagio | ff9c109 | 2018-03-26 13:44:54 +0000 | [diff] [blame] | 172 | |
Andrea Di Biagio | 650b5fc | 2018-05-17 12:27:03 +0000 | [diff] [blame] | 173 | static cl::opt<bool> EnableAllStats("all-stats", |
| 174 | cl::desc("Print all hardware statistics"), |
| 175 | cl::cat(ViewOptions), cl::init(false)); |
| 176 | |
| 177 | static cl::opt<bool> |
| 178 | EnableAllViews("all-views", |
| 179 | cl::desc("Print all views including hardware statistics"), |
| 180 | cl::cat(ViewOptions), cl::init(false)); |
| 181 | |
Andrea Di Biagio | 5c46944 | 2018-04-08 15:10:19 +0000 | [diff] [blame] | 182 | namespace { |
| 183 | |
| 184 | const Target *getTarget(const char *ProgName) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 185 | if (TripleName.empty()) |
| 186 | TripleName = Triple::normalize(sys::getDefaultTargetTriple()); |
| 187 | Triple TheTriple(TripleName); |
| 188 | |
| 189 | // Get the target specific parser. |
| 190 | std::string Error; |
| 191 | const Target *TheTarget = |
| 192 | TargetRegistry::lookupTarget(ArchName, TheTriple, Error); |
| 193 | if (!TheTarget) { |
| 194 | errs() << ProgName << ": " << Error; |
| 195 | return nullptr; |
| 196 | } |
| 197 | |
| 198 | // Return the found target. |
| 199 | return TheTarget; |
| 200 | } |
| 201 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 202 | // A comment consumer that parses strings. |
| 203 | // The only valid tokens are strings. |
| 204 | class MCACommentConsumer : public AsmCommentConsumer { |
| 205 | public: |
| 206 | mca::CodeRegions &Regions; |
| 207 | |
| 208 | MCACommentConsumer(mca::CodeRegions &R) : Regions(R) {} |
| 209 | void HandleComment(SMLoc Loc, StringRef CommentText) override { |
| 210 | // Skip empty comments. |
| 211 | StringRef Comment(CommentText); |
| 212 | if (Comment.empty()) |
| 213 | return; |
| 214 | |
| 215 | // Skip spaces and tabs |
| 216 | unsigned Position = Comment.find_first_not_of(" \t"); |
| 217 | if (Position >= Comment.size()) |
Owen Rodley | 73d18aa | 2018-09-28 04:51:45 +0000 | [diff] [blame] | 218 | // We reached the end of the comment. Bail out. |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 219 | return; |
| 220 | |
| 221 | Comment = Comment.drop_front(Position); |
| 222 | if (Comment.consume_front("LLVM-MCA-END")) { |
| 223 | Regions.endRegion(Loc); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | // Now try to parse string LLVM-MCA-BEGIN |
| 228 | if (!Comment.consume_front("LLVM-MCA-BEGIN")) |
| 229 | return; |
| 230 | |
| 231 | // Skip spaces and tabs |
| 232 | Position = Comment.find_first_not_of(" \t"); |
| 233 | if (Position < Comment.size()) |
Fangrui Song | bb08257 | 2018-04-09 17:06:57 +0000 | [diff] [blame] | 234 | Comment = Comment.drop_front(Position); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 235 | // Use the rest of the string as a descriptor for this code snippet. |
| 236 | Regions.beginRegion(Comment, Loc); |
| 237 | } |
| 238 | }; |
| 239 | |
Matt Davis | accb511 | 2018-08-20 22:41:27 +0000 | [diff] [blame] | 240 | int AssembleInput(MCAsmParser &Parser, const Target *TheTarget, |
| 241 | MCSubtargetInfo &STI, MCInstrInfo &MCII, |
| 242 | MCTargetOptions &MCOptions) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 243 | std::unique_ptr<MCTargetAsmParser> TAP( |
Andrea Di Biagio | 5c46944 | 2018-04-08 15:10:19 +0000 | [diff] [blame] | 244 | TheTarget->createMCAsmParser(STI, Parser, MCII, MCOptions)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 245 | |
| 246 | if (!TAP) { |
Andrea Di Biagio | 24fb4fc | 2018-05-04 13:52:12 +0000 | [diff] [blame] | 247 | WithColor::error() << "this target does not support assembly parsing.\n"; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 248 | return 1; |
| 249 | } |
| 250 | |
Andrea Di Biagio | 5c46944 | 2018-04-08 15:10:19 +0000 | [diff] [blame] | 251 | Parser.setTargetParser(*TAP); |
| 252 | return Parser.Run(false); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Andrea Di Biagio | 5c46944 | 2018-04-08 15:10:19 +0000 | [diff] [blame] | 255 | ErrorOr<std::unique_ptr<ToolOutputFile>> getOutputStream() { |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 256 | if (OutputFilename == "") |
| 257 | OutputFilename = "-"; |
| 258 | std::error_code EC; |
| 259 | auto Out = |
| 260 | llvm::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::F_None); |
| 261 | if (!EC) |
| 262 | return std::move(Out); |
| 263 | return EC; |
| 264 | } |
| 265 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 266 | class MCStreamerWrapper final : public MCStreamer { |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 267 | mca::CodeRegions &Regions; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 268 | |
| 269 | public: |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 270 | MCStreamerWrapper(MCContext &Context, mca::CodeRegions &R) |
| 271 | : MCStreamer(Context), Regions(R) {} |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 272 | |
| 273 | // We only want to intercept the emission of new instructions. |
Andrea Di Biagio | 01b9fd6 | 2018-10-22 15:36:15 +0000 | [diff] [blame] | 274 | virtual void EmitInstruction(const MCInst &Inst, |
| 275 | const MCSubtargetInfo & /* unused */, |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 276 | bool /* unused */) override { |
Andrea Di Biagio | 01b9fd6 | 2018-10-22 15:36:15 +0000 | [diff] [blame] | 277 | Regions.addInstruction(Inst); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override { |
| 281 | return true; |
| 282 | } |
| 283 | |
| 284 | void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
| 285 | unsigned ByteAlignment) override {} |
| 286 | void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, |
Francis Visoiu Mistrih | 4d5b107 | 2018-07-02 17:29:43 +0000 | [diff] [blame] | 287 | uint64_t Size = 0, unsigned ByteAlignment = 0, |
| 288 | SMLoc Loc = SMLoc()) override {} |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 289 | void EmitGPRel32Value(const MCExpr *Value) override {} |
| 290 | void BeginCOFFSymbolDef(const MCSymbol *Symbol) override {} |
| 291 | void EmitCOFFSymbolStorageClass(int StorageClass) override {} |
| 292 | void EmitCOFFSymbolType(int Type) override {} |
| 293 | void EndCOFFSymbolDef() override {} |
| 294 | |
Andrea Di Biagio | 01b9fd6 | 2018-10-22 15:36:15 +0000 | [diff] [blame] | 295 | ArrayRef<MCInst> GetInstructionSequence(unsigned Index) const { |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 296 | return Regions.getInstructionSequence(Index); |
| 297 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 298 | }; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 299 | } // end of anonymous namespace |
| 300 | |
Andrea Di Biagio | 650b5fc | 2018-05-17 12:27:03 +0000 | [diff] [blame] | 301 | static void processOptionImpl(cl::opt<bool> &O, const cl::opt<bool> &Default) { |
| 302 | if (!O.getNumOccurrences() || O.getPosition() < Default.getPosition()) |
| 303 | O = Default.getValue(); |
| 304 | } |
| 305 | |
| 306 | static void processViewOptions() { |
| 307 | if (!EnableAllViews.getNumOccurrences() && |
| 308 | !EnableAllStats.getNumOccurrences()) |
| 309 | return; |
| 310 | |
| 311 | if (EnableAllViews.getNumOccurrences()) { |
Roman Lebedev | 9ddf128 | 2018-06-15 14:01:43 +0000 | [diff] [blame] | 312 | processOptionImpl(PrintSummaryView, EnableAllViews); |
Andrea Di Biagio | 650b5fc | 2018-05-17 12:27:03 +0000 | [diff] [blame] | 313 | processOptionImpl(PrintResourcePressureView, EnableAllViews); |
| 314 | processOptionImpl(PrintTimelineView, EnableAllViews); |
| 315 | processOptionImpl(PrintInstructionInfoView, EnableAllViews); |
| 316 | } |
| 317 | |
| 318 | const cl::opt<bool> &Default = |
| 319 | EnableAllViews.getPosition() < EnableAllStats.getPosition() |
| 320 | ? EnableAllStats |
| 321 | : EnableAllViews; |
| 322 | processOptionImpl(PrintRegisterFileStats, Default); |
| 323 | processOptionImpl(PrintDispatchStats, Default); |
| 324 | processOptionImpl(PrintSchedulerStats, Default); |
| 325 | processOptionImpl(PrintRetireStats, Default); |
| 326 | } |
| 327 | |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 328 | // Returns true on success. |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 329 | static bool runPipeline(mca::Pipeline &P) { |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 330 | // Handle pipeline errors here. |
| 331 | if (auto Err = P.run()) { |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 332 | WithColor::error() << toString(std::move(Err)); |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 333 | return false; |
| 334 | } |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 335 | return true; |
| 336 | } |
| 337 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 338 | int main(int argc, char **argv) { |
Rui Ueyama | 197194b | 2018-04-13 18:26:06 +0000 | [diff] [blame] | 339 | InitLLVM X(argc, argv); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 340 | |
| 341 | // Initialize targets and assembly parsers. |
| 342 | llvm::InitializeAllTargetInfos(); |
| 343 | llvm::InitializeAllTargetMCs(); |
| 344 | llvm::InitializeAllAsmParsers(); |
| 345 | |
| 346 | // Enable printing of available targets when flag --version is specified. |
| 347 | cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); |
| 348 | |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 349 | cl::HideUnrelatedOptions({&ToolOptions, &ViewOptions}); |
| 350 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 351 | // Parse flags and initialize target options. |
| 352 | cl::ParseCommandLineOptions(argc, argv, |
| 353 | "llvm machine code performance analyzer.\n"); |
Andrea Di Biagio | 55e9e0f | 2018-05-17 15:35:14 +0000 | [diff] [blame] | 354 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 355 | MCTargetOptions MCOptions; |
| 356 | MCOptions.PreserveAsmComments = false; |
| 357 | |
| 358 | // Get the target from the triple. If a triple is not specified, then select |
| 359 | // the default triple for the host. If the triple doesn't correspond to any |
| 360 | // registered target, then exit with an error message. |
| 361 | const char *ProgName = argv[0]; |
| 362 | const Target *TheTarget = getTarget(ProgName); |
| 363 | if (!TheTarget) |
| 364 | return 1; |
| 365 | |
| 366 | // GetTarget() may replaced TripleName with a default triple. |
| 367 | // For safety, reconstruct the Triple object. |
| 368 | Triple TheTriple(TripleName); |
| 369 | |
| 370 | ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr = |
| 371 | MemoryBuffer::getFileOrSTDIN(InputFilename); |
| 372 | if (std::error_code EC = BufferPtr.getError()) { |
Jonas Devlieghere | 6adef09 | 2018-04-18 15:26:51 +0000 | [diff] [blame] | 373 | WithColor::error() << InputFilename << ": " << EC.message() << '\n'; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 374 | return 1; |
| 375 | } |
| 376 | |
Andrea Di Biagio | 650b5fc | 2018-05-17 12:27:03 +0000 | [diff] [blame] | 377 | // Apply overrides to llvm-mca specific options. |
| 378 | processViewOptions(); |
| 379 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 380 | SourceMgr SrcMgr; |
| 381 | |
| 382 | // Tell SrcMgr about this buffer, which is what the parser will pick up. |
| 383 | SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); |
| 384 | |
| 385 | std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName)); |
| 386 | assert(MRI && "Unable to create target register info!"); |
| 387 | |
| 388 | std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TripleName)); |
| 389 | assert(MAI && "Unable to create target asm info!"); |
| 390 | |
| 391 | MCObjectFileInfo MOFI; |
| 392 | MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); |
| 393 | MOFI.InitMCObjectFileInfo(TheTriple, /* PIC= */ false, Ctx); |
| 394 | |
| 395 | std::unique_ptr<buffer_ostream> BOS; |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 396 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 397 | mca::CodeRegions Regions(SrcMgr); |
| 398 | MCStreamerWrapper Str(Ctx, Regions); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 399 | |
| 400 | std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo()); |
Andrea Di Biagio | 93c49d5 | 2018-04-25 10:18:25 +0000 | [diff] [blame] | 401 | |
Andrea Di Biagio | 2145b13 | 2018-06-20 10:08:11 +0000 | [diff] [blame] | 402 | std::unique_ptr<MCInstrAnalysis> MCIA( |
| 403 | TheTarget->createMCInstrAnalysis(MCII.get())); |
| 404 | |
Andrea Di Biagio | 93c49d5 | 2018-04-25 10:18:25 +0000 | [diff] [blame] | 405 | if (!MCPU.compare("native")) |
| 406 | MCPU = llvm::sys::getHostCPUName(); |
| 407 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 408 | std::unique_ptr<MCSubtargetInfo> STI( |
| 409 | TheTarget->createMCSubtargetInfo(TripleName, MCPU, /* FeaturesStr */ "")); |
| 410 | if (!STI->isCPUStringValid(MCPU)) |
| 411 | return 1; |
| 412 | |
Andrea Di Biagio | e9384eb | 2018-04-30 12:05:34 +0000 | [diff] [blame] | 413 | if (!PrintInstructionTables && !STI->getSchedModel().isOutOfOrder()) { |
Jonas Devlieghere | 6adef09 | 2018-04-18 15:26:51 +0000 | [diff] [blame] | 414 | WithColor::error() << "please specify an out-of-order cpu. '" << MCPU |
| 415 | << "' is an in-order cpu.\n"; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 416 | return 1; |
| 417 | } |
| 418 | |
| 419 | if (!STI->getSchedModel().hasInstrSchedModel()) { |
Jonas Devlieghere | 6adef09 | 2018-04-18 15:26:51 +0000 | [diff] [blame] | 420 | WithColor::error() |
| 421 | << "unable to find instruction-level scheduling information for" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 422 | << " target triple '" << TheTriple.normalize() << "' and cpu '" << MCPU |
| 423 | << "'.\n"; |
| 424 | |
| 425 | if (STI->getSchedModel().InstrItineraries) |
Jonas Devlieghere | 6adef09 | 2018-04-18 15:26:51 +0000 | [diff] [blame] | 426 | WithColor::note() |
| 427 | << "cpu '" << MCPU << "' provides itineraries. However, " |
| 428 | << "instruction itineraries are currently unsupported.\n"; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 429 | return 1; |
| 430 | } |
| 431 | |
Andrea Di Biagio | 5c46944 | 2018-04-08 15:10:19 +0000 | [diff] [blame] | 432 | std::unique_ptr<MCAsmParser> P(createMCAsmParser(SrcMgr, Ctx, Str, *MAI)); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 433 | MCAsmLexer &Lexer = P->getLexer(); |
| 434 | MCACommentConsumer CC(Regions); |
| 435 | Lexer.setCommentConsumer(&CC); |
| 436 | |
Matt Davis | accb511 | 2018-08-20 22:41:27 +0000 | [diff] [blame] | 437 | if (AssembleInput(*P, TheTarget, *STI, *MCII, MCOptions)) |
Andrea Di Biagio | 5c46944 | 2018-04-08 15:10:19 +0000 | [diff] [blame] | 438 | return 1; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 439 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 440 | if (Regions.empty()) { |
Jonas Devlieghere | 6adef09 | 2018-04-18 15:26:51 +0000 | [diff] [blame] | 441 | WithColor::error() << "no assembly instructions found.\n"; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 442 | return 1; |
| 443 | } |
| 444 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 445 | // Now initialize the output file. |
| 446 | auto OF = getOutputStream(); |
| 447 | if (std::error_code EC = OF.getError()) { |
Jonas Devlieghere | 6adef09 | 2018-04-18 15:26:51 +0000 | [diff] [blame] | 448 | WithColor::error() << EC.message() << '\n'; |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 449 | return 1; |
| 450 | } |
| 451 | |
Andrea Di Biagio | 0626864 | 2018-04-24 16:19:08 +0000 | [diff] [blame] | 452 | unsigned AssemblerDialect = P->getAssemblerDialect(); |
| 453 | if (OutputAsmVariant >= 0) |
| 454 | AssemblerDialect = static_cast<unsigned>(OutputAsmVariant); |
| 455 | std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter( |
| 456 | Triple(TripleName), AssemblerDialect, *MAI, *MCII, *MRI)); |
| 457 | if (!IP) { |
| 458 | WithColor::error() |
| 459 | << "unable to create instruction printer for target triple '" |
| 460 | << TheTriple.normalize() << "' with assembly variant " |
| 461 | << AssemblerDialect << ".\n"; |
| 462 | return 1; |
| 463 | } |
| 464 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 465 | std::unique_ptr<llvm::ToolOutputFile> TOF = std::move(*OF); |
| 466 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 467 | const MCSchedModel &SM = STI->getSchedModel(); |
| 468 | |
| 469 | unsigned Width = SM.IssueWidth; |
| 470 | if (DispatchWidth) |
| 471 | Width = DispatchWidth; |
| 472 | |
Andrea Di Biagio | b5088da | 2018-03-23 11:50:43 +0000 | [diff] [blame] | 473 | // Create an instruction builder. |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 474 | mca::InstrBuilder IB(*STI, *MCII, *MRI, *MCIA); |
Andrea Di Biagio | b5088da | 2018-03-23 11:50:43 +0000 | [diff] [blame] | 475 | |
Matt Davis | 362ea5f | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 476 | // Create a context to control ownership of the pipeline hardware. |
| 477 | mca::Context MCA(*MRI, *STI); |
| 478 | |
| 479 | mca::PipelineOptions PO(Width, RegisterFileSize, LoadQueueSize, |
| 480 | StoreQueueSize, AssumeNoAlias); |
| 481 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 482 | // Number each region in the sequence. |
| 483 | unsigned RegionIdx = 0; |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 484 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 485 | for (const std::unique_ptr<mca::CodeRegion> &Region : Regions) { |
| 486 | // Skip empty code regions. |
| 487 | if (Region->empty()) |
| 488 | continue; |
Andrea Di Biagio | ff9c109 | 2018-03-26 13:44:54 +0000 | [diff] [blame] | 489 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 490 | // Don't print the header of this region if it is the default region, and |
| 491 | // it doesn't have an end location. |
| 492 | if (Region->startLoc().isValid() || Region->endLoc().isValid()) { |
| 493 | TOF->os() << "\n[" << RegionIdx++ << "] Code Region"; |
| 494 | StringRef Desc = Region->getDescription(); |
| 495 | if (!Desc.empty()) |
| 496 | TOF->os() << " - " << Desc; |
| 497 | TOF->os() << "\n\n"; |
Andrea Di Biagio | ff9c109 | 2018-03-26 13:44:54 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 500 | // Lower the MCInst sequence into an mca::Instruction sequence. |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 501 | ArrayRef<MCInst> Insts = Region->getInstructions(); |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 502 | std::vector<std::unique_ptr<mca::Instruction>> LoweredSequence; |
| 503 | for (const MCInst &MCI : Insts) { |
Matt Davis | 9e64a4c | 2018-10-31 17:47:25 +0000 | [diff] [blame^] | 504 | llvm::Expected<std::unique_ptr<mca::Instruction>> Inst = |
| 505 | IB.createInstruction(MCI); |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 506 | if (!Inst) { |
Matt Davis | 9e64a4c | 2018-10-31 17:47:25 +0000 | [diff] [blame^] | 507 | if (auto NewE = handleErrors( |
| 508 | Inst.takeError(), |
| 509 | [&IP, &STI](const mca::InstructionError<MCInst> &IE) { |
| 510 | std::string InstructionStr; |
| 511 | raw_string_ostream SS(InstructionStr); |
| 512 | WithColor::error() << IE.Message << '\n'; |
| 513 | IP->printInst(&IE.Inst, SS, "", *STI); |
| 514 | SS.flush(); |
| 515 | WithColor::note() << "instruction: " << InstructionStr |
| 516 | << '\n'; |
| 517 | })) { |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 518 | // Default case. |
| 519 | WithColor::error() << toString(std::move(NewE)); |
| 520 | } |
| 521 | return 1; |
| 522 | } |
| 523 | |
| 524 | LoweredSequence.emplace_back(std::move(Inst.get())); |
| 525 | } |
| 526 | |
Matt Davis | 9e64a4c | 2018-10-31 17:47:25 +0000 | [diff] [blame^] | 527 | mca::SourceMgr S(LoweredSequence, PrintInstructionTables ? 1 : Iterations); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 528 | |
| 529 | if (PrintInstructionTables) { |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 530 | // Create a pipeline, stages, and a printer. |
| 531 | auto P = llvm::make_unique<mca::Pipeline>(); |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 532 | P->appendStage(llvm::make_unique<mca::FetchStage>(S)); |
Andrea Di Biagio | 65c77d7 | 2018-10-24 16:56:43 +0000 | [diff] [blame] | 533 | P->appendStage(llvm::make_unique<mca::InstructionTables>(SM)); |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 534 | mca::PipelinePrinter Printer(*P); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 535 | |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 536 | // Create the views for this pipeline, execute, and emit a report. |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 537 | if (PrintInstructionInfoView) { |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 538 | Printer.addView(llvm::make_unique<mca::InstructionInfoView>( |
| 539 | *STI, *MCII, Insts, *IP)); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 540 | } |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 541 | Printer.addView( |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 542 | llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts)); |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 543 | |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 544 | if (!runPipeline(*P)) |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 545 | return 1; |
| 546 | |
Matt Davis | 0e8402e | 2018-07-14 23:52:50 +0000 | [diff] [blame] | 547 | Printer.printReport(TOF->os()); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 548 | continue; |
| 549 | } |
| 550 | |
Matt Davis | 362ea5f | 2018-07-06 18:03:14 +0000 | [diff] [blame] | 551 | // Create a basic pipeline simulating an out-of-order backend. |
| 552 | auto P = MCA.createDefaultPipeline(PO, IB, S); |
Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 553 | mca::PipelinePrinter Printer(*P); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 554 | |
Roman Lebedev | 9ddf128 | 2018-06-15 14:01:43 +0000 | [diff] [blame] | 555 | if (PrintSummaryView) |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 556 | Printer.addView(llvm::make_unique<mca::SummaryView>(SM, Insts, Width)); |
Roman Lebedev | 9ddf128 | 2018-06-15 14:01:43 +0000 | [diff] [blame] | 557 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 558 | if (PrintInstructionInfoView) |
| 559 | Printer.addView( |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 560 | llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, Insts, *IP)); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 561 | |
Andrea Di Biagio | 821f650 | 2018-04-10 14:55:14 +0000 | [diff] [blame] | 562 | if (PrintDispatchStats) |
Andrea Di Biagio | 074ff7c | 2018-04-11 12:31:44 +0000 | [diff] [blame] | 563 | Printer.addView(llvm::make_unique<mca::DispatchStatistics>()); |
Andrea Di Biagio | 821f650 | 2018-04-10 14:55:14 +0000 | [diff] [blame] | 564 | |
Andrea Di Biagio | f41ad5c | 2018-04-11 12:12:53 +0000 | [diff] [blame] | 565 | if (PrintSchedulerStats) |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 566 | Printer.addView(llvm::make_unique<mca::SchedulerStatistics>(*STI)); |
| 567 | |
Andrea Di Biagio | f41ad5c | 2018-04-11 12:12:53 +0000 | [diff] [blame] | 568 | if (PrintRetireStats) |
| 569 | Printer.addView(llvm::make_unique<mca::RetireControlUnitStatistics>()); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 570 | |
| 571 | if (PrintRegisterFileStats) |
| 572 | Printer.addView(llvm::make_unique<mca::RegisterFileStatistics>(*STI)); |
| 573 | |
| 574 | if (PrintResourcePressureView) |
| 575 | Printer.addView( |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 576 | llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, Insts)); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 577 | |
| 578 | if (PrintTimelineView) { |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 579 | unsigned TimelineIterations = |
| 580 | TimelineMaxIterations ? TimelineMaxIterations : 10; |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 581 | Printer.addView(llvm::make_unique<mca::TimelineView>( |
Andrea Di Biagio | 84d0051 | 2018-10-26 10:48:04 +0000 | [diff] [blame] | 582 | *STI, *IP, Insts, std::min(TimelineIterations, S.getNumIterations()), |
| 583 | TimelineMaxCycles)); |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Andrea Di Biagio | df4d65d | 2018-10-29 13:29:22 +0000 | [diff] [blame] | 586 | if (!runPipeline(*P)) |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 587 | return 1; |
| 588 | |
Andrea Di Biagio | c659012 | 2018-04-09 16:39:52 +0000 | [diff] [blame] | 589 | Printer.printReport(TOF->os()); |
Andrea Di Biagio | 9b3cb08 | 2018-07-02 20:39:57 +0000 | [diff] [blame] | 590 | |
| 591 | // Clear the InstrBuilder internal state in preparation for another round. |
| 592 | IB.clear(); |
Andrea Di Biagio | d156929 | 2018-03-26 12:04:53 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 595 | TOF->keep(); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 596 | return 0; |
| 597 | } |