10660397eSJoseph Huber // Tests the driver when targeting the NVPTX architecture directly without a 20660397eSJoseph Huber // host toolchain to perform CUDA mappings. 30660397eSJoseph Huber 40660397eSJoseph Huber // 50660397eSJoseph Huber // Test the generated phases when targeting NVPTX. 60660397eSJoseph Huber // 70660397eSJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-phases %s 2>&1 \ 80660397eSJoseph Huber // RUN: | FileCheck -check-prefix=PHASES %s 90660397eSJoseph Huber 100660397eSJoseph Huber // PHASES: 0: input, "[[INPUT:.+]]", c 110660397eSJoseph Huber // PHASES-NEXT: 1: preprocessor, {0}, cpp-output 120660397eSJoseph Huber // PHASES-NEXT: 2: compiler, {1}, ir 130660397eSJoseph Huber // PHASES-NEXT: 3: backend, {2}, assembler 140660397eSJoseph Huber // PHASES-NEXT: 4: assembler, {3}, object 150660397eSJoseph Huber // PHASES-NEXT: 5: linker, {4}, image 160660397eSJoseph Huber 170660397eSJoseph Huber // 180660397eSJoseph Huber // Test the generated bindings when targeting NVPTX. 190660397eSJoseph Huber // 200660397eSJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-bindings %s 2>&1 \ 210660397eSJoseph Huber // RUN: | FileCheck -check-prefix=BINDINGS %s 220660397eSJoseph Huber 230660397eSJoseph Huber // BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX:.+]].s" 240660397eSJoseph Huber // BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX]].s"], output: "[[CUBIN:.+]].o" 250660397eSJoseph Huber // BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN]].o"], output: "a.out" 260660397eSJoseph Huber 270660397eSJoseph Huber // 280660397eSJoseph Huber // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 290660397eSJoseph Huber // Ensure that the '.o' files are converted to '.cubin' if produced internally. 300660397eSJoseph Huber // 310660397eSJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \ 320660397eSJoseph Huber // RUN: | FileCheck -check-prefix=ARGS %s 330660397eSJoseph Huber 340660397eSJoseph Huber // ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s" 3537d0568aSJoseph Huber // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[CUBIN:.+]].o" "[[PTX]].s" "-c" 3637d0568aSJoseph Huber // ARGS-NEXT: clang-nvlink-wrapper{{.*}}"-o" "a.out" "-arch" "sm_61"{{.*}}"[[CUBIN]].o" 370660397eSJoseph Huber 380660397eSJoseph Huber // 390660397eSJoseph Huber // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 400660397eSJoseph Huber // Ensure that we emit '.o' files if compiled with '-c' 410660397eSJoseph Huber // 420660397eSJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -c -### %s 2>&1 \ 430660397eSJoseph Huber // RUN: | FileCheck -check-prefix=OBJECT %s 44861764b1SJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -save-temps -march=sm_61 -c -### %s 2>&1 \ 45861764b1SJoseph Huber // RUN: | FileCheck -check-prefix=OBJECT %s 460660397eSJoseph Huber 470660397eSJoseph Huber // OBJECT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s" 480660397eSJoseph Huber // OBJECT-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[OBJ:.+]].o" "[[PTX]].s" "-c" 490660397eSJoseph Huber 500660397eSJoseph Huber // 510660397eSJoseph Huber // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 520660397eSJoseph Huber // Ensure that we copy input '.o' files to '.cubin' files when linking. 530660397eSJoseph Huber // 540660397eSJoseph Huber // RUN: touch %t.o 550660397eSJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %t.o 2>&1 \ 560660397eSJoseph Huber // RUN: | FileCheck -check-prefix=LINK %s 570660397eSJoseph Huber 5837d0568aSJoseph Huber // LINK: clang-nvlink-wrapper{{.*}}"-o" "a.out" "-arch" "sm_61"{{.*}}[[CUBIN:.+]].o 590660397eSJoseph Huber 600660397eSJoseph Huber // 61f05ce904SJoseph Huber // Test to ensure that we enable handling global constructors in a freestanding 62f05ce904SJoseph Huber // Nvidia compilation. 63f05ce904SJoseph Huber // 64f05ce904SJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_70 %s -### 2>&1 \ 65f05ce904SJoseph Huber // RUN: | FileCheck -check-prefix=LOWERING %s 66*0c71fdd1SJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_70 -flto -c %s -### 2>&1 \ 67*0c71fdd1SJoseph Huber // RUN: | FileCheck -check-prefix=LOWERING-LTO %s 68f05ce904SJoseph Huber 69f05ce904SJoseph Huber // LOWERING: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-mllvm" "--nvptx-lower-global-ctor-dtor" 70*0c71fdd1SJoseph Huber // LOWERING: clang-nvlink-wrapper{{.*}} "-mllvm" "--nvptx-lower-global-ctor-dtor" 71*0c71fdd1SJoseph Huber // LOWERING-LTO-NOT: "--nvptx-lower-global-ctor-dtor" 727155c1efSJoseph Huber 737155c1efSJoseph Huber // 74d5a15f31SJoseph Huber // Test passing arguments directly to nvlink. 75d5a15f31SJoseph Huber // 76e8740d4eSJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -Wl,-v -Wl,a,b -march=sm_52 -### %s 2>&1 \ 77d5a15f31SJoseph Huber // RUN: | FileCheck -check-prefix=LINKER-ARGS %s 78d5a15f31SJoseph Huber 7937d0568aSJoseph Huber // LINKER-ARGS: clang-nvlink-wrapper{{.*}}"-v"{{.*}}"a" "b" 80d5a15f31SJoseph Huber 817155c1efSJoseph Huber // Tests for handling a missing architecture. 827155c1efSJoseph Huber // 837155c1efSJoseph Huber // RUN: not %clang -target nvptx64-nvidia-cuda %s -### 2>&1 \ 847155c1efSJoseph Huber // RUN: | FileCheck -check-prefix=MISSING %s 85047b2b24SYichen Yan // RUN: not %clang -target nvptx64-nvidia-cuda -march=generic %s -### 2>&1 \ 86047b2b24SYichen Yan // RUN: | FileCheck -check-prefix=MISSING %s 877155c1efSJoseph Huber 88b49ce9c3SAaron Ballman // MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'ptxas' 89b49ce9c3SAaron Ballman // MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink' 907155c1efSJoseph Huber 912bf58f5dSJoseph Huber // Do not error when performing LTO. 922bf58f5dSJoseph Huber // 932bf58f5dSJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -flto %s -### 2>&1 \ 942bf58f5dSJoseph Huber // RUN: | FileCheck -check-prefix=MISSING-LTO %s 952bf58f5dSJoseph Huber 962bf58f5dSJoseph Huber // MISSING-LTO-NOT: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink' 972bf58f5dSJoseph Huber 987155c1efSJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \ 997155c1efSJoseph Huber // RUN: | FileCheck -check-prefix=GENERIC %s 100047b2b24SYichen Yan // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto -c %s -### 2>&1 \ 101047b2b24SYichen Yan // RUN: | FileCheck -check-prefix=GENERIC %s 1027155c1efSJoseph Huber 1037155c1efSJoseph Huber // GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu" 1042b162286SJoseph Huber 1052b162286SJoseph Huber // 1062b162286SJoseph Huber // Test forwarding the necessary +ptx feature. 1072b162286SJoseph Huber // 1082b162286SJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda --cuda-feature=+ptx63 -march=sm_52 -### %s 2>&1 \ 1092b162286SJoseph Huber // RUN: | FileCheck -check-prefix=FEATURE %s 1102b162286SJoseph Huber 111f7b6dc82SJoseph Huber // FEATURE: clang-nvlink-wrapper{{.*}}"--plugin-opt=-mattr=+ptx63" 112d4c41804SJoseph Huber 113d4c41804SJoseph Huber // 114d4c41804SJoseph Huber // Test including the libc startup files and libc 115d4c41804SJoseph Huber // 116d4c41804SJoseph Huber // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -stdlib -startfiles \ 117d4c41804SJoseph Huber // RUN: -nogpulib -nogpuinc -### %s 2>&1 | FileCheck -check-prefix=STARTUP %s 118d4c41804SJoseph Huber 119d4c41804SJoseph Huber // STARTUP: clang-nvlink-wrapper{{.*}}"-lc" "-lm" "{{.*}}crt1.o" 120