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