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