| 1 | /* |
| 2 | * Copyright (C) 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 | #pragma once |
| 27 | |
| 28 | #if ENABLE(JIT) |
| 29 | |
| 30 | #include "ValueRecovery.h" |
| 31 | #include "VirtualRegister.h" |
| 32 | #include <wtf/Vector.h> |
| 33 | |
| 34 | namespace JSC { |
| 35 | |
| 36 | // A CachedRecovery is a wrapper around a ValueRecovery that records where said |
| 37 | // value should go on the stack and/or in registers. Whenever we perform an |
| 38 | // operation changing the ValueRecovery, we update the CachedRecovery's member |
| 39 | // in place. |
| 40 | class CachedRecovery { |
| 41 | public: |
| 42 | CachedRecovery(ValueRecovery recovery) |
| 43 | : m_recovery { recovery } |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | CachedRecovery(CachedRecovery&) = delete; |
| 48 | CachedRecovery(CachedRecovery&&) = delete; |
| 49 | CachedRecovery& operator=(CachedRecovery&) = delete; |
| 50 | CachedRecovery& operator=(CachedRecovery&&) = delete; |
| 51 | |
| 52 | const Vector<VirtualRegister, 1>& targets() const { return m_targets; } |
| 53 | |
| 54 | void addTarget(VirtualRegister reg) |
| 55 | { |
| 56 | ASSERT(m_targets.isEmpty() || m_targets.last() < reg); |
| 57 | m_targets.append(reg); |
| 58 | } |
| 59 | |
| 60 | void removeTarget(VirtualRegister reg) |
| 61 | { |
| 62 | ASSERT_UNUSED(reg, m_targets.last() == reg); |
| 63 | m_targets.shrink(m_targets.size() - 1); |
| 64 | } |
| 65 | |
| 66 | void clearTargets() |
| 67 | { |
| 68 | m_targets.clear(); |
| 69 | } |
| 70 | |
| 71 | void setWantedJSValueRegs(JSValueRegs jsValueRegs) |
| 72 | { |
| 73 | ASSERT(m_wantedFPR == InvalidFPRReg); |
| 74 | m_wantedJSValueRegs = jsValueRegs; |
| 75 | } |
| 76 | |
| 77 | void setWantedFPR(FPRReg fpr) |
| 78 | { |
| 79 | ASSERT(!m_wantedJSValueRegs); |
| 80 | m_wantedFPR = fpr; |
| 81 | } |
| 82 | |
| 83 | // Determine whether converting this recovery into a JSValue will |
| 84 | // require additional GPRs and/or FPRs. |
| 85 | // This is guaranteed to only depend on the DataFormat, and the |
| 86 | // result of these calls will stay valid after loads and/or stores. |
| 87 | bool boxingRequiresGPR() const |
| 88 | { |
| 89 | #if USE(JSVALUE64) |
| 90 | return recovery().dataFormat() == DataFormatDouble; |
| 91 | #else |
| 92 | return false; |
| 93 | #endif |
| 94 | } |
| 95 | bool boxingRequiresFPR() const |
| 96 | { |
| 97 | #if USE(JSVALUE64) |
| 98 | switch (recovery().dataFormat()) { |
| 99 | case DataFormatInt52: |
| 100 | case DataFormatStrictInt52: |
| 101 | return true; |
| 102 | |
| 103 | default: |
| 104 | return false; |
| 105 | } |
| 106 | #else |
| 107 | return false; |
| 108 | #endif |
| 109 | } |
| 110 | |
| 111 | // This is used to determine what kind of register we need to be |
| 112 | // able to load a recovery. We only use it when a direct load is |
| 113 | // currently impossible, to determine whether we should spill a |
| 114 | // GPR or an FPR for loading this value. |
| 115 | bool loadsIntoGPR() const; |
| 116 | bool loadsIntoFPR() const; |
| 117 | |
| 118 | ValueRecovery recovery() const { return m_recovery; } |
| 119 | |
| 120 | void setRecovery(ValueRecovery recovery) { m_recovery = recovery; } |
| 121 | |
| 122 | JSValueRegs wantedJSValueRegs() const { return m_wantedJSValueRegs; } |
| 123 | |
| 124 | FPRReg wantedFPR() const { return m_wantedFPR; } |
| 125 | private: |
| 126 | Vector<VirtualRegister, 1> m_targets; |
| 127 | ValueRecovery m_recovery; |
| 128 | JSValueRegs m_wantedJSValueRegs; |
| 129 | FPRReg m_wantedFPR { InvalidFPRReg }; |
| 130 | }; |
| 131 | |
| 132 | } // namespace JSC |
| 133 | |
| 134 | #endif // ENABLE(JIT) |
| 135 | |