jhuber6 created this revision. jhuber6 added reviewers: jdoerfert, tianshilei1992, wsmoses. Herald added subscribers: guansong, yaxunl. Herald added a project: All. jhuber6 requested review of this revision. Herald added subscribers: cfe-commits, sstefan1, MaskRay. Herald added a project: clang.
The Clang driver additional stages to build a complete offloading program for applications using CUDA or OpenMP offloading. This normally requires either a source file input or a valid object file to be handled. This would cause problems when trying to compile an assembly or LLVM IR file through clang with flags that would enable offloading. This patch simply adds a check to prevent the offloading toolchain from being used if we don't have a valid source file. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D125705 Files: clang/lib/Driver/Driver.cpp clang/test/Driver/openmp-offload-gpu-new.c Index: clang/test/Driver/openmp-offload-gpu-new.c =================================================================== --- clang/test/Driver/openmp-offload-gpu-new.c +++ clang/test/Driver/openmp-offload-gpu-new.c @@ -70,6 +70,11 @@ // CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.+]]" // CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[HOST_OBJ]]"], output: "a.out" +// RUN: %clang -x ir -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp --offload-arch=sm_52 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-IR + +// CHECK-IR: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT_IR:.+]]"], output: "[[OBJECT:.+]]" +// CHECK-IR: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[OBJECT]]"], output: "a.out" + // RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target=nvptx64-nvidia-cuda -march=sm_52 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR // CHECK-EMIT-LLVM-IR: "-cc1"{{.*}}"-triple" "nvptx64-nvidia-cuda"{{.*}}"-emit-llvm" Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4377,9 +4377,11 @@ Mode && Mode->getOption().matches(options::OPT_offload_device_only); // Don't build offloading actions if explicitly disabled or we do not have a - // compile action to embed it in. If preprocessing only ignore embedding. - if (HostOnly || !(isa<CompileJobAction>(HostAction) || - getFinalPhase(Args) == phases::Preprocess)) + // valid source input and compile action to embed it in. If preprocessing only + // ignore embedding. + if (HostOnly || !types::isSrcFile(Input.first) || + !(isa<CompileJobAction>(HostAction) || + getFinalPhase(Args) == phases::Preprocess)) return HostAction; ActionList OffloadActions;
Index: clang/test/Driver/openmp-offload-gpu-new.c =================================================================== --- clang/test/Driver/openmp-offload-gpu-new.c +++ clang/test/Driver/openmp-offload-gpu-new.c @@ -70,6 +70,11 @@ // CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.+]]" // CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[HOST_OBJ]]"], output: "a.out" +// RUN: %clang -x ir -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp --offload-arch=sm_52 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-IR + +// CHECK-IR: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT_IR:.+]]"], output: "[[OBJECT:.+]]" +// CHECK-IR: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[OBJECT]]"], output: "a.out" + // RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target=nvptx64-nvidia-cuda -march=sm_52 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR // CHECK-EMIT-LLVM-IR: "-cc1"{{.*}}"-triple" "nvptx64-nvidia-cuda"{{.*}}"-emit-llvm" Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4377,9 +4377,11 @@ Mode && Mode->getOption().matches(options::OPT_offload_device_only); // Don't build offloading actions if explicitly disabled or we do not have a - // compile action to embed it in. If preprocessing only ignore embedding. - if (HostOnly || !(isa<CompileJobAction>(HostAction) || - getFinalPhase(Args) == phases::Preprocess)) + // valid source input and compile action to embed it in. If preprocessing only + // ignore embedding. + if (HostOnly || !types::isSrcFile(Input.first) || + !(isa<CompileJobAction>(HostAction) || + getFinalPhase(Args) == phases::Preprocess)) return HostAction; ActionList OffloadActions;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits