fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +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 | #ifndef DFGValueSource_h |
| 27 | #define DFGValueSource_h |
| 28 | |
| 29 | #include <wtf/Platform.h> |
| 30 | |
| 31 | #if ENABLE(DFG_JIT) |
| 32 | |
| 33 | #include "DFGCommon.h" |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 34 | #include "DFGMinifiedID.h" |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 35 | #include "DataFormat.h" |
| 36 | #include "SpeculatedType.h" |
| 37 | #include "ValueRecovery.h" |
| 38 | |
| 39 | namespace JSC { namespace DFG { |
| 40 | |
| 41 | enum ValueSourceKind { |
| 42 | SourceNotSet, |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 43 | ValueInJSStack, |
| 44 | Int32InJSStack, |
| 45 | CellInJSStack, |
| 46 | BooleanInJSStack, |
| 47 | DoubleInJSStack, |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 48 | ArgumentsSource, |
| 49 | SourceIsDead, |
| 50 | HaveNode |
| 51 | }; |
| 52 | |
| 53 | static inline ValueSourceKind dataFormatToValueSourceKind(DataFormat dataFormat) |
| 54 | { |
| 55 | switch (dataFormat) { |
| 56 | case DataFormatInteger: |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 57 | return Int32InJSStack; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 58 | case DataFormatDouble: |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 59 | return DoubleInJSStack; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 60 | case DataFormatBoolean: |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 61 | return BooleanInJSStack; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 62 | case DataFormatCell: |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 63 | return CellInJSStack; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 64 | case DataFormatDead: |
| 65 | return SourceIsDead; |
| 66 | case DataFormatArguments: |
| 67 | return ArgumentsSource; |
| 68 | default: |
oliver@apple.com | 903b0c0 | 2013-01-24 01:40:37 +0000 | [diff] [blame] | 69 | RELEASE_ASSERT(dataFormat & DataFormatJS); |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 70 | return ValueInJSStack; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | static inline DataFormat valueSourceKindToDataFormat(ValueSourceKind kind) |
| 75 | { |
| 76 | switch (kind) { |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 77 | case ValueInJSStack: |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 78 | return DataFormatJS; |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 79 | case Int32InJSStack: |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 80 | return DataFormatInteger; |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 81 | case CellInJSStack: |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 82 | return DataFormatCell; |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 83 | case BooleanInJSStack: |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 84 | return DataFormatBoolean; |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 85 | case DoubleInJSStack: |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 86 | return DataFormatDouble; |
| 87 | case ArgumentsSource: |
| 88 | return DataFormatArguments; |
| 89 | case SourceIsDead: |
| 90 | return DataFormatDead; |
| 91 | default: |
| 92 | return DataFormatNone; |
| 93 | } |
| 94 | } |
| 95 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 96 | static inline bool isInJSStack(ValueSourceKind kind) |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 97 | { |
| 98 | DataFormat format = valueSourceKindToDataFormat(kind); |
| 99 | return format != DataFormatNone && format < DataFormatOSRMarker; |
| 100 | } |
| 101 | |
| 102 | // Can this value be recovered without having to look at register allocation state or |
| 103 | // DFG node liveness? |
| 104 | static inline bool isTriviallyRecoverable(ValueSourceKind kind) |
| 105 | { |
| 106 | return valueSourceKindToDataFormat(kind) != DataFormatNone; |
| 107 | } |
| 108 | |
| 109 | class ValueSource { |
| 110 | public: |
| 111 | ValueSource() |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 112 | : m_value(idFromKind(SourceNotSet)) |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 113 | { |
| 114 | } |
| 115 | |
| 116 | explicit ValueSource(ValueSourceKind valueSourceKind) |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 117 | : m_value(idFromKind(valueSourceKind)) |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 118 | { |
| 119 | ASSERT(kind() != SourceNotSet); |
| 120 | ASSERT(kind() != HaveNode); |
| 121 | } |
| 122 | |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 123 | explicit ValueSource(MinifiedID id) |
fpizlo@apple.com | 8ff092f | 2013-01-29 08:01:03 +0000 | [diff] [blame] | 124 | : m_value(id) |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 125 | { |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 126 | ASSERT(!!id); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 127 | ASSERT(kind() == HaveNode); |
| 128 | } |
| 129 | |
| 130 | static ValueSource forSpeculation(SpeculatedType prediction) |
| 131 | { |
| 132 | if (isInt32Speculation(prediction)) |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 133 | return ValueSource(Int32InJSStack); |
fpizlo@apple.com | 0052843 | 2012-07-20 03:50:02 +0000 | [diff] [blame] | 134 | if (isArraySpeculation(prediction) || isCellSpeculation(prediction)) |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 135 | return ValueSource(CellInJSStack); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 136 | if (isBooleanSpeculation(prediction)) |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 137 | return ValueSource(BooleanInJSStack); |
| 138 | return ValueSource(ValueInJSStack); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static ValueSource forDataFormat(DataFormat dataFormat) |
| 142 | { |
| 143 | return ValueSource(dataFormatToValueSourceKind(dataFormat)); |
| 144 | } |
| 145 | |
| 146 | bool isSet() const |
| 147 | { |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 148 | return kindFromID(m_value) != SourceNotSet; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | ValueSourceKind kind() const |
| 152 | { |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 153 | return kindFromID(m_value); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 154 | } |
| 155 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 156 | bool isInJSStack() const { return JSC::DFG::isInJSStack(kind()); } |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 157 | bool isTriviallyRecoverable() const { return JSC::DFG::isTriviallyRecoverable(kind()); } |
| 158 | |
| 159 | DataFormat dataFormat() const |
| 160 | { |
| 161 | return valueSourceKindToDataFormat(kind()); |
| 162 | } |
| 163 | |
| 164 | ValueRecovery valueRecovery() const |
| 165 | { |
| 166 | ASSERT(isTriviallyRecoverable()); |
| 167 | switch (kind()) { |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 168 | case ValueInJSStack: |
| 169 | return ValueRecovery::alreadyInJSStack(); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 170 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 171 | case Int32InJSStack: |
| 172 | return ValueRecovery::alreadyInJSStackAsUnboxedInt32(); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 173 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 174 | case CellInJSStack: |
| 175 | return ValueRecovery::alreadyInJSStackAsUnboxedCell(); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 176 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 177 | case BooleanInJSStack: |
| 178 | return ValueRecovery::alreadyInJSStackAsUnboxedBoolean(); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 179 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 180 | case DoubleInJSStack: |
| 181 | return ValueRecovery::alreadyInJSStackAsUnboxedDouble(); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 182 | |
| 183 | case SourceIsDead: |
| 184 | return ValueRecovery::constant(jsUndefined()); |
| 185 | |
| 186 | case ArgumentsSource: |
| 187 | return ValueRecovery::argumentsThatWereNotCreated(); |
| 188 | |
| 189 | default: |
oliver@apple.com | 5598c18 | 2013-01-23 22:25:07 +0000 | [diff] [blame] | 190 | RELEASE_ASSERT_NOT_REACHED(); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 191 | return ValueRecovery(); |
| 192 | } |
| 193 | } |
| 194 | |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 195 | MinifiedID id() const |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 196 | { |
| 197 | ASSERT(kind() == HaveNode); |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 198 | return m_value; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 199 | } |
| 200 | |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 201 | void dump(PrintStream&) const; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 202 | |
| 203 | private: |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 204 | static MinifiedID idFromKind(ValueSourceKind kind) |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 205 | { |
| 206 | ASSERT(kind >= SourceNotSet && kind < HaveNode); |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 207 | return MinifiedID::fromBits(MinifiedID::invalidID() - kind); |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 208 | } |
| 209 | |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 210 | static ValueSourceKind kindFromID(MinifiedID id) |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 211 | { |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 212 | uintptr_t kind = static_cast<uintptr_t>(MinifiedID::invalidID() - id.m_id); |
| 213 | if (kind >= static_cast<uintptr_t>(HaveNode)) |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 214 | return HaveNode; |
| 215 | return static_cast<ValueSourceKind>(kind); |
| 216 | } |
| 217 | |
fpizlo@apple.com | 7e2c646 | 2013-01-26 06:07:23 +0000 | [diff] [blame] | 218 | MinifiedID m_value; |
fpizlo@apple.com | 8618e4b | 2012-07-03 01:27:16 +0000 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | } } // namespace JSC::DFG |
| 222 | |
| 223 | #endif // ENABLE(DFG_JIT) |
| 224 | |
| 225 | #endif // DFGValueSource_h |
| 226 | |