File: unused-global-var.cu

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (53 lines) | stat: -rw-r--r-- 1,570 bytes parent folder | download | duplicates (19)
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
// REQUIRES: amdgpu-registered-target
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
// RUN:   -target-cpu gfx906 | FileCheck %s
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
// RUN:   -target-cpu gfx906 | FileCheck -check-prefix=NEGCHK %s

#include "Inputs/cuda.h"

// AMDGPU internalize unused global variables for whole-program compilation
// (-fno-gpu-rdc for each TU, or -fgpu-rdc for LTO), which are then
// eliminated by global DCE. If there are invisible unused address space casts
// for global variables, these dead users need to be eliminated by global
// DCE before internalization. This test makes sure unused global variables
// are eliminated.

// CHECK-DAG: @v1
__device__ int v1;

// CHECK-DAG: @v2
__constant__ int v2;

// Check unused device/constant variables are eliminated.

// NEGCHK-NOT: @_ZL2v3
constexpr int v3 = 1;

// Check managed variables are always kept.

// CHECK-DAG: @v4
__managed__ int v4;

// Check used device/constant variables are not eliminated.
// CHECK-DAG: @u1
__device__ int u1;

// CHECK-DAG: @u2
__constant__ int u2;

// Check u3 is kept because its address is taken.
// CHECK-DAG: @_ZL2u3
constexpr int u3 = 2;

// Check u4 is not kept because it is not ODR-use.
// NEGCHK-NOT: @_ZL2u4
constexpr int u4 = 3;

__device__ int fun1(const int& x);

__global__ void kern1(int *x) {
  *x = u1 + u2 + fun1(u3) + u4;
}