[clang] [clang][Driver][SPIR-V] Allow linking IR using llvm-link (PR #169572)

Manuel Carrasco via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 10 03:01:52 PST 2025


================
@@ -0,0 +1,31 @@
+// Check BC input
+// RUN: mkdir -p %t
+// RUN: touch %t/a.bc
+// RUN: touch %t/b.bc
+// RUN: %clang -### --target=spirv64 -emit-llvm %t/a.bc %t/b.bc 2>&1 | FileCheck --check-prefix=CHECK-TOOL-BC %s
+
+// CHECK-TOOL-BC: "-cc1" {{.*}} "-o" "[[TMP1_BC:.+]]" "-x" "ir" "{{.*}}.bc"
+// CHECK-TOOL-BC: "-cc1" {{.*}} "-o" "[[TMP2_BC:.+]]" "-x" "ir" "{{.*}}.bc"
+// CHECK-TOOL-BC: llvm-link{{.*}} "-o" {{.*}} "[[TMP1_BC]]" "[[TMP2_BC]]"
+
+// RUN: %clang -ccc-print-bindings --target=spirv64 -emit-llvm %t/a.bc %t/b.bc 2>&1 | FileCheck -check-prefix=CHECK-BINDINGS-BC %s
+
+// CHECK-BINDINGS-BC: "spirv64" - "clang", inputs: ["{{.*}}.bc"], output: "[[TMP1_BINDINGS_BC:.+]]"
+// CHECK-BINDINGS-BC: "spirv64" - "clang", inputs: ["{{.*}}.bc"], output: "[[TMP2_BINDINGS_BC:.+]]"
+// CHECK-BINDINGS-BC: "spirv64" - "SPIR-V::Linker", inputs: ["[[TMP1_BINDINGS_BC]]", "[[TMP2_BINDINGS_BC]]"], output: "{{.*}}.bc"
+
+// Check source input
+// RUN: touch %t/foo.c
+// RUN: touch %t/bar.c
+
+// RUN: %clang -### --target=spirv64 -emit-llvm %t/foo.c %t/bar.c 2>&1 | FileCheck --check-prefix=CHECK-TOOL-SRC %s
+
+// CHECK-TOOL-SRC: "-cc1" {{.*}} "-o" "[[TMP1_SRC_BC:.+]]" "-x" "c" "{{.*}}foo.c"
+// CHECK-TOOL-SRC: "-cc1" {{.*}} "-o" "[[TMP2_SRC_BC:.+]]" "-x" "c" "{{.*}}bar.c"
+// CHECK-TOOL-SRC: llvm-link{{.*}} "-o" {{.*}} "[[TMP1_SRC_BC]]" "[[TMP2_SRC_BC]]"
+
+// RUN: %clang -ccc-print-bindings --target=spirv64 -emit-llvm %t/foo.c %t/bar.c 2>&1 | FileCheck -check-prefix=CHECK-BINDINGS-SRC %s
----------------
mgcarrasco wrote:

@sarnex I tested `clang -### --target=spirv64 -emit-llvm a.bc b.bc -save-temps` and it is invoking `llvm-link` twice. The last `llvm-link` call looks redundant since it has no output file. 

```
 "/home/macarras/spirv/llvm-project/build-release/bin/clang-22" "-cc1" "-triple" "spirv64" "-Wspir-compat" "-emit-llvm-bc" "-emit-llvm-uselists" "-dumpdir" "a-" "-save-temps=cwd" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "a.bc" "-mrelocation-model" "static" "-mframe-pointer=all" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/macarras/spirv/llvm-project-refactor" "-fcoverage-compilation-dir=/home/macarras/spirv/llvm-project-refactor" "-resource-dir" "/home/macarras/spirv/llvm-project/build-release/lib/clang/22" "-ferror-limit" "19" "-fmessage-length=191" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-o" "a.tmp.bc" "-x" "ir" "a.bc"
 "/usr/bin/llvm-link" "-o" "a.bc" "a.tmp.bc"
 "/usr/bin/llvm-link" "a.tmp.bc"
```
The redundant `llvm-link` also happens without `-save-temps`.

Why is the backend is only called on `a.bc` and not `b.bc`?


https://github.com/llvm/llvm-project/pull/169572


More information about the cfe-commits mailing list