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

Side by Side Diff: src/compiler/machine-node-factory.h

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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_MACHINE_NODE_FACTORY_H_
6 #define V8_COMPILER_MACHINE_NODE_FACTORY_H_
7
8 #ifdef USE_SIMULATOR
9 #define MACHINE_ASSEMBLER_SUPPORTS_CALL_C 0
10 #else
11 #define MACHINE_ASSEMBLER_SUPPORTS_CALL_C 1
12 #endif
13
14 #include "src/v8.h"
15
16 #include "src/compiler/machine-operator.h"
17 #include "src/compiler/node.h"
18
19 namespace v8 {
20 namespace internal {
21 namespace compiler {
22
23 class MachineCallDescriptorBuilder : public ZoneObject {
24 public:
25 MachineCallDescriptorBuilder(MachineRepresentation return_type,
26 int parameter_count,
27 const MachineRepresentation* parameter_types)
28 : return_type_(return_type),
29 parameter_count_(parameter_count),
30 parameter_types_(parameter_types) {}
31
32 int parameter_count() const { return parameter_count_; }
33 const MachineRepresentation* parameter_types() const {
34 return parameter_types_;
35 }
36
37 CallDescriptor* BuildCallDescriptor(Zone* zone) {
38 return Linkage::GetSimplifiedCDescriptor(zone, parameter_count_,
39 return_type_, parameter_types_);
40 }
41
42 private:
43 const MachineRepresentation return_type_;
44 const int parameter_count_;
45 const MachineRepresentation* const parameter_types_;
46 };
47
48
49 #define ZONE() static_cast<NodeFactory*>(this)->zone()
50 #define COMMON() static_cast<NodeFactory*>(this)->common()
51 #define MACHINE() \
52 static_cast<NodeFactory*>(this)->machine()
53 #define NEW_NODE_0(op) static_cast<NodeFactory*>(this)->NewNode(op)
54 #define NEW_NODE_1(op, a) \
55 static_cast<NodeFactory*>(this)->NewNode(op, a)
56 #define NEW_NODE_2(op, a, b) \
57 static_cast<NodeFactory*>(this)->NewNode(op, a, b)
58 #define NEW_NODE_3(op, a, b, c) \
59 static_cast<NodeFactory*>(this)->NewNode(op, a, b, c)
60
61 template<typename NodeFactory>
62 class MachineNodeFactory {
63 public:
64 // Constants.
65 Node* PointerConstant(void* value) {
66 return IntPtrConstant(reinterpret_cast<intptr_t>(value));
67 }
68 Node* IntPtrConstant(intptr_t value) {
69 // TODO(dcarney): mark generated code as unserializable if value != 0.
70 return kPointerSize == 8 ? Int64Constant(value) : Int32Constant(value);
71 }
72 Node* Int32Constant(int32_t value) {
73 return NEW_NODE_0(COMMON()->Int32Constant(value));
74 }
75 Node* Int64Constant(int64_t value) {
76 return NEW_NODE_0(COMMON()->Int64Constant(value));
77 }
78 Node* NumberConstant(double value) {
79 return NEW_NODE_0(COMMON()->NumberConstant(value));
80 }
81 Node* Float64Constant(double value) {
82 return NEW_NODE_0(COMMON()->Float64Constant(value));
83 }
84 Node* HeapConstant(Handle<Object> object) {
85 PrintableUnique<Object> val =
86 PrintableUnique<Object>::CreateUninitialized(ZONE(), object);
87 return NEW_NODE_0(COMMON()->HeapConstant(val));
88 }
89
90 // Memory Operations.
91 Node* Load(MachineRepresentation rep, Node* base) {
92 return Load(rep, base, Int32Constant(0));
93 }
94 Node* Load(MachineRepresentation rep, Node* base, Node* index) {
95 return NEW_NODE_2(MACHINE()->Load(rep), base, index);
96 }
97 void Store(MachineRepresentation rep, Node* base, Node* value) {
98 Store(rep, base, Int32Constant(0), value);
99 }
100 void Store(MachineRepresentation rep, Node* base, Node* index, Node* value) {
101 NEW_NODE_3(MACHINE()->Store(rep), base, index, value);
102 }
103 // Arithmetic Operations.
104 Node* WordAnd(Node* a, Node* b) {
105 return NEW_NODE_2(MACHINE()->WordAnd(), a, b);
106 }
107 Node* WordOr(Node* a, Node* b) {
108 return NEW_NODE_2(MACHINE()->WordOr(), a, b);
109 }
110 Node* WordXor(Node* a, Node* b) {
111 return NEW_NODE_2(MACHINE()->WordXor(), a, b);
112 }
113 Node* WordShl(Node* a, Node* b) {
114 return NEW_NODE_2(MACHINE()->WordShl(), a, b);
115 }
116 Node* WordShr(Node* a, Node* b) {
117 return NEW_NODE_2(MACHINE()->WordShr(), a, b);
118 }
119 Node* WordSar(Node* a, Node* b) {
120 return NEW_NODE_2(MACHINE()->WordSar(), a, b);
121 }
122 Node* WordEqual(Node* a, Node* b) {
123 return NEW_NODE_2(MACHINE()->WordEqual(), a, b);
124 }
125 Node* WordNotEqual(Node* a, Node* b) {
126 return WordBinaryNot(WordEqual(a, b));
127 }
128 Node* WordNot(Node* a) {
129 if (MACHINE()->is32()) {
130 return Word32Not(a);
131 } else {
132 return Word64Not(a);
133 }
134 }
135 Node* WordBinaryNot(Node* a) {
136 if (MACHINE()->is32()) {
137 return Word32BinaryNot(a);
138 } else {
139 return Word64BinaryNot(a);
140 }
141 }
142
143 Node* Word32And(Node* a, Node* b) {
144 return NEW_NODE_2(MACHINE()->Word32And(), a, b);
145 }
146 Node* Word32Or(Node* a, Node* b) {
147 return NEW_NODE_2(MACHINE()->Word32Or(), a, b);
148 }
149 Node* Word32Xor(Node* a, Node* b) {
150 return NEW_NODE_2(MACHINE()->Word32Xor(), a, b);
151 }
152 Node* Word32Shl(Node* a, Node* b) {
153 return NEW_NODE_2(MACHINE()->Word32Shl(), a, b);
154 }
155 Node* Word32Shr(Node* a, Node* b) {
156 return NEW_NODE_2(MACHINE()->Word32Shr(), a, b);
157 }
158 Node* Word32Sar(Node* a, Node* b) {
159 return NEW_NODE_2(MACHINE()->Word32Sar(), a, b);
160 }
161 Node* Word32Equal(Node* a, Node* b) {
162 return NEW_NODE_2(MACHINE()->Word32Equal(), a, b);
163 }
164 Node* Word32NotEqual(Node* a, Node* b) {
165 return Word32BinaryNot(Word32Equal(a, b));
166 }
167 Node* Word32Not(Node* a) { return Word32Xor(a, Int32Constant(-1)); }
168 Node* Word32BinaryNot(Node* a) { return Word32Equal(a, Int32Constant(0)); }
169
170 Node* Word64And(Node* a, Node* b) {
171 return NEW_NODE_2(MACHINE()->Word64And(), a, b);
172 }
173 Node* Word64Or(Node* a, Node* b) {
174 return NEW_NODE_2(MACHINE()->Word64Or(), a, b);
175 }
176 Node* Word64Xor(Node* a, Node* b) {
177 return NEW_NODE_2(MACHINE()->Word64Xor(), a, b);
178 }
179 Node* Word64Shl(Node* a, Node* b) {
180 return NEW_NODE_2(MACHINE()->Word64Shl(), a, b);
181 }
182 Node* Word64Shr(Node* a, Node* b) {
183 return NEW_NODE_2(MACHINE()->Word64Shr(), a, b);
184 }
185 Node* Word64Sar(Node* a, Node* b) {
186 return NEW_NODE_2(MACHINE()->Word64Sar(), a, b);
187 }
188 Node* Word64Equal(Node* a, Node* b) {
189 return NEW_NODE_2(MACHINE()->Word64Equal(), a, b);
190 }
191 Node* Word64NotEqual(Node* a, Node* b) {
192 return Word64BinaryNot(Word64Equal(a, b));
193 }
194 Node* Word64Not(Node* a) { return Word64Xor(a, Int64Constant(-1)); }
195 Node* Word64BinaryNot(Node* a) { return Word64Equal(a, Int64Constant(0)); }
196
197 Node* Int32Add(Node* a, Node* b) {
198 return NEW_NODE_2(MACHINE()->Int32Add(), a, b);
199 }
200 Node* Int32Sub(Node* a, Node* b) {
201 return NEW_NODE_2(MACHINE()->Int32Sub(), a, b);
202 }
203 Node* Int32Mul(Node* a, Node* b) {
204 return NEW_NODE_2(MACHINE()->Int32Mul(), a, b);
205 }
206 Node* Int32Div(Node* a, Node* b) {
207 return NEW_NODE_2(MACHINE()->Int32Div(), a, b);
208 }
209 Node* Int32UDiv(Node* a, Node* b) {
210 return NEW_NODE_2(MACHINE()->Int32UDiv(), a, b);
211 }
212 Node* Int32Mod(Node* a, Node* b) {
213 return NEW_NODE_2(MACHINE()->Int32Mod(), a, b);
214 }
215 Node* Int32UMod(Node* a, Node* b) {
216 return NEW_NODE_2(MACHINE()->Int32UMod(), a, b);
217 }
218 Node* Int32LessThan(Node* a, Node* b) {
219 return NEW_NODE_2(MACHINE()->Int32LessThan(), a, b);
220 }
221 Node* Int32LessThanOrEqual(Node* a, Node* b) {
222 return NEW_NODE_2(MACHINE()->Int32LessThanOrEqual(), a, b);
223 }
224 Node* Uint32LessThan(Node* a, Node* b) {
225 return NEW_NODE_2(MACHINE()->Uint32LessThan(), a, b);
226 }
227 Node* Uint32LessThanOrEqual(Node* a, Node* b) {
228 return NEW_NODE_2(MACHINE()->Uint32LessThanOrEqual(), a, b);
229 }
230 Node* Int32GreaterThan(Node* a, Node* b) { return Int32LessThan(b, a); }
231 Node* Int32GreaterThanOrEqual(Node* a, Node* b) {
232 return Int32LessThanOrEqual(b, a);
233 }
234 Node* Int32Neg(Node* a) { return Int32Sub(Int32Constant(0), a); }
235
236 Node* Int64Add(Node* a, Node* b) {
237 return NEW_NODE_2(MACHINE()->Int64Add(), a, b);
238 }
239 Node* Int64Sub(Node* a, Node* b) {
240 return NEW_NODE_2(MACHINE()->Int64Sub(), a, b);
241 }
242 Node* Int64Mul(Node* a, Node* b) {
243 return NEW_NODE_2(MACHINE()->Int64Mul(), a, b);
244 }
245 Node* Int64Div(Node* a, Node* b) {
246 return NEW_NODE_2(MACHINE()->Int64Div(), a, b);
247 }
248 Node* Int64UDiv(Node* a, Node* b) {
249 return NEW_NODE_2(MACHINE()->Int64UDiv(), a, b);
250 }
251 Node* Int64Mod(Node* a, Node* b) {
252 return NEW_NODE_2(MACHINE()->Int64Mod(), a, b);
253 }
254 Node* Int64UMod(Node* a, Node* b) {
255 return NEW_NODE_2(MACHINE()->Int64UMod(), a, b);
256 }
257 Node* Int64Neg(Node* a) { return Int64Sub(Int64Constant(0), a); }
258 Node* Int64LessThan(Node* a, Node* b) {
259 return NEW_NODE_2(MACHINE()->Int64LessThan(), a, b);
260 }
261 Node* Int64LessThanOrEqual(Node* a, Node* b) {
262 return NEW_NODE_2(MACHINE()->Int64LessThanOrEqual(), a, b);
263 }
264 Node* Int64GreaterThan(Node* a, Node* b) { return Int64LessThan(b, a); }
265 Node* Int64GreaterThanOrEqual(Node* a, Node* b) {
266 return Int64LessThanOrEqual(b, a);
267 }
268
269 Node* ConvertIntPtrToInt32(Node* a) {
270 return kPointerSize == 8 ?
271 NEW_NODE_1(MACHINE()->ConvertInt64ToInt32(), a) : a;
272 }
273 Node* ConvertInt32ToIntPtr(Node* a) {
274 return kPointerSize == 8 ?
275 NEW_NODE_1(MACHINE()->ConvertInt32ToInt64(), a) : a;
276 }
277
278 #define INTPTR_BINOP(prefix, name) \
279 Node* IntPtr##name(Node* a, Node* b) { \
280 return kPointerSize == 8 ? prefix##64##name(a, b) : \
281 prefix##32##name(a, b); \
282 }
283
284 INTPTR_BINOP(Int, Add);
285 INTPTR_BINOP(Int, Sub);
286 INTPTR_BINOP(Int, LessThan);
287 INTPTR_BINOP(Int, LessThanOrEqual);
288 INTPTR_BINOP(Word, Equal);
289 INTPTR_BINOP(Word, NotEqual);
290 INTPTR_BINOP(Int, GreaterThanOrEqual);
291 INTPTR_BINOP(Int, GreaterThan);
292
293 #undef INTPTR_BINOP
294
295 Node* Float64Add(Node* a, Node* b) {
296 return NEW_NODE_2(MACHINE()->Float64Add(), a, b);
297 }
298 Node* Float64Sub(Node* a, Node* b) {
299 return NEW_NODE_2(MACHINE()->Float64Sub(), a, b);
300 }
301 Node* Float64Mul(Node* a, Node* b) {
302 return NEW_NODE_2(MACHINE()->Float64Mul(), a, b);
303 }
304 Node* Float64Div(Node* a, Node* b) {
305 return NEW_NODE_2(MACHINE()->Float64Div(), a, b);
306 }
307 Node* Float64Mod(Node* a, Node* b) {
308 return NEW_NODE_2(MACHINE()->Float64Mod(), a, b);
309 }
310 Node* Float64Equal(Node* a, Node* b) {
311 return NEW_NODE_2(MACHINE()->Float64Equal(), a, b);
312 }
313 Node* Float64NotEqual(Node* a, Node* b) {
314 return WordBinaryNot(Float64Equal(a, b));
315 }
316 Node* Float64LessThan(Node* a, Node* b) {
317 return NEW_NODE_2(MACHINE()->Float64LessThan(), a, b);
318 }
319 Node* Float64LessThanOrEqual(Node* a, Node* b) {
320 return NEW_NODE_2(MACHINE()->Float64LessThanOrEqual(), a, b);
321 }
322 Node* Float64GreaterThan(Node* a, Node* b) {
323 return Float64LessThan(b, a);
324 }
325 Node* Float64GreaterThanOrEqual(Node* a, Node* b) {
326 return Float64LessThanOrEqual(b, a);
327 }
328
329 // Conversions.
330 Node* ConvertInt32ToInt64(Node* a) {
331 return NEW_NODE_1(MACHINE()->ConvertInt32ToInt64(), a);
332 }
333 Node* ConvertInt64ToInt32(Node* a) {
334 return NEW_NODE_1(MACHINE()->ConvertInt64ToInt32(), a);
335 }
336 Node* ConvertInt32ToFloat64(Node* a) {
337 return NEW_NODE_1(MACHINE()->ConvertInt32ToFloat64(), a);
338 }
339 Node* ConvertFloat64ToInt32(Node* a) {
340 return NEW_NODE_1(MACHINE()->ConvertFloat64ToInt32(), a);
341 }
342
343 #ifdef MACHINE_ASSEMBLER_SUPPORTS_CALL_C
344 // Call to C.
345 Node* CallC(Node* function_address, MachineRepresentation return_type,
346 MachineRepresentation* arg_types, Node** args, int n_args) {
347 CallDescriptor* descriptor = Linkage::GetSimplifiedCDescriptor(
348 ZONE(), n_args, return_type, arg_types);
349 Node** passed_args =
350 static_cast<Node**>(alloca((n_args + 1) * sizeof(args[0])));
351 passed_args[0] = function_address;
352 for (int i = 0; i < n_args; ++i) {
353 passed_args[i + 1] = args[i];
354 }
355 return NEW_NODE_2(COMMON()->Call(descriptor), n_args + 1, passed_args);
356 }
357 #endif
358 };
359
360 #undef NEW_NODE_0
361 #undef NEW_NODE_1
362 #undef NEW_NODE_2
363 #undef NEW_NODE_3
364 #undef MACHINE
365 #undef COMMON
366 #undef ZONE
367
368 } // namespace compiler
369 } // namespace internal
370 } // namespace v8
371
372 #endif // V8_COMPILER_MACHINE_NODE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698