jhuber6 created this revision. jhuber6 added reviewers: jdoerfert, JonChesterfield, tra, yaxunl, tianshilei1992, MaskRay. Herald added a subscriber: StephenFan. Herald added a project: All. jhuber6 requested review of this revision. Herald added subscribers: cfe-commits, sstefan1. Herald added a project: clang.
The "new" driver embeds metadata along with the compiled device image to be used by the linking phase. One bit of metadata is the "kind" field which determines which runtime to generate registration code for once it's linked. E.g. if it was compiled with OpenMP it should be registered with the OpenMP runtime. However, in a freestanding build the implication is that there may not be a standard runtime and instead we should expect it to be handled externally. This patch causes the `-ffreestanding` option to set the value to `None` which results in no registration code being created. This is useful for generating pure GPU libraries using the offloading tools. E.g. we can build a `libc` with OpenMP tooling and link it with `CUDA` without requiring the OpenMP runtime be linked. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138862 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/openmp-offload.c Index: clang/test/Driver/openmp-offload.c =================================================================== --- clang/test/Driver/openmp-offload.c +++ clang/test/Driver/openmp-offload.c @@ -206,3 +206,13 @@ // RUN: -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHK-SYNTAX-ONLY-ARGS %s // CHK-SYNTAX-ONLY-ARGS: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu"{{.*}}"-fsyntax-only" // CHK-SYNTAX-ONLY-ARGS: "-cc1" "-triple" "powerpc64le-unknown-linux"{{.*}}"-fsyntax-only" + +// +// Ensure that we do not set the kind in a freestanding offloading build. +// +// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \ +// RUN: -ffreestanding %s 2>&1 | FileCheck -check-prefix=FREESTANDING %s +// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \ +// RUN: -Xopenmp-target=powerpc64le-ibm-linux-gnu -ffreestanding %s 2>&1 | FileCheck -check-prefix=FREESTANDING %s +// FREESTANDING: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le-unknown-linux"{{.*}}"-ffreestanding" +// FREESTANDING: clang-offload-packager"{{.*}}"--image=file={{.*}},triple=powerpc64le-ibm-linux-gnu,arch=,kind=none" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -8354,8 +8354,10 @@ StringRef Arch = (OffloadAction->getOffloadingArch()) ? OffloadAction->getOffloadingArch() : TCArgs.getLastArgValue(options::OPT_march_EQ); - StringRef Kind = - Action::GetOffloadKindName(OffloadAction->getOffloadingDeviceKind()); + StringRef Kind = TCArgs.hasArg(options::OPT_ffreestanding) + ? "none" + : Action::GetOffloadKindName( + OffloadAction->getOffloadingDeviceKind()); ArgStringList Features; SmallVector<StringRef> FeatureArgs;
Index: clang/test/Driver/openmp-offload.c =================================================================== --- clang/test/Driver/openmp-offload.c +++ clang/test/Driver/openmp-offload.c @@ -206,3 +206,13 @@ // RUN: -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHK-SYNTAX-ONLY-ARGS %s // CHK-SYNTAX-ONLY-ARGS: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu"{{.*}}"-fsyntax-only" // CHK-SYNTAX-ONLY-ARGS: "-cc1" "-triple" "powerpc64le-unknown-linux"{{.*}}"-fsyntax-only" + +// +// Ensure that we do not set the kind in a freestanding offloading build. +// +// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \ +// RUN: -ffreestanding %s 2>&1 | FileCheck -check-prefix=FREESTANDING %s +// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \ +// RUN: -Xopenmp-target=powerpc64le-ibm-linux-gnu -ffreestanding %s 2>&1 | FileCheck -check-prefix=FREESTANDING %s +// FREESTANDING: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le-unknown-linux"{{.*}}"-ffreestanding" +// FREESTANDING: clang-offload-packager"{{.*}}"--image=file={{.*}},triple=powerpc64le-ibm-linux-gnu,arch=,kind=none" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -8354,8 +8354,10 @@ StringRef Arch = (OffloadAction->getOffloadingArch()) ? OffloadAction->getOffloadingArch() : TCArgs.getLastArgValue(options::OPT_march_EQ); - StringRef Kind = - Action::GetOffloadKindName(OffloadAction->getOffloadingDeviceKind()); + StringRef Kind = TCArgs.hasArg(options::OPT_ffreestanding) + ? "none" + : Action::GetOffloadKindName( + OffloadAction->getOffloadingDeviceKind()); ArgStringList Features; SmallVector<StringRef> FeatureArgs;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits