]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGPromotedHeapLocation.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGPromotedHeapLocation.h
1 /*
2 * Copyright (C) 2014, 2015 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 DFGPromotedHeapLocation_h
27 #define DFGPromotedHeapLocation_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include "DFGNode.h"
32 #include <wtf/PrintStream.h>
33
34 namespace JSC { namespace DFG {
35
36 enum PromotedLocationKind {
37 InvalidPromotedLocationKind,
38
39 StructurePLoc,
40 ActivationSymbolTablePLoc,
41 NamedPropertyPLoc,
42 ArgumentPLoc,
43 ArgumentCountPLoc,
44 ArgumentsCalleePLoc,
45
46 FunctionExecutablePLoc,
47 FunctionActivationPLoc,
48 ActivationScopePLoc,
49 ClosureVarPLoc,
50 };
51
52 class PromotedLocationDescriptor {
53 public:
54 PromotedLocationDescriptor(
55 PromotedLocationKind kind = InvalidPromotedLocationKind, unsigned info = 0)
56 : m_kind(kind)
57 , m_info(info)
58 {
59 }
60
61 bool operator!() const { return m_kind == InvalidPromotedLocationKind; }
62
63 PromotedLocationKind kind() const { return m_kind; }
64 unsigned info() const { return m_info; }
65
66 OpInfo imm1() const { return OpInfo(static_cast<uint32_t>(m_kind)); }
67 OpInfo imm2() const { return OpInfo(static_cast<uint32_t>(m_info)); }
68
69 unsigned hash() const
70 {
71 return m_kind + m_info;
72 }
73
74 bool operator==(const PromotedLocationDescriptor& other) const
75 {
76 return m_kind == other.m_kind
77 && m_info == other.m_info;
78 }
79
80 bool operator!=(const PromotedLocationDescriptor& other) const
81 {
82 return !(*this == other);
83 }
84
85 bool isHashTableDeletedValue() const
86 {
87 return m_kind == InvalidPromotedLocationKind && m_info;
88 }
89
90 void dump(PrintStream& out) const;
91
92 private:
93 PromotedLocationKind m_kind;
94 unsigned m_info;
95 };
96
97 class PromotedHeapLocation {
98 public:
99 PromotedHeapLocation(
100 PromotedLocationKind kind = InvalidPromotedLocationKind,
101 Node* base = nullptr, unsigned info = 0)
102 : m_base(base)
103 , m_meta(kind, info)
104 {
105 }
106
107 PromotedHeapLocation(
108 PromotedLocationKind kind, Edge base, unsigned info = 0)
109 : PromotedHeapLocation(kind, base.node(), info)
110 {
111 }
112
113 PromotedHeapLocation(Node* base, PromotedLocationDescriptor meta)
114 : m_base(base)
115 , m_meta(meta)
116 {
117 }
118
119 PromotedHeapLocation(WTF::HashTableDeletedValueType)
120 : m_base(nullptr)
121 , m_meta(InvalidPromotedLocationKind, 1)
122 {
123 }
124
125 Node* createHint(Graph&, NodeOrigin, Node* value);
126
127 bool operator!() const { return kind() == InvalidPromotedLocationKind; }
128
129 PromotedLocationKind kind() const { return m_meta.kind(); }
130 Node* base() const { return m_base; }
131 unsigned info() const { return m_meta.info(); }
132 PromotedLocationDescriptor descriptor() const { return m_meta; }
133
134 unsigned hash() const
135 {
136 return m_meta.hash() + WTF::PtrHash<Node*>::hash(m_base);
137 }
138
139 bool operator==(const PromotedHeapLocation& other) const
140 {
141 return m_base == other.m_base
142 && m_meta == other.m_meta;
143 }
144
145 bool isHashTableDeletedValue() const
146 {
147 return m_meta.isHashTableDeletedValue();
148 }
149
150 void dump(PrintStream& out) const;
151
152 private:
153 Node* m_base;
154 PromotedLocationDescriptor m_meta;
155 };
156
157 struct PromotedHeapLocationHash {
158 static unsigned hash(const PromotedHeapLocation& key) { return key.hash(); }
159 static bool equal(const PromotedHeapLocation& a, const PromotedHeapLocation& b) { return a == b; }
160 static const bool safeToCompareToEmptyOrDeleted = true;
161 };
162
163 } } // namespace JSC::DFG
164
165 namespace WTF {
166
167 void printInternal(PrintStream&, JSC::DFG::PromotedLocationKind);
168
169 template<typename T> struct DefaultHash;
170 template<> struct DefaultHash<JSC::DFG::PromotedHeapLocation> {
171 typedef JSC::DFG::PromotedHeapLocationHash Hash;
172 };
173
174 template<typename T> struct HashTraits;
175 template<> struct HashTraits<JSC::DFG::PromotedHeapLocation> : SimpleClassHashTraits<JSC::DFG::PromotedHeapLocation> {
176 static const bool emptyValueIsZero = false;
177 };
178
179 } // namespace WTF
180
181 #endif // ENABLE(DFG_JIT)
182
183 #endif // DFGPromotedHeapLocation_h
184