]> granicus.if.org Git - clang/commitdiff
PGO: use linker magic to find instrumentation data on Darwin
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 20 Mar 2014 03:57:11 +0000 (03:57 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 20 Mar 2014 03:57:11 +0000 (03:57 +0000)
<rdar://problem/15943240>

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

lib/CodeGen/CodeGenPGO.cpp

index 86df30e5475ae89087f8fa5aad4c9a5f17b47d95..4071caee69150b822a13d7eb80dd0fac95ede1e4 100644 (file)
@@ -182,6 +182,10 @@ static llvm::Function *getRegisterFunc(CodeGenModule &CGM) {
 }
 
 static llvm::BasicBlock *getOrInsertRegisterBB(CodeGenModule &CGM) {
+  // Don't do this for Darwin.  compiler-rt uses linker magic.
+  if (CGM.getTarget().getTriple().isOSDarwin())
+    return nullptr;
+
   // Only need to insert this once per module.
   if (llvm::Function *RegisterF = getRegisterFunc(CGM))
     return &RegisterF->getEntryBlock();
@@ -286,9 +290,10 @@ void CodeGenPGO::emitInstrumentationData() {
   auto *Data = buildDataVar();
 
   // Register the data.
-  //
-  // TODO: only register when static initialization is required.
-  CGBuilderTy Builder(getOrInsertRegisterBB(CGM)->getTerminator());
+  auto *RegisterBB = getOrInsertRegisterBB(CGM);
+  if (!RegisterBB)
+    return;
+  CGBuilderTy Builder(RegisterBB->getTerminator());
   auto *VoidPtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
   Builder.CreateCall(getOrInsertRuntimeRegister(CGM),
                      Builder.CreateBitCast(Data, VoidPtrTy));