r204408 - PGO: Don't define instrumentation data available_externally
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Mar 20 15:50:08 PDT 2014
Author: dexonsmith
Date: Thu Mar 20 17:50:08 2014
New Revision: 204408
URL: http://llvm.org/viewvc/llvm-project?rev=204408&view=rev
Log:
PGO: Don't define instrumentation data available_externally
Variables with available_externally linkage can be dropped at will.
This causes link errors, since there are still references to the
instrumentation! linkonce_odr is almost equivalent, so use that
instead.
As a drive-by fix (I don't have an Elf system, so I'm not sure how to
write a testcase), use linkonce linkage for the instrumentation of
extern_weak functions.
<rdar://problem/15943240>
Added:
cfe/trunk/test/Profile/c-linkage-available_externally.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=204408&r1=204407&r2=204408&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Thu Mar 20 17:50:08 2014
@@ -824,7 +824,22 @@ void CodeGenPGO::assignRegionCounters(co
if (!D)
return;
setFuncName(Fn);
+
+ // Set the linkage for variables based on the function linkage. Usually, we
+ // want to match it, but available_externally and extern_weak both have the
+ // wrong semantics.
VarLinkage = Fn->getLinkage();
+ switch (VarLinkage) {
+ case llvm::GlobalValue::ExternalWeakLinkage:
+ VarLinkage = llvm::GlobalValue::LinkOnceAnyLinkage;
+ break;
+ case llvm::GlobalValue::AvailableExternallyLinkage:
+ VarLinkage = llvm::GlobalValue::LinkOnceODRLinkage;
+ break;
+ default:
+ break;
+ }
+
mapRegionCounters(D);
if (InstrumentRegions)
emitCounterVariables();
Added: cfe/trunk/test/Profile/c-linkage-available_externally.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-linkage-available_externally.c?rev=204408&view=auto
==============================================================================
--- cfe/trunk/test/Profile/c-linkage-available_externally.c (added)
+++ cfe/trunk/test/Profile/c-linkage-available_externally.c Thu Mar 20 17:50:08 2014
@@ -0,0 +1,12 @@
+// Make sure instrementation data from available_externally functions doesn't
+// get thrown out.
+// RUN: %clang_cc1 -O2 -triple x86_64-apple-macosx10.9 -main-file-name c-linkage-available_externally.c %s -o - -emit-llvm -fprofile-instr-generate | FileCheck %s
+
+// CHECK: @__llvm_profile_counters_foo = linkonce_odr global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8
+// CHECK: @__llvm_profile_name_foo = linkonce_odr constant [3 x i8] c"foo", section "__DATA,__llvm_prf_names", align 1
+// CHECK: @__llvm_profile_data_foo = linkonce_odr constant { i32, i32, i64, i8*, i64* } { i32 3, i32 1, i64 1, i8* getelementptr inbounds ([3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i64* getelementptr inbounds ([1 x i64]* @__llvm_profile_counters_foo, i32 0, i32 0) }, section "__DATA,__llvm_prf_data", align 8
+inline int foo(void) { return 1; }
+
+int main(void) {
+ return foo();
+}
More information about the cfe-commits
mailing list