25 #include "llvm/Support/InitLLVM.h"
26 #include "llvm/Support/SourceMgr.h"
27 #include "llvm/Support/ToolOutputFile.h"
33 StringRef inputFilename,
34 bool insertImplictModule) {
36 std::string errorMessage;
39 llvm::errs() << errorMessage <<
"\n";
43 auto sourceMgr = std::make_shared<llvm::SourceMgr>();
44 sourceMgr->AddNewSourceBuffer(std::move(file), SMLoc());
52 static llvm::cl::opt<bool> help(
"h", llvm::cl::desc(
"Alias for -help"),
55 static llvm::cl::OptionCategory mlirReduceCategory(
"mlir-reduce options");
57 static llvm::cl::opt<std::string> inputFilename(
58 llvm::cl::Positional, llvm::cl::desc(
"<input file>"),
59 llvm::cl::cat(mlirReduceCategory));
61 static llvm::cl::opt<std::string> outputFilename(
62 "o", llvm::cl::desc(
"Output filename for the reduced test case"),
63 llvm::cl::init(
"-"), llvm::cl::cat(mlirReduceCategory));
65 static llvm::cl::opt<bool> noImplicitModule{
68 "Disable implicit addition of a top-level module op during parsing"),
69 llvm::cl::init(
false)};
71 llvm::cl::HideUnrelatedOptions(mlirReduceCategory);
73 llvm::InitLLVM y(argc, argv);
75 registerReducerPasses();
78 llvm::cl::ParseCommandLineOptions(argc, argv,
79 "MLIR test case reduction tool.\n");
82 llvm::cl::PrintHelpMessage();
86 std::string errorMessage;
93 loadModule(context, inputFilename, !noImplicitModule);
97 auto errorHandler = [&](
const Twine &msg) {
108 if (failed(pm.
run(op.
get())))
111 op.
get()->print(output->os());
OwningOpRef< Operation * > loadModule(MLIRContext &context, StringRef inputFilename, bool insertImplictModule)
MLIRContext is the top-level object for a collection of MLIR operations.
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.
The main pass manager and pipeline builder.
LogicalResult run(Operation *op)
Run the passes within this manager on the provided operation.
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.
Include the generated interface declarations.
std::unique_ptr< llvm::MemoryBuffer > openInputFile(llvm::StringRef inputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for reading.
std::unique_ptr< llvm::ToolOutputFile > openOutputFile(llvm::StringRef outputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for writing.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
OwningOpRef< Operation * > parseSourceFileForTool(const std::shared_ptr< llvm::SourceMgr > &sourceMgr, const ParserConfig &config, bool insertImplicitModule)
This parses the file specified by the indicated SourceMgr.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult mlirReduceMain(int argc, char **argv, MLIRContext &context)