@@ -40,10 +40,32 @@ class CIRDialectLLVMIRTranslationInterface
40
40
mlir::Operation *op, llvm::ArrayRef<llvm::Instruction *> instructions,
41
41
mlir::NamedAttribute attribute,
42
42
mlir::LLVM::ModuleTranslation &moduleTranslation) const override {
43
- // Translate CIR's extra function attributes to LLVM's function attributes.
44
- auto func = dyn_cast<mlir::LLVM::LLVMFuncOp>(op);
45
- if (!func)
46
- return mlir::success ();
43
+ if (auto func = dyn_cast<mlir::LLVM::LLVMFuncOp>(op)) {
44
+ amendFunction (func, instructions, attribute, moduleTranslation);
45
+ }
46
+ return mlir::success ();
47
+ }
48
+
49
+ // / Translates the given operation to LLVM IR using the provided IR builder
50
+ // / and saving the state in `moduleTranslation`.
51
+ mlir::LogicalResult convertOperation (
52
+ mlir::Operation *op, llvm::IRBuilderBase &builder,
53
+ mlir::LLVM::ModuleTranslation &moduleTranslation) const final {
54
+
55
+ if (auto cirOp = llvm::dyn_cast<mlir::LLVM::ZeroOp>(op))
56
+ moduleTranslation.mapValue (cirOp.getResult ()) =
57
+ llvm::Constant::getNullValue (
58
+ moduleTranslation.convertType (cirOp.getType ()));
59
+
60
+ return mlir::success ();
61
+ }
62
+
63
+ private:
64
+ // Translate CIR's extra function attributes to LLVM's function attributes.
65
+ void amendFunction (mlir::LLVM::LLVMFuncOp func,
66
+ llvm::ArrayRef<llvm::Instruction *> instructions,
67
+ mlir::NamedAttribute attribute,
68
+ mlir::LLVM::ModuleTranslation &moduleTranslation) const {
47
69
llvm::Function *llvmFunc = moduleTranslation.lookupFunction (func.getName ());
48
70
if (auto extraAttr = mlir::dyn_cast<mlir::cir::ExtraFuncAttributesAttr>(
49
71
attribute.getValue ())) {
@@ -72,25 +94,9 @@ class CIRDialectLLVMIRTranslationInterface
72
94
}
73
95
74
96
// Drop ammended CIR attribute from LLVM op.
75
- op->removeAttr (attribute.getName ());
76
- return mlir::success ();
97
+ func->removeAttr (attribute.getName ());
77
98
}
78
99
79
- // / Translates the given operation to LLVM IR using the provided IR builder
80
- // / and saving the state in `moduleTranslation`.
81
- mlir::LogicalResult convertOperation (
82
- mlir::Operation *op, llvm::IRBuilderBase &builder,
83
- mlir::LLVM::ModuleTranslation &moduleTranslation) const final {
84
-
85
- if (auto cirOp = llvm::dyn_cast<mlir::LLVM::ZeroOp>(op))
86
- moduleTranslation.mapValue (cirOp.getResult ()) =
87
- llvm::Constant::getNullValue (
88
- moduleTranslation.convertType (cirOp.getType ()));
89
-
90
- return mlir::success ();
91
- }
92
-
93
- private:
94
100
void emitOpenCLKernelMetadata (
95
101
mlir::cir::OpenCLKernelMetadataAttr clKernelMetadata,
96
102
llvm::Function *llvmFunc,
0 commit comments