Subzero: Make thread_local work under MacOS 10.6.
MacOS doesn't support the thread_local keyword until 10.7 or later, and our bots run 10.6.
Who knows whether Visual Studio supports it yet.
In the meantime, use the old-style syntax.
BUG= https://codereview.chromium.org/873443004/
R=jfb@chromium.org
Review URL: https://codereview.chromium.org/865973006
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index b5cc93b..a56ae2e 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -25,7 +25,7 @@
namespace Ice {
-thread_local const Cfg *Cfg::CurrentCfg = nullptr;
+ICE_ATTRIBUTE_TLS const Cfg *Cfg::CurrentCfg = nullptr;
ArenaAllocator<> *getCurrentCfgAllocator() {
return Cfg::getCurrentCfgAllocator();
diff --git a/src/IceCfg.h b/src/IceCfg.h
index 15f353c..b45a95be 100644
--- a/src/IceCfg.h
+++ b/src/IceCfg.h
@@ -213,7 +213,7 @@
// Maintain a pointer in TLS to the current Cfg being translated.
// This is primarily for accessing its allocator statelessly, but
// other uses are possible.
- thread_local static const Cfg *CurrentCfg;
+ ICE_ATTRIBUTE_TLS static const Cfg *CurrentCfg;
};
} // end of namespace Ice
diff --git a/src/IceDefs.h b/src/IceDefs.h
index 991e47f..66a500f 100644
--- a/src/IceDefs.h
+++ b/src/IceDefs.h
@@ -38,6 +38,15 @@
#include "llvm/Support/ELF.h"
#include "llvm/Support/raw_ostream.h"
+// TODO(stichnot): Define ICE_ATTRIBUTE_TLS as thread_local after all
+// compilers support that C++11 keyword. In particular, MacOS 10.6
+// does not support it.
+#if defined (_MSC_VER)
+#define ICE_ATTRIBUTE_TLS __declspec(thread)
+#else // !_MSC_VER
+#define ICE_ATTRIBUTE_TLS __thread
+#endif // !_MSC_VER
+
namespace Ice {
class Assembler;
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index 74dfb9e..9e1b72c 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -518,6 +518,6 @@
}
}
-thread_local GlobalContext::ThreadContext *GlobalContext::TLS;
+ICE_ATTRIBUTE_TLS GlobalContext::ThreadContext *GlobalContext::TLS;
} // end of namespace Ice
diff --git a/src/IceGlobalContext.h b/src/IceGlobalContext.h
index 751147e..1f0a600 100644
--- a/src/IceGlobalContext.h
+++ b/src/IceGlobalContext.h
@@ -274,7 +274,7 @@
std::vector<ThreadContext *> AllThreadContexts;
// Each thread has its own TLS pointer which is also held in
// AllThreadContexts.
- thread_local static ThreadContext *TLS;
+ ICE_ATTRIBUTE_TLS static ThreadContext *TLS;
// Private helpers for mangleName()
typedef llvm::SmallVector<char, 32> ManglerVector;