1/*
2 * Copyright (C) 2013-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(DFG_JIT)
29
30#include "DFGNodeFlags.h"
31#include "DFGUseKind.h"
32#include "DataFormat.h"
33#include "DumpContext.h"
34#include <wtf/PrintStream.h>
35
36namespace JSC { namespace DFG {
37
38enum FlushFormat : uint8_t {
39 DeadFlush,
40 FlushedInt32,
41 FlushedInt52,
42 FlushedDouble,
43 FlushedCell,
44 FlushedBoolean,
45 FlushedJSValue,
46 ConflictingFlush
47};
48
49inline NodeFlags resultFor(FlushFormat format)
50{
51 switch (format) {
52 case DeadFlush:
53 case FlushedJSValue:
54 case FlushedCell:
55 case ConflictingFlush:
56 return NodeResultJS;
57 case FlushedInt32:
58 return NodeResultInt32;
59 case FlushedInt52:
60 return NodeResultInt52;
61 case FlushedDouble:
62 return NodeResultDouble;
63 case FlushedBoolean:
64 return NodeResultBoolean;
65 }
66 RELEASE_ASSERT_NOT_REACHED();
67 return 0;
68}
69
70inline UseKind useKindFor(FlushFormat format)
71{
72 switch (format) {
73 case DeadFlush:
74 case FlushedJSValue:
75 case ConflictingFlush:
76 return UntypedUse;
77 case FlushedCell:
78 return CellUse;
79 case FlushedInt32:
80 return Int32Use;
81 case FlushedInt52:
82 return Int52RepUse;
83 case FlushedDouble:
84 return DoubleRepUse;
85 case FlushedBoolean:
86 return BooleanUse;
87 }
88 RELEASE_ASSERT_NOT_REACHED();
89 return UntypedUse;
90}
91
92inline UseKind uncheckedUseKindFor(FlushFormat format)
93{
94 switch (format) {
95 case DeadFlush:
96 case FlushedJSValue:
97 case ConflictingFlush:
98 return UntypedUse;
99 case FlushedCell:
100 return KnownCellUse;
101 case FlushedInt32:
102 return KnownInt32Use;
103 case FlushedInt52:
104 return Int52RepUse;
105 case FlushedDouble:
106 return DoubleRepUse;
107 case FlushedBoolean:
108 return KnownBooleanUse;
109 }
110 RELEASE_ASSERT_NOT_REACHED();
111 return UntypedUse;
112}
113
114inline SpeculatedType typeFilterFor(FlushFormat format)
115{
116 return typeFilterFor(useKindFor(format));
117}
118
119inline DataFormat dataFormatFor(FlushFormat format)
120{
121 switch (format) {
122 case DeadFlush:
123 case ConflictingFlush:
124 return DataFormatDead;
125 case FlushedJSValue:
126 return DataFormatJS;
127 case FlushedDouble:
128 return DataFormatDouble;
129 case FlushedInt32:
130 return DataFormatInt32;
131 case FlushedInt52:
132 return DataFormatInt52;
133 case FlushedCell:
134 return DataFormatCell;
135 case FlushedBoolean:
136 return DataFormatBoolean;
137 }
138 RELEASE_ASSERT_NOT_REACHED();
139 return DataFormatDead;
140}
141
142inline FlushFormat merge(FlushFormat a, FlushFormat b)
143{
144 if (a == DeadFlush)
145 return b;
146 if (b == DeadFlush)
147 return a;
148 if (a == b)
149 return a;
150 return ConflictingFlush;
151}
152
153inline bool isConcrete(FlushFormat format)
154{
155 return format != DeadFlush && format != ConflictingFlush;
156}
157
158} } // namespace JSC::DFG
159
160namespace WTF {
161
162void printInternal(PrintStream&, JSC::DFG::FlushFormat);
163
164inline JSC::DFG::FlushFormat inContext(JSC::DFG::FlushFormat format, JSC::DumpContext*)
165{
166 return format;
167}
168
169} // namespace WTF
170
171#endif // ENABLE(DFG_JIT)
172