DFGBasicBlock.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (C) 2011, 2013 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 DFGBasicBlock_h
  26. #define DFGBasicBlock_h
  27. #if ENABLE(DFG_JIT)
  28. #include "DFGAbstractValue.h"
  29. #include "DFGBranchDirection.h"
  30. #include "DFGNode.h"
  31. #include "DFGVariadicFunction.h"
  32. #include "Operands.h"
  33. #include <wtf/OwnPtr.h>
  34. #include <wtf/Vector.h>
  35. namespace JSC { namespace DFG {
  36. class Graph;
  37. typedef Vector_shared <BlockIndex, 2> PredecessorList;
  38. struct BasicBlock : Vector_shared<Node*, 8> {
  39. BasicBlock(unsigned bytecodeBegin, unsigned numArguments, unsigned numLocals)
  40. : bytecodeBegin(bytecodeBegin)
  41. , isOSRTarget(false)
  42. , cfaHasVisited(false)
  43. , cfaShouldRevisit(false)
  44. , cfaFoundConstants(false)
  45. , cfaDidFinish(true)
  46. , cfaBranchDirection(InvalidBranchDirection)
  47. #if !ASSERT_DISABLED
  48. , isLinked(false)
  49. #endif
  50. , isReachable(false)
  51. , variablesAtHead(numArguments, numLocals)
  52. , variablesAtTail(numArguments, numLocals)
  53. , valuesAtHead(numArguments, numLocals)
  54. , valuesAtTail(numArguments, numLocals)
  55. {
  56. }
  57. ~BasicBlock()
  58. {
  59. }
  60. void ensureLocals(unsigned newNumLocals)
  61. {
  62. variablesAtHead.ensureLocals(newNumLocals);
  63. variablesAtTail.ensureLocals(newNumLocals);
  64. valuesAtHead.ensureLocals(newNumLocals);
  65. valuesAtTail.ensureLocals(newNumLocals);
  66. }
  67. size_t numNodes() const { return phis.size() + size(); }
  68. Node* node(size_t i) const
  69. {
  70. if (i < phis.size())
  71. return phis[i];
  72. return at(i - phis.size());
  73. }
  74. bool isPhiIndex(size_t i) const { return i < phis.size(); }
  75. bool isInPhis(Node* node) const
  76. {
  77. for (size_t i = 0; i < phis.size(); ++i) {
  78. if (phis[i] == node)
  79. return true;
  80. }
  81. return false;
  82. }
  83. bool isInBlock(Node* myNode) const
  84. {
  85. for (size_t i = 0; i < numNodes(); ++i) {
  86. if (node(i) == myNode)
  87. return true;
  88. }
  89. return false;
  90. }
  91. #define DFG_DEFINE_APPEND_NODE(templatePre, templatePost, typeParams, valueParamsComma, valueParams, valueArgs) \
  92. templatePre typeParams templatePost Node* appendNode(Graph&, SpeculatedType valueParamsComma valueParams);
  93. DFG_VARIADIC_TEMPLATE_FUNCTION(DFG_DEFINE_APPEND_NODE)
  94. #undef DFG_DEFINE_APPEND_NODE
  95. // This value is used internally for block linking and OSR entry. It is mostly meaningless
  96. // for other purposes due to inlining.
  97. unsigned bytecodeBegin;
  98. bool isOSRTarget;
  99. bool cfaHasVisited;
  100. bool cfaShouldRevisit;
  101. bool cfaFoundConstants;
  102. bool cfaDidFinish;
  103. BranchDirection cfaBranchDirection;
  104. #if !ASSERT_DISABLED
  105. bool isLinked;
  106. #endif
  107. bool isReachable;
  108. Vector_shared<Node*> phis;
  109. PredecessorList m_predecessors;
  110. Operands_shared<Node*, NodePointerTraits> variablesAtHead;
  111. Operands_shared<Node*, NodePointerTraits> variablesAtTail;
  112. Operands_shared<AbstractValue> valuesAtHead;
  113. Operands_shared<AbstractValue> valuesAtTail;
  114. #if ENABLE(DETACHED_JIT)
  115. DETACHED_JIT_MAKE_SHARED_DATA_ALLOCATED;
  116. #endif
  117. };
  118. struct UnlinkedBlock {
  119. BlockIndex m_blockIndex;
  120. bool m_needsNormalLinking;
  121. bool m_needsEarlyReturnLinking;
  122. UnlinkedBlock() { }
  123. explicit UnlinkedBlock(BlockIndex blockIndex)
  124. : m_blockIndex(blockIndex)
  125. , m_needsNormalLinking(true)
  126. , m_needsEarlyReturnLinking(false)
  127. {
  128. }
  129. };
  130. } } // namespace JSC::DFG
  131. #endif // ENABLE(DFG_JIT)
  132. #endif // DFGBasicBlock_h