31 :
public mlir::LLVMTranslationDialectInterface {
33 using LLVMTranslationDialectInterface::LLVMTranslationDialectInterface;
38 mlir::Operation *op, llvm::IRBuilderBase &builder,
39 mlir::LLVM::ModuleTranslation &moduleTranslation)
const final {
41 if (
auto cirOp = llvm::dyn_cast<mlir::LLVM::ZeroOp>(op))
42 moduleTranslation.mapValue(cirOp.getResult()) =
43 llvm::Constant::getNullValue(
44 moduleTranslation.convertType(cirOp.getType()));
46 return mlir::success();
53 mlir::NamedAttribute attribute,
54 mlir::LLVM::ModuleTranslation &moduleTranslation)
const override {
55 if (
auto func = dyn_cast<mlir::LLVM::LLVMFuncOp>(op)) {
57 amendFunction(func, instructions, attribute, moduleTranslation)))
58 return mlir::failure();
59 }
else if (
auto mod = dyn_cast<mlir::ModuleOp>(op)) {
60 if (mlir::failed(amendModule(mod, attribute, moduleTranslation)))
61 return mlir::failure();
63 return mlir::success();
69 amendFunction(mlir::LLVM::LLVMFuncOp func,
71 mlir::NamedAttribute attribute,
72 mlir::LLVM::ModuleTranslation &moduleTranslation)
const {
73 llvm::Function *llvmFunc = moduleTranslation.lookupFunction(func.getName());
74 llvm::StringRef attrName = attribute.getName().strref();
77 llvm::StringRef llvmAttrName = attrName.substr(strlen(
"cir."));
78 if (
auto strAttr = mlir::dyn_cast<mlir::StringAttr>(attribute.getValue()))
79 llvmFunc->addFnAttr(llvmAttrName, strAttr.getValue());
80 return mlir::success();
85 amendModule(mlir::ModuleOp mod, mlir::NamedAttribute attribute,
86 mlir::LLVM::ModuleTranslation &moduleTranslation)
const {
87 llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
88 llvm::LLVMContext &llvmContext = llvmModule->getContext();
90 if (attribute.getName() ==
"cir.amdhsa_code_object_version") {
92 mlir::dyn_cast<mlir::IntegerAttr>(attribute.getValue())) {
93 llvmModule->addModuleFlag(llvm::Module::Error,
94 "amdhsa_code_object_version",
95 static_cast<uint32_t
>(intAttr.getInt()));
99 if (attribute.getName() ==
"cir.amdgpu_printf_kind") {
101 mlir::dyn_cast<mlir::StringAttr>(attribute.getValue())) {
102 llvm::MDString *mdStr =
103 llvm::MDString::get(llvmContext, strAttr.getValue());
104 llvmModule->addModuleFlag(llvm::Module::Error,
"amdgpu_printf_kind",
109 return mlir::success();
mlir::LogicalResult convertOperation(mlir::Operation *op, llvm::IRBuilderBase &builder, mlir::LLVM::ModuleTranslation &moduleTranslation) const final
Translates the given operation to LLVM IR using the provided IR builder and saving the state in modul...
virtual mlir::LogicalResult amendOperation(mlir::Operation *op, llvm::ArrayRef< llvm::Instruction * > instructions, mlir::NamedAttribute attribute, mlir::LLVM::ModuleTranslation &moduleTranslation) const override
Any named attribute in the CIR dialect, i.e, with name started with "cir.", will be handled here.