[cfe-commits] r69032 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/function-attributes.c test/CodeGen/inline.c

Chris Lattner sabre at nondot.org
Mon Apr 13 23:44:48 PDT 2009


Author: lattner
Date: Tue Apr 14 01:44:48 2009
New Revision: 69032

URL: http://llvm.org/viewvc/llvm-project?rev=69032&view=rev
Log:
defer emission of always_inline, extern_inline, and inline functions (when 
not in c89 mode).

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/function-attributes.c
    cfe/trunk/test/CodeGen/inline.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=69032&r1=69031&r2=69032&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 14 01:44:48 2009
@@ -482,18 +482,23 @@
     if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>())
       return false;
 
-    // FIXME: What about inline, and/or extern inline?
-    if (FD->getStorageClass() != FunctionDecl::Static)
-      return false;
-  } else {
-    const VarDecl *VD = cast<VarDecl>(Global);
-    assert(VD->isFileVarDecl() && "Invalid decl");
+    GVALinkage Linkage = GetLinkageForFunctionOrMethodDecl(FD);
+    
+    // static, static inline, always_inline, and extern inline functions can
+    // always be deferred.
+    if (Linkage == GVA_Internal || Linkage == GVA_ExternInline)
+      return true;
 
-    if (VD->getStorageClass() != VarDecl::Static)
-      return false;
+    // inline functions can be deferred unless we're in C89 mode.
+    if (Linkage == GVA_Inline && (Features.C99 || Features.CPlusPlus))
+      return true;
+    
+    return false;
   }
-
-  return true;
+  
+  const VarDecl *VD = cast<VarDecl>(Global);
+  assert(VD->isFileVarDecl() && "Invalid decl");
+  return VD->getStorageClass() == VarDecl::Static;
 }
 
 void CodeGenModule::EmitGlobal(const ValueDecl *Global) {

Modified: cfe/trunk/test/CodeGen/function-attributes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/function-attributes.c?rev=69032&r1=69031&r2=69032&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/function-attributes.c (original)
+++ cfe/trunk/test/CodeGen/function-attributes.c Tue Apr 14 01:44:48 2009
@@ -7,7 +7,6 @@
 // RUN: grep 'define zeroext i16 @f5(i32 %x) nounwind' %t &&
 // RUN: grep 'define void @f6(i16 signext %x) nounwind' %t &&
 // RUN: grep 'define void @f7(i16 zeroext %x) nounwind' %t &&
-// RUN: grep 'define void @f8() nounwind alwaysinline' %t &&
 
 signed char f0(int x) { return x; }
 
@@ -25,6 +24,8 @@
 
 void f7(unsigned short x) { }
 
+// F8 is dead so it should not be emitted.
+// RUN: not grep '@f8' %t &&
 void __attribute__((always_inline)) f8(void) { }
 
 // RUN: grep 'call void @f9_t() noreturn' %t &&

Modified: cfe/trunk/test/CodeGen/inline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/inline.c?rev=69032&r1=69031&r2=69032&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/inline.c (original)
+++ cfe/trunk/test/CodeGen/inline.c Tue Apr 14 01:44:48 2009
@@ -2,19 +2,20 @@
 // RUN: grep "define available_externally i32 @ei()" %t &&
 // RUN: grep "define i32 @foo()" %t &&
 // RUN: grep "define i32 @bar()" %t &&
-// RUN: grep "define void @unreferenced()" %t &&
+// RUN: grep "define void @unreferenced1()" %t &&
+// RUN: not grep unreferenced2 %t &&
 
 // RUN: clang %s -emit-llvm -S -o %t -std=c99 &&
 // RUN: grep "define available_externally i32 @ei()" %t &&
 // RUN: grep "define available_externally i32 @foo()" %t &&
 // RUN: grep "define i32 @bar()" %t &&
-// RUN: grep "define available_externally void @unreferenced()" %t &&
+// RUN: not grep unreferenced %t &&
 
 // RUN: clang %s -emit-llvm -S -o %t -std=c++98 &&
 // RUN: grep "define available_externally i32 @_Z2eiv()" %t &&
 // RUN: grep "define linkonce_odr i32 @_Z3foov()" %t &&
 // RUN: grep "define i32 @_Z3barv()" %t &&
-// RUN: grep "define linkonce_odr void @_Z12unreferencedv()" %t
+// RUN: not grep unreferenced %t
 
 extern inline int ei() { return 123; }
 
@@ -25,5 +26,6 @@
 int bar() { return foo(); }
 
 
-inline void unreferenced() {}
+inline void unreferenced1() {}
+extern inline void unreferenced2() {}
 





More information about the cfe-commits mailing list