Optimize FrameState for large linear scripts (bug 591836, r=dmandelin).
[mozilla-central.git] / js / src / methodjit / FrameEntry.h
blobcb411488f38adc49691ec0a590d4bf1d2648ee97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=99:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
18 * May 28, 2008.
20 * The Initial Developer of the Original Code is
21 * Brendan Eich <brendan@mozilla.org>
23 * Contributor(s):
24 * David Anderson <danderson@mozilla.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #if !defined jsjaeger_valueinfo_h__ && defined JS_METHODJIT
41 #define jsjaeger_valueinfo_h__
43 #include "jsapi.h"
44 #include "methodjit/MachineRegs.h"
45 #include "methodjit/RematInfo.h"
46 #include "assembler/assembler/MacroAssembler.h"
48 namespace js {
49 namespace mjit {
51 class FrameEntry
53 friend class FrameState;
54 friend class ImmutableSync;
56 public:
57 bool isConstant() const {
58 return data.isConstant();
61 const jsval_layout &getConstant() const {
62 JS_ASSERT(isConstant());
63 return v_;
66 const Value &getValue() const {
67 JS_ASSERT(isConstant());
68 return Valueify(JSVAL_FROM_LAYOUT(v_));
71 bool isTypeKnown() const {
72 return type.isConstant();
75 JSValueType getKnownType() const {
76 JS_ASSERT(isTypeKnown());
77 return knownType;
80 #if defined JS_NUNBOX32
81 JSValueTag getKnownTag() const {
82 return v_.s.tag;
84 #elif defined JS_PUNBOX64
85 JSValueShiftedTag getKnownShiftedTag() const {
86 return JSValueShiftedTag(v_.asBits & JSVAL_TAG_MASK);
88 #endif
90 // Return true iff the type of this value is definitely known to be type_.
91 bool isType(JSValueType type_) const {
92 return isTypeKnown() && getKnownType() == type_;
95 // Return true iff the type of this value is definitely known not to be type_.
96 bool isNotType(JSValueType type_) const {
97 return isTypeKnown() && getKnownType() != type_;
100 #if defined JS_NUNBOX32
101 uint32 getPayload32() const {
102 //JS_ASSERT(!Valueify(v_.asBits).isDouble() || type.synced());
103 return v_.s.payload.u32;
105 #elif defined JS_PUNBOX64
106 uint64 getPayload64() const {
107 return v_.asBits & JSVAL_PAYLOAD_MASK;
109 #endif
111 bool isCachedNumber() const {
112 return isNumber;
115 private:
116 void setType(JSValueType type_) {
117 type.setConstant();
118 #if defined JS_NUNBOX32
119 v_.s.tag = JSVAL_TYPE_TO_TAG(type_);
120 #elif defined JS_PUNBOX64
121 v_.asBits &= JSVAL_PAYLOAD_MASK;
122 v_.asBits |= JSVAL_TYPE_TO_SHIFTED_TAG(type_);
123 #endif
124 knownType = type_;
125 JS_ASSERT(!isNumber);
128 void track(uint32 index) {
129 clear();
130 index_ = index;
131 tracked = true;
134 void clear() {
135 copied = false;
136 copy = NULL;
137 isNumber = false;
140 uint32 trackerIndex() {
141 return index_;
145 * Marks the FE as unsynced & invalid.
147 void resetUnsynced() {
148 clear();
149 type.unsync();
150 data.unsync();
151 #ifdef DEBUG
152 type.invalidate();
153 data.invalidate();
154 #endif
158 * Marks the FE as synced & in memory.
160 void resetSynced() {
161 clear();
162 type.setMemory();
163 data.setMemory();
167 * Marks the FE as having a constant.
169 void setConstant(const jsval &v) {
170 clear();
171 type.unsync();
172 data.unsync();
173 type.setConstant();
174 data.setConstant();
175 v_.asBits = JSVAL_BITS(v);
176 Value cv = Valueify(v);
177 if (cv.isDouble())
178 knownType = JSVAL_TYPE_DOUBLE;
179 else
180 knownType = cv.extractNonDoubleType();
183 bool isCopied() const {
184 return copied;
187 void setCopied() {
188 JS_ASSERT(!isCopy());
189 copied = true;
192 bool isCopy() const {
193 return !!copy;
196 FrameEntry *copyOf() const {
197 JS_ASSERT(isCopy());
198 return copy;
201 void setNotCopied() {
202 copied = false;
206 * Set copy index.
208 void setCopyOf(FrameEntry *fe) {
209 JS_ASSERT_IF(fe, !fe->isConstant());
210 JS_ASSERT(!isCopied());
211 copy = fe;
214 inline bool isTracked() const {
215 return tracked;
218 inline void untrack() {
219 tracked = false;
222 private:
223 JSValueType knownType;
224 jsval_layout v_;
225 RematInfo type;
226 RematInfo data;
227 uint32 index_;
228 FrameEntry *copy;
229 bool copied;
230 bool isNumber;
231 bool tracked;
232 char padding[1];
235 } /* namespace mjit */
236 } /* namespace js */
238 #endif /* jsjaeger_valueinfo_h__ */