MLIR 23.0.0git
LLVMTranslationInterface.h
Go to the documentation of this file.
1//===- LLVMTranslationInterface.h - Translation to LLVM iface ---*- C++ -*-===//
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 header file defines dialect interfaces for translation to LLVM IR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_TARGET_LLVMIR_LLVMTRANSLATIONINTERFACE_H
14#define MLIR_TARGET_LLVMIR_LLVMTRANSLATIONINTERFACE_H
15
19
20namespace llvm {
21class Instruction;
22class IRBuilderBase;
23} // namespace llvm
24
25namespace mlir {
26namespace LLVM {
28class LLVMFuncOp;
29} // namespace LLVM
30} // namespace mlir
31
32#include "mlir/Target/LLVMIR/LLVMTranslationDialectInterface.h.inc"
33
34namespace mlir {
35
36/// Interface collection for translation to LLVM IR, dispatches to a concrete
37/// interface implementation based on the dialect to which the given op belongs.
39 : public DialectInterfaceCollection<LLVMTranslationDialectInterface> {
40public:
41 using Base::Base;
42
43 /// Translates the given operation to LLVM IR using the interface implemented
44 /// by the op's dialect.
45 virtual LogicalResult
46 convertOperation(Operation *op, llvm::IRBuilderBase &builder,
47 LLVM::ModuleTranslation &moduleTranslation) const {
48 if (const LLVMTranslationDialectInterface *iface = getInterfaceFor(op))
49 return iface->convertOperation(op, builder, moduleTranslation);
50 return failure();
51 }
52
53 /// Acts on the given operation using the interface implemented by the dialect
54 /// of one of the operation's dialect attributes.
55 virtual LogicalResult
57 NamedAttribute attribute,
58 LLVM::ModuleTranslation &moduleTranslation) const {
59 if (const LLVMTranslationDialectInterface *iface =
60 getInterfaceFor(attribute.getNameDialect())) {
61 return iface->amendOperation(op, instructions, attribute,
62 moduleTranslation);
63 }
64 return success();
65 }
66
67 /// Acts on the given function operation using the interface implemented by
68 /// the dialect of one of the function parameter attributes.
69 virtual LogicalResult
70 convertParameterAttr(LLVM::LLVMFuncOp function, int argIdx,
71 NamedAttribute attribute,
72 LLVM::ModuleTranslation &moduleTranslation) const {
73 if (const LLVMTranslationDialectInterface *iface =
74 getInterfaceFor(attribute.getNameDialect())) {
75 return iface->convertParameterAttr(function, argIdx, attribute,
76 moduleTranslation);
77 }
78 function.emitWarning("Unhandled parameter attribute '" +
79 attribute.getName().str() + "'");
80 return success();
81 }
82};
83
84} // namespace mlir
85
86#endif // MLIR_TARGET_LLVMIR_LLVMTRANSLATIONINTERFACE_H
return success()
DialectInterfaceCollection< LLVMTranslationDialectInterface > Base
const LLVMTranslationDialectInterface * getInterfaceFor(Object *obj) const
Interface collection for translation to LLVM IR, dispatches to a concrete interface implementation ba...
virtual LogicalResult convertParameterAttr(LLVM::LLVMFuncOp function, int argIdx, NamedAttribute attribute, LLVM::ModuleTranslation &moduleTranslation) const
Acts on the given function operation using the interface implemented by the dialect of one of the fun...
virtual LogicalResult amendOperation(Operation *op, ArrayRef< llvm::Instruction * > instructions, NamedAttribute attribute, LLVM::ModuleTranslation &moduleTranslation) const
Acts on the given operation using the interface implemented by the dialect of one of the operation's ...
virtual LogicalResult convertOperation(Operation *op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation) const
Translates the given operation to LLVM IR using the interface implemented by the op's dialect.
Implementation class for module translation.
NamedAttribute represents a combination of a name and an Attribute value.
Definition Attributes.h:164
StringAttr getName() const
Return the name of the attribute.
Dialect * getNameDialect() const
Return the dialect of the name of this attribute, if the name is prefixed by a dialect namespace.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
Include the generated interface declarations.