2 * Copyright (C) 2012 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 DFGVariableEvent_h
27 #define DFGVariableEvent_h
29 #include <wtf/Platform.h>
33 #include "DFGCommon.h"
34 #include "DFGMinifiedID.h"
35 #include "DataFormat.h"
36 #include "MacroAssembler.h"
39 namespace JSC
{ namespace DFG
{
41 enum VariableEventKind
{
42 // Marks the beginning of a checkpoint. If you interpret the variable
43 // events starting at a Reset point then you'll get everything you need.
46 // Node births. Points in the code where a node becomes relevant for OSR.
47 // It may be the point where it is actually born (i.e. assigned) or it may
48 // be a later point, if it's only later in the sequence of instructions
49 // that we start to care about this node.
53 // Events related to how a node is represented.
57 // Death of a node - after this we no longer care about this node.
60 // A MovHintEvent means that a node is being associated with a bytecode operand,
61 // but that it has not been stored into that operand.
64 // A SetLocalEvent means that a node's value has actually been stored into the
65 // bytecode operand that it's associated with.
68 // Used to indicate an uninitialized VariableEvent. Don't use for other
73 union VariableRepresentation
{
74 MacroAssembler::RegisterID gpr
;
75 MacroAssembler::FPRegisterID fpr
;
78 MacroAssembler::RegisterID tagGPR
;
79 MacroAssembler::RegisterID payloadGPR
;
88 : m_kind(InvalidEventKind
)
92 static VariableEvent
reset()
99 static VariableEvent
fillGPR(VariableEventKind kind
, MinifiedID id
, MacroAssembler::RegisterID gpr
, DataFormat dataFormat
)
101 ASSERT(kind
== BirthToFill
|| kind
== Fill
);
102 ASSERT(dataFormat
!= DataFormatDouble
);
103 #if USE(JSVALUE32_64)
104 ASSERT(!(dataFormat
& DataFormatJS
));
110 event
.m_dataFormat
= dataFormat
;
114 #if USE(JSVALUE32_64)
115 static VariableEvent
fillPair(VariableEventKind kind
, MinifiedID id
, MacroAssembler::RegisterID tagGPR
, MacroAssembler::RegisterID payloadGPR
)
117 ASSERT(kind
== BirthToFill
|| kind
== Fill
);
120 event
.u
.pair
.tagGPR
= tagGPR
;
121 event
.u
.pair
.payloadGPR
= payloadGPR
;
123 event
.m_dataFormat
= DataFormatJS
;
126 #endif // USE(JSVALUE32_64)
128 static VariableEvent
fillFPR(VariableEventKind kind
, MinifiedID id
, MacroAssembler::FPRegisterID fpr
)
130 ASSERT(kind
== BirthToFill
|| kind
== Fill
);
135 event
.m_dataFormat
= DataFormatDouble
;
139 static VariableEvent
spill(VariableEventKind kind
, MinifiedID id
, VirtualRegister virtualRegister
, DataFormat format
)
141 ASSERT(kind
== BirthToSpill
|| kind
== Spill
);
144 event
.u
.virtualReg
= virtualRegister
;
146 event
.m_dataFormat
= format
;
150 static VariableEvent
death(MinifiedID id
)
154 event
.m_kind
= Death
;
158 static VariableEvent
setLocal(int operand
, DataFormat format
)
161 event
.u
.virtualReg
= operand
;
162 event
.m_kind
= SetLocalEvent
;
163 event
.m_dataFormat
= format
;
167 static VariableEvent
movHint(MinifiedID id
, int operand
)
171 event
.u
.virtualReg
= operand
;
172 event
.m_kind
= MovHintEvent
;
176 VariableEventKind
kind() const
178 return static_cast<VariableEventKind
>(m_kind
);
181 MinifiedID
id() const
183 ASSERT(m_kind
== BirthToFill
|| m_kind
== Fill
184 || m_kind
== BirthToSpill
|| m_kind
== Spill
185 || m_kind
== Death
|| m_kind
== MovHintEvent
);
189 DataFormat
dataFormat() const
191 ASSERT(m_kind
== BirthToFill
|| m_kind
== Fill
192 || m_kind
== BirthToSpill
|| m_kind
== Spill
193 || m_kind
== SetLocalEvent
);
194 return static_cast<DataFormat
>(m_dataFormat
);
197 MacroAssembler::RegisterID
gpr() const
199 ASSERT(m_kind
== BirthToFill
|| m_kind
== Fill
);
200 ASSERT(m_dataFormat
);
201 ASSERT(m_dataFormat
!= DataFormatDouble
);
202 #if USE(JSVALUE32_64)
203 ASSERT(!(m_dataFormat
& DataFormatJS
));
208 #if USE(JSVALUE32_64)
209 MacroAssembler::RegisterID
tagGPR() const
211 ASSERT(m_kind
== BirthToFill
|| m_kind
== Fill
);
212 ASSERT(m_dataFormat
& DataFormatJS
);
213 return u
.pair
.tagGPR
;
215 MacroAssembler::RegisterID
payloadGPR() const
217 ASSERT(m_kind
== BirthToFill
|| m_kind
== Fill
);
218 ASSERT(m_dataFormat
& DataFormatJS
);
219 return u
.pair
.payloadGPR
;
221 #endif // USE(JSVALUE32_64)
223 MacroAssembler::FPRegisterID
fpr() const
225 ASSERT(m_kind
== BirthToFill
|| m_kind
== Fill
);
226 ASSERT(m_dataFormat
== DataFormatDouble
);
230 VirtualRegister
virtualRegister() const
232 ASSERT(m_kind
== BirthToSpill
|| m_kind
== Spill
);
233 return static_cast<VirtualRegister
>(u
.virtualReg
);
238 ASSERT(m_kind
== SetLocalEvent
|| m_kind
== MovHintEvent
);
242 const VariableRepresentation
& variableRepresentation() const { return u
; }
244 void dump(PrintStream
&) const;
247 void dumpFillInfo(const char* name
, PrintStream
&) const;
248 void dumpSpillInfo(const char* name
, PrintStream
&) const;
252 // For BirthToFill, Fill:
253 // - The GPR or FPR, or a GPR pair.
254 // For BirthToSpill, Spill:
255 // - The virtual register.
256 // For MovHintEvent, SetLocalEvent:
257 // - The bytecode operand.
260 VariableRepresentation u
;
266 } } // namespace JSC::DFG
268 #endif // ENABLE(DFG_JIT)
270 #endif // DFGVariableEvent_h