[cfe-commits] r130286 - in /cfe/trunk: lib/CodeGen/ItaniumCXXABI.cpp test/CodeGenCXX/threadsafe-statics.cpp

Anders Carlsson andersca at mac.com
Tue Apr 26 21:37:08 PDT 2011


Author: andersca
Date: Tue Apr 26 23:37:08 2011
New Revision: 130286

URL: http://llvm.org/viewvc/llvm-project?rev=130286&view=rev
Log:
When compiling with -fno-threadsafe-statics, guard variables for globals with internal linkage don't have to be i64, i8 works just fine!

Modified:
    cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
    cfe/trunk/test/CodeGenCXX/threadsafe-statics.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=130286&r1=130285&r2=130286&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Tue Apr 26 23:37:08 2011
@@ -1066,10 +1066,18 @@
   // global initialization is always single-threaded.
   bool ThreadsafeStatics = (getContext().getLangOptions().ThreadsafeStatics &&
                             D.isLocalVarDecl());
-  
-  // Guard variables are 64 bits in the generic ABI and 32 bits on ARM.
-  const llvm::IntegerType *GuardTy
-    = (IsARM ? Builder.getInt32Ty() : Builder.getInt64Ty());
+
+  const llvm::IntegerType *GuardTy;
+
+  // If we have a global variable with internal linkage and thread-safe statics
+  // are disabled, we can just let the guard variable be of type i8.
+  bool UseInt8GuardVariable = !ThreadsafeStatics && GV->hasInternalLinkage();
+  if (UseInt8GuardVariable)
+    GuardTy = Builder.getInt8Ty();
+  else {
+    // Guard variables are 64 bits in the generic ABI and 32 bits on ARM.
+    GuardTy = (IsARM ? Builder.getInt32Ty() : Builder.getInt64Ty());
+  }
   const llvm::PointerType *GuardPtrTy = GuardTy->getPointerTo();
 
   // Create the guard variable.
@@ -1100,7 +1108,7 @@
   //       if (__cxa_guard_acquire(&obj_guard))
   //         ...
   //     }
-  if (IsARM) {
+  if (IsARM && !UseInt8GuardVariable) {
     llvm::Value *V = Builder.CreateLoad(GuardVariable);
     V = Builder.CreateAnd(V, Builder.getInt32(1));
     IsInitialized = Builder.CreateIsNull(V, "guard.uninitialized");

Modified: cfe/trunk/test/CodeGenCXX/threadsafe-statics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/threadsafe-statics.cpp?rev=130286&r1=130285&r2=130286&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/threadsafe-statics.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/threadsafe-statics.cpp Tue Apr 26 23:37:08 2011
@@ -1,8 +1,11 @@
-// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix=WITH-TSS %s
-// RUN: %clang_cc1 -emit-llvm -o - %s -fno-threadsafe-statics | FileCheck -check-prefix=NO-TSS %s
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-apple-darwin10 -o - %s | FileCheck -check-prefix=WITH-TSS %s
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-apple-darwin10 -o - %s -fno-threadsafe-statics | FileCheck -check-prefix=NO-TSS %s
 
 int f();
 
+// WITH-TSS: @_ZZ1gvE1a = internal global i32 0, align 4
+// WITH-TSS: @_ZGVZ1gvE1a = internal global i64 0
+
 // WITH-TSS: define void @_Z1gv() nounwind
 // WITH-TSS: call i32 @__cxa_guard_acquire
 // WITH-TSS: call void @__cxa_guard_release
@@ -11,6 +14,9 @@
   static int a = f();
 }
 
+// NO-TSS: @_ZZ1gvE1a = internal global i32 0, align 4
+// NO-TSS: @_ZGVZ1gvE1a = internal global i8 0
+
 // NO-TSS: define void @_Z1gv() nounwind
 // NO-TSS-NOT: call i32 @__cxa_guard_acquire
 // NO-TSS-NOT: call void @__cxa_guard_release





More information about the cfe-commits mailing list