]> git.saurik.com Git - apple/javascriptcore.git/blame - dfg/DFGArrayifySlowPathGenerator.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGArrayifySlowPathGenerator.h
CommitLineData
93a37866
A
1/*
2 * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
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 DFGArrayifySlowPathGenerator_h
27#define DFGArrayifySlowPathGenerator_h
28
93a37866
A
29#if ENABLE(DFG_JIT)
30
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>
38
39namespace JSC { namespace DFG {
40
41class ArrayifySlowPathGenerator : public JumpingSlowPathGenerator<MacroAssembler::JumpList> {
42public:
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)
47 , m_op(node->op())
48 , m_arrayMode(node->arrayMode())
49 , m_structure(node->op() == ArrayifyToStructure ? node->structure() : 0)
50 , m_baseGPR(baseGPR)
51 , m_propertyGPR(propertyGPR)
52 , m_tempGPR(tempGPR)
53 , m_structureGPR(structureGPR)
54 {
55 ASSERT(m_op == Arrayify || m_op == ArrayifyToStructure);
56
57 jit->silentSpillAllRegistersImpl(false, m_plans, InvalidGPRReg);
58
59 if (m_propertyGPR != InvalidGPRReg) {
60 switch (m_arrayMode.type()) {
61 case Array::Int32:
62 case Array::Double:
63 case Array::Contiguous:
81345200 64 m_badPropertyJump = jit->speculationCheck(Uncountable, JSValueRegs(), 0);
93a37866
A
65 break;
66 default:
67 break;
68 }
69 }
81345200 70 m_badIndexingTypeJump = jit->speculationCheck(BadIndexingType, JSValueSource::unboxedCell(m_baseGPR), 0);
93a37866
A
71 }
72
73protected:
81345200 74 virtual void generateInternal(SpeculativeJIT* jit) override
93a37866
A
75 {
76 linkFrom(jit);
77
78 ASSERT(m_op == Arrayify || m_op == ArrayifyToStructure);
79
80 if (m_propertyGPR != InvalidGPRReg) {
81 switch (m_arrayMode.type()) {
82 case Array::Int32:
83 case Array::Double:
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)));
88 break;
89 default:
90 break;
91 }
92 }
93
94 for (unsigned i = 0; i < m_plans.size(); ++i)
95 jit->silentSpill(m_plans[i]);
96 switch (m_arrayMode.type()) {
97 case Array::Int32:
98 jit->callOperation(operationEnsureInt32, m_tempGPR, m_baseGPR);
99 break;
100 case Array::Double:
101 jit->callOperation(operationEnsureDouble, m_tempGPR, m_baseGPR);
102 break;
103 case Array::Contiguous:
ed1e77d3 104 jit->callOperation(operationEnsureContiguous, m_tempGPR, m_baseGPR);
93a37866
A
105 break;
106 case Array::ArrayStorage:
107 case Array::SlowPutArrayStorage:
108 jit->callOperation(operationEnsureArrayStorage, m_tempGPR, m_baseGPR);
109 break;
110 default:
111 CRASH();
112 break;
113 }
114 for (unsigned i = m_plans.size(); i--;)
115 jit->silentFill(m_plans[i], GPRInfo::regT0);
116
117 if (m_op == ArrayifyToStructure) {
118 ASSERT(m_structure);
119 m_badIndexingTypeJump.fill(
81345200 120 jit, jit->m_jit.branchWeakStructure(MacroAssembler::NotEqual, MacroAssembler::Address(m_baseGPR, JSCell::structureIDOffset()), m_structure));
93a37866 121 } else {
93a37866
A
122 // Finally, check that we have the kind of array storage that we wanted to get.
123 // Note that this is a backwards speculation check, which will result in the
124 // bytecode operation corresponding to this arrayification being reexecuted.
125 // That's fine, since arrayification is not user-visible.
126 jit->m_jit.load8(
81345200 127 MacroAssembler::Address(m_baseGPR, JSCell::indexingTypeOffset()), m_structureGPR);
93a37866
A
128 m_badIndexingTypeJump.fill(
129 jit, jit->jumpSlowForUnwantedArrayMode(m_structureGPR, m_arrayMode));
130 }
131
132 jumpTo(jit);
133 }
134
135private:
136 NodeType m_op;
137 ArrayMode m_arrayMode;
138 Structure* m_structure;
139 GPRReg m_baseGPR;
140 GPRReg m_propertyGPR;
141 GPRReg m_tempGPR;
142 GPRReg m_structureGPR;
143 OSRExitJumpPlaceholder m_badPropertyJump;
144 OSRExitJumpPlaceholder m_badIndexingTypeJump;
145 Vector<SilentRegisterSavePlan, 2> m_plans;
146};
147
148} } // namespace JSC::DFG
149
150#endif // ENABLE(DFG_JIT)
151
152#endif // DFGArrayifySlowPathGenerator_h
153