diff options
| author | Slava Zakharin <szakharin@nvidia.com> | 2022-11-03 09:07:44 -0700 |
|---|---|---|
| committer | Slava Zakharin <szakharin@nvidia.com> | 2022-11-03 09:19:02 -0700 |
| commit | 6f04011f15aca2581571989f349b7a3f332bb4f6 (patch) | |
| tree | 7c1f4f5a3cd579cd67b09393acd5a0ae55840a59 /mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | |
| parent | 0eb2f663d27432111e3f0f68a0d586ade4c8036e (diff) | |
[mlir][llvmir] Add support for llvm.signext/zeroext function attributes.
This change-set adds basic support for llvm.signext and llvm.zeroext
attributes, and makes sure that the attributes are translated to LLVM IR
when attached to arguments.
This is needed for https://github.com/llvm/llvm-project/issues/58579
Differential Revision: https://reviews.llvm.org/D137048
Diffstat (limited to 'mlir/lib/Target/LLVMIR/ModuleTranslation.cpp')
| -rw-r--r-- | mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 3f808a5d05f7..7c0e3efe8e0b 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -984,6 +984,25 @@ LogicalResult ModuleTranslation::convertFunctionSignatures() { llvmArg.addAttrs(llvm::AttrBuilder(llvmArg.getContext()) .addAttribute(llvm::Attribute::NoUndef)); } + if (auto attr = function.getArgAttrOfType<UnitAttr>( + argIdx, LLVMDialect::getSExtAttrName())) { + // llvm.signext can be added to any integer argument type. + if (!mlirArgTy.isa<mlir::IntegerType>()) + return function.emitError( + "llvm.signext attribute attached to LLVM non-integer argument"); + llvmArg.addAttrs(llvm::AttrBuilder(llvmArg.getContext()) + .addAttribute(llvm::Attribute::SExt)); + } + if (auto attr = function.getArgAttrOfType<UnitAttr>( + argIdx, LLVMDialect::getZExtAttrName())) { + // llvm.zeroext can be added to any integer argument type. + if (!mlirArgTy.isa<mlir::IntegerType>()) + return function.emitError( + "llvm.zeroext attribute attached to LLVM non-integer argument"); + llvmArg.addAttrs(llvm::AttrBuilder(llvmArg.getContext()) + .addAttribute(llvm::Attribute::ZExt)); + } + ++argIdx; } |
