[PATCH] MS ABI: Implement thread_local for global variables
Reid Kleckner
rnk at google.com
Fri Oct 3 13:43:14 PDT 2014
================
Comment at: lib/CodeGen/CGCXXABI.h:449-450
@@ -448,1 +448,4 @@
+ /// Return whether the __tls_init function require a guard variable.
+ virtual bool requiresTLSGuard() const = 0;
+
----------------
This method appears dead now.
================
Comment at: lib/CodeGen/CGCXXABI.h:493
@@ -489,3 +492,3 @@
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
llvm::Constant *dtor, llvm::Constant *addr);
----------------
Make this pure and delete the generic CGCXXABI implementation now?
================
Comment at: lib/CodeGen/CGCXXABI.h:500-501
@@ -496,4 +499,4 @@
///
/// \param Decls The thread_local declarations in this translation unit.
/// \param InitFunc If this translation unit contains any non-constant
/// initialization or non-trivial destruction for thread_local
----------------
Can you update or delete the doxygen? IIRC there are clang warnings that detect parameter name mismatches like this.
================
Comment at: lib/CodeGen/ItaniumCXXABI.cpp:237-238
@@ -236,2 +236,4 @@
+ virtual bool requiresTLSGuard() const override { return true; }
+
llvm::Function *getOrCreateThreadLocalWrapper(const VarDecl *VD,
----------------
dead
================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:274
@@ -261,1 +273,3 @@
+
+ virtual bool requiresTLSGuard() const override { return false; }
----------------
dead
================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:1780
@@ +1779,3 @@
+
+ std::vector<llvm::Function *> NondiscardableInits;
+ for (size_t I = 0, E = CXXThreadLocalInitVars.size(); I != E; ++I) {
----------------
"Nondiscardable" seems like the wrong name. Perhaps "NonComdatInits" or "TUOrderedInits"?
================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:1801-1803
@@ +1800,5 @@
+ if (!NondiscardableInits.empty()) {
+ llvm::Function *InitFunc =
+ CGM.CreateGlobalInitOrDestructFunction(FTy, "__tls_init",
+ /*TLS=*/true);
+ CodeGenFunction(CGM)
----------------
One possible alternative is to build a single global in the .CRT$XDU section that is an ordered array of all the thread local initializers that need to be run. I guess you considered and rejected this, because the single function allows for more optimization?
================
Comment at: test/CodeGenCXX/ms-thread_local.cpp:21
@@ +20,2 @@
+ (void)b;
+}
----------------
Maybe add some code CHECKs like:
// CHECK-LABEL: define internal void @__tls_init()
// CHECK: call void @"\01??__E?b@@3UA@@A"()
http://reviews.llvm.org/D5597
More information about the cfe-commits
mailing list