1// REQUIRES: clang-driver
2// REQUIRES: x86-registered-target
3// REQUIRES: amdgpu-registered-target
4
5// RUN: %clang -c -### -target x86_64-linux-gnu \
6// RUN:   -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
7// RUN:   --hip-device-lib=lib1.bc --hip-device-lib=lib2.bc \
8// RUN:   --hip-device-lib-path=%S/Inputs/hip_multiple_inputs/lib1 \
9// RUN:   --hip-device-lib-path=%S/Inputs/hip_multiple_inputs/lib2 \
10// RUN:   -fuse-ld=lld -fgpu-rdc -nogpuinc \
11// RUN:   %S/Inputs/hip_multiple_inputs/a.cu \
12// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
13// RUN: 2>&1 | FileCheck %s
14
15// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-mllvm" "--amdhsa-code-object-version=4" "-triple" "amdgcn-amd-amdhsa"
16// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
17// CHECK-SAME: "-emit-llvm-bc"
18// CHECK-SAME: {{.*}} "-main-file-name" "a.cu"
19// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden"
20// CHECK-SAME: "-fapply-global-visibility-to-externs"
21// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc"
22// CHECK-SAME: "-target-cpu" "gfx803"
23// CHECK-SAME: {{.*}} "-o" "[[A_BC1:.*bc]]" "-x" "hip"
24// CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
25
26// CHECK: [[CLANG]] "-cc1" "-mllvm" "--amdhsa-code-object-version=4" "-triple" "amdgcn-amd-amdhsa"
27// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
28// CHECK-SAME: "-emit-llvm-bc"
29// CHECK-SAME: {{.*}} "-main-file-name" "a.cu"
30// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc"
31// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc"
32// CHECK-SAME: "-target-cpu" "gfx900"
33// CHECK-SAME: {{.*}} "-o" "[[A_BC2:.*bc]]" "-x" "hip"
34// CHECK-SAME: {{.*}} [[A_SRC]]
35
36// CHECK: [[CLANG]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
37// CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa"
38// CHECK-SAME: "-emit-obj"
39// CHECK-SAME: {{.*}} "-main-file-name" "a.cu"
40// CHECK-SAME: {{.*}} "-o" "[[A_OBJ_HOST:.*o]]" "-x" "hip"
41// CHECK-SAME: {{.*}} [[A_SRC]]
42
43// CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
44// CHECK-SAME: "-targets=hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900,host-x86_64-unknown-linux-gnu"
45// CHECK-SAME: "-outputs=[[A_O:.*a.o]]" "-inputs=[[A_BC1]],[[A_BC2]],[[A_OBJ_HOST]]"
46
47// CHECK: [[CLANG]] "-cc1" "-mllvm" "--amdhsa-code-object-version=4" "-triple" "amdgcn-amd-amdhsa"
48// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
49// CHECK-SAME: "-emit-llvm-bc"
50// CHECK-SAME: {{.*}} "-main-file-name" "b.hip"
51// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden"
52// CHECK-SAME: "-fapply-global-visibility-to-externs"
53// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc"
54// CHECK-SAME: "-target-cpu" "gfx803"
55// CHECK-SAME: {{.*}} "-o" "[[B_BC1:.*bc]]" "-x" "hip"
56// CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]]
57
58// CHECK: [[CLANG]] "-cc1" "-mllvm" "--amdhsa-code-object-version=4" "-triple" "amdgcn-amd-amdhsa"
59// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
60// CHECK-SAME: "-emit-llvm-bc"
61// CHECK-SAME: {{.*}} "-main-file-name" "b.hip"
62// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc"
63// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc"
64// CHECK-SAME: "-target-cpu" "gfx900"
65// CHECK-SAME: {{.*}} "-o" "[[B_BC2:.*bc]]" "-x" "hip"
66// CHECK-SAME: {{.*}} [[B_SRC]]
67
68// CHECK: [[CLANG]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
69// CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa"
70// CHECK-SAME: "-emit-obj"
71// CHECK-SAME: {{.*}} "-main-file-name" "b.hip"
72// CHECK-SAME: {{.*}} "-o" "[[B_OBJ_HOST:.*o]]" "-x" "hip"
73// CHECK-SAME: {{.*}} [[B_SRC]]
74
75// CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
76// CHECK-SAME: "-targets=hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900,host-x86_64-unknown-linux-gnu"
77// CHECK-SAME: "-outputs=[[B_O:.*b.o]]" "-inputs=[[B_BC1]],[[B_BC2]],[[B_OBJ_HOST]]"
78
79// RUN: touch %T/a.o
80// RUN: touch %T/b.o
81// RUN: %clang --hip-link -### -target x86_64-linux-gnu \
82// RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
83// RUN:   -fuse-ld=lld -fgpu-rdc -nogpuinc \
84// RUN:   %T/a.o %T/b.o \
85// RUN: 2>&1 | FileCheck -check-prefix=LINK %s
86
87// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
88// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
89// LINK-SAME: "-inputs=[[A_O:.*a.o]]" "-outputs=[[A_OBJ_HOST:.*o]],{{.*o}},{{.*o}}"
90// LINK: "-unbundle"
91
92// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
93// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
94// LINK-SAME: "-inputs=[[B_O:.*b.o]]" "-outputs=[[B_OBJ_HOST:.*o]],{{.*o}},{{.*o}}"
95// LINK: "-unbundle"
96
97// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
98// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
99// LINK-SAME: "-inputs=[[A_O]]" "-outputs={{.*o}},[[A_BC1:.*o]],[[A_BC2:.*o]]"
100// LINK: "-unbundle"
101
102// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
103// LINK-SAME: "-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx803,hip-amdgcn-amd-amdhsa-gfx900"
104// LINK-SAME: "-inputs=[[B_O]]" "-outputs={{.*o}},[[B_BC1:.*o]],[[B_BC2:.*o]]"
105// LINK: "-unbundle"
106
107// LINK-NOT: "*.llvm-link"
108// LINK-NOT: ".*opt"
109// LINK-NOT: ".*llc"
110// LINK: {{".*lld.*"}} {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
111// LINK: "-plugin-opt=mcpu=gfx803"
112// LINK-SAME: "-o" "[[IMG_DEV1:.*.out]]" "[[A_BC1]]" "[[B_BC1]]"
113
114// LINK-NOT: "*.llvm-link"
115// LINK-NOT: ".*opt"
116// LINK-NOT: ".*llc"
117// LINK: {{".*lld.*"}} {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
118// LINK: "-plugin-opt=mcpu=gfx900"
119// LINK-SAME: "-o" "[[IMG_DEV2:.*.out]]" "[[A_BC2]]" "[[B_BC2]]"
120
121// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
122// LINK-SAME: "-targets={{.*}},hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx900"
123// LINK-SAME: "-inputs={{.*}},[[IMG_DEV1]],[[IMG_DEV2]]" "-outputs=[[BUNDLE:.*hipfb]]"
124
125// LINK: {{".*llvm-mc.*"}} "-o" "[[OBJBUNDLE:.*o]]" "{{.*}}.mcin" "--filetype=obj"
126
127// LINK: [[LD:".*ld.*"]] {{.*}} "-o" "a.out" {{.*}} "[[A_OBJ_HOST]]"
128// LINK-SAME: "[[B_OBJ_HOST]]" "[[OBJBUNDLE]]"
129