2 * Copyright (C) 2014, 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 "DFGAvailabilityMap.h"
32 #include "JSCInlines.h"
33 #include "OperandsInlines.h"
34 #include <wtf/ListDump.h>
36 namespace JSC { namespace DFG {
38 void AvailabilityMap::pruneHeap()
43 HashSet<Node*> possibleNodes;
45 for (unsigned i = m_locals.size(); i--;) {
46 if (m_locals[i].hasNode())
47 possibleNodes.add(m_locals[i].node());
51 [&] (Node* node) -> bool {
52 return possibleNodes.contains(node);
54 [&] (Node* node) -> bool {
55 return possibleNodes.add(node).isNewEntry;
58 HashMap<PromotedHeapLocation, Availability> newHeap;
59 for (auto pair : m_heap) {
60 if (possibleNodes.contains(pair.key.base()))
61 newHeap.add(pair.key, pair.value);
66 void AvailabilityMap::pruneByLiveness(Graph& graph, CodeOrigin where)
68 Operands<Availability> localsCopy(OperandsLike, m_locals);
69 graph.forAllLiveInBytecode(
71 [&] (VirtualRegister reg) {
72 localsCopy.operand(reg) = m_locals.operand(reg);
74 m_locals = localsCopy;
78 void AvailabilityMap::clear()
80 m_locals.fill(Availability());
84 void AvailabilityMap::dump(PrintStream& out) const
86 out.print("{locals = ", m_locals, "; heap = ", mapDump(m_heap), "}");
89 bool AvailabilityMap::operator==(const AvailabilityMap& other) const
91 return m_locals == other.m_locals
92 && m_heap == other.m_heap;
95 void AvailabilityMap::merge(const AvailabilityMap& other)
97 for (unsigned i = other.m_locals.size(); i--;)
98 m_locals[i] = other.m_locals[i].merge(m_locals[i]);
100 for (auto pair : other.m_heap) {
101 auto result = m_heap.add(pair.key, Availability());
102 result.iterator->value = pair.value.merge(result.iterator->value);
106 } } // namespace JSC::DFG
108 #endif // ENABLE(DFG_JIT)