26 #include "llvm/Support/InitLLVM.h"
27 #include "llvm/Support/SourceMgr.h"
28 #include "llvm/Support/ToolOutputFile.h"
34 StringRef inputFilename,
35 bool insertImplictModule) {
37 std::string errorMessage;
40 llvm::errs() << errorMessage <<
"\n";
44 auto sourceMgr = std::make_shared<llvm::SourceMgr>();
45 sourceMgr->AddNewSourceBuffer(std::move(file), SMLoc());
53 static llvm::cl::opt<bool> help(
"h", llvm::cl::desc(
"Alias for -help"),
56 static llvm::cl::OptionCategory mlirReduceCategory(
"mlir-reduce options");
58 static llvm::cl::opt<std::string> inputFilename(
59 llvm::cl::Positional, llvm::cl::desc(
"<input file>"),
60 llvm::cl::cat(mlirReduceCategory));
62 static llvm::cl::opt<std::string> outputFilename(
63 "o", llvm::cl::desc(
"Output filename for the reduced test case"),
64 llvm::cl::init(
"-"), llvm::cl::cat(mlirReduceCategory));
66 static llvm::cl::opt<bool> noImplicitModule{
69 "Disable implicit addition of a top-level module op during parsing"),
70 llvm::cl::init(
false)};
72 llvm::cl::HideUnrelatedOptions(mlirReduceCategory);
74 llvm::InitLLVM y(argc, argv);
76 registerReducerPasses();
79 llvm::cl::ParseCommandLineOptions(argc, argv,
80 "MLIR test case reduction tool.\n");
83 llvm::cl::PrintHelpMessage();
87 std::string errorMessage;
94 loadModule(context, inputFilename, !noImplicitModule);
98 auto errorHandler = [&](
const Twine &msg) {
112 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.
void print(raw_ostream &os, const OpPrintingFlags &flags=std::nullopt)
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.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
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.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
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)
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.