MLIR 22.0.0git
TranslationRegistration.cpp
Go to the documentation of this file.
1//===- TranslationRegistration.cpp - Register translation -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "mlir/IR/BuiltinOps.h"
14#include "llvm/ADT/TypeSwitch.h"
15#include "llvm/Support/Casting.h"
16
17using namespace mlir;
18
19namespace mlir {
20
21//===----------------------------------------------------------------------===//
22// Translation registration
23//===----------------------------------------------------------------------===//
24
27 "irdl-to-cpp", "translate IRDL dialect definitions to C++ definitions",
28 [](Operation *op, raw_ostream &output) {
30 .Case<irdl::DialectOp>([&](irdl::DialectOp dialectOp) {
31 return irdl::translateIRDLDialectToCpp(dialectOp, output);
32 })
33 .Case<ModuleOp>([&](ModuleOp moduleOp) {
34 for (Operation &op : moduleOp.getBody()->getOperations())
35 if (auto dialectOp = llvm::dyn_cast<irdl::DialectOp>(op))
36 if (failed(
37 irdl::translateIRDLDialectToCpp(dialectOp, output)))
38 return failure();
39 return success();
40 })
41 .Default([](Operation *op) {
42 return op->emitError(
43 "unsupported operation for IRDL to C++ translation");
44 });
45 },
46 [](DialectRegistry &registry) { registry.insert<irdl::IRDLDialect>(); });
47}
48
49} // namespace mlir
return success()
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
LogicalResult translateIRDLDialectToCpp(llvm::ArrayRef< irdl::DialectOp > dialects, raw_ostream &output)
Translates an IRDL dialect definition to a C++ definition that can be used with MLIR.
Include the generated interface declarations.
void registerIRDLToCppTranslation()
llvm::TypeSwitch< T, ResultT > TypeSwitch
Definition LLVM.h:144