38#include "llvm/ADT/ScopeExit.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/ADT/StringSet.h"
41#include "llvm/Remarks/RemarkFormat.h"
42#include "llvm/Support/CommandLine.h"
43#include "llvm/Support/Debug.h"
44#include "llvm/Support/InitLLVM.h"
45#include "llvm/Support/LogicalResult.h"
46#include "llvm/Support/ManagedStatic.h"
47#include "llvm/Support/Process.h"
48#include "llvm/Support/Regex.h"
49#include "llvm/Support/SourceMgr.h"
50#include "llvm/Support/ThreadPool.h"
51#include "llvm/Support/ToolOutputFile.h"
57class BytecodeVersionParser :
public cl::parser<std::optional<int64_t>> {
59 BytecodeVersionParser(cl::Option &o)
60 : cl::parser<std::optional<int64_t>>(o) {}
62 bool parse(cl::Option &o, StringRef , StringRef arg,
63 std::optional<int64_t> &v) {
65 if (getAsSignedInteger(arg, 10, w))
66 return o.error(
"Invalid argument '" + arg +
67 "', only integer is supported.");
76 MlirOptMainConfigCLOptions() {
82 static cl::opt<bool,
true> allowUnregisteredDialects(
83 "allow-unregistered-dialect",
84 cl::desc(
"Allow operation with no registered dialects"),
85 cl::location(allowUnregisteredDialectsFlag), cl::init(
false));
87 static cl::opt<bool,
true> dumpPassPipeline(
88 "dump-pass-pipeline", cl::desc(
"Print the pipeline that will be run"),
89 cl::location(dumpPassPipelineFlag), cl::init(
false));
91 static cl::opt<bool,
true> emitBytecode(
92 "emit-bytecode", cl::desc(
"Emit bytecode when generating output"),
93 cl::location(emitBytecodeFlag), cl::init(
false));
95 static cl::opt<bool,
true> elideResourcesFromBytecode(
96 "elide-resource-data-from-bytecode",
97 cl::desc(
"Elide resources when generating bytecode"),
98 cl::location(elideResourceDataFromBytecodeFlag), cl::init(
false));
100 static cl::opt<std::string,
true> emitBytecodeProducer(
101 "emit-bytecode-producer",
102 cl::desc(
"Use specified producer when generating bytecode output"),
103 cl::location(emitBytecodeProducerFlag), cl::init(
""));
105 static cl::opt<std::optional<int64_t>,
true,
106 BytecodeVersionParser>
108 "emit-bytecode-version",
109 cl::desc(
"Use specified bytecode when generating output"),
110 cl::location(emitBytecodeVersion), cl::init(std::nullopt));
112 static cl::list<std::string, std::vector<std::string>>
113 bytecodeDialectVersions(
114 "emit-bytecode-dialect-version",
116 "Use the specified dialect version when generating bytecode "
117 "(may be repeated for different dialects)"),
118 cl::value_desc(
"dialect=version"),
119 cl::location(emitBytecodeDialectVersions));
121 static cl::opt<std::string,
true> irdlFile(
123 cl::desc(
"IRDL file to register before processing the input"),
124 cl::location(irdlFileFlag), cl::init(
""), cl::value_desc(
"filename"));
127 diagnosticVerbosityLevel(
128 "mlir-diagnostic-verbosity-level",
129 cl::desc(
"Choose level of diagnostic information"),
130 cl::location(diagnosticVerbosityLevelFlag),
131 cl::init(VerbosityLevel::ErrorsWarningsAndRemarks),
133 clEnumValN(VerbosityLevel::ErrorsOnly,
"errors",
"Errors only"),
134 clEnumValN(VerbosityLevel::ErrorsAndWarnings,
"warnings",
135 "Errors and warnings"),
136 clEnumValN(VerbosityLevel::ErrorsWarningsAndRemarks,
"remarks",
137 "Errors, warnings and remarks")));
139 static cl::opt<bool,
true> disableDiagnosticNotes(
140 "mlir-disable-diagnostic-notes", cl::desc(
"Disable diagnostic notes."),
141 cl::location(disableDiagnosticNotesFlag), cl::init(
false));
143 static cl::opt<bool,
true> explicitModule(
144 "no-implicit-module",
145 cl::desc(
"Disable implicit addition of a top-level module op during "
147 cl::location(useExplicitModuleFlag), cl::init(
false));
149 static cl::opt<bool,
true> listPasses(
150 "list-passes", cl::desc(
"Print the list of registered passes and exit"),
151 cl::location(listPassesFlag), cl::init(
false));
153 static cl::opt<bool,
true> runReproducer(
154 "run-reproducer", cl::desc(
"Run the pipeline stored in the reproducer"),
155 cl::location(runReproducerFlag), cl::init(
false));
157 static cl::opt<bool,
true> showDialects(
159 cl::desc(
"Print the list of registered dialects and exit"),
160 cl::location(showDialectsFlag), cl::init(
false));
162 static cl::opt<std::string,
true> splitInputFile{
164 llvm::cl::ValueOptional,
165 cl::callback([&](
const std::string &str) {
170 cl::desc(
"Split the input file into chunks using the given or "
171 "default marker and process each chunk independently"),
172 cl::location(splitInputFileFlag),
175 static cl::opt<std::string,
true> outputSplitMarker(
176 "output-split-marker",
177 cl::desc(
"Split marker to use for merging the ouput"),
183 "verify-diagnostics", llvm::cl::ValueOptional,
184 cl::desc(
"Check that emitted diagnostics match expected-* lines on "
185 "the corresponding line"),
186 cl::location(verifyDiagnosticsFlag),
188 clEnumValN(SourceMgrDiagnosticVerifierHandler::Level::All,
190 "Check all diagnostics (expected, unexpected, "
194 clEnumValN(SourceMgrDiagnosticVerifierHandler::Level::All,
"",
195 "Check all diagnostics (expected, unexpected, "
198 SourceMgrDiagnosticVerifierHandler::Level::OnlyExpected,
199 "only-expected",
"Check only expected diagnostics"))};
201 static cl::opt<bool,
true> verifyPasses(
203 cl::desc(
"Run the verifier after each transformation pass"),
204 cl::location(verifyPassesFlag), cl::init(
true));
206 static cl::opt<bool,
true> disableVerifyOnParsing(
207 "mlir-very-unsafe-disable-verifier-on-parsing",
208 cl::desc(
"Disable the verifier on parsing (very unsafe)"),
209 cl::location(disableVerifierOnParsingFlag), cl::init(
false));
211 static cl::opt<bool,
true> verifyRoundtrip(
213 cl::desc(
"Round-trip the IR after parsing and ensure it succeeds"),
214 cl::location(verifyRoundtripFlag), cl::init(
false));
216 static cl::list<std::string> passPlugins(
217 "load-pass-plugin", cl::desc(
"Load passes from plugin library"));
219 static cl::opt<std::string,
true>
220 generateReproducerFile(
221 "mlir-generate-reproducer",
223 "Generate an mlir reproducer at the provided filename"
224 " (no crash required)"),
225 cl::location(generateReproducerFileFlag), cl::init(
""),
226 cl::value_desc(
"filename"));
228 static cl::OptionCategory remarkCategory(
230 "Filter remarks by regular expression (llvm::Regex syntax).");
234 llvm::cl::desc(
"Specify the format for remark output."),
235 cl::location(remarkFormatFlag),
236 llvm::cl::value_desc(
"format"),
237 llvm::cl::init(RemarkFormat::REMARK_FORMAT_STDOUT),
238 llvm::cl::values(clEnumValN(RemarkFormat::REMARK_FORMAT_STDOUT,
240 "Print as emitRemark to command-line"),
241 clEnumValN(RemarkFormat::REMARK_FORMAT_YAML,
"yaml",
243 clEnumValN(RemarkFormat::REMARK_FORMAT_BITSTREAM,
244 "bitstream",
"Print bitstream file")),
245 llvm::cl::cat(remarkCategory)};
249 llvm::cl::desc(
"Specify the policy for remark output."),
250 cl::location(remarkPolicyFlag),
251 llvm::cl::value_desc(
"format"),
252 llvm::cl::init(RemarkPolicy::REMARK_POLICY_ALL),
253 llvm::cl::values(clEnumValN(RemarkPolicy::REMARK_POLICY_ALL,
"all",
254 "Print all remarks"),
255 clEnumValN(RemarkPolicy::REMARK_POLICY_FINAL,
"final",
256 "Print final remarks")),
257 llvm::cl::cat(remarkCategory)};
259 static cl::opt<std::string,
true> remarksAll(
261 cl::desc(
"Show all remarks: passed, missed, failed, analysis"),
262 cl::location(remarksAllFilterFlag), cl::init(
""),
263 cl::cat(remarkCategory));
265 static cl::opt<std::string,
true> remarksFile(
266 "remarks-output-file",
268 "Output file for yaml and bitstream remark formats. Default is "
269 "mlir-remarks.yaml or mlir-remarks.bitstream"),
270 cl::location(remarksOutputFileFlag), cl::init(
""),
271 cl::cat(remarkCategory));
273 static cl::opt<std::string,
true> remarksPassed(
274 "remarks-filter-passed", cl::desc(
"Show passed remarks"),
275 cl::location(remarksPassedFilterFlag), cl::init(
""),
276 cl::cat(remarkCategory));
278 static cl::opt<std::string,
true> remarksFailed(
279 "remarks-filter-failed", cl::desc(
"Show failed remarks"),
280 cl::location(remarksFailedFilterFlag), cl::init(
""),
281 cl::cat(remarkCategory));
283 static cl::opt<std::string,
true> remarksMissed(
284 "remarks-filter-missed", cl::desc(
"Show missed remarks"),
285 cl::location(remarksMissedFilterFlag), cl::init(
""),
286 cl::cat(remarkCategory));
288 static cl::opt<std::string,
true> remarksAnalyse(
289 "remarks-filter-analyse", cl::desc(
"Show analysis remarks"),
290 cl::location(remarksAnalyseFilterFlag), cl::init(
""),
291 cl::cat(remarkCategory));
294 passPlugins.setCallback([&](
const std::string &pluginPath) {
297 errs() <<
"Failed to load passes from '" << pluginPath
298 <<
"'. Request ignored.\n";
301 plugin.get().registerPassRegistryCallbacks();
304 static cl::list<std::string> dialectPlugins(
305 "load-dialect-plugin", cl::desc(
"Load dialects from plugin library"));
306 this->dialectPlugins = std::addressof(dialectPlugins);
308 static PassPipelineCLParser passPipeline(
"",
"Compiler passes to run",
"p");
309 setPassPipelineParser(passPipeline);
313 void setDialectPluginsCallback(DialectRegistry ®istry);
317 cl::list<std::string> *dialectPlugins =
nullptr;
325 bool showNotes =
true)
326 : ScopedDiagnosticHandler(ctx) {
327 setHandler([verbosityLevel, showNotes](Diagnostic &diag) {
336 if (verbosityLevel == VerbosityLevel::ErrorsOnly)
341 if (verbosityLevel == VerbosityLevel::ErrorsOnly ||
342 verbosityLevel == VerbosityLevel::ErrorsAndWarnings)
352 llvm_unreachable(
"Unknown diagnostic severity");
373 auto errorHandler = [&](
const Twine &msg) {
374 emitError(UnknownLoc::get(pm.getContext())) << msg;
382 llvm::errs() <<
"\n";
389void MlirOptMainConfigCLOptions::setDialectPluginsCallback(
391 dialectPlugins->setCallback([&](
const std::string &pluginPath) {
394 errs() <<
"Failed to load dialect plugin from '" << pluginPath
395 <<
"'. Request ignored.\n";
398 plugin.get().registerDialectRegistryCallbacks(registry);
404 registry.
insert<irdl::IRDLDialect>();
408 std::string errorMessage;
409 std::unique_ptr<MemoryBuffer> file =
openInputFile(irdlFile, &errorMessage);
411 emitError(UnknownLoc::get(&ctx)) << errorMessage;
418 sourceMgr.AddNewSourceBuffer(std::move(file), SMLoc());
444 if (!irdlFile.empty() && failed(
loadIRDLDialects(irdlFile, roundtripContext)))
447 std::string testType = (useBytecode) ?
"bytecode" :
"textual";
452 llvm::raw_string_ostream ostream(buffer);
456 <<
"failed to write bytecode, cannot verify round-trip.\n";
465 &fallbackResourceMap);
467 if (!roundtripModule) {
468 op->
emitOpError() <<
"failed to parse " << testType
469 <<
" content back, cannot verify round-trip.\n";
476 std::string reference, roundtrip;
478 llvm::raw_string_ostream ostreamref(reference);
479 op->
print(ostreamref,
481 llvm::raw_string_ostream ostreamrndtrip(roundtrip);
482 roundtripModule.
get()->print(
486 if (reference != roundtrip) {
490 <<
" roundTrip testing roundtripped module differs "
491 "from reference:\n<<<<<<Reference\n"
492 << reference <<
"\n=====\n"
493 << roundtrip <<
"\n>>>>>roundtripped\n";
503 return success(succeeded(txtStatus) && succeeded(bcStatus));
514 const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
532 &fallbackResourceMap);
559 -> std::unique_ptr<mlir::remark::detail::RemarkEmittingPolicyBase> {
561 return std::make_unique<mlir::remark::RemarkEmittingPolicyAll>();
563 return std::make_unique<mlir::remark::RemarkEmittingPolicyFinal>();
565 llvm_unreachable(
"Invalid remark policy");
577 ?
"mlir-remarks.yaml"
580 ctx, file, llvm::remarks::Format::YAML,
createPolicy(), cats)))
587 ?
"mlir-remarks.bitstream"
590 ctx, file, llvm::remarks::Format::Bitstream,
createPolicy(), cats)))
597 llvm::scope_exit finalizeRemarks([&ctx] {
599 engine->getRemarkEmittingPolicy()->finalize();
607 pm.enableTiming(timing);
614 if (failed(pm.run(*op)))
619 StringRef anchorName = pm.getOpAnchorName();
620 const auto &passes = pm.getPasses();
636 auto [name, version] = entry.split(
'=');
637 if (name.empty() || version.empty())
638 return op.
get()->emitError() <<
"expected 'dialect=version' for "
639 "--emit-bytecode-dialect-version, got '"
641 if (!versionedDialects.insert(name).second)
642 return op.
get()->emitError()
643 <<
"duplicate bytecode version for dialect '" << name <<
"'";
646 return op.
get()->emitError()
647 <<
"unknown dialect '" << name <<
"' for bytecode emission";
649 dialect->getRegisteredInterface<BytecodeDialectInterface>();
650 std::unique_ptr<DialectVersion> parsedVersion =
651 interface ? interface->parseVersion(version) :
nullptr;
654 << "dialect '" << name << "' does not support emitting bytecode "
655 << "version '" << version << "'";
656 writerConfig.setDialectVersion(name, std::move(parsedVersion));
658 if (config.shouldElideResourceDataFromBytecode())
659 writerConfig.setElideResourceDataFlag();
660 return writeBytecodeToFile(op.get(), os, writerConfig);
663 if (config.bytecodeVersionToEmit().has_value())
664 return emitError(UnknownLoc::get(pm.getContext()))
665 << "bytecode version while not emitting bytecode";
667 if (!config.bytecodeDialectVersionsToEmit().empty())
668 return emitError(UnknownLoc::get(pm.getContext()))
669 << "dialect bytecode version while not emitting bytecode";
673 AsmState asmState(op.get(),
674 OpPrintingFlags().assumeVerified(
675 config.shouldVerifyPasses() && !pm.empty()),
676 nullptr, &fallbackResourceMap);
677 os << OpWithState(op.get(), asmState) << '\n';
684processBuffer(raw_ostream &os, std::unique_ptr<MemoryBuffer> ownedBuffer,
685 llvm::MemoryBufferRef sourceBuffer,
686 const MlirOptMainConfig &config, DialectRegistry ®istry,
687 SourceMgrDiagnosticVerifierHandler *verifyHandler,
688 llvm::ThreadPoolInterface *threadPool) {
690 auto sourceMgr = std::make_shared<SourceMgr>();
693 sourceMgr->AddNewSourceBuffer(
694 llvm::MemoryBuffer::getMemBuffer(sourceBuffer,
697 sourceMgr->AddNewSourceBuffer(std::move(ownedBuffer), SMLoc());
701 MLIRContext context(registry, MLIRContext::Threading::DISABLED);
703 context.setThreadPool(*threadPool);
705 std::unique_ptr<ScopedDiagnosticHandler> verifierRegistration;
707 verifierRegistration = verifyHandler->registerInContext(&context);
709 StringRef irdlFile = config.getIrdlFile();
710 if (!irdlFile.empty() && failed(loadIRDLDialects(irdlFile, context)))
714 context.allowUnregisteredDialects(config.shouldAllowUnregisteredDialects());
715 if (config.shouldVerifyDiagnostics())
716 context.printOpOnDiagnostic(false);
718 tracing::InstallDebugHandler installDebugHandler(context,
719 config.getDebugConfig());
723 if (!config.shouldVerifyDiagnostics()) {
724 SourceMgrDiagnosticHandler sourceMgrHandler(*sourceMgr, &context);
725 DiagnosticFilter diagnosticFilter(&context,
726 config.getDiagnosticVerbosityLevel(),
727 config.shouldShowNotes());
728 return performActions(os, sourceMgr, &context, config);
734 (void)performActions(os, sourceMgr, &context, config);
739std::string mlir::registerCLIOptions(llvm::StringRef toolName,
740 DialectRegistry ®istry) {
741 MlirOptMainConfig::registerCLOptions(registry);
742 registerAsmPrinterCLOptions();
743 registerMLIRContextCLOptions();
744 registerPassManagerCLOptions();
745 registerDefaultTimingManagerCLOptions();
746 tracing::DebugCounter::registerCLOptions();
749 std::string helpHeader = (toolName + "\nAvailable Dialects: ").str();
751 llvm::raw_string_ostream os(helpHeader);
752 interleaveComma(registry.getRegisteredDialectNames(), os,
753 [&](auto name) { os << name; });
758std::pair<std::string, std::string>
759mlir::parseCLIOptions(int argc, char **argv, llvm::StringRef helpHeader) {
760 static cl::opt<std::string> inputFilename(
761 cl::Positional, cl::desc("<input file>"), cl::init("-"));
763 static cl::opt<std::string> outputFilename("o", cl::desc("Output filename"),
764 cl::value_desc("filename"),
766 cl::ParseCommandLineOptions(argc, argv, helpHeader);
767 return std::make_pair(inputFilename.getValue(), outputFilename.getValue());
770std::pair<std::string, std::string>
771mlir::registerAndParseCLIOptions(int argc, char **argv,
772 llvm::StringRef toolName,
773 DialectRegistry ®istry) {
774 auto helpHeader = registerCLIOptions(toolName, registry);
775 return parseCLIOptions(argc, argv, helpHeader);
778static LogicalResult printRegisteredDialects(DialectRegistry ®istry) {
779 llvm::outs() << "Available Dialects: ";
780 interleave(registry.getRegisteredDialectNames(), llvm::outs(), ",");
781 llvm::outs() << "\n";
785static LogicalResult printRegisteredPassesAndReturn() {
786 mlir::printRegisteredPasses();
790LogicalResult mlir::MlirOptMain(llvm::raw_ostream &outputStream,
791 std::unique_ptr<llvm::MemoryBuffer> buffer,
792 DialectRegistry ®istry,
793 const MlirOptMainConfig &config) {
794 if (config.shouldShowDialects())
795 return printRegisteredDialects(registry);
797 if (config.shouldListPasses())
798 return printRegisteredPassesAndReturn();
804 ThreadPoolInterface *threadPool = nullptr;
810 MLIRContext threadPoolCtx;
811 if (threadPoolCtx.isMultithreadingEnabled())
812 threadPool = &threadPoolCtx.getThreadPool();
815 sourceMgr.AddNewSourceBuffer(
816 llvm::MemoryBuffer::getMemBuffer(buffer->getMemBufferRef(),
822 SourceMgrDiagnosticVerifierHandler sourceMgrHandler(
823 sourceMgr, &threadPoolCtx, config.verifyDiagnosticsLevel());
824 auto chunkFn = [&](std::unique_ptr<MemoryBuffer> chunkBuffer,
825 llvm::MemoryBufferRef sourceBuffer, raw_ostream &os) {
826 return processBuffer(
827 os, std::move(chunkBuffer), sourceBuffer, config, registry,
828 config.shouldVerifyDiagnostics() ? &sourceMgrHandler : nullptr,
831 LogicalResult status = splitAndProcessBuffer(
832 llvm::MemoryBuffer::getMemBuffer(buffer->getMemBufferRef(),
834 chunkFn, outputStream, config.inputSplitMarker(),
835 config.outputSplitMarker());
836 if (config.shouldVerifyDiagnostics() && failed(sourceMgrHandler.verify()))
841LogicalResult mlir::MlirOptMain(int argc, char **argv,
842 llvm::StringRef inputFilename,
843 llvm::StringRef outputFilename,
844 DialectRegistry ®istry) {
846 InitLLVM y(argc, argv);
848 MlirOptMainConfig config = MlirOptMainConfig::createFromCLOptions();
850 if (config.shouldShowDialects())
851 return printRegisteredDialects(registry);
853 if (config.shouldListPasses())
854 return printRegisteredPassesAndReturn();
859 if (inputFilename == "-" &&
860 sys::Process::FileDescriptorIsDisplayed(fileno(stdin)))
861 llvm::errs() << "(processing input from stdin now, hit ctrl-c/ctrl-d to "
865 std::string errorMessage;
866 auto file = openInputFile(inputFilename, &errorMessage);
868 llvm::errs() << errorMessage << "\n";
872 auto output = openOutputFile(outputFilename, &errorMessage);
874 llvm::errs() << errorMessage << "\n";
877 if (failed(MlirOptMain(output->os(), std::move(file), registry, config)))
885LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
886 DialectRegistry ®istry) {
889 std::string inputFilename, outputFilename;
890 std::tie(inputFilename, outputFilename) =
891 registerAndParseCLIOptions(argc, argv, toolName, registry);
893 return MlirOptMain(argc, argv, inputFilename, outputFilename, registry);
if(failed(verifyVectorMemoryOp(getOperation(), memrefType, getVectorType()))) return failure()
static ManagedStatic< DebugConfigCLOptions > clOptionsConfig
LogicalResult loadIRDLDialects(StringRef irdlFile, MLIRContext &ctx)
static LogicalResult doVerifyRoundTrip(Operation *op, const MlirOptMainConfig &config, bool useBytecode)
static LogicalResult performActions(raw_ostream &os, const std::shared_ptr< llvm::SourceMgr > &sourceMgr, MLIRContext *context, const MlirOptMainConfig &config)
Perform the actions on the input file indicated by the command line flags within the specified contex...
This class contains the configuration used for the bytecode writer.
void setDesiredBytecodeVersion(int64_t bytecodeVersion)
Set the desired bytecode version to emit.
Facilities for time measurement and report printing to an output stream.
DiagnosticSeverity getSeverity() const
Returns the severity of this diagnostic.
static llvm::Expected< DialectPlugin > load(const std::string &filename)
Attempts to load a dialect plugin from a given file.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
A fallback map containing external resources not explicitly handled by another parser/printer.
MLIRContext is the top-level object for a collection of MLIR operations.
void appendDialectRegistry(const DialectRegistry ®istry)
Append the contents of the given dialect registry to the registry associated with this context.
void disableMultithreading(bool disable=true)
Set the flag specifying if multi-threading is disabled by the context.
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
void enableMultithreading(bool enable=true)
remark::detail::RemarkEngine * getRemarkEngine()
Returns the remark engine for this context, or nullptr if none has been set.
const DialectRegistry & getDialectRegistry()
Return the dialect registry associated with this context.
void allowUnregisteredDialects(bool allow=true)
Enables creating operations in unregistered dialects.
bool allowsUnregisteredDialects()
Return true if we allow to create operation for unregistered dialects.
bool isMultithreadingEnabled()
Return true if multi-threading is enabled by the context.
Configuration options for the mlir-opt tool.
std::string getRemarksAnalyseFilter() const
Set the remark analyse filters.
std::string getRemarksMissedFilter() const
Set the remark missed filters.
static MlirOptMainConfig createFromCLOptions()
Create a new config with the default set from the CL options.
bool shouldVerifyPasses() const
bool shouldVerifyRoundtrip() const
StringRef getReproducerFilename() const
Reproducer file generation (no crash required).
std::string getRemarksOutputFile() const
Set the remark output file.
std::string getRemarksFailedFilter() const
Set the remark failed filters.
std::function< LogicalResult(PassManager &)> passPipelineCallback
The callback to populate the pass manager.
bool shouldVerifyOnParsing() const
std::string getRemarksAllFilter() const
Set the remark format to use.
RemarkPolicy getRemarkPolicy() const
Set the remark policy to use.
bool shouldEmitBytecode() const
RemarkFormat getRemarkFormat() const
Set the reproducer output filename.
ArrayRef< std::string > bytecodeDialectVersionsToEmit() const
std::optional< StringRef > bytecodeProducerToEmit() const
LogicalResult setupPassPipeline(PassManager &pm) const
Populate the passmanager, if any callback was set.
static void registerCLOptions(DialectRegistry &dialectRegistry)
Register the options as global LLVM command line options.
bool shouldUseExplicitModule() const
bool shouldRunReproducer() const
Return true if the reproducer should be run.
std::optional< int64_t > bytecodeVersionToEmit() const
bool shouldDumpPassPipeline() const
std::string getRemarksPassedFilter() const
Set the remark passed filters.
StringRef getIrdlFile() const
MlirOptMainConfig & setPassPipelineParser(const PassPipelineCLParser &parser)
Set the parser to use to populate the pass manager.
@ Implicit
Implicit nesting behavior.
Set of flags used to control the behavior of the various IR print methods (e.g.
Operation is the basic unit of execution within MLIR.
void print(raw_ostream &os, const OpPrintingFlags &flags={})
MLIRContext * getContext()
Return the context this operation is associated with.
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
OpTy get() const
Allow accessing the internal op.
This class represents a configuration for the MLIR assembly parser.
The main pass manager and pipeline builder.
This class implements a command-line parser for MLIR passes.
LogicalResult addToPipeline(OpPassManager &pm, function_ref< LogicalResult(const Twine &)> errorHandler) const
Adds the passes defined by this parser entry to the given pass manager.
static llvm::Expected< PassPlugin > load(const std::string &filename)
Attempts to load a pass plugin from a given file.
This diagnostic handler is a simple RAII class that registers and erases a diagnostic handler on a gi...
This class is a utility diagnostic handler for use with llvm::SourceMgr.
TimingScope getRootScope()
Get the root timer of this timing manager wrapped in a TimingScope for convenience.
An RAII-style wrapper around a timer that ensures the timer is properly started and stopped.
TimingScope nest(Args... args)
Create a nested timing scope.
void stop()
Manually stop the timer early.
static DebugConfig createFromCLOptions()
Create a new config with the default set from the CL options.
static void registerCLOptions()
Register the options as global LLVM command line options.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
llvm::LogicalResult loadDialects(ModuleOp op)
Load all the dialects defined in the module.
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
Include the generated interface declarations.
LogicalResult applyPassManagerCLOptions(PassManager &pm)
Apply any values provided to the pass manager options that were registered with 'registerPassManagerO...
const char *const kDefaultSplitMarker
std::string makeReproducer(StringRef anchorName, const llvm::iterator_range< OpPassManager::pass_iterator > &passes, Operation *op, StringRef outputFile, bool disableThreads=false, bool verifyPasses=false)
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
std::unique_ptr< llvm::MemoryBuffer > openInputFile(llvm::StringRef inputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for reading.
LogicalResult parseSourceString(llvm::StringRef sourceStr, Block *block, const ParserConfig &config, StringRef sourceName="", LocationAttr *sourceFileLoc=nullptr)
This parses the IR string and appends parsed operations to the given block.
LogicalResult parseSourceFile(const llvm::SourceMgr &sourceMgr, Block *block, const ParserConfig &config, LocationAttr *sourceFileLoc=nullptr)
This parses the file specified by the indicated SourceMgr and appends parsed operations to the given ...
void applyDefaultTimingManagerCLOptions(DefaultTimingManager &tm)
Apply any values that were registered with 'registerDefaultTimingManagerOptions' to a DefaultTimingMa...
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
OwningOpRef< Operation * > parseSourceFileForTool(const std::shared_ptr< llvm::SourceMgr > &sourceMgr, const ParserConfig &config, bool insertImplicitModule)
This parses the file specified by the indicated SourceMgr.
@ REMARK_FORMAT_BITSTREAM
VerbosityLevel
enum class to indicate the verbosity level of the diagnostic filter.
LogicalResult writeBytecodeToFile(Operation *op, raw_ostream &os, const BytecodeWriterConfig &config={})
Write the bytecode for the given operation to the provided output stream.
void attachResourceParser(ParserConfig &config)
Attach an assembly resource parser to 'config' that collects the MLIR reproducer configuration into t...
LogicalResult apply(PassManager &pm) const
Apply the reproducer options to 'pm' and its context.