| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 ThreadContext &operator=(const ThreadContext &) = delete; | 138 ThreadContext &operator=(const ThreadContext &) = delete; |
| 139 | 139 |
| 140 public: | 140 public: |
| 141 ThreadContext() {} | 141 ThreadContext() {} |
| 142 CodeStats StatsFunction; | 142 CodeStats StatsFunction; |
| 143 CodeStats StatsCumulative; | 143 CodeStats StatsCumulative; |
| 144 TimerList Timers; | 144 TimerList Timers; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 public: | 147 public: |
| 148 // The dump stream is a log stream while emit is the stream code |
| 149 // is emitted to. The error stream is strictly for logging errors. |
| 150 // If an error stream is not provided, the dump stream will be |
| 151 // used instead. |
| 148 GlobalContext(Ostream *OsDump, Ostream *OsEmit, ELFStreamer *ELFStreamer, | 152 GlobalContext(Ostream *OsDump, Ostream *OsEmit, ELFStreamer *ELFStreamer, |
| 149 const ClFlags &Flags); | 153 const ClFlags &Flags, Ostream *OsError = nullptr); |
| 150 ~GlobalContext(); | 154 ~GlobalContext(); |
| 151 | 155 |
| 152 // The dump and emit streams need to be used by only one thread at a | 156 // |
| 153 // time. This is done by exclusively reserving the streams via | 157 // The dump, error, and emit streams need to be used by only one |
| 154 // lockStr() and unlockStr(). The OstreamLocker class can be used | 158 // thread at a time. This is done by exclusively reserving the |
| 155 // to conveniently manage this. | 159 // streams via lockStr() and unlockStr(). The OstreamLocker class |
| 160 // can be used to conveniently manage this. |
| 156 // | 161 // |
| 157 // The model is that a thread grabs the stream lock, then does an | 162 // The model is that a thread grabs the stream lock, then does an |
| 158 // arbitrary amount of work during which far-away callees may grab | 163 // arbitrary amount of work during which far-away callees may grab |
| 159 // the stream and do something with it, and finally the thread | 164 // the stream and do something with it, and finally the thread |
| 160 // releases the stream lock. This allows large chunks of output to | 165 // releases the stream lock. This allows large chunks of output to |
| 161 // be dumped or emitted without risking interleaving from multiple | 166 // be dumped or emitted without risking interleaving from multiple |
| 162 // threads. | 167 // threads. |
| 163 void lockStr() { StrLock.lock(); } | 168 void lockStr() { StrLock.lock(); } |
| 164 void unlockStr() { StrLock.unlock(); } | 169 void unlockStr() { StrLock.unlock(); } |
| 165 Ostream &getStrDump() { return *StrDump; } | 170 Ostream &getStrDump() { return *StrDump; } |
| 171 Ostream &getStrError() { return StrError ? *StrError : *StrDump; } |
| 166 Ostream &getStrEmit() { return *StrEmit; } | 172 Ostream &getStrEmit() { return *StrEmit; } |
| 167 | 173 |
| 168 LockedPtr<ErrorCode> getErrorStatus() { | 174 LockedPtr<ErrorCode> getErrorStatus() { |
| 169 return LockedPtr<ErrorCode>(&ErrorStatus, &ErrorStatusLock); | 175 return LockedPtr<ErrorCode>(&ErrorStatus, &ErrorStatusLock); |
| 170 } | 176 } |
| 171 | 177 |
| 172 // When emitting assembly, we allow a string to be prepended to | 178 // When emitting assembly, we allow a string to be prepended to |
| 173 // names of translated functions. This makes it easier to create an | 179 // names of translated functions. This makes it easier to create an |
| 174 // execution test against a reference translator like llc, with both | 180 // execution test against a reference translator like llc, with both |
| 175 // translators using the same bitcode as input. | 181 // translators using the same bitcode as input. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // Managed by getTimers() | 417 // Managed by getTimers() |
| 412 GlobalLockType TimerLock; | 418 GlobalLockType TimerLock; |
| 413 TimerList Timers; | 419 TimerList Timers; |
| 414 | 420 |
| 415 ICE_CACHELINE_BOUNDARY; | 421 ICE_CACHELINE_BOUNDARY; |
| 416 // StrLock is a global lock on the dump and emit output streams. | 422 // StrLock is a global lock on the dump and emit output streams. |
| 417 typedef std::mutex StrLockType; | 423 typedef std::mutex StrLockType; |
| 418 StrLockType StrLock; | 424 StrLockType StrLock; |
| 419 Ostream *StrDump; // Stream for dumping / diagnostics | 425 Ostream *StrDump; // Stream for dumping / diagnostics |
| 420 Ostream *StrEmit; // Stream for code emission | 426 Ostream *StrEmit; // Stream for code emission |
| 427 Ostream *StrError; // If non-null, stream for logging errors. |
| 421 | 428 |
| 422 ICE_CACHELINE_BOUNDARY; | 429 ICE_CACHELINE_BOUNDARY; |
| 423 | 430 |
| 424 Intrinsics IntrinsicsInfo; | 431 Intrinsics IntrinsicsInfo; |
| 425 const ClFlags &Flags; | 432 const ClFlags &Flags; |
| 426 RandomNumberGenerator RNG; // TODO(stichnot): Move into Cfg. | 433 RandomNumberGenerator RNG; // TODO(stichnot): Move into Cfg. |
| 427 std::unique_ptr<ELFObjectWriter> ObjectWriter; | 434 std::unique_ptr<ELFObjectWriter> ObjectWriter; |
| 428 BoundedProducerConsumerQueue<Cfg> OptQ; | 435 BoundedProducerConsumerQueue<Cfg> OptQ; |
| 429 BoundedProducerConsumerQueue<EmitterWorkItem> EmitQ; | 436 BoundedProducerConsumerQueue<EmitterWorkItem> EmitQ; |
| 430 | 437 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 512 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } |
| 506 ~OstreamLocker() { Ctx->unlockStr(); } | 513 ~OstreamLocker() { Ctx->unlockStr(); } |
| 507 | 514 |
| 508 private: | 515 private: |
| 509 GlobalContext *const Ctx; | 516 GlobalContext *const Ctx; |
| 510 }; | 517 }; |
| 511 | 518 |
| 512 } // end of namespace Ice | 519 } // end of namespace Ice |
| 513 | 520 |
| 514 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 521 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| OLD | NEW |