1 | /*
|
---|
2 | * Copyright (C) 2014, 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 "DFGAvailabilityMap.h"
|
---|
28 |
|
---|
29 | #if ENABLE(DFG_JIT)
|
---|
30 |
|
---|
31 | #include "DFGGraph.h"
|
---|
32 | #include "JSCJSValueInlines.h"
|
---|
33 | #include "OperandsInlines.h"
|
---|
34 | #include <wtf/ListDump.h>
|
---|
35 |
|
---|
36 | namespace JSC { namespace DFG {
|
---|
37 |
|
---|
38 | void AvailabilityMap::pruneHeap()
|
---|
39 | {
|
---|
40 | if (m_heap.isEmpty())
|
---|
41 | return;
|
---|
42 |
|
---|
43 | NodeSet possibleNodes;
|
---|
44 |
|
---|
45 | for (unsigned i = m_locals.size(); i--;) {
|
---|
46 | if (m_locals[i].hasNode())
|
---|
47 | possibleNodes.addVoid(m_locals[i].node());
|
---|
48 | }
|
---|
49 |
|
---|
50 | closeOverNodes(
|
---|
51 | [&] (Node* node) -> bool {
|
---|
52 | return possibleNodes.contains(node);
|
---|
53 | },
|
---|
54 | [&] (Node* node) -> bool {
|
---|
55 | return possibleNodes.add(node).isNewEntry;
|
---|
56 | });
|
---|
57 |
|
---|
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);
|
---|
62 | }
|
---|
63 | m_heap = WTFMove(newHeap);
|
---|
64 | }
|
---|
65 |
|
---|
66 | void AvailabilityMap::pruneByLiveness(Graph& graph, CodeOrigin where)
|
---|
67 | {
|
---|
68 | Operands<Availability> localsCopy(OperandsLike, m_locals, Availability::unavailable());
|
---|
69 | graph.forAllLiveInBytecode(
|
---|
70 | where,
|
---|
71 | [&] (Operand reg) {
|
---|
72 | localsCopy.operand(reg) = m_locals.operand(reg);
|
---|
73 | });
|
---|
74 | m_locals = WTFMove(localsCopy);
|
---|
75 | pruneHeap();
|
---|
76 | }
|
---|
77 |
|
---|
78 | void AvailabilityMap::clear()
|
---|
79 | {
|
---|
80 | m_locals.fill(Availability());
|
---|
81 | m_heap.clear();
|
---|
82 | }
|
---|
83 |
|
---|
84 | void AvailabilityMap::dump(PrintStream& out) const
|
---|
85 | {
|
---|
86 | out.print("{locals = ", m_locals, "; heap = ", mapDump(m_heap), "}");
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool AvailabilityMap::operator==(const AvailabilityMap& other) const
|
---|
90 | {
|
---|
91 | return m_locals == other.m_locals
|
---|
92 | && m_heap == other.m_heap;
|
---|
93 | }
|
---|
94 |
|
---|
95 | void AvailabilityMap::merge(const AvailabilityMap& other)
|
---|
96 | {
|
---|
97 | for (unsigned i = other.m_locals.size(); i--;)
|
---|
98 | m_locals[i] = other.m_locals[i].merge(m_locals[i]);
|
---|
99 |
|
---|
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);
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | } } // namespace JSC::DFG
|
---|
107 |
|
---|
108 | #endif // ENABLE(DFG_JIT)
|
---|
109 |
|
---|