fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | d0f1808 | 2015-05-12 18:01:28 +0000 | [diff] [blame] | 2 | * Copyright (C) 2014, 2015 Apple Inc. All rights reserved. |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 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 | |
fpizlo@apple.com | d0f1808 | 2015-05-12 18:01:28 +0000 | [diff] [blame] | 31 | #include "DFGGraph.h" |
| 32 | #include "JSCInlines.h" |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 33 | #include "OperandsInlines.h" |
| 34 | #include <wtf/ListDump.h> |
| 35 | |
| 36 | namespace JSC { namespace DFG { |
| 37 | |
fpizlo@apple.com | d0f1808 | 2015-05-12 18:01:28 +0000 | [diff] [blame] | 38 | void AvailabilityMap::pruneHeap() |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 39 | { |
| 40 | if (m_heap.isEmpty()) |
| 41 | return; |
| 42 | |
fpizlo@apple.com | 6e69370 | 2017-03-14 21:37:41 +0000 | [diff] [blame] | 43 | NodeSet possibleNodes; |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 44 | |
| 45 | for (unsigned i = m_locals.size(); i--;) { |
| 46 | if (m_locals[i].hasNode()) |
fpizlo@apple.com | 6e69370 | 2017-03-14 21:37:41 +0000 | [diff] [blame] | 47 | possibleNodes.addVoid(m_locals[i].node()); |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 48 | } |
| 49 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 50 | closeOverNodes( |
| 51 | [&] (Node* node) -> bool { |
| 52 | return possibleNodes.contains(node); |
| 53 | }, |
| 54 | [&] (Node* node) -> bool { |
| 55 | return possibleNodes.add(node).isNewEntry; |
| 56 | }); |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 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 | } |
utatane.tea@gmail.com | f1b453d | 2017-07-14 08:21:52 +0000 | [diff] [blame] | 63 | m_heap = WTFMove(newHeap); |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 64 | } |
| 65 | |
fpizlo@apple.com | d0f1808 | 2015-05-12 18:01:28 +0000 | [diff] [blame] | 66 | void AvailabilityMap::pruneByLiveness(Graph& graph, CodeOrigin where) |
| 67 | { |
| 68 | Operands<Availability> localsCopy(OperandsLike, m_locals); |
| 69 | graph.forAllLiveInBytecode( |
| 70 | where, |
| 71 | [&] (VirtualRegister reg) { |
| 72 | localsCopy.operand(reg) = m_locals.operand(reg); |
| 73 | }); |
utatane.tea@gmail.com | f1b453d | 2017-07-14 08:21:52 +0000 | [diff] [blame] | 74 | m_locals = WTFMove(localsCopy); |
fpizlo@apple.com | d0f1808 | 2015-05-12 18:01:28 +0000 | [diff] [blame] | 75 | pruneHeap(); |
| 76 | } |
| 77 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 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 | |