Chromium Code Reviews| 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 /// \file | 10 /// \file |
| 11 /// This file declares aspects of the compilation that persist across | 11 /// This file declares aspects of the compilation that persist across |
| 12 /// multiple functions. | 12 /// multiple functions. |
| 13 /// | 13 /// |
| 14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
| 15 | 15 |
| 16 #ifndef SUBZERO_SRC_ICEGLOBALCONTEXT_H | 16 #ifndef SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| 17 #define SUBZERO_SRC_ICEGLOBALCONTEXT_H | 17 #define SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| 18 | 18 |
| 19 #include "IceDefs.h" | 19 #include "IceDefs.h" |
| 20 #include "IceClFlags.h" | 20 #include "IceClFlags.h" |
| 21 #include "IceIntrinsics.h" | 21 #include "IceIntrinsics.h" |
| 22 #include "IceRNG.h" | 22 #include "IceRNG.h" |
| 23 #include "IceSwitchLowering.h" | |
| 23 #include "IceThreading.h" | 24 #include "IceThreading.h" |
| 24 #include "IceTimerTree.h" | 25 #include "IceTimerTree.h" |
| 25 #include "IceTypes.h" | 26 #include "IceTypes.h" |
| 26 #include "IceUtils.h" | 27 #include "IceUtils.h" |
| 27 | 28 |
| 28 #include <array> | 29 #include <array> |
| 29 #include <functional> | 30 #include <functional> |
| 30 #include <mutex> | 31 #include <mutex> |
| 31 #include <thread> | 32 #include <thread> |
| 32 #include <type_traits> | 33 #include <type_traits> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 48 public: | 49 public: |
| 49 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { | 50 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { |
| 50 Lock->lock(); | 51 Lock->lock(); |
| 51 } | 52 } |
| 52 LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) { | 53 LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) { |
| 53 Other.Value = nullptr; | 54 Other.Value = nullptr; |
| 54 Other.Lock = nullptr; | 55 Other.Lock = nullptr; |
| 55 } | 56 } |
| 56 ~LockedPtr() { Lock->unlock(); } | 57 ~LockedPtr() { Lock->unlock(); } |
| 57 T *operator->() const { return Value; } | 58 T *operator->() const { return Value; } |
| 59 T &operator*() const { return *Value; } | |
| 58 | 60 |
| 59 private: | 61 private: |
| 60 T *Value; | 62 T *Value; |
| 61 GlobalLockType *Lock; | 63 GlobalLockType *Lock; |
| 62 }; | 64 }; |
| 63 | 65 |
| 64 class GlobalContext { | 66 class GlobalContext { |
| 65 GlobalContext() = delete; | 67 GlobalContext() = delete; |
| 66 GlobalContext(const GlobalContext &) = delete; | 68 GlobalContext(const GlobalContext &) = delete; |
| 67 GlobalContext &operator=(const GlobalContext &) = delete; | 69 GlobalContext &operator=(const GlobalContext &) = delete; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 /// Returns an undef. | 204 /// Returns an undef. |
| 203 Constant *getConstantUndef(Type Ty); | 205 Constant *getConstantUndef(Type Ty); |
| 204 /// Returns a zero value. | 206 /// Returns a zero value. |
| 205 Constant *getConstantZero(Type Ty); | 207 Constant *getConstantZero(Type Ty); |
| 206 /// getConstantPool() returns a copy of the constant pool for | 208 /// getConstantPool() returns a copy of the constant pool for |
| 207 /// constants of a given type. | 209 /// constants of a given type. |
| 208 ConstantList getConstantPool(Type Ty); | 210 ConstantList getConstantPool(Type Ty); |
| 209 /// Returns a copy of the list of external symbols. | 211 /// Returns a copy of the list of external symbols. |
| 210 ConstantList getConstantExternSyms(); | 212 ConstantList getConstantExternSyms(); |
| 211 | 213 |
| 214 /// Return a locked pointer to the registered jump tables. | |
| 215 LockedPtr<std::vector<JumpTableData>> getJumpTables() { | |
| 216 return LockedPtr<std::vector<JumpTableData>>(&JumpTables, &JumpTablesLock); | |
| 217 } | |
| 218 /// Create a new jump table entry and return a reference to it. | |
| 219 JumpTableData &addJumpTable(IceString FuncName, SizeT Id, SizeT NumTargets) { | |
|
jvoung (off chromium)
2015/07/29 21:31:16
Maybe outline this instead of having it inline in
ascull
2015/07/29 22:43:04
Done.
| |
| 220 LockedPtr<std::vector<JumpTableData>> JumpTables = getJumpTables(); | |
| 221 JumpTables->emplace_back(FuncName, Id, NumTargets); | |
| 222 return JumpTables->back(); | |
| 223 } | |
| 224 | |
| 212 const ClFlags &getFlags() const { return Flags; } | 225 const ClFlags &getFlags() const { return Flags; } |
| 213 | 226 |
| 214 bool isIRGenerationDisabled() const { | 227 bool isIRGenerationDisabled() const { |
| 215 return getFlags().getDisableIRGeneration(); | 228 return getFlags().getDisableIRGeneration(); |
| 216 } | 229 } |
| 217 | 230 |
| 218 /// Allocate data of type T using the global allocator. We allow entities | 231 /// Allocate data of type T using the global allocator. We allow entities |
| 219 /// allocated from this global allocator to be either trivially or | 232 /// allocated from this global allocator to be either trivially or |
| 220 /// non-trivially destructible. We optimize the case when T is trivially | 233 /// non-trivially destructible. We optimize the case when T is trivially |
| 221 /// destructible by not registering a destructor. Destructors will be invoked | 234 /// destructible by not registering a destructor. Destructors will be invoked |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 /// called or the Sequential flag was set. | 341 /// called or the Sequential flag was set. |
| 329 std::unique_ptr<Cfg> optQueueBlockingPop(); | 342 std::unique_ptr<Cfg> optQueueBlockingPop(); |
| 330 /// Notifies that no more work will be added to the work queue. | 343 /// Notifies that no more work will be added to the work queue. |
| 331 void optQueueNotifyEnd() { OptQ.notifyEnd(); } | 344 void optQueueNotifyEnd() { OptQ.notifyEnd(); } |
| 332 | 345 |
| 333 /// Emit file header for output file. | 346 /// Emit file header for output file. |
| 334 void emitFileHeader(); | 347 void emitFileHeader(); |
| 335 | 348 |
| 336 void lowerConstants(); | 349 void lowerConstants(); |
| 337 | 350 |
| 351 void lowerJumpTables(); | |
| 352 | |
| 338 void emitQueueBlockingPush(EmitterWorkItem *Item); | 353 void emitQueueBlockingPush(EmitterWorkItem *Item); |
| 339 EmitterWorkItem *emitQueueBlockingPop(); | 354 EmitterWorkItem *emitQueueBlockingPop(); |
| 340 void emitQueueNotifyEnd() { EmitQ.notifyEnd(); } | 355 void emitQueueNotifyEnd() { EmitQ.notifyEnd(); } |
| 341 | 356 |
| 342 void initParserThread() { | 357 void initParserThread() { |
| 343 ThreadContext *Tls = new ThreadContext(); | 358 ThreadContext *Tls = new ThreadContext(); |
| 344 auto Timers = getTimers(); | 359 auto Timers = getTimers(); |
| 345 Timers->initInto(Tls->Timers); | 360 Timers->initInto(Tls->Timers); |
| 346 AllThreadContexts.push_back(Tls); | 361 AllThreadContexts.push_back(Tls); |
| 347 ICE_TLS_SET_FIELD(TLS, Tls); | 362 ICE_TLS_SET_FIELD(TLS, Tls); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 typedef std::vector<std::function<void()>> DestructorArray; | 464 typedef std::vector<std::function<void()>> DestructorArray; |
| 450 GlobalLockType DestructorsLock; | 465 GlobalLockType DestructorsLock; |
| 451 DestructorArray Destructors; | 466 DestructorArray Destructors; |
| 452 | 467 |
| 453 ICE_CACHELINE_BOUNDARY; | 468 ICE_CACHELINE_BOUNDARY; |
| 454 // Managed by getConstantPool() | 469 // Managed by getConstantPool() |
| 455 GlobalLockType ConstPoolLock; | 470 GlobalLockType ConstPoolLock; |
| 456 std::unique_ptr<ConstantPool> ConstPool; | 471 std::unique_ptr<ConstantPool> ConstPool; |
| 457 | 472 |
| 458 ICE_CACHELINE_BOUNDARY; | 473 ICE_CACHELINE_BOUNDARY; |
| 474 // Managed by getJumpTables() | |
| 475 GlobalLockType JumpTablesLock; | |
| 476 std::vector<JumpTableData> JumpTables; | |
| 477 | |
| 478 ICE_CACHELINE_BOUNDARY; | |
| 459 // Managed by getErrorStatus() | 479 // Managed by getErrorStatus() |
| 460 GlobalLockType ErrorStatusLock; | 480 GlobalLockType ErrorStatusLock; |
| 461 ErrorCode ErrorStatus; | 481 ErrorCode ErrorStatus; |
| 462 | 482 |
| 463 ICE_CACHELINE_BOUNDARY; | 483 ICE_CACHELINE_BOUNDARY; |
| 464 // Managed by getStatsCumulative() | 484 // Managed by getStatsCumulative() |
| 465 GlobalLockType StatsLock; | 485 GlobalLockType StatsLock; |
| 466 CodeStats StatsCumulative; | 486 CodeStats StatsCumulative; |
| 467 | 487 |
| 468 ICE_CACHELINE_BOUNDARY; | 488 ICE_CACHELINE_BOUNDARY; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 618 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } |
| 599 ~OstreamLocker() { Ctx->unlockStr(); } | 619 ~OstreamLocker() { Ctx->unlockStr(); } |
| 600 | 620 |
| 601 private: | 621 private: |
| 602 GlobalContext *const Ctx; | 622 GlobalContext *const Ctx; |
| 603 }; | 623 }; |
| 604 | 624 |
| 605 } // end of namespace Ice | 625 } // end of namespace Ice |
| 606 | 626 |
| 607 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 627 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| OLD | NEW |