Commit 04e9b1ce by Lei Zhang Committed by Nicolas Capens

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/12688Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 33438a68
...@@ -372,6 +372,11 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, ...@@ -372,6 +372,11 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError,
} }
} }
void GlobalContext::translateFunctionsWrapper(ThreadContext *MyTLS) {
ICE_TLS_SET_FIELD(TLS, MyTLS);
translateFunctions();
}
void GlobalContext::translateFunctions() { void GlobalContext::translateFunctions() {
TimerMarker Timer(TimerStack::TT_translateFunctions, this); TimerMarker Timer(TimerStack::TT_translateFunctions, this);
while (std::unique_ptr<OptWorkItem> OptItem = optQueueBlockingPop()) { while (std::unique_ptr<OptWorkItem> OptItem = optQueueBlockingPop()) {
...@@ -454,6 +459,9 @@ void resizePending(std::vector<std::unique_ptr<EmitterWorkItem>> *Pending, ...@@ -454,6 +459,9 @@ void resizePending(std::vector<std::unique_ptr<EmitterWorkItem>> *Pending,
} // end of anonymous namespace } // end of anonymous namespace
// static
void GlobalContext::TlsInit() { ICE_TLS_INIT_FIELD(TLS); }
void GlobalContext::emitFileHeader() { void GlobalContext::emitFileHeader() {
TimerMarker T1(Ice::TimerStack::TT_emitAsm, this); TimerMarker T1(Ice::TimerStack::TT_emitAsm, this);
if (getFlags().getOutFileType() == FT_Elf) { if (getFlags().getOutFileType() == FT_Elf) {
...@@ -556,6 +564,11 @@ void GlobalContext::lowerProfileData() { ...@@ -556,6 +564,11 @@ void GlobalContext::lowerProfileData() {
lowerGlobals(ProfileDataSection); lowerGlobals(ProfileDataSection);
} }
void GlobalContext::emitterWrapper(ThreadContext *MyTLS) {
ICE_TLS_SET_FIELD(TLS, MyTLS);
emitItems();
}
void GlobalContext::emitItems() { void GlobalContext::emitItems() {
const bool Threaded = !getFlags().isSequential(); const bool Threaded = !getFlags().isSequential();
// Pending is a vector containing the reassembled, ordered list of // Pending is a vector containing the reassembled, ordered list of
...@@ -987,6 +1000,38 @@ std::unique_ptr<EmitterWorkItem> GlobalContext::emitQueueBlockingPop() { ...@@ -987,6 +1000,38 @@ std::unique_ptr<EmitterWorkItem> GlobalContext::emitQueueBlockingPop() {
return EmitQ.blockingPop(); 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) { void GlobalContext::dumpStats(const Cfg *Func) {
if (!getFlags().getDumpStats()) if (!getFlags().getDumpStats())
return; return;
...@@ -997,6 +1042,54 @@ void GlobalContext::dumpStats(const Cfg *Func) { ...@@ -997,6 +1042,54 @@ void GlobalContext::dumpStats(const Cfg *Func) {
} }
} }
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) { void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
if (!BuildDefs::timers()) if (!BuildDefs::timers())
return; return;
......
...@@ -297,55 +297,16 @@ public: ...@@ -297,55 +297,16 @@ public:
ELFObjectWriter *getObjectWriter() const { return ObjectWriter.get(); } ELFObjectWriter *getObjectWriter() const { return ObjectWriter.get(); }
/// Reset stats at the beginning of a function. /// Reset stats at the beginning of a function.
void resetStats() { void resetStats();
if (BuildDefs::dump())
ICE_TLS_GET_FIELD(TLS)->StatsFunction.reset();
}
void dumpStats(const Cfg *Func = nullptr); void dumpStats(const Cfg *Func = nullptr);
void statsUpdateEmitted(uint32_t InstCount) { void statsUpdateEmitted(uint32_t InstCount);
if (!getFlags().getDumpStats()) void statsUpdateRegistersSaved(uint32_t Num);
return; void statsUpdateFrameBytes(uint32_t Bytes);
ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS); void statsUpdateSpills();
Tls->StatsFunction.update(CodeStats::CS_InstCount, InstCount); void statsUpdateFills();
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);
}
/// Number of Randomized or Pooled Immediates /// Number of Randomized or Pooled Immediates
void statsUpdateRPImms() { 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);
}
/// These are predefined TimerStackIdT values. /// These are predefined TimerStackIdT values.
enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num }; enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num };
...@@ -403,32 +364,8 @@ public: ...@@ -403,32 +364,8 @@ public:
std::unique_ptr<EmitterWorkItem> emitQueueBlockingPop(); std::unique_ptr<EmitterWorkItem> emitQueueBlockingPop();
void emitQueueNotifyEnd() { EmitQ.notifyEnd(); } void emitQueueNotifyEnd() { EmitQ.notifyEnd(); }
void initParserThread() { void initParserThread();
ThreadContext *Tls = new ThreadContext(); void startWorkerThreads();
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 waitForWorkerThreads(); void waitForWorkerThreads();
...@@ -444,18 +381,12 @@ public: ...@@ -444,18 +381,12 @@ public:
} }
/// Translation thread startup routine. /// Translation thread startup routine.
void translateFunctionsWrapper(ThreadContext *MyTLS) { void translateFunctionsWrapper(ThreadContext *MyTLS);
ICE_TLS_SET_FIELD(TLS, MyTLS);
translateFunctions();
}
/// Translate functions from the Cfg queue until the queue is empty. /// Translate functions from the Cfg queue until the queue is empty.
void translateFunctions(); void translateFunctions();
/// Emitter thread startup routine. /// Emitter thread startup routine.
void emitterWrapper(ThreadContext *MyTLS) { void emitterWrapper(ThreadContext *MyTLS);
ICE_TLS_SET_FIELD(TLS, MyTLS);
emitItems();
}
/// Emit functions and global initializers from the emitter queue until the /// Emit functions and global initializers from the emitter queue until the
/// queue is empty. /// queue is empty.
void emitItems(); void emitItems();
...@@ -643,7 +574,7 @@ private: ...@@ -643,7 +574,7 @@ private:
ICE_TLS_DECLARE_FIELD(ThreadContext *, TLS); ICE_TLS_DECLARE_FIELD(ThreadContext *, TLS);
public: 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 /// Helper class to push and pop a timer marker. The constructor pushes a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment