MLIR  20.0.0git
BuiltinToLLVMIRTranslation.cpp
Go to the documentation of this file.
1 //===- BuiltinToLLVMIRTranslation.cpp - Translate builtin to LLVM IR ------===//
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 //
9 // This file implements a translation between the MLIR builtin dialect and LLVM
10 // IR.
11 //
12 //===----------------------------------------------------------------------===//
14 #include "mlir/IR/BuiltinDialect.h"
15 #include "mlir/IR/BuiltinOps.h"
17 
18 using namespace mlir;
19 
20 namespace {
21 
22 class BuiltinDialectLLVMIRTranslationInterface
24 public:
26 
27  LogicalResult
28  convertOperation(Operation *op, llvm::IRBuilderBase &builder,
29  LLVM::ModuleTranslation &moduleTranslation) const override {
30  return success(isa<ModuleOp>(op));
31  }
32 };
33 
34 } // namespace
35 
37  registry.addExtension(+[](MLIRContext *ctx, BuiltinDialect *dialect) {
38  dialect->addInterfaces<BuiltinDialectLLVMIRTranslationInterface>();
39  });
40 }
41 
43  DialectRegistry registry;
45  context.appendDialectRegistry(registry);
46 }
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
Base class for dialect interfaces providing translation to LLVM IR.
Implementation class for module translation.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
void appendDialectRegistry(const DialectRegistry &registry)
Append the contents of the given dialect registry to the registry associated with this context.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Include the generated interface declarations.
void registerBuiltinDialectTranslation(DialectRegistry &registry)
Register the translation from the builtin dialect to the LLVM IR in the given registry.