Debian Codegraph @

clang/test/CodeGenCUDA/offload_via_llvm.cu

raw
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2 // RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -foffload-via-llvm -emit-llvm -o - | FileCheck %s --check-prefix=HST
3 // RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device -foffload-via-llvm -emit-llvm -o - | FileCheck %s --check-prefix=DEV
4
5 // Check that we generate LLVM/Offload calls, including the KERNEL_LAUNCH_PARAMS argument.
6
7 #define __OFFLOAD_VIA_LLVM__ 1
8 #include "Inputs/cuda.h"
9
10 // HST-LABEL: define dso_local ptx_kernel void @_Z18__device_stub__fooisPvS_(
11 // HST-SAME: i32 noundef [[TMP0:%.*]], i16 noundef signext [[TMP1:%.*]], ptr noundef [[TMP2:%.*]], ptr noundef [[TMP3:%.*]]) #[[ATTR0:[0-9]+]] {
12 // HST-NEXT: [[ENTRY:.*:]]
13 // HST-NEXT: [[DOTADDR:%.*]] = alloca i32, align 4
14 // HST-NEXT: [[DOTADDR1:%.*]] = alloca i16, align 2
15 // HST-NEXT: [[DOTADDR2:%.*]] = alloca ptr, align 4
16 // HST-NEXT: [[DOTADDR3:%.*]] = alloca ptr, align 4
17 // HST-NEXT: [[KERNEL_ARGS:%.*]] = alloca [[TMP0]], align 16
18 // HST-NEXT: [[KERNEL_LAUNCH_PARAMS:%.*]] = alloca [[TMP1]], align 16
19 // HST-NEXT: [[GRID_DIM:%.*]] = alloca [[STRUCT_DIM3:%.*]], align 8
20 // HST-NEXT: [[BLOCK_DIM:%.*]] = alloca [[STRUCT_DIM3]], align 8
21 // HST-NEXT: [[SHMEM_SIZE:%.*]] = alloca i32, align 4
22 // HST-NEXT: [[STREAM:%.*]] = alloca ptr, align 4
23 // HST-NEXT: store i32 [[TMP0]], ptr [[DOTADDR]], align 4
24 // HST-NEXT: store i16 [[TMP1]], ptr [[DOTADDR1]], align 2
25 // HST-NEXT: store ptr [[TMP2]], ptr [[DOTADDR2]], align 4
26 // HST-NEXT: store ptr [[TMP3]], ptr [[DOTADDR3]], align 4
27 // HST-NEXT: [[TMP4:%.*]] = getelementptr inbounds nuw [[TMP1]], ptr [[KERNEL_LAUNCH_PARAMS]], i32 0, i32 0
28 // HST-NEXT: store i64 16, ptr [[TMP4]], align 16
29 // HST-NEXT: [[TMP5:%.*]] = getelementptr inbounds nuw [[TMP1]], ptr [[KERNEL_LAUNCH_PARAMS]], i32 0, i32 1
30 // HST-NEXT: store ptr [[KERNEL_ARGS]], ptr [[TMP5]], align 8
31 // HST-NEXT: [[TMP6:%.*]] = getelementptr inbounds nuw [[TMP1]], ptr [[KERNEL_LAUNCH_PARAMS]], i32 0, i32 2
32 // HST-NEXT: store ptr null, ptr [[TMP6]], align 4
33 // HST-NEXT: [[TMP7:%.*]] = load i32, ptr [[DOTADDR]], align 4
34 // HST-NEXT: [[TMP8:%.*]] = getelementptr inbounds nuw [[TMP0]], ptr [[KERNEL_ARGS]], i32 0, i32 0
35 // HST-NEXT: store i32 [[TMP7]], ptr [[TMP8]], align 16
36 // HST-NEXT: [[TMP9:%.*]] = load i16, ptr [[DOTADDR1]], align 2
37 // HST-NEXT: [[TMP10:%.*]] = getelementptr inbounds nuw [[TMP0]], ptr [[KERNEL_ARGS]], i32 0, i32 1
38 // HST-NEXT: store i16 [[TMP9]], ptr [[TMP10]], align 4
39 // HST-NEXT: [[TMP11:%.*]] = load ptr, ptr [[DOTADDR2]], align 4
40 // HST-NEXT: [[TMP12:%.*]] = getelementptr inbounds nuw [[TMP0]], ptr [[KERNEL_ARGS]], i32 0, i32 2
41 // HST-NEXT: store ptr [[TMP11]], ptr [[TMP12]], align 8
42 // HST-NEXT: [[TMP13:%.*]] = load ptr, ptr [[DOTADDR3]], align 4
43 // HST-NEXT: [[TMP14:%.*]] = getelementptr inbounds nuw [[TMP0]], ptr [[KERNEL_ARGS]], i32 0, i32 3
44 // HST-NEXT: store ptr [[TMP13]], ptr [[TMP14]], align 4
45 // HST-NEXT: [[TMP15:%.*]] = call i32 @__llvmPopCallConfiguration(ptr [[GRID_DIM]], ptr [[BLOCK_DIM]], ptr [[SHMEM_SIZE]], ptr [[STREAM]])
46 // HST-NEXT: [[TMP16:%.*]] = load i32, ptr [[SHMEM_SIZE]], align 4
47 // HST-NEXT: [[TMP17:%.*]] = load ptr, ptr [[STREAM]], align 4
48 // HST-NEXT: [[CALL:%.*]] = call noundef i32 @llvmLaunchKernel(ptr noundef @_Z18__device_stub__fooisPvS_, ptr noundef byval([[STRUCT_DIM3]]) align 4 [[GRID_DIM]], ptr noundef byval([[STRUCT_DIM3]]) align 4 [[BLOCK_DIM]], ptr noundef [[KERNEL_LAUNCH_PARAMS]], i32 noundef [[TMP16]], ptr noundef [[TMP17]])
49 // HST-NEXT: br label %[[SETUP_END:.*]]
50 // HST: [[SETUP_END]]:
51 // HST-NEXT: ret void
52 //
53 // DEV-LABEL: define dso_local ptx_kernel void @_Z3fooisPvS_(
54 // DEV-SAME: i32 noundef [[TMP0:%.*]], i16 noundef signext [[TMP1:%.*]], ptr noundef [[TMP2:%.*]], ptr noundef [[TMP3:%.*]]) #[[ATTR0:[0-9]+]] {
55 // DEV-NEXT: [[ENTRY:.*:]]
56 // DEV-NEXT: [[DOTADDR:%.*]] = alloca i32, align 4
57 // DEV-NEXT: [[DOTADDR1:%.*]] = alloca i16, align 2
58 // DEV-NEXT: [[DOTADDR2:%.*]] = alloca ptr, align 4
59 // DEV-NEXT: [[DOTADDR3:%.*]] = alloca ptr, align 4
60 // DEV-NEXT: store i32 [[TMP0]], ptr [[DOTADDR]], align 4
61 // DEV-NEXT: store i16 [[TMP1]], ptr [[DOTADDR1]], align 2
62 // DEV-NEXT: store ptr [[TMP2]], ptr [[DOTADDR2]], align 4
63 // DEV-NEXT: store ptr [[TMP3]], ptr [[DOTADDR3]], align 4
64 // DEV-NEXT: ret void
65 //
66 __global__ void foo(int, short, void *, void *) {}
67
68 // HST-LABEL: define dso_local void @_Z5test1Pv(
69 // HST-SAME: ptr noundef [[PTR:%.*]]) #[[ATTR1:[0-9]+]] {
70 // HST-NEXT: [[ENTRY:.*:]]
71 // HST-NEXT: [[PTR_ADDR:%.*]] = alloca ptr, align 4
72 // HST-NEXT: [[AGG_TMP:%.*]] = alloca [[STRUCT_DIM3:%.*]], align 4
73 // HST-NEXT: [[AGG_TMP1:%.*]] = alloca [[STRUCT_DIM3]], align 4
74 // HST-NEXT: store ptr [[PTR]], ptr [[PTR_ADDR]], align 4
75 // HST-NEXT: call void @_ZN4dim3C1Ejjj(ptr noundef nonnull align 4 dereferenceable(12) [[AGG_TMP]], i32 noundef 3, i32 noundef 1, i32 noundef 1)
76 // HST-NEXT: call void @_ZN4dim3C1Ejjj(ptr noundef nonnull align 4 dereferenceable(12) [[AGG_TMP1]], i32 noundef 7, i32 noundef 1, i32 noundef 1)
77 // HST-NEXT: [[CALL:%.*]] = call i32 @__llvmPushCallConfiguration(ptr noundef byval([[STRUCT_DIM3]]) align 4 [[AGG_TMP]], ptr noundef byval([[STRUCT_DIM3]]) align 4 [[AGG_TMP1]], i32 noundef 0, ptr noundef null)
78 // HST-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[CALL]], 0
79 // HST-NEXT: br i1 [[TOBOOL]], label %[[KCALL_END:.*]], label %[[KCALL_CONFIGOK:.*]]
80 // HST: [[KCALL_CONFIGOK]]:
81 // HST-NEXT: [[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 4
82 // HST-NEXT: [[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR]], align 4
83 // HST-NEXT: call void @_Z18__device_stub__fooisPvS_(i32 noundef 13, i16 noundef signext 1, ptr noundef [[TMP0]], ptr noundef [[TMP1]]) #[[ATTR3:[0-9]+]]
84 // HST-NEXT: br label %[[KCALL_END]]
85 // HST: [[KCALL_END]]:
86 // HST-NEXT: ret void
87 //
88 void test1(void *Ptr) {
89 foo<<<3, 7>>>(13, 1, Ptr, Ptr);
90 }