]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGLivenessAnalysisPhase.cpp
b3131a4a59480175374bcce8f72b47b3b1870f77
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()) {
73 "Bad liveness analysis result: live at root is not empty: ",
74 nodeListDump(m_graph
.block(0)->ssa
->liveAtHead
), "\n");
75 dataLog("IR at time of error:\n");
84 void process(BlockIndex blockIndex
)
86 BasicBlock
* block
= m_graph
.block(blockIndex
);
90 // FIXME: It's likely that this can be improved, for static analyses that use
91 // HashSets. https://bugs.webkit.org/show_bug.cgi?id=118455
92 m_live
= block
->ssa
->liveAtTail
;
94 for (unsigned nodeIndex
= block
->size(); nodeIndex
--;) {
95 Node
* node
= block
->at(nodeIndex
);
101 // We say that it def's @p and @n and uses @x.
107 // We say nothing. It's neither a use nor a def.
111 // n: Thingy(@a, @b, @c)
113 // We say that it def's @n and uses @a, @b, @c.
115 switch (node
->op()) {
117 Node
* phi
= node
->phi();
120 m_live
.add(node
->child1().node());
130 DFG_NODE_DO_TO_CHILDREN(m_graph
, node
, addChildUse
);
135 if (m_live
== block
->ssa
->liveAtHead
)
139 block
->ssa
->liveAtHead
= m_live
;
140 for (unsigned i
= block
->predecessors
.size(); i
--;)
141 block
->predecessors
[i
]->ssa
->liveAtTail
.add(m_live
.begin(), m_live
.end());
144 void addChildUse(Node
*, Edge
& edge
)
149 void addChildUse(Edge
& edge
)
151 edge
.setKillStatus(m_live
.add(edge
.node()).isNewEntry
? DoesKill
: DoesNotKill
);
155 HashSet
<Node
*> m_live
;
158 bool performLivenessAnalysis(Graph
& graph
)
160 SamplingRegion
samplingRegion("DFG Liveness Analysis Phase");
161 return runPhase
<LivenessAnalysisPhase
>(graph
);
164 } } // namespace JSC::DFG
166 #endif // ENABLE(DFG_JIT)