]> granicus.if.org Git - clang/commitdiff
PGO: Remove explicit static initialization
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 20 Mar 2014 19:23:46 +0000 (19:23 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 20 Mar 2014 19:23:46 +0000 (19:23 +0000)
Remove the remaining explicit static initialization from translation
units, at least on Darwin.  Instead, create a use of __llvm_pgo_runtime,
which will pull in required code from compiler-rt.

After this commit (and its pair in compiler-rt), a user can define their
own __llvm_pgo_runtime to satisfy this undefined symbol and call the
functions in compiler-rt directly.

<rdar://problem/15943240>

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

lib/CodeGen/CodeGenPGO.cpp
lib/Driver/ToolChains.cpp

index 20305c3567ef6af03ae3624e0e02c38188131151..96409fef64b9c1282019c94bfe611d97f391b4c2 100644 (file)
@@ -198,7 +198,6 @@ static llvm::BasicBlock *getOrInsertRegisterBB(CodeGenModule &CGM) {
                                            "__llvm_pgo_register_functions",
                                            &CGM.getModule());
   RegisterF->setUnnamedAddr(true);
-  RegisterF->addFnAttr(llvm::Attribute::NoInline);
   if (CGM.getCodeGenOpts().DisableRedZone)
     RegisterF->addFnAttr(llvm::Attribute::NoRedZone);
 
@@ -217,14 +216,6 @@ static llvm::Constant *getOrInsertRuntimeRegister(CodeGenModule &CGM) {
                                              RuntimeRegisterTy);
 }
 
-static llvm::Constant *getOrInsertRuntimeWriteAtExit(CodeGenModule &CGM) {
-  // TODO: make this depend on a command-line option.
-  auto *VoidTy = llvm::Type::getVoidTy(CGM.getLLVMContext());
-  auto *WriteAtExitTy = llvm::FunctionType::get(VoidTy, false);
-  return CGM.getModule().getOrInsertFunction("__llvm_pgo_register_write_atexit",
-                                             WriteAtExitTy);
-}
-
 static bool isMachO(const CodeGenModule &CGM) {
   return CGM.getTarget().getTriple().isOSBinFormatMachO();
 }
@@ -307,10 +298,9 @@ llvm::Function *CodeGenPGO::emitInitialization(CodeGenModule &CGM) {
   if (CGM.getModule().getFunction("__llvm_pgo_init"))
     return nullptr;
 
-  // Get the functions to call at initialization.
+  // Get the function to call at initialization.
   llvm::Constant *RegisterF = getRegisterFunc(CGM);
-  llvm::Constant *WriteAtExitF = getOrInsertRuntimeWriteAtExit(CGM);
-  if (!RegisterF && !WriteAtExitF)
+  if (!RegisterF)
     return nullptr;
 
   // Create the initialization function.
@@ -325,10 +315,7 @@ llvm::Function *CodeGenPGO::emitInitialization(CodeGenModule &CGM) {
 
   // Add the basic block and the necessary calls.
   CGBuilderTy Builder(llvm::BasicBlock::Create(CGM.getLLVMContext(), "", F));
-  if (RegisterF)
-    Builder.CreateCall(RegisterF);
-  if (WriteAtExitF)
-    Builder.CreateCall(WriteAtExitF);
+  Builder.CreateCall(RegisterF);
   Builder.CreateRetVoid();
 
   return F;
index 03c49e357ae51c4e628ba35c08baaba04dc6924f..936acec3c520619a3252c68edf4a47c1fe809b94 100644 (file)
@@ -325,6 +325,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
       Args.hasArg(options::OPT_fprofile_instr_generate) ||
       Args.hasArg(options::OPT_fcreate_profile) ||
       Args.hasArg(options::OPT_coverage)) {
+    // Pull in runtime for -fprofile-inst-generate.  This is required since
+    // there are no calls to the runtime in the code.
+    if (Args.hasArg(options::OPT_fprofile_instr_generate)) {
+      CmdArgs.push_back("-u");
+      CmdArgs.push_back("___llvm_pgo_runtime");
+    }
+
     // Select the appropriate runtime library for the target.
     if (isTargetIOSBased())
       AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a");