Skip to content

Commit b748248

Browse files
[HIP][SPIRV] Create an intermediate file for the llvm-link output
Before this patch we had: clang -cc1 source.c -o bitcode.bc llvm-link -o a.out bitcode.bc llvm-spirv -o a.out a.out Now we have: clang -cc1 source.c -o bitcode.bc llvm-link -o a-linked.bc bitcode.bc llvm-spirv -o a.out a-linked.bc Co-authored-by: Manuel Carrasco <[email protected]>
1 parent 070d11c commit b748248

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,12 @@ void AMDGCN::Linker::constructLinkAndEmitSpirvCommand(
168168
const InputInfo &Output, const llvm::opt::ArgList &Args) const {
169169
assert(!Inputs.empty() && "Must have at least one input.");
170170

171-
constructLlvmLinkCommand(C, JA, Inputs, Output, Args);
171+
std::string LinkedBCFilePrefix(
172+
Twine(llvm::sys::path::stem(Output.getFilename()), "-linked").str());
173+
const char *LinkedBCFilePath = HIP::getTempFile(C, LinkedBCFilePrefix, "bc");
174+
InputInfo LinkedBCFile(&JA, LinkedBCFilePath, Output.getBaseInput());
172175

173-
// Linked BC is now in Output
176+
constructLlvmLinkCommand(C, JA, Inputs, LinkedBCFile, Args);
174177

175178
// Emit SPIR-V binary.
176179
llvm::opt::ArgStringList TrArgs{
@@ -180,7 +183,7 @@ void AMDGCN::Linker::constructLinkAndEmitSpirvCommand(
180183
"--spirv-lower-const-expr",
181184
"--spirv-preserve-auxdata",
182185
"--spirv-debug-info-version=nonsemantic-shader-200"};
183-
SPIRV::constructTranslateCommand(C, *this, JA, Output, Output, TrArgs);
186+
SPIRV::constructTranslateCommand(C, *this, JA, Output, LinkedBCFile, TrArgs);
184187
}
185188

186189
// For amdgcn the inputs of the linker job are device bitcode and output is

clang/test/Driver/hip-toolchain-no-rdc.hip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
//
208208

209209
// AMDGCNSPIRV: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-emit-llvm-bc" {{.*}}"-fembed-bitcode=marker" "-disable-llvm-passes" {{.*}} "-o" "[[AMDGCNSPV_BC:.*bc]]"
210-
// AMDGCNSPIRV: {{".*llvm-link.*"}} "-o" "[[AMDGCNSPV_TMP:.*out]]" "[[AMDGCNSPV_BC]]"
210+
// AMDGCNSPIRV: {{".*llvm-link.*"}} "-o" "[[AMDGCNSPV_TMP:.*bc]]" "[[AMDGCNSPV_BC]]"
211211
// AMDGCNSPIRV: {{".*llvm-spirv.*"}} "--spirv-max-version=1.6" "--spirv-ext=+all" {{.*}} "[[AMDGCNSPV_TMP]]" {{.*}}"-o" "[[AMDGCNSPV_CO:.*out]]"
212212
// AMDGCNSPIRV: "-cc1" "-triple" "amdgcn-amd-amdhsa" {{.*}}"-emit-obj" {{.*}}"-target-cpu" "gfx900"{{.*}} "-o" "[[GFX900_OBJ:.*o]]"
213213
// AMDGCNSPIRV: {{".*lld.*"}} {{.*}}"-plugin-opt=mcpu=gfx900" {{.*}} "-o" "[[GFX900_CO:.*out]]" {{.*}}"[[GFX900_OBJ]]"

clang/test/Driver/spirv-amd-toolchain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
// RUN: %clang -### --target=spirv64-amd-amdhsa %s -nogpulib -nogpuinc 2>&1 \
1616
// RUN: | FileCheck %s --check-prefix=INVOCATION
1717
// INVOCATION: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-disable-llvm-optzns" {{.*}} "-o" "[[OUTPUT:.+]]" "-x" "c"
18-
// INVOCATION: "{{.*}}llvm-link" "-o" "a.out" "[[OUTPUT]]"
19-
// INVOCATION: "{{.*}}llvm-spirv" "--spirv-max-version=1.6" "--spirv-ext=+all" "--spirv-allow-unknown-intrinsics" "--spirv-lower-const-expr" "--spirv-preserve-auxdata" "--spirv-debug-info-version=nonsemantic-shader-200" "a.out" "-o" "a.out"
18+
// INVOCATION: "{{.*}}llvm-link" "-o" "[[LINKED_OUTPUT:.+]]" "[[OUTPUT]]"
19+
// INVOCATION: "{{.*}}llvm-spirv" "--spirv-max-version=1.6" "--spirv-ext=+all" "--spirv-allow-unknown-intrinsics" "--spirv-lower-const-expr" "--spirv-preserve-auxdata" "--spirv-debug-info-version=nonsemantic-shader-200" "[[LINKED_OUTPUT]]" "-o" "a.out"

0 commit comments

Comments
 (0)