2
0

Lifetime.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. class Lifetime
  7. {
  8. public:
  9. Lifetime(JitArenaAllocator * alloc, StackSym *sym, RegNum reg, uint32 start, uint32 end, Func *func)
  10. : sym(sym), reg(reg), start(start), end(end), previousDefBlockNumber(0), defList(alloc),
  11. useList(alloc), lastUseLabel(NULL), region(NULL), isSpilled(false), useCount(0), useCountAdjust(0), allDefsCost(0), isLiveAcrossCalls(false),
  12. isLiveAcrossUserCalls(false), isDeadStore(true), isOpHelperSpilled(false), cantOpHelperSpill(false), isOpHelperSpillAsArg(false),
  13. isFloat(false), isSimd128F4(false), isSimd128I4(false), isSimd128I8(false), isSimd128I16(false), isSimd128U4(false), isSimd128U8(false), isSimd128U16(false),
  14. isSimd128D2(false), isSimd128B4(false), isSimd128B8(false), isSimd128B16(false), cantSpill(false), dontAllocate(false), isSecondChanceAllocated(false), isCheapSpill(false), spillStackSlot(NULL),
  15. totalOpHelperLengthByEnd(0), needsStoreCompensation(false), alloc(alloc), regionUseCount(NULL), regionUseCountAdjust(NULL),
  16. cantStackPack(false)
  17. {
  18. intUsageBv.ClearAll();
  19. regPreference.ClearAll();
  20. }
  21. public:
  22. StackSym * sym;
  23. uint32 * regionUseCount;
  24. uint32 * regionUseCountAdjust;
  25. SList<IR::Instr *> defList;
  26. SList<IR::Instr *> useList;
  27. IR::LabelInstr * lastUseLabel;
  28. Region * region;
  29. StackSlot * spillStackSlot;
  30. JitArenaAllocator * alloc;
  31. BitVector intUsageBv;
  32. BitVector regPreference;
  33. uint32 start;
  34. uint32 end;
  35. uint32 previousDefBlockNumber;
  36. uint32 useCount;
  37. uint32 useCountAdjust;
  38. uint32 allDefsCost;
  39. uint32 lastAllocationStart;
  40. RegNum reg;
  41. uint totalOpHelperLengthByEnd;
  42. uint8 isSpilled:1;
  43. uint8 isLiveAcrossCalls:1;
  44. uint8 isLiveAcrossUserCalls:1;
  45. uint8 isDeadStore:1;
  46. uint8 isOpHelperSpilled:1;
  47. uint8 isOpHelperSpillAsArg : 1;
  48. uint8 cantOpHelperSpill:1;
  49. uint8 isFloat:1;
  50. uint8 isSimd128F4 : 1;
  51. uint8 isSimd128I4 : 1;
  52. uint8 isSimd128I8 : 1;
  53. uint8 isSimd128I16 : 1;
  54. uint8 isSimd128B4 : 1;
  55. uint8 isSimd128B8 : 1;
  56. uint8 isSimd128B16 : 1;
  57. uint8 isSimd128U4 : 1;
  58. uint8 isSimd128U8 : 1;
  59. uint8 isSimd128U16 : 1;
  60. uint8 isSimd128D2 : 1;
  61. uint8 cantSpill:1;
  62. uint8 dontAllocate:1;
  63. uint8 isSecondChanceAllocated:1;
  64. uint8 isCheapSpill:1;
  65. uint8 needsStoreCompensation:1;
  66. uint8 cantStackPack : 1;
  67. bool isSimd128()
  68. {
  69. bool result = isSimd128F4;
  70. result |= isSimd128I4;
  71. result |= isSimd128I8;
  72. result |= isSimd128I16;
  73. result |= isSimd128U4;
  74. result |= isSimd128U8;
  75. result |= isSimd128U16;
  76. result |= isSimd128D2;
  77. result |= isSimd128B4;
  78. result |= isSimd128B8;
  79. result |= isSimd128B16;
  80. return result;
  81. }
  82. void AddToUseCount(uint32 newUseValue, Loop *loop, Func *func)
  83. {
  84. Assert((this->useCount + newUseValue) >= this->useCount);
  85. this->useCount += newUseValue;
  86. if (loop)
  87. {
  88. if (!this->regionUseCount)
  89. {
  90. this->regionUseCount = AnewArrayZ(this->alloc, uint32, func->loopCount+1);
  91. this->regionUseCountAdjust = AnewArrayZ(this->alloc, uint32, func->loopCount+1);
  92. }
  93. while (loop)
  94. {
  95. this->regionUseCount[loop->loopNumber] += newUseValue;
  96. loop = loop->parent;
  97. }
  98. }
  99. }
  100. void SubFromUseCount(uint32 newUseValue, Loop *loop)
  101. {
  102. Assert((this->useCount - newUseValue) <= this->useCount);
  103. this->useCount -= newUseValue;
  104. Assert(!loop || this->regionUseCount);
  105. while (loop)
  106. {
  107. Assert((this->regionUseCount[loop->loopNumber] - newUseValue) <= this->regionUseCount[loop->loopNumber]);
  108. this->regionUseCount[loop->loopNumber] -= newUseValue;
  109. loop = loop->parent;
  110. }
  111. }
  112. uint32 GetRegionUseCount(Loop *loop)
  113. {
  114. if (loop && !PHASE_OFF1(Js::RegionUseCountPhase))
  115. {
  116. if (this->regionUseCount)
  117. {
  118. return this->regionUseCount[loop->loopNumber];
  119. }
  120. else
  121. {
  122. return 0;
  123. }
  124. }
  125. else
  126. {
  127. return this->useCount;
  128. }
  129. }
  130. void AddToUseCountAdjust(uint32 newUseValue, Loop *loop, Func *func)
  131. {
  132. Assert((this->useCountAdjust + newUseValue) >= this->useCountAdjust);
  133. this->useCountAdjust += newUseValue;
  134. if (loop)
  135. {
  136. if (!this->regionUseCount)
  137. {
  138. this->regionUseCount = AnewArrayZ(this->alloc, uint32, func->loopCount+1);
  139. this->regionUseCountAdjust = AnewArrayZ(this->alloc, uint32, func->loopCount+1);
  140. }
  141. do
  142. {
  143. this->regionUseCountAdjust[loop->loopNumber] += newUseValue;
  144. loop = loop->parent;
  145. } while (loop);
  146. }
  147. }
  148. void ApplyUseCountAdjust(Loop *loop)
  149. {
  150. Assert((this->useCount + this->useCountAdjust) >= this->useCount);
  151. this->useCount -= this->useCountAdjust;
  152. this->useCountAdjust = 0;
  153. if (loop && this->regionUseCount)
  154. {
  155. do
  156. {
  157. Assert((this->regionUseCount[loop->loopNumber] - this->regionUseCountAdjust[loop->loopNumber]) <= this->regionUseCount[loop->loopNumber]);
  158. this->regionUseCount[loop->loopNumber] -= this->regionUseCountAdjust[loop->loopNumber];
  159. this->regionUseCountAdjust[loop->loopNumber] = 0;
  160. loop = loop->parent;
  161. } while (loop);
  162. }
  163. }
  164. };