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

Side by Side Diff: src/IceGlobalContext.h

Issue 1834473002: Allow Subzero to parse function blocks in parallel. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Clean up code. Created 4 years, 9 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 ~LockedPtr() { Lock->unlock(); } 70 ~LockedPtr() { Lock->unlock(); }
71 T *operator->() const { return Value; } 71 T *operator->() const { return Value; }
72 T &operator*() const { return *Value; } 72 T &operator*() const { return *Value; }
73 T *get() { return Value; } 73 T *get() { return Value; }
74 74
75 private: 75 private:
76 T *Value; 76 T *Value;
77 GlobalLockType *Lock; 77 GlobalLockType *Lock;
78 }; 78 };
79 79
80 /// OptWorkItem is a simple wrapper used to pass parse information on a function
81 /// block, to a translator thread.
82 class OptWorkItem {
83 OptWorkItem(const OptWorkItem &) = delete;
84 OptWorkItem &operator=(const OptWorkItem &) = delete;
85
86 public:
87 // Get the Cfg for the funtion to translate.
88 virtual std::unique_ptr<Cfg> getParsedCfg() = 0;
89 virtual ~OptWorkItem() {}
90
91 protected:
92 OptWorkItem() {}
93 };
94
80 class GlobalContext { 95 class GlobalContext {
81 GlobalContext() = delete; 96 GlobalContext() = delete;
82 GlobalContext(const GlobalContext &) = delete; 97 GlobalContext(const GlobalContext &) = delete;
83 GlobalContext &operator=(const GlobalContext &) = delete; 98 GlobalContext &operator=(const GlobalContext &) = delete;
84 99
85 /// CodeStats collects rudimentary statistics during translation. 100 /// CodeStats collects rudimentary statistics during translation.
86 class CodeStats { 101 class CodeStats {
87 CodeStats(const CodeStats &) = delete; 102 CodeStats(const CodeStats &) = delete;
88 CodeStats &operator=(const CodeStats &) = default; 103 CodeStats &operator=(const CodeStats &) = default;
89 #define CODESTATS_TABLE \ 104 #define CODESTATS_TABLE \
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 /// This is the first work item sequence number that the parser produces, and 386 /// This is the first work item sequence number that the parser produces, and
372 /// correspondingly the first sequence number that the emitter thread will 387 /// correspondingly the first sequence number that the emitter thread will
373 /// wait for. Start numbering at 1 to leave room for a sentinel, in case e.g. 388 /// wait for. Start numbering at 1 to leave room for a sentinel, in case e.g.
374 /// we wish to inject items with a special sequence number that may be 389 /// we wish to inject items with a special sequence number that may be
375 /// executed out of order. 390 /// executed out of order.
376 static uint32_t getFirstSequenceNumber() { return 1; } 391 static uint32_t getFirstSequenceNumber() { return 1; }
377 /// Adds a newly parsed and constructed function to the Cfg work queue. 392 /// Adds a newly parsed and constructed function to the Cfg work queue.
378 /// Notifies any idle workers that a new function is available for 393 /// Notifies any idle workers that a new function is available for
379 /// translating. May block if the work queue is too large, in order to control 394 /// translating. May block if the work queue is too large, in order to control
380 /// memory footprint. 395 /// memory footprint.
381 void optQueueBlockingPush(std::unique_ptr<Cfg> Func); 396 void optQueueBlockingPush(std::unique_ptr<OptWorkItem> Item);
382 /// Takes a Cfg from the work queue for translating. May block if the work 397 /// Takes a Cfg from the work queue for translating. May block if the work
383 /// queue is currently empty. Returns nullptr if there is no more work - the 398 /// queue is currently empty. Returns nullptr if there is no more work - the
384 /// queue is empty and either end() has been called or the Sequential flag was 399 /// queue is empty and either end() has been called or the Sequential flag was
385 /// set. 400 /// set.
386 std::unique_ptr<Cfg> optQueueBlockingPop(); 401 std::unique_ptr<OptWorkItem> optQueueBlockingPop();
387 /// Notifies that no more work will be added to the work queue. 402 /// Notifies that no more work will be added to the work queue.
388 void optQueueNotifyEnd() { OptQ.notifyEnd(); } 403 void optQueueNotifyEnd() { OptQ.notifyEnd(); }
389 404
390 /// Emit file header for output file. 405 /// Emit file header for output file.
391 void emitFileHeader(); 406 void emitFileHeader();
392 407
393 void lowerConstants(); 408 void lowerConstants();
394 409
395 void lowerJumpTables(); 410 void lowerJumpTables();
396 411
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 StrLockType StrLock; 571 StrLockType StrLock;
557 Ostream *StrDump; /// Stream for dumping / diagnostics 572 Ostream *StrDump; /// Stream for dumping / diagnostics
558 Ostream *StrEmit; /// Stream for code emission 573 Ostream *StrEmit; /// Stream for code emission
559 Ostream *StrError; /// Stream for logging errors. 574 Ostream *StrError; /// Stream for logging errors.
560 575
561 ICE_CACHELINE_BOUNDARY; 576 ICE_CACHELINE_BOUNDARY;
562 577
563 Intrinsics IntrinsicsInfo; 578 Intrinsics IntrinsicsInfo;
564 // TODO(jpp): move to EmitterContext. 579 // TODO(jpp): move to EmitterContext.
565 std::unique_ptr<ELFObjectWriter> ObjectWriter; 580 std::unique_ptr<ELFObjectWriter> ObjectWriter;
566 BoundedProducerConsumerQueue<Cfg> OptQ; 581 static constexpr size_t MaxOptQSize = 1 << 16;
582 BoundedProducerConsumerQueue<OptWorkItem, MaxOptQSize> OptQ;
567 BoundedProducerConsumerQueue<EmitterWorkItem> EmitQ; 583 BoundedProducerConsumerQueue<EmitterWorkItem> EmitQ;
568 // DataLowering is only ever used by a single thread at a time (either in 584 // DataLowering is only ever used by a single thread at a time (either in
569 // emitItems(), or in IceCompiler::run before the compilation is over.) 585 // emitItems(), or in IceCompiler::run before the compilation is over.)
570 // TODO(jpp): move to EmitterContext. 586 // TODO(jpp): move to EmitterContext.
571 std::unique_ptr<TargetDataLowering> DataLowering; 587 std::unique_ptr<TargetDataLowering> DataLowering;
572 /// If !HasEmittedCode, SubZero will accumulate all Globals (which are "true" 588 /// If !HasEmittedCode, SubZero will accumulate all Globals (which are "true"
573 /// program global variables) until the first code WorkItem is seen. 589 /// program global variables) until the first code WorkItem is seen.
574 // TODO(jpp): move to EmitterContext. 590 // TODO(jpp): move to EmitterContext.
575 bool HasSeenCode = false; 591 bool HasSeenCode = false;
576 // TODO(jpp): move to EmitterContext. 592 // TODO(jpp): move to EmitterContext.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } 713 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); }
698 ~OstreamLocker() { Ctx->unlockStr(); } 714 ~OstreamLocker() { Ctx->unlockStr(); }
699 715
700 private: 716 private:
701 GlobalContext *const Ctx; 717 GlobalContext *const Ctx;
702 }; 718 };
703 719
704 } // end of namespace Ice 720 } // end of namespace Ice
705 721
706 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H 722 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698