DFGAdjacencyList.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 DFGAdjacencyList_h
  26. #define DFGAdjacencyList_h
  27. #include <wtf/Platform.h>
  28. #if ENABLE(DFG_JIT)
  29. #include "DFGCommon.h"
  30. #include "DFGEdge.h"
  31. namespace JSC { namespace DFG {
  32. class AdjacencyList {
  33. public:
  34. enum Kind {
  35. Fixed,
  36. Variable
  37. };
  38. enum { Size = 3 };
  39. AdjacencyList() { }
  40. AdjacencyList(Kind kind)
  41. {
  42. if (kind == Variable) {
  43. m_words[0].m_encodedWord = UINT_MAX;
  44. m_words[1].m_encodedWord = UINT_MAX;
  45. }
  46. }
  47. AdjacencyList(Kind kind, Edge child1, Edge child2, Edge child3)
  48. {
  49. ASSERT_UNUSED(kind, kind == Fixed);
  50. initialize(child1, child2, child3);
  51. }
  52. AdjacencyList(Kind kind, unsigned firstChild, unsigned numChildren)
  53. {
  54. ASSERT_UNUSED(kind, kind == Variable);
  55. setFirstChild(firstChild);
  56. setNumChildren(numChildren);
  57. }
  58. const Edge& child(unsigned i) const
  59. {
  60. ASSERT(i < Size);
  61. return m_words[i];
  62. }
  63. Edge& child(unsigned i)
  64. {
  65. ASSERT(i < Size);
  66. return m_words[i];
  67. }
  68. void setChild(unsigned i, Edge nodeUse)
  69. {
  70. ASSERT(i < Size);
  71. m_words[i] = nodeUse;
  72. }
  73. Edge child1() const { return child(0); }
  74. Edge child2() const { return child(1); }
  75. Edge child3() const { return child(2); }
  76. Edge& child1() { return child(0); }
  77. Edge& child2() { return child(1); }
  78. Edge& child3() { return child(2); }
  79. void setChild1(Edge nodeUse) { setChild(0, nodeUse); }
  80. void setChild2(Edge nodeUse) { setChild(1, nodeUse); }
  81. void setChild3(Edge nodeUse) { setChild(2, nodeUse); }
  82. Edge child1Unchecked() const { return m_words[0]; }
  83. void initialize(Edge child1, Edge child2, Edge child3)
  84. {
  85. child(0) = child1;
  86. child(1) = child2;
  87. child(2) = child3;
  88. }
  89. void initialize(Node* child1 = 0, Node* child2 = 0, Node* child3 = 0)
  90. {
  91. initialize(Edge(child1), Edge(child2), Edge(child3));
  92. }
  93. void reset()
  94. {
  95. initialize();
  96. }
  97. // Call this if you wish to remove an edge and the node treats the list of children.
  98. void removeEdge(unsigned edgeIndex)
  99. {
  100. for (unsigned i = edgeIndex; i < Size - 1; ++i)
  101. setChild(i, child(i + 1));
  102. setChild(Size - 1, Edge());
  103. }
  104. unsigned firstChild() const
  105. {
  106. return m_words[0].m_encodedWord;
  107. }
  108. void setFirstChild(unsigned firstChild)
  109. {
  110. m_words[0].m_encodedWord = firstChild;
  111. }
  112. unsigned numChildren() const
  113. {
  114. return m_words[1].m_encodedWord;
  115. }
  116. void setNumChildren(unsigned numChildren)
  117. {
  118. m_words[1].m_encodedWord = numChildren;
  119. }
  120. private:
  121. Edge m_words[Size];
  122. };
  123. } } // namespace JSC::DFG
  124. #endif // ENABLE(DFG_JIT)
  125. #endif // DFGAdjacencyList_h