Skip to content

Commit e1fb519

Browse files
committed
[NFC][clang][driver] Improve readability of long and complex if statement
1 parent 3d5d32c commit e1fb519

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5191,50 +5191,55 @@ Action *Driver::ConstructPhaseAction(
51915191
return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC);
51925192
}
51935193
case phases::Backend: {
5194+
bool IsOffloadHIP = TargetDeviceOffloadKind == Action::OFK_HIP;
5195+
bool IsNewOffloadDriver =
5196+
Args.hasFlag(options::OPT_offload_new_driver,
5197+
options::OPT_no_offload_new_driver, false);
51945198
// Skip a redundant Backend phase for HIP device code when using the new
51955199
// offload driver, where mid-end is done in linker wrapper.
5196-
if (TargetDeviceOffloadKind == Action::OFK_HIP &&
5197-
Args.hasFlag(options::OPT_offload_new_driver,
5198-
options::OPT_no_offload_new_driver, false) &&
5199-
!offloadDeviceOnly())
5200+
if (IsOffloadHIP && IsNewOffloadDriver && !offloadDeviceOnly())
52005201
return Input;
5201-
5202-
if (isUsingLTO() && TargetDeviceOffloadKind == Action::OFK_None) {
5202+
bool IsOffloadBuild = TargetDeviceOffloadKind != Action::OFK_None;
5203+
bool IsEmitLLVM = Args.hasArg(options::OPT_emit_llvm);
5204+
bool IsEmitAssembly = Args.hasArg(options::OPT_S);
5205+
if (isUsingLTO() && !IsOffloadBuild) {
52035206
types::ID Output;
5204-
if (Args.hasArg(options::OPT_ffat_lto_objects) &&
5205-
!Args.hasArg(options::OPT_emit_llvm))
5207+
if (Args.hasArg(options::OPT_ffat_lto_objects) && !IsEmitLLVM)
52065208
Output = types::TY_PP_Asm;
5207-
else if (Args.hasArg(options::OPT_S))
5209+
else if (IsEmitAssembly)
52085210
Output = types::TY_LTO_IR;
52095211
else
52105212
Output = types::TY_LTO_BC;
52115213
return C.MakeAction<BackendJobAction>(Input, Output);
52125214
}
5213-
if (isUsingOffloadLTO() && TargetDeviceOffloadKind != Action::OFK_None) {
5214-
types::ID Output =
5215-
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
5215+
if (isUsingOffloadLTO() && IsOffloadBuild) {
5216+
types::ID Output = IsEmitAssembly ? types::TY_LTO_IR : types::TY_LTO_BC;
52165217
return C.MakeAction<BackendJobAction>(Input, Output);
52175218
}
5218-
if (Args.hasArg(options::OPT_emit_llvm) ||
5219-
TargetDeviceOffloadKind == Action::OFK_SYCL ||
5220-
(((Input->getOffloadingToolChain() &&
5221-
Input->getOffloadingToolChain()->getTriple().isAMDGPU() &&
5222-
TargetDeviceOffloadKind != Action::OFK_None) ||
5223-
TargetDeviceOffloadKind == Action::OFK_HIP) &&
5224-
((Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
5225-
false) ||
5226-
(Args.hasFlag(options::OPT_offload_new_driver,
5227-
options::OPT_no_offload_new_driver, false) &&
5228-
(!offloadDeviceOnly() ||
5229-
(Input->getOffloadingToolChain() &&
5230-
TargetDeviceOffloadKind == Action::OFK_HIP &&
5231-
Input->getOffloadingToolChain()->getTriple().isSPIRV())))) ||
5232-
TargetDeviceOffloadKind == Action::OFK_OpenMP))) {
5219+
5220+
bool IsOffloadSYCL = TargetDeviceOffloadKind == Action::OFK_SYCL;
5221+
auto OffloadingToolChain = Input->getOffloadingToolChain();
5222+
bool IsOffloadAMDGPU = OffloadingToolChain &&
5223+
OffloadingToolChain->getTriple().isAMDGPU() &&
5224+
IsOffloadBuild;
5225+
bool IsRDC =
5226+
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
5227+
bool IsSPIRV =
5228+
OffloadingToolChain && OffloadingToolChain->getTriple().isSPIRV();
5229+
bool IsOffloadOpenMP = TargetDeviceOffloadKind == Action::OFK_OpenMP;
5230+
5231+
bool IsLLVMBitcodeOutput =
5232+
IsEmitLLVM || IsOffloadSYCL ||
5233+
((IsOffloadAMDGPU || IsOffloadHIP) &&
5234+
((IsRDC || (IsNewOffloadDriver &&
5235+
(!offloadDeviceOnly() || (IsOffloadHIP && IsSPIRV)))) ||
5236+
IsOffloadOpenMP));
5237+
5238+
if (IsLLVMBitcodeOutput) {
52335239
types::ID Output =
5234-
Args.hasArg(options::OPT_S) &&
5235-
(TargetDeviceOffloadKind == Action::OFK_None ||
5236-
offloadDeviceOnly() ||
5237-
(TargetDeviceOffloadKind == Action::OFK_HIP &&
5240+
IsEmitAssembly &&
5241+
(!IsOffloadBuild || offloadDeviceOnly() ||
5242+
(IsOffloadHIP &&
52385243
!Args.hasFlag(options::OPT_offload_new_driver,
52395244
options::OPT_no_offload_new_driver,
52405245
C.isOffloadingHostKind(Action::OFK_Cuda))))

0 commit comments

Comments
 (0)