]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGMovHintRemovalPhase.cpp
e2cf37e901922c66819b16f8fcd763266a25b48a
2 * Copyright (C) 2015 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 "DFGMovHintRemovalPhase.h"
31 #include "BytecodeLivenessAnalysisInlines.h"
33 #include "DFGForAllKills.h"
35 #include "DFGInsertionSet.h"
36 #include "DFGMayExit.h"
38 #include "JSCInlines.h"
39 #include "OperandsInlines.h"
41 namespace JSC
{ namespace DFG
{
47 class MovHintRemovalPhase
: public Phase
{
49 MovHintRemovalPhase(Graph
& graph
)
50 : Phase(graph
, "MovHint removal")
51 , m_state(OperandsLike
, graph
.block(0)->variablesAtHead
)
59 dataLog("Graph before MovHint removal:\n");
63 for (BasicBlock
* block
: m_graph
.blocksInNaturalOrder())
70 void handleBlock(BasicBlock
* block
)
73 dataLog("Handing block ", pointerDump(block
), "\n");
75 // A MovHint is unnecessary if the local dies before it is used. We answer this question by
76 // maintaining the current exit epoch, and associating an epoch with each local. When a
77 // local dies, it gets the current exit epoch. If a MovHint occurs in the same epoch as its
78 // local, then it means there was no exit between the local's death and the MovHint - i.e.
79 // the MovHint is unnecessary.
81 Epoch currentEpoch
= Epoch::first();
83 m_state
.fill(Epoch());
84 m_graph
.forAllLiveInBytecode(
85 block
->terminal()->origin
.forExit
,
86 [&] (VirtualRegister reg
) {
87 m_state
.operand(reg
) = currentEpoch
;
91 dataLog(" Locals: ", m_state
, "\n");
93 // Assume that blocks after us exit.
96 for (unsigned nodeIndex
= block
->size(); nodeIndex
--;) {
97 Node
* node
= block
->at(nodeIndex
);
99 if (node
->op() == MovHint
) {
100 Epoch localEpoch
= m_state
.operand(node
->unlinkedLocal());
102 dataLog(" At ", node
, ": current = ", currentEpoch
, ", local = ", localEpoch
, "\n");
103 if (!localEpoch
|| localEpoch
== currentEpoch
) {
104 node
->setOpAndDefaultFlags(ZombieHint
);
105 node
->child1() = Edge();
108 m_state
.operand(node
->unlinkedLocal()) = Epoch();
111 if (mayExit(m_graph
, node
))
115 forAllKilledOperands(
116 m_graph
, block
->at(nodeIndex
- 1), node
,
117 [&] (VirtualRegister reg
) {
118 // This function is a bit sloppy - it might claim to kill a local even if
119 // it's still live after. We need to protect against that.
120 if (!!m_state
.operand(reg
))
124 dataLog(" Killed operand at ", node
, ": ", reg
, "\n");
125 m_state
.operand(reg
) = currentEpoch
;
131 Operands
<Epoch
> m_state
;
135 } // anonymous namespace
137 bool performMovHintRemoval(Graph
& graph
)
139 SamplingRegion
samplingRegion("DFG MovHint Removal Phase");
140 return runPhase
<MovHintRemovalPhase
>(graph
);
143 } } // namespace JSC::DFG
145 #endif // ENABLE(DFG_JIT)