| OLD | NEW |
| 1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// | 1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file declares aspects of the compilation that persist across | 10 // This file declares aspects of the compilation that persist across |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 class EmitterWorkItem; | 38 class EmitterWorkItem; |
| 39 class FuncSigType; | 39 class FuncSigType; |
| 40 | 40 |
| 41 // LockedPtr is a way to provide automatically locked access to some object. | 41 // LockedPtr is a way to provide automatically locked access to some object. |
| 42 template <typename T> class LockedPtr { | 42 template <typename T> class LockedPtr { |
| 43 LockedPtr() = delete; | 43 LockedPtr() = delete; |
| 44 LockedPtr(const LockedPtr &) = delete; | 44 LockedPtr(const LockedPtr &) = delete; |
| 45 LockedPtr &operator=(const LockedPtr &) = delete; | 45 LockedPtr &operator=(const LockedPtr &) = delete; |
| 46 | 46 |
| 47 public: | 47 public: |
| 48 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { | 48 LockedPtr(T *MyValue, GlobalLockType *MyLock) : Value(MyValue), Lock(MyLock) { |
| 49 Lock->lock(); | 49 Lock->lock(); |
| 50 } | 50 } |
| 51 LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) { | 51 LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) { |
| 52 Other.Value = nullptr; | 52 Other.Value = nullptr; |
| 53 Other.Lock = nullptr; | 53 Other.Lock = nullptr; |
| 54 } | 54 } |
| 55 ~LockedPtr() { Lock->unlock(); } | 55 ~LockedPtr() { Lock->unlock(); } |
| 56 T *operator->() const { return Value; } | 56 T *operator->() const { return Value; } |
| 57 | 57 |
| 58 private: | 58 private: |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 void emitFileHeader(); | 333 void emitFileHeader(); |
| 334 | 334 |
| 335 void lowerConstants(); | 335 void lowerConstants(); |
| 336 | 336 |
| 337 void emitQueueBlockingPush(EmitterWorkItem *Item); | 337 void emitQueueBlockingPush(EmitterWorkItem *Item); |
| 338 EmitterWorkItem *emitQueueBlockingPop(); | 338 EmitterWorkItem *emitQueueBlockingPop(); |
| 339 void emitQueueNotifyEnd() { EmitQ.notifyEnd(); } | 339 void emitQueueNotifyEnd() { EmitQ.notifyEnd(); } |
| 340 | 340 |
| 341 void initParserThread() { | 341 void initParserThread() { |
| 342 ThreadContext *Tls = new ThreadContext(); | 342 ThreadContext *Tls = new ThreadContext(); |
| 343 auto Timers = getTimers(); | 343 auto MyTimers = getTimers(); |
| 344 Timers->initInto(Tls->Timers); | 344 MyTimers->initInto(Tls->Timers); |
| 345 AllThreadContexts.push_back(Tls); | 345 AllThreadContexts.push_back(Tls); |
| 346 ICE_TLS_SET_FIELD(TLS, Tls); | 346 ICE_TLS_SET_FIELD(TLS, Tls); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void startWorkerThreads() { | 349 void startWorkerThreads() { |
| 350 size_t NumWorkers = getFlags().getNumTranslationThreads(); | 350 size_t NumWorkers = getFlags().getNumTranslationThreads(); |
| 351 auto Timers = getTimers(); | 351 auto MyTimers = getTimers(); |
| 352 for (size_t i = 0; i < NumWorkers; ++i) { | 352 for (size_t i = 0; i < NumWorkers; ++i) { |
| 353 ThreadContext *WorkerTLS = new ThreadContext(); | 353 ThreadContext *WorkerTLS = new ThreadContext(); |
| 354 Timers->initInto(WorkerTLS->Timers); | 354 MyTimers->initInto(WorkerTLS->Timers); |
| 355 AllThreadContexts.push_back(WorkerTLS); | 355 AllThreadContexts.push_back(WorkerTLS); |
| 356 TranslationThreads.push_back(std::thread( | 356 TranslationThreads.push_back(std::thread( |
| 357 &GlobalContext::translateFunctionsWrapper, this, WorkerTLS)); | 357 &GlobalContext::translateFunctionsWrapper, this, WorkerTLS)); |
| 358 } | 358 } |
| 359 if (NumWorkers) { | 359 if (NumWorkers) { |
| 360 ThreadContext *WorkerTLS = new ThreadContext(); | 360 ThreadContext *WorkerTLS = new ThreadContext(); |
| 361 Timers->initInto(WorkerTLS->Timers); | 361 MyTimers->initInto(WorkerTLS->Timers); |
| 362 AllThreadContexts.push_back(WorkerTLS); | 362 AllThreadContexts.push_back(WorkerTLS); |
| 363 EmitterThreads.push_back( | 363 EmitterThreads.push_back( |
| 364 std::thread(&GlobalContext::emitterWrapper, this, WorkerTLS)); | 364 std::thread(&GlobalContext::emitterWrapper, this, WorkerTLS)); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 void waitForWorkerThreads() { | 368 void waitForWorkerThreads() { |
| 369 optQueueNotifyEnd(); | 369 optQueueNotifyEnd(); |
| 370 for (std::thread &Worker : TranslationThreads) { | 370 for (std::thread &Worker : TranslationThreads) { |
| 371 Worker.join(); | 371 Worker.join(); |
| 372 } | 372 } |
| 373 TranslationThreads.clear(); | 373 TranslationThreads.clear(); |
| 374 | 374 |
| 375 // Only notify the emit queue to end after all the translation | 375 // Only notify the emit queue to end after all the translation |
| 376 // threads have ended. | 376 // threads have ended. |
| 377 emitQueueNotifyEnd(); | 377 emitQueueNotifyEnd(); |
| 378 for (std::thread &Worker : EmitterThreads) { | 378 for (std::thread &Worker : EmitterThreads) { |
| 379 Worker.join(); | 379 Worker.join(); |
| 380 } | 380 } |
| 381 EmitterThreads.clear(); | 381 EmitterThreads.clear(); |
| 382 | 382 |
| 383 if (BuildDefs::dump()) { | 383 if (BuildDefs::dump()) { |
| 384 auto Timers = getTimers(); | 384 auto MyTimers = getTimers(); |
| 385 for (ThreadContext *TLS : AllThreadContexts) | 385 for (ThreadContext *TLS : AllThreadContexts) |
| 386 Timers->mergeFrom(TLS->Timers); | 386 MyTimers->mergeFrom(TLS->Timers); |
| 387 } | 387 } |
| 388 if (BuildDefs::dump()) { | 388 if (BuildDefs::dump()) { |
| 389 // Do a separate loop over AllThreadContexts to avoid holding | 389 // Do a separate loop over AllThreadContexts to avoid holding |
| 390 // two locks at once. | 390 // two locks at once. |
| 391 auto Stats = getStatsCumulative(); | 391 auto Stats = getStatsCumulative(); |
| 392 for (ThreadContext *TLS : AllThreadContexts) | 392 for (ThreadContext *TLS : AllThreadContexts) |
| 393 Stats->add(TLS->StatsCumulative); | 393 Stats->add(TLS->StatsCumulative); |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 | 396 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 550 |
| 551 // Helper class to push and pop a timer marker. The constructor | 551 // Helper class to push and pop a timer marker. The constructor |
| 552 // pushes a marker, and the destructor pops it. This is for | 552 // pushes a marker, and the destructor pops it. This is for |
| 553 // convenient timing of regions of code. | 553 // convenient timing of regions of code. |
| 554 class TimerMarker { | 554 class TimerMarker { |
| 555 TimerMarker() = delete; | 555 TimerMarker() = delete; |
| 556 TimerMarker(const TimerMarker &) = delete; | 556 TimerMarker(const TimerMarker &) = delete; |
| 557 TimerMarker &operator=(const TimerMarker &) = delete; | 557 TimerMarker &operator=(const TimerMarker &) = delete; |
| 558 | 558 |
| 559 public: | 559 public: |
| 560 TimerMarker(TimerIdT ID, GlobalContext *Ctx, | 560 TimerMarker(TimerIdT MyID, GlobalContext *MyCtx, |
| 561 TimerStackIdT StackID = GlobalContext::TSK_Default) | 561 TimerStackIdT MyStackID = GlobalContext::TSK_Default) |
| 562 : ID(ID), Ctx(Ctx), StackID(StackID) { | 562 : ID(MyID), Ctx(MyCtx), StackID(MyStackID) { |
| 563 if (BuildDefs::dump()) | 563 if (BuildDefs::dump()) |
| 564 push(); | 564 push(); |
| 565 } | 565 } |
| 566 TimerMarker(TimerIdT ID, const Cfg *Func, | 566 TimerMarker(TimerIdT MyID, const Cfg *Func, |
| 567 TimerStackIdT StackID = GlobalContext::TSK_Default) | 567 TimerStackIdT MyStackID = GlobalContext::TSK_Default) |
| 568 : ID(ID), Ctx(nullptr), StackID(StackID) { | 568 : ID(MyID), Ctx(nullptr), StackID(MyStackID) { |
| 569 // Ctx gets set at the beginning of pushCfg(). | 569 // Ctx gets set at the beginning of pushCfg(). |
| 570 if (BuildDefs::dump()) | 570 if (BuildDefs::dump()) |
| 571 pushCfg(Func); | 571 pushCfg(Func); |
| 572 } | 572 } |
| 573 | 573 |
| 574 ~TimerMarker() { | 574 ~TimerMarker() { |
| 575 if (BuildDefs::dump() && Active) | 575 if (BuildDefs::dump() && Active) |
| 576 Ctx->popTimer(ID, StackID); | 576 Ctx->popTimer(ID, StackID); |
| 577 } | 577 } |
| 578 | 578 |
| 579 private: | 579 private: |
| 580 void push(); | 580 void push(); |
| 581 void pushCfg(const Cfg *Func); | 581 void pushCfg(const Cfg *Func); |
| 582 const TimerIdT ID; | 582 const TimerIdT ID; |
| 583 GlobalContext *Ctx; | 583 GlobalContext *Ctx; |
| 584 const TimerStackIdT StackID; | 584 const TimerStackIdT StackID; |
| 585 bool Active = false; | 585 bool Active = false; |
| 586 }; | 586 }; |
| 587 | 587 |
| 588 // Helper class for locking the streams and then automatically | 588 // Helper class for locking the streams and then automatically |
| 589 // unlocking them. | 589 // unlocking them. |
| 590 class OstreamLocker { | 590 class OstreamLocker { |
| 591 private: | 591 private: |
| 592 OstreamLocker() = delete; | 592 OstreamLocker() = delete; |
| 593 OstreamLocker(const OstreamLocker &) = delete; | 593 OstreamLocker(const OstreamLocker &) = delete; |
| 594 OstreamLocker &operator=(const OstreamLocker &) = delete; | 594 OstreamLocker &operator=(const OstreamLocker &) = delete; |
| 595 | 595 |
| 596 public: | 596 public: |
| 597 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 597 explicit OstreamLocker(GlobalContext *MyCtx) : Ctx(MyCtx) { Ctx->lockStr(); } |
| 598 ~OstreamLocker() { Ctx->unlockStr(); } | 598 ~OstreamLocker() { Ctx->unlockStr(); } |
| 599 | 599 |
| 600 private: | 600 private: |
| 601 GlobalContext *const Ctx; | 601 GlobalContext *const Ctx; |
| 602 }; | 602 }; |
| 603 | 603 |
| 604 } // end of namespace Ice | 604 } // end of namespace Ice |
| 605 | 605 |
| 606 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 606 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| OLD | NEW |