DFGMinifiedNode.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 DFGMinifiedNode_h
  26. #define DFGMinifiedNode_h
  27. #include <wtf/Platform.h>
  28. #if ENABLE(DFG_JIT)
  29. #include "DFGCommon.h"
  30. #include "DFGMinifiedID.h"
  31. #include "DFGNodeType.h"
  32. namespace JSC { namespace DFG {
  33. struct Node;
  34. inline bool belongsInMinifiedGraph(NodeType type)
  35. {
  36. switch (type) {
  37. case JSConstant:
  38. case WeakJSConstant:
  39. case ValueToInt32:
  40. case Int32ToDouble:
  41. case ForwardInt32ToDouble:
  42. case UInt32ToNumber:
  43. case DoubleAsInt32:
  44. case PhantomArguments:
  45. return true;
  46. default:
  47. return false;
  48. }
  49. }
  50. class MinifiedNode {
  51. public:
  52. MinifiedNode() { }
  53. static MinifiedNode fromNode(Node*);
  54. MinifiedID id() const { return m_id; }
  55. NodeType op() const { return m_op; }
  56. bool hasChild1() const { return hasChild(m_op); }
  57. MinifiedID child1() const
  58. {
  59. ASSERT(hasChild(m_op));
  60. return MinifiedID::fromBits(m_childOrInfo);
  61. }
  62. bool hasConstant() const { return hasConstantNumber() || hasWeakConstant(); }
  63. bool hasConstantNumber() const { return hasConstantNumber(m_op); }
  64. unsigned constantNumber() const
  65. {
  66. ASSERT(hasConstantNumber(m_op));
  67. return m_childOrInfo;
  68. }
  69. bool hasWeakConstant() const { return hasWeakConstant(m_op); }
  70. JSCell* weakConstant() const
  71. {
  72. ASSERT(hasWeakConstant(m_op));
  73. return bitwise_cast<JSCell*>(m_childOrInfo);
  74. }
  75. static MinifiedID getID(MinifiedNode* node) { return node->id(); }
  76. static bool compareByNodeIndex(const MinifiedNode& a, const MinifiedNode& b)
  77. {
  78. return a.m_id < b.m_id;
  79. }
  80. private:
  81. static bool hasChild(NodeType type)
  82. {
  83. switch (type) {
  84. case ValueToInt32:
  85. case Int32ToDouble:
  86. case ForwardInt32ToDouble:
  87. case UInt32ToNumber:
  88. case DoubleAsInt32:
  89. return true;
  90. default:
  91. return false;
  92. }
  93. }
  94. static bool hasConstantNumber(NodeType type)
  95. {
  96. return type == JSConstant;
  97. }
  98. static bool hasWeakConstant(NodeType type)
  99. {
  100. return type == WeakJSConstant;
  101. }
  102. MinifiedID m_id;
  103. uintptr_t m_childOrInfo; // Nodes in the minified graph have only one child each.
  104. NodeType m_op;
  105. };
  106. } } // namespace JSC::DFG
  107. #endif // ENABLE(DFG_JIT)
  108. #endif // DFGMinifiedNode_h