Do not generate LLVM IR for available_externally function bodies at

-O0, since we won't be using the definitions for anything anyway. For
lib/System/Path.o when built in Debug+Asserts mode, this leads to a 4%
improvement in compile time (and suppresses 440 function bodies).

<rdar://problem/7987644>

llvm-svn: 108156
This commit is contained in:
Douglas Gregor 2010-07-12 17:24:55 +00:00
parent 4be8f2ffad
commit dbb2806a7b
7 changed files with 33 additions and 13 deletions

View File

@ -817,14 +817,22 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) {
if (Method->isVirtual())
getVTables().EmitThunks(GD);
if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D))
return EmitCXXConstructor(CD, GD.getCtorType());
if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
// At -O0, don't generate IR for functions with available_externally
// linkage.
if (CodeGenOpts.OptimizationLevel == 0 &&
getFunctionLinkage(Function)
== llvm::Function::AvailableExternallyLinkage)
return;
if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(Function))
return EmitCXXConstructor(CD, GD.getCtorType());
if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D))
return EmitCXXDestructor(DD, GD.getDtorType());
if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(Function))
return EmitCXXDestructor(DD, GD.getDtorType());
if (isa<FunctionDecl>(D))
return EmitGlobalFunctionDefinition(GD);
}
if (const VarDecl *VD = dyn_cast<VarDecl>(D))
return EmitGlobalVarDefinition(VD);

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -emit-llvm -std=c++0x -o - %s | FileCheck %s
// RUN: %clang_cc1 -O1 -emit-llvm -std=c++0x -o - %s | FileCheck %s
template<typename T>
struct X0 {

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple x86_64-apple-darwin10 %s | FileCheck %s
// Ensure that we don't emit available_externally functions at -O0.
int x;
inline void f0(int y) { x = y; }
// CHECK: define void @test()
// CHECK: declare void @f0(i32)
void test() {
f0(17);
}

View File

@ -1,5 +1,5 @@
// RUN: echo "GNU89 tests:"
// RUN: %clang %s -emit-llvm -S -o %t -std=gnu89
// RUN: %clang %s -O1 -emit-llvm -S -o %t -std=gnu89
// RUN: grep "define available_externally i32 @ei()" %t
// RUN: grep "define i32 @foo()" %t
// RUN: grep "define i32 @bar()" %t
@ -14,7 +14,7 @@
// RUN: grep "define available_externally i32 @test5" %t
// RUN: echo "\nC99 tests:"
// RUN: %clang %s -emit-llvm -S -o %t -std=c99
// RUN: %clang %s -O1 -emit-llvm -S -o %t -std=c99
// RUN: grep "define i32 @ei()" %t
// RUN: grep "define available_externally i32 @foo()" %t
// RUN: grep "define i32 @bar()" %t
@ -29,7 +29,7 @@
// RUN: grep "define available_externally i32 @test5" %t
// RUN: echo "\nC++ tests:"
// RUN: %clang %s -emit-llvm -S -o %t -std=c++98
// RUN: %clang %s -O1 -emit-llvm -S -o %t -std=c++98
// RUN: grep "define linkonce_odr i32 @_Z2eiv()" %t
// RUN: grep "define linkonce_odr i32 @_Z3foov()" %t
// RUN: grep "define i32 @_Z3barv()" %t

View File

@ -1,5 +1,5 @@
// RUN: %clang_cc1 -std=gnu89 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix GNU89 %s
// RUN: %clang_cc1 -std=c99 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix C99 %s
// RUN: %clang_cc1 -O1 -std=gnu89 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix GNU89 %s
// RUN: %clang_cc1 -O1 -std=c99 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix C99 %s
// CHECK-GNU89: define i32 @f0()
// CHECK-C99: define i32 @f0()

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 %s -O1 -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
// CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant
// CHECK-NOT: _ZTVN5test315basic_fstreamXXIcEE

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -emit-llvm -o - -fvisibility hidden %s | FileCheck %s
// RUN: %clang_cc1 -O1 -emit-llvm -o - -fvisibility hidden %s | FileCheck %s
template<typename T>
struct X {