Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: src/IceGlobalContext.h

Issue 1221643012: Subzero: Add -Wshadow to the build. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /// \file 10 /// \file
(...skipping 28 matching lines...) Expand all
39 class EmitterWorkItem; 39 class EmitterWorkItem;
40 class FuncSigType; 40 class FuncSigType;
41 41
42 /// LockedPtr is a way to provide automatically locked access to some object. 42 /// LockedPtr is a way to provide automatically locked access to some object.
43 template <typename T> class LockedPtr { 43 template <typename T> class LockedPtr {
44 LockedPtr() = delete; 44 LockedPtr() = delete;
45 LockedPtr(const LockedPtr &) = delete; 45 LockedPtr(const LockedPtr &) = delete;
46 LockedPtr &operator=(const LockedPtr &) = delete; 46 LockedPtr &operator=(const LockedPtr &) = delete;
47 47
48 public: 48 public:
49 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { 49 LockedPtr(T *MyValue, GlobalLockType *MyLock) : Value(MyValue), Lock(MyLock) {
50 Lock->lock(); 50 Lock->lock();
51 } 51 }
52 LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) { 52 LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) {
53 Other.Value = nullptr; 53 Other.Value = nullptr;
54 Other.Lock = nullptr; 54 Other.Lock = nullptr;
55 } 55 }
56 ~LockedPtr() { Lock->unlock(); } 56 ~LockedPtr() { Lock->unlock(); }
57 T *operator->() const { return Value; } 57 T *operator->() const { return Value; }
58 58
59 private: 59 private:
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 void emitFileHeader(); 334 void emitFileHeader();
335 335
336 void lowerConstants(); 336 void lowerConstants();
337 337
338 void emitQueueBlockingPush(EmitterWorkItem *Item); 338 void emitQueueBlockingPush(EmitterWorkItem *Item);
339 EmitterWorkItem *emitQueueBlockingPop(); 339 EmitterWorkItem *emitQueueBlockingPop();
340 void emitQueueNotifyEnd() { EmitQ.notifyEnd(); } 340 void emitQueueNotifyEnd() { EmitQ.notifyEnd(); }
341 341
342 void initParserThread() { 342 void initParserThread() {
343 ThreadContext *Tls = new ThreadContext(); 343 ThreadContext *Tls = new ThreadContext();
344 auto Timers = getTimers(); 344 auto MyTimers = getTimers();
345 Timers->initInto(Tls->Timers); 345 MyTimers->initInto(Tls->Timers);
346 AllThreadContexts.push_back(Tls); 346 AllThreadContexts.push_back(Tls);
347 ICE_TLS_SET_FIELD(TLS, Tls); 347 ICE_TLS_SET_FIELD(TLS, Tls);
348 } 348 }
349 349
350 void startWorkerThreads() { 350 void startWorkerThreads() {
351 size_t NumWorkers = getFlags().getNumTranslationThreads(); 351 size_t NumWorkers = getFlags().getNumTranslationThreads();
352 auto Timers = getTimers(); 352 auto MyTimers = getTimers();
353 for (size_t i = 0; i < NumWorkers; ++i) { 353 for (size_t i = 0; i < NumWorkers; ++i) {
354 ThreadContext *WorkerTLS = new ThreadContext(); 354 ThreadContext *WorkerTLS = new ThreadContext();
355 Timers->initInto(WorkerTLS->Timers); 355 MyTimers->initInto(WorkerTLS->Timers);
356 AllThreadContexts.push_back(WorkerTLS); 356 AllThreadContexts.push_back(WorkerTLS);
357 TranslationThreads.push_back(std::thread( 357 TranslationThreads.push_back(std::thread(
358 &GlobalContext::translateFunctionsWrapper, this, WorkerTLS)); 358 &GlobalContext::translateFunctionsWrapper, this, WorkerTLS));
359 } 359 }
360 if (NumWorkers) { 360 if (NumWorkers) {
361 ThreadContext *WorkerTLS = new ThreadContext(); 361 ThreadContext *WorkerTLS = new ThreadContext();
362 Timers->initInto(WorkerTLS->Timers); 362 MyTimers->initInto(WorkerTLS->Timers);
363 AllThreadContexts.push_back(WorkerTLS); 363 AllThreadContexts.push_back(WorkerTLS);
364 EmitterThreads.push_back( 364 EmitterThreads.push_back(
365 std::thread(&GlobalContext::emitterWrapper, this, WorkerTLS)); 365 std::thread(&GlobalContext::emitterWrapper, this, WorkerTLS));
366 } 366 }
367 } 367 }
368 368
369 void waitForWorkerThreads() { 369 void waitForWorkerThreads() {
370 optQueueNotifyEnd(); 370 optQueueNotifyEnd();
371 for (std::thread &Worker : TranslationThreads) { 371 for (std::thread &Worker : TranslationThreads) {
372 Worker.join(); 372 Worker.join();
373 } 373 }
374 TranslationThreads.clear(); 374 TranslationThreads.clear();
375 375
376 // Only notify the emit queue to end after all the translation 376 // Only notify the emit queue to end after all the translation
377 // threads have ended. 377 // threads have ended.
378 emitQueueNotifyEnd(); 378 emitQueueNotifyEnd();
379 for (std::thread &Worker : EmitterThreads) { 379 for (std::thread &Worker : EmitterThreads) {
380 Worker.join(); 380 Worker.join();
381 } 381 }
382 EmitterThreads.clear(); 382 EmitterThreads.clear();
383 383
384 if (BuildDefs::dump()) { 384 if (BuildDefs::dump()) {
385 auto Timers = getTimers(); 385 auto MyTimers = getTimers();
386 for (ThreadContext *TLS : AllThreadContexts) 386 for (ThreadContext *TLS : AllThreadContexts)
387 Timers->mergeFrom(TLS->Timers); 387 MyTimers->mergeFrom(TLS->Timers);
388 } 388 }
389 if (BuildDefs::dump()) { 389 if (BuildDefs::dump()) {
390 // Do a separate loop over AllThreadContexts to avoid holding 390 // Do a separate loop over AllThreadContexts to avoid holding
391 // two locks at once. 391 // two locks at once.
392 auto Stats = getStatsCumulative(); 392 auto Stats = getStatsCumulative();
393 for (ThreadContext *TLS : AllThreadContexts) 393 for (ThreadContext *TLS : AllThreadContexts)
394 Stats->add(TLS->StatsCumulative); 394 Stats->add(TLS->StatsCumulative);
395 } 395 }
396 } 396 }
397 397
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 551
552 /// Helper class to push and pop a timer marker. The constructor 552 /// Helper class to push and pop a timer marker. The constructor
553 /// pushes a marker, and the destructor pops it. This is for 553 /// pushes a marker, and the destructor pops it. This is for
554 /// convenient timing of regions of code. 554 /// convenient timing of regions of code.
555 class TimerMarker { 555 class TimerMarker {
556 TimerMarker() = delete; 556 TimerMarker() = delete;
557 TimerMarker(const TimerMarker &) = delete; 557 TimerMarker(const TimerMarker &) = delete;
558 TimerMarker &operator=(const TimerMarker &) = delete; 558 TimerMarker &operator=(const TimerMarker &) = delete;
559 559
560 public: 560 public:
561 TimerMarker(TimerIdT ID, GlobalContext *Ctx, 561 TimerMarker(TimerIdT MyID, GlobalContext *MyCtx,
562 TimerStackIdT StackID = GlobalContext::TSK_Default) 562 TimerStackIdT MyStackID = GlobalContext::TSK_Default)
563 : ID(ID), Ctx(Ctx), StackID(StackID) { 563 : ID(MyID), Ctx(MyCtx), StackID(MyStackID) {
564 if (BuildDefs::dump()) 564 if (BuildDefs::dump())
565 push(); 565 push();
566 } 566 }
567 TimerMarker(TimerIdT ID, const Cfg *Func, 567 TimerMarker(TimerIdT MyID, const Cfg *Func,
568 TimerStackIdT StackID = GlobalContext::TSK_Default) 568 TimerStackIdT MyStackID = GlobalContext::TSK_Default)
569 : ID(ID), Ctx(nullptr), StackID(StackID) { 569 : ID(MyID), Ctx(nullptr), StackID(MyStackID) {
570 // Ctx gets set at the beginning of pushCfg(). 570 // Ctx gets set at the beginning of pushCfg().
571 if (BuildDefs::dump()) 571 if (BuildDefs::dump())
572 pushCfg(Func); 572 pushCfg(Func);
573 } 573 }
574 574
575 ~TimerMarker() { 575 ~TimerMarker() {
576 if (BuildDefs::dump() && Active) 576 if (BuildDefs::dump() && Active)
577 Ctx->popTimer(ID, StackID); 577 Ctx->popTimer(ID, StackID);
578 } 578 }
579 579
580 private: 580 private:
581 void push(); 581 void push();
582 void pushCfg(const Cfg *Func); 582 void pushCfg(const Cfg *Func);
583 const TimerIdT ID; 583 const TimerIdT ID;
584 GlobalContext *Ctx; 584 GlobalContext *Ctx;
585 const TimerStackIdT StackID; 585 const TimerStackIdT StackID;
586 bool Active = false; 586 bool Active = false;
587 }; 587 };
588 588
589 /// Helper class for locking the streams and then automatically 589 /// Helper class for locking the streams and then automatically
590 /// unlocking them. 590 /// unlocking them.
591 class OstreamLocker { 591 class OstreamLocker {
592 private: 592 private:
593 OstreamLocker() = delete; 593 OstreamLocker() = delete;
594 OstreamLocker(const OstreamLocker &) = delete; 594 OstreamLocker(const OstreamLocker &) = delete;
595 OstreamLocker &operator=(const OstreamLocker &) = delete; 595 OstreamLocker &operator=(const OstreamLocker &) = delete;
596 596
597 public: 597 public:
598 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } 598 explicit OstreamLocker(GlobalContext *MyCtx) : Ctx(MyCtx) { Ctx->lockStr(); }
599 ~OstreamLocker() { Ctx->unlockStr(); } 599 ~OstreamLocker() { Ctx->unlockStr(); }
600 600
601 private: 601 private:
602 GlobalContext *const Ctx; 602 GlobalContext *const Ctx;
603 }; 603 };
604 604
605 } // end of namespace Ice 605 } // end of namespace Ice
606 606
607 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H 607 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698