Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/compiler/node-properties-inl.h

Issue 883613006: [turbofan] Cleanup the NodeProperties. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/node-properties.cc ('k') | src/compiler/representation-change.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_COMPILER_NODE_PROPERTIES_INL_H_
6 #define V8_COMPILER_NODE_PROPERTIES_INL_H_
7
8 #include "src/v8.h"
9
10 #include "src/compiler/common-operator.h"
11 #include "src/compiler/node-properties.h"
12 #include "src/compiler/opcodes.h"
13 #include "src/compiler/operator.h"
14 #include "src/compiler/operator-properties.h"
15
16 namespace v8 {
17 namespace internal {
18 namespace compiler {
19
20 // -----------------------------------------------------------------------------
21 // Input layout.
22 // Inputs are always arranged in order as follows:
23 // 0 [ values, context, effects, control ] node->InputCount()
24
25 inline int NodeProperties::FirstValueIndex(Node* node) { return 0; }
26
27 inline int NodeProperties::FirstContextIndex(Node* node) {
28 return PastValueIndex(node);
29 }
30
31 inline int NodeProperties::FirstFrameStateIndex(Node* node) {
32 return PastContextIndex(node);
33 }
34
35 inline int NodeProperties::FirstEffectIndex(Node* node) {
36 return PastFrameStateIndex(node);
37 }
38
39 inline int NodeProperties::FirstControlIndex(Node* node) {
40 return PastEffectIndex(node);
41 }
42
43
44 inline int NodeProperties::PastValueIndex(Node* node) {
45 return FirstValueIndex(node) + node->op()->ValueInputCount();
46 }
47
48 inline int NodeProperties::PastContextIndex(Node* node) {
49 return FirstContextIndex(node) +
50 OperatorProperties::GetContextInputCount(node->op());
51 }
52
53 inline int NodeProperties::PastFrameStateIndex(Node* node) {
54 return FirstFrameStateIndex(node) +
55 OperatorProperties::GetFrameStateInputCount(node->op());
56 }
57
58 inline int NodeProperties::PastEffectIndex(Node* node) {
59 return FirstEffectIndex(node) + node->op()->EffectInputCount();
60 }
61
62 inline int NodeProperties::PastControlIndex(Node* node) {
63 return FirstControlIndex(node) + node->op()->ControlInputCount();
64 }
65
66
67 // -----------------------------------------------------------------------------
68 // Input accessors.
69
70 inline Node* NodeProperties::GetValueInput(Node* node, int index) {
71 DCHECK(0 <= index && index < node->op()->ValueInputCount());
72 return node->InputAt(FirstValueIndex(node) + index);
73 }
74
75 inline Node* NodeProperties::GetContextInput(Node* node) {
76 DCHECK(OperatorProperties::HasContextInput(node->op()));
77 return node->InputAt(FirstContextIndex(node));
78 }
79
80 inline Node* NodeProperties::GetFrameStateInput(Node* node) {
81 DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
82 return node->InputAt(FirstFrameStateIndex(node));
83 }
84
85 inline Node* NodeProperties::GetEffectInput(Node* node, int index) {
86 DCHECK(0 <= index && index < node->op()->EffectInputCount());
87 return node->InputAt(FirstEffectIndex(node) + index);
88 }
89
90 inline Node* NodeProperties::GetControlInput(Node* node, int index) {
91 DCHECK(0 <= index && index < node->op()->ControlInputCount());
92 return node->InputAt(FirstControlIndex(node) + index);
93 }
94
95 inline int NodeProperties::GetFrameStateIndex(Node* node) {
96 DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
97 return FirstFrameStateIndex(node);
98 }
99
100 // -----------------------------------------------------------------------------
101 // Edge kinds.
102
103 inline bool NodeProperties::IsInputRange(Edge edge, int first, int num) {
104 // TODO(titzer): edge.index() is linear time;
105 // edges maybe need to be marked as value/effect/control.
106 if (num == 0) return false;
107 int index = edge.index();
108 return first <= index && index < first + num;
109 }
110
111 inline bool NodeProperties::IsValueEdge(Edge edge) {
112 Node* node = edge.from();
113 return IsInputRange(edge, FirstValueIndex(node),
114 node->op()->ValueInputCount());
115 }
116
117 inline bool NodeProperties::IsContextEdge(Edge edge) {
118 Node* node = edge.from();
119 return IsInputRange(edge, FirstContextIndex(node),
120 OperatorProperties::GetContextInputCount(node->op()));
121 }
122
123 inline bool NodeProperties::IsEffectEdge(Edge edge) {
124 Node* node = edge.from();
125 return IsInputRange(edge, FirstEffectIndex(node),
126 node->op()->EffectInputCount());
127 }
128
129 inline bool NodeProperties::IsControlEdge(Edge edge) {
130 Node* node = edge.from();
131 return IsInputRange(edge, FirstControlIndex(node),
132 node->op()->ControlInputCount());
133 }
134
135
136 // -----------------------------------------------------------------------------
137 // Miscellaneous predicates.
138
139 inline bool NodeProperties::IsControl(Node* node) {
140 return IrOpcode::IsControlOpcode(node->opcode());
141 }
142
143
144 // -----------------------------------------------------------------------------
145 // Miscellaneous mutators.
146
147 inline void NodeProperties::ReplaceContextInput(Node* node, Node* context) {
148 node->ReplaceInput(FirstContextIndex(node), context);
149 }
150
151 inline void NodeProperties::ReplaceControlInput(Node* node, Node* control) {
152 node->ReplaceInput(FirstControlIndex(node), control);
153 }
154
155 inline void NodeProperties::ReplaceEffectInput(Node* node, Node* effect,
156 int index) {
157 DCHECK(index < node->op()->EffectInputCount());
158 return node->ReplaceInput(FirstEffectIndex(node) + index, effect);
159 }
160
161 inline void NodeProperties::ReplaceFrameStateInput(Node* node,
162 Node* frame_state) {
163 DCHECK(OperatorProperties::HasFrameStateInput(node->op()));
164 node->ReplaceInput(FirstFrameStateIndex(node), frame_state);
165 }
166
167 inline void NodeProperties::RemoveNonValueInputs(Node* node) {
168 node->TrimInputCount(node->op()->ValueInputCount());
169 }
170
171
172 // Replace value uses of {node} with {value} and effect uses of {node} with
173 // {effect}. If {effect == NULL}, then use the effect input to {node}.
174 inline void NodeProperties::ReplaceWithValue(Node* node, Node* value,
175 Node* effect) {
176 DCHECK(node->op()->ControlOutputCount() == 0);
177 if (effect == NULL && node->op()->EffectInputCount() > 0) {
178 effect = NodeProperties::GetEffectInput(node);
179 }
180
181 // Requires distinguishing between value and effect edges.
182 for (Edge edge : node->use_edges()) {
183 if (NodeProperties::IsEffectEdge(edge)) {
184 DCHECK_NE(NULL, effect);
185 edge.UpdateTo(effect);
186 } else {
187 edge.UpdateTo(value);
188 }
189 }
190 }
191
192
193 // -----------------------------------------------------------------------------
194 // Type Bounds.
195
196 inline bool NodeProperties::IsTyped(Node* node) {
197 Bounds bounds = node->bounds();
198 DCHECK((bounds.lower == NULL) == (bounds.upper == NULL));
199 return bounds.upper != NULL;
200 }
201
202 inline Bounds NodeProperties::GetBounds(Node* node) {
203 DCHECK(IsTyped(node));
204 return node->bounds();
205 }
206
207 inline void NodeProperties::RemoveBounds(Node* node) {
208 Bounds empty;
209 node->set_bounds(empty);
210 }
211
212 inline void NodeProperties::SetBounds(Node* node, Bounds b) {
213 DCHECK(b.lower != NULL && b.upper != NULL);
214 node->set_bounds(b);
215 }
216
217 inline bool NodeProperties::AllValueInputsAreTyped(Node* node) {
218 int input_count = node->op()->ValueInputCount();
219 for (int i = 0; i < input_count; ++i) {
220 if (!IsTyped(GetValueInput(node, i))) return false;
221 }
222 return true;
223 }
224
225
226 }
227 }
228 } // namespace v8::internal::compiler
229
230 #endif // V8_COMPILER_NODE_PROPERTIES_INL_H_
OLDNEW
« no previous file with comments | « src/compiler/node-properties.cc ('k') | src/compiler/representation-change.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698