forked from OSchip/llvm-project
[mlir] Adds argument attributes for using LLVM's sret and byval attributes
to the conversion of LLVM IR dialect. These attributes are used in FIR to support the lowering of Fortran using target-specific calling conventions. Add roundtrip tests. Add changes per review comments/concerns. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D94052
This commit is contained in:
parent
ce7f30b2a8
commit
70b841ac31
|
@ -1102,6 +1102,22 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
|
|||
llvm::AttrBuilder().addAlignmentAttr(llvm::Align(attr.getInt())));
|
||||
}
|
||||
|
||||
if (auto attr = func.getArgAttrOfType<UnitAttr>(argIdx, "llvm.sret")) {
|
||||
auto argTy = mlirArg.getType();
|
||||
if (!argTy.isa<LLVM::LLVMPointerType>())
|
||||
return func.emitError(
|
||||
"llvm.sret attribute attached to LLVM non-pointer argument");
|
||||
llvmArg.addAttr(llvm::Attribute::AttrKind::StructRet);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
valueMapping[mlirArg] = &llvmArg;
|
||||
argIdx++;
|
||||
}
|
||||
|
|
|
@ -87,6 +87,16 @@ module {
|
|||
llvm.return
|
||||
}
|
||||
|
||||
// CHECK: llvm.func @byvalattr(%{{.*}}: !llvm.ptr<i32> {llvm.byval})
|
||||
llvm.func @byvalattr(%arg0: !llvm.ptr<i32> {llvm.byval}) {
|
||||
llvm.return
|
||||
}
|
||||
|
||||
// CHECK: llvm.func @sretattr(%{{.*}}: !llvm.ptr<i32> {llvm.sret})
|
||||
llvm.func @sretattr(%arg0: !llvm.ptr<i32> {llvm.sret}) {
|
||||
llvm.return
|
||||
}
|
||||
|
||||
// CHECK: llvm.func @variadic(...)
|
||||
llvm.func @variadic(...)
|
||||
|
||||
|
|
|
@ -14,6 +14,19 @@ llvm.func @invalid_noalias(%arg0 : !llvm.float {llvm.noalias = true}) -> !llvm.f
|
|||
|
||||
// -----
|
||||
|
||||
// expected-error @+1 {{llvm.sret attribute attached to LLVM non-pointer argument}}
|
||||
llvm.func @invalid_noalias(%arg0 : !llvm.float {llvm.sret}) -> !llvm.float {
|
||||
llvm.return %arg0 : !llvm.float
|
||||
}
|
||||
// -----
|
||||
|
||||
// expected-error @+1 {{llvm.byval attribute attached to LLVM non-pointer argument}}
|
||||
llvm.func @invalid_noalias(%arg0 : !llvm.float {llvm.byval}) -> !llvm.float {
|
||||
llvm.return %arg0 : !llvm.float
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// expected-error @+1 {{llvm.align attribute attached to LLVM non-pointer argument}}
|
||||
llvm.func @invalid_align(%arg0 : !llvm.float {llvm.align = 4}) -> !llvm.float {
|
||||
llvm.return %arg0 : !llvm.float
|
||||
|
|
Loading…
Reference in New Issue