oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | #ifndef FTLValueSource_h |
| 27 | #define FTLValueSource_h |
| 28 | |
| 29 | #include <wtf/Platform.h> |
| 30 | |
| 31 | #if ENABLE(FTL_JIT) |
| 32 | |
| 33 | #include "DFGNode.h" |
| 34 | #include <wtf/PrintStream.h> |
| 35 | #include <wtf/StdLibExtras.h> |
| 36 | |
| 37 | namespace JSC { namespace FTL { |
| 38 | |
| 39 | enum ValueSourceKind { |
| 40 | SourceNotSet, |
| 41 | ValueInJSStack, |
| 42 | Int32InJSStack, |
fpizlo@apple.com | 6921b29 | 2013-09-18 17:14:02 +0000 | [diff] [blame] | 43 | Int52InJSStack, |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 44 | DoubleInJSStack, |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 45 | SourceIsDead, |
| 46 | HaveNode |
| 47 | }; |
| 48 | |
| 49 | class ValueSource { |
| 50 | public: |
| 51 | ValueSource() |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 52 | : m_kind(SourceNotSet) |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 53 | { |
| 54 | } |
| 55 | |
| 56 | explicit ValueSource(ValueSourceKind kind) |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 57 | : m_kind(kind) |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 58 | { |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 59 | ASSERT(m_kind == SourceIsDead); |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | explicit ValueSource(DFG::Node* node) |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 63 | : m_kind(HaveNode) |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 64 | { |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 65 | m_value.node = node; |
| 66 | } |
| 67 | |
| 68 | ValueSource(ValueSourceKind kind, VirtualRegister reg) |
| 69 | : m_kind(kind) |
| 70 | { |
| 71 | ASSERT(m_kind == ValueInJSStack || m_kind == Int32InJSStack || m_kind == Int52InJSStack || m_kind == DoubleInJSStack); |
| 72 | m_value.virtualRegister = reg.offset(); |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | ValueSourceKind kind() const |
| 76 | { |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 77 | return m_kind; |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 78 | } |
| 79 | |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 80 | bool operator!() const { return kind() == SourceNotSet; } |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 81 | |
| 82 | DFG::Node* node() const |
| 83 | { |
| 84 | ASSERT(kind() == HaveNode); |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 85 | return m_value.node; |
| 86 | } |
| 87 | |
| 88 | VirtualRegister virtualRegister() const |
| 89 | { |
| 90 | ASSERT(kind() == ValueInJSStack || kind() == Int32InJSStack || kind() == Int52InJSStack || kind() == DoubleInJSStack); |
| 91 | return VirtualRegister(m_value.virtualRegister); |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void dump(PrintStream&) const; |
oliver@apple.com | 237b146 | 2013-07-25 04:05:36 +0000 | [diff] [blame] | 95 | void dumpInContext(PrintStream&, DumpContext*) const; |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 96 | |
| 97 | private: |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 98 | ValueSourceKind m_kind; |
| 99 | union { |
| 100 | DFG::Node* node; |
| 101 | int virtualRegister; |
| 102 | } m_value; |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } } // namespace JSC::FTL |
| 106 | |
| 107 | #endif // ENABLE(FTL_JIT) |
| 108 | |
| 109 | #endif // FTLValueSource_h |
| 110 | |