llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangir

Author: Qi Ye (Qi-Ye-079)

<details>
<summary>Changes</summary>

This PR adds support of spirv* triples to clang CIR pipeline:

- Map `spirv`, `spirv32` and `spirv64` triples (excluding AMD-vendor SPIR-V and 
HLSL) to the SPIR-V ABI target in the clang pipeline, so 
`cir-call-conv-lowering` pass runs by default for SPIR-V device code.
- Add clang tests that check SPIR-V argument types, return types, C++ records, 
SYCL and CUDA kernel arguments, and the Intel vendor triple against classic 
codegen, plus a test of which SPIR-V triples run the pass. Add ClangIR RUN 
lines to the existing SPIR-V kernel ABI tests.

Assisted by: Claude Opus 5.5

---

Patch is 35.90 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/244409.diff


16 Files Affected:

- (modified) clang/docs/CIR/ABILowering.md (+2-3) 
- (modified) clang/lib/CIR/Lowering/CIRPasses.cpp (+12-5) 
- (added) clang/test/CIR/CodeGen/call-conv-lowering-spirv-target.c (+22) 
- (modified) 
clang/test/CIR/CodeGen/varargs-with-nonzero-default-address-space.c (+5-2) 
- (added) clang/test/CIR/CodeGenHLSL/call-conv-lowering-spirv.hlsl (+8) 
- (modified) clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp (+3-1) 
- (modified) clang/test/CIR/CodeGenSYCL/sycl-external.cpp (+3-5) 
- (modified) clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu (+3) 
- (added) clang/test/CodeGenCUDASPIRV/kernel-args-abi.cu (+43) 
- (modified) clang/test/CodeGenCUDASPIRV/kernel-argument.cu (+3) 
- (added) clang/test/CodeGenSPIRV/abi-classify-arg-types.c (+114) 
- (added) clang/test/CodeGenSPIRV/abi-classify-cxx-records.cpp (+81) 
- (added) clang/test/CodeGenSPIRV/abi-classify-intel.cpp (+52) 
- (added) clang/test/CodeGenSPIRV/abi-classify-return-types.c (+83) 
- (modified) clang/test/CodeGenSPIRV/kernel-ptr-arg.c (+2) 
- (added) clang/test/CodeGenSYCL/spirv-kernel-args-abi.cpp (+79) 


``````````diff
diff --git a/clang/docs/CIR/ABILowering.md b/clang/docs/CIR/ABILowering.md
index 8d9a525e98e2e2..662caa83030e96 100644
--- a/clang/docs/CIR/ABILowering.md
+++ b/clang/docs/CIR/ABILowering.md
@@ -543,9 +543,8 @@ indirect call, and each `cir.va_arg`.
 ### Enabling the Pass
 
 `cir-call-conv-lowering` runs by default whenever ClangIR code generation is
-enabled on an x86_64 target. On every other triple the pipeline omits the
-pass, because x86_64 System V is the only classifier implemented so far, and
-signatures reach the LLVM dialect in their high-level form.
+enabled on a target that has a classifier. On other triples the pipeline omits
+the pass, and signatures reach the LLVM dialect in their high-level form.
 
 `-fno-clangir-call-conv-lowering` turns the pass off and
 `-fclangir-call-conv-lowering` turns it back on. The last one on the
diff --git a/clang/lib/CIR/Lowering/CIRPasses.cpp 
b/clang/lib/CIR/Lowering/CIRPasses.cpp
index 02d6a144d6a96f..54b80b9dcb03e0 100644
--- a/clang/lib/CIR/Lowering/CIRPasses.cpp
+++ b/clang/lib/CIR/Lowering/CIRPasses.cpp
@@ -23,7 +23,9 @@ namespace cir {
 
 /// Map a target triple to the ABI target that drives CallConvLowering.
 /// Returns None for targets whose calling convention is not yet implemented.
-static CallConvTarget getCallConvTarget(const llvm::Triple &triple) {
+static CallConvTarget
+getCallConvTarget(const llvm::Triple &triple,
+                  cir::LoweringOptionsAttr loweringLangOpts) {
   // Windows is not supported.  UEFI shares its convention.
   if (triple.getArch() == llvm::Triple::x86_64 && !triple.isOSWindowsOrUEFI())
     return CallConvTarget::X86_64;
@@ -32,6 +34,11 @@ static CallConvTarget getCallConvTarget(const llvm::Triple 
&triple) {
   if (triple.isAArch64() && !triple.isOSWindows() &&
       triple.getArch() != llvm::Triple::aarch64_32)
     return CallConvTarget::AArch64;
+  bool isHLSL = loweringLangOpts && loweringLangOpts.getHlsl();
+  // AMDGCN-flavored SPIR-V follows the AMDGPU ABI instead. HLSL's integer
+  // promotion rules and resource types are not modeled yet.
+  if (triple.isSPIRV() && triple.getVendor() != llvm::Triple::AMD && !isHLSL)
+    return CallConvTarget::SPIRV;
   return CallConvTarget::None;
 }
 
@@ -136,7 +143,9 @@ runCIRToCIRPasses(mlir::ModuleOp theModule, 
mlir::MLIRContext &mlirContext,
     // 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.
-    CallConvTarget target = getCallConvTarget(*triple);
+    auto loweringLangOpts = theModule->getAttrOfType<cir::LoweringOptionsAttr>(
+        cir::CIRDialect::getLoweringOptionsAttrName());
+    CallConvTarget target = getCallConvTarget(*triple, loweringLangOpts);
     if (target != CallConvTarget::None) {
       // Source the ABI-compatibility version from the module's serialized
       // #cir.lowering_options so a reloaded .cir classifies the same way
@@ -144,9 +153,7 @@ runCIRToCIRPasses(mlir::ModuleOp theModule, 
mlir::MLIRContext &mlirContext,
       // attribute at module construction; if it is absent fall back to the
       // LangOptions default, matching how LowerModule reads the same 
attribute.
       auto compat = clang::LangOptions::ClangABI::Latest;
-      if (auto loweringLangOpts =
-              theModule->getAttrOfType<cir::LoweringOptionsAttr>(
-                  cir::CIRDialect::getLoweringOptionsAttrName()))
+      if (loweringLangOpts)
         compat = static_cast<clang::LangOptions::ClangABI>(
             loweringLangOpts.getClangAbiCompat());
       pm.addPass(mlir::createCallConvLoweringPass(
diff --git a/clang/test/CIR/CodeGen/call-conv-lowering-spirv-target.c 
b/clang/test/CIR/CodeGen/call-conv-lowering-spirv-target.c
new file mode 100644
index 00000000000000..bf263f01570283
--- /dev/null
+++ b/clang/test/CIR/CodeGen/call-conv-lowering-spirv-target.c
@@ -0,0 +1,22 @@
+// Checks which SPIR-V triples run CallConvLowering in the Clang pipeline. The
+// SPIR-V ABI extends a char argument with signext, so it is there only when 
the
+// pass runs.
+
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown -fclangir -emit-llvm %s -o 
- \
+// RUN:   | FileCheck %s --check-prefix=ON
+// RUN: %clang_cc1 -triple spirv32-unknown-unknown -fclangir -emit-llvm %s -o 
- \
+// RUN:   | FileCheck %s --check-prefix=ON
+// RUN: %clang_cc1 -triple spirv64-intel -fclangir -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefix=ON
+// RUN: %clang_cc1 -triple spirv-unknown-vulkan1.3 -fclangir -emit-llvm %s -o 
- \
+// RUN:   | FileCheck %s --check-prefix=ON
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -fclangir -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefix=OFF
+// RUN: %clang_cc1 -triple spir64-unknown-unknown -fclangir -emit-llvm %s -o - 
\
+// RUN:   | FileCheck %s --check-prefix=OFF
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefix=ON
+
+// ON: define {{.*}}void @take_char(i8 noundef signext %{{[^,)]+}})
+// OFF: define {{.*}}void @take_char(i8 noundef %{{[^,)]+}})
+void take_char(char c) {}
diff --git 
a/clang/test/CIR/CodeGen/varargs-with-nonzero-default-address-space.c 
b/clang/test/CIR/CodeGen/varargs-with-nonzero-default-address-space.c
index 3247361347188f..61b524673f88e1 100644
--- a/clang/test/CIR/CodeGen/varargs-with-nonzero-default-address-space.c
+++ b/clang/test/CIR/CodeGen/varargs-with-nonzero-default-address-space.c
@@ -1,10 +1,13 @@
-// RUN: %clang_cc1 -triple spirv64-unknown-unknown -fcuda-is-device -fclangir 
-emit-cir %s -o %t.cir
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown -fcuda-is-device -fclangir 
-fno-clangir-call-conv-lowering -emit-cir %s -o %t.cir
 // RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
-// RUN: %clang_cc1 -triple spirv64-unknown-unknown -fcuda-is-device -fclangir 
-emit-llvm %s -o %t-cir.ll
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown -fcuda-is-device -fclangir 
-fno-clangir-call-conv-lowering -emit-llvm %s -o %t-cir.ll
 // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefixes=LLVM,LLVMCIR
 // RUN: %clang_cc1 -triple spirv64-unknown-unknown -fcuda-is-device -emit-llvm 
%s -o %t.ll
 // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
+// RUN: not %clang_cc1 -triple spirv64-unknown-unknown -fcuda-is-device 
-fclangir -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=NYI
 
+// NYI: error: 'cir.va_arg' op not yet implemented in CallConvLowering for 
SPIR-V
+//
 // TODO(cir): Add aggregate va_arg once va_arg ABI lowering supports SPIR-V.
 int testva(int n, ...) {
   __builtin_va_list ap;
diff --git a/clang/test/CIR/CodeGenHLSL/call-conv-lowering-spirv.hlsl 
b/clang/test/CIR/CodeGenHLSL/call-conv-lowering-spirv.hlsl
new file mode 100644
index 00000000000000..a9c08e608c80a3
--- /dev/null
+++ b/clang/test/CIR/CodeGenHLSL/call-conv-lowering-spirv.hlsl
@@ -0,0 +1,8 @@
+// The Clang pipeline doesn't run CallConvLowering for HLSL on SPIR-V, so a 
bool
+// argument isn't extended, matching classic codegen.
+
+// RUN: %clang_cc1 -x hlsl -triple spirv-unknown-vulkan-library 
-finclude-default-header -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
+// RUN: %clang_cc1 -x hlsl -triple spirv-unknown-vulkan-library 
-finclude-default-header -fclangir -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: define {{.*}}void @_Z9take_boolb(i1 noundef %{{[^,)]+}})
+export void take_bool(bool b) {}
diff --git a/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp 
b/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
index cf9a923d466144..0218a91b5ca52b 100644
--- a/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
+++ b/clang/test/CIR/CodeGenSYCL/kernel-caller-entry-point.cpp
@@ -87,11 +87,13 @@ void test() {
 // CIR:         cir.call @_ZNK1KclEv
 // CIR:         cir.return
 
-// LLVM-OGCG-LABEL: define {{.*}}spir_kernel void @_ZTS2KN
+// The kernel object is copied byval.
+// LLVM-OGCG-LABEL: define {{.*}}spir_kernel void @_ZTS2KN(ptr noundef 
byval(%struct.K) align 1 %{{[^,)]+}})
 // LLVM:              call {{.*}}void @_ZNK1KclEv
 // OGCG:              call {{.*}}spir_func void @_ZNK1KclEv
 // LLVM-OGCG:         ret void
 // LLVM-OGCG-NOT:   define {{.*}}@_Z18kernel_single_task
+// LLVM-OGCG-LABEL: define {{.*}}spir_kernel void @_ZTS8MemberKN(ptr noundef 
byval(%struct.K) align 1 %{{[^,)]+}})
 
 // On ELF, the kernel caller entry point definition is dso_local in CIR,
 // CIR-lowered LLVM IR, and classic CodeGen alike.
diff --git a/clang/test/CIR/CodeGenSYCL/sycl-external.cpp 
b/clang/test/CIR/CodeGenSYCL/sycl-external.cpp
index ff0ca3af7d21be..3655f9b80fc4cd 100644
--- a/clang/test/CIR/CodeGenSYCL/sycl-external.cpp
+++ b/clang/test/CIR/CodeGenSYCL/sycl-external.cpp
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -fsycl-is-device -triple spirv64-unknown-unknown -fclangir 
-emit-cir %s -o %t.cir
 // RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
 // RUN: %clang_cc1 -fsycl-is-device -triple spirv64-unknown-unknown -fclangir 
-emit-llvm %s -o %t-cir.ll
-// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefixes=LLVM,LLVM-CIR
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
 // RUN: %clang_cc1 -fsycl-is-device -triple spirv64-unknown-unknown -emit-llvm 
%s -o %t.ll
-// RUN: FileCheck --input-file=%t.ll %s --check-prefixes=LLVM,OGCG
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=LLVM
 
 // Verify that sycl_external functions are emitted in device code, matching
 // classic CodeGen, and that their definitions carry the "sycl-module-id"
@@ -62,9 +62,7 @@ int squareNoAttr(int x) { return x * x; }
 // LLVM: define spir_func noundef i32 @_Z8withAttrv() #[[EXT]]
 // LLVM: define spir_func noundef i32 @_Z4ret1v() #[[NOEXT:[0-9]+]]
 // LLVM: define spir_func void @_Z5tFuncIiEvT_(i32 noundef %{{.*}}) #[[EXT]]
-// ClangIR does not yet pass kernel arguments byval.
-// LLVM-CIR: define spir_kernel void @_ZTS2KN({{.*}}) #[[EXT]]
-// OGCG: define spir_kernel void @_ZTS2KN(ptr noundef byval({{.*}}) #[[EXT]]
+// LLVM: define spir_kernel void @_ZTS2KN(ptr noundef byval({{.*}}) #[[EXT]]
 // LLVM-NOT: @_Z8declOnlyv
 // LLVM-NOT: @_Z12squareNoAttri
 // LLVM-DAG: attributes #[[EXT]] = { 
{{.*}}"sycl-module-id"="{{.*}}sycl-external.cpp" }
diff --git a/clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu 
b/clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
index a011298c1a1705..cf1361afad14a7 100644
--- a/clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
+++ b/clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
@@ -16,6 +16,9 @@
 // RUN: llvm-dis %t.bc -o %t.ll
 // RUN: FileCheck %s --input-file=%t.ll
 
+// RUN: %if cir-enabled %{ %clang -emit-llvm -S --cuda-device-only 
--offload=spirv32 -fclangir -nocudalib -nocudainc %s -o - | FileCheck %s %}
+// RUN: %if cir-enabled %{ %clang -emit-llvm -S --cuda-device-only 
--offload=spirv64 -fclangir -nocudalib -nocudainc %s -o - | FileCheck %s %}
+
 class GpuData {
  public:
   __attribute__((host)) __attribute__((device)) GpuData(int* src) {}
diff --git a/clang/test/CodeGenCUDASPIRV/kernel-args-abi.cu 
b/clang/test/CodeGenCUDASPIRV/kernel-args-abi.cu
new file mode 100644
index 00000000000000..847848bc5db87b
--- /dev/null
+++ b/clang/test/CodeGenCUDASPIRV/kernel-args-abi.cu
@@ -0,0 +1,43 @@
+// Checks how CUDA kernels on SPIR-V pass their arguments. The default address
+// space is Generic.
+
+// RUN: %clang_cc1 -fcuda-is-device -triple spirv64 -x cuda -emit-llvm %s -o - 
| FileCheck %s
+// RUN: %if cir-enabled %{ %clang_cc1 -fcuda-is-device -triple spirv64 -x cuda 
-fclangir -emit-llvm %s -o - | FileCheck %s %}
+
+#define __device__ __attribute__((device))
+#define __global__ __attribute__((global))
+
+struct Small { int a, b; };
+struct NonCopyable {
+  int i;
+  __device__ NonCopyable(const NonCopyable &);
+};
+
+// Device function pointers keep the Generic address space.
+// CHECK: define spir_func void @_Z7dev_ptrPi(ptr addrspace(4) noundef 
%{{[^,)]+}})
+__device__ void dev_ptr(int *p) {}
+
+// Generic kernel pointers are passed as CrossWorkgroup ones; the body still
+// sees a Generic pointer.
+// CHECK-LABEL: define spir_kernel void @_Z5k_ptrPi(ptr addrspace(1) noundef 
%{{[^,)]+}})
+// CHECK:   call spir_func void @_Z7dev_ptrPi(ptr addrspace(4) noundef 
%{{[^,)]+}})
+__global__ void k_ptr(int *p) { dev_ptr(p); }
+
+// Pointers in any other address space are left alone.
+// CHECK: define spir_kernel void @_Z12k_global_ptrPU3AS1i(ptr addrspace(1) 
noundef %{{[^,)]+}})
+__global__ void k_global_ptr(__attribute__((address_space(1))) int *p) {}
+
+// CHECK: define spir_kernel void @_Z13k_private_ptrPU3AS0i(ptr noundef 
%{{[^,)]+}})
+__global__ void k_private_ptr(__attribute__((address_space(0))) int *p) {}
+
+// Device compilations copy kernel records byval, even one that cannot be
+// copied bitwise.
+// CHECK: define spir_kernel void @_Z7k_small5Small(ptr noundef 
byval(%struct.Small) align 4 %{{[^,)]+}})
+__global__ void k_small(Small s) {}
+
+// CHECK: define spir_kernel void @_Z14k_non_copyable11NonCopyable(ptr noundef 
byval(%struct.NonCopyable) align 4 %{{[^,)]+}})
+__global__ void k_non_copyable(NonCopyable n) {}
+
+// Sub-word kernel arguments are extended.
+// CHECK: define spir_kernel void @_Z5k_extcb(i8 noundef signext %{{[^,)]+}}, 
i1 noundef zeroext %{{[^,)]+}})
+__global__ void k_ext(char c, bool b) {}
diff --git a/clang/test/CodeGenCUDASPIRV/kernel-argument.cu 
b/clang/test/CodeGenCUDASPIRV/kernel-argument.cu
index 37ee76ad1b1456..49d30a0b975327 100644
--- a/clang/test/CodeGenCUDASPIRV/kernel-argument.cu
+++ b/clang/test/CodeGenCUDASPIRV/kernel-argument.cu
@@ -16,6 +16,9 @@
 // RUN: llvm-dis %t.bc -o %t.ll
 // RUN: FileCheck %s --input-file=%t.ll
 
+// RUN: %if cir-enabled %{ %clang -emit-llvm -S --cuda-device-only 
--offload=spirv32 -fclangir -nocudalib -nocudainc %s -o - | FileCheck %s %}
+// RUN: %if cir-enabled %{ %clang -emit-llvm -S --cuda-device-only 
--offload=spirv64 -fclangir -nocudalib -nocudainc %s -o - | FileCheck %s %}
+
 // CHECK: define
 // CHECK-SAME: spir_kernel void @_Z6kernelPi(ptr addrspace(1) noundef
 
diff --git a/clang/test/CodeGenSPIRV/abi-classify-arg-types.c 
b/clang/test/CodeGenSPIRV/abi-classify-arg-types.c
new file mode 100644
index 00000000000000..c27257ad3fb9f0
--- /dev/null
+++ b/clang/test/CodeGenSPIRV/abi-classify-arg-types.c
@@ -0,0 +1,114 @@
+// Checks how non-kernel SPIR-V functions pass arguments.
+
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %if cir-enabled %{ %clang_cc1 -triple spirv64-unknown-unknown 
-fclangir -emit-llvm %s -o - | FileCheck %s %}
+
+typedef struct {} empty_t;
+typedef struct { int i; } i32_wrapper_t;
+typedef struct { char a, b, c; } small_t;
+typedef struct { int data[17]; } big_t;
+typedef union { int i; float f; } int_float_t;
+typedef union {
+  int *ip;
+  float *fp;
+} __attribute__((transparent_union)) transparent_t;
+typedef short short4 __attribute__((ext_vector_type(4)));
+typedef float float3 __attribute__((ext_vector_type(3)));
+
+// Sub-word integers and bool carry signext or zeroext per their signedness.
+// CHECK: define spir_func void @arg_bool(i1 noundef zeroext %{{[^,)]+}})
+void arg_bool(_Bool b) {}
+
+// CHECK: define spir_func void @arg_char(i8 noundef signext %{{[^,)]+}})
+void arg_char(char c) {}
+
+// CHECK: define spir_func void @arg_uchar(i8 noundef zeroext %{{[^,)]+}})
+void arg_uchar(unsigned char c) {}
+
+// CHECK: define spir_func void @arg_short(i16 noundef signext %{{[^,)]+}})
+void arg_short(short s) {}
+
+// CHECK: define spir_func void @arg_ushort(i16 noundef zeroext %{{[^,)]+}})
+void arg_ushort(unsigned short s) {}
+
+// The call site carries the same extension as the callee.
+// CHECK-LABEL: define spir_func void @call_char(i8 noundef signext 
%{{[^,)]+}})
+// CHECK:   call spir_func void @arg_char(i8 noundef signext %{{[^,)]+}})
+void call_char(char c) { arg_char(c); }
+
+// Word-sized and wider scalars, pointers and vectors pass through unchanged.
+// CHECK: define spir_func void @arg_int(i32 noundef %{{[^,)]+}})
+void arg_int(int i) {}
+
+// CHECK: define spir_func void @arg_long(i64 noundef %{{[^,)]+}})
+void arg_long(long l) {}
+
+// CHECK: define spir_func void @arg_half(half noundef %{{[^,)]+}})
+void arg_half(_Float16 h) {}
+
+// CHECK: define spir_func void @arg_float(float noundef %{{[^,)]+}})
+void arg_float(float f) {}
+
+// CHECK: define spir_func void @arg_double(double noundef %{{[^,)]+}})
+void arg_double(double d) {}
+
+// Pointers keep their address space outside kernels.
+// CHECK: define spir_func void @arg_ptr(ptr noundef %{{[^,)]+}})
+void arg_ptr(int *p) {}
+
+// CHECK: define spir_func void @arg_short4(<4 x i16> noundef %{{[^,)]+}})
+void arg_short4(short4 v) {}
+
+// CHECK: define spir_func void @arg_float3(<3 x float> noundef %{{[^,)]+}})
+void arg_float3(float3 v) {}
+
+// SPIR-V has no 128-bit integer, so a _BitInt wider than 64 bits is passed
+// indirectly.
+// CHECK: define spir_func void @arg_bitint64(i64 noundef %{{[^,)]+}})
+void arg_bitint64(_BitInt(64) i) {}
+
+// CHECK: define spir_func void @arg_bitint65(ptr noundef byval(i128) align 8 
%{{[^,)]+}})
+void arg_bitint65(_BitInt(65) i) {}
+
+// Every aggregate is copied byval, including an empty one.
+// CHECK: define spir_func void @arg_empty(ptr noundef byval(%struct.empty_t) 
align 1 %{{[^,)]+}}, i32 noundef %{{[^,)]+}})
+void arg_empty(empty_t e, int i) {}
+
+// CHECK: define spir_func void @arg_i32_wrapper(ptr noundef 
byval(%struct.i32_wrapper_t) align 4 %{{[^,)]+}})
+void arg_i32_wrapper(i32_wrapper_t w) {}
+
+// CHECK: define spir_func void @arg_small(ptr noundef byval(%struct.small_t) 
align 1 %{{[^,)]+}})
+void arg_small(small_t s) {}
+
+// CHECK: define spir_func void @arg_big(ptr noundef byval(%struct.big_t) 
align 4 %{{[^,)]+}})
+void arg_big(big_t b) {}
+
+// CHECK: define spir_func void @arg_union(ptr noundef 
byval(%union.int_float_t) align 4 %{{[^,)]+}})
+void arg_union(int_float_t u) {}
+
+// CHECK: define spir_func void @arg_cfloat(ptr noundef byval({ float, float 
}) align 4 %{{[^,)]+}})
+void arg_cfloat(_Complex float c) {}
+
+// CHECK: define spir_func void @arg_cdouble(ptr noundef byval({ double, 
double }) align 8 %{{[^,)]+}})
+void arg_cdouble(_Complex double c) {}
+
+// A transparent union is passed as its first member.
+// CHECK: define spir_func void @arg_transparent(ptr %{{[^,)]+}})
+void arg_transparent(transparent_t u) {}
+
+// Call sites, direct and indirect, pass the same byval pointer.
+// CHECK-LABEL: define spir_func void @call_small(ptr noundef 
byval(%struct.small_t) align 1 %{{[^,)]+}})
+// CHECK:   call spir_func void @arg_small(ptr noundef byval(%struct.small_t) 
align 1 %{{[^,)]+}})
+void call_small(small_t s) { arg_small(s); }
+
+// CHECK-LABEL: define spir_func void @call_fnptr(ptr noundef %{{[^,)]+}}, ptr 
noundef byval(%struct.small_t) align 1 %{{[^,)]+}})
+// CHECK:   call spir_func void %{{.*}}(ptr noundef byval(%struct.small_t) 
align 1 %{{[^,)]+}})
+void call_fnptr(void (*fp)(small_t), small_t s) { fp(s); }
+
+void variadic(int n, ...);
+
+// Variadic arguments are classified like fixed ones, after default argument
+// promotion.
+// CHECK-LABEL: define spir_func void @call_variadic(ptr noundef 
byval(%struct.small_t) align 1 %{{[^,)]+}}, i8 noundef signext %{{[^,)]+}})
+// CHECK:   call spir_func void (i32, ...) @variadic(i32 noundef 2, ptr 
noundef byval(%struct.small_t) align 1 %{{[^,)]+}}, i32 noundef %{{[^,)]+}})
+void call_variadic(small_t s, char c) { variadic(2, s, c); }
diff --git a/clang/test/CodeGenSPIRV/abi-classify-cxx-records.cpp 
b/clang/test/CodeGenSPIRV/abi-classify-cxx-records.cpp
new file mode 100644
index 00000000000000..d291680a963b4f
--- /dev/null
+++ b/clang/test/CodeGenSPIRV/abi-classify-cxx-records.cpp
@@ -0,0 +1,81 @@
+// Checks how SPIR-V functions pass and return C++ records, where triviality
+// changes the result. Without a device language the default address space is
+// the private one and kernels don't copy non-trivial records byval.
+
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %if cir-enabled %{ %clang_cc1 -triple spirv64-unknown-unknown 
-fclangir -emit-llvm %s -o - | FileCheck %s %}
+
+struct Empty {};
+struct Small { int a, b; };
+struct NonTrivialDtor { int i; ~NonTrivialDtor(); };
+struct NonTrivialCopy { int i; NonTrivialCopy(const NonTrivialCopy &); };
+struct TrivialBase { int i; };
+struct Derived : TrivialBase { int j; };
+typedef int TrivialBase::*mdp_t;
+typedef voi...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/244409
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to