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 DFGCallArrayAllocatorSlowPathGenerator_h
27 #define DFGCallArrayAllocatorSlowPathGenerator_h
29 #include <wtf/Platform.h>
33 #include "DFGCommon.h"
34 #include "DFGSlowPathGenerator.h"
35 #include "DFGSpeculativeJIT.h"
36 #include <wtf/Vector.h>
38 namespace JSC
{ namespace DFG
{
40 class CallArrayAllocatorSlowPathGenerator
: public JumpingSlowPathGenerator
<MacroAssembler::JumpList
> {
42 CallArrayAllocatorSlowPathGenerator(
43 MacroAssembler::JumpList from
, SpeculativeJIT
* jit
, P_DFGOperation_EStZ function
,
44 GPRReg resultGPR
, GPRReg storageGPR
, Structure
* structure
, size_t size
)
45 : JumpingSlowPathGenerator
<MacroAssembler::JumpList
>(from
, jit
)
46 , m_function(function
)
47 , m_resultGPR(resultGPR
)
48 , m_storageGPR(storageGPR
)
49 , m_structure(structure
)
52 ASSERT(size
< static_cast<size_t>(std::numeric_limits
<int32_t>::max()));
53 jit
->silentSpillAllRegistersImpl(false, m_plans
, resultGPR
);
57 void generateInternal(SpeculativeJIT
* jit
)
60 for (unsigned i
= 0; i
< m_plans
.size(); ++i
)
61 jit
->silentSpill(m_plans
[i
]);
62 jit
->callOperation(m_function
, m_resultGPR
, m_structure
, m_size
);
63 GPRReg canTrample
= SpeculativeJIT::pickCanTrample(m_resultGPR
);
64 for (unsigned i
= m_plans
.size(); i
--;)
65 jit
->silentFill(m_plans
[i
], canTrample
);
66 jit
->m_jit
.loadPtr(MacroAssembler::Address(m_resultGPR
, JSObject::butterflyOffset()), m_storageGPR
);
71 P_DFGOperation_EStZ m_function
;
74 Structure
* m_structure
;
76 Vector
<SilentRegisterSavePlan
, 2> m_plans
;
79 class CallArrayAllocatorWithVariableSizeSlowPathGenerator
: public JumpingSlowPathGenerator
<MacroAssembler::JumpList
> {
81 CallArrayAllocatorWithVariableSizeSlowPathGenerator(
82 MacroAssembler::JumpList from
, SpeculativeJIT
* jit
, P_DFGOperation_EStZ function
,
83 GPRReg resultGPR
, Structure
* contiguousStructure
, Structure
* arrayStorageStructure
, GPRReg sizeGPR
)
84 : JumpingSlowPathGenerator
<MacroAssembler::JumpList
>(from
, jit
)
85 , m_function(function
)
86 , m_resultGPR(resultGPR
)
87 , m_contiguousStructure(contiguousStructure
)
88 , m_arrayStorageStructure(arrayStorageStructure
)
91 jit
->silentSpillAllRegistersImpl(false, m_plans
, resultGPR
);
95 void generateInternal(SpeculativeJIT
* jit
)
98 for (unsigned i
= 0; i
< m_plans
.size(); ++i
)
99 jit
->silentSpill(m_plans
[i
]);
100 GPRReg scratchGPR
= AssemblyHelpers::selectScratchGPR(m_sizeGPR
);
101 MacroAssembler::Jump bigLength
= jit
->m_jit
.branch32(MacroAssembler::AboveOrEqual
, m_sizeGPR
, MacroAssembler::TrustedImm32(MIN_SPARSE_ARRAY_INDEX
));
102 jit
->m_jit
.move(MacroAssembler::TrustedImmPtr(m_contiguousStructure
), scratchGPR
);
103 MacroAssembler::Jump done
= jit
->m_jit
.jump();
104 bigLength
.link(&jit
->m_jit
);
105 jit
->m_jit
.move(MacroAssembler::TrustedImmPtr(m_arrayStorageStructure
), scratchGPR
);
106 done
.link(&jit
->m_jit
);
107 jit
->callOperation(m_function
, m_resultGPR
, scratchGPR
, m_sizeGPR
);
108 GPRReg canTrample
= SpeculativeJIT::pickCanTrample(m_resultGPR
);
109 for (unsigned i
= m_plans
.size(); i
--;)
110 jit
->silentFill(m_plans
[i
], canTrample
);
115 P_DFGOperation_EStZ m_function
;
117 Structure
* m_contiguousStructure
;
118 Structure
* m_arrayStorageStructure
;
120 Vector
<SilentRegisterSavePlan
, 2> m_plans
;
123 } } // namespace JSC::DFG
125 #endif // ENABLE(DFG_JIT)
127 #endif // DFGCallArrayAllocatorSlowPathGenerator_h