davidxl created this revision.
davidxl added reviewers: cfe-commits, bogner, silvas, xur.

See patch-1 for description

http://reviews.llvm.org/D12716

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenPGO.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -457,6 +457,9 @@
       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.InstrProfileWithNames =
+    Args.hasFlag(OPT_fprofile_instr_with_names, 
+		 OPT_fno_profile_instr_with_names, false);
   Opts.CoverageMapping =
       Args.hasFlag(OPT_fcoverage_mapping, OPT_fno_coverage_mapping, false);
   Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping);
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2953,6 +2953,19 @@
     }
   }
 
+  if (Args.hasFlag(options::OPT_fprofile_instr_with_names,
+                   options::OPT_fno_profile_instr_with_names, true))
+    CmdArgs.push_back("-fprofile-instr-with-names");
+
+  if (!Args.hasFlag(options::OPT_fprofile_instr_with_names,
+                   options::OPT_fno_profile_instr_with_names, true) &&
+      Args.hasFlag(options::OPT_fcoverage_mapping,
+                   options::OPT_fno_coverage_mapping, false))
+    D.Diag(diag::err_drv_argument_only_allowed_with)
+        << "-fno-profile-instr-with-names"
+        << "-fno-coverage-mapping";
+
+
   if (Args.hasArg(options::OPT_ftest_coverage) ||
       Args.hasArg(options::OPT_coverage))
     CmdArgs.push_back("-femit-coverage-notes");
Index: lib/CodeGen/CodeGenPGO.cpp
===================================================================
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -69,8 +69,12 @@
            Linkage == llvm::GlobalValue::ExternalLinkage)
     Linkage = llvm::GlobalValue::PrivateLinkage;
 
-  auto *Value =
-      llvm::ConstantDataArray::getString(CGM.getLLVMContext(), FuncName, false);
+  StringRef FuncNameOrHash = FuncName;
+  if (!CGM.getCodeGenOpts().InstrProfileWithNames)
+    FuncNameOrHash = llvm::MD5HashStr(FuncName);
+
+  auto *Value = llvm::ConstantDataArray::getString(CGM.getLLVMContext(),
+                                                   FuncNameOrHash, false);
   FuncNameVar =
       new llvm::GlobalVariable(CGM.getModule(), Value->getType(), true, Linkage,
                                Value, "__llvm_profile_name_" + FuncName);
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -406,6 +406,7 @@
 
   if (CodeGenOpts.ProfileInstrGenerate) {
     InstrProfOptions Options;
+    Options.IncludeNamesInProfile = CodeGenOpts.InstrProfileWithNames;
     Options.NoRedZone = CodeGenOpts.DisableRedZone;
     Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
     MPM->add(createInstrProfilingPass(Options));
Index: include/clang/Frontend/CodeGenOptions.h
===================================================================
--- include/clang/Frontend/CodeGenOptions.h
+++ include/clang/Frontend/CodeGenOptions.h
@@ -158,6 +158,10 @@
   /// and -fprofile-generate.
   std::string InstrProfileOutput;
 
+  /// Include full assembly names in profile data. If the flag is false,
+  /// the profile data will use MD5 hash string instead
+  bool InstrProfileWithNames;
+
   /// Name of the profile file to use with -fprofile-sample-use.
   std::string SampleProfileFile;
 
Index: include/clang/Frontend/CodeGenOptions.def
===================================================================
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -101,6 +101,7 @@
 
 CODEGENOPT(ProfileInstrGenerate , 1, 0) ///< Instrument code to generate
                                         ///< execution counts to use with PGO.
+CODEGENOPT(InstrProfileWithNames, 1, 0) ///< Include full names in profile.
 CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
                                    ///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -441,6 +441,12 @@
 def fno_coverage_mapping : Flag<["-"], "fno-coverage-mapping">,
     Group<f_Group>, Flags<[DriverOption]>,
     HelpText<"Disable code coverage analysis">;
+def fprofile_instr_with_names : Flag<["-"], "fprofile-instr-with-names">,
+    Group<f_Group>, Flags<[CC1Option]>,
+    HelpText<"Include full function names in profile data">;
+def fno_profile_instr_with_names : Flag<["-"], "fno-profile-instr-with-names">,
+    Group<f_Group>, Flags<[DriverOption]>,
+    HelpText<"Do not include full function names in profile data">;
 def fprofile_generate : Flag<["-"], "fprofile-generate">,
     Alias<fprofile_instr_generate>;
 def fprofile_generate_EQ : Joined<["-"], "fprofile-generate=">,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to