|
23 | 23 | #include "mlir/IR/Diagnostics.h"
|
24 | 24 | #include "mlir/IR/Location.h"
|
25 | 25 | #include "mlir/IR/MLIRContext.h"
|
| 26 | +#include "mlir/IR/Remarks.h" |
26 | 27 | #include "mlir/Parser/Parser.h"
|
27 | 28 | #include "mlir/Pass/PassManager.h"
|
28 | 29 | #include "mlir/Pass/PassRegistry.h"
|
| 30 | +#include "mlir/Remark/RemarkStreamer.h" |
29 | 31 | #include "mlir/Support/FileUtilities.h"
|
30 | 32 | #include "mlir/Support/Timing.h"
|
31 | 33 | #include "mlir/Support/ToolUtilities.h"
|
32 | 34 | #include "mlir/Tools/ParseUtilities.h"
|
33 | 35 | #include "mlir/Tools/Plugins/DialectPlugin.h"
|
34 | 36 | #include "mlir/Tools/Plugins/PassPlugin.h"
|
35 | 37 | #include "llvm/ADT/StringRef.h"
|
| 38 | +#include "llvm/Remarks/RemarkFormat.h" |
36 | 39 | #include "llvm/Support/CommandLine.h"
|
37 | 40 | #include "llvm/Support/InitLLVM.h"
|
38 | 41 | #include "llvm/Support/LogicalResult.h"
|
@@ -204,6 +207,58 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
|
204 | 207 | cl::location(generateReproducerFileFlag), cl::init(""),
|
205 | 208 | cl::value_desc("filename"));
|
206 | 209 |
|
| 210 | + static cl::OptionCategory remarkCategory( |
| 211 | + "Remark Options", |
| 212 | + "Filter remarks by regular expression (llvm::Regex syntax)."); |
| 213 | + |
| 214 | + static llvm::cl::opt<RemarkFormat, /*ExternalStorage=*/true> remarkFormat{ |
| 215 | + "remark-format", |
| 216 | + llvm::cl::desc("Specify the format for remark output."), |
| 217 | + cl::location(remarkFormatFlag), |
| 218 | + llvm::cl::value_desc("format"), |
| 219 | + llvm::cl::init(REMARK_FORMAT_STDOUT), |
| 220 | + llvm::cl::values( |
| 221 | + clEnumValN(REMARK_FORMAT_STDOUT, "emitRemark", |
| 222 | + "Print as emitRemark to command-line"), |
| 223 | + clEnumValN(REMARK_FORMAT_YAML, "yaml", "Print yaml file"), |
| 224 | + clEnumValN(REMARK_FORMAT_BITSTREAM, "bitstream", |
| 225 | + "Print bitstream file")), |
| 226 | + llvm::cl::cat(remarkCategory)}; |
| 227 | + |
| 228 | + static cl::opt<std::string, /*ExternalStorage=*/true> remarksAll( |
| 229 | + "remarks-filter", |
| 230 | + cl::desc("Show all remarks: passed, missed, failed, analysis"), |
| 231 | + cl::location(remarksAllFilterFlag), cl::init(""), |
| 232 | + cl::cat(remarkCategory)); |
| 233 | + |
| 234 | + static cl::opt<std::string, /*ExternalStorage=*/true> remarksFile( |
| 235 | + "remarks-output-file", |
| 236 | + cl::desc( |
| 237 | + "Output file for yaml and bitstream remark formats. Default is " |
| 238 | + "mlir-remarks.yaml or mlir-remarks.bitstream"), |
| 239 | + cl::location(remarksOutputFileFlag), cl::init(""), |
| 240 | + cl::cat(remarkCategory)); |
| 241 | + |
| 242 | + static cl::opt<std::string, /*ExternalStorage=*/true> remarksPassed( |
| 243 | + "remarks-filter-passed", cl::desc("Show passed remarks"), |
| 244 | + cl::location(remarksPassedFilterFlag), cl::init(""), |
| 245 | + cl::cat(remarkCategory)); |
| 246 | + |
| 247 | + static cl::opt<std::string, /*ExternalStorage=*/true> remarksFailed( |
| 248 | + "remarks-filter-failed", cl::desc("Show failed remarks"), |
| 249 | + cl::location(remarksFailedFilterFlag), cl::init(""), |
| 250 | + cl::cat(remarkCategory)); |
| 251 | + |
| 252 | + static cl::opt<std::string, /*ExternalStorage=*/true> remarksMissed( |
| 253 | + "remarks-filter-missed", cl::desc("Show missed remarks"), |
| 254 | + cl::location(remarksMissedFilterFlag), cl::init(""), |
| 255 | + cl::cat(remarkCategory)); |
| 256 | + |
| 257 | + static cl::opt<std::string, /*ExternalStorage=*/true> remarksAnalyse( |
| 258 | + "remarks-filter-analyse", cl::desc("Show analysis remarks"), |
| 259 | + cl::location(remarksAnalyseFilterFlag), cl::init(""), |
| 260 | + cl::cat(remarkCategory)); |
| 261 | + |
207 | 262 | /// Set the callback to load a pass plugin.
|
208 | 263 | passPlugins.setCallback([&](const std::string &pluginPath) {
|
209 | 264 | auto plugin = PassPlugin::load(pluginPath);
|
@@ -241,23 +296,23 @@ class DiagnosticFilter : public ScopedDiagnosticHandler {
|
241 | 296 | setHandler([verbosityLevel, showNotes](Diagnostic &diag) {
|
242 | 297 | auto severity = diag.getSeverity();
|
243 | 298 | switch (severity) {
|
244 |
| - case DiagnosticSeverity::Error: |
| 299 | + case mlir::DiagnosticSeverity::Error: |
245 | 300 | // failure indicates that the error is not handled by the filter and
|
246 | 301 | // goes through to the default handler. Therefore, the error can be
|
247 | 302 | // successfully printed.
|
248 | 303 | return failure();
|
249 |
| - case DiagnosticSeverity::Warning: |
| 304 | + case mlir::DiagnosticSeverity::Warning: |
250 | 305 | if (verbosityLevel == VerbosityLevel::ErrorsOnly)
|
251 | 306 | return success();
|
252 | 307 | else
|
253 | 308 | return failure();
|
254 |
| - case DiagnosticSeverity::Remark: |
| 309 | + case mlir::DiagnosticSeverity::Remark: |
255 | 310 | if (verbosityLevel == VerbosityLevel::ErrorsOnly ||
|
256 | 311 | verbosityLevel == VerbosityLevel::ErrorsAndWarnings)
|
257 | 312 | return success();
|
258 | 313 | else
|
259 | 314 | return failure();
|
260 |
| - case DiagnosticSeverity::Note: |
| 315 | + case mlir::DiagnosticSeverity::Note: |
261 | 316 | if (showNotes)
|
262 | 317 | return failure();
|
263 | 318 | else
|
@@ -462,6 +517,41 @@ performActions(raw_ostream &os,
|
462 | 517 |
|
463 | 518 | context->enableMultithreading(wasThreadingEnabled);
|
464 | 519 |
|
| 520 | + remark::RemarkCategories cats{ |
| 521 | + config.getRemarksAllFilter(), config.getRemarksPassedFilter(), |
| 522 | + config.getRemarksMissedFilter(), config.getRemarksAnalyseFilter(), |
| 523 | + config.getRemarksFailedFilter()}; |
| 524 | + |
| 525 | + mlir::MLIRContext &ctx = *context; |
| 526 | + |
| 527 | + switch (config.getRemarkFormat()) { |
| 528 | + case REMARK_FORMAT_STDOUT: |
| 529 | + if (failed(mlir::remark::enableOptimizationRemarks( |
| 530 | + ctx, nullptr, cats, true /*printAsEmitRemarks*/))) |
| 531 | + return failure(); |
| 532 | + break; |
| 533 | + |
| 534 | + case REMARK_FORMAT_YAML: { |
| 535 | + std::string file = config.getRemarksOutputFile().empty() |
| 536 | + ? "mlir-remarks.yaml" |
| 537 | + : config.getRemarksOutputFile(); |
| 538 | + if (failed(mlir::remark::enableOptimizationRemarksWithLLVMStreamer( |
| 539 | + ctx, file, llvm::remarks::Format::YAML, cats))) |
| 540 | + return failure(); |
| 541 | + break; |
| 542 | + } |
| 543 | + |
| 544 | + case REMARK_FORMAT_BITSTREAM: { |
| 545 | + std::string file = config.getRemarksOutputFile().empty() |
| 546 | + ? "mlir-remarks.bitstream" |
| 547 | + : config.getRemarksOutputFile(); |
| 548 | + if (failed(mlir::remark::enableOptimizationRemarksWithLLVMStreamer( |
| 549 | + ctx, file, llvm::remarks::Format::Bitstream, cats))) |
| 550 | + return failure(); |
| 551 | + break; |
| 552 | + } |
| 553 | + } |
| 554 | + |
465 | 555 | // Prepare the pass manager, applying command-line and reproducer options.
|
466 | 556 | PassManager pm(op.get()->getName(), PassManager::Nesting::Implicit);
|
467 | 557 | pm.enableVerifier(config.shouldVerifyPasses());
|
@@ -523,8 +613,8 @@ processBuffer(raw_ostream &os, std::unique_ptr<MemoryBuffer> ownedBuffer,
|
523 | 613 | SMLoc());
|
524 | 614 | sourceMgr->AddNewSourceBuffer(std::move(ownedBuffer), SMLoc());
|
525 | 615 |
|
526 |
| - // Create a context just for the current buffer. Disable threading on creation |
527 |
| - // since we'll inject the thread-pool separately. |
| 616 | + // Create a context just for the current buffer. Disable threading on |
| 617 | + // creation since we'll inject the thread-pool separately. |
528 | 618 | MLIRContext context(registry, MLIRContext::Threading::DISABLED);
|
529 | 619 | if (threadPool)
|
530 | 620 | context.setThreadPool(*threadPool);
|
@@ -669,9 +759,9 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv,
|
669 | 759 | if (config.shouldListPasses())
|
670 | 760 | return printRegisteredPassesAndReturn();
|
671 | 761 |
|
672 |
| - // When reading from stdin and the input is a tty, it is often a user mistake |
673 |
| - // and the process "appears to be stuck". Print a message to let the user know |
674 |
| - // about it! |
| 762 | + // When reading from stdin and the input is a tty, it is often a user |
| 763 | + // mistake and the process "appears to be stuck". Print a message to let the |
| 764 | + // user know about it! |
675 | 765 | if (inputFilename == "-" &&
|
676 | 766 | sys::Process::FileDescriptorIsDisplayed(fileno(stdin)))
|
677 | 767 | llvm::errs() << "(processing input from stdin now, hit ctrl-c/ctrl-d to "
|
|
0 commit comments