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