33 static llvm::cl::opt<bool> help(
"h", llvm::cl::desc(
"Alias for -help"),
36 static llvm::cl::OptionCategory mlirReduceCategory(
"mlir-reduce options");
38 static llvm::cl::opt<std::string> inputFilename(
39 llvm::cl::Positional, llvm::cl::desc(
"<input file>"),
40 llvm::cl::cat(mlirReduceCategory));
42 static llvm::cl::opt<std::string> outputFilename(
43 "o", llvm::cl::desc(
"Output filename for the reduced test case"),
44 llvm::cl::init(
"-"), llvm::cl::cat(mlirReduceCategory));
46 static llvm::cl::opt<bool> noImplicitModule{
49 "Disable implicit addition of a top-level module op during parsing"),
50 llvm::cl::init(
false)};
52 static llvm::cl::opt<bool> allowUnregisteredDialects(
53 "allow-unregistered-dialect",
54 llvm::cl::desc(
"Allow operation with no registered dialects"),
55 llvm::cl::init(
false));
57 static llvm::cl::opt<std::string> splitInputFile(
58 "split-input-file", llvm::cl::ValueOptional,
59 llvm::cl::callback([&](
const std::string &str) {
65 llvm::cl::desc(
"Split the input file into chunks using the given or "
66 "default marker and process each chunk independently"),
69 llvm::cl::HideUnrelatedOptions(mlirReduceCategory);
71 llvm::InitLLVM y(argc, argv);
73 registerReducerPasses();
76 llvm::cl::ParseCommandLineOptions(argc, argv,
77 "MLIR test case reduction tool.\n");
80 llvm::cl::PrintHelpMessage();
83 if (allowUnregisteredDialects)
86 std::string errorMessage;
92 std::unique_ptr<llvm::MemoryBuffer> input =
95 llvm::errs() << errorMessage <<
"\n";
99 auto errorHandler = [&](
const Twine &msg) {
100 return emitError(UnknownLoc::get(&context)) << msg;
103 auto chunkFn = [&](std::unique_ptr<llvm::MemoryBuffer> chunkBuffer,
105 auto sourceMgr = std::make_shared<llvm::SourceMgr>();
106 sourceMgr->AddNewSourceBuffer(std::move(chunkBuffer), SMLoc());
118 if (failed(pm.
run(op.
get())))
120 op.
get()->print(output->os());
125 auto &splitInputFileDelimiter = splitInputFile.getValue();
126 if (!splitInputFileDelimiter.empty())
128 splitInputFileDelimiter,
129 splitInputFileDelimiter);
131 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.