blob: 3a4a55bd99febb8a9b59d91b5a0bcf2251ab65fb [file] [log] [blame]
oliver@apple.comea771492013-07-25 03:58:38 +00001/*
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
37namespace JSC { namespace FTL {
38
39enum ValueSourceKind {
40 SourceNotSet,
41 ValueInJSStack,
42 Int32InJSStack,
fpizlo@apple.com6921b292013-09-18 17:14:02 +000043 Int52InJSStack,
oliver@apple.comea771492013-07-25 03:58:38 +000044 DoubleInJSStack,
oliver@apple.comea771492013-07-25 03:58:38 +000045 SourceIsDead,
46 HaveNode
47};
48
49class ValueSource {
50public:
51 ValueSource()
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000052 : m_kind(SourceNotSet)
oliver@apple.comea771492013-07-25 03:58:38 +000053 {
54 }
55
56 explicit ValueSource(ValueSourceKind kind)
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000057 : m_kind(kind)
oliver@apple.comea771492013-07-25 03:58:38 +000058 {
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000059 ASSERT(m_kind == SourceIsDead);
oliver@apple.comea771492013-07-25 03:58:38 +000060 }
61
62 explicit ValueSource(DFG::Node* node)
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000063 : m_kind(HaveNode)
oliver@apple.comea771492013-07-25 03:58:38 +000064 {
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000065 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.comea771492013-07-25 03:58:38 +000073 }
74
75 ValueSourceKind kind() const
76 {
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000077 return m_kind;
oliver@apple.comea771492013-07-25 03:58:38 +000078 }
79
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000080 bool operator!() const { return kind() == SourceNotSet; }
oliver@apple.comea771492013-07-25 03:58:38 +000081
82 DFG::Node* node() const
83 {
84 ASSERT(kind() == HaveNode);
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000085 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.comea771492013-07-25 03:58:38 +000092 }
93
94 void dump(PrintStream&) const;
oliver@apple.com237b1462013-07-25 04:05:36 +000095 void dumpInContext(PrintStream&, DumpContext*) const;
oliver@apple.comea771492013-07-25 03:58:38 +000096
97private:
fpizlo@apple.coma62d4822013-10-06 04:22:43 +000098 ValueSourceKind m_kind;
99 union {
100 DFG::Node* node;
101 int virtualRegister;
102 } m_value;
oliver@apple.comea771492013-07-25 03:58:38 +0000103};
104
105} } // namespace JSC::FTL
106
107#endif // ENABLE(FTL_JIT)
108
109#endif // FTLValueSource_h
110