Line data Source code
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_RAW_MACHINE_ASSEMBLER_H_
6 : #define V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_
7 :
8 : #include "src/assembler.h"
9 : #include "src/compiler/common-operator.h"
10 : #include "src/compiler/graph.h"
11 : #include "src/compiler/linkage.h"
12 : #include "src/compiler/machine-operator.h"
13 : #include "src/compiler/node.h"
14 : #include "src/compiler/operator.h"
15 : #include "src/factory.h"
16 : #include "src/globals.h"
17 :
18 : namespace v8 {
19 : namespace internal {
20 : namespace compiler {
21 :
22 : class BasicBlock;
23 : class RawMachineLabel;
24 : class Schedule;
25 :
26 :
27 : // The RawMachineAssembler produces a low-level IR graph. All nodes are wired
28 : // into a graph and also placed into a schedule immediately, hence subsequent
29 : // code generation can happen without the need for scheduling.
30 : //
31 : // In order to create a schedule on-the-fly, the assembler keeps track of basic
32 : // blocks by having one current basic block being populated and by referencing
33 : // other basic blocks through the use of labels.
34 : //
35 : // Also note that the generated graph is only valid together with the generated
36 : // schedule, using one without the other is invalid as the graph is inherently
37 : // non-schedulable due to missing control and effect dependencies.
38 : class V8_EXPORT_PRIVATE RawMachineAssembler {
39 : public:
40 : RawMachineAssembler(
41 : Isolate* isolate, Graph* graph, CallDescriptor* call_descriptor,
42 : MachineRepresentation word = MachineType::PointerRepresentation(),
43 : MachineOperatorBuilder::Flags flags =
44 : MachineOperatorBuilder::Flag::kNoFlags,
45 : MachineOperatorBuilder::AlignmentRequirements alignment_requirements =
46 : MachineOperatorBuilder::AlignmentRequirements::
47 : FullUnalignedAccessSupport());
48 : ~RawMachineAssembler() {}
49 :
50 : Isolate* isolate() const { return isolate_; }
51 : Graph* graph() const { return graph_; }
52 5044989 : Zone* zone() const { return graph()->zone(); }
53 : MachineOperatorBuilder* machine() { return &machine_; }
54 : CommonOperatorBuilder* common() { return &common_; }
55 : CallDescriptor* call_descriptor() const { return call_descriptor_; }
56 :
57 : // Finalizes the schedule and exports it to be used for code generation. Note
58 : // that this RawMachineAssembler becomes invalid after export.
59 : Schedule* Export();
60 :
61 : // ===========================================================================
62 : // The following utility methods create new nodes with specific operators and
63 : // place them into the current basic block. They don't perform control flow,
64 : // hence will not switch the current basic block.
65 :
66 : Node* NullConstant() {
67 : return HeapConstant(isolate()->factory()->null_value());
68 : }
69 :
70 : Node* UndefinedConstant() {
71 : return HeapConstant(isolate()->factory()->undefined_value());
72 : }
73 :
74 : // Constants.
75 : Node* PointerConstant(void* value) {
76 : return IntPtrConstant(reinterpret_cast<intptr_t>(value));
77 : }
78 : Node* IntPtrConstant(intptr_t value) {
79 : // TODO(dcarney): mark generated code as unserializable if value != 0.
80 : return kPointerSize == 8 ? Int64Constant(value)
81 4112590 : : Int32Constant(static_cast<int>(value));
82 : }
83 : Node* RelocatableIntPtrConstant(intptr_t value, RelocInfo::Mode rmode);
84 890771 : Node* Int32Constant(int32_t value) {
85 1781542 : return AddNode(common()->Int32Constant(value));
86 : }
87 : Node* StackSlot(MachineRepresentation rep) {
88 : return AddNode(machine()->StackSlot(rep));
89 : }
90 4127079 : Node* Int64Constant(int64_t value) {
91 8254159 : return AddNode(common()->Int64Constant(value));
92 : }
93 102568 : Node* NumberConstant(double value) {
94 205136 : return AddNode(common()->NumberConstant(value));
95 : }
96 : Node* Float32Constant(float value) {
97 : return AddNode(common()->Float32Constant(value));
98 : }
99 5848 : Node* Float64Constant(double value) {
100 11696 : return AddNode(common()->Float64Constant(value));
101 : }
102 771970 : Node* HeapConstant(Handle<HeapObject> object) {
103 1543940 : return AddNode(common()->HeapConstant(object));
104 : }
105 19616 : Node* BooleanConstant(bool value) {
106 19616 : Handle<Object> object = isolate()->factory()->ToBoolean(value);
107 9808 : return HeapConstant(Handle<HeapObject>::cast(object));
108 : }
109 298421 : Node* ExternalConstant(ExternalReference address) {
110 596842 : return AddNode(common()->ExternalConstant(address));
111 : }
112 : Node* RelocatableInt32Constant(int32_t value, RelocInfo::Mode rmode) {
113 : return AddNode(common()->RelocatableInt32Constant(value, rmode));
114 : }
115 378 : Node* RelocatableInt64Constant(int64_t value, RelocInfo::Mode rmode) {
116 756 : return AddNode(common()->RelocatableInt64Constant(value, rmode));
117 : }
118 :
119 5289 : Node* Projection(int index, Node* a) {
120 10578 : return AddNode(common()->Projection(index), a);
121 : }
122 :
123 : // Memory Operations.
124 206085 : Node* Load(MachineType rep, Node* base) {
125 206085 : return Load(rep, base, IntPtrConstant(0));
126 : }
127 1493357 : Node* Load(MachineType rep, Node* base, Node* index) {
128 2986713 : return AddNode(machine()->Load(rep), base, index);
129 : }
130 128829 : Node* Store(MachineRepresentation rep, Node* base, Node* value,
131 : WriteBarrierKind write_barrier) {
132 257658 : return Store(rep, base, IntPtrConstant(0), value, write_barrier);
133 : }
134 856058 : Node* Store(MachineRepresentation rep, Node* base, Node* index, Node* value,
135 : WriteBarrierKind write_barrier) {
136 : return AddNode(machine()->Store(StoreRepresentation(rep, write_barrier)),
137 1712117 : base, index, value);
138 : }
139 0 : Node* Retain(Node* value) { return AddNode(common()->Retain(), value); }
140 :
141 : // Unaligned memory operations
142 : Node* UnalignedLoad(MachineType rep, Node* base) {
143 : return UnalignedLoad(rep, base, IntPtrConstant(0));
144 : }
145 : Node* UnalignedLoad(MachineType rep, Node* base, Node* index) {
146 : if (machine()->UnalignedLoadSupported(rep, 1)) {
147 : return AddNode(machine()->Load(rep), base, index);
148 : } else {
149 : return AddNode(machine()->UnalignedLoad(rep), base, index);
150 : }
151 : }
152 : Node* UnalignedStore(MachineRepresentation rep, Node* base, Node* value) {
153 : return UnalignedStore(rep, base, IntPtrConstant(0), value);
154 : }
155 : Node* UnalignedStore(MachineRepresentation rep, Node* base, Node* index,
156 : Node* value) {
157 : MachineType t = MachineType::TypeForRepresentation(rep);
158 : if (machine()->UnalignedStoreSupported(t, 1)) {
159 : return AddNode(machine()->Store(StoreRepresentation(
160 : rep, WriteBarrierKind::kNoWriteBarrier)),
161 : base, index, value);
162 : } else {
163 : return AddNode(
164 : machine()->UnalignedStore(UnalignedStoreRepresentation(rep)), base,
165 : index, value);
166 : }
167 : }
168 :
169 : // Atomic memory operations.
170 258 : Node* AtomicLoad(MachineType rep, Node* base, Node* index) {
171 516 : return AddNode(machine()->AtomicLoad(rep), base, index);
172 : }
173 129 : Node* AtomicStore(MachineRepresentation rep, Node* base, Node* index,
174 : Node* value) {
175 258 : return AddNode(machine()->AtomicStore(rep), base, index, value);
176 : }
177 : #define ATOMIC_FUNCTION(name) \
178 : Node* Atomic##name(MachineType rep, Node* base, Node* index, Node* value) { \
179 : return AddNode(machine()->Atomic##name(rep), base, index, value); \
180 : }
181 516 : ATOMIC_FUNCTION(Exchange);
182 516 : ATOMIC_FUNCTION(Add);
183 516 : ATOMIC_FUNCTION(Sub);
184 516 : ATOMIC_FUNCTION(And);
185 516 : ATOMIC_FUNCTION(Or);
186 516 : ATOMIC_FUNCTION(Xor);
187 : #undef ATOMIC_FUNCTION
188 :
189 258 : Node* AtomicCompareExchange(MachineType rep, Node* base, Node* index,
190 : Node* old_value, Node* new_value) {
191 : return AddNode(machine()->AtomicCompareExchange(rep), base, index,
192 516 : old_value, new_value);
193 : }
194 :
195 : // Arithmetic Operations.
196 215966 : Node* WordAnd(Node* a, Node* b) {
197 431932 : return AddNode(machine()->WordAnd(), a, b);
198 : }
199 34986 : Node* WordOr(Node* a, Node* b) { return AddNode(machine()->WordOr(), a, b); }
200 0 : Node* WordXor(Node* a, Node* b) {
201 0 : return AddNode(machine()->WordXor(), a, b);
202 : }
203 396885 : Node* WordShl(Node* a, Node* b) {
204 793770 : return AddNode(machine()->WordShl(), a, b);
205 : }
206 98544 : Node* WordShr(Node* a, Node* b) {
207 197088 : return AddNode(machine()->WordShr(), a, b);
208 : }
209 76123 : Node* WordSar(Node* a, Node* b) {
210 152246 : return AddNode(machine()->WordSar(), a, b);
211 : }
212 0 : Node* WordRor(Node* a, Node* b) {
213 0 : return AddNode(machine()->WordRor(), a, b);
214 : }
215 590469 : Node* WordEqual(Node* a, Node* b) {
216 1180938 : return AddNode(machine()->WordEqual(), a, b);
217 : }
218 62720 : Node* WordNotEqual(Node* a, Node* b) {
219 62720 : return Word32BinaryNot(WordEqual(a, b));
220 : }
221 : Node* WordNot(Node* a) {
222 : if (machine()->Is32()) {
223 : return Word32Not(a);
224 : } else {
225 : return Word64Not(a);
226 : }
227 : }
228 :
229 65169 : Node* Word32And(Node* a, Node* b) {
230 130338 : return AddNode(machine()->Word32And(), a, b);
231 : }
232 1505 : Node* Word32Or(Node* a, Node* b) {
233 3010 : return AddNode(machine()->Word32Or(), a, b);
234 : }
235 5550 : Node* Word32Xor(Node* a, Node* b) {
236 11100 : return AddNode(machine()->Word32Xor(), a, b);
237 : }
238 1991 : Node* Word32Shl(Node* a, Node* b) {
239 3982 : return AddNode(machine()->Word32Shl(), a, b);
240 : }
241 18693 : Node* Word32Shr(Node* a, Node* b) {
242 37386 : return AddNode(machine()->Word32Shr(), a, b);
243 : }
244 301 : Node* Word32Sar(Node* a, Node* b) {
245 602 : return AddNode(machine()->Word32Sar(), a, b);
246 : }
247 0 : Node* Word32Ror(Node* a, Node* b) {
248 0 : return AddNode(machine()->Word32Ror(), a, b);
249 : }
250 86 : Node* Word32Clz(Node* a) { return AddNode(machine()->Word32Clz(), a); }
251 234289 : Node* Word32Equal(Node* a, Node* b) {
252 468578 : return AddNode(machine()->Word32Equal(), a, b);
253 : }
254 40930 : Node* Word32NotEqual(Node* a, Node* b) {
255 40930 : return Word32BinaryNot(Word32Equal(a, b));
256 : }
257 0 : Node* Word32Not(Node* a) { return Word32Xor(a, Int32Constant(-1)); }
258 103650 : Node* Word32BinaryNot(Node* a) { return Word32Equal(a, Int32Constant(0)); }
259 :
260 0 : Node* Word64And(Node* a, Node* b) {
261 0 : return AddNode(machine()->Word64And(), a, b);
262 : }
263 0 : Node* Word64Or(Node* a, Node* b) {
264 0 : return AddNode(machine()->Word64Or(), a, b);
265 : }
266 0 : Node* Word64Xor(Node* a, Node* b) {
267 0 : return AddNode(machine()->Word64Xor(), a, b);
268 : }
269 : Node* Word64Shl(Node* a, Node* b) {
270 : return AddNode(machine()->Word64Shl(), a, b);
271 : }
272 0 : Node* Word64Shr(Node* a, Node* b) {
273 0 : return AddNode(machine()->Word64Shr(), a, b);
274 : }
275 0 : Node* Word64Sar(Node* a, Node* b) {
276 0 : return AddNode(machine()->Word64Sar(), a, b);
277 : }
278 0 : Node* Word64Ror(Node* a, Node* b) {
279 0 : return AddNode(machine()->Word64Ror(), a, b);
280 : }
281 : Node* Word64Clz(Node* a) { return AddNode(machine()->Word64Clz(), a); }
282 5487 : Node* Word64Equal(Node* a, Node* b) {
283 10974 : return AddNode(machine()->Word64Equal(), a, b);
284 : }
285 0 : Node* Word64NotEqual(Node* a, Node* b) {
286 0 : return Word32BinaryNot(Word64Equal(a, b));
287 : }
288 : Node* Word64Not(Node* a) { return Word64Xor(a, Int64Constant(-1)); }
289 :
290 8439 : Node* Int32Add(Node* a, Node* b) {
291 16878 : return AddNode(machine()->Int32Add(), a, b);
292 : }
293 0 : Node* Int32AddWithOverflow(Node* a, Node* b) {
294 0 : return AddNode(machine()->Int32AddWithOverflow(), a, b);
295 : }
296 8470 : Node* Int32Sub(Node* a, Node* b) {
297 16940 : return AddNode(machine()->Int32Sub(), a, b);
298 : }
299 : Node* Int32SubWithOverflow(Node* a, Node* b) {
300 : return AddNode(machine()->Int32SubWithOverflow(), a, b);
301 : }
302 7285 : Node* Int32Mul(Node* a, Node* b) {
303 14570 : return AddNode(machine()->Int32Mul(), a, b);
304 : }
305 : Node* Int32MulHigh(Node* a, Node* b) {
306 : return AddNode(machine()->Int32MulHigh(), a, b);
307 : }
308 516 : Node* Int32MulWithOverflow(Node* a, Node* b) {
309 1032 : return AddNode(machine()->Int32MulWithOverflow(), a, b);
310 : }
311 344 : Node* Int32Div(Node* a, Node* b) {
312 688 : return AddNode(machine()->Int32Div(), a, b);
313 : }
314 860 : Node* Int32Mod(Node* a, Node* b) {
315 1720 : return AddNode(machine()->Int32Mod(), a, b);
316 : }
317 14613 : Node* Int32LessThan(Node* a, Node* b) {
318 29226 : return AddNode(machine()->Int32LessThan(), a, b);
319 : }
320 17514 : Node* Int32LessThanOrEqual(Node* a, Node* b) {
321 35028 : return AddNode(machine()->Int32LessThanOrEqual(), a, b);
322 : }
323 : Node* Uint32Div(Node* a, Node* b) {
324 : return AddNode(machine()->Uint32Div(), a, b);
325 : }
326 1763 : Node* Uint32LessThan(Node* a, Node* b) {
327 3526 : return AddNode(machine()->Uint32LessThan(), a, b);
328 : }
329 3147 : Node* Uint32LessThanOrEqual(Node* a, Node* b) {
330 6294 : return AddNode(machine()->Uint32LessThanOrEqual(), a, b);
331 : }
332 : Node* Uint32Mod(Node* a, Node* b) {
333 : return AddNode(machine()->Uint32Mod(), a, b);
334 : }
335 : Node* Uint32MulHigh(Node* a, Node* b) {
336 : return AddNode(machine()->Uint32MulHigh(), a, b);
337 : }
338 3325 : Node* Int32GreaterThan(Node* a, Node* b) { return Int32LessThan(b, a); }
339 : Node* Int32GreaterThanOrEqual(Node* a, Node* b) {
340 10169 : return Int32LessThanOrEqual(b, a);
341 : }
342 : Node* Uint32GreaterThan(Node* a, Node* b) { return Uint32LessThan(b, a); }
343 : Node* Uint32GreaterThanOrEqual(Node* a, Node* b) {
344 1175 : return Uint32LessThanOrEqual(b, a);
345 : }
346 : Node* Int32Neg(Node* a) { return Int32Sub(Int32Constant(0), a); }
347 :
348 852034 : Node* Int64Add(Node* a, Node* b) {
349 1704068 : return AddNode(machine()->Int64Add(), a, b);
350 : }
351 1161 : Node* Int64AddWithOverflow(Node* a, Node* b) {
352 2322 : return AddNode(machine()->Int64AddWithOverflow(), a, b);
353 : }
354 36728 : Node* Int64Sub(Node* a, Node* b) {
355 73456 : return AddNode(machine()->Int64Sub(), a, b);
356 : }
357 645 : Node* Int64SubWithOverflow(Node* a, Node* b) {
358 1290 : return AddNode(machine()->Int64SubWithOverflow(), a, b);
359 : }
360 38003 : Node* Int64Mul(Node* a, Node* b) {
361 76006 : return AddNode(machine()->Int64Mul(), a, b);
362 : }
363 : Node* Int64Div(Node* a, Node* b) {
364 : return AddNode(machine()->Int64Div(), a, b);
365 : }
366 : Node* Int64Mod(Node* a, Node* b) {
367 : return AddNode(machine()->Int64Mod(), a, b);
368 : }
369 : Node* Int64Neg(Node* a) { return Int64Sub(Int64Constant(0), a); }
370 8200 : Node* Int64LessThan(Node* a, Node* b) {
371 16400 : return AddNode(machine()->Int64LessThan(), a, b);
372 : }
373 8220 : Node* Int64LessThanOrEqual(Node* a, Node* b) {
374 16440 : return AddNode(machine()->Int64LessThanOrEqual(), a, b);
375 : }
376 16966 : Node* Uint64LessThan(Node* a, Node* b) {
377 33932 : return AddNode(machine()->Uint64LessThan(), a, b);
378 : }
379 109042 : Node* Uint64LessThanOrEqual(Node* a, Node* b) {
380 218084 : return AddNode(machine()->Uint64LessThanOrEqual(), a, b);
381 : }
382 1740 : Node* Int64GreaterThan(Node* a, Node* b) { return Int64LessThan(b, a); }
383 : Node* Int64GreaterThanOrEqual(Node* a, Node* b) {
384 2845 : return Int64LessThanOrEqual(b, a);
385 : }
386 3053 : Node* Uint64GreaterThan(Node* a, Node* b) { return Uint64LessThan(b, a); }
387 : Node* Uint64GreaterThanOrEqual(Node* a, Node* b) {
388 107408 : return Uint64LessThanOrEqual(b, a);
389 : }
390 : Node* Uint64Div(Node* a, Node* b) {
391 : return AddNode(machine()->Uint64Div(), a, b);
392 : }
393 : Node* Uint64Mod(Node* a, Node* b) {
394 : return AddNode(machine()->Uint64Mod(), a, b);
395 : }
396 : Node* Int32PairAdd(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
397 : return AddNode(machine()->Int32PairAdd(), a_low, a_high, b_low, b_high);
398 : }
399 : Node* Int32PairSub(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
400 : return AddNode(machine()->Int32PairSub(), a_low, a_high, b_low, b_high);
401 : }
402 : Node* Int32PairMul(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
403 : return AddNode(machine()->Int32PairMul(), a_low, a_high, b_low, b_high);
404 : }
405 : Node* Word32PairShl(Node* low_word, Node* high_word, Node* shift) {
406 : return AddNode(machine()->Word32PairShl(), low_word, high_word, shift);
407 : }
408 : Node* Word32PairShr(Node* low_word, Node* high_word, Node* shift) {
409 : return AddNode(machine()->Word32PairShr(), low_word, high_word, shift);
410 : }
411 : Node* Word32PairSar(Node* low_word, Node* high_word, Node* shift) {
412 : return AddNode(machine()->Word32PairSar(), low_word, high_word, shift);
413 : }
414 :
415 : #define INTPTR_BINOP(prefix, name) \
416 : Node* IntPtr##name(Node* a, Node* b) { \
417 : return kPointerSize == 8 ? prefix##64##name(a, b) \
418 : : prefix##32##name(a, b); \
419 : }
420 :
421 852034 : INTPTR_BINOP(Int, Add);
422 1161 : INTPTR_BINOP(Int, AddWithOverflow);
423 36728 : INTPTR_BINOP(Int, Sub);
424 645 : INTPTR_BINOP(Int, SubWithOverflow);
425 38003 : INTPTR_BINOP(Int, Mul);
426 : INTPTR_BINOP(Int, Div);
427 6460 : INTPTR_BINOP(Int, LessThan);
428 5375 : INTPTR_BINOP(Int, LessThanOrEqual);
429 3182 : INTPTR_BINOP(Word, Equal);
430 : INTPTR_BINOP(Word, NotEqual);
431 : INTPTR_BINOP(Int, GreaterThanOrEqual);
432 : INTPTR_BINOP(Int, GreaterThan);
433 :
434 : #undef INTPTR_BINOP
435 :
436 : #define UINTPTR_BINOP(prefix, name) \
437 : Node* UintPtr##name(Node* a, Node* b) { \
438 : return kPointerSize == 8 ? prefix##64##name(a, b) \
439 : : prefix##32##name(a, b); \
440 : }
441 :
442 13913 : UINTPTR_BINOP(Uint, LessThan);
443 1634 : UINTPTR_BINOP(Uint, LessThanOrEqual);
444 : UINTPTR_BINOP(Uint, GreaterThanOrEqual);
445 : UINTPTR_BINOP(Uint, GreaterThan);
446 :
447 : #undef UINTPTR_BINOP
448 :
449 0 : Node* Int32AbsWithOverflow(Node* a) {
450 0 : return AddNode(machine()->Int32AbsWithOverflow().op(), a);
451 : }
452 :
453 0 : Node* Int64AbsWithOverflow(Node* a) {
454 0 : return AddNode(machine()->Int64AbsWithOverflow().op(), a);
455 : }
456 :
457 : Node* IntPtrAbsWithOverflow(Node* a) {
458 : return kPointerSize == 8 ? Int64AbsWithOverflow(a)
459 0 : : Int32AbsWithOverflow(a);
460 : }
461 :
462 : Node* Float32Add(Node* a, Node* b) {
463 : return AddNode(machine()->Float32Add(), a, b);
464 : }
465 : Node* Float32Sub(Node* a, Node* b) {
466 : return AddNode(machine()->Float32Sub(), a, b);
467 : }
468 : Node* Float32Mul(Node* a, Node* b) {
469 : return AddNode(machine()->Float32Mul(), a, b);
470 : }
471 : Node* Float32Div(Node* a, Node* b) {
472 : return AddNode(machine()->Float32Div(), a, b);
473 : }
474 : Node* Float32Abs(Node* a) { return AddNode(machine()->Float32Abs(), a); }
475 : Node* Float32Neg(Node* a) { return AddNode(machine()->Float32Neg(), a); }
476 : Node* Float32Sqrt(Node* a) { return AddNode(machine()->Float32Sqrt(), a); }
477 0 : Node* Float32Equal(Node* a, Node* b) {
478 0 : return AddNode(machine()->Float32Equal(), a, b);
479 : }
480 : Node* Float32NotEqual(Node* a, Node* b) {
481 : return Word32BinaryNot(Float32Equal(a, b));
482 : }
483 0 : Node* Float32LessThan(Node* a, Node* b) {
484 0 : return AddNode(machine()->Float32LessThan(), a, b);
485 : }
486 0 : Node* Float32LessThanOrEqual(Node* a, Node* b) {
487 0 : return AddNode(machine()->Float32LessThanOrEqual(), a, b);
488 : }
489 0 : Node* Float32GreaterThan(Node* a, Node* b) { return Float32LessThan(b, a); }
490 : Node* Float32GreaterThanOrEqual(Node* a, Node* b) {
491 0 : return Float32LessThanOrEqual(b, a);
492 : }
493 : Node* Float32Max(Node* a, Node* b) {
494 : return AddNode(machine()->Float32Max(), a, b);
495 : }
496 : Node* Float32Min(Node* a, Node* b) {
497 : return AddNode(machine()->Float32Min(), a, b);
498 : }
499 1336 : Node* Float64Add(Node* a, Node* b) {
500 2672 : return AddNode(machine()->Float64Add(), a, b);
501 : }
502 754 : Node* Float64Sub(Node* a, Node* b) {
503 1508 : return AddNode(machine()->Float64Sub(), a, b);
504 : }
505 731 : Node* Float64Mul(Node* a, Node* b) {
506 1462 : return AddNode(machine()->Float64Mul(), a, b);
507 : }
508 215 : Node* Float64Div(Node* a, Node* b) {
509 430 : return AddNode(machine()->Float64Div(), a, b);
510 : }
511 401 : Node* Float64Mod(Node* a, Node* b) {
512 802 : return AddNode(machine()->Float64Mod(), a, b);
513 : }
514 43 : Node* Float64Max(Node* a, Node* b) {
515 86 : return AddNode(machine()->Float64Max(), a, b);
516 : }
517 43 : Node* Float64Min(Node* a, Node* b) {
518 86 : return AddNode(machine()->Float64Min(), a, b);
519 : }
520 4988 : Node* Float64Abs(Node* a) { return AddNode(machine()->Float64Abs(), a); }
521 156 : Node* Float64Neg(Node* a) { return AddNode(machine()->Float64Neg(), a); }
522 86 : Node* Float64Acos(Node* a) { return AddNode(machine()->Float64Acos(), a); }
523 86 : Node* Float64Acosh(Node* a) { return AddNode(machine()->Float64Acosh(), a); }
524 86 : Node* Float64Asin(Node* a) { return AddNode(machine()->Float64Asin(), a); }
525 86 : Node* Float64Asinh(Node* a) { return AddNode(machine()->Float64Asinh(), a); }
526 86 : Node* Float64Atan(Node* a) { return AddNode(machine()->Float64Atan(), a); }
527 86 : Node* Float64Atanh(Node* a) { return AddNode(machine()->Float64Atanh(), a); }
528 43 : Node* Float64Atan2(Node* a, Node* b) {
529 86 : return AddNode(machine()->Float64Atan2(), a, b);
530 : }
531 86 : Node* Float64Cbrt(Node* a) { return AddNode(machine()->Float64Cbrt(), a); }
532 86 : Node* Float64Cos(Node* a) { return AddNode(machine()->Float64Cos(), a); }
533 86 : Node* Float64Cosh(Node* a) { return AddNode(machine()->Float64Cosh(), a); }
534 86 : Node* Float64Exp(Node* a) { return AddNode(machine()->Float64Exp(), a); }
535 86 : Node* Float64Expm1(Node* a) { return AddNode(machine()->Float64Expm1(), a); }
536 86 : Node* Float64Log(Node* a) { return AddNode(machine()->Float64Log(), a); }
537 86 : Node* Float64Log1p(Node* a) { return AddNode(machine()->Float64Log1p(), a); }
538 86 : Node* Float64Log10(Node* a) { return AddNode(machine()->Float64Log10(), a); }
539 86 : Node* Float64Log2(Node* a) { return AddNode(machine()->Float64Log2(), a); }
540 43 : Node* Float64Pow(Node* a, Node* b) {
541 86 : return AddNode(machine()->Float64Pow(), a, b);
542 : }
543 86 : Node* Float64Sin(Node* a) { return AddNode(machine()->Float64Sin(), a); }
544 86 : Node* Float64Sinh(Node* a) { return AddNode(machine()->Float64Sinh(), a); }
545 86 : Node* Float64Sqrt(Node* a) { return AddNode(machine()->Float64Sqrt(), a); }
546 86 : Node* Float64Tan(Node* a) { return AddNode(machine()->Float64Tan(), a); }
547 86 : Node* Float64Tanh(Node* a) { return AddNode(machine()->Float64Tanh(), a); }
548 18651 : Node* Float64Equal(Node* a, Node* b) {
549 37302 : return AddNode(machine()->Float64Equal(), a, b);
550 : }
551 : Node* Float64NotEqual(Node* a, Node* b) {
552 : return Word32BinaryNot(Float64Equal(a, b));
553 : }
554 3854 : Node* Float64LessThan(Node* a, Node* b) {
555 7708 : return AddNode(machine()->Float64LessThan(), a, b);
556 : }
557 1055 : Node* Float64LessThanOrEqual(Node* a, Node* b) {
558 2110 : return AddNode(machine()->Float64LessThanOrEqual(), a, b);
559 : }
560 457 : Node* Float64GreaterThan(Node* a, Node* b) { return Float64LessThan(b, a); }
561 : Node* Float64GreaterThanOrEqual(Node* a, Node* b) {
562 383 : return Float64LessThanOrEqual(b, a);
563 : }
564 :
565 : // Conversions.
566 : Node* BitcastTaggedToWord(Node* a) {
567 : #ifdef ENABLE_VERIFY_CSA
568 : return AddNode(machine()->BitcastTaggedToWord(), a);
569 : #else
570 : return a;
571 : #endif
572 : }
573 101593 : Node* BitcastWordToTagged(Node* a) {
574 203186 : return AddNode(machine()->BitcastWordToTagged(), a);
575 : }
576 : Node* BitcastWordToTaggedSigned(Node* a) {
577 : #ifdef ENABLE_VERIFY_CSA
578 : return AddNode(machine()->BitcastWordToTaggedSigned(), a);
579 : #else
580 : return a;
581 : #endif
582 : }
583 6727 : Node* TruncateFloat64ToWord32(Node* a) {
584 13454 : return AddNode(machine()->TruncateFloat64ToWord32(), a);
585 : }
586 344 : Node* ChangeFloat32ToFloat64(Node* a) {
587 688 : return AddNode(machine()->ChangeFloat32ToFloat64(), a);
588 : }
589 25070 : Node* ChangeInt32ToFloat64(Node* a) {
590 50140 : return AddNode(machine()->ChangeInt32ToFloat64(), a);
591 : }
592 1039 : Node* ChangeUint32ToFloat64(Node* a) {
593 2078 : return AddNode(machine()->ChangeUint32ToFloat64(), a);
594 : }
595 : Node* ChangeFloat64ToInt32(Node* a) {
596 : return AddNode(machine()->ChangeFloat64ToInt32(), a);
597 : }
598 7 : Node* ChangeFloat64ToUint32(Node* a) {
599 14 : return AddNode(machine()->ChangeFloat64ToUint32(), a);
600 : }
601 129 : Node* ChangeFloat64ToUint64(Node* a) {
602 258 : return AddNode(machine()->ChangeFloat64ToUint64(), a);
603 : }
604 : Node* TruncateFloat64ToUint32(Node* a) {
605 : return AddNode(machine()->TruncateFloat64ToUint32(), a);
606 : }
607 : Node* TruncateFloat32ToInt32(Node* a) {
608 : return AddNode(machine()->TruncateFloat32ToInt32(), a);
609 : }
610 : Node* TruncateFloat32ToUint32(Node* a) {
611 : return AddNode(machine()->TruncateFloat32ToUint32(), a);
612 : }
613 : Node* TryTruncateFloat32ToInt64(Node* a) {
614 : return AddNode(machine()->TryTruncateFloat32ToInt64(), a);
615 : }
616 : Node* TryTruncateFloat64ToInt64(Node* a) {
617 : return AddNode(machine()->TryTruncateFloat64ToInt64(), a);
618 : }
619 : Node* TryTruncateFloat32ToUint64(Node* a) {
620 : return AddNode(machine()->TryTruncateFloat32ToUint64(), a);
621 : }
622 : Node* TryTruncateFloat64ToUint64(Node* a) {
623 : return AddNode(machine()->TryTruncateFloat64ToUint64(), a);
624 : }
625 78852 : Node* ChangeInt32ToInt64(Node* a) {
626 157704 : return AddNode(machine()->ChangeInt32ToInt64(), a);
627 : }
628 59250 : Node* ChangeUint32ToUint64(Node* a) {
629 118500 : return AddNode(machine()->ChangeUint32ToUint64(), a);
630 : }
631 197 : Node* TruncateFloat64ToFloat32(Node* a) {
632 394 : return AddNode(machine()->TruncateFloat64ToFloat32(), a);
633 : }
634 73280 : Node* TruncateInt64ToInt32(Node* a) {
635 146560 : return AddNode(machine()->TruncateInt64ToInt32(), a);
636 : }
637 9271 : Node* RoundFloat64ToInt32(Node* a) {
638 18542 : return AddNode(machine()->RoundFloat64ToInt32(), a);
639 : }
640 154 : Node* RoundInt32ToFloat32(Node* a) {
641 308 : return AddNode(machine()->RoundInt32ToFloat32(), a);
642 : }
643 : Node* RoundInt64ToFloat32(Node* a) {
644 : return AddNode(machine()->RoundInt64ToFloat32(), a);
645 : }
646 709 : Node* RoundInt64ToFloat64(Node* a) {
647 1418 : return AddNode(machine()->RoundInt64ToFloat64(), a);
648 : }
649 : Node* RoundUint32ToFloat32(Node* a) {
650 : return AddNode(machine()->RoundUint32ToFloat32(), a);
651 : }
652 : Node* RoundUint64ToFloat32(Node* a) {
653 : return AddNode(machine()->RoundUint64ToFloat32(), a);
654 : }
655 : Node* RoundUint64ToFloat64(Node* a) {
656 : return AddNode(machine()->RoundUint64ToFloat64(), a);
657 : }
658 : Node* BitcastFloat32ToInt32(Node* a) {
659 : return AddNode(machine()->BitcastFloat32ToInt32(), a);
660 : }
661 : Node* BitcastFloat64ToInt64(Node* a) {
662 : return AddNode(machine()->BitcastFloat64ToInt64(), a);
663 : }
664 : Node* BitcastInt32ToFloat32(Node* a) {
665 : return AddNode(machine()->BitcastInt32ToFloat32(), a);
666 : }
667 : Node* BitcastInt64ToFloat64(Node* a) {
668 : return AddNode(machine()->BitcastInt64ToFloat64(), a);
669 : }
670 : Node* Float32RoundDown(Node* a) {
671 : return AddNode(machine()->Float32RoundDown().op(), a);
672 : }
673 84 : Node* Float64RoundDown(Node* a) {
674 168 : return AddNode(machine()->Float64RoundDown().op(), a);
675 : }
676 : Node* Float32RoundUp(Node* a) {
677 : return AddNode(machine()->Float32RoundUp().op(), a);
678 : }
679 84 : Node* Float64RoundUp(Node* a) {
680 168 : return AddNode(machine()->Float64RoundUp().op(), a);
681 : }
682 : Node* Float32RoundTruncate(Node* a) {
683 : return AddNode(machine()->Float32RoundTruncate().op(), a);
684 : }
685 1477 : Node* Float64RoundTruncate(Node* a) {
686 2954 : return AddNode(machine()->Float64RoundTruncate().op(), a);
687 : }
688 : Node* Float64RoundTiesAway(Node* a) {
689 : return AddNode(machine()->Float64RoundTiesAway().op(), a);
690 : }
691 : Node* Float32RoundTiesEven(Node* a) {
692 : return AddNode(machine()->Float32RoundTiesEven().op(), a);
693 : }
694 123 : Node* Float64RoundTiesEven(Node* a) {
695 246 : return AddNode(machine()->Float64RoundTiesEven().op(), a);
696 : }
697 : Node* Word32ReverseBytes(Node* a) {
698 : return AddNode(machine()->Word32ReverseBytes().op(), a);
699 : }
700 : Node* Word64ReverseBytes(Node* a) {
701 : return AddNode(machine()->Word64ReverseBytes().op(), a);
702 : }
703 :
704 : // Float64 bit operations.
705 0 : Node* Float64ExtractLowWord32(Node* a) {
706 0 : return AddNode(machine()->Float64ExtractLowWord32(), a);
707 : }
708 2630 : Node* Float64ExtractHighWord32(Node* a) {
709 5260 : return AddNode(machine()->Float64ExtractHighWord32(), a);
710 : }
711 0 : Node* Float64InsertLowWord32(Node* a, Node* b) {
712 0 : return AddNode(machine()->Float64InsertLowWord32(), a, b);
713 : }
714 0 : Node* Float64InsertHighWord32(Node* a, Node* b) {
715 0 : return AddNode(machine()->Float64InsertHighWord32(), a, b);
716 : }
717 1283 : Node* Float64SilenceNaN(Node* a) {
718 2566 : return AddNode(machine()->Float64SilenceNaN(), a);
719 : }
720 :
721 : // Stack operations.
722 86 : Node* LoadStackPointer() { return AddNode(machine()->LoadStackPointer()); }
723 1702 : Node* LoadFramePointer() { return AddNode(machine()->LoadFramePointer()); }
724 54233 : Node* LoadParentFramePointer() {
725 108466 : return AddNode(machine()->LoadParentFramePointer());
726 : }
727 :
728 : // Parameters.
729 : Node* Parameter(size_t index);
730 :
731 : // Pointer utilities.
732 : Node* LoadFromPointer(void* address, MachineType rep, int32_t offset = 0) {
733 : return Load(rep, PointerConstant(address), Int32Constant(offset));
734 : }
735 : Node* StoreToPointer(void* address, MachineRepresentation rep, Node* node) {
736 : return Store(rep, PointerConstant(address), node, kNoWriteBarrier);
737 : }
738 : Node* UnalignedLoadFromPointer(void* address, MachineType rep,
739 : int32_t offset = 0) {
740 : return UnalignedLoad(rep, PointerConstant(address), Int32Constant(offset));
741 : }
742 : Node* UnalignedStoreToPointer(void* address, MachineRepresentation rep,
743 : Node* node) {
744 : return UnalignedStore(rep, PointerConstant(address), node);
745 : }
746 : Node* StringConstant(const char* string) {
747 : return HeapConstant(isolate()->factory()->InternalizeUtf8String(string));
748 : }
749 :
750 : // Call a given call descriptor and the given arguments.
751 : // The call target is passed as part of the {inputs} array.
752 : Node* CallN(CallDescriptor* desc, int input_count, Node* const* inputs);
753 :
754 : // Call a given call descriptor and the given arguments and frame-state.
755 : // The call target and frame state are passed as part of the {inputs} array.
756 : Node* CallNWithFrameState(CallDescriptor* desc, int input_count,
757 : Node* const* inputs);
758 :
759 : // Tail call a given call descriptor and the given arguments.
760 : // The call target is passed as part of the {inputs} array.
761 : Node* TailCallN(CallDescriptor* desc, int input_count, Node* const* inputs);
762 :
763 : // Call to a C function with zero arguments.
764 : Node* CallCFunction0(MachineType return_type, Node* function);
765 : // Call to a C function with one parameter.
766 : Node* CallCFunction1(MachineType return_type, MachineType arg0_type,
767 : Node* function, Node* arg0);
768 : // Call to a C function with two arguments.
769 : Node* CallCFunction2(MachineType return_type, MachineType arg0_type,
770 : MachineType arg1_type, Node* function, Node* arg0,
771 : Node* arg1);
772 : // Call to a C function with three arguments.
773 : Node* CallCFunction3(MachineType return_type, MachineType arg0_type,
774 : MachineType arg1_type, MachineType arg2_type,
775 : Node* function, Node* arg0, Node* arg1, Node* arg2);
776 : // Call to a C function with six arguments.
777 : Node* CallCFunction6(MachineType return_type, MachineType arg0_type,
778 : MachineType arg1_type, MachineType arg2_type,
779 : MachineType arg3_type, MachineType arg4_type,
780 : MachineType arg5_type, Node* function, Node* arg0,
781 : Node* arg1, Node* arg2, Node* arg3, Node* arg4,
782 : Node* arg5);
783 : // Call to a C function with eight arguments.
784 : Node* CallCFunction8(MachineType return_type, MachineType arg0_type,
785 : MachineType arg1_type, MachineType arg2_type,
786 : MachineType arg3_type, MachineType arg4_type,
787 : MachineType arg5_type, MachineType arg6_type,
788 : MachineType arg7_type, Node* function, Node* arg0,
789 : Node* arg1, Node* arg2, Node* arg3, Node* arg4,
790 : Node* arg5, Node* arg6, Node* arg7);
791 : // Call to a C function with nine arguments.
792 : Node* CallCFunction9(MachineType return_type, MachineType arg0_type,
793 : MachineType arg1_type, MachineType arg2_type,
794 : MachineType arg3_type, MachineType arg4_type,
795 : MachineType arg5_type, MachineType arg6_type,
796 : MachineType arg7_type, MachineType arg8_type,
797 : Node* function, Node* arg0, Node* arg1, Node* arg2,
798 : Node* arg3, Node* arg4, Node* arg5, Node* arg6,
799 : Node* arg7, Node* arg8);
800 :
801 : // ===========================================================================
802 : // The following utility methods deal with control flow, hence might switch
803 : // the current basic block or create new basic blocks for labels.
804 :
805 : // Control flow.
806 : void Goto(RawMachineLabel* label);
807 : void Branch(Node* condition, RawMachineLabel* true_val,
808 : RawMachineLabel* false_val);
809 : void Switch(Node* index, RawMachineLabel* default_label,
810 : const int32_t* case_values, RawMachineLabel** case_labels,
811 : size_t case_count);
812 : void Return(Node* value);
813 : void Return(Node* v1, Node* v2);
814 : void Return(Node* v1, Node* v2, Node* v3);
815 : void PopAndReturn(Node* pop, Node* value);
816 : void PopAndReturn(Node* pop, Node* v1, Node* v2);
817 : void PopAndReturn(Node* pop, Node* v1, Node* v2, Node* v3);
818 : void Bind(RawMachineLabel* label);
819 : void Deoptimize(Node* state);
820 : void DebugBreak();
821 : void Unreachable();
822 : void Comment(const char* msg);
823 :
824 : #if DEBUG
825 : void Bind(RawMachineLabel* label, AssemblerDebugInfo info);
826 : void SetInitialDebugInformation(AssemblerDebugInfo info);
827 : void PrintCurrentBlock(std::ostream& os);
828 : #endif // DEBUG
829 :
830 : // Add success / exception successor blocks and ends the current block ending
831 : // in a potentially throwing call node.
832 : void Continuations(Node* call, RawMachineLabel* if_success,
833 : RawMachineLabel* if_exception);
834 :
835 : // Variables.
836 : Node* Phi(MachineRepresentation rep, Node* n1, Node* n2) {
837 : return AddNode(common()->Phi(rep, 2), n1, n2, graph()->start());
838 : }
839 : Node* Phi(MachineRepresentation rep, Node* n1, Node* n2, Node* n3) {
840 : return AddNode(common()->Phi(rep, 3), n1, n2, n3, graph()->start());
841 : }
842 : Node* Phi(MachineRepresentation rep, Node* n1, Node* n2, Node* n3, Node* n4) {
843 : return AddNode(common()->Phi(rep, 4), n1, n2, n3, n4, graph()->start());
844 : }
845 : Node* Phi(MachineRepresentation rep, int input_count, Node* const* inputs);
846 : void AppendPhiInput(Node* phi, Node* new_input);
847 :
848 : // ===========================================================================
849 : // The following generic node creation methods can be used for operators that
850 : // are not covered by the above utility methods. There should rarely be a need
851 : // to do that outside of testing though.
852 :
853 : Node* AddNode(const Operator* op, int input_count, Node* const* inputs);
854 :
855 : Node* AddNode(const Operator* op) {
856 6261250 : return AddNode(op, 0, static_cast<Node* const*>(nullptr));
857 : }
858 :
859 : template <class... TArgs>
860 : Node* AddNode(const Operator* op, Node* n1, TArgs... args) {
861 6460900 : Node* buffer[] = {n1, args...};
862 6460900 : return AddNode(op, sizeof...(args) + 1, buffer);
863 : }
864 :
865 : private:
866 : Node* MakeNode(const Operator* op, int input_count, Node* const* inputs);
867 : BasicBlock* Use(RawMachineLabel* label);
868 : BasicBlock* EnsureBlock(RawMachineLabel* label);
869 : BasicBlock* CurrentBlock();
870 :
871 : Schedule* schedule() { return schedule_; }
872 1897142 : size_t parameter_count() const { return call_descriptor_->ParameterCount(); }
873 :
874 : Isolate* isolate_;
875 : Graph* graph_;
876 : Schedule* schedule_;
877 : MachineOperatorBuilder machine_;
878 : CommonOperatorBuilder common_;
879 : CallDescriptor* call_descriptor_;
880 : NodeVector parameters_;
881 : BasicBlock* current_block_;
882 :
883 : DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler);
884 : };
885 :
886 : class V8_EXPORT_PRIVATE RawMachineLabel final {
887 : public:
888 : enum Type { kDeferred, kNonDeferred };
889 :
890 : explicit RawMachineLabel(Type type = kNonDeferred)
891 1725747 : : deferred_(type == kDeferred) {}
892 : ~RawMachineLabel();
893 :
894 : BasicBlock* block() const { return block_; }
895 :
896 : private:
897 : BasicBlock* block_ = nullptr;
898 : bool used_ = false;
899 : bool bound_ = false;
900 : bool deferred_;
901 : friend class RawMachineAssembler;
902 : DISALLOW_COPY_AND_ASSIGN(RawMachineLabel);
903 : };
904 :
905 : } // namespace compiler
906 : } // namespace internal
907 : } // namespace v8
908 :
909 : #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_
|