37#include "llvm/ADT/ScopeExit.h"
38#include "llvm/ADT/StringRef.h"
39#include "llvm/Remarks/RemarkFormat.h"
40#include "llvm/Support/CommandLine.h"
41#include "llvm/Support/Debug.h"
42#include "llvm/Support/InitLLVM.h"
43#include "llvm/Support/LogicalResult.h"
44#include "llvm/Support/ManagedStatic.h"
45#include "llvm/Support/Process.h"
46#include "llvm/Support/Regex.h"
47#include "llvm/Support/SourceMgr.h"
48#include "llvm/Support/ThreadPool.h"
49#include "llvm/Support/ToolOutputFile.h"
55class BytecodeVersionParser :
public cl::parser<std::optional<int64_t>> {
57 BytecodeVersionParser(cl::Option &o)
58 : cl::parser<std::optional<int64_t>>(o) {}
60 bool parse(cl::Option &o, StringRef , StringRef arg,
61 std::optional<int64_t> &v) {
63 if (getAsSignedInteger(arg, 10, w))
64 return o.error(
"Invalid argument '" + arg +
65 "', only integer is supported.");
74 MlirOptMainConfigCLOptions() {
80 static cl::opt<bool,
true> allowUnregisteredDialects(
81 "allow-unregistered-dialect",
82 cl::desc(
"Allow operation with no registered dialects"),
83 cl::location(allowUnregisteredDialectsFlag), cl::init(
false));
85 static cl::opt<bool,
true> dumpPassPipeline(
86 "dump-pass-pipeline", cl::desc(
"Print the pipeline that will be run"),
87 cl::location(dumpPassPipelineFlag), cl::init(
false));
89 static cl::opt<bool,
true> emitBytecode(
90 "emit-bytecode", cl::desc(
"Emit bytecode when generating output"),
91 cl::location(emitBytecodeFlag), cl::init(
false));
93 static cl::opt<bool,
true> elideResourcesFromBytecode(
94 "elide-resource-data-from-bytecode",
95 cl::desc(
"Elide resources when generating bytecode"),
96 cl::location(elideResourceDataFromBytecodeFlag), cl::init(
false));
98 static cl::opt<std::string,
true> emitBytecodeProducer(
99 "emit-bytecode-producer",
100 cl::desc(
"Use specified producer when generating bytecode output"),
101 cl::location(emitBytecodeProducerFlag), cl::init(
""));
103 static cl::opt<std::optional<int64_t>,
true,
104 BytecodeVersionParser>
106 "emit-bytecode-version",
107 cl::desc(
"Use specified bytecode when generating output"),
108 cl::location(emitBytecodeVersion), cl::init(std::nullopt));
110 static cl::opt<std::string,
true> irdlFile(
112 cl::desc(
"IRDL file to register before processing the input"),
113 cl::location(irdlFileFlag), cl::init(
""), cl::value_desc(
"filename"));
116 diagnosticVerbosityLevel(
117 "mlir-diagnostic-verbosity-level",
118 cl::desc(
"Choose level of diagnostic information"),
119 cl::location(diagnosticVerbosityLevelFlag),
120 cl::init(VerbosityLevel::ErrorsWarningsAndRemarks),
122 clEnumValN(VerbosityLevel::ErrorsOnly,
"errors",
"Errors only"),
123 clEnumValN(VerbosityLevel::ErrorsAndWarnings,
"warnings",
124 "Errors and warnings"),
125 clEnumValN(VerbosityLevel::ErrorsWarningsAndRemarks,
"remarks",
126 "Errors, warnings and remarks")));
128 static cl::opt<bool,
true> disableDiagnosticNotes(
129 "mlir-disable-diagnostic-notes", cl::desc(
"Disable diagnostic notes."),
130 cl::location(disableDiagnosticNotesFlag), cl::init(
false));
132 static cl::opt<bool,
true> explicitModule(
133 "no-implicit-module",
134 cl::desc(
"Disable implicit addition of a top-level module op during "
136 cl::location(useExplicitModuleFlag), cl::init(
false));
138 static cl::opt<bool,
true> listPasses(
139 "list-passes", cl::desc(
"Print the list of registered passes and exit"),
140 cl::location(listPassesFlag), cl::init(
false));
142 static cl::opt<bool,
true> runReproducer(
143 "run-reproducer", cl::desc(
"Run the pipeline stored in the reproducer"),
144 cl::location(runReproducerFlag), cl::init(
false));
146 static cl::opt<bool,
true> showDialects(
148 cl::desc(
"Print the list of registered dialects and exit"),
149 cl::location(showDialectsFlag), cl::init(
false));
151 static cl::opt<std::string,
true> splitInputFile{
153 llvm::cl::ValueOptional,
154 cl::callback([&](
const std::string &str) {
159 cl::desc(
"Split the input file into chunks using the given or "
160 "default marker and process each chunk independently"),
161 cl::location(splitInputFileFlag),
164 static cl::opt<std::string,
true> outputSplitMarker(
165 "output-split-marker",
166 cl::desc(
"Split marker to use for merging the ouput"),
172 "verify-diagnostics", llvm::cl::ValueOptional,
173 cl::desc(
"Check that emitted diagnostics match expected-* lines on "
174 "the corresponding line"),
175 cl::location(verifyDiagnosticsFlag),
177 clEnumValN(SourceMgrDiagnosticVerifierHandler::Level::All,
179 "Check all diagnostics (expected, unexpected, "
183 clEnumValN(SourceMgrDiagnosticVerifierHandler::Level::All,
"",
184 "Check all diagnostics (expected, unexpected, "
187 SourceMgrDiagnosticVerifierHandler::Level::OnlyExpected,
188 "only-expected",
"Check only expected diagnostics"))};
190 static cl::opt<bool,
true> verifyPasses(
192 cl::desc(
"Run the verifier after each transformation pass"),
193 cl::location(verifyPassesFlag), cl::init(
true));
195 static cl::opt<bool,
true> disableVerifyOnParsing(
196 "mlir-very-unsafe-disable-verifier-on-parsing",
197 cl::desc(
"Disable the verifier on parsing (very unsafe)"),
198 cl::location(disableVerifierOnParsingFlag), cl::init(
false));
200 static cl::opt<bool,
true> verifyRoundtrip(
202 cl::desc(
"Round-trip the IR after parsing and ensure it succeeds"),
203 cl::location(verifyRoundtripFlag), cl::init(
false));
205 static cl::list<std::string> passPlugins(
206 "load-pass-plugin", cl::desc(
"Load passes from plugin library"));
208 static cl::opt<std::string,
true>
209 generateReproducerFile(
210 "mlir-generate-reproducer",
212 "Generate an mlir reproducer at the provided filename"
213 " (no crash required)"),
214 cl::location(generateReproducerFileFlag), cl::init(
""),
215 cl::value_desc(
"filename"));
217 static cl::OptionCategory remarkCategory(
219 "Filter remarks by regular expression (llvm::Regex syntax).");
223 llvm::cl::desc(
"Specify the format for remark output."),
224 cl::location(remarkFormatFlag),
225 llvm::cl::value_desc(
"format"),
226 llvm::cl::init(RemarkFormat::REMARK_FORMAT_STDOUT),
227 llvm::cl::values(clEnumValN(RemarkFormat::REMARK_FORMAT_STDOUT,
229 "Print as emitRemark to command-line"),
230 clEnumValN(RemarkFormat::REMARK_FORMAT_YAML,
"yaml",
232 clEnumValN(RemarkFormat::REMARK_FORMAT_BITSTREAM,
233 "bitstream",
"Print bitstream file")),
234 llvm::cl::cat(remarkCategory)};
238 llvm::cl::desc(
"Specify the policy for remark output."),
239 cl::location(remarkPolicyFlag),
240 llvm::cl::value_desc(
"format"),
241 llvm::cl::init(RemarkPolicy::REMARK_POLICY_ALL),
242 llvm::cl::values(clEnumValN(RemarkPolicy::REMARK_POLICY_ALL,
"all",
243 "Print all remarks"),
244 clEnumValN(RemarkPolicy::REMARK_POLICY_FINAL,
"final",
245 "Print final remarks")),
246 llvm::cl::cat(remarkCategory)};
248 static cl::opt<std::string,
true> remarksAll(
250 cl::desc(
"Show all remarks: passed, missed, failed, analysis"),
251 cl::location(remarksAllFilterFlag), cl::init(
""),
252 cl::cat(remarkCategory));
254 static cl::opt<std::string,
true> remarksFile(
255 "remarks-output-file",
257 "Output file for yaml and bitstream remark formats. Default is "
258 "mlir-remarks.yaml or mlir-remarks.bitstream"),
259 cl::location(remarksOutputFileFlag), cl::init(
""),
260 cl::cat(remarkCategory));
262 static cl::opt<std::string,
true> remarksPassed(
263 "remarks-filter-passed", cl::desc(
"Show passed remarks"),
264 cl::location(remarksPassedFilterFlag), cl::init(
""),
265 cl::cat(remarkCategory));
267 static cl::opt<std::string,
true> remarksFailed(
268 "remarks-filter-failed", cl::desc(
"Show failed remarks"),
269 cl::location(remarksFailedFilterFlag), cl::init(
""),
270 cl::cat(remarkCategory));
272 static cl::opt<std::string,
true> remarksMissed(
273 "remarks-filter-missed", cl::desc(
"Show missed remarks"),
274 cl::location(remarksMissedFilterFlag), cl::init(
""),
275 cl::cat(remarkCategory));
277 static cl::opt<std::string,
true> remarksAnalyse(
278 "remarks-filter-analyse", cl::desc(
"Show analysis remarks"),
279 cl::location(remarksAnalyseFilterFlag), cl::init(
""),
280 cl::cat(remarkCategory));
283 passPlugins.setCallback([&](
const std::string &pluginPath) {
286 errs() <<
"Failed to load passes from '" << pluginPath
287 <<
"'. Request ignored.\n";
290 plugin.get().registerPassRegistryCallbacks();
293 static cl::list<std::string> dialectPlugins(
294 "load-dialect-plugin", cl::desc(
"Load dialects from plugin library"));
295 this->dialectPlugins = std::addressof(dialectPlugins);
297 static PassPipelineCLParser passPipeline(
"",
"Compiler passes to run",
"p");
298 setPassPipelineParser(passPipeline);
302 void setDialectPluginsCallback(DialectRegistry ®istry);
306 cl::list<std::string> *dialectPlugins =
nullptr;
314 bool showNotes =
true)
315 : ScopedDiagnosticHandler(ctx) {
316 setHandler([verbosityLevel, showNotes](Diagnostic &diag) {
325 if (verbosityLevel == VerbosityLevel::ErrorsOnly)
330 if (verbosityLevel == VerbosityLevel::ErrorsOnly ||
331 verbosityLevel == VerbosityLevel::ErrorsAndWarnings)
341 llvm_unreachable(
"Unknown diagnostic severity");
362 auto errorHandler = [&](
const Twine &msg) {
363 emitError(UnknownLoc::get(pm.getContext())) << msg;
371 llvm::errs() <<
"\n";
378void MlirOptMainConfigCLOptions::setDialectPluginsCallback(
380 dialectPlugins->setCallback([&](
const std::string &pluginPath) {
383 errs() <<
"Failed to load dialect plugin from '" << pluginPath
384 <<
"'. Request ignored.\n";
387 plugin.get().registerDialectRegistryCallbacks(registry);
393 registry.
insert<irdl::IRDLDialect>();
397 std::string errorMessage;
398 std::unique_ptr<MemoryBuffer> file =
openInputFile(irdlFile, &errorMessage);
400 emitError(UnknownLoc::get(&ctx)) << errorMessage;
407 sourceMgr.AddNewSourceBuffer(std::move(file), SMLoc());
433 if (!irdlFile.empty() && failed(
loadIRDLDialects(irdlFile, roundtripContext)))
436 std::string testType = (useBytecode) ?
"bytecode" :
"textual";
441 llvm::raw_string_ostream ostream(buffer);
445 <<
"failed to write bytecode, cannot verify round-trip.\n";
454 &fallbackResourceMap);
456 if (!roundtripModule) {
457 op->
emitOpError() <<
"failed to parse " << testType
458 <<
" content back, cannot verify round-trip.\n";
465 std::string reference, roundtrip;
467 llvm::raw_string_ostream ostreamref(reference);
468 op->
print(ostreamref,
470 llvm::raw_string_ostream ostreamrndtrip(roundtrip);
471 roundtripModule.
get()->print(
475 if (reference != roundtrip) {
479 <<
" roundTrip testing roundtripped module differs "
480 "from reference:\n<<<<<<Reference\n"
481 << reference <<
"\n=====\n"
482 << roundtrip <<
"\n>>>>>roundtripped\n";
492 return success(succeeded(txtStatus) && succeeded(bcStatus));
503 const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
521 &fallbackResourceMap);
547 auto createPolicy = [&config]()
548 -> std::unique_ptr<mlir::remark::detail::RemarkEmittingPolicyBase> {
550 return std::make_unique<mlir::remark::RemarkEmittingPolicyAll>();
552 return std::make_unique<mlir::remark::RemarkEmittingPolicyFinal>();
554 llvm_unreachable(
"Invalid remark policy");
560 ctx,
nullptr, createPolicy(), cats,
true )))
566 ?
"mlir-remarks.yaml"
569 ctx, file, llvm::remarks::Format::YAML, createPolicy(), cats)))
576 ?
"mlir-remarks.bitstream"
579 ctx, file, llvm::remarks::Format::Bitstream, createPolicy(), cats)))
586 llvm::scope_exit finalizeRemarks([&ctx] {
588 engine->getRemarkEmittingPolicy()->finalize();
596 pm.enableTiming(timing);
603 if (failed(pm.run(*op)))
608 StringRef anchorName = pm.getOpAnchorName();
609 const auto &passes = pm.getPasses();
629 return emitError(UnknownLoc::get(pm.getContext()))
630 <<
"bytecode version while not emitting bytecode";
637 nullptr, &fallbackResourceMap);
646 llvm::MemoryBufferRef sourceBuffer,
649 llvm::ThreadPoolInterface *threadPool) {
651 auto sourceMgr = std::make_shared<SourceMgr>();
654 sourceMgr->AddNewSourceBuffer(
655 llvm::MemoryBuffer::getMemBuffer(sourceBuffer,
658 sourceMgr->AddNewSourceBuffer(std::move(ownedBuffer), SMLoc());
666 std::unique_ptr<ScopedDiagnosticHandler> verifierRegistration;
686 DiagnosticFilter diagnosticFilter(&context,
710 std::string helpHeader = (toolName +
"\nAvailable Dialects: ").str();
712 llvm::raw_string_ostream os(helpHeader);
714 [&](
auto name) { os << name; });
719std::pair<std::string, std::string>
721 static cl::opt<std::string> inputFilename(
722 cl::Positional, cl::desc(
"<input file>"), cl::init(
"-"));
724 static cl::opt<std::string> outputFilename(
"o", cl::desc(
"Output filename"),
725 cl::value_desc(
"filename"),
727 cl::ParseCommandLineOptions(argc, argv, helpHeader);
728 return std::make_pair(inputFilename.getValue(), outputFilename.getValue());
731std::pair<std::string, std::string>
733 llvm::StringRef toolName,
740 llvm::outs() <<
"Available Dialects: ";
742 llvm::outs() <<
"\n";
752 std::unique_ptr<llvm::MemoryBuffer> buffer,
765 ThreadPoolInterface *threadPool =
nullptr;
776 sourceMgr.AddNewSourceBuffer(
777 llvm::MemoryBuffer::getMemBuffer(buffer->getMemBufferRef(),
785 auto chunkFn = [&](std::unique_ptr<MemoryBuffer> chunkBuffer,
786 llvm::MemoryBufferRef sourceBuffer,
raw_ostream &os) {
788 os, std::move(chunkBuffer), sourceBuffer, config, registry,
793 llvm::MemoryBuffer::getMemBuffer(buffer->getMemBufferRef(),
803 llvm::StringRef inputFilename,
804 llvm::StringRef outputFilename,
807 InitLLVM y(argc, argv);
820 if (inputFilename ==
"-" &&
821 sys::Process::FileDescriptorIsDisplayed(fileno(stdin)))
822 llvm::errs() <<
"(processing input from stdin now, hit ctrl-c/ctrl-d to "
826 std::string errorMessage;
829 llvm::errs() << errorMessage <<
"\n";
835 llvm::errs() << errorMessage <<
"\n";
838 if (failed(
MlirOptMain(output->os(), std::move(file), registry, config)))
850 std::string inputFilename, outputFilename;
851 std::tie(inputFilename, outputFilename) =
854 return MlirOptMain(argc, argv, inputFilename, outputFilename, registry);
static ManagedStatic< DebugConfigCLOptions > clOptionsConfig
static LogicalResult printRegisteredDialects(DialectRegistry ®istry)
LogicalResult loadIRDLDialects(StringRef irdlFile, MLIRContext &ctx)
static LogicalResult doVerifyRoundTrip(Operation *op, const MlirOptMainConfig &config, bool useBytecode)
static LogicalResult processBuffer(raw_ostream &os, std::unique_ptr< MemoryBuffer > ownedBuffer, llvm::MemoryBufferRef sourceBuffer, const MlirOptMainConfig &config, DialectRegistry ®istry, SourceMgrDiagnosticVerifierHandler *verifyHandler, llvm::ThreadPoolInterface *threadPool)
Parses the memory buffer.
static LogicalResult printRegisteredPassesAndReturn()
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 provides management for the lifetime of the state used when printing the IR.
This class contains the configuration used for the bytecode writer.
void setElideResourceDataFlag(bool shouldElideResourceData=true)
Set a boolean flag to skip emission of resources into the bytecode file.
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.
SmallVector< StringRef > getRegisteredDialectNames() const
Return the names of dialects registered in this registry with an allocator function.
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.
void setThreadPool(llvm::ThreadPoolInterface &pool)
Set a new thread pool to be used in this context.
void enableMultithreading(bool enable=true)
remark::detail::RemarkEngine * getRemarkEngine()
Returns the remark engine for this context, or nullptr if none has been set.
void printOpOnDiagnostic(bool enable)
Set the flag specifying if we should attach the operation to diagnostics emitted via Operation::emit.
const DialectRegistry & getDialectRegistry()
Return the dialect registry associated with this context.
llvm::ThreadPoolInterface & getThreadPool()
Return the thread pool used by this context.
bool isMultithreadingEnabled()
Return true if multi-threading is enabled by the 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.
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
StringRef inputSplitMarker() const
MlirOptMainConfig & outputSplitMarker(std::string splitMarker=kDefaultSplitMarker)
Set whether to merge the output chunks into one file using the given marker.
bool shouldVerifyRoundtrip() const
SourceMgrDiagnosticVerifierHandler::Level verifyDiagnosticsLevel() const
bool shouldShowNotes() const
StringRef getReproducerFilename() const
Reproducer file generation (no crash required).
std::string getRemarksOutputFile() const
Set the remark output file.
bool shouldShowDialects() const
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 shouldElideResourceDataFromBytecode() const
bool shouldEmitBytecode() const
RemarkFormat getRemarkFormat() const
Set the reproducer output filename.
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 shouldAllowUnregisteredDialects() const
bool shouldUseExplicitModule() const
VerbosityLevel getDiagnosticVerbosityLevel() const
bool shouldRunReproducer() const
Return true if the reproducer should be run.
std::optional< int64_t > bytecodeVersionToEmit() const
bool shouldDumpPassPipeline() const
bool shouldVerifyDiagnostics() const
tracing::DebugConfig & getDebugConfig()
std::string getRemarksPassedFilter() const
Set the remark passed filters.
bool shouldListPasses() const
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.
A wrapper class that allows for printing an operation with a custom AsmState, useful to act as a "str...
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.
This class is a utility diagnostic handler for use with llvm::SourceMgr that verifies that emitted di...
std::unique_ptr< ScopedDiagnosticHandler > registerInContext(MLIRContext *ctx)
Register this handler with ctx and return a scoped registration.
LogicalResult verify()
Returns the status of the handler and verifies that all expected diagnostics were emitted.
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.
static void registerCLOptions()
Register the command line options for debug counters.
This is a RAII class that installs the debug handlers on the context based on the provided configurat...
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.
std::pair< std::string, std::string > parseCLIOptions(int argc, char **argv, llvm::StringRef helpHeader)
Parse command line options.
LogicalResult applyPassManagerCLOptions(PassManager &pm)
Apply any values provided to the pass manager options that were registered with 'registerPassManagerO...
const char *const kDefaultSplitMarker
void registerDefaultTimingManagerCLOptions()
Register a set of useful command-line options that can be used to configure a DefaultTimingManager.
std::unique_ptr< llvm::ToolOutputFile > openOutputFile(llvm::StringRef outputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for writing.
std::string registerCLIOptions(llvm::StringRef toolName, DialectRegistry ®istry)
Register basic command line options.
void printRegisteredPasses()
Prints the passes that were previously registered and stored in passRegistry.
LogicalResult MlirOptMain(llvm::raw_ostream &outputStream, std::unique_ptr< llvm::MemoryBuffer > buffer, DialectRegistry ®istry, const MlirOptMainConfig &config)
Perform the core processing behind mlir-opt.
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.
void registerMLIRContextCLOptions()
Register a set of useful command-line options that can be used to configure various flags within the ...
std::unique_ptr< llvm::MemoryBuffer > openInputFile(llvm::StringRef inputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for reading.
LogicalResult splitAndProcessBuffer(std::unique_ptr< llvm::MemoryBuffer > originalBuffer, ChunkBufferHandler processChunkBuffer, raw_ostream &os, llvm::StringRef inputSplitMarker=kDefaultSplitMarker, llvm::StringRef outputSplitMarker="")
Splits the specified buffer on a marker (// ----- by default), processes each chunk independently acc...
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.
void registerAsmPrinterCLOptions()
Register a set of useful command-line options that can be used to configure various flags within the ...
void registerPassManagerCLOptions()
Register a set of useful command-line options that can be used to configure a pass manager.
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...
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
std::pair< std::string, std::string > registerAndParseCLIOptions(int argc, char **argv, llvm::StringRef toolName, DialectRegistry ®istry)
Register and parse command line options.
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.