1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
// RUN: %clang_cc1 -no-opaque-pointers -x hip -emit-llvm -std=c++11 %s -o - \
// RUN: -triple x86_64-linux-gnu \
// RUN: | FileCheck -check-prefix=HOST %s
// RUN: %clang_cc1 -no-opaque-pointers -x hip -emit-llvm -std=c++11 %s -o - \
// RUN: -triple amdgcn-amd-amdhsa -fcuda-is-device \
// RUN: | FileCheck -check-prefix=DEV %s
#include "Inputs/cuda.h"
// HOST: %[[T1:.*]] = type <{ i32*, i32, [4 x i8] }>
// HOST: %[[T2:.*]] = type { i32*, i32** }
// HOST: %[[T3:.*]] = type <{ i32*, i32, [4 x i8] }>
// DEV: %[[T1:.*]] = type { i32* }
// DEV: %[[T2:.*]] = type { i32** }
// DEV: %[[T3:.*]] = type <{ i32*, i32, [4 x i8] }>
int global_host_var;
__device__ int global_device_var;
template<class F>
__global__ void kern(F f) { f(); }
// DEV-LABEL: @_ZZ27dev_capture_dev_ref_by_copyPiENKUlvE_clEv(
// DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: store i32 %[[VAL]]
__device__ void dev_capture_dev_ref_by_copy(int *out) {
int &ref = global_device_var;
[=](){ *out = ref;}();
}
// DEV-LABEL: @_ZZ28dev_capture_dev_rval_by_copyPiENKUlvE_clEv(
// DEV: store i32 3
__device__ void dev_capture_dev_rval_by_copy(int *out) {
constexpr int a = 1;
constexpr int b = 2;
constexpr int c = a + b;
[=](){ *out = c;}();
}
// DEV-LABEL: @_ZZ26dev_capture_dev_ref_by_refPiENKUlvE_clEv(
// DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
// DEV: store i32 %[[VAL2]], i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: store i32 %[[VAL]]
__device__ void dev_capture_dev_ref_by_ref(int *out) {
int &ref = global_device_var;
[&](){ ref++; *out = ref;}();
}
// DEV-LABEL: define{{.*}} void @_Z7dev_refPi(
// DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
// DEV: store i32 %[[VAL2]], i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: store i32 %[[VAL]]
__device__ void dev_ref(int *out) {
int &ref = global_device_var;
ref++;
*out = ref;
}
// DEV-LABEL: @_ZZ14dev_lambda_refPiENKUlvE_clEv(
// DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
// DEV: store i32 %[[VAL2]], i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* @global_device_var to i32*)
// DEV: store i32 %[[VAL]]
__device__ void dev_lambda_ref(int *out) {
[=](){
int &ref = global_device_var;
ref++;
*out = ref;
}();
}
// HOST-LABEL: @_ZZ29host_capture_host_ref_by_copyPiENKUlvE_clEv(
// HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
// HOST: store i32 %[[VAL]]
void host_capture_host_ref_by_copy(int *out) {
int &ref = global_host_var;
[=](){ *out = ref;}();
}
// HOST-LABEL: @_ZZ28host_capture_host_ref_by_refPiENKUlvE_clEv(
// HOST: %[[CAP:.*]] = getelementptr inbounds %[[T2]], %[[T2]]* %this1, i32 0, i32 0
// HOST: %[[REF:.*]] = load i32*, i32** %[[CAP]]
// HOST: %[[VAL:.*]] = load i32, i32* %[[REF]]
// HOST: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
// HOST: store i32 %[[VAL2]], i32* %[[REF]]
// HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
// HOST: store i32 %[[VAL]]
void host_capture_host_ref_by_ref(int *out) {
int &ref = global_host_var;
[&](){ ref++; *out = ref;}();
}
// HOST-LABEL: define{{.*}} void @_Z8host_refPi(
// HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
// HOST: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
// HOST: store i32 %[[VAL2]], i32* @global_host_var
// HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
// HOST: store i32 %[[VAL]]
void host_ref(int *out) {
int &ref = global_host_var;
ref++;
*out = ref;
}
// HOST-LABEL: @_ZZ15host_lambda_refPiENKUlvE_clEv(
// HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
// HOST: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
// HOST: store i32 %[[VAL2]], i32* @global_host_var
// HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
// HOST: store i32 %[[VAL]]
void host_lambda_ref(int *out) {
[=](){
int &ref = global_host_var;
ref++;
*out = ref;
}();
}
// HOST-LABEL: define{{.*}} void @_Z28dev_capture_host_ref_by_copyPi(
// HOST: %[[CAP:.*]] = getelementptr inbounds %[[T3]], %[[T3]]* %{{.*}}, i32 0, i32 1
// HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
// HOST: store i32 %[[VAL]], i32* %[[CAP]]
// DEV-LABEL: define internal void @_ZZ28dev_capture_host_ref_by_copyPiENKUlvE_clEv(
// DEV: %[[CAP:.*]] = getelementptr inbounds %[[T3]], %[[T3]]* %this1, i32 0, i32 1
// DEV: %[[VAL:.*]] = load i32, i32* %[[CAP]]
// DEV: store i32 %[[VAL]]
void dev_capture_host_ref_by_copy(int *out) {
int &ref = global_host_var;
kern<<<1, 1>>>([=]__device__() { *out = ref;});
}
|