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