]> granicus.if.org Git - clang/commitdiff
InstrProf: Support for setting profile output from command line
authorJustin Bogner <mail@justinbogner.com>
Thu, 30 Apr 2015 23:49:42 +0000 (23:49 +0000)
committerJustin Bogner <mail@justinbogner.com>
Thu, 30 Apr 2015 23:49:42 +0000 (23:49 +0000)
This change is the third of 3 patches to add support for specifying
the profile output from the command line via -fprofile-instr-generate=<path>,
where the specified output path/file will be overridden by the
LLVM_PROFILE_FILE environment variable.

This patch adds the necessary support to the clang frontend, and adds a
new test.

The compiler-rt and llvm parts are r236055 and r236288, respectively.

Patch by Teresa Johnson. Thanks!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236289 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Options.td
include/clang/Frontend/CodeGenOptions.h
lib/CodeGen/BackendUtil.cpp
lib/Driver/ToolChains.cpp
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
test/Profile/c-generate.c [new file with mode: 0644]

index b0eb0de804de1f09b9018fb90d75b5bafb837e72..9c4cf8c656432a2290e7194f6b4c3e6b4085644d 100644 (file)
@@ -418,7 +418,10 @@ def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
     Alias<fprofile_sample_use_EQ>;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
     Group<f_Group>, Flags<[CC1Option]>,
-    HelpText<"Generate instrumented code to collect execution counts">;
+    HelpText<"Generate instrumented code to collect execution counts into default.profraw file (overriden by '=' form of option or LLVM_PROFILE_FILE env var)">;
+def fprofile_instr_generate_EQ : Joined<["-"], "fprofile-instr-generate=">,
+    Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<file>">,
+    HelpText<"Generate instrumented code to collect execution counts into <file> (overridden by LLVM_PROFILE_FILE env var)">;
 def fprofile_instr_use : Flag<["-"], "fprofile-instr-use">, Group<f_Group>;
 def fprofile_instr_use_EQ : Joined<["-"], "fprofile-instr-use=">,
     Group<f_Group>, Flags<[CC1Option]>,
index 36c33c7e3bc85c723586550affdac53154c2977c..3a1721aa4871f2b56b0cc9c5ff96a3590f16952c 100644 (file)
@@ -154,6 +154,9 @@ public:
   /// A list of dependent libraries.
   std::vector<std::string> DependentLibraries;
 
+  /// Name of the profile file to use as output for -fprofile-instr-generate
+  std::string InstrProfileOutput;
+
   /// Name of the profile file to use with -fprofile-sample-use.
   std::string SampleProfileFile;
 
index 7bc351a61abdd95d3aaf0d2058dde8c46a16ac3a..22ae565b38f2a130b355408900cc784228b9cf01 100644 (file)
@@ -394,6 +394,7 @@ void EmitAssemblyHelper::CreatePasses() {
   if (CodeGenOpts.ProfileInstrGenerate) {
     InstrProfOptions Options;
     Options.NoRedZone = CodeGenOpts.DisableRedZone;
+    Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
     MPM->add(createInstrProfilingPass(Options));
   }
 
index 434dc4d331409b83a22f2b842a8c6a8be0e58f9a..20a308dedf39800343b0f1e810f8ed6fef3de13f 100644 (file)
@@ -379,6 +379,7 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
                    false) ||
       Args.hasArg(options::OPT_fprofile_generate) ||
       Args.hasArg(options::OPT_fprofile_instr_generate) ||
+      Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
       Args.hasArg(options::OPT_fcreate_profile) ||
       Args.hasArg(options::OPT_coverage)) {
     // Select the appropriate runtime library for the target.
index 10837996a3ab35327630c3696bc60653d43cd726..27e6427d0d4fa4ba4bb00c42fccfde47c8884b3f 100644 (file)
@@ -2251,6 +2251,7 @@ static void addProfileRT(const ToolChain &TC, const ArgList &Args,
                      false) ||
         Args.hasArg(options::OPT_fprofile_generate) ||
         Args.hasArg(options::OPT_fprofile_instr_generate) ||
+        Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
         Args.hasArg(options::OPT_fcreate_profile) ||
         Args.hasArg(options::OPT_coverage)))
     return;
@@ -3397,13 +3398,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
 
   Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
 
-  if (Args.hasArg(options::OPT_fprofile_instr_generate) &&
+  if ((Args.hasArg(options::OPT_fprofile_instr_generate) ||
+       Args.hasArg(options::OPT_fprofile_instr_generate_EQ)) &&
       (Args.hasArg(options::OPT_fprofile_instr_use) ||
        Args.hasArg(options::OPT_fprofile_instr_use_EQ)))
     D.Diag(diag::err_drv_argument_not_allowed_with)
       << "-fprofile-instr-generate" << "-fprofile-instr-use";
 
-  Args.AddAllArgs(CmdArgs, options::OPT_fprofile_instr_generate);
+  if (Arg *A = Args.getLastArg(options::OPT_fprofile_instr_generate_EQ))
+    A->render(Args, CmdArgs);
+  else
+    Args.AddAllArgs(CmdArgs, options::OPT_fprofile_instr_generate);
 
   if (Arg *A = Args.getLastArg(options::OPT_fprofile_instr_use_EQ))
     A->render(Args, CmdArgs);
@@ -3419,7 +3424,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("-femit-coverage-data");
 
   if (Args.hasArg(options::OPT_fcoverage_mapping) &&
-      !Args.hasArg(options::OPT_fprofile_instr_generate))
+      !(Args.hasArg(options::OPT_fprofile_instr_generate) ||
+        Args.hasArg(options::OPT_fprofile_instr_generate_EQ)))
     D.Diag(diag::err_drv_argument_only_allowed_with)
       << "-fcoverage-mapping" << "-fprofile-instr-generate";
 
index 2a80b07beecb32c1675b2ef59926fb2461955c95..a91e31e36c1737a650fb9b9db6909e59cafa8e2e 100644 (file)
@@ -431,7 +431,9 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
-  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate);
+  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
+      Args.hasArg(OPT_fprofile_instr_generate_EQ);;
+  Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ);
   Opts.CoverageMapping = Args.hasArg(OPT_fcoverage_mapping);
   Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping);
diff --git a/test/Profile/c-generate.c b/test/Profile/c-generate.c
new file mode 100644 (file)
index 0000000..8b979d6
--- /dev/null
@@ -0,0 +1,10 @@
+// Check that the -fprofile-instr-generate= form works.
+// RUN: %clang_cc1 -main-file-name c-generate.c %s -o - -emit-llvm -fprofile-instr-generate=c-generate-test.profraw | FileCheck %s
+
+// CHECK: private constant [24 x i8] c"c-generate-test.profraw\00"
+// CHECK: call void @__llvm_profile_set_filename_env_override(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @0, i32 0, i32 0))
+// CHECK: declare void @__llvm_profile_set_filename_env_override(i8*)
+
+int main(void) {
+  return 0;
+}