]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | /* |
2 | * Copyright (C) 2015 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 | #include "config.h" | |
27 | #include "DFGMovHintRemovalPhase.h" | |
28 | ||
29 | #if ENABLE(DFG_JIT) | |
30 | ||
31 | #include "BytecodeLivenessAnalysisInlines.h" | |
32 | #include "DFGEpoch.h" | |
33 | #include "DFGForAllKills.h" | |
34 | #include "DFGGraph.h" | |
35 | #include "DFGInsertionSet.h" | |
36 | #include "DFGMayExit.h" | |
37 | #include "DFGPhase.h" | |
38 | #include "JSCInlines.h" | |
39 | #include "OperandsInlines.h" | |
40 | ||
41 | namespace JSC { namespace DFG { | |
42 | ||
43 | namespace { | |
44 | ||
45 | bool verbose = false; | |
46 | ||
47 | class MovHintRemovalPhase : public Phase { | |
48 | public: | |
49 | MovHintRemovalPhase(Graph& graph) | |
50 | : Phase(graph, "MovHint removal") | |
51 | , m_state(OperandsLike, graph.block(0)->variablesAtHead) | |
52 | , m_changed(false) | |
53 | { | |
54 | } | |
55 | ||
56 | bool run() | |
57 | { | |
58 | if (verbose) { | |
59 | dataLog("Graph before MovHint removal:\n"); | |
60 | m_graph.dump(); | |
61 | } | |
62 | ||
63 | for (BasicBlock* block : m_graph.blocksInNaturalOrder()) | |
64 | handleBlock(block); | |
65 | ||
66 | return m_changed; | |
67 | } | |
68 | ||
69 | private: | |
70 | void handleBlock(BasicBlock* block) | |
71 | { | |
72 | if (verbose) | |
73 | dataLog("Handing block ", pointerDump(block), "\n"); | |
74 | ||
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. | |
80 | ||
81 | Epoch currentEpoch = Epoch::first(); | |
82 | ||
83 | m_state.fill(Epoch()); | |
84 | m_graph.forAllLiveInBytecode( | |
85 | block->terminal()->origin.forExit, | |
86 | [&] (VirtualRegister reg) { | |
87 | m_state.operand(reg) = currentEpoch; | |
88 | }); | |
89 | ||
90 | if (verbose) | |
91 | dataLog(" Locals: ", m_state, "\n"); | |
92 | ||
93 | // Assume that blocks after us exit. | |
94 | currentEpoch.bump(); | |
95 | ||
96 | for (unsigned nodeIndex = block->size(); nodeIndex--;) { | |
97 | Node* node = block->at(nodeIndex); | |
98 | ||
99 | if (node->op() == MovHint) { | |
100 | Epoch localEpoch = m_state.operand(node->unlinkedLocal()); | |
101 | if (verbose) | |
102 | dataLog(" At ", node, ": current = ", currentEpoch, ", local = ", localEpoch, "\n"); | |
103 | if (!localEpoch || localEpoch == currentEpoch) { | |
104 | node->setOpAndDefaultFlags(ZombieHint); | |
105 | node->child1() = Edge(); | |
106 | m_changed = true; | |
107 | } | |
108 | m_state.operand(node->unlinkedLocal()) = Epoch(); | |
109 | } | |
110 | ||
111 | if (mayExit(m_graph, node)) | |
112 | currentEpoch.bump(); | |
113 | ||
114 | if (nodeIndex) { | |
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)) | |
121 | return; | |
122 | ||
123 | if (verbose) | |
124 | dataLog(" Killed operand at ", node, ": ", reg, "\n"); | |
125 | m_state.operand(reg) = currentEpoch; | |
126 | }); | |
127 | } | |
128 | } | |
129 | } | |
130 | ||
131 | Operands<Epoch> m_state; | |
132 | bool m_changed; | |
133 | }; | |
134 | ||
135 | } // anonymous namespace | |
136 | ||
137 | bool performMovHintRemoval(Graph& graph) | |
138 | { | |
139 | SamplingRegion samplingRegion("DFG MovHint Removal Phase"); | |
140 | return runPhase<MovHintRemovalPhase>(graph); | |
141 | } | |
142 | ||
143 | } } // namespace JSC::DFG | |
144 | ||
145 | #endif // ENABLE(DFG_JIT) | |
146 |