Do not inline GlobalContext TLS methods.
The gold linker thinks that causes an ODR violation.
BUG=chromium:449754
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/2896133003 .
Patch from Lei Zhang <thestig@chromium.org>.
Change-Id: I7f39b1f6e638ad3462b9b462ebdb6348473b9fc5
Reviewed-on: https://swiftshader-review.googlesource.com/12688
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/third_party/subzero/src/IceGlobalContext.cpp b/third_party/subzero/src/IceGlobalContext.cpp
index 45fb999..3a21b3a 100644
--- a/third_party/subzero/src/IceGlobalContext.cpp
+++ b/third_party/subzero/src/IceGlobalContext.cpp
@@ -372,6 +372,11 @@
}
}
+void GlobalContext::translateFunctionsWrapper(ThreadContext *MyTLS) {
+ ICE_TLS_SET_FIELD(TLS, MyTLS);
+ translateFunctions();
+}
+
void GlobalContext::translateFunctions() {
TimerMarker Timer(TimerStack::TT_translateFunctions, this);
while (std::unique_ptr<OptWorkItem> OptItem = optQueueBlockingPop()) {
@@ -454,6 +459,9 @@
} // end of anonymous namespace
+// static
+void GlobalContext::TlsInit() { ICE_TLS_INIT_FIELD(TLS); }
+
void GlobalContext::emitFileHeader() {
TimerMarker T1(Ice::TimerStack::TT_emitAsm, this);
if (getFlags().getOutFileType() == FT_Elf) {
@@ -556,6 +564,11 @@
lowerGlobals(ProfileDataSection);
}
+void GlobalContext::emitterWrapper(ThreadContext *MyTLS) {
+ ICE_TLS_SET_FIELD(TLS, MyTLS);
+ emitItems();
+}
+
void GlobalContext::emitItems() {
const bool Threaded = !getFlags().isSequential();
// Pending is a vector containing the reassembled, ordered list of
@@ -987,6 +1000,38 @@
return EmitQ.blockingPop();
}
+void GlobalContext::initParserThread() {
+ ThreadContext *Tls = new ThreadContext();
+ auto Timers = getTimers();
+ Timers->initInto(Tls->Timers);
+ AllThreadContexts.push_back(Tls);
+ ICE_TLS_SET_FIELD(TLS, Tls);
+}
+
+void GlobalContext::startWorkerThreads() {
+ size_t NumWorkers = getFlags().getNumTranslationThreads();
+ auto Timers = getTimers();
+ for (size_t i = 0; i < NumWorkers; ++i) {
+ ThreadContext *WorkerTLS = new ThreadContext();
+ Timers->initInto(WorkerTLS->Timers);
+ AllThreadContexts.push_back(WorkerTLS);
+ TranslationThreads.push_back(std::thread(
+ &GlobalContext::translateFunctionsWrapper, this, WorkerTLS));
+ }
+ if (NumWorkers) {
+ ThreadContext *WorkerTLS = new ThreadContext();
+ Timers->initInto(WorkerTLS->Timers);
+ AllThreadContexts.push_back(WorkerTLS);
+ EmitterThreads.push_back(
+ std::thread(&GlobalContext::emitterWrapper, this, WorkerTLS));
+ }
+}
+
+void GlobalContext::resetStats() {
+ if (BuildDefs::dump())
+ ICE_TLS_GET_FIELD(TLS)->StatsFunction.reset();
+}
+
void GlobalContext::dumpStats(const Cfg *Func) {
if (!getFlags().getDumpStats())
return;
@@ -997,6 +1042,54 @@
}
}
+void GlobalContext::statsUpdateEmitted(uint32_t InstCount) {
+ if (!getFlags().getDumpStats())
+ return;
+ ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
+ Tls->StatsFunction.update(CodeStats::CS_InstCount, InstCount);
+ Tls->StatsCumulative.update(CodeStats::CS_InstCount, InstCount);
+}
+
+void GlobalContext::statsUpdateRegistersSaved(uint32_t Num) {
+ if (!getFlags().getDumpStats())
+ return;
+ ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
+ Tls->StatsFunction.update(CodeStats::CS_RegsSaved, Num);
+ Tls->StatsCumulative.update(CodeStats::CS_RegsSaved, Num);
+}
+
+void GlobalContext::statsUpdateFrameBytes(uint32_t Bytes) {
+ if (!getFlags().getDumpStats())
+ return;
+ ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
+ Tls->StatsFunction.update(CodeStats::CS_FrameByte, Bytes);
+ Tls->StatsCumulative.update(CodeStats::CS_FrameByte, Bytes);
+}
+
+void GlobalContext::statsUpdateSpills() {
+ if (!getFlags().getDumpStats())
+ return;
+ ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
+ Tls->StatsFunction.update(CodeStats::CS_NumSpills);
+ Tls->StatsCumulative.update(CodeStats::CS_NumSpills);
+}
+
+void GlobalContext::statsUpdateFills() {
+ if (!getFlags().getDumpStats())
+ return;
+ ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
+ Tls->StatsFunction.update(CodeStats::CS_NumFills);
+ Tls->StatsCumulative.update(CodeStats::CS_NumFills);
+}
+
+void GlobalContext::statsUpdateRPImms() {
+ if (!getFlags().getDumpStats())
+ return;
+ ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
+ Tls->StatsFunction.update(CodeStats::CS_NumRPImms);
+ Tls->StatsCumulative.update(CodeStats::CS_NumRPImms);
+}
+
void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
if (!BuildDefs::timers())
return;
diff --git a/third_party/subzero/src/IceGlobalContext.h b/third_party/subzero/src/IceGlobalContext.h
index aed4341..55b37d8 100644
--- a/third_party/subzero/src/IceGlobalContext.h
+++ b/third_party/subzero/src/IceGlobalContext.h
@@ -297,55 +297,16 @@
ELFObjectWriter *getObjectWriter() const { return ObjectWriter.get(); }
/// Reset stats at the beginning of a function.
- void resetStats() {
- if (BuildDefs::dump())
- ICE_TLS_GET_FIELD(TLS)->StatsFunction.reset();
- }
+ void resetStats();
void dumpStats(const Cfg *Func = nullptr);
- void statsUpdateEmitted(uint32_t InstCount) {
- if (!getFlags().getDumpStats())
- return;
- ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
- Tls->StatsFunction.update(CodeStats::CS_InstCount, InstCount);
- Tls->StatsCumulative.update(CodeStats::CS_InstCount, InstCount);
- }
- void statsUpdateRegistersSaved(uint32_t Num) {
- if (!getFlags().getDumpStats())
- return;
- ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
- Tls->StatsFunction.update(CodeStats::CS_RegsSaved, Num);
- Tls->StatsCumulative.update(CodeStats::CS_RegsSaved, Num);
- }
- void statsUpdateFrameBytes(uint32_t Bytes) {
- if (!getFlags().getDumpStats())
- return;
- ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
- Tls->StatsFunction.update(CodeStats::CS_FrameByte, Bytes);
- Tls->StatsCumulative.update(CodeStats::CS_FrameByte, Bytes);
- }
- void statsUpdateSpills() {
- if (!getFlags().getDumpStats())
- return;
- ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
- Tls->StatsFunction.update(CodeStats::CS_NumSpills);
- Tls->StatsCumulative.update(CodeStats::CS_NumSpills);
- }
- void statsUpdateFills() {
- if (!getFlags().getDumpStats())
- return;
- ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
- Tls->StatsFunction.update(CodeStats::CS_NumFills);
- Tls->StatsCumulative.update(CodeStats::CS_NumFills);
- }
+ void statsUpdateEmitted(uint32_t InstCount);
+ void statsUpdateRegistersSaved(uint32_t Num);
+ void statsUpdateFrameBytes(uint32_t Bytes);
+ void statsUpdateSpills();
+ void statsUpdateFills();
/// Number of Randomized or Pooled Immediates
- void statsUpdateRPImms() {
- if (!getFlags().getDumpStats())
- return;
- ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
- Tls->StatsFunction.update(CodeStats::CS_NumRPImms);
- Tls->StatsCumulative.update(CodeStats::CS_NumRPImms);
- }
+ void statsUpdateRPImms();
/// These are predefined TimerStackIdT values.
enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num };
@@ -403,32 +364,8 @@
std::unique_ptr<EmitterWorkItem> emitQueueBlockingPop();
void emitQueueNotifyEnd() { EmitQ.notifyEnd(); }
- void initParserThread() {
- ThreadContext *Tls = new ThreadContext();
- auto Timers = getTimers();
- Timers->initInto(Tls->Timers);
- AllThreadContexts.push_back(Tls);
- ICE_TLS_SET_FIELD(TLS, Tls);
- }
-
- void startWorkerThreads() {
- size_t NumWorkers = getFlags().getNumTranslationThreads();
- auto Timers = getTimers();
- for (size_t i = 0; i < NumWorkers; ++i) {
- ThreadContext *WorkerTLS = new ThreadContext();
- Timers->initInto(WorkerTLS->Timers);
- AllThreadContexts.push_back(WorkerTLS);
- TranslationThreads.push_back(std::thread(
- &GlobalContext::translateFunctionsWrapper, this, WorkerTLS));
- }
- if (NumWorkers) {
- ThreadContext *WorkerTLS = new ThreadContext();
- Timers->initInto(WorkerTLS->Timers);
- AllThreadContexts.push_back(WorkerTLS);
- EmitterThreads.push_back(
- std::thread(&GlobalContext::emitterWrapper, this, WorkerTLS));
- }
- }
+ void initParserThread();
+ void startWorkerThreads();
void waitForWorkerThreads();
@@ -444,18 +381,12 @@
}
/// Translation thread startup routine.
- void translateFunctionsWrapper(ThreadContext *MyTLS) {
- ICE_TLS_SET_FIELD(TLS, MyTLS);
- translateFunctions();
- }
+ void translateFunctionsWrapper(ThreadContext *MyTLS);
/// Translate functions from the Cfg queue until the queue is empty.
void translateFunctions();
/// Emitter thread startup routine.
- void emitterWrapper(ThreadContext *MyTLS) {
- ICE_TLS_SET_FIELD(TLS, MyTLS);
- emitItems();
- }
+ void emitterWrapper(ThreadContext *MyTLS);
/// Emit functions and global initializers from the emitter queue until the
/// queue is empty.
void emitItems();
@@ -643,7 +574,7 @@
ICE_TLS_DECLARE_FIELD(ThreadContext *, TLS);
public:
- static void TlsInit() { ICE_TLS_INIT_FIELD(TLS); }
+ static void TlsInit();
};
/// Helper class to push and pop a timer marker. The constructor pushes a