[PATCH] D100598: [CUDA, FDO] Filter out profiling options from GPU-side compilations.
Artem Belevich via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 15 13:54:56 PDT 2021
tra created this revision.
tra added reviewers: yaxunl, tejohnson.
Herald added subscribers: wenlei, bixia.
tra requested review of this revision.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100598
Files:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c
Index: clang/test/Driver/clang_f_opts.c
===================================================================
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -58,6 +58,19 @@
// RUN: %clang -### -S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s
// CHECK-SAMPLE-PROFILE: "-fprofile-sample-use={{.*}}/file.prof"
+//
+// RUN: %clang -### -x cuda -nocudainc -nocudalib \
+// RUN: -c -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-CUDA-SAMPLE-PROFILE %s
+// -fprofile-sample-use should not be passed to the GPU compilation
+// CHECK-CUDA-SAMPLE-PROFILE: "-cc1"
+// CHECK-CUDA-SAMPLE-PROFILE-SAME: "-triple" "nvptx
+// CHECK-CUDA-SAMPLE-PROFILE-NOT: "-fprofile-sample-use={{.*}}/file.prof"
+// Host compilation should still have the option.
+// CHECK-CUDA-SAMPLE-PROFILE: "-cc1"
+// CHECK-CUDA-SAMPLE-PROFILE-SAME: "-fprofile-sample-use={{.*}}/file.prof"
+
+
// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s
// CHECK-AUTO-PROFILE: "-fprofile-sample-use={{.*}}/file.prof"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4159,7 +4159,9 @@
// include as part of the module. All other jobs are expected to have exactly
// one input.
bool IsCuda = JA.isOffloading(Action::OFK_Cuda);
+ bool IsCudaDevice = JA.isDeviceOffloading(Action::OFK_Cuda);
bool IsHIP = JA.isOffloading(Action::OFK_HIP);
+ bool IsHIPDevice = JA.isDeviceOffloading(Action::OFK_HIP);
bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
bool IsHeaderModulePrecompile = isa<HeaderModulePrecompileJobAction>(JA);
@@ -5003,8 +5005,7 @@
// Prepare `-aux-target-cpu` and `-aux-target-feature` unless
// `--gpu-use-aux-triple-only` is specified.
if (!Args.getLastArg(options::OPT_gpu_use_aux_triple_only) &&
- ((IsCuda && JA.isDeviceOffloading(Action::OFK_Cuda)) ||
- (IsHIP && JA.isDeviceOffloading(Action::OFK_HIP)))) {
+ (IsCudaDevice || IsHIPDevice)) {
const ArgList &HostArgs =
C.getArgsForToolChain(nullptr, StringRef(), Action::OFK_None);
std::string HostCPU =
@@ -5826,27 +5827,29 @@
// Forward -f options with positive and negative forms; we translate
// these by hand.
- if (Arg *A = getLastProfileSampleUseArg(Args)) {
- auto *PGOArg = Args.getLastArg(
- options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ,
- options::OPT_fcs_profile_generate, options::OPT_fcs_profile_generate_EQ,
- options::OPT_fprofile_use, options::OPT_fprofile_use_EQ);
- if (PGOArg)
- D.Diag(diag::err_drv_argument_not_allowed_with)
- << "SampleUse with PGO options";
+ if (!IsCudaDevice) {
+ if (Arg *A = getLastProfileSampleUseArg(Args)) {
+ auto *PGOArg = Args.getLastArg(
+ options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ,
+ options::OPT_fcs_profile_generate,
+ options::OPT_fcs_profile_generate_EQ, options::OPT_fprofile_use,
+ options::OPT_fprofile_use_EQ);
+ if (PGOArg)
+ D.Diag(diag::err_drv_argument_not_allowed_with)
+ << "SampleUse with PGO options";
- StringRef fname = A->getValue();
- if (!llvm::sys::fs::exists(fname))
- D.Diag(diag::err_drv_no_such_file) << fname;
- else
- A->render(Args, CmdArgs);
+ StringRef fname = A->getValue();
+ if (!llvm::sys::fs::exists(fname))
+ D.Diag(diag::err_drv_no_such_file) << fname;
+ else
+ A->render(Args, CmdArgs);
+ }
+ Args.AddLastArg(CmdArgs, options::OPT_fprofile_remapping_file_EQ);
+
+ if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+ options::OPT_fno_pseudo_probe_for_profiling, false))
+ CmdArgs.push_back("-fpseudo-probe-for-profiling");
}
- Args.AddLastArg(CmdArgs, options::OPT_fprofile_remapping_file_EQ);
-
- if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
- options::OPT_fno_pseudo_probe_for_profiling, false))
- CmdArgs.push_back("-fpseudo-probe-for-profiling");
-
RenderBuiltinOptions(TC, RawTriple, Args, CmdArgs);
if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100598.337891.patch
Type: text/x-patch
Size: 4407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210415/34e054f4/attachment-0001.bin>
More information about the cfe-commits
mailing list