]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGLivenessAnalysisPhase.cpp
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 "DFGLivenessAnalysisPhase.h"
31 #include "DFGBasicBlockInlines.h"
33 #include "DFGInsertionSet.h"
35 #include "JSCInlines.h"
37 namespace JSC
{ namespace DFG
{
39 class LivenessAnalysisPhase
: public Phase
{
41 LivenessAnalysisPhase(Graph
& graph
)
42 : Phase(graph
, "liveness analysis")
48 ASSERT(m_graph
.m_form
== SSA
);
50 // Liveness is a backwards analysis; the roots are the blocks that
51 // end in a terminal (Return/Throw/ThrowReferenceError). For now, we
52 // use a fixpoint formulation since liveness is a rapid analysis with
53 // convergence guaranteed after O(connectivity).
55 // Start by assuming that everything is dead.
56 for (BlockIndex blockIndex
= m_graph
.numBlocks(); blockIndex
--;) {
57 BasicBlock
* block
= m_graph
.block(blockIndex
);
60 block
->ssa
->liveAtHead
.clear();
61 block
->ssa
->liveAtTail
.clear();
66 for (BlockIndex blockIndex
= m_graph
.numBlocks(); blockIndex
--;)
70 if (!m_graph
.block(0)->ssa
->liveAtHead
.isEmpty()) {
74 "Bad liveness analysis result: live at root is not empty: ",
75 nodeListDump(m_graph
.block(0)->ssa
->liveAtHead
)).data());
82 void process(BlockIndex blockIndex
)
84 BasicBlock
* block
= m_graph
.block(blockIndex
);
88 // FIXME: It's likely that this can be improved, for static analyses that use
89 // HashSets. https://bugs.webkit.org/show_bug.cgi?id=118455
90 m_live
= block
->ssa
->liveAtTail
;
92 for (unsigned nodeIndex
= block
->size(); nodeIndex
--;) {
93 Node
* node
= block
->at(nodeIndex
);
99 // We say that it def's @p and @n and uses @x.
105 // We say nothing. It's neither a use nor a def.
109 // n: Thingy(@a, @b, @c)
111 // We say that it def's @n and uses @a, @b, @c.
113 switch (node
->op()) {
115 Node
* phi
= node
->phi();
118 m_live
.add(node
->child1().node());
128 DFG_NODE_DO_TO_CHILDREN(m_graph
, node
, addChildUse
);
133 if (m_live
== block
->ssa
->liveAtHead
)
137 block
->ssa
->liveAtHead
= m_live
;
138 for (unsigned i
= block
->predecessors
.size(); i
--;)
139 block
->predecessors
[i
]->ssa
->liveAtTail
.add(m_live
.begin(), m_live
.end());
142 void addChildUse(Node
*, Edge
& edge
)
147 void addChildUse(Edge
& edge
)
149 edge
.setKillStatus(m_live
.add(edge
.node()).isNewEntry
? DoesKill
: DoesNotKill
);
153 HashSet
<Node
*> m_live
;
156 bool performLivenessAnalysis(Graph
& graph
)
158 SamplingRegion
samplingRegion("DFG Liveness Analysis Phase");
159 return runPhase
<LivenessAnalysisPhase
>(graph
);
162 } } // namespace JSC::DFG
164 #endif // ENABLE(DFG_JIT)