[cfe-commits] r110189 - in /cfe/trunk: lib/CodeGen/CGVTables.cpp test/CodeGenCXX/mangle-subst-std.cpp test/CodeGenCXX/virt-template-vtable.cpp test/CodeGenCXX/vtable-linkage.cpp
John McCall
rjmccall at apple.com
Tue Aug 3 23:38:15 PDT 2010
Author: rjmccall
Date: Wed Aug 4 01:38:15 2010
New Revision: 110189
URL: http://llvm.org/viewvc/llvm-project?rev=110189&view=rev
Log:
Extend the hidden-visibility vtables optimization to template classes that
haven't been explicitly instantiated.
Modified:
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp
cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp
cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp
Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=110189&r1=110188&r2=110189&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Wed Aug 4 01:38:15 2010
@@ -2929,18 +2929,34 @@
// It's okay to have multiple copies of a vtable, so don't make the
// dynamic linker unique them. Suppress this optimization if it's
- // possible that there might be unresolved references elsewhere,
- // which can happen if
- // - there's a key function and the vtable is getting emitted weak
- // anyway for whatever reason
- // - there might be an explicit instantiation declaration somewhere,
- // i.e. if it's a template at all
+ // possible that there might be unresolved references elsewhere
+ // which can only be resolved by this emission.
if (Linkage == llvm::GlobalVariable::WeakODRLinkage &&
VTable->getVisibility() == llvm::GlobalVariable::DefaultVisibility &&
- !RD->hasAttr<VisibilityAttr>() &&
- RD->getTemplateSpecializationKind() == TSK_Undeclared &&
- !CGM.Context.getKeyFunction(RD)) {
- VTable->setVisibility(llvm::GlobalVariable::HiddenVisibility);
+ !RD->hasAttr<VisibilityAttr>()) {
+ switch (RD->getTemplateSpecializationKind()) {
+
+ // Every use of a non-template or explicitly-specialized class's
+ // vtable has to emit it.
+ case TSK_ExplicitSpecialization:
+ case TSK_Undeclared:
+ // Implicit instantiations can ignore the possibility of an
+ // explicit instantiation declaration because there necessarily
+ // must be an EI definition somewhere with default visibility.
+ case TSK_ImplicitInstantiation:
+ // If there's a key function, there may be translation units
+ // that don't have the key function's definition.
+ if (!CGM.Context.getKeyFunction(RD))
+ // Otherwise, drop the visibility to hidden.
+ VTable->setVisibility(llvm::GlobalValue::HiddenVisibility);
+ break;
+
+ // We have to disable the optimization if this is an EI definition
+ // because there might be EI declarations in other shared objects.
+ case TSK_ExplicitInstantiationDefinition:
+ case TSK_ExplicitInstantiationDeclaration:
+ break;
+ }
}
}
Modified: cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp?rev=110189&r1=110188&r2=110189&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp Wed Aug 4 01:38:15 2010
@@ -3,13 +3,13 @@
// Check mangling of Vtables, VTTs, and construction vtables that
// involve standard substitutions.
-// CHECK: @_ZTVSd = weak_odr constant
+// CHECK: @_ZTVSd = weak_odr hidden constant
// CHECK: @_ZTCSd0_Si = internal constant
// CHECK: @_ZTCSd16_So = internal constant
// CHECK: @_ZTTSd = weak_odr constant
-// CHECK: @_ZTVSo = weak_odr constant
+// CHECK: @_ZTVSo = weak_odr hidden constant
// CHECK: @_ZTTSo = weak_odr constant
-// CHECK: @_ZTVSi = weak_odr constant
+// CHECK: @_ZTVSi = weak_odr hidden constant
// CHECK: @_ZTTSi = weak_odr constant
namespace std {
struct A { A(); };
Modified: cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp?rev=110189&r1=110188&r2=110189&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp Wed Aug 4 01:38:15 2010
@@ -19,4 +19,4 @@
// CHECK: @_ZTV1B = weak_odr hidden constant
// CHECK: @_ZTV1AIlE = weak_odr constant
// CHECK: @_ZTV1AIsE = weak_odr constant
-// CHECK: @_ZTV1AIiE = weak_odr constant
+// CHECK: @_ZTV1AIiE = weak_odr hidden constant
Modified: cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp?rev=110189&r1=110188&r2=110189&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp Wed Aug 4 01:38:15 2010
@@ -11,6 +11,7 @@
// RUN: FileCheck --check-prefix=CHECK-10 %s < %t
// RUN: FileCheck --check-prefix=CHECK-11 %s < %t
// RUN: FileCheck --check-prefix=CHECK-12 %s < %t
+// RUN: FileCheck --check-prefix=CHECK-13 %s < %t
namespace {
struct A {
@@ -83,12 +84,13 @@
template struct F<short>;
extern template struct F<int>;
-void use_F(F<char> &fc) {
+void use_F() {
+ F<char> fc;
+ fc.foo();
F<int> fi;
fi.foo();
F<long> fl;
(void)fl;
- fc.foo();
}
// B has a key function that is not defined in this translation unit so its vtable
@@ -135,8 +137,8 @@
// CHECK-7: @_ZTI1EIlE = weak_odr constant
// F<long> is an implicit template instantiation with no key function,
-// so its vtable should have weak_odr linkage.
-// CHECK-8: @_ZTV1FIlE = weak_odr constant
+// so its vtable should have weak_odr linkage and hidden visibility.
+// CHECK-8: @_ZTV1FIlE = weak_odr hidden constant
// CHECK-8: @_ZTS1FIlE = weak_odr constant
// CHECK-8: @_ZTI1FIlE = weak_odr constant
@@ -161,6 +163,12 @@
// CHECK-12: @_ZTSN12_GLOBAL__N_11AE = internal constant
// CHECK-12: @_ZTIN12_GLOBAL__N_11AE = internal constant
+// F<char> is an explicit specialization without a key function, so
+// its vtable should have weak_odr linkage and hidden visibility.
+// CHECK-13: @_ZTV1FIcE = weak_odr hidden constant
+// CHECK-13: @_ZTS1FIcE = weak_odr constant
+// CHECK-13: @_ZTI1FIcE = weak_odr constant
+
// RUN: FileCheck --check-prefix=CHECK-G %s < %t
//
// CHECK-G: @_ZTV1GIiE = weak_odr constant
More information about the cfe-commits
mailing list