]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGSSACalculator.cpp
2 * Copyright (C) 2014 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 "DFGSSACalculator.h"
31 #include "DFGBlockMapInlines.h"
32 #include <wtf/CommaPrinter.h>
33 #include <wtf/ListDump.h>
35 namespace JSC
{ namespace DFG
{
37 void SSACalculator::Variable::dump(PrintStream
& out
) const
39 out
.print("var", m_index
);
42 void SSACalculator::Variable::dumpVerbose(PrintStream
& out
) const
45 if (!m_blocksWithDefs
.isEmpty()) {
48 for (BasicBlock
* block
: m_blocksWithDefs
)
49 out
.print(comma
, *block
);
54 void SSACalculator::Def::dump(PrintStream
& out
) const
56 out
.print("def(", *m_variable
, ", ", *m_block
, ", ", m_value
, ")");
59 SSACalculator::SSACalculator(Graph
& graph
)
65 SSACalculator::~SSACalculator()
69 void SSACalculator::reset()
74 for (BlockIndex blockIndex
= m_data
.size(); blockIndex
--;) {
75 m_data
[blockIndex
].m_defs
.clear();
76 m_data
[blockIndex
].m_phis
.clear();
80 SSACalculator::Variable
* SSACalculator::newVariable()
82 return &m_variables
.alloc(Variable(m_variables
.size()));
85 SSACalculator::Def
* SSACalculator::newDef(Variable
* variable
, BasicBlock
* block
, Node
* value
)
87 Def
* def
= m_defs
.add(Def(variable
, block
, value
));
88 auto result
= m_data
[block
].m_defs
.add(variable
, def
);
89 if (result
.isNewEntry
)
90 variable
->m_blocksWithDefs
.append(block
);
92 result
.iterator
->value
= def
;
96 SSACalculator::Def
* SSACalculator::nonLocalReachingDef(BasicBlock
* block
, Variable
* variable
)
98 return reachingDefAtTail(m_graph
.m_dominators
.immediateDominatorOf(block
), variable
);
101 SSACalculator::Def
* SSACalculator::reachingDefAtTail(BasicBlock
* block
, Variable
* variable
)
103 for (; block
; block
= m_graph
.m_dominators
.immediateDominatorOf(block
)) {
104 if (Def
* def
= m_data
[block
].m_defs
.get(variable
))
110 void SSACalculator::dump(PrintStream
& out
) const
112 out
.print("<Variables: [");
114 for (unsigned i
= 0; i
< m_variables
.size(); ++i
) {
116 m_variables
[i
].dumpVerbose(out
);
118 out
.print("], Defs: [");
119 comma
= CommaPrinter();
120 for (Def
* def
: const_cast<SSACalculator
*>(this)->m_defs
)
121 out
.print(comma
, *def
);
122 out
.print("], Phis: [");
123 comma
= CommaPrinter();
124 for (Def
* def
: const_cast<SSACalculator
*>(this)->m_phis
)
125 out
.print(comma
, *def
);
126 out
.print("], Block data: [");
127 comma
= CommaPrinter();
128 for (BlockIndex blockIndex
= 0; blockIndex
< m_graph
.numBlocks(); ++blockIndex
) {
129 BasicBlock
* block
= m_graph
.block(blockIndex
);
133 out
.print(comma
, *block
, "=>(");
134 out
.print("Defs: {");
135 CommaPrinter innerComma
;
136 for (auto entry
: m_data
[block
].m_defs
)
137 out
.print(innerComma
, *entry
.key
, "->", *entry
.value
);
138 out
.print("}, Phis: {");
139 innerComma
= CommaPrinter();
140 for (Def
* def
: m_data
[block
].m_phis
)
141 out
.print(innerComma
, *def
);
147 } } // namespace JSC::DFG
149 #endif // ENABLE(DFG_JIT)