2 * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef DFGPromotedHeapLocation_h
27 #define DFGPromotedHeapLocation_h
32 #include <wtf/PrintStream.h>
34 namespace JSC { namespace DFG {
36 enum PromotedLocationKind {
37 InvalidPromotedLocationKind,
40 ActivationSymbolTablePLoc,
46 FunctionExecutablePLoc,
47 FunctionActivationPLoc,
52 class PromotedLocationDescriptor {
54 PromotedLocationDescriptor(
55 PromotedLocationKind kind = InvalidPromotedLocationKind, unsigned info = 0)
61 bool operator!() const { return m_kind == InvalidPromotedLocationKind; }
63 PromotedLocationKind kind() const { return m_kind; }
64 unsigned info() const { return m_info; }
66 OpInfo imm1() const { return OpInfo(static_cast<uint32_t>(m_kind)); }
67 OpInfo imm2() const { return OpInfo(static_cast<uint32_t>(m_info)); }
71 return m_kind + m_info;
74 bool operator==(const PromotedLocationDescriptor& other) const
76 return m_kind == other.m_kind
77 && m_info == other.m_info;
80 bool operator!=(const PromotedLocationDescriptor& other) const
82 return !(*this == other);
85 bool isHashTableDeletedValue() const
87 return m_kind == InvalidPromotedLocationKind && m_info;
90 void dump(PrintStream& out) const;
93 PromotedLocationKind m_kind;
97 class PromotedHeapLocation {
100 PromotedLocationKind kind = InvalidPromotedLocationKind,
101 Node* base = nullptr, unsigned info = 0)
107 PromotedHeapLocation(
108 PromotedLocationKind kind, Edge base, unsigned info = 0)
109 : PromotedHeapLocation(kind, base.node(), info)
113 PromotedHeapLocation(Node* base, PromotedLocationDescriptor meta)
119 PromotedHeapLocation(WTF::HashTableDeletedValueType)
121 , m_meta(InvalidPromotedLocationKind, 1)
125 Node* createHint(Graph&, NodeOrigin, Node* value);
127 bool operator!() const { return kind() == InvalidPromotedLocationKind; }
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; }
134 unsigned hash() const
136 return m_meta.hash() + WTF::PtrHash<Node*>::hash(m_base);
139 bool operator==(const PromotedHeapLocation& other) const
141 return m_base == other.m_base
142 && m_meta == other.m_meta;
145 bool isHashTableDeletedValue() const
147 return m_meta.isHashTableDeletedValue();
150 void dump(PrintStream& out) const;
154 PromotedLocationDescriptor m_meta;
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;
163 } } // namespace JSC::DFG
167 void printInternal(PrintStream&, JSC::DFG::PromotedLocationKind);
169 template<typename T> struct DefaultHash;
170 template<> struct DefaultHash<JSC::DFG::PromotedHeapLocation> {
171 typedef JSC::DFG::PromotedHeapLocationHash Hash;
174 template<typename T> struct HashTraits;
175 template<> struct HashTraits<JSC::DFG::PromotedHeapLocation> : SimpleClassHashTraits<JSC::DFG::PromotedHeapLocation> {
176 static const bool emptyValueIsZero = false;
181 #endif // ENABLE(DFG_JIT)
183 #endif // DFGPromotedHeapLocation_h