Author: Chaitanya Date: 2026-11-18T09:57:16+05:30 New Revision: 3c1e4b66aaf525f715c0e8f8f682f1b06d6f12cb
URL: https://github.com/llvm/llvm-project/commit/3c1e4b66aaf525f715c0e8f8f682f1b06d6f12cb DIFF: https://github.com/llvm/llvm-project/commit/3c1e4b66aaf525f715c0e8f8f682f1b06d6f12cb.diff LOG: [CIR] Enable CallConvLowering for AMDGPU triples (#233822) **Summary:** - Map AMDGPU triples to the AMDGPU ABI target in the clang pipeline, so `cir-call-conv-lowering` pass runs by default for AMDGPU device code. - Add clang tests that check AMDGPU argument types, return types, C++ records and HIP kernel arguments against classic codegen. Related to issue: https://github.com/llvm/llvm-project/issues/220471 Pre-requisite PRs: https://github.com/llvm/llvm-project/pull/240808 https://github.com/llvm/llvm-project/pull/241158 Assisted by: claude opus 5.5 Added: clang/test/CodeGen/AMDGPU/abi-classify-arg-types.c clang/test/CodeGen/AMDGPU/abi-classify-cxx-records.cpp clang/test/CodeGen/AMDGPU/abi-classify-return-types.c clang/test/CodeGenHIP/amdgpu-kernel-args-abi.hip Modified: clang/lib/CIR/Lowering/CIRPasses.cpp clang/test/CIR/CodeGenCUDA/vtable-host-device.cu clang/test/CIR/CodeGenHIP/cleanup-alloca-addrspace.hip Removed: ################################################################################ diff --git a/clang/lib/CIR/Lowering/CIRPasses.cpp b/clang/lib/CIR/Lowering/CIRPasses.cpp index 43c21f71c34e7f..9b5004fd5e61a5 100644 --- a/clang/lib/CIR/Lowering/CIRPasses.cpp +++ b/clang/lib/CIR/Lowering/CIRPasses.cpp @@ -27,6 +27,8 @@ static CallConvTarget getCallConvTarget(const llvm::Triple &triple) { // Windows is not supported. UEFI shares its convention. if (triple.getArch() == llvm::Triple::x86_64 && !triple.isOSWindowsOrUEFI()) return CallConvTarget::X86_64; + if (triple.isAMDGPU()) + return CallConvTarget::AMDGPU; return CallConvTarget::None; } @@ -130,8 +132,7 @@ runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirContext, if (enableCallConvLowering) { // CallConvLowering rewrites signatures and call sites using the classifier, // so it must run after CXXABILowering has lowered C++ ABI types to plain - // records the classifier can handle. Only the x86_64 System V classifier - // is implemented; other targets are left unchanged. + // records the classifier can handle. CallConvTarget target = getCallConvTarget(*triple); if (target != CallConvTarget::None) { // Source the ABI-compatibility version from the module's serialized diff --git a/clang/test/CIR/CodeGenCUDA/vtable-host-device.cu b/clang/test/CIR/CodeGenCUDA/vtable-host-device.cu index e7cb421ecfbbf6..0fb2e072291f32 100644 --- a/clang/test/CIR/CodeGenCUDA/vtable-host-device.cu +++ b/clang/test/CIR/CodeGenCUDA/vtable-host-device.cu @@ -53,10 +53,10 @@ const char *host_name() { return Square(3.0f).name(); } // HOST-DAG: declare {{.*}}void @__cxa_pure_virtual() // HOST-DAG: declare {{.*}}void @__cxa_deleted_virtual() -// CIR-DEV: cir.func weak {{.*}}@__cxa_deleted_virtual() requires_call_conv_lowering attributes {runtime_func} { +// CIR-DEV: cir.func weak {{.*}}@__cxa_deleted_virtual() attributes {runtime_func} { // CIR-DEV-NEXT: cir.trap // CIR-DEV-NEXT: } -// CIR-DEV: cir.func weak {{.*}}@__cxa_pure_virtual() requires_call_conv_lowering attributes {runtime_func} { +// CIR-DEV: cir.func weak {{.*}}@__cxa_pure_virtual() attributes {runtime_func} { // CIR-DEV-NEXT: cir.trap // CIR-DEV-NEXT: } diff --git a/clang/test/CIR/CodeGenHIP/cleanup-alloca-addrspace.hip b/clang/test/CIR/CodeGenHIP/cleanup-alloca-addrspace.hip index c55cd55a98d675..7cbb8ff8301ec0 100644 --- a/clang/test/CIR/CodeGenHIP/cleanup-alloca-addrspace.hip +++ b/clang/test/CIR/CodeGenHIP/cleanup-alloca-addrspace.hip @@ -7,9 +7,10 @@ // correct address space after flatten cfg. This is important for address-space // aware targets like amdgpu. -// CIR-FLAT-LABEL: cir.func {{.*}} @_Z1fv +// S is not trivially destructible, so f returns it through a generic sret +// pointer rather than a __retval alloca. +// CIR-FLAT-LABEL: cir.func {{.*}} @_Z1fv(%arg0: !cir.ptr<!rec_S> {{.*}}llvm.sret = !rec_S // CIR-FLAT: cir.alloca "__cleanup_dest_slot" {{.*}} : !cir.ptr<!s32i, target_address_space(5)> -// CIR-FLAT: cir.alloca "__retval" {{.*}} : !cir.ptr<!rec_S, target_address_space(5)> // CIR-FLAT: cir.alloca "nrvo" {{.*}} : !cir.ptr<!cir.bool, target_address_space(5)> // CIR-FLAT-LABEL: cir.func {{.*}} @_ZN1SD1Ev @@ -18,9 +19,8 @@ // CIR-FLAT-LABEL: cir.func {{.*}} @_ZN1SD2Ev // CIR-FLAT: cir.alloca "this" {{.*}} : !cir.ptr<!cir.ptr<!rec_S>, target_address_space(5)> -// LLVM-LABEL: define {{.*}} @_Z1fv +// LLVM-LABEL: define {{.*}} void @_Z1fv(ptr {{.*}}sret(%struct.S) // LLVM: alloca i32, align 4, addrspace(5) -// LLVM: alloca %struct.S, align 1, addrspace(5) // LLVM: alloca i8, align 1, addrspace(5) // LLVM-LABEL: define {{.*}} @_ZN1SD1Ev diff --git a/clang/test/CodeGen/AMDGPU/abi-classify-arg-types.c b/clang/test/CodeGen/AMDGPU/abi-classify-arg-types.c new file mode 100644 index 00000000000000..01dfbb69700827 --- /dev/null +++ b/clang/test/CodeGen/AMDGPU/abi-classify-arg-types.c @@ -0,0 +1,380 @@ +// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -emit-llvm %s -o - | FileCheck %s +// RUN: %if cir-enabled %{ %clang_cc1 -triple amdgpu-amd-amdhsa -fclangir -emit-llvm %s -o - | FileCheck %s %} + +// Checks how non-kernel AMDGPU functions pass arguments. + +typedef struct {} empty_t; +typedef struct { char c; } i8_wrapper_t; +typedef struct { int i; } i32_wrapper_t; +typedef struct { float f; } f32_wrapper_t; +typedef struct { int *p; } ptr_wrapper_t; +typedef struct { char a, b; } char2_t; +typedef struct { char a, b, c; } small_t; +typedef union { int i; float f; } int_float_t; +typedef union { + int *ip; + float *fp; +} __attribute__((transparent_union)) transparent_t; +typedef struct { int a, b; } pair_t; +typedef struct { int a, b, c; } triple_t; +typedef struct { int data[17]; } big_t; +typedef struct { int data[16]; } big16_t; +typedef struct { int a : 3; int b : 5; } bits_t; +typedef struct { int n; int data[]; } fam_t; +typedef struct { _Complex double c; } cdwrap_t; +typedef struct { int v[3]; } arrwrap_t; +typedef struct { struct { int a, b, c; } t; } nestwrap_t; +typedef union { int a[3]; double d; } u_pad_t; +typedef union { double d[2]; long l[2]; } u_dl_t; +typedef union __attribute__((packed)) { char c[13]; double d; } u_packed_t; +typedef short short4 __attribute__((ext_vector_type(4))); +typedef float float3 __attribute__((ext_vector_type(3))); + +void arg_void(void) {} + +// CHECK: define {{.*}}void @arg_void() + +// Sub-word integers and bool carry signext or zeroext per their signedness. +void arg_bool(_Bool b) {} + +// CHECK: define {{.*}}void @arg_bool(i1 noundef zeroext %{{.*}}) + +void arg_char(char c) {} + +// CHECK: define {{.*}}void @arg_char(i8 noundef signext %{{.*}}) + +void arg_uchar(unsigned char c) {} + +// CHECK: define {{.*}}void @arg_uchar(i8 noundef zeroext %{{.*}}) + +void arg_short(short s) {} + +// CHECK: define {{.*}}void @arg_short(i16 noundef signext %{{.*}}) + +// The call site carries the same extension as the callee. +void call_char(char c) { arg_char(c); } + +// CHECK: define {{.*}}void @call_char(i8 noundef signext %{{.*}}) +// CHECK: call void @arg_char(i8 noundef signext %{{.*}}) + +// Word-sized and wider scalars pass through unchanged. +void arg_int(int i) {} + +// CHECK: define {{.*}}void @arg_int(i32 noundef %{{.*}}) + +void arg_long(long l) {} + +// CHECK: define {{.*}}void @arg_long(i64 noundef %{{.*}}) + +// 128-bit integers pass whole. +void arg_int128(__int128 i) {} + +// CHECK: define {{.*}}void @arg_int128(i128 noundef %[[I:[^)]+]]) +// CHECK: store i128 %[[I]], ptr %{{.*}} + +void arg_bitint128(_BitInt(128) i) {} + +// CHECK: define {{.*}}void @arg_bitint128(i128 noundef %[[I:[^)]+]]) +// CHECK: store i128 %[[I]], ptr %{{.*}}, align 8 + +void arg_float(float f) {} + +// CHECK: define {{.*}}void @arg_float(float noundef %{{.*}}) + +void arg_double(double d) {} + +// CHECK: define {{.*}}void @arg_double(double noundef %{{.*}}) + +void arg_half(_Float16 h) {} + +// CHECK: define {{.*}}void @arg_half(half noundef %{{.*}}) + +// Outside a HIP kernel a generic pointer stays generic. +void arg_ptr(int *p) {} + +// CHECK: define {{.*}}void @arg_ptr(ptr noundef %{{.*}}) + +// A _BitInt wider than 64 bits and vectors, including 16-bit and 3-element +// ones, pass whole. +void arg_bitint65(_BitInt(65) i) {} + +// CHECK: define {{.*}}void @arg_bitint65(i65 noundef %{{.*}}) + +void arg_short4(short4 v) {} + +// CHECK: define {{.*}}void @arg_short4(<4 x i16> noundef %{{.*}}) + +void arg_float3(float3 v) {} + +// CHECK: define {{.*}}void @arg_float3(<3 x float> noundef %{{.*}}) + +// An empty struct is dropped from the signature. +void arg_empty(empty_t e) {} + +// CHECK: define {{.*}}void @arg_empty() + +// Single-element structs pass as their element. The callee rebuilds the +// struct in a private (addrspace 5) slot. +void arg_i8_wrapper(i8_wrapper_t w) {} + +// CHECK: define {{.*}}void @arg_i8_wrapper(i8 %{{.*}}) + +void arg_i32_wrapper(i32_wrapper_t w) {} + +// CHECK: define {{.*}}void @arg_i32_wrapper(i32 %{{.*}}) + +void arg_f32_wrapper(f32_wrapper_t w) {} + +// CHECK: define {{.*}}void @arg_f32_wrapper(float %{{.*}}) + +void arg_ptr_wrapper(ptr_wrapper_t w) {} + +// CHECK: define {{.*}}void @arg_ptr_wrapper(ptr %{{.*}}) + +// A struct of one aggregate field is passed as that field. +void arg_cdwrap(cdwrap_t w) {} + +// CHECK: define {{.*}}void @arg_cdwrap({ double, double } %{{.*}}) + +void arg_arrwrap(arrwrap_t w) {} + +// CHECK: define {{.*}}void @arg_arrwrap([3 x i32] %[[W:[^)]+]]) +// CHECK: %[[W_V:.*]] = getelementptr inbounds nuw %struct.arrwrap_t, ptr addrspace(5) %{{.*}}, i32 0, i32 0 +// CHECK-NEXT: store [3 x i32] %[[W]], ptr addrspace(5) %[[W_V]], align 4 + +void arg_nestwrap(nestwrap_t w) {} + +// CHECK: define {{.*}}void @arg_nestwrap(%struct.anon{{.*}} %{{.*}}) + +// Aggregates up to 32 bits are packed into one integer register. +void arg_char2(char2_t s) {} + +// CHECK: define {{.*}}void @arg_char2(i16 %{{.*}}) + +void arg_small(small_t s) {} + +// CHECK: define {{.*}}void @arg_small(i32 %{{.*}}) + +void arg_union(int_float_t u) {} + +// CHECK: define {{.*}}void @arg_union(i32 %{{.*}}) + +// Bit-fields are packed like any other small aggregate. +void arg_bits(bits_t b) {} + +// CHECK: define {{.*}}void @arg_bits(i32 %[[B:[^)]+]]) +// CHECK: store i32 %[[B]], ptr addrspace(5) %{{.*}}, align 4 + +// Aggregates of 33 to 64 bits are packed into a pair of i32 registers. +void arg_pair(pair_t p) {} + +// CHECK: define {{.*}}void @arg_pair([2 x i32] %[[P:[^)]+]]) +// CHECK: store [2 x i32] %[[P]], ptr addrspace(5) %{{.*}}, align 4 + +// A _Complex up to 64 bits is packed like a small aggregate. +void arg_cfloat(_Complex float c) {} + +// CHECK: define {{.*}}void @arg_cfloat([2 x i32] noundef %[[C:[^)]+]]) +// CHECK: store [2 x i32] %[[C]], ptr addrspace(5) %{{.*}}, align 4 + +// The call site is coerced the same way as the callee. +void call_small(small_t s) { arg_small(s); } + +// CHECK: define {{.*}}void @call_small(i32 %{{.*}}) +// CHECK: call void @arg_small(i32 %{{.*}}) + +void call_pair(pair_t p) { arg_pair(p); } + +// CHECK: define {{.*}}void @call_pair( +// CHECK: %[[ARG:.*]] = load [2 x i32], ptr %{{.*}}, align 4 +// CHECK: call void @arg_pair([2 x i32] %[[ARG]]) + +// A transparent union is passed as its first member. +void arg_transparent(transparent_t u) {} + +// CHECK: define {{.*}}void @arg_transparent(ptr %[[U:[^)]+]]) +// CHECK: store ptr %[[U]], ptr addrspace(5) %{{.*}}, align 8 + +// A caller can pass any member type directly. +void call_transparent(int *p) { arg_transparent(p); } + +// CHECK: define {{.*}}void @call_transparent(ptr noundef %{{.*}}) +// CHECK: call void @arg_transparent(ptr %{{.*}}) + +// Larger aggregates that fit the register budget pass one field per register. +void arg_triple(triple_t t) {} + +// CHECK: define {{.*}}void @arg_triple(i32 %[[T0:[^,]+]], i32 %[[T1:[^,]+]], i32 %[[T2:[^)]+]]) +// CHECK: store i32 %[[T0]], ptr addrspace(5) %{{.*}}, align 4 +// CHECK: store i32 %[[T1]], ptr addrspace(5) %{{.*}}, align 4 +// CHECK: store i32 %[[T2]], ptr addrspace(5) %{{.*}}, align 4 + +void call_triple(triple_t t) { arg_triple(t); } + +// CHECK: define {{.*}}void @call_triple( +// CHECK: call void @arg_triple(i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}}) + +// A call through a function pointer is coerced like a direct call. +void call_fnptr(void (*fp)(triple_t), triple_t t) { fp(t); } + +// CHECK: define {{.*}}void @call_fnptr(ptr noundef %{{.*}}, i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}}) +// CHECK: %[[FN:.*]] = load ptr, ptr %{{.*}}, align 8 +// CHECK: call void %[[FN]](i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}}) + +// A _Complex wider than 64 bits is split into its two parts. +void arg_cdouble(_Complex double c) {} + +// CHECK: define {{.*}}void @arg_cdouble(double noundef %[[RE:[^,]+]], double noundef %[[IM:[^)]+]]) +// CHECK: %[[C_RE:.*]] = getelementptr inbounds nuw { double, double }, ptr addrspace(5) %[[C:.*]], i32 0, i32 0 +// CHECK-NEXT: store double %[[RE]], ptr addrspace(5) %[[C_RE]], align 8 +// CHECK-NEXT: %[[C_IM:.*]] = getelementptr inbounds nuw { double, double }, ptr addrspace(5) %[[C]], i32 0, i32 1 +// CHECK-NEXT: store double %[[IM]], ptr addrspace(5) %[[C_IM]], align 8 + +void arg_clong(_Complex long c) {} + +// CHECK: define {{.*}}void @arg_clong(i64 noundef %[[RE:[^,]+]], i64 noundef %[[IM:[^)]+]]) +// CHECK: store i64 %[[RE]], ptr addrspace(5) %{{.*}}, align 8 +// CHECK-NEXT: %{{.*}} = getelementptr inbounds nuw { i64, i64 }, ptr addrspace(5) %{{.*}}, i32 0, i32 1 +// CHECK-NEXT: store i64 %[[IM]], ptr addrspace(5) %{{.*}}, align 8 + +// The caller splits it the same way. +void call_cdouble(_Complex double c) { arg_cdouble(c); } + +// CHECK: define {{.*}}void @call_cdouble(double noundef %{{.*}}, double noundef %{{.*}}) +// CHECK: %[[RE:.*]] = load double, ptr addrspace(5) %{{.*}}, align 8 +// CHECK-NEXT: %{{.*}} = getelementptr inbounds nuw { double, double }, ptr addrspace(5) %{{.*}}, i32 0, i32 1 +// CHECK-NEXT: %[[IM:.*]] = load double, ptr addrspace(5) %{{.*}}, align 8 +// CHECK-NEXT: call void @arg_cdouble(double noundef %[[RE]], double noundef %[[IM]]) + +// A union is passed as its storage member, then its tail padding. +void arg_u_pad(u_pad_t u) {} + +// CHECK: define {{.*}}void @arg_u_pad(double %[[D:[^,]+]], [8 x i8] %[[PAD:[^)]+]]) +// CHECK: store double %[[D]], ptr addrspace(5) %{{.*}}, align 8 +// CHECK-NEXT: %{{.*}} = getelementptr inbounds nuw {{.*}}, ptr addrspace(5) %{{.*}}, i32 0, i32 1 +// CHECK-NEXT: store [8 x i8] %[[PAD]], ptr addrspace(5) %{{.*}} + +void call_u_pad(u_pad_t u) { arg_u_pad(u); } + +// CHECK: define {{.*}}void @call_u_pad(double %{{.*}}, [8 x i8] %{{.*}}) +// CHECK: %[[D:.*]] = load double, ptr %{{.*}}, align 8 +// CHECK-NEXT: %{{.*}} = getelementptr inbounds nuw {{.*}}, ptr %{{.*}}, i32 0, i32 1 +// CHECK-NEXT: %[[PAD:.*]] = load [8 x i8], ptr %{{.*}}, align 8 +// CHECK-NEXT: call void @arg_u_pad(double %[[D]], [8 x i8] %[[PAD]]) + +// With no tail padding a union is passed as its storage member alone. +void arg_u_dl(u_dl_t u) {} + +// CHECK: define {{.*}}void @arg_u_dl([2 x double] %[[U:[^)]+]]) +// CHECK: store [2 x double] %[[U]], ptr addrspace(5) %{{.*}}, align 8 + +// A packed union keeps its padding, and its double is stored at align 1. +void arg_u_packed(u_packed_t u) {} + +// CHECK: define {{.*}}void @arg_u_packed(double %[[D:[^,]+]], [5 x i8] %[[PAD:[^)]+]]) +// CHECK: store double %[[D]], ptr addrspace(5) %{{.*}}, align 1 +// CHECK-NEXT: %{{.*}} = getelementptr inbounds nuw {{.*}}, ptr addrspace(5) %{{.*}}, i32 0, i32 1 +// CHECK-NEXT: store [5 x i8] %[[PAD]], ptr addrspace(5) %{{.*}}, align 1 + +// An aggregate of exactly 16 registers is passed direct. +void arg_big16(big16_t b) {} + +// CHECK: define {{.*}}void @arg_big16([16 x i32] %[[B:[^)]+]]) +// CHECK: %[[B_DATA:.*]] = getelementptr inbounds nuw %struct.big16_t, ptr addrspace(5) %{{.*}}, i32 0, i32 0 +// CHECK-NEXT: store [16 x i32] %[[B]], ptr addrspace(5) %[[B_DATA]], align 4 + +// An aggregate past the register budget is passed byref in addrspace(5). +void arg_big(big_t b) {} + +// CHECK: define {{.*}}void @arg_big(ptr addrspace(5) noundef byref(%struct.big_t) align 4 %[[B_ARG:.*]]) +// CHECK: call void @llvm.memcpy.{{.*}}(ptr{{.*}} align 4 %{{.*}}, ptr addrspace(5) align 4 %[[B_ARG]], i64 68, i1 false) + +// The caller passes its own local, not a copy of it. +void call_big(void) { + big_t b = {0}; + arg_big(b); +} + +// CHECK: define {{.*}}void @call_big() +// CHECK: call void @arg_big(ptr addrspace(5) noundef byref(%struct.big_t) align 4 %{{.*}}) + +// Scalars use the same register budget, so a struct that would fit on its +// own is passed byref once they have used it up. +void arg_budget(int a0, int a1, int a2, int a3, int a4, int a5, int a6, + int a7, int a8, int a9, int a10, int a11, int a12, int a13, + triple_t t) {} + +// CHECK: define {{.*}}void @arg_budget(i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, ptr addrspace(5) noundef byref(%struct.triple_t) align 4 %[[T_ARG:.*]]) +// CHECK: call void @llvm.memcpy.{{.*}}(ptr{{.*}} align 4 %{{.*}}, ptr addrspace(5) align 4 %[[T_ARG]], i64 12, i1 false) + +// A struct that takes exactly the registers left is still passed direct. +void arg_budget_exact(int a0, int a1, int a2, int a3, int a4, int a5, int a6, + int a7, int a8, int a9, int a10, int a11, int a12, + triple_t t) {} + +// CHECK: define {{.*}}void @arg_budget_exact(i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 %[[T0:[^,]+]], i32 %[[T1:[^,]+]], i32 %[[T2:[^)]+]]) +// CHECK: store i32 %[[T0]], ptr addrspace(5) %{{.*}}, align 4 +// CHECK-NEXT: %{{.*}} = getelementptr inbounds nuw %struct.triple_t, ptr addrspace(5) %{{.*}}, i32 0, i32 1 +// CHECK-NEXT: store i32 %[[T1]], ptr addrspace(5) %{{.*}}, align 4 +// CHECK-NEXT: %{{.*}} = getelementptr inbounds nuw %struct.triple_t, ptr addrspace(5) %{{.*}}, i32 0, i32 2 +// CHECK-NEXT: store i32 %[[T2]], ptr addrspace(5) %{{.*}}, align 4 + +// An aggregate of up to 64 bits is packed even once the budget is used up. +void arg_budget_pair(int a0, int a1, int a2, int a3, int a4, int a5, int a6, + int a7, int a8, int a9, int a10, int a11, int a12, + int a13, int a14, int a15, pair_t p) {} + +// CHECK: define {{.*}}void @arg_budget_pair(i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, [2 x i32] %[[P:[^)]+]]) +// CHECK: store [2 x i32] %[[P]], ptr addrspace(5) %{{.*}}, align 4 + +// A packed aggregate still uses budget, so the next struct no longer fits. +void arg_budget_pair_triple(int a0, int a1, int a2, int a3, int a4, int a5, + int a6, int a7, int a8, int a9, int a10, int a11, + int a12, int a13, pair_t p, triple_t t) {} + +// CHECK: define {{.*}}void @arg_budget_pair_triple(i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, [2 x i32] %[[P:[^,]+]], ptr addrspace(5) noundef byref(%struct.triple_t) align 4 %[[T_ARG:[^)]+]]) +// CHECK: store [2 x i32] %[[P]], ptr addrspace(5) %{{.*}}, align 4 +// CHECK: call void @llvm.memcpy.{{.*}}(ptr{{.*}} align 4 %{{.*}}, ptr addrspace(5) align 4 %[[T_ARG]], i64 12, i1 false) + +// Past the register budget a _Complex is passed byref in addrspace(5). +void arg_cdouble_budget(int a0, int a1, int a2, int a3, int a4, int a5, int a6, + int a7, int a8, int a9, int a10, int a11, int a12, + int a13, _Complex double c) {} + +// CHECK: define {{.*}}void @arg_cdouble_budget(i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, i32 noundef %{{.*}}, ptr addrspace(5) noundef byref({ double, double }) align 8 %{{.*}}) + +// A struct with a flexible array member is passed byval in addrspace(5). +void arg_fam(fam_t s) {} + +// CHECK: define {{.*}}void @arg_fam(ptr addrspace(5) noundef byval(%struct.fam_t) align 4 %{{.*}}) + +// The caller passes its own local as the byval pointer. +void call_fam(fam_t s) { arg_fam(s); } + +// CHECK: define {{.*}}void @call_fam(ptr addrspace(5) noundef byval(%struct.fam_t) align 4 %{{.*}}) +// CHECK: call void @arg_fam(ptr addrspace(5) noundef byval(%struct.fam_t) align 4 %{{.*}}) + +void take_var(int n, ...); + +// Promoted scalars pass through an ellipsis unchanged. +void call_var_scalars(char c, double d) { take_var(2, c, d); } + +// CHECK: define {{.*}}void @call_var_scalars( +// CHECK: %[[C_INT:.*]] = sext i8 %{{.*}} to i32 +// CHECK-NEXT: %[[D:.*]] = load double, ptr %{{.*}}, align 8 +// CHECK-NEXT: call void (i32, ...) @take_var(i32 noundef 2, i32 noundef %[[C_INT]], double noundef %[[D]]) +// CHECK: declare void @take_var(i32 noundef, ...) + +// Aggregates pass through an ellipsis whole, not packed into registers. +void call_var_aggs(pair_t p, small_t s) { take_var(2, p, s); } + +// CHECK: define {{.*}}void @call_var_aggs([2 x i32] %{{.*}}, i32 %{{.*}}) +// CHECK: %[[P:.*]] = load %struct.pair_t, ptr %{{.*}}, align 4 +// CHECK-NEXT: %[[S:.*]] = load %struct.small_t, ptr %{{.*}}, align 1 +// CHECK-NEXT: call void (i32, ...) @take_var(i32 noundef 2, %struct.pair_t %[[P]], %struct.small_t %[[S]]) + +// Through an ellipsis a _Complex is passed whole. +void call_var_cdouble(_Complex double c) { take_var(1, c); } + +// CHECK: define {{.*}}void @call_var_cdouble(double noundef %{{.*}}, double noundef %{{.*}}) +// CHECK: call void (i32, ...) @take_var(i32 noundef 1, { double, double } noundef %{{.*}}) diff --git a/clang/test/CodeGen/AMDGPU/abi-classify-cxx-records.cpp b/clang/test/CodeGen/AMDGPU/abi-classify-cxx-records.cpp new file mode 100644 index 00000000000000..ec762e95cecc74 --- /dev/null +++ b/clang/test/CodeGen/AMDGPU/abi-classify-cxx-records.cpp @@ -0,0 +1,104 @@ +// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -emit-llvm %s -o - | FileCheck %s +// RUN: %if cir-enabled %{ %clang_cc1 -triple amdgpu-amd-amdhsa -fclangir -emit-llvm %s -o - | FileCheck %s %} + +// Checks how AMDGPU functions pass and return C++ records, where triviality +// and layout change the result. + +struct Empty {}; + +struct NonTrivialDtor { + int i; + ~NonTrivialDtor(); +}; + +struct NonCopyable { + int i; + NonCopyable(); + NonCopyable(const NonCopyable &) = delete; +}; + +struct TrivialBase { int i; }; +struct DerivedSingle : TrivialBase {}; +struct DerivedPair : TrivialBase { int j; }; +struct MemberPtrHolder { int TrivialBase::*p; }; +typedef void (TrivialBase::*mfp_t)(); + +// A record that cannot be passed in registers is built directly in a generic +// sret. +NonTrivialDtor ret_non_trivial_dtor() { return {1}; } + +// CHECK: define {{.*}}void @_Z20ret_non_trivial_dtorv(ptr dead_on_unwind noalias writable sret(%struct.NonTrivialDtor) align 4 %[[RET:.*]]) +// CHECK: %[[I:.*]] = getelementptr inbounds nuw %struct.NonTrivialDtor, ptr %[[RET]], i32 0, i32 0 +// CHECK: store i32 1, ptr %[[I]], align 4 + +// The caller's local is built in place by the callee. +void use_non_trivial_dtor() { NonTrivialDtor x = ret_non_trivial_dtor(); } + +// CHECK: define {{.*}}void @_Z20use_non_trivial_dtorv() +// CHECK: call void @_Z20ret_non_trivial_dtorv(ptr dead_on_unwind writable sret(%struct.NonTrivialDtor) align 4 %{{.*}}) + +NonCopyable ret_non_copyable() { return NonCopyable(); } + +// CHECK: define {{.*}}void @_Z16ret_non_copyablev(ptr dead_on_unwind noalias writable sret(%struct.NonCopyable) align 4 %{{.*}}) + +// A base subobject holding the only field still counts as a single element. +DerivedSingle ret_derived_single() { return {}; } + +// CHECK: define {{.*}}i32 @_Z18ret_derived_singlev() + +void arg_derived_single(DerivedSingle d) {} + +// CHECK: define {{.*}}void @_Z18arg_derived_single13DerivedSingle(i32 %{{.*}}) + +// A base plus a field is packed into a pair of i32 registers. +DerivedPair ret_derived_pair() { return {}; } + +// CHECK: define {{.*}}[2 x i32] @_Z16ret_derived_pairv() +// CHECK: %[[RET:.*]] = load [2 x i32], ptr addrspace(5) %{{.*}}, align 4 +// CHECK: ret [2 x i32] %[[RET]] + +void arg_derived_pair(DerivedPair d) {} + +// CHECK: define {{.*}}void @_Z16arg_derived_pair11DerivedPair([2 x i32] %[[D:[^)]+]]) +// CHECK: store [2 x i32] %[[D]], ptr addrspace(5) %{{.*}}, align 4 + +// A data member pointer is passed as its i64 offset. +MemberPtrHolder ret_member_ptr() { return {nullptr}; } + +// CHECK: define {{.*}}i64 @_Z14ret_member_ptrv() + +void arg_member_ptr(MemberPtrHolder h) {} + +// CHECK: define {{.*}}void @_Z14arg_member_ptr15MemberPtrHolder(i64 %{{.*}}) + +// A member function pointer is a pair of i64 that passes one field per +// register. +void arg_mfp(mfp_t f) {} + +// CHECK: define {{.*}}void @_Z7arg_mfpM11TrivialBaseFvvE(i64 %[[PTR:[^,]+]], i64 %[[ADJ:[^)]+]]) +// CHECK: store i64 %[[PTR]], ptr addrspace(5) %{{.*}}, align 8 +// CHECK: store i64 %[[ADJ]], ptr addrspace(5) %{{.*}}, align 8 + +mfp_t ret_mfp() { return nullptr; } + +// CHECK: define {{.*}}{ i64, i64 } @_Z7ret_mfpv() + +// An empty C++ record is one byte in size but is still dropped. +void arg_empty(Empty e) {} + +// CHECK: define {{.*}}void @_Z9arg_empty5Empty() + +// A non-trivial record argument is passed through a pointer in addrspace(5). +void arg_non_trivial_dtor(NonTrivialDtor n) {} + +// CHECK: define {{.*}}void @_Z20arg_non_trivial_dtor14NonTrivialDtor(ptr addrspace(5) nofreeobj noundef align 4 dereferenceable(4) %{{.*}}) + +// The caller passes its copied temporary, not a further copy. +void call_non_trivial_dtor(NonTrivialDtor &n) { arg_non_trivial_dtor(n); } + +// CHECK: define {{.*}}void @_Z21call_non_trivial_dtorR14NonTrivialDtor( +// CHECK: %[[TMP:.*]] = alloca %struct.NonTrivialDtor, align 4, addrspace(5) +// CHECK: %[[TMP_VIEW:.*]] = addrspacecast ptr addrspace(5) %[[TMP]] to ptr +// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[TMP_VIEW]], ptr align 4 %{{.*}}, i64 4, i1 false) +// CHECK: call void @_Z20arg_non_trivial_dtor14NonTrivialDtor(ptr addrspace(5) nofreeobj noundef align 4 dereferenceable(4) %{{.*}}) +// CHECK: call void @_ZN14NonTrivialDtorD1Ev(ptr {{.*}}%[[TMP_VIEW]]) diff --git a/clang/test/CodeGen/AMDGPU/abi-classify-return-types.c b/clang/test/CodeGen/AMDGPU/abi-classify-return-types.c new file mode 100644 index 00000000000000..1b50028ac35334 --- /dev/null +++ b/clang/test/CodeGen/AMDGPU/abi-classify-return-types.c @@ -0,0 +1,218 @@ +// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -emit-llvm %s -o - | FileCheck %s +// RUN: %if cir-enabled %{ %clang_cc1 -triple amdgpu-amd-amdhsa -fclangir -emit-llvm %s -o - | FileCheck %s %} + +// Checks how non-kernel AMDGPU functions return values. + +typedef struct {} empty_t; +typedef struct { char c; } i8_wrapper_t; +typedef struct { int i; } i32_wrapper_t; +typedef struct { float f; } f32_wrapper_t; +typedef struct { int *p; } ptr_wrapper_t; +typedef struct { char a, b; } char2_t; +typedef struct { char a, b, c; } small_t; +typedef union { int i; float f; } int_float_t; +typedef struct { int a, b; } pair_t; +typedef struct { int a, b, c; } triple_t; +typedef struct { int data[17]; } big_t; +typedef struct { int data[16]; } big16_t; +typedef struct { int n; int data[]; } fam_t; +typedef struct { _Complex double c; } cdwrap_t; +typedef union { int a[3]; double d; } u_pad_t; + +void ret_void(void) {} + +// CHECK: define {{.*}}void @ret_void() + +// Sub-word integers and bool carry signext or zeroext per their signedness. +_Bool ret_bool(void) { return 0; } + +// CHECK: define {{.*}}zeroext i1 @ret_bool() + +char ret_char(void) { return 0; } + +// CHECK: define {{.*}}signext i8 @ret_char() + +unsigned char ret_uchar(void) { return 0; } + +// CHECK: define {{.*}}zeroext i8 @ret_uchar() + +short ret_short(void) { return 0; } + +// CHECK: define {{.*}}signext i16 @ret_short() + +// Word-sized and wider scalars and pointers return unchanged. +int ret_int(void) { return 0; } + +// CHECK: define {{.*}}i32 @ret_int() + +long ret_long(void) { return 0; } + +// CHECK: define {{.*}}i64 @ret_long() + +float ret_float(void) { return 0; } + +// CHECK: define {{.*}}float @ret_float() + +double ret_double(void) { return 0; } + +// CHECK: define {{.*}}double @ret_double() + +_Float16 ret_half(void) { return 0; } + +// CHECK: define {{.*}}half @ret_half() + +int *ret_ptr(void) { return 0; } + +// CHECK: define {{.*}}ptr @ret_ptr() + +_BitInt(65) ret_bitint65(void) { return 0; } + +// CHECK: define {{.*}}i65 @ret_bitint65() + +// An empty struct return becomes void. +empty_t ret_empty(void) { + empty_t e; + return e; +} + +// CHECK: define {{.*}}void @ret_empty() + +// Single-element structs return as their element. +i8_wrapper_t ret_i8_wrapper(void) { + i8_wrapper_t w = {1}; + return w; +} + +// CHECK: define {{.*}}i8 @ret_i8_wrapper() + +i32_wrapper_t ret_i32_wrapper(void) { + i32_wrapper_t w = {1}; + return w; +} + +// CHECK: define {{.*}}i32 @ret_i32_wrapper() + +f32_wrapper_t ret_f32_wrapper(void) { + f32_wrapper_t w = {1.0f}; + return w; +} + +// CHECK: define {{.*}}float @ret_f32_wrapper() + +ptr_wrapper_t ret_ptr_wrapper(void) { + ptr_wrapper_t w = {0}; + return w; +} + +// CHECK: define {{.*}}ptr @ret_ptr_wrapper() + +// A one-field struct return is not unwrapped. +cdwrap_t ret_cdwrap(void) { + cdwrap_t w = {0}; + return w; +} + +// CHECK: define {{.*}}%struct.cdwrap_t @ret_cdwrap() +// CHECK: %[[RET:.*]] = load %struct.cdwrap_t, ptr addrspace(5) %{{.*}}, align 8 +// CHECK-NEXT: ret %struct.cdwrap_t %[[RET]] + +// Aggregates up to 32 bits are packed into one integer register. +char2_t ret_char2(void) { + char2_t s = {1, 2}; + return s; +} + +// CHECK: define {{.*}}i16 @ret_char2() + +small_t ret_small(void) { + small_t s = {1, 2, 3}; + return s; +} + +// CHECK: define {{.*}}i32 @ret_small() + +int_float_t ret_union(void) { + int_float_t u = {1}; + return u; +} + +// CHECK: define {{.*}}i32 @ret_union() + +// Aggregates of 33 to 64 bits are packed into a pair of i32 registers. +pair_t ret_pair(void) { + pair_t p = {1, 2}; + return p; +} + +// CHECK: define {{.*}}[2 x i32] @ret_pair() +// CHECK: %[[RET:.*]] = load [2 x i32], ptr addrspace(5) %{{.*}}, align 4 +// CHECK: ret [2 x i32] %[[RET]] + +// The call site unpacks the result the same way. +void call_ret_pair(void) { pair_t p = ret_pair(); } + +// CHECK: define {{.*}}void @call_ret_pair() +// CHECK: %[[RES:.*]] = call [2 x i32] @ret_pair() +// CHECK: store [2 x i32] %[[RES]], ptr addrspace(5) %{{.*}}, align 4 + +// A _Complex up to 64 bits is packed like a small aggregate. +_Complex float ret_cfloat(void) { return 0; } + +// CHECK: define {{.*}}[2 x i32] @ret_cfloat() +// CHECK: %[[RET:.*]] = load [2 x i32], ptr addrspace(5) %{{.*}}, align 4 +// CHECK-NEXT: ret [2 x i32] %[[RET]] + +// Larger aggregates that fit the register budget return whole. +triple_t ret_triple(void) { + triple_t t = {1, 2, 3}; + return t; +} + +// CHECK: define {{.*}}%struct.triple_t @ret_triple() +// CHECK: %[[RET:.*]] = load %struct.triple_t, ptr addrspace(5) %{{.*}}, align 4 +// CHECK: ret %struct.triple_t %[[RET]] + +// A wider _Complex that fits the register budget returns whole. +_Complex double ret_cdouble(void) { return 0; } + +// CHECK: define {{.*}}{ double, double } @ret_cdouble() +// CHECK: ret { double, double } %{{.*}} + +// A union return is not flattened. +u_pad_t ret_u_pad(u_pad_t *p) { return *p; } + +// CHECK: define {{.*}}%union.u_pad_t @ret_u_pad(ptr noundef %{{.*}}) +// CHECK: %[[RET:.*]] = load %union.u_pad_t, ptr addrspace(5) %{{.*}}, align 8 +// CHECK-NEXT: ret %union.u_pad_t %[[RET]] + +// An aggregate of exactly 16 registers is returned direct. +big16_t ret_big16(big16_t *p) { return *p; } + +// CHECK: define {{.*}}%struct.big16_t @ret_big16(ptr noundef %{{.*}}) +// CHECK: %[[RET:.*]] = load %struct.big16_t, ptr addrspace(5) %{{.*}}, align 4 +// CHECK-NEXT: ret %struct.big16_t %[[RET]] + +// An aggregate past the register budget returns through sret in addrspace(5). +big_t ret_big(void) { + big_t b = {0}; + return b; +} + +// CHECK: define {{.*}}void @ret_big(ptr addrspace(5) dead_on_unwind noalias writable sret(%struct.big_t) align 4 %[[RET:[^)]+]]) +// CHECK: %{{.*}} = addrspacecast ptr addrspace(5) %[[RET]] to ptr + +// The caller's local is passed as the sret. +void call_ret_big(void) { big_t b = ret_big(); } + +// CHECK: define {{.*}}void @call_ret_big() +// CHECK: alloca %struct.big_t, align 4, addrspace(5) +// CHECK: call void @ret_big(ptr addrspace(5) dead_on_unwind writable sret(%struct.big_t) align 4 %{{.*}}) + +// A struct with a flexible array member returns through sret in addrspace(5). +fam_t ret_fam(void) { + fam_t s = {0}; + return s; +} + +// CHECK: define {{.*}}void @ret_fam(ptr addrspace(5) dead_on_unwind noalias writable sret(%struct.fam_t) align 4 %[[RET:[^)]+]]) +// CHECK: %{{.*}} = addrspacecast ptr addrspace(5) %[[RET]] to ptr diff --git a/clang/test/CodeGenHIP/amdgpu-kernel-args-abi.hip b/clang/test/CodeGenHIP/amdgpu-kernel-args-abi.hip new file mode 100644 index 00000000000000..19da6224203d93 --- /dev/null +++ b/clang/test/CodeGenHIP/amdgpu-kernel-args-abi.hip @@ -0,0 +1,137 @@ +// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -x hip -fcuda-is-device -emit-llvm %s -o - | FileCheck %s +// RUN: %if cir-enabled %{ %clang_cc1 -triple amdgpu-amd-amdhsa -x hip -fcuda-is-device -fclangir -emit-llvm %s -o - | FileCheck %s %} + +// Checks how HIP kernels take arguments through the kernarg segment. + +#define __global__ __attribute__((global)) +#define __device__ __attribute__((device)) + +typedef struct { int i; } i32_wrapper_t; +typedef struct { i32_wrapper_t w; } nested_t; +typedef struct { float f[1]; } f32_array1_t; +typedef struct { float *x; } ptr_wrapper_t; +typedef struct { int a; int b; } pair_t; +typedef struct {} empty_t; +typedef struct { float *x; int n; } ptr_pair_t; + +// Unlike ptr_wrapper_t, the pointer field is not coerced to addrspace(1). +// CHECK: %struct.ptr_pair_t = type { ptr, i32 } + +typedef float float3 __attribute__((ext_vector_type(3))); +typedef float float4 __attribute__((ext_vector_type(4))); +typedef short short4 __attribute__((ext_vector_type(4))); + +// Word-sized scalars pass through unchanged. +__global__ void kern_scalar(int i, float f) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z11kern_scalarif(i32 noundef %{{.*}}, float noundef %{{.*}}) + +__global__ void kern_wide(long l, double d) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z9kern_wideld(i64 noundef %{{.*}}, double noundef %{{.*}}) + +__global__ void kern_half(_Float16 h) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z9kern_halfDF16_(half noundef %{{.*}}) + +__global__ void kern_bitint(_BitInt(65) b) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z11kern_bitintDB65_(i65 noundef %{{.*}}) + +// Kernel arguments are read from the kernarg segment, so sub-word integers +// and bool are not extended, unlike in a device function. +__global__ void kern_char(char c) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z9kern_charc(i8 noundef %{{.*}}) + +__global__ void kern_uchar(unsigned char c) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z10kern_ucharh(i8 noundef %{{.*}}) + +__global__ void kern_short(short s) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z10kern_shorts(i16 noundef %{{.*}}) + +__global__ void kern_bool(bool b) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z9kern_boolb(i1 noundef %{{.*}}) + +// The same argument to a device function is extended. +__device__ void dev_char(char c) {} + +// CHECK: define {{.*}}void @_Z8dev_charc(i8 noundef signext %{{.*}}) + +// Vectors, including 16-bit and 3-element ones, pass whole. +__global__ void kern_float4(float4 v) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z11kern_float4Dv4_f(<4 x float> noundef %{{.*}}) + +__global__ void kern_short4(short4 v) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z11kern_short4Dv4_s(<4 x i16> noundef %{{.*}}) + +__global__ void kern_float3(float3 v) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z11kern_float3Dv3_f(<3 x float> noundef %{{.*}}) + +// A pointer already in a non-generic address space keeps it. +__global__ void kern_global_ptr(__attribute__((address_space(1))) int *p) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z15kern_global_ptrPU3AS1i(ptr addrspace(1) noundef %{{.*}}) + +// HIP passes a generic pointer or reference as a global pointer and casts it +// back to generic in the kernel. +__global__ void kern_ptr(int *p) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z8kern_ptrPi(ptr addrspace(1) noundef %{{.*}}) + +__global__ void kern_ref(int &r) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z8kern_refRi(ptr addrspace(1) noundef nonnull align 4 dereferenceable(4) %{{.*}}) + +// A struct holding only a pointer is unwrapped first, so it is coerced too. +__global__ void kern_ptr_wrap(ptr_wrapper_t w) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z13kern_ptr_wrap13ptr_wrapper_t(ptr addrspace(1) %{{.*}}) + +// A device function keeps the generic pointer. +__device__ void dev_ptr(int *p) {} + +// CHECK: define {{.*}}void @_Z7dev_ptrPi(ptr noundef %{{.*}}) + +// A single-element struct kernel argument is passed as its element. +__global__ void kern_wrapper(i32_wrapper_t w) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z12kern_wrapper13i32_wrapper_t(i32 %{{.*}}) + +// The element is found through nested structs and one-element arrays. +__global__ void kern_nested(nested_t n) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z11kern_nested8nested_t(i32 %{{.*}}) + +__global__ void kern_array1(f32_array1_t a) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z11kern_array112f32_array1_t(float %{{.*}}) + +// A multi-field struct is read in place from the kernarg segment, addrspace(4). +__global__ void kern_pair(pair_t p) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z9kern_pair6pair_t(ptr addrspace(4) noundef byref(%struct.pair_t) align 4 %[[PAIR:.*]]) +// CHECK: call void @llvm.memcpy.{{.*}}(ptr{{.*}} align 4 %{{.*}}, ptr addrspace(4) align 4 %[[PAIR]], i64 8, i1 false) + +// Kernels do not drop an empty struct. It is read from the kernarg segment. +__global__ void kern_empty(empty_t e) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z10kern_empty7empty_t(ptr addrspace(4) noundef byref(%struct.empty_t) align 1 %[[E:.*]]) +// CHECK: call void @llvm.memcpy.{{.*}}(ptr{{.*}} align 1 %{{.*}}, ptr addrspace(4) align 1 %[[E]], i64 1, i1 false) + +// A _Complex is an aggregate, so it is read in place too. +__global__ void kern_cfloat(_Complex float c) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z11kern_cfloatCf(ptr addrspace(4) noundef byref({ float, float }) align 4 %{{.*}}) + +// A pointer inside a multi-field struct stays generic. +__global__ void kern_ptr_pair(ptr_pair_t p) {} + +// CHECK: define {{.*}}amdgpu_kernel void @_Z13kern_ptr_pair10ptr_pair_t(ptr addrspace(4) noundef byref(%struct.ptr_pair_t) align 8 %[[P:.*]]) +// CHECK: call void @llvm.memcpy.{{.*}}(ptr{{.*}} align 8 %{{.*}}, ptr addrspace(4) align 8 %[[P]], i64 16, i1 false) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
