================
@@ -5234,57 +5243,87 @@ Action *Driver::ConstructPhaseAction(
     return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC);
   }
   case phases::Backend: {
+    bool IsOffloadHIP = TargetDeviceOffloadKind == Action::OFK_HIP;
+    bool IsNewOffloadDriver =
+        Args.hasFlag(options::OPT_offload_new_driver,
+                     options::OPT_no_offload_new_driver, false);
     // Skip a redundant Backend phase for HIP device code when using the new
     // offload driver, where mid-end is done in linker wrapper.
-    if (TargetDeviceOffloadKind == Action::OFK_HIP &&
-        Args.hasFlag(options::OPT_offload_new_driver,
-                     options::OPT_no_offload_new_driver, false) &&
-        !offloadDeviceOnly())
+    if (IsOffloadHIP && IsNewOffloadDriver && !offloadDeviceOnly())
       return Input;
-
-    if (isUsingLTO() && TargetDeviceOffloadKind == Action::OFK_None) {
+    bool IsOffloadBuild = TargetDeviceOffloadKind != Action::OFK_None;
+    bool IsEmitLLVM = Args.hasArg(options::OPT_emit_llvm);
+    bool IsEmitAssembly = Args.hasArg(options::OPT_S);
+    if (isUsingLTO() && !IsOffloadBuild) {
       types::ID Output;
-      if (Args.hasArg(options::OPT_ffat_lto_objects) &&
-          !Args.hasArg(options::OPT_emit_llvm))
+      if (Args.hasArg(options::OPT_ffat_lto_objects) && !IsEmitLLVM)
         Output = types::TY_PP_Asm;
-      else if (Args.hasArg(options::OPT_S))
+      else if (IsEmitAssembly)
         Output = types::TY_LTO_IR;
       else
         Output = types::TY_LTO_BC;
       return C.MakeAction<BackendJobAction>(Input, Output);
     }
-    if (isUsingOffloadLTO() && TargetDeviceOffloadKind != Action::OFK_None) {
-      types::ID Output =
-          Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
+    if (isUsingOffloadLTO() && IsOffloadBuild) {
+      types::ID Output = IsEmitAssembly ? types::TY_LTO_IR : types::TY_LTO_BC;
       return C.MakeAction<BackendJobAction>(Input, Output);
     }
-    if (Args.hasArg(options::OPT_emit_llvm) ||
-        TargetDeviceOffloadKind == Action::OFK_SYCL ||
-        (((Input->getOffloadingToolChain() &&
-           Input->getOffloadingToolChain()->getTriple().isAMDGPU() &&
-           TargetDeviceOffloadKind != Action::OFK_None) ||
-          TargetDeviceOffloadKind == Action::OFK_HIP) &&
-         ((Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
-                        false) ||
-           (Args.hasFlag(options::OPT_offload_new_driver,
-                         options::OPT_no_offload_new_driver, false) &&
-            (!offloadDeviceOnly() ||
-             (Input->getOffloadingToolChain() &&
-              TargetDeviceOffloadKind == Action::OFK_HIP &&
-              Input->getOffloadingToolChain()->getTriple().isSPIRV())))) ||
-          TargetDeviceOffloadKind == Action::OFK_OpenMP))) {
+
+    bool IsOffloadSYCL = TargetDeviceOffloadKind == Action::OFK_SYCL;
----------------
mgcarrasco wrote:

Reviewing the changes from the commit link workarounds the diffing problem 
between the functional changes and the NFC refactoring. The link should also 
allow writing comments. I know this is not ideal, sorry about that.

I think that understanding the introduced changes without refactoring the 
affected if statement could be quite challenging. Rebasing would require some 
effort but merging the NFC doesn't introduce any breaking changes to those PRs.

https://github.com/llvm/llvm-project/pull/167543
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to