2 * Copyright (C) 2012, 2013 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 DFGArrayifySlowPathGenerator_h
27 #define DFGArrayifySlowPathGenerator_h
29 #include <wtf/Platform.h>
33 #include "DFGArrayMode.h"
34 #include "DFGCommon.h"
35 #include "DFGOSRExitJumpPlaceholder.h"
36 #include "DFGOperations.h"
37 #include "DFGSlowPathGenerator.h"
38 #include "DFGSpeculativeJIT.h"
39 #include <wtf/Vector.h>
41 namespace JSC
{ namespace DFG
{
43 class ArrayifySlowPathGenerator
: public JumpingSlowPathGenerator
<MacroAssembler::JumpList
> {
45 ArrayifySlowPathGenerator(
46 const MacroAssembler::JumpList
& from
, SpeculativeJIT
* jit
, Node
* node
, GPRReg baseGPR
,
47 GPRReg propertyGPR
, GPRReg tempGPR
, GPRReg structureGPR
)
48 : JumpingSlowPathGenerator
<MacroAssembler::JumpList
>(from
, jit
)
50 , m_arrayMode(node
->arrayMode())
51 , m_structure(node
->op() == ArrayifyToStructure
? node
->structure() : 0)
53 , m_propertyGPR(propertyGPR
)
55 , m_structureGPR(structureGPR
)
57 ASSERT(m_op
== Arrayify
|| m_op
== ArrayifyToStructure
);
59 jit
->silentSpillAllRegistersImpl(false, m_plans
, InvalidGPRReg
);
61 if (m_propertyGPR
!= InvalidGPRReg
) {
62 switch (m_arrayMode
.type()) {
65 case Array::Contiguous
:
66 m_badPropertyJump
= jit
->backwardSpeculationCheck(Uncountable
, JSValueRegs(), 0);
72 m_badIndexingTypeJump
= jit
->backwardSpeculationCheck(BadIndexingType
, JSValueSource::unboxedCell(m_baseGPR
), 0);
76 void generateInternal(SpeculativeJIT
* jit
)
80 ASSERT(m_op
== Arrayify
|| m_op
== ArrayifyToStructure
);
82 if (m_propertyGPR
!= InvalidGPRReg
) {
83 switch (m_arrayMode
.type()) {
86 case Array::Contiguous
:
87 m_badPropertyJump
.fill(jit
, jit
->m_jit
.branch32(
88 MacroAssembler::AboveOrEqual
, m_propertyGPR
,
89 MacroAssembler::TrustedImm32(MIN_SPARSE_ARRAY_INDEX
)));
96 for (unsigned i
= 0; i
< m_plans
.size(); ++i
)
97 jit
->silentSpill(m_plans
[i
]);
98 switch (m_arrayMode
.type()) {
100 jit
->callOperation(operationEnsureInt32
, m_tempGPR
, m_baseGPR
);
103 jit
->callOperation(operationEnsureDouble
, m_tempGPR
, m_baseGPR
);
105 case Array::Contiguous
:
106 if (m_arrayMode
.conversion() == Array::RageConvert
)
107 jit
->callOperation(operationRageEnsureContiguous
, m_tempGPR
, m_baseGPR
);
109 jit
->callOperation(operationEnsureContiguous
, m_tempGPR
, m_baseGPR
);
111 case Array::ArrayStorage
:
112 case Array::SlowPutArrayStorage
:
113 jit
->callOperation(operationEnsureArrayStorage
, m_tempGPR
, m_baseGPR
);
119 for (unsigned i
= m_plans
.size(); i
--;)
120 jit
->silentFill(m_plans
[i
], GPRInfo::regT0
);
122 if (m_op
== ArrayifyToStructure
) {
124 m_badIndexingTypeJump
.fill(
125 jit
, jit
->m_jit
.branchWeakPtr(
126 MacroAssembler::NotEqual
,
127 MacroAssembler::Address(m_baseGPR
, JSCell::structureOffset()),
130 // Alas, we need to reload the structure because silent spilling does not save
131 // temporaries. Nor would it be useful for it to do so. Either way we're talking
134 MacroAssembler::Address(m_baseGPR
, JSCell::structureOffset()), m_structureGPR
);
136 // Finally, check that we have the kind of array storage that we wanted to get.
137 // Note that this is a backwards speculation check, which will result in the
138 // bytecode operation corresponding to this arrayification being reexecuted.
139 // That's fine, since arrayification is not user-visible.
141 MacroAssembler::Address(m_structureGPR
, Structure::indexingTypeOffset()), m_structureGPR
);
142 m_badIndexingTypeJump
.fill(
143 jit
, jit
->jumpSlowForUnwantedArrayMode(m_structureGPR
, m_arrayMode
));
151 ArrayMode m_arrayMode
;
152 Structure
* m_structure
;
154 GPRReg m_propertyGPR
;
156 GPRReg m_structureGPR
;
157 OSRExitJumpPlaceholder m_badPropertyJump
;
158 OSRExitJumpPlaceholder m_badIndexingTypeJump
;
159 Vector
<SilentRegisterSavePlan
, 2> m_plans
;
162 } } // namespace JSC::DFG
164 #endif // ENABLE(DFG_JIT)
166 #endif // DFGArrayifySlowPathGenerator_h