DFGVariableEvent.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef DFGVariableEvent_h
  26. #define DFGVariableEvent_h
  27. #include <wtf/Platform.h>
  28. #if ENABLE(DFG_JIT)
  29. #include "DFGCommon.h"
  30. #include "DFGMinifiedID.h"
  31. #include "DataFormat.h"
  32. #include "MacroAssembler.h"
  33. #include <stdio.h>
  34. namespace JSC { namespace DFG {
  35. enum VariableEventKind {
  36. // Marks the beginning of a checkpoint. If you interpret the variable
  37. // events starting at a Reset point then you'll get everything you need.
  38. Reset,
  39. // Node births. Points in the code where a node becomes relevant for OSR.
  40. // It may be the point where it is actually born (i.e. assigned) or it may
  41. // be a later point, if it's only later in the sequence of instructions
  42. // that we start to care about this node.
  43. BirthToFill,
  44. BirthToSpill,
  45. // Events related to how a node is represented.
  46. Fill,
  47. Spill,
  48. // Death of a node - after this we no longer care about this node.
  49. Death,
  50. // A MovHintEvent means that a node is being associated with a bytecode operand,
  51. // but that it has not been stored into that operand.
  52. MovHintEvent,
  53. // A SetLocalEvent means that a node's value has actually been stored into the
  54. // bytecode operand that it's associated with.
  55. SetLocalEvent,
  56. // Used to indicate an uninitialized VariableEvent. Don't use for other
  57. // purposes.
  58. InvalidEventKind
  59. };
  60. union VariableRepresentation {
  61. MacroAssembler::RegisterID gpr;
  62. MacroAssembler::FPRegisterID fpr;
  63. #if USE(JSVALUE32_64)
  64. struct {
  65. MacroAssembler::RegisterID tagGPR;
  66. MacroAssembler::RegisterID payloadGPR;
  67. } pair;
  68. #endif
  69. int32_t virtualReg;
  70. };
  71. class VariableEvent {
  72. public:
  73. VariableEvent()
  74. : m_kind(InvalidEventKind)
  75. {
  76. }
  77. static VariableEvent reset()
  78. {
  79. VariableEvent event;
  80. event.m_kind = Reset;
  81. return event;
  82. }
  83. static VariableEvent fillGPR(VariableEventKind kind, MinifiedID id, MacroAssembler::RegisterID gpr, DataFormat dataFormat)
  84. {
  85. ASSERT(kind == BirthToFill || kind == Fill);
  86. ASSERT(dataFormat != DataFormatDouble);
  87. #if USE(JSVALUE32_64)
  88. ASSERT(!(dataFormat & DataFormatJS));
  89. #endif
  90. VariableEvent event;
  91. event.m_id = id;
  92. event.u.gpr = gpr;
  93. event.m_kind = kind;
  94. event.m_dataFormat = dataFormat;
  95. return event;
  96. }
  97. #if USE(JSVALUE32_64)
  98. static VariableEvent fillPair(VariableEventKind kind, MinifiedID id, MacroAssembler::RegisterID tagGPR, MacroAssembler::RegisterID payloadGPR)
  99. {
  100. ASSERT(kind == BirthToFill || kind == Fill);
  101. VariableEvent event;
  102. event.m_id = id;
  103. event.u.pair.tagGPR = tagGPR;
  104. event.u.pair.payloadGPR = payloadGPR;
  105. event.m_kind = kind;
  106. event.m_dataFormat = DataFormatJS;
  107. return event;
  108. }
  109. #endif // USE(JSVALUE32_64)
  110. static VariableEvent fillFPR(VariableEventKind kind, MinifiedID id, MacroAssembler::FPRegisterID fpr)
  111. {
  112. ASSERT(kind == BirthToFill || kind == Fill);
  113. VariableEvent event;
  114. event.m_id = id;
  115. event.u.fpr = fpr;
  116. event.m_kind = kind;
  117. event.m_dataFormat = DataFormatDouble;
  118. return event;
  119. }
  120. static VariableEvent spill(VariableEventKind kind, MinifiedID id, VirtualRegister virtualRegister, DataFormat format)
  121. {
  122. ASSERT(kind == BirthToSpill || kind == Spill);
  123. VariableEvent event;
  124. event.m_id = id;
  125. event.u.virtualReg = virtualRegister;
  126. event.m_kind = kind;
  127. event.m_dataFormat = format;
  128. return event;
  129. }
  130. static VariableEvent death(MinifiedID id)
  131. {
  132. VariableEvent event;
  133. event.m_id = id;
  134. event.m_kind = Death;
  135. return event;
  136. }
  137. static VariableEvent setLocal(int operand, DataFormat format)
  138. {
  139. VariableEvent event;
  140. event.u.virtualReg = operand;
  141. event.m_kind = SetLocalEvent;
  142. event.m_dataFormat = format;
  143. return event;
  144. }
  145. static VariableEvent movHint(MinifiedID id, int operand)
  146. {
  147. VariableEvent event;
  148. event.m_id = id;
  149. event.u.virtualReg = operand;
  150. event.m_kind = MovHintEvent;
  151. return event;
  152. }
  153. VariableEventKind kind() const
  154. {
  155. return static_cast<VariableEventKind>(m_kind);
  156. }
  157. MinifiedID id() const
  158. {
  159. ASSERT(m_kind == BirthToFill || m_kind == Fill
  160. || m_kind == BirthToSpill || m_kind == Spill
  161. || m_kind == Death || m_kind == MovHintEvent);
  162. return m_id;
  163. }
  164. DataFormat dataFormat() const
  165. {
  166. ASSERT(m_kind == BirthToFill || m_kind == Fill
  167. || m_kind == BirthToSpill || m_kind == Spill
  168. || m_kind == SetLocalEvent);
  169. return static_cast<DataFormat>(m_dataFormat);
  170. }
  171. MacroAssembler::RegisterID gpr() const
  172. {
  173. ASSERT(m_kind == BirthToFill || m_kind == Fill);
  174. ASSERT(m_dataFormat);
  175. ASSERT(m_dataFormat != DataFormatDouble);
  176. #if USE(JSVALUE32_64)
  177. ASSERT(!(m_dataFormat & DataFormatJS));
  178. #endif
  179. return u.gpr;
  180. }
  181. #if USE(JSVALUE32_64)
  182. MacroAssembler::RegisterID tagGPR() const
  183. {
  184. ASSERT(m_kind == BirthToFill || m_kind == Fill);
  185. ASSERT(m_dataFormat & DataFormatJS);
  186. return u.pair.tagGPR;
  187. }
  188. MacroAssembler::RegisterID payloadGPR() const
  189. {
  190. ASSERT(m_kind == BirthToFill || m_kind == Fill);
  191. ASSERT(m_dataFormat & DataFormatJS);
  192. return u.pair.payloadGPR;
  193. }
  194. #endif // USE(JSVALUE32_64)
  195. MacroAssembler::FPRegisterID fpr() const
  196. {
  197. ASSERT(m_kind == BirthToFill || m_kind == Fill);
  198. ASSERT(m_dataFormat == DataFormatDouble);
  199. return u.fpr;
  200. }
  201. VirtualRegister virtualRegister() const
  202. {
  203. ASSERT(m_kind == BirthToSpill || m_kind == Spill);
  204. return static_cast<VirtualRegister>(u.virtualReg);
  205. }
  206. int operand() const
  207. {
  208. ASSERT(m_kind == SetLocalEvent || m_kind == MovHintEvent);
  209. return u.virtualReg;
  210. }
  211. const VariableRepresentation& variableRepresentation() const { return u; }
  212. void dump(PrintStream&) const;
  213. private:
  214. void dumpFillInfo(const char* name, PrintStream&) const;
  215. void dumpSpillInfo(const char* name, PrintStream&) const;
  216. MinifiedID m_id;
  217. // For BirthToFill, Fill:
  218. // - The GPR or FPR, or a GPR pair.
  219. // For BirthToSpill, Spill:
  220. // - The virtual register.
  221. // For MovHintEvent, SetLocalEvent:
  222. // - The bytecode operand.
  223. // For Death:
  224. // - Unused.
  225. VariableRepresentation u;
  226. int8_t m_kind;
  227. int8_t m_dataFormat;
  228. };
  229. } } // namespace JSC::DFG
  230. #endif // ENABLE(DFG_JIT)
  231. #endif // DFGVariableEvent_h