31 static llvm::cl::OptionCategory mlirReduceCategory(
"mlir-reduce options");
33 static llvm::cl::opt<std::string> inputFilename(
34 llvm::cl::Positional, llvm::cl::desc(
"<input file>"),
35 llvm::cl::cat(mlirReduceCategory));
37 static llvm::cl::opt<std::string> outputFilename(
38 "o", llvm::cl::desc(
"Output filename for the reduced test case"),
39 llvm::cl::init(
"-"), llvm::cl::cat(mlirReduceCategory));
41 static llvm::cl::opt<bool> noImplicitModule{
44 "Disable implicit addition of a top-level module op during parsing"),
45 llvm::cl::init(
false)};
47 static llvm::cl::opt<bool> allowUnregisteredDialects(
48 "allow-unregistered-dialect",
49 llvm::cl::desc(
"Allow operation with no registered dialects"),
50 llvm::cl::init(
false));
52 static llvm::cl::opt<std::string> splitInputFile(
53 "split-input-file", llvm::cl::ValueOptional,
54 llvm::cl::callback([&](
const std::string &str) {
60 llvm::cl::desc(
"Split the input file into chunks using the given or "
61 "default marker and process each chunk independently"),
64 llvm::cl::HideUnrelatedOptions(mlirReduceCategory);
66 llvm::InitLLVM y(argc, argv);
71 llvm::cl::ParseCommandLineOptions(argc, argv,
72 "MLIR test case reduction tool.\n");
74 if (allowUnregisteredDialects)
77 std::string errorMessage;
83 std::unique_ptr<llvm::MemoryBuffer> input =
86 llvm::errs() << errorMessage <<
"\n";
90 auto errorHandler = [&](
const Twine &msg) {
91 return emitError(UnknownLoc::get(&context)) << msg;
94 auto chunkFn = [&](std::unique_ptr<llvm::MemoryBuffer> chunkBuffer,
96 auto sourceMgr = std::make_shared<llvm::SourceMgr>();
97 sourceMgr->AddNewSourceBuffer(std::move(chunkBuffer), SMLoc());
109 if (failed(pm.
run(op.
get())))
111 op.
get()->print(output->os());
116 auto &splitInputFileDelimiter = splitInputFile.getValue();
117 if (!splitInputFileDelimiter.empty())
119 splitInputFileDelimiter,
120 splitInputFileDelimiter);
122 return chunkFn(std::move(input), output->os());
MLIRContext is the top-level object for a collection of MLIR operations.
void allowUnregisteredDialects(bool allow=true)
Enables creating operations in unregistered dialects.
std::unique_ptr< llvm::ToolOutputFile > openOutputFile(llvm::StringRef outputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for writing.
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...
OwningOpRef< Operation * > parseSourceFileForTool(const std::shared_ptr< llvm::SourceMgr > &sourceMgr, const ParserConfig &config, bool insertImplicitModule)
This parses the file specified by the indicated SourceMgr.