]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 | 1 | /* |
81345200 | 2 | * Copyright (C) 2012, 2013, 2014 Apple Inc. All rights reserved. |
6fe7ccc8 A |
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 DFGInsertionSet_h | |
81345200 | 27 | #define DFGInsertionSet_h |
6fe7ccc8 A |
28 | |
29 | #if ENABLE(DFG_JIT) | |
30 | ||
93a37866 | 31 | #include "DFGGraph.h" |
81345200 | 32 | #include <wtf/Insertion.h> |
6fe7ccc8 A |
33 | #include <wtf/Vector.h> |
34 | ||
35 | namespace JSC { namespace DFG { | |
36 | ||
81345200 | 37 | typedef WTF::Insertion<Node*> Insertion; |
6fe7ccc8 | 38 | |
6fe7ccc8 A |
39 | class InsertionSet { |
40 | public: | |
93a37866 A |
41 | InsertionSet(Graph& graph) |
42 | : m_graph(graph) | |
43 | { | |
44 | } | |
6fe7ccc8 | 45 | |
ed1e77d3 A |
46 | Graph& graph() { return m_graph; } |
47 | ||
93a37866 | 48 | Node* insert(const Insertion& insertion) |
6fe7ccc8 A |
49 | { |
50 | ASSERT(!m_insertions.size() || m_insertions.last().index() <= insertion.index()); | |
51 | m_insertions.append(insertion); | |
93a37866 | 52 | return insertion.element(); |
6fe7ccc8 A |
53 | } |
54 | ||
93a37866 | 55 | Node* insert(size_t index, Node* element) |
6fe7ccc8 | 56 | { |
93a37866 A |
57 | return insert(Insertion(index, element)); |
58 | } | |
59 | ||
81345200 A |
60 | template<typename... Params> |
61 | Node* insertNode(size_t index, SpeculatedType type, Params... params) | |
62 | { | |
63 | return insert(index, m_graph.addNode(type, params...)); | |
6fe7ccc8 A |
64 | } |
65 | ||
81345200 | 66 | Node* insertConstant( |
ed1e77d3 | 67 | size_t index, NodeOrigin origin, FrozenValue* value, |
81345200 A |
68 | NodeType op = JSConstant) |
69 | { | |
81345200 | 70 | return insertNode( |
ed1e77d3 | 71 | index, speculationFromValue(value->value()), op, origin, OpInfo(value)); |
81345200 A |
72 | } |
73 | ||
74 | Node* insertConstant( | |
ed1e77d3 | 75 | size_t index, CodeOrigin origin, FrozenValue* value, NodeType op = JSConstant) |
81345200 A |
76 | { |
77 | return insertConstant(index, NodeOrigin(origin), value, op); | |
78 | } | |
79 | ||
80 | Edge insertConstantForUse( | |
ed1e77d3 | 81 | size_t index, NodeOrigin origin, FrozenValue* value, UseKind useKind) |
81345200 A |
82 | { |
83 | NodeType op; | |
84 | if (isDouble(useKind)) | |
85 | op = DoubleConstant; | |
86 | else if (useKind == Int52RepUse) | |
87 | op = Int52Constant; | |
88 | else | |
89 | op = JSConstant; | |
90 | return Edge(insertConstant(index, origin, value, op), useKind); | |
91 | } | |
92 | ||
93 | Edge insertConstantForUse( | |
ed1e77d3 | 94 | size_t index, CodeOrigin origin, FrozenValue* value, UseKind useKind) |
81345200 A |
95 | { |
96 | return insertConstantForUse(index, NodeOrigin(origin), value, useKind); | |
97 | } | |
98 | ||
ed1e77d3 A |
99 | Node* insertConstant(size_t index, NodeOrigin origin, JSValue value, NodeType op = JSConstant) |
100 | { | |
101 | return insertConstant(index, origin, m_graph.freeze(value), op); | |
102 | } | |
103 | ||
104 | Node* insertConstant(size_t index, CodeOrigin origin, JSValue value, NodeType op = JSConstant) | |
105 | { | |
106 | return insertConstant(index, origin, m_graph.freeze(value), op); | |
107 | } | |
108 | ||
109 | Edge insertConstantForUse(size_t index, NodeOrigin origin, JSValue value, UseKind useKind) | |
110 | { | |
111 | return insertConstantForUse(index, origin, m_graph.freeze(value), useKind); | |
112 | } | |
113 | ||
114 | Edge insertConstantForUse(size_t index, CodeOrigin origin, JSValue value, UseKind useKind) | |
115 | { | |
116 | return insertConstantForUse(index, NodeOrigin(origin), value, useKind); | |
117 | } | |
118 | ||
119 | Edge insertBottomConstantForUse(size_t index, NodeOrigin origin, UseKind useKind) | |
120 | { | |
121 | if (isDouble(useKind)) | |
122 | return insertConstantForUse(index, origin, jsNumber(PNaN), useKind); | |
123 | if (useKind == Int52RepUse) | |
124 | return insertConstantForUse(index, origin, jsNumber(0), useKind); | |
125 | return insertConstantForUse(index, origin, jsUndefined(), useKind); | |
126 | } | |
127 | ||
128 | Node* insertCheck(size_t index, NodeOrigin origin, AdjacencyList children) | |
129 | { | |
130 | children = children.justChecks(); | |
131 | if (children.isEmpty()) | |
132 | return nullptr; | |
133 | return insertNode(index, SpecNone, Check, origin, children); | |
134 | } | |
135 | ||
136 | Node* insertCheck(size_t index, Node* node) | |
137 | { | |
138 | return insertCheck(index, node->origin, node->children); | |
139 | } | |
140 | ||
141 | Node* insertCheck(size_t index, NodeOrigin origin, Edge edge) | |
142 | { | |
143 | if (edge.willHaveCheck()) | |
144 | return insertNode(index, SpecNone, Check, origin, edge); | |
145 | return nullptr; | |
146 | } | |
147 | ||
93a37866 | 148 | void execute(BasicBlock* block) |
6fe7ccc8 | 149 | { |
81345200 | 150 | executeInsertions(*block, m_insertions); |
6fe7ccc8 A |
151 | } |
152 | private: | |
93a37866 A |
153 | Graph& m_graph; |
154 | Vector<Insertion, 8> m_insertions; | |
6fe7ccc8 A |
155 | }; |
156 | ||
157 | } } // namespace JSC::DFG | |
158 | ||
159 | #endif // ENABLE(DFG_JIT) | |
160 | ||
161 | #endif // DFGInsertionSet_h | |
162 |