]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGPureValue.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGPureValue.h
1 /*
2 * Copyright (C) 2014 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 DFGPureValue_h
27 #define DFGPureValue_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include "DFGNode.h"
32
33 namespace JSC { namespace DFG {
34
35 class PureValue {
36 public:
37 PureValue()
38 : m_op(LastNodeType)
39 , m_info(0)
40 {
41 }
42
43 PureValue(NodeType op, const AdjacencyList& children, uintptr_t info)
44 : m_op(op)
45 , m_children(children.sanitized())
46 , m_info(info)
47 {
48 ASSERT(!(defaultFlags(op) & NodeHasVarArgs));
49 }
50
51 PureValue(NodeType op, const AdjacencyList& children, const void* ptr)
52 : PureValue(op, children, bitwise_cast<uintptr_t>(ptr))
53 {
54 }
55
56 PureValue(NodeType op, const AdjacencyList& children)
57 : PureValue(op, children, static_cast<uintptr_t>(0))
58 {
59 }
60
61 PureValue(Node* node, uintptr_t info)
62 : PureValue(node->op(), node->children, info)
63 {
64 }
65
66 PureValue(Node* node, const void* ptr)
67 : PureValue(node->op(), node->children, ptr)
68 {
69 }
70
71 PureValue(Node* node)
72 : PureValue(node->op(), node->children)
73 {
74 }
75
76 PureValue(WTF::HashTableDeletedValueType)
77 : m_op(LastNodeType)
78 , m_info(1)
79 {
80 }
81
82 bool operator!() const { return m_op == LastNodeType && !m_info; }
83
84 NodeType op() const { return m_op; }
85 const AdjacencyList& children() const { return m_children; }
86 uintptr_t info() const { return m_info; }
87
88 unsigned hash() const
89 {
90 return WTF::IntHash<int>::hash(static_cast<int>(m_op)) + m_children.hash() + m_info;
91 }
92
93 bool operator==(const PureValue& other) const
94 {
95 return m_op == other.m_op
96 && m_children == other.m_children
97 && m_info == other.m_info;
98 }
99
100 bool isHashTableDeletedValue() const
101 {
102 return m_op == LastNodeType && m_info;
103 }
104
105 void dump(PrintStream& out) const;
106
107 private:
108 NodeType m_op;
109 AdjacencyList m_children;
110 uintptr_t m_info;
111 };
112
113 struct PureValueHash {
114 static unsigned hash(const PureValue& key) { return key.hash(); }
115 static bool equal(const PureValue& a, const PureValue& b) { return a == b; }
116 static const bool safeToCompareToEmptyOrDeleted = true;
117 };
118
119 } } // namespace JSC::DFG
120
121 namespace WTF {
122
123 template<typename T> struct DefaultHash;
124 template<> struct DefaultHash<JSC::DFG::PureValue> {
125 typedef JSC::DFG::PureValueHash Hash;
126 };
127
128 template<typename T> struct HashTraits;
129 template<> struct HashTraits<JSC::DFG::PureValue> : SimpleClassHashTraits<JSC::DFG::PureValue> {
130 static const bool emptyValueIsZero = false;
131 };
132
133 } // namespace WTF
134
135 namespace JSC { namespace DFG {
136
137 typedef HashMap<PureValue, Node*> PureMap;
138 typedef HashMap<PureValue, Vector<Node*>> PureMultiMap;
139
140 } } // namespace JSC::DFG
141
142 #endif // ENABLE(DFG_JIT)
143
144 #endif // DFGPureValue_h
145