2 * Copyright (C) 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.
27 #include "DFGOSRAvailabilityAnalysisPhase.h"
31 #include "DFGBasicBlockInlines.h"
33 #include "DFGInsertionSet.h"
35 #include "JSCInlines.h"
37 namespace JSC
{ namespace DFG
{
39 class OSRAvailabilityAnalysisPhase
: public Phase
{
41 OSRAvailabilityAnalysisPhase(Graph
& graph
)
42 : Phase(graph
, "OSR availability analysis")
48 ASSERT(m_graph
.m_form
== SSA
);
50 for (BlockIndex blockIndex
= m_graph
.numBlocks(); blockIndex
--;) {
51 BasicBlock
* block
= m_graph
.block(blockIndex
);
54 block
->ssa
->availabilityAtHead
.fill(Availability());
55 block
->ssa
->availabilityAtTail
.fill(Availability());
58 BasicBlock
* root
= m_graph
.block(0);
59 for (unsigned argument
= root
->ssa
->availabilityAtHead
.numberOfArguments(); argument
--;) {
60 root
->ssa
->availabilityAtHead
.argument(argument
) =
61 Availability::unavailable().withFlush(
62 FlushedAt(FlushedJSValue
, virtualRegisterForArgument(argument
)));
65 if (m_graph
.m_plan
.mode
== FTLForOSREntryMode
) {
66 for (unsigned local
= m_graph
.m_profiledBlock
->m_numCalleeRegisters
; local
--;)
67 root
->ssa
->availabilityAtHead
.local(local
) = Availability::unavailable();
69 for (unsigned local
= root
->ssa
->availabilityAtHead
.numberOfLocals(); local
--;)
70 root
->ssa
->availabilityAtHead
.local(local
) = Availability::unavailable();
73 // This could be made more efficient by processing blocks in reverse postorder.
74 Operands
<Availability
> availability
;
79 for (BlockIndex blockIndex
= 0; blockIndex
< m_graph
.numBlocks(); ++blockIndex
) {
80 BasicBlock
* block
= m_graph
.block(blockIndex
);
84 availability
= block
->ssa
->availabilityAtHead
;
86 for (unsigned nodeIndex
= 0; nodeIndex
< block
->size(); ++nodeIndex
) {
87 Node
* node
= block
->at(nodeIndex
);
91 VariableAccessData
* variable
= node
->variableAccessData();
92 availability
.operand(variable
->local()) =
93 Availability(node
->child1().node(), variable
->flushedAt());
98 VariableAccessData
* variable
= node
->variableAccessData();
99 availability
.operand(variable
->local()) =
100 Availability(node
, variable
->flushedAt());
105 availability
.operand(node
->unlinkedLocal()) =
106 Availability(node
->child1().node());
111 availability
.operand(node
->unlinkedLocal()) =
112 Availability::unavailable();
121 if (availability
== block
->ssa
->availabilityAtTail
)
124 block
->ssa
->availabilityAtTail
= availability
;
127 for (unsigned successorIndex
= block
->numSuccessors(); successorIndex
--;) {
128 BasicBlock
* successor
= block
->successor(successorIndex
);
129 for (unsigned i
= availability
.size(); i
--;) {
130 successor
->ssa
->availabilityAtHead
[i
] = availability
[i
].merge(
131 successor
->ssa
->availabilityAtHead
[i
]);
141 bool performOSRAvailabilityAnalysis(Graph
& graph
)
143 SamplingRegion
samplingRegion("DFG OSR Availability Analysis Phase");
144 return runPhase
<OSRAvailabilityAnalysisPhase
>(graph
);
147 } } // namespace JSC::DFG
149 #endif // ENABLE(DFG_JIT)