diff options
author | Anders Carlsson <andersca@mac.com> | 2011-04-27 04:37:08 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2011-04-27 04:37:08 +0000 |
commit | 173d51286bcaff4b6b76eebf6542d3b1311142e2 (patch) | |
tree | 0f72736dee5c39d574285ef3a8d60d3d5c026771 /lib | |
parent | 6add6fbc5997c42fb014969b68770b1b29aa318b (diff) |
When compiling with -fno-threadsafe-statics, guard variables for globals with internal linkage don't have to be i64, i8 works just fine!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/ItaniumCXXABI.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index a53ef1a265..f278646223 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -1066,10 +1066,18 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF, // 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 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF, // 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"); |