[mlir][llvm] Expose getters for alias and align attribute names

This adds getters for `llvm.align` and `llvm.noalias` strings that are used
as attribute names in the llvm dialect.

Differential Revision: https://reviews.llvm.org/D91166
This commit is contained in:
Stephan Herhut 2020-11-10 16:59:54 +01:00
parent 5dfe6545d4
commit 67cc5cec77
3 changed files with 10 additions and 4 deletions

View File

@ -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.

View File

@ -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<BoolAttr>())
if (argAttr.first == LLVMDialect::getNoAliasAttrName() &&
!argAttr.second.isa<BoolAttr>())
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<IntegerAttr>())
if (argAttr.first == LLVMDialect::getAlignAttrName() &&
!argAttr.second.isa<IntegerAttr>())
return op->emitError()
<< "llvm.align argument attribute of non integer type";
return success();

View File

@ -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<BoolAttr>(argIdx, "llvm.noalias")) {
if (auto attr = func.getArgAttrOfType<BoolAttr>(
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<LLVM::LLVMType>();
@ -834,7 +835,8 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
llvmArg.addAttr(llvm::Attribute::AttrKind::NoAlias);
}
if (auto attr = func.getArgAttrOfType<IntegerAttr>(argIdx, "llvm.align")) {
if (auto attr = func.getArgAttrOfType<IntegerAttr>(
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<LLVM::LLVMType>();