Skip to content

Commit cb678c7

Browse files
committed
Retain unmodified CodeGen output for AMDGCN SPIRV.
1 parent f97d25d commit cb678c7

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,13 @@ void AMDGPUToolChain::addClangTargetOptions(
858858
CC1Args.push_back("-fapply-global-visibility-to-externs");
859859
}
860860

861+
// For SPIR-V we want to retain the pristine output of Clang CodeGen, since
862+
// optimizations might lose structure / information that is necessary for
863+
// generating optimal concrete AMDGPU code.
864+
if (getTriple().isSPIRV() &&
865+
!DriverArgs.hasArg(options::OPT_disable_llvm_passes))
866+
CC1Args.push_back("-disable-llvm-passes");
867+
861868
if (DeviceOffloadingKind == Action::OFK_None)
862869
addOpenCLBuiltinsLib(getDriver(), DriverArgs, CC1Args);
863870
}

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ void HIPAMDToolChain::addClangTargetOptions(
261261
// with options that match the user-supplied ones.
262262
if (!DriverArgs.hasArg(options::OPT_fembed_bitcode_marker))
263263
CC1Args.push_back("-fembed-bitcode=marker");
264+
// For SPIR-V we want to retain the pristine output of Clang CodeGen, since
265+
// optimizations might lose structure / information that is necessary for
266+
// generating optimal concrete AMDGPU code. We duplicate this because the
267+
// HIP TC doesn't invoke the base AMDGPU TC addClangTargetOptions.
268+
if (!DriverArgs.hasArg(options::OPT_disable_llvm_passes))
269+
CC1Args.push_back("-disable-llvm-passes");
264270
return; // No DeviceLibs for SPIR-V.
265271
}
266272

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
// Check mixed AMDGCNSPIRV and concrete GPU arch.
207207
//
208208

209-
// AMDGCNSPIRV: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-emit-llvm-bc" {{.*}} "-o" "[[AMDGCNSPV_BC:.*bc]]"
209+
// AMDGCNSPIRV: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-emit-llvm-bc" {{.*}}"-fembed-bitcode=marker" "-disable-llvm-passes" {{.*}} "-o" "[[AMDGCNSPV_BC:.*bc]]"
210210
// AMDGCNSPIRV: {{".*llvm-link.*"}} "-o" "[[AMDGCNSPV_TMP:.*out]]" "[[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]]"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
// RUN: %clang -### --target=spirv64-amd-amdhsa %s -nogpulib -nogpuinc 2>&1 \
1616
// RUN: | FileCheck %s --check-prefix=INVOCATION
17-
// INVOCATION: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}} "-o" "[[OUTPUT:.+]]" "-x" "c"
17+
// INVOCATION: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-disable-llvm-passes" {{.*}} "-o" "[[OUTPUT:.+]]" "-x" "c"
1818
// INVOCATION: "{{.*}}llvm-link" "-o" "a.out" "[[OUTPUT]]"
1919
// 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"

0 commit comments

Comments
 (0)