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

llvm-svn: 298446
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 48a2cf0..afe6be7 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -407,7 +407,7 @@
     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 @@
   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