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
31 #include "DFGArrayMode.h"
32 #include "DFGCommon.h"
33 #include "DFGOSRExitJumpPlaceholder.h"
34 #include "DFGOperations.h"
35 #include "DFGSlowPathGenerator.h"
36 #include "DFGSpeculativeJIT.h"
37 #include <wtf/Vector.h>
39 namespace JSC
{ namespace DFG
{
41 class ArrayifySlowPathGenerator
: public JumpingSlowPathGenerator
<MacroAssembler::JumpList
> {
43 ArrayifySlowPathGenerator(
44 const MacroAssembler::JumpList
& from
, SpeculativeJIT
* jit
, Node
* node
, GPRReg baseGPR
,
45 GPRReg propertyGPR
, GPRReg tempGPR
, GPRReg structureGPR
)
46 : JumpingSlowPathGenerator
<MacroAssembler::JumpList
>(from
, jit
)
48 , m_arrayMode(node
->arrayMode())
49 , m_structure(node
->op() == ArrayifyToStructure
? node
->structure() : 0)
51 , m_propertyGPR(propertyGPR
)
53 , m_structureGPR(structureGPR
)
55 ASSERT(m_op
== Arrayify
|| m_op
== ArrayifyToStructure
);
57 jit
->silentSpillAllRegistersImpl(false, m_plans
, InvalidGPRReg
);
59 if (m_propertyGPR
!= InvalidGPRReg
) {
60 switch (m_arrayMode
.type()) {
63 case Array::Contiguous
:
64 m_badPropertyJump
= jit
->speculationCheck(Uncountable
, JSValueRegs(), 0);
70 m_badIndexingTypeJump
= jit
->speculationCheck(BadIndexingType
, JSValueSource::unboxedCell(m_baseGPR
), 0);
74 virtual void generateInternal(SpeculativeJIT
* jit
) override
78 ASSERT(m_op
== Arrayify
|| m_op
== ArrayifyToStructure
);
80 if (m_propertyGPR
!= InvalidGPRReg
) {
81 switch (m_arrayMode
.type()) {
84 case Array::Contiguous
:
85 m_badPropertyJump
.fill(jit
, jit
->m_jit
.branch32(
86 MacroAssembler::AboveOrEqual
, m_propertyGPR
,
87 MacroAssembler::TrustedImm32(MIN_SPARSE_ARRAY_INDEX
)));
94 for (unsigned i
= 0; i
< m_plans
.size(); ++i
)
95 jit
->silentSpill(m_plans
[i
]);
96 switch (m_arrayMode
.type()) {
98 jit
->callOperation(operationEnsureInt32
, m_tempGPR
, m_baseGPR
);
101 jit
->callOperation(operationEnsureDouble
, m_tempGPR
, m_baseGPR
);
103 case Array::Contiguous
:
104 if (m_arrayMode
.conversion() == Array::RageConvert
)
105 jit
->callOperation(operationRageEnsureContiguous
, m_tempGPR
, m_baseGPR
);
107 jit
->callOperation(operationEnsureContiguous
, m_tempGPR
, m_baseGPR
);
109 case Array::ArrayStorage
:
110 case Array::SlowPutArrayStorage
:
111 jit
->callOperation(operationEnsureArrayStorage
, m_tempGPR
, m_baseGPR
);
117 for (unsigned i
= m_plans
.size(); i
--;)
118 jit
->silentFill(m_plans
[i
], GPRInfo::regT0
);
120 if (m_op
== ArrayifyToStructure
) {
122 m_badIndexingTypeJump
.fill(
123 jit
, jit
->m_jit
.branchWeakStructure(MacroAssembler::NotEqual
, MacroAssembler::Address(m_baseGPR
, JSCell::structureIDOffset()), m_structure
));
125 // Finally, check that we have the kind of array storage that we wanted to get.
126 // Note that this is a backwards speculation check, which will result in the
127 // bytecode operation corresponding to this arrayification being reexecuted.
128 // That's fine, since arrayification is not user-visible.
130 MacroAssembler::Address(m_baseGPR
, JSCell::indexingTypeOffset()), m_structureGPR
);
131 m_badIndexingTypeJump
.fill(
132 jit
, jit
->jumpSlowForUnwantedArrayMode(m_structureGPR
, m_arrayMode
));
140 ArrayMode m_arrayMode
;
141 Structure
* m_structure
;
143 GPRReg m_propertyGPR
;
145 GPRReg m_structureGPR
;
146 OSRExitJumpPlaceholder m_badPropertyJump
;
147 OSRExitJumpPlaceholder m_badIndexingTypeJump
;
148 Vector
<SilentRegisterSavePlan
, 2> m_plans
;
151 } } // namespace JSC::DFG
153 #endif // ENABLE(DFG_JIT)
155 #endif // DFGArrayifySlowPathGenerator_h