[PATCH] D68587: [hip] Assume host-only compilation if the final phase is ahead of `backend`.

Michael Liao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 7 12:25:25 PDT 2019


hliao created this revision.
hliao added reviewers: tra, yaxunl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- There are several scenarios where the compilation needs stopping before `backend`, such as `-E`, `-fsyntax-ony`, and even more if developers want to diagnose outputs from different phases. Under these cases, the offload bundler is not yet required or not valid to run as the output from the device-side compilation is not ready yet. As the result, it's assumed that, if the final phase is ahead of `backend`, these compilations are host only. If developers need the corresponding outputs for those phases from the device-side one, `--cuda-device-only` needs specifying to the compiler.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68587

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/hip-pre-backend-phases.hip


Index: clang/test/Driver/hip-pre-backend-phases.hip
===================================================================
--- /dev/null
+++ clang/test/Driver/hip-pre-backend-phases.hip
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -M %s 2>&1 | FileCheck %s
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -E %s 2>&1 | FileCheck %s
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -fsyntax-only %s 2>&1 | FileCheck %s
+
+// CHECK-NOT: clang{{.*}}" "-cc1" {{.*}} "-fcuda-is-device"
+// CHECK: clang{{.*}}" "-cc1" "-triple" "x86_64"
+// CHECK-NOT: clang-offload-bundler"
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2661,6 +2661,13 @@
     getDeviceDependences(OffloadAction::DeviceDependences &DA,
                          phases::ID CurPhase, phases::ID FinalPhase,
                          PhasesTy &Phases) override {
+      // If the final phase won't be able to generate the output bundling both
+      // device and host objects, it assumes such usage are host only unless
+      // device only compilation option is specified.
+      if (!CompileDeviceOnly && FinalPhase < phases::Backend) {
+        CudaDeviceActions.clear();
+        return ABRT_Inactive;
+      }
       // amdgcn does not support linking of object files, therefore we skip
       // backend and assemble phases to output LLVM IR. Except for generating
       // non-relocatable device coee, where we generate fat binary for device


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68587.223636.patch
Type: text/x-patch
Size: 1671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191007/d936fade/attachment.bin>


More information about the cfe-commits mailing list