[PATCH] D22613: [Profile] deprecate __llvm_profile_override_default_filename (part-1)

David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 23:26:30 PDT 2016


davidxl created this revision.
davidxl added a reviewer: vsk.
davidxl added a subscriber: llvm-commits.

When non-default profile name is specified on command line, the current instrumentation needs to synthesize __llvm_profile_init function and emits function call to __llvm_profile_override_filename (in addition to creating a char array variable with private linkage to hold the name). 

In fact, such calls are completely unnecessary. It is enough to promote the profile name var to global linkage in comdat (or weakany) and eliminate the call. The text size will be reduced, so will the readonly data size (duplicates gets commoned). The runtime start up time will also improve slightly.

https://reviews.llvm.org/D22613

Files:
  include/llvm/ProfileData/InstrProfData.inc
  lib/Transforms/Instrumentation/InstrProfiling.cpp

Index: lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -602,8 +602,21 @@
 void InstrProfiling::emitInitialization() {
   std::string InstrProfileOutput = Options.InstrProfileOutput;
 
+  if (!InstrProfileOutput.empty()) {
+    // Create variable for profile name.
+    Constant *ProfileNameConst =
+        ConstantDataArray::getString(M->getContext(), InstrProfileOutput, true);
+    GlobalVariable *ProfileNameVar = new GlobalVariable(
+        *M, ProfileNameConst->getType(), true, GlobalValue::WeakAnyLinkage,
+        ProfileNameConst, INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR));
+    Triple TT(M->getTargetTriple());
+    if (TT.supportsCOMDAT())
+      ProfileNameVar->setComdat(M->getOrInsertComdat(
+          StringRef(INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR))));
+  }
+
   Constant *RegisterF = M->getFunction(getInstrProfRegFuncsName());
-  if (!RegisterF && InstrProfileOutput.empty())
+  if (!RegisterF)
     return;
 
   // Create the initialization function.
@@ -620,21 +633,6 @@
   IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", F));
   if (RegisterF)
     IRB.CreateCall(RegisterF, {});
-  if (!InstrProfileOutput.empty()) {
-    auto *Int8PtrTy = Type::getInt8PtrTy(M->getContext());
-    auto *SetNameTy = FunctionType::get(VoidTy, Int8PtrTy, false);
-    auto *SetNameF = Function::Create(SetNameTy, GlobalValue::ExternalLinkage,
-                                      getInstrProfFileOverriderFuncName(), M);
-
-    // Create variable for profile name.
-    Constant *ProfileNameConst =
-        ConstantDataArray::getString(M->getContext(), InstrProfileOutput, true);
-    GlobalVariable *ProfileName =
-        new GlobalVariable(*M, ProfileNameConst->getType(), true,
-                           GlobalValue::PrivateLinkage, ProfileNameConst);
-
-    IRB.CreateCall(SetNameF, IRB.CreatePointerCast(ProfileName, Int8PtrTy));
-  }
   IRB.CreateRetVoid();
 
   appendToGlobalCtors(*M, F, 0);
Index: include/llvm/ProfileData/InstrProfData.inc
===================================================================
--- include/llvm/ProfileData/InstrProfData.inc
+++ include/llvm/ProfileData/InstrProfData.inc
@@ -605,6 +605,10 @@
 #define VARIANT_MASK_IR_PROF (0x1ULL << 56)
 #define IR_LEVEL_PROF_VERSION_VAR __llvm_profile_raw_version
 
+/* The variable that holds the name of the profile data
+ * specified via command line. */
+#define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename
+
 /* Runtime section names and name strings.  */
 #define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data
 #define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22613.64824.patch
Type: text/x-patch
Size: 2762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160721/b4440c40/attachment.bin>


More information about the llvm-commits mailing list