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), llvm::cl::cat(mlirReduceCategory)};
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), llvm::cl::cat(mlirReduceCategory));
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"),
62 llvm::cl::init(
""), llvm::cl::cat(mlirReduceCategory));
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;
81 llvm::errs() << errorMessage <<
"\n";
85 std::unique_ptr<llvm::MemoryBuffer> input =
88 llvm::errs() << errorMessage <<
"\n";
92 auto errorHandler = [&](
const Twine &msg) {
93 return emitError(UnknownLoc::get(&context)) << msg;
96 auto chunkFn = [&](std::unique_ptr<llvm::MemoryBuffer> chunkBuffer,
98 auto sourceMgr = std::make_shared<llvm::SourceMgr>();
99 sourceMgr->AddNewSourceBuffer(std::move(chunkBuffer), SMLoc());
111 if (failed(pm.
run(op.
get())))
113 op.
get()->print(output->os());
118 auto &splitInputFileDelimiter = splitInputFile.getValue();
119 if (!splitInputFileDelimiter.empty())
121 splitInputFileDelimiter,
122 splitInputFileDelimiter);
124 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.