From 44eac33ae12df384f3f002102f919f603bee330f Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 13 Jul 2010 06:02:28 +0000 Subject: [PATCH] Reinstate the optimization suppressing available_externally functions at -O0. The only change from the previous patch is that we don't try to generate virtual method thunks for an available_externally function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108230 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 25 +++++++++++++------ .../temp.spec/temp.explicit/p9-linkage.cpp | 2 +- test/CodeGen/available-externally-suppress.c | 12 +++++++++ test/CodeGen/inline.c | 6 ++--- test/CodeGen/inline2.c | 4 +-- test/CodeGenCXX/template-instantiation.cpp | 2 +- .../visibility-hidden-extern-templates.cpp | 2 +- 7 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 test/CodeGen/available-externally-suppress.c diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index cb83ffde6f..bf606a6165 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -813,18 +813,27 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) { Context.getSourceManager(), "Generating code for declaration"); - if (const CXXMethodDecl *Method = dyn_cast(D)) - if (Method->isVirtual()) - getVTables().EmitThunks(GD); + if (const FunctionDecl *Function = dyn_cast(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 CXXMethodDecl *Method = dyn_cast(D)) { + if (Method->isVirtual()) + getVTables().EmitThunks(GD); - if (const CXXConstructorDecl *CD = dyn_cast(D)) - return EmitCXXConstructor(CD, GD.getCtorType()); + if (const CXXConstructorDecl *CD = dyn_cast(Method)) + return EmitCXXConstructor(CD, GD.getCtorType()); - if (const CXXDestructorDecl *DD = dyn_cast(D)) - return EmitCXXDestructor(DD, GD.getDtorType()); + if (const CXXDestructorDecl *DD = dyn_cast(Method)) + return EmitCXXDestructor(DD, GD.getDtorType()); + } - if (isa(D)) return EmitGlobalFunctionDefinition(GD); + } if (const VarDecl *VD = dyn_cast(D)) return EmitGlobalVarDefinition(VD); diff --git a/test/CXX/temp/temp.spec/temp.explicit/p9-linkage.cpp b/test/CXX/temp/temp.spec/temp.explicit/p9-linkage.cpp index e67233c375..57b012f9a9 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p9-linkage.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p9-linkage.cpp @@ -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 struct X0 { diff --git a/test/CodeGen/available-externally-suppress.c b/test/CodeGen/available-externally-suppress.c new file mode 100644 index 0000000000..c3b7a213ba --- /dev/null +++ b/test/CodeGen/available-externally-suppress.c @@ -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); +} diff --git a/test/CodeGen/inline.c b/test/CodeGen/inline.c index a17b069929..a6b4b3e448 100644 --- a/test/CodeGen/inline.c +++ b/test/CodeGen/inline.c @@ -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 diff --git a/test/CodeGen/inline2.c b/test/CodeGen/inline2.c index 737b58fa44..fca4fff7ca 100644 --- a/test/CodeGen/inline2.c +++ b/test/CodeGen/inline2.c @@ -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() diff --git a/test/CodeGenCXX/template-instantiation.cpp b/test/CodeGenCXX/template-instantiation.cpp index 4a3857542d..cb6c812316 100644 --- a/test/CodeGenCXX/template-instantiation.cpp +++ b/test/CodeGenCXX/template-instantiation.cpp @@ -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 diff --git a/test/CodeGenCXX/visibility-hidden-extern-templates.cpp b/test/CodeGenCXX/visibility-hidden-extern-templates.cpp index 4c133ec32c..7629b77c2c 100644 --- a/test/CodeGenCXX/visibility-hidden-extern-templates.cpp +++ b/test/CodeGenCXX/visibility-hidden-extern-templates.cpp @@ -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 struct X { -- 2.40.0