Skip to content

Commit 1d6df1f

Browse files
committed
[mlir] sret and byval now require a type argument when constructed.
Fixes the LLVM code gen bugs and adds the missing tests. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D95378
1 parent 302432f commit 1d6df1f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1105,15 +1105,17 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
11051105
if (!argTy.isa<LLVM::LLVMPointerType>())
11061106
return func.emitError(
11071107
"llvm.sret attribute attached to LLVM non-pointer argument");
1108-
llvmArg.addAttr(llvm::Attribute::AttrKind::StructRet);
1108+
llvmArg.addAttrs(llvm::AttrBuilder().addStructRetAttr(
1109+
llvmArg.getType()->getPointerElementType()));
11091110
}
11101111

11111112
if (auto attr = func.getArgAttrOfType<UnitAttr>(argIdx, "llvm.byval")) {
11121113
auto argTy = mlirArg.getType();
11131114
if (!argTy.isa<LLVM::LLVMPointerType>())
11141115
return func.emitError(
11151116
"llvm.byval attribute attached to LLVM non-pointer argument");
1116-
llvmArg.addAttr(llvm::Attribute::AttrKind::ByVal);
1117+
llvmArg.addAttrs(llvm::AttrBuilder().addByValAttr(
1118+
llvmArg.getType()->getPointerElementType()));
11171119
}
11181120

11191121
valueMapping[mlirArg] = &llvmArg;

mlir/test/Target/llvmir.mlir

+10
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,16 @@ llvm.func @llvm_noalias(%arg0: !llvm.ptr<f32> {llvm.noalias = true}) {
939939
llvm.return
940940
}
941941

942+
// CHECK-LABEL: define void @byvalattr(i32* byval(i32) %
943+
llvm.func @byvalattr(%arg0: !llvm.ptr<i32> {llvm.byval}) {
944+
llvm.return
945+
}
946+
947+
// CHECK-LABEL: define void @sretattr(i32* sret(i32) %
948+
llvm.func @sretattr(%arg0: !llvm.ptr<i32> {llvm.sret}) {
949+
llvm.return
950+
}
951+
942952
// CHECK-LABEL: define void @llvm_align(float* align 4 {{%*.}})
943953
llvm.func @llvm_align(%arg0: !llvm.ptr<f32> {llvm.align = 4}) {
944954
llvm.return

0 commit comments

Comments
 (0)