Skip to content

Commit

Permalink
[mlir] sret and byval now require a type argument when constructed.
Browse files Browse the repository at this point in the history
Fixes the LLVM code gen bugs and adds the missing tests.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D95378
  • Loading branch information
schweitzpgi authored and memfrob committed Oct 4, 2022
1 parent 0c17ab4 commit 4509d48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,15 +1105,17 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
if (!argTy.isa<LLVM::LLVMPointerType>())
return func.emitError(
"llvm.sret attribute attached to LLVM non-pointer argument");
llvmArg.addAttr(llvm::Attribute::AttrKind::StructRet);
llvmArg.addAttrs(llvm::AttrBuilder().addStructRetAttr(
llvmArg.getType()->getPointerElementType()));
}

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

valueMapping[mlirArg] = &llvmArg;
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/Target/llvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,16 @@ llvm.func @llvm_noalias(%arg0: !llvm.ptr<f32> {llvm.noalias = true}) {
llvm.return
}

// CHECK-LABEL: define void @byvalattr(i32* byval(i32) %
llvm.func @byvalattr(%arg0: !llvm.ptr<i32> {llvm.byval}) {
llvm.return
}

// CHECK-LABEL: define void @sretattr(i32* sret(i32) %
llvm.func @sretattr(%arg0: !llvm.ptr<i32> {llvm.sret}) {
llvm.return
}

// CHECK-LABEL: define void @llvm_align(float* align 4 {{%*.}})
llvm.func @llvm_align(%arg0: !llvm.ptr<f32> {llvm.align = 4}) {
llvm.return
Expand Down

0 comments on commit 4509d48

Please sign in to comment.