 Chromium Code Reviews
 Chromium Code Reviews Issue 1775253003:
  Cache common constants before lowering.  (Closed) 
  Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
    
  
    Issue 1775253003:
  Cache common constants before lowering.  (Closed) 
  Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master| 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 /// \brief Declares aspects of the compilation that persist across multiple | 11 /// \brief Declares aspects of the compilation that persist across multiple | 
| 12 /// functions. | 12 /// 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 "IceSwitchLowering.h" | 
| 24 #include "IceTargetLowering.def" | |
| 24 #include "IceThreading.h" | 25 #include "IceThreading.h" | 
| 25 #include "IceTimerTree.h" | 26 #include "IceTimerTree.h" | 
| 26 #include "IceTypes.h" | 27 #include "IceTypes.h" | 
| 27 #include "IceUtils.h" | 28 #include "IceUtils.h" | 
| 28 | 29 | 
| 29 #include <array> | 30 #include <array> | 
| 30 #include <functional> | 31 #include <functional> | 
| 31 #include <memory> | 32 #include <memory> | 
| 32 #include <mutex> | 33 #include <mutex> | 
| 33 #include <thread> | 34 #include <thread> | 
| 34 #include <type_traits> | 35 #include <type_traits> | 
| 35 #include <utility> | 36 #include <utility> | 
| 36 #include <vector> | 37 #include <vector> | 
| 37 | 38 | 
| 38 namespace Ice { | 39 namespace Ice { | 
| 39 | 40 | 
| 40 class ClFlags; | 41 class ClFlags; | 
| 41 class ConstantPool; | 42 class ConstantPool; | 
| 42 class EmitterWorkItem; | 43 class EmitterWorkItem; | 
| 43 class FuncSigType; | 44 class FuncSigType; | 
| 44 | 45 | 
| 46 // Runtime helper function ID's | |
| 
Jim Stichnoth
2016/03/17 00:14:52
IDs
 
Karl
2016/03/17 16:40:53
Done.
 | |
| 47 enum RuntimeHelperFuncID { | |
| 
John
2016/03/17 14:31:33
**I think** this should be an inner type (of Globa
 
Karl
2016/03/17 16:40:53
I agree that this enum should be put in an enclosi
 
John
2016/03/17 16:57:17
Please, don't add a namespace. Use a class enum in
 
Karl
2016/03/17 18:54:55
Done.
 | |
| 48 #define X(Tag, Name) H_##Tag, | |
| 49 RUNTIME_HELPER_FUNCTIONS_TABLE | |
| 50 #undef X | |
| 51 H_Num | |
| 52 }; | |
| 53 | |
| 45 /// LockedPtr is a way to provide automatically locked access to some object. | 54 /// LockedPtr is a way to provide automatically locked access to some object. | 
| 46 template <typename T> class LockedPtr { | 55 template <typename T> class LockedPtr { | 
| 47 LockedPtr() = delete; | 56 LockedPtr() = delete; | 
| 48 LockedPtr(const LockedPtr &) = delete; | 57 LockedPtr(const LockedPtr &) = delete; | 
| 49 LockedPtr &operator=(const LockedPtr &) = delete; | 58 LockedPtr &operator=(const LockedPtr &) = delete; | 
| 50 | 59 | 
| 51 public: | 60 public: | 
| 52 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { | 61 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { | 
| 53 Lock->lock(); | 62 Lock->lock(); | 
| 54 } | 63 } | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 191 | 
| 183 LockedPtr<ErrorCode> getErrorStatus() { | 192 LockedPtr<ErrorCode> getErrorStatus() { | 
| 184 return LockedPtr<ErrorCode>(&ErrorStatus, &ErrorStatusLock); | 193 return LockedPtr<ErrorCode>(&ErrorStatus, &ErrorStatusLock); | 
| 185 } | 194 } | 
| 186 | 195 | 
| 187 /// \name Manage Constants. | 196 /// \name Manage Constants. | 
| 188 /// @{ | 197 /// @{ | 
| 189 // getConstant*() functions are not const because they might add something to | 198 // getConstant*() functions are not const because they might add something to | 
| 190 // the constant pool. | 199 // the constant pool. | 
| 191 Constant *getConstantInt(Type Ty, int64_t Value); | 200 Constant *getConstantInt(Type Ty, int64_t Value); | 
| 192 Constant *getConstantInt1(int8_t ConstantInt1); | 201 Constant *getConstantInt1(int8_t ConstantInt1) { | 
| 193 Constant *getConstantInt8(int8_t ConstantInt8); | 202 ConstantInt1 &= INT8_C(1); | 
| 194 Constant *getConstantInt16(int16_t ConstantInt16); | 203 switch (ConstantInt1) { | 
| 195 Constant *getConstantInt32(int32_t ConstantInt32); | 204 case 0: | 
| 196 Constant *getConstantInt64(int64_t ConstantInt64); | 205 return getConstantZero(IceType_i1); | 
| 206 case 1: | |
| 207 return ConstantTrue; | |
| 208 default: | |
| 209 return installConstantInt1(ConstantInt1); | |
| 
John
2016/03/17 14:31:33
maybe assert here -- anything other than {0, 1} sh
 
Karl
2016/03/17 16:40:53
Done.
 | |
| 210 } | |
| 211 } | |
| 212 Constant *getConstantInt8(int8_t ConstantInt8) { | |
| 213 switch (ConstantInt8) { | |
| 214 case 0: | |
| 215 return getConstantZero(IceType_i8); | |
| 216 default: | |
| 217 return installConstantInt8(ConstantInt8); | |
| 218 } | |
| 219 } | |
| 220 Constant *getConstantInt16(int16_t ConstantInt16) { | |
| 221 switch (ConstantInt16) { | |
| 222 case 0: | |
| 223 return getConstantZero(IceType_i16); | |
| 224 default: | |
| 225 return installConstantInt16(ConstantInt16); | |
| 226 } | |
| 227 } | |
| 228 Constant *getConstantInt32(int32_t ConstantInt32) { | |
| 229 switch (ConstantInt32) { | |
| 230 case 0: | |
| 231 return getConstantZero(IceType_i32); | |
| 232 default: | |
| 233 return installConstantInt32(ConstantInt32); | |
| 234 } | |
| 235 } | |
| 236 Constant *getConstantInt64(int64_t ConstantInt64) { | |
| 237 switch (ConstantInt64) { | |
| 238 case 0: | |
| 239 return getConstantZero(IceType_i64); | |
| 240 default: | |
| 241 return installConstantInt64(ConstantInt64); | |
| 242 } | |
| 243 } | |
| 197 Constant *getConstantFloat(float Value); | 244 Constant *getConstantFloat(float Value); | 
| 198 Constant *getConstantDouble(double Value); | 245 Constant *getConstantDouble(double Value); | 
| 199 /// Returns a symbolic constant. | 246 /// Returns a symbolic constant. | 
| 200 Constant *getConstantSym(const RelocOffsetT Offset, | 247 Constant *getConstantSym(const RelocOffsetT Offset, | 
| 201 const RelocOffsetArray &OffsetExpr, | 248 const RelocOffsetArray &OffsetExpr, | 
| 202 const IceString &Name, const IceString &EmitString); | 249 const IceString &Name, const IceString &EmitString); | 
| 203 Constant *getConstantSym(RelocOffsetT Offset, const IceString &Name); | 250 Constant *getConstantSym(RelocOffsetT Offset, const IceString &Name); | 
| 204 Constant *getConstantExternSym(const IceString &Name); | 251 Constant *getConstantExternSym(const IceString &Name); | 
| 205 /// Returns an undef. | 252 /// Returns an undef. | 
| 206 Constant *getConstantUndef(Type Ty); | 253 Constant *getConstantUndef(Type Ty); | 
| 207 /// Returns a zero value. | 254 /// Returns a zero value. | 
| 208 Constant *getConstantZero(Type Ty); | 255 Constant *getConstantZero(Type Ty) { | 
| 256 Constant *Zero = ConstZeroForType[Ty]; | |
| 257 assert(Zero && "Unsupported zero constant"); | |
| 258 return Zero; | |
| 259 } | |
| 209 /// getConstantPool() returns a copy of the constant pool for constants of a | 260 /// getConstantPool() returns a copy of the constant pool for constants of a | 
| 210 /// given type. | 261 /// given type. | 
| 211 ConstantList getConstantPool(Type Ty); | 262 ConstantList getConstantPool(Type Ty); | 
| 212 /// Returns a copy of the list of external symbols. | 263 /// Returns a copy of the list of external symbols. | 
| 213 ConstantList getConstantExternSyms(); | 264 ConstantList getConstantExternSyms(); | 
| 214 /// @} | 265 /// @} | 
| 266 Constant *getRuntimeHelperFunc(RuntimeHelperFuncID FuncID) const { | |
| 267 assert(FuncID < H_Num); | |
| 268 Constant *Result = RuntimeHelperFunc[FuncID]; | |
| 269 assert(Result != nullptr && "No such runtime helper function"); | |
| 270 return Result; | |
| 271 } | |
| 215 | 272 | 
| 216 /// Return a locked pointer to the registered jump tables. | 273 /// Return a locked pointer to the registered jump tables. | 
| 217 JumpTableDataList getJumpTables(); | 274 JumpTableDataList getJumpTables(); | 
| 218 /// Create a new jump table entry and return a reference to it. | 275 /// Create a new jump table entry and return a reference to it. | 
| 219 JumpTableData &addJumpTable(const IceString &FuncName, SizeT Id, | 276 JumpTableData &addJumpTable(const IceString &FuncName, SizeT Id, | 
| 220 const JumpTableData::TargetList &TargetList); | 277 const JumpTableData::TargetList &TargetList); | 
| 221 | 278 | 
| 222 static const ClFlags &getFlags() { return Flags; } | 279 static const ClFlags &getFlags() { return Flags; } | 
| 223 | 280 | 
| 224 /// Allocate data of type T using the global allocator. We allow entities | 281 /// Allocate data of type T using the global allocator. We allow entities | 
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 /// If !HasEmittedCode, SubZero will accumulate all Globals (which are "true" | 574 /// If !HasEmittedCode, SubZero will accumulate all Globals (which are "true" | 
| 518 /// program global variables) until the first code WorkItem is seen. | 575 /// program global variables) until the first code WorkItem is seen. | 
| 519 // TODO(jpp): move to EmitterContext. | 576 // TODO(jpp): move to EmitterContext. | 
| 520 bool HasSeenCode = false; | 577 bool HasSeenCode = false; | 
| 521 // TODO(jpp): move to EmitterContext. | 578 // TODO(jpp): move to EmitterContext. | 
| 522 VariableDeclaration *ProfileBlockInfoVarDecl = nullptr; | 579 VariableDeclaration *ProfileBlockInfoVarDecl = nullptr; | 
| 523 std::vector<VariableDeclaration *> ProfileBlockInfos; | 580 std::vector<VariableDeclaration *> ProfileBlockInfos; | 
| 524 /// Indicates if global variable declarations can be disposed of right after | 581 /// Indicates if global variable declarations can be disposed of right after | 
| 525 /// lowering. | 582 /// lowering. | 
| 526 bool DisposeGlobalVariablesAfterLowering = true; | 583 bool DisposeGlobalVariablesAfterLowering = true; | 
| 584 Constant *ConstZeroForType[IceType_NUM]; | |
| 585 Constant *ConstantTrue; | |
| 586 // Holds the constants representing each runtime helper function. | |
| 587 Constant *RuntimeHelperFunc[H_Num]; | |
| 527 | 588 | 
| 589 Constant *installConstantZero(Type Ty); | |
| 590 Constant *installConstantInt(Type Ty, int64_t Value); | |
| 591 Constant *installConstantInt1(int8_t ConstantInt1); | |
| 592 Constant *installConstantInt8(int8_t ConstantInt8); | |
| 593 Constant *installConstantInt16(int16_t ConstantInt16); | |
| 594 Constant *installConstantInt32(int32_t ConstantInt32); | |
| 595 Constant *installConstantInt64(int64_t ConstantInt64); | |
| 528 LockedPtr<ArenaAllocator> getAllocator() { | 596 LockedPtr<ArenaAllocator> getAllocator() { | 
| 529 return LockedPtr<ArenaAllocator>(&Allocator, &AllocLock); | 597 return LockedPtr<ArenaAllocator>(&Allocator, &AllocLock); | 
| 530 } | 598 } | 
| 531 LockedPtr<VariableDeclarationList> getInitializerAllocator() { | 599 LockedPtr<VariableDeclarationList> getInitializerAllocator() { | 
| 532 return LockedPtr<VariableDeclarationList>(&Globals, &InitAllocLock); | 600 return LockedPtr<VariableDeclarationList>(&Globals, &InitAllocLock); | 
| 533 } | 601 } | 
| 534 LockedPtr<ConstantPool> getConstPool() { | 602 LockedPtr<ConstantPool> getConstPool() { | 
| 535 return LockedPtr<ConstantPool>(ConstPool.get(), &ConstPoolLock); | 603 return LockedPtr<ConstantPool>(ConstPool.get(), &ConstPoolLock); | 
| 536 } | 604 } | 
| 537 LockedPtr<JumpTableDataList> getJumpTableList() { | 605 LockedPtr<JumpTableDataList> getJumpTableList() { | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 699 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 
| 632 ~OstreamLocker() { Ctx->unlockStr(); } | 700 ~OstreamLocker() { Ctx->unlockStr(); } | 
| 633 | 701 | 
| 634 private: | 702 private: | 
| 635 GlobalContext *const Ctx; | 703 GlobalContext *const Ctx; | 
| 636 }; | 704 }; | 
| 637 | 705 | 
| 638 } // end of namespace Ice | 706 } // end of namespace Ice | 
| 639 | 707 | 
| 640 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 708 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 
| OLD | NEW |