1 // Tests the driver when targeting the NVPTX architecture directly without a
2 // host toolchain to perform CUDA mappings.
5 // Test the generated phases when targeting NVPTX.
7 // RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-phases %s 2>&1 \
8 // RUN: | FileCheck -check-prefix=PHASES %s
10 // PHASES: 0: input, "[[INPUT:.+]]", c
11 // PHASES-NEXT: 1: preprocessor, {0}, cpp-output
12 // PHASES-NEXT: 2: compiler, {1}, ir
13 // PHASES-NEXT: 3: backend, {2}, assembler
14 // PHASES-NEXT: 4: assembler, {3}, object
15 // PHASES-NEXT: 5: linker, {4}, image
18 // Test the generated bindings when targeting NVPTX.
20 // RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-bindings %s 2>&1 \
21 // RUN: | FileCheck -check-prefix=BINDINGS %s
23 // BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX:.+]].s"
24 // BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX]].s"], output: "[[CUBIN:.+]].o"
25 // BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN]].o"], output: "a.out"
28 // Test the generated arguments to the CUDA binary utils when targeting NVPTX.
29 // Ensure that the '.o' files are converted to '.cubin' if produced internally.
31 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
32 // RUN: | FileCheck -check-prefix=ARGS %s
34 // ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
35 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[CUBIN:.+]].o" "[[PTX]].s" "-c"
36 // ARGS-NEXT: clang-nvlink-wrapper{{.*}}"-o" "a.out" "-arch" "sm_61"{{.*}}"[[CUBIN]].o"
39 // Test the generated arguments to the CUDA binary utils when targeting NVPTX.
40 // Ensure that we emit '.o' files if compiled with '-c'
42 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -c -### %s 2>&1 \
43 // RUN: | FileCheck -check-prefix=OBJECT %s
44 // RUN: %clang -target nvptx64-nvidia-cuda -save-temps -march=sm_61 -c -### %s 2>&1 \
45 // RUN: | FileCheck -check-prefix=OBJECT %s
47 // OBJECT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
48 // OBJECT-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[OBJ:.+]].o" "[[PTX]].s" "-c"
51 // Test the generated arguments to the CUDA binary utils when targeting NVPTX.
52 // Ensure that we copy input '.o' files to '.cubin' files when linking.
55 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %t.o 2>&1 \
56 // RUN: | FileCheck -check-prefix=LINK %s
58 // LINK: clang-nvlink-wrapper{{.*}}"-o" "a.out" "-arch" "sm_61"{{.*}}[[CUBIN:.+]].o
61 // Test to ensure that we enable handling global constructors in a freestanding
62 // Nvidia compilation.
64 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_70 %s -### 2>&1 \
65 // RUN: | FileCheck -check-prefix=LOWERING %s
67 // LOWERING: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-mllvm" "--nvptx-lower-global-ctor-dtor"
70 // Test passing arguments directly to nvlink.
72 // RUN: %clang -target nvptx64-nvidia-cuda -Wl,-v -Wl,a,b -march=sm_52 -### %s 2>&1 \
73 // RUN: | FileCheck -check-prefix=LINKER-ARGS %s
75 // LINKER-ARGS: clang-nvlink-wrapper{{.*}}"-v"{{.*}}"a" "b"
77 // Tests for handling a missing architecture.
79 // RUN: not %clang -target nvptx64-nvidia-cuda %s -### 2>&1 \
80 // RUN: | FileCheck -check-prefix=MISSING %s
81 // RUN: not %clang -target nvptx64-nvidia-cuda -march=generic %s -### 2>&1 \
82 // RUN: | FileCheck -check-prefix=MISSING %s
84 // MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'ptxas'
85 // MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink'
87 // Do not error when performing LTO.
89 // RUN: %clang -target nvptx64-nvidia-cuda -flto %s -### 2>&1 \
90 // RUN: | FileCheck -check-prefix=MISSING-LTO %s
92 // MISSING-LTO-NOT: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink'
94 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
95 // RUN: | FileCheck -check-prefix=GENERIC %s
96 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto -c %s -### 2>&1 \
97 // RUN: | FileCheck -check-prefix=GENERIC %s
99 // GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
102 // Test forwarding the necessary +ptx feature.
104 // RUN: %clang -target nvptx64-nvidia-cuda --cuda-feature=+ptx63 -march=sm_52 -### %s 2>&1 \
105 // RUN: | FileCheck -check-prefix=FEATURE %s
107 // FEATURE: clang-nvlink-wrapper{{.*}}"--plugin-opt=-mattr=+ptx63"
110 // Test including the libc startup files and libc
112 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -stdlib -startfiles \
113 // RUN: -nogpulib -nogpuinc -### %s 2>&1 | FileCheck -check-prefix=STARTUP %s
115 // STARTUP: clang-nvlink-wrapper{{.*}}"-lc" "-lm" "{{.*}}crt1.o"