diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp index 62a988b37533..65fe667f6ff9 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp @@ -39,10 +39,32 @@ class CIRDialectLLVMIRTranslationInterface mlir::Operation *op, llvm::ArrayRef instructions, mlir::NamedAttribute attribute, mlir::LLVM::ModuleTranslation &moduleTranslation) const override { - // Translate CIR's extra function attributes to LLVM's function attributes. - auto func = dyn_cast(op); - if (!func) - return mlir::success(); + if (auto func = dyn_cast(op)) { + amendFunction(func, instructions, attribute, moduleTranslation); + } + return mlir::success(); + } + + /// Translates the given operation to LLVM IR using the provided IR builder + /// and saving the state in `moduleTranslation`. + mlir::LogicalResult convertOperation( + mlir::Operation *op, llvm::IRBuilderBase &builder, + mlir::LLVM::ModuleTranslation &moduleTranslation) const final { + + if (auto cirOp = llvm::dyn_cast(op)) + moduleTranslation.mapValue(cirOp.getResult()) = + llvm::Constant::getNullValue( + moduleTranslation.convertType(cirOp.getType())); + + return mlir::success(); + } + +private: + // Translate CIR's extra function attributes to LLVM's function attributes. + void amendFunction(mlir::LLVM::LLVMFuncOp func, + llvm::ArrayRef instructions, + mlir::NamedAttribute attribute, + mlir::LLVM::ModuleTranslation &moduleTranslation) const { llvm::Function *llvmFunc = moduleTranslation.lookupFunction(func.getName()); if (auto extraAttr = mlir::dyn_cast( attribute.getValue())) { @@ -71,25 +93,9 @@ class CIRDialectLLVMIRTranslationInterface } // Drop ammended CIR attribute from LLVM op. - op->removeAttr(attribute.getName()); - return mlir::success(); + func->removeAttr(attribute.getName()); } - /// Translates the given operation to LLVM IR using the provided IR builder - /// and saving the state in `moduleTranslation`. - mlir::LogicalResult convertOperation( - mlir::Operation *op, llvm::IRBuilderBase &builder, - mlir::LLVM::ModuleTranslation &moduleTranslation) const final { - - if (auto cirOp = llvm::dyn_cast(op)) - moduleTranslation.mapValue(cirOp.getResult()) = - llvm::Constant::getNullValue( - moduleTranslation.convertType(cirOp.getType())); - - return mlir::success(); - } - -private: void emitOpenCLKernelMetadata( mlir::cir::OpenCLKernelMetadataAttr clKernelMetadata, llvm::Function *llvmFunc,