Skip to content

Commit 86491a8

Browse files
committed
Revert "[NFC][clang][driver] Improve readability of long and complex if statement" while keeping the required underlying functional changes.
1 parent 46bd79c commit 86491a8

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5243,66 +5243,66 @@ Action *Driver::ConstructPhaseAction(
52435243
return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC);
52445244
}
52455245
case phases::Backend: {
5246-
bool IsOffloadHIP = TargetDeviceOffloadKind == Action::OFK_HIP;
5247-
bool IsNewOffloadDriver =
5248-
Args.hasFlag(options::OPT_offload_new_driver,
5249-
options::OPT_no_offload_new_driver, false);
52505246
// Skip a redundant Backend phase for HIP device code when using the new
52515247
// offload driver, where mid-end is done in linker wrapper.
5252-
if (IsOffloadHIP && IsNewOffloadDriver && !offloadDeviceOnly())
5248+
if (TargetDeviceOffloadKind == Action::OFK_HIP &&
5249+
Args.hasFlag(options::OPT_offload_new_driver,
5250+
options::OPT_no_offload_new_driver, false) &&
5251+
!offloadDeviceOnly())
52535252
return Input;
5254-
bool IsOffloadBuild = TargetDeviceOffloadKind != Action::OFK_None;
5255-
bool IsEmitLLVM = Args.hasArg(options::OPT_emit_llvm);
5256-
bool IsEmitAssembly = Args.hasArg(options::OPT_S);
5257-
if (isUsingLTO() && !IsOffloadBuild) {
5253+
5254+
if (isUsingLTO() && TargetDeviceOffloadKind == Action::OFK_None) {
52585255
types::ID Output;
5259-
if (Args.hasArg(options::OPT_ffat_lto_objects) && !IsEmitLLVM)
5256+
if (Args.hasArg(options::OPT_ffat_lto_objects) &&
5257+
!Args.hasArg(options::OPT_emit_llvm))
52605258
Output = types::TY_PP_Asm;
5261-
else if (IsEmitAssembly)
5259+
else if (Args.hasArg(options::OPT_S))
52625260
Output = types::TY_LTO_IR;
52635261
else
52645262
Output = types::TY_LTO_BC;
52655263
return C.MakeAction<BackendJobAction>(Input, Output);
52665264
}
5267-
if (isUsingOffloadLTO() && IsOffloadBuild) {
5268-
types::ID Output = IsEmitAssembly ? types::TY_LTO_IR : types::TY_LTO_BC;
5265+
if (isUsingOffloadLTO() && TargetDeviceOffloadKind != Action::OFK_None) {
5266+
types::ID Output =
5267+
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
52695268
return C.MakeAction<BackendJobAction>(Input, Output);
52705269
}
5271-
5272-
bool IsOffloadSYCL = TargetDeviceOffloadKind == Action::OFK_SYCL;
5273-
auto OffloadingToolChain = Input->getOffloadingToolChain();
5274-
bool IsOffloadAMDGPU = OffloadingToolChain &&
5275-
OffloadingToolChain->getTriple().isAMDGPU() &&
5276-
IsOffloadBuild;
5277-
bool IsRDC =
5278-
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
5279-
bool IsSPIRV =
5280-
OffloadingToolChain && OffloadingToolChain->getTriple().isSPIRV();
5281-
bool IsOffloadOpenMP = TargetDeviceOffloadKind == Action::OFK_OpenMP;
5282-
5283-
bool IsHIP = TargetDeviceOffloadKind == Action::OFK_HIP;
52845270
bool UseSPIRVBackend = Args.hasFlag(options::OPT_use_spirv_backend,
52855271
options::OPT_no_use_spirv_backend,
52865272
/*Default=*/false);
5287-
// If offloadDeviceOnly(), we call the SPIRV backend unless LLVM bitcode was
5288-
// requested explicitly or RDC is set. If !offloadDeviceOnly, we emit LLVM
5289-
// bitcode, and clang-linker-wrapper will compile it to SPIRV.
5290-
bool UseSPIRVBackendForHipDeviceOnlyNoRDC =
5291-
IsHIP && IsSPIRV && UseSPIRVBackend && offloadDeviceOnly() && !IsRDC;
5292-
5293-
bool IsLLVMBitcodeOutput =
5294-
IsEmitLLVM || IsOffloadSYCL ||
5295-
((IsOffloadAMDGPU || IsOffloadHIP) &&
5296-
!UseSPIRVBackendForHipDeviceOnlyNoRDC &&
5297-
((IsRDC || (IsNewOffloadDriver &&
5298-
(!offloadDeviceOnly() || (IsOffloadHIP && IsSPIRV)))) ||
5299-
IsOffloadOpenMP));
53005273

5301-
if (IsLLVMBitcodeOutput) {
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+
5285+
if (Args.hasArg(options::OPT_emit_llvm) ||
5286+
TargetDeviceOffloadKind == Action::OFK_SYCL ||
5287+
(((Input->getOffloadingToolChain() &&
5288+
Input->getOffloadingToolChain()->getTriple().isAMDGPU() &&
5289+
TargetDeviceOffloadKind != Action::OFK_None) ||
5290+
TargetDeviceOffloadKind == Action::OFK_HIP) &&
5291+
UseSPIRVBackendForHipDeviceOnlyNoRDC &&
5292+
((Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
5293+
false) ||
5294+
(Args.hasFlag(options::OPT_offload_new_driver,
5295+
options::OPT_no_offload_new_driver, false) &&
5296+
(!offloadDeviceOnly() ||
5297+
(Input->getOffloadingToolChain() &&
5298+
TargetDeviceOffloadKind == Action::OFK_HIP &&
5299+
Input->getOffloadingToolChain()->getTriple().isSPIRV())))) ||
5300+
TargetDeviceOffloadKind == Action::OFK_OpenMP))) {
53025301
types::ID Output =
5303-
IsEmitAssembly &&
5304-
(!IsOffloadBuild || offloadDeviceOnly() ||
5305-
(IsOffloadHIP &&
5302+
Args.hasArg(options::OPT_S) &&
5303+
(TargetDeviceOffloadKind == Action::OFK_None ||
5304+
offloadDeviceOnly() ||
5305+
(TargetDeviceOffloadKind == Action::OFK_HIP &&
53065306
!Args.hasFlag(options::OPT_offload_new_driver,
53075307
options::OPT_no_offload_new_driver,
53085308
C.isOffloadingHostKind(Action::OFK_Cuda))))

0 commit comments

Comments
 (0)