]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 | 1 | /* |
81345200 | 2 | * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. |
6fe7ccc8 A |
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 LazyOperandValueProfile_h | |
27 | #define LazyOperandValueProfile_h | |
28 | ||
81345200 | 29 | #include "ConcurrentJITLock.h" |
6fe7ccc8 | 30 | #include "ValueProfile.h" |
81345200 | 31 | #include "VirtualRegister.h" |
6fe7ccc8 A |
32 | #include <wtf/HashMap.h> |
33 | #include <wtf/Noncopyable.h> | |
34 | #include <wtf/OwnPtr.h> | |
35 | #include <wtf/SegmentedVector.h> | |
36 | ||
37 | namespace JSC { | |
38 | ||
39 | class ScriptExecutable; | |
40 | ||
41 | class LazyOperandValueProfileKey { | |
42 | public: | |
43 | LazyOperandValueProfileKey() | |
44 | : m_bytecodeOffset(0) // 0 = empty value | |
81345200 | 45 | , m_operand(VirtualRegister()) // not a valid operand index in our current scheme |
6fe7ccc8 A |
46 | { |
47 | } | |
48 | ||
49 | LazyOperandValueProfileKey(WTF::HashTableDeletedValueType) | |
50 | : m_bytecodeOffset(1) // 1 = deleted value | |
81345200 | 51 | , m_operand(VirtualRegister()) // not a valid operand index in our current scheme |
6fe7ccc8 A |
52 | { |
53 | } | |
54 | ||
81345200 | 55 | LazyOperandValueProfileKey(unsigned bytecodeOffset, VirtualRegister operand) |
6fe7ccc8 A |
56 | : m_bytecodeOffset(bytecodeOffset) |
57 | , m_operand(operand) | |
58 | { | |
81345200 | 59 | ASSERT(m_operand.isValid()); |
6fe7ccc8 A |
60 | } |
61 | ||
62 | bool operator!() const | |
63 | { | |
81345200 | 64 | return !m_operand.isValid(); |
6fe7ccc8 A |
65 | } |
66 | ||
67 | bool operator==(const LazyOperandValueProfileKey& other) const | |
68 | { | |
69 | return m_bytecodeOffset == other.m_bytecodeOffset | |
70 | && m_operand == other.m_operand; | |
71 | } | |
72 | ||
73 | unsigned hash() const | |
74 | { | |
81345200 | 75 | return WTF::intHash(m_bytecodeOffset) + m_operand.offset(); |
6fe7ccc8 A |
76 | } |
77 | ||
78 | unsigned bytecodeOffset() const | |
79 | { | |
80 | ASSERT(!!*this); | |
81 | return m_bytecodeOffset; | |
82 | } | |
81345200 A |
83 | |
84 | VirtualRegister operand() const | |
6fe7ccc8 A |
85 | { |
86 | ASSERT(!!*this); | |
87 | return m_operand; | |
88 | } | |
89 | ||
90 | bool isHashTableDeletedValue() const | |
91 | { | |
81345200 | 92 | return !m_operand.isValid() && m_bytecodeOffset; |
6fe7ccc8 A |
93 | } |
94 | private: | |
95 | unsigned m_bytecodeOffset; | |
81345200 | 96 | VirtualRegister m_operand; |
6fe7ccc8 A |
97 | }; |
98 | ||
99 | struct LazyOperandValueProfileKeyHash { | |
100 | static unsigned hash(const LazyOperandValueProfileKey& key) { return key.hash(); } | |
101 | static bool equal( | |
102 | const LazyOperandValueProfileKey& a, | |
103 | const LazyOperandValueProfileKey& b) { return a == b; } | |
104 | static const bool safeToCompareToEmptyOrDeleted = true; | |
105 | }; | |
106 | ||
107 | } // namespace JSC | |
108 | ||
109 | namespace WTF { | |
110 | ||
111 | template<typename T> struct DefaultHash; | |
112 | template<> struct DefaultHash<JSC::LazyOperandValueProfileKey> { | |
113 | typedef JSC::LazyOperandValueProfileKeyHash Hash; | |
114 | }; | |
115 | ||
116 | template<typename T> struct HashTraits; | |
117 | template<> struct HashTraits<JSC::LazyOperandValueProfileKey> : public GenericHashTraits<JSC::LazyOperandValueProfileKey> { | |
118 | static void constructDeletedValue(JSC::LazyOperandValueProfileKey& slot) { new (NotNull, &slot) JSC::LazyOperandValueProfileKey(HashTableDeletedValue); } | |
119 | static bool isDeletedValue(const JSC::LazyOperandValueProfileKey& value) { return value.isHashTableDeletedValue(); } | |
120 | }; | |
121 | ||
122 | } // namespace WTF | |
123 | ||
124 | namespace JSC { | |
125 | ||
126 | struct LazyOperandValueProfile : public MinimalValueProfile { | |
127 | LazyOperandValueProfile() | |
128 | : MinimalValueProfile() | |
81345200 | 129 | , m_operand(VirtualRegister()) |
6fe7ccc8 A |
130 | { |
131 | } | |
132 | ||
133 | explicit LazyOperandValueProfile(const LazyOperandValueProfileKey& key) | |
134 | : MinimalValueProfile(key.bytecodeOffset()) | |
135 | , m_operand(key.operand()) | |
136 | { | |
137 | } | |
138 | ||
139 | LazyOperandValueProfileKey key() const | |
140 | { | |
141 | return LazyOperandValueProfileKey(m_bytecodeOffset, m_operand); | |
142 | } | |
143 | ||
81345200 | 144 | VirtualRegister m_operand; |
6fe7ccc8 A |
145 | |
146 | typedef SegmentedVector<LazyOperandValueProfile, 8> List; | |
147 | }; | |
148 | ||
149 | class LazyOperandValueProfileParser; | |
150 | ||
151 | class CompressedLazyOperandValueProfileHolder { | |
152 | WTF_MAKE_NONCOPYABLE(CompressedLazyOperandValueProfileHolder); | |
153 | public: | |
154 | CompressedLazyOperandValueProfileHolder(); | |
155 | ~CompressedLazyOperandValueProfileHolder(); | |
156 | ||
81345200 | 157 | void computeUpdatedPredictions(const ConcurrentJITLocker&); |
6fe7ccc8 | 158 | |
81345200 A |
159 | LazyOperandValueProfile* add( |
160 | const ConcurrentJITLocker&, const LazyOperandValueProfileKey& key); | |
6fe7ccc8 A |
161 | |
162 | private: | |
163 | friend class LazyOperandValueProfileParser; | |
164 | OwnPtr<LazyOperandValueProfile::List> m_data; | |
165 | }; | |
166 | ||
167 | class LazyOperandValueProfileParser { | |
168 | WTF_MAKE_NONCOPYABLE(LazyOperandValueProfileParser); | |
169 | public: | |
81345200 | 170 | explicit LazyOperandValueProfileParser(); |
6fe7ccc8 A |
171 | ~LazyOperandValueProfileParser(); |
172 | ||
81345200 A |
173 | void initialize( |
174 | const ConcurrentJITLocker&, CompressedLazyOperandValueProfileHolder& holder); | |
175 | ||
6fe7ccc8 A |
176 | LazyOperandValueProfile* getIfPresent( |
177 | const LazyOperandValueProfileKey& key) const; | |
178 | ||
81345200 A |
179 | SpeculatedType prediction( |
180 | const ConcurrentJITLocker&, const LazyOperandValueProfileKey& key) const; | |
6fe7ccc8 | 181 | private: |
6fe7ccc8 A |
182 | HashMap<LazyOperandValueProfileKey, LazyOperandValueProfile*> m_map; |
183 | }; | |
184 | ||
185 | } // namespace JSC | |
186 | ||
6fe7ccc8 A |
187 | #endif // LazyOperandValueProfile_h |
188 | ||
189 |