DFGMinifiedID.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 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 DFGMinifiedID_h
  26. #define DFGMinifiedID_h
  27. #include <wtf/Platform.h>
  28. #if ENABLE(DFG_JIT)
  29. #include "DFGCommon.h"
  30. #include <wtf/HashMap.h>
  31. #include <wtf/PrintStream.h>
  32. namespace JSC { namespace DFG {
  33. class Graph;
  34. class MinifiedNode;
  35. class ValueSource;
  36. class MinifiedID {
  37. public:
  38. MinifiedID() : m_id(invalidID()) { }
  39. MinifiedID(WTF::HashTableDeletedValueType) : m_id(otherInvalidID()) { }
  40. explicit MinifiedID(Node* node) : m_id(bitwise_cast<uintptr_t>(node)) { }
  41. bool operator!() const { return m_id == invalidID(); }
  42. // This takes Graph& to remind you, that you should only be calling this method
  43. // when you're in the main compilation pass (i.e. you have a graph) and not later,
  44. // like during OSR exit compilation.
  45. Node* node(const Graph&) const { return bitwise_cast<Node*>(m_id); }
  46. bool operator==(const MinifiedID& other) const { return m_id == other.m_id; }
  47. bool operator!=(const MinifiedID& other) const { return m_id != other.m_id; }
  48. bool operator<(const MinifiedID& other) const { return m_id < other.m_id; }
  49. bool operator>(const MinifiedID& other) const { return m_id > other.m_id; }
  50. bool operator<=(const MinifiedID& other) const { return m_id <= other.m_id; }
  51. bool operator>=(const MinifiedID& other) const { return m_id >= other.m_id; }
  52. unsigned hash() const { return WTF::IntHash<uintptr_t>::hash(m_id); }
  53. void dump(PrintStream& out) const { out.print(RawPointer(reinterpret_cast<void*>(m_id))); }
  54. bool isHashTableDeletedValue() const { return m_id == otherInvalidID(); }
  55. private:
  56. friend class MinifiedNode;
  57. friend class ValueSource;
  58. static uintptr_t invalidID() { return static_cast<uintptr_t>(static_cast<intptr_t>(-1)); }
  59. static uintptr_t otherInvalidID() { return static_cast<uintptr_t>(static_cast<intptr_t>(-2)); }
  60. static MinifiedID fromBits(uintptr_t value)
  61. {
  62. MinifiedID result;
  63. result.m_id = value;
  64. return result;
  65. }
  66. uintptr_t m_id;
  67. };
  68. struct MinifiedIDHash {
  69. static unsigned hash(const MinifiedID& key) { return key.hash(); }
  70. static bool equal(const MinifiedID& a, const MinifiedID& b) { return a == b; }
  71. static const bool safeToCompareToEmptyOrDeleted = true;
  72. };
  73. } } // namespace JSC::DFG
  74. namespace WTF {
  75. template<typename T> struct DefaultHash;
  76. template<> struct DefaultHash<JSC::DFG::MinifiedID> {
  77. typedef JSC::DFG::MinifiedIDHash Hash;
  78. };
  79. template<typename T> struct HashTraits;
  80. template<> struct HashTraits<JSC::DFG::MinifiedID> : SimpleClassHashTraits<JSC::DFG::MinifiedID> { };
  81. } // namespace WTF
  82. #endif // ENABLE(DFG_JIT)
  83. #endif // DFGMinifiedID_h