Skip to content

Commit a860c83

Browse files
authored
Revert "[clang][Driver] Support for the SPIR-V backend when compiling HIP (#167543)" (#169528)
This reverts commit 1a03673. Reverted due to a failure in hip-spirv-backend-opt.c for fuchsia-x86_64-linux.
1 parent 5017370 commit a860c83

File tree

7 files changed

+17
-293
lines changed

7 files changed

+17
-293
lines changed

clang/include/clang/Options/Options.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,16 +1427,6 @@ def fhip_emit_relocatable : Flag<["-"], "fhip-emit-relocatable">,
14271427
HelpText<"Compile HIP source to relocatable">;
14281428
def fno_hip_emit_relocatable : Flag<["-"], "fno-hip-emit-relocatable">,
14291429
HelpText<"Do not override toolchain to compile HIP source to relocatable">;
1430-
def use_spirv_backend
1431-
: Flag<["-"], "use-spirv-backend">,
1432-
Group<hip_Group>,
1433-
Flags<[HelpHidden]>,
1434-
HelpText<"Use the SPIRV backend for compilation ">;
1435-
def no_use_spirv_backend
1436-
: Flag<["-"], "no-use-spirv-backend">,
1437-
Group<hip_Group>,
1438-
Flags<[HelpHidden]>,
1439-
HelpText<"Do not use the SPIRV backend for compilation ">;
14401430
}
14411431

14421432
// Clang specific/exclusive options for OpenACC.

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5024,24 +5024,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50245024
// Compiling HIP in device-only non-RDC mode requires linking each action
50255025
// individually.
50265026
for (Action *&A : DeviceActions) {
5027+
// Special handling for the HIP SPIR-V toolchain because it doesn't use
5028+
// the SPIR-V backend yet doesn't report the output as an object.
50275029
bool IsAMDGCNSPIRV = A->getOffloadingToolChain() &&
50285030
A->getOffloadingToolChain()->getTriple().getOS() ==
50295031
llvm::Triple::OSType::AMDHSA &&
50305032
A->getOffloadingToolChain()->getTriple().isSPIRV();
5031-
bool UseSPIRVBackend = Args.hasFlag(options::OPT_use_spirv_backend,
5032-
options::OPT_no_use_spirv_backend,
5033-
/*Default=*/false);
5034-
5035-
// Special handling for the HIP SPIR-V toolchain in device-only.
5036-
// The translator path has a linking step, whereas the SPIR-V backend path
5037-
// does not to avoid any external dependency such as spirv-link. The
5038-
// linking step is skipped for the SPIR-V backend path.
5039-
bool IsAMDGCNSPIRVWithBackend = IsAMDGCNSPIRV && UseSPIRVBackend;
5040-
50415033
if ((A->getType() != types::TY_Object && !IsAMDGCNSPIRV &&
50425034
A->getType() != types::TY_LTO_BC) ||
5043-
HIPRelocatableObj || !HIPNoRDC || !offloadDeviceOnly() ||
5044-
(IsAMDGCNSPIRVWithBackend && offloadDeviceOnly()))
5035+
HIPRelocatableObj || !HIPNoRDC || !offloadDeviceOnly())
50455036
continue;
50465037
ActionList LinkerInput = {A};
50475038
A = C.MakeAction<LinkJobAction>(LinkerInput, types::TY_Image);
@@ -5267,28 +5258,12 @@ Action *Driver::ConstructPhaseAction(
52675258
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
52685259
return C.MakeAction<BackendJobAction>(Input, Output);
52695260
}
5270-
bool UseSPIRVBackend = Args.hasFlag(options::OPT_use_spirv_backend,
5271-
options::OPT_no_use_spirv_backend,
5272-
/*Default=*/false);
5273-
5274-
auto OffloadingToolChain = Input->getOffloadingToolChain();
5275-
// For AMD SPIRV, if offloadDeviceOnly(), we call the SPIRV backend unless
5276-
// LLVM bitcode was requested explicitly or RDC is set. If
5277-
// !offloadDeviceOnly, we emit LLVM bitcode, and clang-linker-wrapper will
5278-
// compile it to SPIRV.
5279-
bool UseSPIRVBackendForHipDeviceOnlyNoRDC =
5280-
TargetDeviceOffloadKind == Action::OFK_HIP && OffloadingToolChain &&
5281-
OffloadingToolChain->getTriple().isSPIRV() && UseSPIRVBackend &&
5282-
offloadDeviceOnly() &&
5283-
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
5284-
52855261
if (Args.hasArg(options::OPT_emit_llvm) ||
52865262
TargetDeviceOffloadKind == Action::OFK_SYCL ||
52875263
(((Input->getOffloadingToolChain() &&
52885264
Input->getOffloadingToolChain()->getTriple().isAMDGPU() &&
52895265
TargetDeviceOffloadKind != Action::OFK_None) ||
52905266
TargetDeviceOffloadKind == Action::OFK_HIP) &&
5291-
!UseSPIRVBackendForHipDeviceOnlyNoRDC &&
52925267
((Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
52935268
false) ||
52945269
(Args.hasFlag(options::OPT_offload_new_driver,
@@ -5310,19 +5285,6 @@ Action *Driver::ConstructPhaseAction(
53105285
: types::TY_LLVM_BC;
53115286
return C.MakeAction<BackendJobAction>(Input, Output);
53125287
}
5313-
5314-
// The SPIRV backend compilation path for HIP must avoid external
5315-
// dependencies. The default compilation path assembles and links its
5316-
// output, but the SPIRV assembler and linker are external tools. This code
5317-
// ensures the backend emits binary SPIRV directly to bypass those steps and
5318-
// avoid failures. Without -save-temps, the compiler may already skip
5319-
// assembling and linking. With -save-temps, these steps must be explicitly
5320-
// disabled, as done here. We also force skipping these steps regardless of
5321-
// -save-temps to avoid relying on optimizations (unless -S is set).
5322-
// The current HIP bundling expects the type to be types::TY_Image
5323-
if (UseSPIRVBackendForHipDeviceOnlyNoRDC && !Args.hasArg(options::OPT_S))
5324-
return C.MakeAction<BackendJobAction>(Input, types::TY_Image);
5325-
53265288
return C.MakeAction<BackendJobAction>(Input, types::TY_PP_Asm);
53275289
}
53285290
case phases::Assemble:

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5057,10 +5057,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
50575057
Args.ClaimAllArgs(options::OPT_femit_dwarf_unwind_EQ);
50585058
}
50595059

5060-
bool IsAMDSPIRVForHIPDevice =
5061-
IsHIPDevice && getToolChain().getTriple().isSPIRV() &&
5062-
getToolChain().getTriple().getVendor() == llvm::Triple::AMD;
5063-
50645060
if (isa<AnalyzeJobAction>(JA)) {
50655061
assert(JA.getType() == types::TY_Plist && "Invalid output type.");
50665062
CmdArgs.push_back("-analyze");
@@ -5158,8 +5154,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51585154
rewriteKind = RK_Fragile;
51595155
} else if (JA.getType() == types::TY_CIR) {
51605156
CmdArgs.push_back("-emit-cir");
5161-
} else if (JA.getType() == types::TY_Image && IsAMDSPIRVForHIPDevice) {
5162-
CmdArgs.push_back("-emit-obj");
51635157
} else {
51645158
assert(JA.getType() == types::TY_PP_Asm && "Unexpected output type!");
51655159
}
@@ -9090,9 +9084,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
90909084
OPT_fno_lto,
90919085
OPT_flto,
90929086
OPT_flto_partitions_EQ,
9093-
OPT_flto_EQ,
9094-
OPT_use_spirv_backend};
9095-
9087+
OPT_flto_EQ};
90969088
const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
90979089
auto ShouldForwardForToolChain = [&](Arg *A, const ToolChain &TC) {
90989090
// Don't forward -mllvm to toolchains that don't support LLVM.

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
159159

160160
// For SPIR-V the inputs for the job are device AMDGCN SPIR-V flavoured bitcode
161161
// and the output is either a compiled SPIR-V binary or bitcode (-emit-llvm). It
162-
// calls llvm-link and then the llvm-spirv translator or the SPIR-V BE.
163-
// TODO: consider if we want to run any targeted optimisations over IR here,
164-
// over generic SPIR-V.
162+
// calls llvm-link and then the llvm-spirv translator. Once the SPIR-V BE will
163+
// be promoted from experimental, we will switch to using that. TODO: consider
164+
// if we want to run any targeted optimisations over IR here, over generic
165+
// SPIR-V.
165166
void AMDGCN::Linker::constructLinkAndEmitSpirvCommand(
166167
Compilation &C, const JobAction &JA, const InputInfoList &Inputs,
167168
const InputInfo &Output, const llvm::opt::ArgList &Args) const {
@@ -172,40 +173,17 @@ void AMDGCN::Linker::constructLinkAndEmitSpirvCommand(
172173
const char *LinkedBCFilePath = HIP::getTempFile(C, LinkedBCFilePrefix, "bc");
173174
InputInfo LinkedBCFile(&JA, LinkedBCFilePath, Output.getBaseInput());
174175

175-
bool UseSPIRVBackend =
176-
Args.hasFlag(options::OPT_use_spirv_backend,
177-
options::OPT_no_use_spirv_backend, /*Default=*/false);
178-
179176
constructLlvmLinkCommand(C, JA, Inputs, LinkedBCFile, Args);
180177

181-
if (UseSPIRVBackend) {
182-
// This code handles the case in the new driver when --offload-device-only
183-
// is unset and clang-linker-wrapper forwards the bitcode that must be
184-
// compiled to SPIR-V.
185-
186-
llvm::opt::ArgStringList CmdArgs;
187-
const char *Triple =
188-
C.getArgs().MakeArgString("-triple=spirv64-amd-amdhsa");
189-
190-
CmdArgs.append({"-cc1", Triple, "-emit-obj", "-disable-llvm-optzns",
191-
LinkedBCFile.getFilename(), "-o", Output.getFilename()});
192-
193-
const char *Exec = getToolChain().getDriver().getClangProgramPath();
194-
C.addCommand(std::make_unique<Command>(JA, *this,
195-
ResponseFileSupport::None(), Exec,
196-
CmdArgs, LinkedBCFile, Output));
197-
} else {
198-
// Emit SPIR-V binary using the translator
199-
llvm::opt::ArgStringList TrArgs{
200-
"--spirv-max-version=1.6",
201-
"--spirv-ext=+all",
202-
"--spirv-allow-unknown-intrinsics",
203-
"--spirv-lower-const-expr",
204-
"--spirv-preserve-auxdata",
205-
"--spirv-debug-info-version=nonsemantic-shader-200"};
206-
SPIRV::constructTranslateCommand(C, *this, JA, Output, LinkedBCFile,
207-
TrArgs);
208-
}
178+
// Emit SPIR-V binary.
179+
llvm::opt::ArgStringList TrArgs{
180+
"--spirv-max-version=1.6",
181+
"--spirv-ext=+all",
182+
"--spirv-allow-unknown-intrinsics",
183+
"--spirv-lower-const-expr",
184+
"--spirv-preserve-auxdata",
185+
"--spirv-debug-info-version=nonsemantic-shader-200"};
186+
SPIRV::constructTranslateCommand(C, *this, JA, Output, LinkedBCFile, TrArgs);
209187
}
210188

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

clang/test/Driver/hip-spirv-backend-bindings.c

Lines changed: 0 additions & 57 deletions
This file was deleted.

clang/test/Driver/hip-spirv-backend-opt.c

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)