17#include <mlir/Pass/Pass.h>
19#include <llvm/ADT/StringExtras.h>
20#include <llvm/Support/CommandLine.h>
21#include <llvm/Support/ErrorHandling.h>
22#include <llvm/Support/raw_ostream.h>
40 template <
typename ValueT,
typename CreateFnT,
typename InitializeFnT>
42 CreateFnT &&createValue, llvm::StringRef kind, InitializeFnT &&initializeValue
44 auto value = createValue();
50 if (failed(initializeValue(*value,
str, error))) {
51 llvm::report_fatal_error(
52 llvm::Twine(
"failed to initialize previously-validated nested ") + kind +
70 static mlir::LogicalResult
71 initializePass(mlir::Pass &pass, llvm::StringRef options, std::string &error) {
72 return pass.initializeOptions(options, [&error](
const llvm::Twine &message) {
73 error = message.str();
74 return mlir::failure();
89 static mlir::LogicalResult
91 llvm::raw_string_ostream errorStream(error);
92 return options.parseFromString(value, errorStream);
111 if (options.consume_front(
"{") && !options.consume_back(
"}")) {
112 return O.error(llvm::Twine(
"expected nested ") + kind +
" options to end with '}'");
118 static void print(llvm::raw_ostream &OS,
const OptionsT &Val) { OS <<
'{' << Val.str <<
'}'; }
121 const Option &O,
const OptionsT &V,
const OptionValue<OptionsT> &Default,
size_t GlobalWidth
123 this->printOptionName(O, GlobalWidth);
124 print(llvm::outs(), V);
125 llvm::outs() <<
" (default: ";
126 if (Default.hasValue()) {
127 print(llvm::outs(), Default.getValue());
129 llvm::outs() <<
"<unspecified>";
131 llvm::outs() <<
")\n";
136template <auto CreatePass>
151 auto pass = CreatePass();
154 return O.error(error);
157 Val.
str = options.str();
164template <
typename PipelineOptionsT>
179 PipelineOptionsT pipelineOptions;
182 return O.error(error);
185 Val.
str = options.str();
bool parseNestedOptions(Option &O, StringRef Arg, StringRef kind, StringRef &options) const
Parse a nested pass or pipeline option payload, optionally stripping a surrounding {....
NestedOptionsParserBase(Option &O)
void printOptionDiff(const Option &O, const OptionsT &V, const OptionValue< OptionsT > &Default, size_t GlobalWidth) const
static void print(llvm::raw_ostream &OS, const OptionsT &Val)
llzk::NestedPassOptions< CreatePass > OptionsT
bool parse(Option &O, StringRef, StringRef Arg, OptionsT &Val)
NestedOptionsParserBase< OptionsT > Base
llzk::NestedPipelineOptions< PipelineOptionsT > OptionsT
NestedOptionsParserBase< OptionsT > Base
bool parse(Option &O, StringRef, StringRef Arg, OptionsT &Val)
Provides the necessary information to the RemoveUnusedDiscardableAllocations pass about operations th...
Stores textual options for a constituent pass after validating them against that pass' native MLIR op...
static mlir::LogicalResult initializePass(mlir::Pass &pass, llvm::StringRef options, std::string &error)
std::unique_ptr< mlir::Pass > createPass() const
Build a fresh pass instance with the validated options applied.
Stores textual options for a constituent pipeline after validating them against that pipeline's nativ...
std::unique_ptr< PipelineOptionsT > createOptions() const
Build a fresh options object with the validated options applied.
static mlir::LogicalResult initializeOptions(StructInliningFlatteningOptions &options, llvm::StringRef value, std::string &error)
Shared storage and helpers for nested textual pass and pipeline options.
std::string str
The validated textual form without the outer {...} delimiters.
std::unique_ptr< ValueT > createValidatedValue(CreateFnT &&createValue, llvm::StringRef kind, InitializeFnT &&initializeValue) const
Recreate a nested value from the stored option string and re-validate it.