From 845442e018c91327a550c7df3b0c61dd9d83547c Mon Sep 17 00:00:00 2001 From: Dehao Chen Date: Tue, 21 Mar 2017 21:40:53 +0000 Subject: [PATCH] Add support for -fno-auto-profile and -fno-profile-sample-use Summary: We need to be able to disable samplepgo for specific files by supporting -fno-auto-profile and -fno-profile-sample-use Reviewers: davidxl, dnovillo, echristo Reviewed By: echristo Subscribers: echristo, cfe-commits Differential Revision: https://reviews.llvm.org/D31213 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298446 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 8 ++++++++ lib/Driver/ToolChains/Clang.cpp | 2 +- lib/Driver/ToolChains/CommonArgs.cpp | 18 +++++++++++++++++- lib/Driver/ToolChains/CommonArgs.h | 1 + test/Driver/clang_f_opts.c | 7 +++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 71e05b932b..5eabfd278f 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -613,9 +613,17 @@ def fno_gnu_inline_asm : Flag<["-"], "fno-gnu-inline-asm">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Disable GNU style inline asm">; +def fprofile_sample_use : Flag<["-"], "fprofile-sample-use">, Group, + Flags<[CoreOption]>; +def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, Group, + Flags<[CoreOption]>; def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Enable sample-based profile guided optimizations">; +def fauto_profile : Flag<["-"], "fauto-profile">, Group, + Alias; +def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group, + Alias; def fauto_profile_EQ : Joined<["-"], "fauto-profile=">, Alias; def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, Group, diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index ea0603c630..06d782d296 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -3431,7 +3431,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // Forward -f options with positive and negative forms; we translate // these by hand. - if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { + if (Arg *A = getLastProfileSampleUseArg(Args)) { StringRef fname = A->getValue(); if (!llvm::sys::fs::exists(fname)) D.Diag(diag::err_drv_no_such_file) << fname; diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp index 48a2cf038d..afe6be773b 100644 --- a/lib/Driver/ToolChains/CommonArgs.cpp +++ b/lib/Driver/ToolChains/CommonArgs.cpp @@ -407,7 +407,7 @@ void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, CmdArgs.push_back("-plugin-opt=-data-sections"); } - if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { + if (Arg *A = getLastProfileSampleUseArg(Args)) { StringRef FName = A->getValue(); if (!llvm::sys::fs::exists(FName)) D.Diag(diag::err_drv_no_such_file) << FName; @@ -673,6 +673,22 @@ Arg *tools::getLastProfileUseArg(const ArgList &Args) { return ProfileUseArg; } +Arg *tools::getLastProfileSampleUseArg(const ArgList &Args) { + auto *ProfileSampleUseArg = Args.getLastArg( + options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ, + options::OPT_fauto_profile, options::OPT_fauto_profile_EQ, + options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile); + + if (ProfileSampleUseArg && + (ProfileSampleUseArg->getOption().matches( + options::OPT_fno_profile_sample_use) || + ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile))) + return nullptr; + + return Args.getLastArg(options::OPT_fprofile_sample_use_EQ, + options::OPT_fauto_profile_EQ); +} + /// Parses the various -fpic/-fPIC/-fpie/-fPIE arguments. Then, /// smooshes them together with platform defaults, to decide whether /// this compile should be using PIC mode or not. Returns a tuple of diff --git a/lib/Driver/ToolChains/CommonArgs.h b/lib/Driver/ToolChains/CommonArgs.h index 252dbf590b..f5747aa85f 100644 --- a/lib/Driver/ToolChains/CommonArgs.h +++ b/lib/Driver/ToolChains/CommonArgs.h @@ -63,6 +63,7 @@ void addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC, const llvm::opt::ArgList &Args); llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args); +llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args); bool isObjCAutoRefCount(const llvm::opt::ArgList &Args); diff --git a/test/Driver/clang_f_opts.c b/test/Driver/clang_f_opts.c index 0261d93c49..15c1eacb96 100644 --- a/test/Driver/clang_f_opts.c +++ b/test/Driver/clang_f_opts.c @@ -59,6 +59,13 @@ // 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" +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-profile-sample-use %s 2>&1 | FileCheck -check-prefix=CHECK-NO-AUTO-PROFILE %s +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-auto-profile %s 2>&1 | FileCheck -check-prefix=CHECK-NO-AUTO-PROFILE %s +// CHECK-NO-AUTO-PROFILE-NOT: "-fprofile-sample-use={{.*}}/file.prof" + +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-profile-sample-use -fauto-profile %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s +// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-auto-profile -fprofile-sample-use %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s + // RUN: %clang -### -S -fprofile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-ARCS %s // RUN: %clang -### -S -fno-profile-arcs -fprofile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-ARCS %s // RUN: %clang -### -S -fno-profile-arcs %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROFILE-ARCS %s -- 2.40.0