From: Duncan P. N. Exon Smith Date: Thu, 20 Mar 2014 19:23:46 +0000 (+0000) Subject: PGO: Remove explicit static initialization X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c3d0e7f4c2781bda631fbae86ab24b7334df1d7;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204379 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index 20305c3567..96409fef64 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -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; diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 03c49e357a..936acec3c5 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -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");