r204379 - PGO: Remove explicit static initialization
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Mar 20 12:23:47 PDT 2014
Author: dexonsmith
Date: Thu Mar 20 14:23:46 2014
New Revision: 204379
URL: http://llvm.org/viewvc/llvm-project?rev=204379&view=rev
Log:
PGO: Remove explicit static initialization
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>
Modified:
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=204379&r1=204378&r2=204379&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Thu Mar 20 14:23:46 2014
@@ -198,7 +198,6 @@ static llvm::BasicBlock *getOrInsertRegi
"__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 *getOrInsertRuntim
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::emitInitiali
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::emitInitiali
// 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;
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=204379&r1=204378&r2=204379&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Mar 20 14:23:46 2014
@@ -325,6 +325,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(
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");
More information about the cfe-commits
mailing list