diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td index 5530c5dd0f99..58dc908183f6 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td @@ -30,6 +30,8 @@ def LLVM_Dialect : Dialect { let extraClassDeclaration = [{ /// Name of the data layout attributes. static StringRef getDataLayoutAttrName() { return "llvm.data_layout"; } + static StringRef getAlignAttrName() { return "llvm.align"; } + static StringRef getNoAliasAttrName() { return "llvm.noalias"; } /// Verifies if the given string is a well-formed data layout descriptor. /// Uses `reportError` to report errors. diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index e67f09f9c167..5cdb8f326d41 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1833,11 +1833,13 @@ LogicalResult LLVMDialect::verifyRegionArgAttribute(Operation *op, unsigned argIdx, NamedAttribute argAttr) { // Check that llvm.noalias is a boolean attribute. - if (argAttr.first == "llvm.noalias" && !argAttr.second.isa()) + if (argAttr.first == LLVMDialect::getNoAliasAttrName() && + !argAttr.second.isa()) return op->emitError() << "llvm.noalias argument attribute of non boolean type"; // Check that llvm.align is an integer attribute. - if (argAttr.first == "llvm.align" && !argAttr.second.isa()) + if (argAttr.first == LLVMDialect::getAlignAttrName() && + !argAttr.second.isa()) return op->emitError() << "llvm.align argument attribute of non integer type"; return success(); diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index f8c49e743b2a..a275c83e61e2 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -823,7 +823,8 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) { llvm::Argument &llvmArg = std::get<1>(kvp); BlockArgument mlirArg = std::get<0>(kvp); - if (auto attr = func.getArgAttrOfType(argIdx, "llvm.noalias")) { + if (auto attr = func.getArgAttrOfType( + argIdx, LLVMDialect::getNoAliasAttrName())) { // NB: Attribute already verified to be boolean, so check if we can indeed // attach the attribute to this argument, based on its type. auto argTy = mlirArg.getType().dyn_cast(); @@ -834,7 +835,8 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) { llvmArg.addAttr(llvm::Attribute::AttrKind::NoAlias); } - if (auto attr = func.getArgAttrOfType(argIdx, "llvm.align")) { + if (auto attr = func.getArgAttrOfType( + argIdx, LLVMDialect::getAlignAttrName())) { // NB: Attribute already verified to be int, so check if we can indeed // attach the attribute to this argument, based on its type. auto argTy = mlirArg.getType().dyn_cast();