diff options
author | John McCall <rjmccall@apple.com> | 2010-08-04 06:38:15 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-08-04 06:38:15 +0000 |
commit | 0c7d32bde03ae90367cb0666cf8614d425290aa3 (patch) | |
tree | 8f1e13f1433f379b9db852c2670777f4715fd7e7 /lib | |
parent | 0b2517299415ab1c28b9cb87d536ccea84317a10 (diff) |
Extend the hidden-visibility vtables optimization to template classes that
haven't been explicitly instantiated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110189 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGVTables.cpp | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 052a6fdca3..9cb64c6d5b 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -2929,18 +2929,34 @@ CodeGenVTables::EmitVTableDefinition(llvm::GlobalVariable *VTable, // 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; + } } } |