Revert "[HIPSPV] Add in-tree SPIR-V backend support for chipStar" (#213088)

Reverts llvm/llvm-project#206910 
which broke buildbot:
https://lab.llvm.org/buildbot/#/builders/144/builds/60707
This commit is contained in:
Prabhu Rajasekaran 2026-07-30 11:37:52 -07:00 committed by GitHub
parent 63b3eb10e5
commit 6162922a8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 73 additions and 184 deletions

View file

@ -13,7 +13,6 @@
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Options/Options.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
@ -49,28 +48,6 @@ static std::string findPassPlugin(const Driver &D,
return std::string();
}
// Runs the HipSpvPasses plugin via `opt` on TempFile when the plugin is found.
// Returns the lowered bitcode path, or TempFile unchanged if no plugin exists.
static const char *runHipSpvPasses(Compilation &C, const JobAction &JA,
const Tool &Creator, const ToolChain &TC,
const InputInfoList &Inputs,
const InputInfo &Output,
const llvm::opt::ArgList &Args,
StringRef Name, const char *TempFile) {
auto PassPluginPath = findPassPlugin(C.getDriver(), Args);
if (PassPluginPath.empty())
return TempFile;
const char *PassPathCStr = C.getArgs().MakeArgString(PassPluginPath);
const char *OptOutput = HIP::getTempFile(C, Name.str() + "-lower", "bc");
ArgStringList OptArgs{TempFile, "-load-pass-plugin",
PassPathCStr, "-passes=hip-post-link-passes",
"-o", OptOutput};
const char *Opt = Args.MakeArgString(TC.GetProgramPath("opt"));
C.addCommand(std::make_unique<Command>(
JA, Creator, ResponseFileSupport::None(), Opt, OptArgs, Inputs, Output));
return OptOutput;
}
void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(
Compilation &C, const JobAction &JA, const InputInfoList &Inputs,
const InputInfo &Output, const llvm::opt::ArgList &Args) const {
@ -96,99 +73,44 @@ void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(
tools::constructLLVMLinkCommand(C, *this, JA, Inputs, LinkArgs, Output, Args,
TempFile);
auto T = getToolChain().getTriple();
// Post-link HIP lowering.
if (T.getOS() == llvm::Triple::ChipStar) {
// chipStar: run HipSpvPasses via opt, then emit SPIR-V with the in-tree
// SPIR-V backend by default, or with the external llvm-spirv translator
// when -fno-integrated-objemitter is given (or the backend is not built).
// Run HipSpvPasses plugin via opt (must run on LLVM IR before
// the SPIR-V backend lowers to MIR).
TempFile = runHipSpvPasses(C, JA, *this, getToolChain(), Inputs, Output,
Args, Name, TempFile);
if (!getToolChain().useIntegratedBackend()) {
// External translator path: BC -> SPIR-V via llvm-spirv.
llvm::opt::ArgStringList TrArgs;
if (T.getSubArch() == llvm::Triple::NoSubArch)
TrArgs.push_back("--spirv-max-version=1.2");
// Keep this extension list in sync with the in-tree backend fallback
// below.
TrArgs.push_back("--spirv-ext=-all"
",+SPV_INTEL_function_pointers"
",+SPV_INTEL_subgroups"
",+SPV_KHR_bit_instructions"
",+SPV_EXT_shader_atomic_float_add");
// Preserve debug info in the NonSemantic.Shader.DebugInfo form (see the
// comment on the equivalent block in the non-chipStar path below).
// These flags are passed unconditionally instead of gating on -g: in
// RDC-mode links this job runs in a clang invoked by
// clang-linker-wrapper where the original -g is not visible, but the
// debug info itself travels in the bitcode. SPV_KHR_non_semantic_info
// and the debug info version only take effect when the bitcode carries
// debug info. SPV_INTEL_optnone is not tied to debug info: clang emits
// optnone at -O0 even without -g, and the emitter needs the extension
// allowed to encode it.
TrArgs.push_back("--spirv-ext=+SPV_KHR_non_semantic_info"
",+SPV_INTEL_optnone");
TrArgs.push_back("--spirv-debug-info-version=nonsemantic-shader-200");
InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile, "");
SPIRV::constructTranslateCommand(C, *this, JA, Output, TrInput, TrArgs);
return;
}
// Default: compile the lowered bitcode to SPIR-V with the in-tree backend.
// Invoke `clang -cc1` directly rather than the clang driver: the driver
// would re-run config-file loading, toolchain detection and argument
// translation over an input that is already device-compiled and lowered,
// which is both wasteful and fragile. This mirrors how HIPAMD drives its
// SPIR-V backend emission (see HIPAMD::constructLinkAndEmitSpirvCommand).
// Keep the default -O0 backend pipeline (i.e. no -disable-llvm-optzns) so
// the mandatory lowering passes still run, matching the previously
// validated driver `-c` behavior.
ArgStringList Cc1Args;
Cc1Args.push_back("-cc1");
Cc1Args.push_back("-triple");
Cc1Args.push_back(C.getArgs().MakeArgString(T.getTriple()));
Cc1Args.push_back("-emit-obj");
// SPIR-V extensions the chipStar runtime relies on. Keep in sync with the
// llvm-spirv translator path above. SPV_KHR_non_semantic_info and
// SPV_INTEL_optnone let the backend emit NonSemantic.Shader.DebugInfo and
// the OptNoneINTEL function control when the bitcode carries debug info /
// optnone attributes (the backend's debug handler is a no-op otherwise).
Cc1Args.push_back("-mllvm");
Cc1Args.push_back("-spirv-ext=+SPV_INTEL_function_pointers"
",+SPV_INTEL_subgroups"
",+SPV_KHR_bit_instructions"
",+SPV_EXT_shader_atomic_float_add"
",+SPV_KHR_non_semantic_info"
",+SPV_INTEL_optnone");
Cc1Args.push_back(TempFile);
Cc1Args.push_back("-o");
Cc1Args.push_back(Output.getFilename());
const Driver &Drv = C.getDriver();
const char *Clang = Drv.getDriverProgramPath();
// Run LLVM IR passes to lower/expand/emulate HIP code that does not translate
// to SPIR-V (E.g. dynamic shared memory).
auto PassPluginPath = findPassPlugin(C.getDriver(), Args);
if (!PassPluginPath.empty()) {
const char *PassPathCStr = C.getArgs().MakeArgString(PassPluginPath);
const char *OptOutput = HIP::getTempFile(C, Name + "-lower", "bc");
ArgStringList OptArgs{TempFile, "-load-pass-plugin",
PassPathCStr, "-passes=hip-post-link-passes",
"-o", OptOutput};
const char *Opt = Args.MakeArgString(getToolChain().GetProgramPath("opt"));
C.addCommand(std::make_unique<Command>(
JA, *this, ResponseFileSupport::None(), Clang, Cc1Args, Inputs, Output,
Drv.getPrependArg()));
return;
JA, *this, ResponseFileSupport::None(), Opt, OptArgs, Inputs, Output));
TempFile = OptOutput;
}
// Non-chipStar: run HIP passes via opt, then translate with llvm-spirv.
TempFile = runHipSpvPasses(C, JA, *this, getToolChain(), Inputs, Output, Args,
Name, TempFile);
// Emit SPIR-V binary via llvm-spirv translator (non-chipStar targets).
// Emit SPIR-V binary.
llvm::opt::ArgStringList TrArgs;
if (T.getSubArch() == llvm::Triple::NoSubArch)
TrArgs.push_back("--spirv-max-version=1.1");
TrArgs.push_back("--spirv-ext=+all");
auto T = getToolChain().getTriple();
bool HasNoSubArch = T.getSubArch() == llvm::Triple::NoSubArch;
if (T.getOS() == llvm::Triple::ChipStar) {
// chipStar needs 1.2 for supporting warp-level primitivies via sub-group
// extensions. Strictly put we'd need 1.3 for the standard non-extension
// shuffle operations, but it's not supported by any backend driver of the
// chipStar.
if (HasNoSubArch)
TrArgs.push_back("--spirv-max-version=1.2");
TrArgs.push_back("--spirv-ext=-all"
// Needed for experimental indirect call support.
",+SPV_INTEL_function_pointers"
// Needed for shuffles below SPIR-V 1.3
",+SPV_INTEL_subgroups");
} else {
if (HasNoSubArch)
TrArgs.push_back("--spirv-max-version=1.1");
TrArgs.push_back("--spirv-ext=+all");
}
// Preserve debug info requested via -g into the emitted SPIR-V using the
// NonSemantic.Shader.DebugInfo form. Downstream consumers such as Intel's IGC
@ -253,18 +175,6 @@ HIPSPVToolChain::HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
getProgramPaths().push_back(getDriver().Dir);
}
bool HIPSPVToolChain::IsIntegratedBackendSupported() const {
// The in-tree SPIR-V backend can only be used when it is built.
std::string IgnoredError;
return llvm::TargetRegistry::lookupTarget(getTriple(), IgnoredError);
}
bool HIPSPVToolChain::IsIntegratedBackendDefault() const {
// Prefer the in-tree SPIR-V backend; fall back to the external llvm-spirv
// translator when the backend is not built.
return IsIntegratedBackendSupported();
}
void HIPSPVToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
BoundArch BA, Action::OffloadKind DeviceOffloadingKind) const {

View file

@ -52,13 +52,10 @@ public:
const llvm::opt::ArgList &Args);
const llvm::Triple *getAuxTriple() const override {
return HostTC ? &HostTC->getTriple() : nullptr;
assert(HostTC);
return &HostTC->getTriple();
}
bool IsIntegratedBackendDefault() const override;
bool IsIntegratedBackendSupported() const override;
bool IsNonIntegratedBackendSupported() const override { return true; }
void
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args, BoundArch BA,

View file

@ -49,8 +49,7 @@
// DELETE-SDL-NEW: "{{.*}}llvm-link" "-o" "{{.*}}.bc" "{{.*}}.o" "{{.*}}.o"
// SDL-NEW-WRAPPER: clang{{.*}}" --no-default-config -o {{[^ ]*.img}}
// SDL-NEW-WRAPPER-SAME: --target=spirv64-unknown-chipstar
// SDL-NEW-WRAPPER-SAME: {{[^ ]*.o}}
// SDL-NEW-WRAPPER-SAME: {{[^ ]*.o}} {{[^ ]*.o}}
// SDL-NEW-WRAPPER-SAME: --hip-path=[[HIP_PATH]]
// SDL: "{{.*}}opt"

View file

@ -1,4 +1,3 @@
// REQUIRES: spirv-registered-target
// UNSUPPORTED: system-windows
// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
@ -17,24 +16,23 @@
// RUN: --no-offload-new-driver -nogpuinc -nogpulib %s \
// RUN: 2>&1 | FileCheck --check-prefixes=ALL,NO-PLUGIN %s
// Run commands for the new offload driver (chipStar uses in-tree SPIR-V
// backend instead of llvm-spirv):
// Run commands for the new offload driver:
// RUN: touch %t.dummy.o
// RUN: env "PATH=" %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
// RUN: %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
// RUN: %t.dummy.o --hip-path=%S/Inputs/hipspv \
// RUN: 2>&1 | FileCheck %s --check-prefixes=CHIPSTAR,FROM-HIP-PATH
// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FROM-HIP-PATH
// RUN: env "PATH=" %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
// RUN: %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
// RUN: %t.dummy.o --hipspv-pass-plugin=%S/Inputs/pass-plugin.so \
// RUN: 2>&1 | FileCheck %s --check-prefixes=CHIPSTAR,FROM-OPTION
// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FROM-OPTION
// RUN: not env "PATH=" %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
// RUN: not %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
// RUN: %t.dummy.o --hipspv-pass-plugin=foo.so \
// RUN: 2>&1 | FileCheck %s --check-prefixes=CHIPSTAR,FROM-OPTION-INVALID
// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FROM-OPTION-INVALID
// RUN: env "PATH=" %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
// RUN: %t.dummy.o 2>&1 | FileCheck %s --check-prefixes=CHIPSTAR,NO-PLUGIN
// RUN: %clang -### --no-default-config -o /dev/null --target=spirv64-unknown-chipstar \
// RUN: %t.dummy.o 2>&1 | FileCheck %s --check-prefixes=ALL,NO-PLUGIN
// FROM-HIP-PATH: {{".*opt"}} {{".*.bc"}} "-load-pass-plugin"
// FROM-HIP-PATH-SAME: {{".*/Inputs/hipspv/lib/libLLVMHipSpvPasses.so"}}
@ -44,5 +42,3 @@
// NO-PLUGIN-NOT: {{".*opt"}} {{".*.bc"}} "-load-pass-plugin"
// NO-PLUGIN-NOT: {{".*/Inputs/hipspv/lib/libLLVMHipSpvPasses.so"}}
// ALL: {{".*llvm-spirv[^ ]*"}}
// CHIPSTAR: {{".*clang.*"}} "-cc1"
// CHIPSTAR-SAME: "-emit-obj"

View file

@ -60,10 +60,6 @@
// RUN: llvm-offload-binary -o %t.dev.out \
// RUN: --image=file=%t.dev.bc,kind=hip,triple=spirv64-unknown-chipstar,arch=generic
// The linker wrapper forwards --hip-path from --device-compiler= to the inner
// clang invocation; the HIPSPV toolchain inside that clang then drives the
// llvm-link / opt (HipSpvPasses) / SPIR-V backend pipeline (covered by the
// CHIPSTAR run below).
// RUN: clang-linker-wrapper --dry-run \
// RUN: --device-compiler=spirv64-unknown-chipstar=--hip-path="%S/Inputs/hipspv" \
// RUN: --host-triple=spirv64-unknown-chipstar \
@ -76,8 +72,6 @@
// WRAPPER-SAME: {{[^ ]*.o}}
// WRAPPER-SAME: --hip-path=[[HIP_PATH]]
// The in-tree SPIR-V backend is the default emitter; PATH content (e.g. a
// stray llvm-spirv) must not affect the choice.
// RUN: touch %t.dummy.o
// RUN: %clang -### --no-default-config -o %t.dummy.img \
// RUN: --target=spirv64-unknown-chipstar %t.dummy.o \
@ -91,9 +85,8 @@
// CHIPSTAR-SAME: "[[HIP_PATH]]/lib/libLLVMHipSpvPasses.so"
// CHIPSTAR-SAME: "-passes=hip-post-link-passes" "-o" [[LOWER_BC:".*bc"]]
// CHIPSTAR: {{".*clang.*"}} "-cc1" "-triple" "spirv64-unknown-chipstar"
// CHIPSTAR-SAME: "-emit-obj"
// CHIPSTAR-SAME: "-mllvm" "-spirv-ext=+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups,+SPV_KHR_bit_instructions,+SPV_EXT_shader_atomic_float_add,+SPV_KHR_non_semantic_info,+SPV_INTEL_optnone"
// CHIPSTAR: {{".*llvm-spirv"}} "--spirv-max-version=1.2"
// CHIPSTAR-SAME: "--spirv-ext=-all,+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups"
// CHIPSTAR-SAME: [[LOWER_BC]] "-o" "[[SPIRV_OUT:.*img]]"
// RUN: %clang -### --no-default-config -o %t.dummy.img \
@ -108,27 +101,10 @@
// CHIPSTAR-SUBARCH-SAME: "[[HIP_PATH]]/lib/libLLVMHipSpvPasses.so"
// CHIPSTAR-SUBARCH-SAME: "-passes=hip-post-link-passes" "-o" [[LOWER_BC:".*bc"]]
// CHIPSTAR-SUBARCH: {{".*clang.*"}} "-cc1" "-triple" "spirv64v1.3-unknown-chipstar"
// CHIPSTAR-SUBARCH-SAME: "-emit-obj"
// CHIPSTAR-SUBARCH-SAME: "-mllvm" "-spirv-ext=+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups,+SPV_KHR_bit_instructions,+SPV_EXT_shader_atomic_float_add,+SPV_KHR_non_semantic_info,+SPV_INTEL_optnone"
// CHIPSTAR-SUBARCH: {{".*llvm-spirv"}}
// CHIPSTAR-SUBARCH-SAME: "--spirv-ext=-all,+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups"
// CHIPSTAR-SUBARCH-SAME: [[LOWER_BC]] "-o" "[[SPIRV_OUT:.*img]]"
// -fno-integrated-objemitter selects the external llvm-spirv translator.
// RUN: %clang -### --no-default-config -o %t.dummy.img \
// RUN: --target=spirv64-unknown-chipstar %t.dummy.o \
// RUN: --hip-path="%S/Inputs/hipspv" -fno-integrated-objemitter \
// RUN: 2>&1 | FileCheck %s --check-prefix=CHIPSTAR-XTOR -DHIP_PATH=%S/Inputs/hipspv
// CHIPSTAR-XTOR: {{".*opt"}} {{".*bc"}} "-load-pass-plugin"
// CHIPSTAR-XTOR-SAME: "[[HIP_PATH]]/lib/libLLVMHipSpvPasses.so"
// CHIPSTAR-XTOR-SAME: "-passes=hip-post-link-passes" "-o" [[LOWER_BC:".*bc"]]
// CHIPSTAR-XTOR: {{".*llvm-spirv.*"}} "--spirv-max-version=1.2"
// CHIPSTAR-XTOR-SAME: "--spirv-ext=-all,+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups,+SPV_KHR_bit_instructions,+SPV_EXT_shader_atomic_float_add"
// CHIPSTAR-XTOR-SAME: "--spirv-ext=+SPV_KHR_non_semantic_info,+SPV_INTEL_optnone"
// CHIPSTAR-XTOR-SAME: "--spirv-debug-info-version=nonsemantic-shader-200"
// CHIPSTAR-XTOR-SAME: [[LOWER_BC]] "-o" "{{.*img}}"
// Check unknown linker options are ignored - such as ones that are targeted at
// spirv-link. HIPSPV toolchain does linking via llvm-link.
// RUN: %clang -### --no-default-config -o %t.dummy.img \
@ -147,21 +123,33 @@
// RUN: | FileCheck -DVERSION=%llvm-version-major \
// RUN: --check-prefix=VERSIONED %s
// With -fno-integrated-objemitter the chipStar path must pick the same
// versioned translator (lookup shared with SPIRV::constructTranslateCommand).
// RUN: env "PATH=%t/versioned" %clang -### --no-default-config \
// RUN: -o %t.dummy.img --target=spirv64-unknown-chipstar %t.dummy.o \
// RUN: --hip-path="%S/Inputs/hipspv" -fno-integrated-objemitter 2>&1 \
// RUN: | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
// RUN: -o %t.dummy.img --target=spirv64-unknown-chipstar %t.dummy.o \
// RUN: --hip-path="%S/Inputs/hipspv" -o /dev/null 2>&1 \
// RUN: | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
//-----------------------------------------------------------------------------
// The debug-info flags are passed regardless of -g (covered by the
// CHIPSTAR-XTOR checks above): in RDC-mode links this job runs in a clang
// invoked by clang-linker-wrapper where the original -g is not visible, but
// debug info travels in the bitcode and the flags are no-ops without it.
// Check that -g preserves device debug info by requesting the
// NonSemantic.Shader.DebugInfo form (and the extension it depends on) from the
// translator, and that no debug flags are emitted without -g.
// RUN: %clang -### --no-default-config -g -o %t.dummy.img \
// RUN: --target=spirv64-unknown-chipstar %t.dummy.o \
// RUN: --hip-path="%S/Inputs/hipspv" -fno-integrated-objemitter \
// RUN: 2>&1 | FileCheck %s --check-prefix=CHIPSTAR-XTOR -DHIP_PATH=%S/Inputs/hipspv
// RUN: --hip-path="%S/Inputs/hipspv" \
// RUN: 2>&1 | FileCheck %s --check-prefix=DEBUG
// DEBUG: {{".*llvm-spirv"}} "--spirv-max-version=1.2"
// DEBUG-SAME: "--spirv-ext=-all,+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups"
// DEBUG-SAME: "--spirv-ext=+SPV_KHR_non_semantic_info,+SPV_INTEL_optnone"
// DEBUG-SAME: "--spirv-debug-info-version=nonsemantic-shader-200"
// RUN: %clang -### --no-default-config -o %t.dummy.img \
// RUN: --target=spirv64-unknown-chipstar %t.dummy.o \
// RUN: --hip-path="%S/Inputs/hipspv" \
// RUN: 2>&1 | FileCheck %s --check-prefix=NODEBUG
// NODEBUG: {{".*llvm-spirv"}}
// NODEBUG-NOT: SPV_KHR_non_semantic_info
// NODEBUG-NOT: SPV_INTEL_optnone
// NODEBUG-NOT: spirv-debug-info-version

View file

@ -91,8 +91,7 @@ SPIRVSubtarget::SPIRVSubtarget(const Triple &TT, const std::string &CPU,
if (TargetTriple.getOS() == Triple::Vulkan)
Env = Shader;
else if (TargetTriple.getOS() == Triple::OpenCL ||
TargetTriple.getVendor() == Triple::AMD ||
TargetTriple.getOS() == Triple::ChipStar)
TargetTriple.getVendor() == Triple::AMD)
Env = Kernel;
else
Env = Unknown;