llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.97k stars 11.54k forks source link

missed optimization for inline virtual methods #7119

Open llvmbot opened 14 years ago

llvmbot commented 14 years ago
Bugzilla Link 6747
Version unspecified
OS Linux
Attachments proposed patch, updated patch, rebased patch
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

Given the translation unit

struct foo {
  virtual void bar();
  virtual void baz() {}
};
void zed() {
  foo b;
  b.baz();
}

we currently produce

define linkonce_odr void @​_ZN3foo3bazEv

it should probably be available_externally. Given that the function is virtual and we know we will have a vtable in some other translation unit, we can produce this one as available_externally.

DougGregor commented 14 years ago

We've had to remove this optimization in r103741; see the comment in that commit. We can revisit this optimization later.

llvmbot commented 14 years ago

Fixed in 101757.

DougGregor commented 14 years ago

Created an attachment (id=4663) [details] rebased patch

--- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -314,7 +314,15 @@ GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD, if (FD->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDeclaration) return CodeGenModule::GVA_C99Inline;

The RD->isDynamicClass() check is redundant.

Otherwise, this patch looks good. Thanks!