13 #ifndef MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H
14 #define MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H
17 #include "llvm/Support/CommandLine.h"
21 template <
typename OpTy>
29 const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
MLIRContext *)>;
31 std::function<OwningOpRef<Operation *>(llvm::SourceMgr &sourceMgr,
39 std::function<OwningOpRef<Operation *>(llvm::StringRef,
MLIRContext *)>;
44 std::function<LogicalResult(
Operation *, llvm::raw_ostream &output)>;
52 const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
65 std::optional<llvm::Align> inputAlignment)
66 : function(std::move(function)), description(description),
67 inputAlignment(inputAlignment) {}
74 return inputAlignment;
78 LogicalResult
operator()(
const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
79 llvm::raw_ostream &output,
81 return function(sourceMgr, output, context);
89 StringRef description;
92 std::optional<llvm::Align> inputAlignment;
112 llvm::StringRef name, llvm::StringRef description,
116 std::optional<llvm::Align> inputAlignment = std::nullopt);
118 llvm::StringRef name, llvm::StringRef description,
122 std::optional<llvm::Align> inputAlignment = std::nullopt);
124 llvm::StringRef name, llvm::StringRef description,
128 std::optional<llvm::Align> inputAlignment = std::nullopt);
133 llvm::StringRef name, llvm::StringRef description,
138 template <
typename FuncTy,
typename OpTy = detail::first_argument<FuncTy>,
139 typename = std::enable_if_t<!std::is_same_v<OpTy, Operation *>>>
141 llvm::StringRef name, llvm::StringRef description, FuncTy
function,
146 [
function](
Operation *op, raw_ostream &os) -> LogicalResult {
147 if (
auto casted = dyn_cast<OpTy>(op))
148 return function(casted, os);
150 <<
"expected a '" << OpTy::getOperationName()
153 dialectRegistration) {}
166 size_t globalWidth)
const override;
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
Operation is the basic unit of execution within MLIR.
Location getLoc()
The source location the operation was defined or derived from.
OperationName getName()
The name of an operation is the key identifier for it.
This class contains all of the components necessary for performing a translation.
LogicalResult operator()(const std::shared_ptr< llvm::SourceMgr > &sourceMgr, llvm::raw_ostream &output, MLIRContext *context) const
Invoke the translation function with the given input and output streams.
Translation(TranslateFunction function, StringRef description, std::optional< llvm::Align > inputAlignment)
std::optional< llvm::Align > getInputAlignment() const
Return the optional alignment desired for the input of the translation.
StringRef getDescription() const
Return the description of this translation.
Include the generated interface declarations.
std::function< LogicalResult(const std::shared_ptr< llvm::SourceMgr > &sourceMgr, llvm::raw_ostream &output, MLIRContext *)> TranslateFunction
Interface of the function that performs file-to-file translation involving MLIR.
std::function< OwningOpRef< Operation * >(llvm::SourceMgr &sourceMgr, MLIRContext *)> TranslateRawSourceMgrToMLIRFunction
void registerTranslationCLOptions()
Register command-line options used by the translation registry.
std::function< void(DialectRegistry &)> DialectRegistrationFunction
Interface of the function that adds all dialects and dialect extensions used for the translation to t...
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
std::function< LogicalResult(Operation *, llvm::raw_ostream &output)> TranslateFromMLIRFunction
Interface of the function that translates MLIR to a different format and outputs the result to a stre...
std::function< OwningOpRef< Operation * >(llvm::StringRef, MLIRContext *)> TranslateStringRefToMLIRFunction
Interface of the function that translates the given string to MLIR.
std::function< OwningOpRef< Operation * >(const std::shared_ptr< llvm::SourceMgr > &sourceMgr, MLIRContext *)> TranslateSourceMgrToMLIRFunction
Interface of the function that translates the sources managed by sourceMgr to MLIR.
TranslateFromMLIRRegistration(llvm::StringRef name, llvm::StringRef description, FuncTy function, const DialectRegistrationFunction &dialectRegistration=[](DialectRegistry &) {})
TranslateFromMLIRRegistration(llvm::StringRef name, llvm::StringRef description, const TranslateFromMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration=[](DialectRegistry &) {})
TranslateRegistration(llvm::StringRef name, llvm::StringRef description, const TranslateFunction &function)
Use Translate[ToMLIR|FromMLIR]Registration as an initializer that registers a function and associates...
TranslateToMLIRRegistration(llvm::StringRef name, llvm::StringRef description, const TranslateStringRefToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration=[](DialectRegistry &) {}, std::optional< llvm::Align > inputAlignment=std::nullopt)
TranslateToMLIRRegistration(llvm::StringRef name, llvm::StringRef description, const TranslateRawSourceMgrToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration=[](DialectRegistry &) {}, std::optional< llvm::Align > inputAlignment=std::nullopt)
TranslateToMLIRRegistration(llvm::StringRef name, llvm::StringRef description, const TranslateSourceMgrToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration=[](DialectRegistry &) {}, std::optional< llvm::Align > inputAlignment=std::nullopt)
A command line parser for translation functions.
void printOptionInfo(const llvm::cl::Option &o, size_t globalWidth) const override
TranslationParser(llvm::cl::Option &opt)