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 | 8a705c15d9a468ed0377da1b254b50fac1b2b1bc (patch) | |
tree | 8e4fea6d344461470f52717ec30d3029f5ed2080 /clang/lib/CodeGen/CGVTables.cpp | |
parent | 2dd7d441354dbe519585646b51980d4d93e94eb8 (diff) | |
download | bcm5719-llvm-8a705c15d9a468ed0377da1b254b50fac1b2b1bc.tar.gz bcm5719-llvm-8a705c15d9a468ed0377da1b254b50fac1b2b1bc.zip |
Extend the hidden-visibility vtables optimization to template classes that
haven't been explicitly instantiated.
llvm-svn: 110189
Diffstat (limited to 'clang/lib/CodeGen/CGVTables.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGVTables.cpp | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 052a6fdca36..9cb64c6d5b3 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/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; + } } } |