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 3435576 : 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 : Node* UndefinedConstant();
68 :
69 : // Constants.
70 : Node* PointerConstant(void* value) {
71 173173 : return IntPtrConstant(reinterpret_cast<intptr_t>(value));
72 : }
73 : Node* IntPtrConstant(intptr_t value) {
74 : // TODO(dcarney): mark generated code as unserializable if value != 0.
75 : return kPointerSize == 8 ? Int64Constant(value)
76 2475334 : : Int32Constant(static_cast<int>(value));
77 : }
78 : Node* RelocatableIntPtrConstant(intptr_t value, RelocInfo::Mode rmode);
79 1317544 : Node* Int32Constant(int32_t value) {
80 2635088 : return AddNode(common()->Int32Constant(value));
81 : }
82 24 : Node* StackSlot(MachineRepresentation rep, int alignment = 0) {
83 48 : return AddNode(machine()->StackSlot(rep, alignment));
84 : }
85 2630434 : Node* Int64Constant(int64_t value) {
86 5260868 : return AddNode(common()->Int64Constant(value));
87 : }
88 428 : Node* NumberConstant(double value) {
89 856 : return AddNode(common()->NumberConstant(value));
90 : }
91 6333 : Node* Float32Constant(float value) {
92 12666 : return AddNode(common()->Float32Constant(value));
93 : }
94 15371 : Node* Float64Constant(double value) {
95 30742 : return AddNode(common()->Float64Constant(value));
96 : }
97 375943 : Node* HeapConstant(Handle<HeapObject> object) {
98 751886 : return AddNode(common()->HeapConstant(object));
99 : }
100 18356 : Node* BooleanConstant(bool value) {
101 18356 : Handle<Object> object = isolate()->factory()->ToBoolean(value);
102 9178 : return HeapConstant(Handle<HeapObject>::cast(object));
103 : }
104 133558 : Node* ExternalConstant(ExternalReference address) {
105 267116 : return AddNode(common()->ExternalConstant(address));
106 : }
107 11 : Node* RelocatableInt32Constant(int32_t value, RelocInfo::Mode rmode) {
108 22 : return AddNode(common()->RelocatableInt32Constant(value, rmode));
109 : }
110 276 : Node* RelocatableInt64Constant(int64_t value, RelocInfo::Mode rmode) {
111 552 : return AddNode(common()->RelocatableInt64Constant(value, rmode));
112 : }
113 :
114 242496 : Node* Projection(int index, Node* a) {
115 484992 : return AddNode(common()->Projection(index), a);
116 : }
117 :
118 : // Memory Operations.
119 86864 : Node* Load(MachineType rep, Node* base) {
120 86864 : return Load(rep, base, IntPtrConstant(0));
121 : }
122 989447 : Node* Load(MachineType rep, Node* base, Node* index) {
123 1978894 : return AddNode(machine()->Load(rep), base, index);
124 : }
125 175060 : Node* Store(MachineRepresentation rep, Node* base, Node* value,
126 : WriteBarrierKind write_barrier) {
127 350120 : return Store(rep, base, IntPtrConstant(0), value, write_barrier);
128 : }
129 477697 : Node* Store(MachineRepresentation rep, Node* base, Node* index, Node* value,
130 : WriteBarrierKind write_barrier) {
131 : return AddNode(machine()->Store(StoreRepresentation(rep, write_barrier)),
132 955394 : base, index, value);
133 : }
134 0 : Node* Retain(Node* value) { return AddNode(common()->Retain(), value); }
135 :
136 : // Unaligned memory operations
137 : Node* UnalignedLoad(MachineType type, Node* base) {
138 : return UnalignedLoad(type, base, IntPtrConstant(0));
139 : }
140 2538 : Node* UnalignedLoad(MachineType type, Node* base, Node* index) {
141 5076 : if (machine()->UnalignedLoadSupported(type.representation())) {
142 5076 : return AddNode(machine()->Load(type), base, index);
143 : } else {
144 0 : return AddNode(machine()->UnalignedLoad(type), base, index);
145 : }
146 : }
147 48 : Node* UnalignedStore(MachineRepresentation rep, Node* base, Node* value) {
148 48 : return UnalignedStore(rep, base, IntPtrConstant(0), value);
149 : }
150 1176 : Node* UnalignedStore(MachineRepresentation rep, Node* base, Node* index,
151 : Node* value) {
152 1176 : if (machine()->UnalignedStoreSupported(rep)) {
153 : return AddNode(machine()->Store(StoreRepresentation(
154 : rep, WriteBarrierKind::kNoWriteBarrier)),
155 2352 : base, index, value);
156 : } else {
157 : return AddNode(
158 : machine()->UnalignedStore(UnalignedStoreRepresentation(rep)), base,
159 0 : index, value);
160 : }
161 : }
162 :
163 : // Atomic memory operations.
164 186 : Node* AtomicLoad(MachineType type, Node* base, Node* index) {
165 372 : return AddNode(machine()->AtomicLoad(type), base, index);
166 : }
167 93 : Node* AtomicStore(MachineRepresentation rep, Node* base, Node* index,
168 : Node* value) {
169 186 : return AddNode(machine()->AtomicStore(rep), base, index, value);
170 : }
171 : #define ATOMIC_FUNCTION(name) \
172 : Node* Atomic##name(MachineType rep, Node* base, Node* index, Node* value) { \
173 : return AddNode(machine()->Atomic##name(rep), base, index, value); \
174 : }
175 372 : ATOMIC_FUNCTION(Exchange);
176 372 : ATOMIC_FUNCTION(Add);
177 372 : ATOMIC_FUNCTION(Sub);
178 372 : ATOMIC_FUNCTION(And);
179 372 : ATOMIC_FUNCTION(Or);
180 372 : ATOMIC_FUNCTION(Xor);
181 : #undef ATOMIC_FUNCTION
182 :
183 186 : Node* AtomicCompareExchange(MachineType rep, Node* base, Node* index,
184 : Node* old_value, Node* new_value) {
185 : return AddNode(machine()->AtomicCompareExchange(rep), base, index,
186 372 : old_value, new_value);
187 : }
188 :
189 : // Arithmetic Operations.
190 133660 : Node* WordAnd(Node* a, Node* b) {
191 267320 : return AddNode(machine()->WordAnd(), a, b);
192 : }
193 38192 : Node* WordOr(Node* a, Node* b) { return AddNode(machine()->WordOr(), a, b); }
194 6 : Node* WordXor(Node* a, Node* b) {
195 12 : return AddNode(machine()->WordXor(), a, b);
196 : }
197 181872 : Node* WordShl(Node* a, Node* b) {
198 363744 : return AddNode(machine()->WordShl(), a, b);
199 : }
200 25853 : Node* WordShr(Node* a, Node* b) {
201 51706 : return AddNode(machine()->WordShr(), a, b);
202 : }
203 62914 : Node* WordSar(Node* a, Node* b) {
204 125828 : return AddNode(machine()->WordSar(), a, b);
205 : }
206 0 : Node* WordRor(Node* a, Node* b) {
207 0 : return AddNode(machine()->WordRor(), a, b);
208 : }
209 326486 : Node* WordEqual(Node* a, Node* b) {
210 652972 : return AddNode(machine()->WordEqual(), a, b);
211 : }
212 51639 : Node* WordNotEqual(Node* a, Node* b) {
213 51639 : return Word32BinaryNot(WordEqual(a, b));
214 : }
215 : Node* WordNot(Node* a) {
216 : if (machine()->Is32()) {
217 : return Word32Not(a);
218 : } else {
219 : return Word64Not(a);
220 : }
221 : }
222 :
223 62163 : Node* Word32And(Node* a, Node* b) {
224 124326 : return AddNode(machine()->Word32And(), a, b);
225 : }
226 4304 : Node* Word32Or(Node* a, Node* b) {
227 8608 : return AddNode(machine()->Word32Or(), a, b);
228 : }
229 6406 : Node* Word32Xor(Node* a, Node* b) {
230 12812 : return AddNode(machine()->Word32Xor(), a, b);
231 : }
232 3053 : Node* Word32Shl(Node* a, Node* b) {
233 6106 : return AddNode(machine()->Word32Shl(), a, b);
234 : }
235 15451 : Node* Word32Shr(Node* a, Node* b) {
236 30902 : return AddNode(machine()->Word32Shr(), a, b);
237 : }
238 759 : Node* Word32Sar(Node* a, Node* b) {
239 1518 : return AddNode(machine()->Word32Sar(), a, b);
240 : }
241 497 : Node* Word32Ror(Node* a, Node* b) {
242 994 : return AddNode(machine()->Word32Ror(), a, b);
243 : }
244 74 : Node* Word32Clz(Node* a) { return AddNode(machine()->Word32Clz(), a); }
245 220706 : Node* Word32Equal(Node* a, Node* b) {
246 441412 : return AddNode(machine()->Word32Equal(), a, b);
247 : }
248 36198 : Node* Word32NotEqual(Node* a, Node* b) {
249 36198 : return Word32BinaryNot(Word32Equal(a, b));
250 : }
251 998 : Node* Word32Not(Node* a) { return Word32Xor(a, Int32Constant(-1)); }
252 88320 : Node* Word32BinaryNot(Node* a) { return Word32Equal(a, Int32Constant(0)); }
253 :
254 16 : Node* Word64And(Node* a, Node* b) {
255 32 : return AddNode(machine()->Word64And(), a, b);
256 : }
257 1 : Node* Word64Or(Node* a, Node* b) {
258 2 : return AddNode(machine()->Word64Or(), a, b);
259 : }
260 1 : Node* Word64Xor(Node* a, Node* b) {
261 2 : return AddNode(machine()->Word64Xor(), a, b);
262 : }
263 104 : Node* Word64Shl(Node* a, Node* b) {
264 208 : return AddNode(machine()->Word64Shl(), a, b);
265 : }
266 27 : Node* Word64Shr(Node* a, Node* b) {
267 54 : return AddNode(machine()->Word64Shr(), a, b);
268 : }
269 3 : Node* Word64Sar(Node* a, Node* b) {
270 6 : return AddNode(machine()->Word64Sar(), a, b);
271 : }
272 0 : Node* Word64Ror(Node* a, Node* b) {
273 0 : return AddNode(machine()->Word64Ror(), a, b);
274 : }
275 10 : Node* Word64Clz(Node* a) { return AddNode(machine()->Word64Clz(), a); }
276 4972 : Node* Word64Equal(Node* a, Node* b) {
277 9944 : return AddNode(machine()->Word64Equal(), a, b);
278 : }
279 30 : Node* Word64NotEqual(Node* a, Node* b) {
280 30 : return Word32BinaryNot(Word64Equal(a, b));
281 : }
282 : Node* Word64Not(Node* a) { return Word64Xor(a, Int64Constant(-1)); }
283 :
284 41695 : Node* Int32Add(Node* a, Node* b) {
285 83390 : return AddNode(machine()->Int32Add(), a, b);
286 : }
287 17410 : Node* Int32AddWithOverflow(Node* a, Node* b) {
288 34820 : return AddNode(machine()->Int32AddWithOverflow(), a, b);
289 : }
290 8114 : Node* Int32Sub(Node* a, Node* b) {
291 16228 : return AddNode(machine()->Int32Sub(), a, b);
292 : }
293 17410 : Node* Int32SubWithOverflow(Node* a, Node* b) {
294 34820 : return AddNode(machine()->Int32SubWithOverflow(), a, b);
295 : }
296 29382 : Node* Int32Mul(Node* a, Node* b) {
297 58764 : return AddNode(machine()->Int32Mul(), a, b);
298 : }
299 8 : Node* Int32MulHigh(Node* a, Node* b) {
300 16 : return AddNode(machine()->Int32MulHigh(), a, b);
301 : }
302 17751 : Node* Int32MulWithOverflow(Node* a, Node* b) {
303 35502 : return AddNode(machine()->Int32MulWithOverflow(), a, b);
304 : }
305 761 : Node* Int32Div(Node* a, Node* b) {
306 1522 : return AddNode(machine()->Int32Div(), a, b);
307 : }
308 1097 : Node* Int32Mod(Node* a, Node* b) {
309 2194 : return AddNode(machine()->Int32Mod(), a, b);
310 : }
311 16594 : Node* Int32LessThan(Node* a, Node* b) {
312 33188 : return AddNode(machine()->Int32LessThan(), a, b);
313 : }
314 12642 : Node* Int32LessThanOrEqual(Node* a, Node* b) {
315 25284 : return AddNode(machine()->Int32LessThanOrEqual(), a, b);
316 : }
317 12 : Node* Uint32Div(Node* a, Node* b) {
318 24 : return AddNode(machine()->Uint32Div(), a, b);
319 : }
320 2039 : Node* Uint32LessThan(Node* a, Node* b) {
321 4078 : return AddNode(machine()->Uint32LessThan(), a, b);
322 : }
323 2677 : Node* Uint32LessThanOrEqual(Node* a, Node* b) {
324 5354 : return AddNode(machine()->Uint32LessThanOrEqual(), a, b);
325 : }
326 12 : Node* Uint32Mod(Node* a, Node* b) {
327 24 : return AddNode(machine()->Uint32Mod(), a, b);
328 : }
329 6 : Node* Uint32MulHigh(Node* a, Node* b) {
330 12 : return AddNode(machine()->Uint32MulHigh(), a, b);
331 : }
332 2696 : Node* Int32GreaterThan(Node* a, Node* b) { return Int32LessThan(b, a); }
333 : Node* Int32GreaterThanOrEqual(Node* a, Node* b) {
334 7160 : return Int32LessThanOrEqual(b, a);
335 : }
336 12 : Node* Uint32GreaterThan(Node* a, Node* b) { return Uint32LessThan(b, a); }
337 : Node* Uint32GreaterThanOrEqual(Node* a, Node* b) {
338 830 : return Uint32LessThanOrEqual(b, a);
339 : }
340 5 : Node* Int32Neg(Node* a) { return Int32Sub(Int32Constant(0), a); }
341 :
342 391031 : Node* Int64Add(Node* a, Node* b) {
343 782062 : return AddNode(machine()->Int64Add(), a, b);
344 : }
345 34499 : Node* Int64AddWithOverflow(Node* a, Node* b) {
346 68998 : return AddNode(machine()->Int64AddWithOverflow(), a, b);
347 : }
348 50274 : Node* Int64Sub(Node* a, Node* b) {
349 100548 : return AddNode(machine()->Int64Sub(), a, b);
350 : }
351 34065 : Node* Int64SubWithOverflow(Node* a, Node* b) {
352 68130 : return AddNode(machine()->Int64SubWithOverflow(), a, b);
353 : }
354 22434 : Node* Int64Mul(Node* a, Node* b) {
355 44868 : return AddNode(machine()->Int64Mul(), a, b);
356 : }
357 : Node* Int64Div(Node* a, Node* b) {
358 : return AddNode(machine()->Int64Div(), a, b);
359 : }
360 : Node* Int64Mod(Node* a, Node* b) {
361 : return AddNode(machine()->Int64Mod(), a, b);
362 : }
363 : Node* Int64Neg(Node* a) { return Int64Sub(Int64Constant(0), a); }
364 8120 : Node* Int64LessThan(Node* a, Node* b) {
365 16240 : return AddNode(machine()->Int64LessThan(), a, b);
366 : }
367 6866 : Node* Int64LessThanOrEqual(Node* a, Node* b) {
368 13732 : return AddNode(machine()->Int64LessThanOrEqual(), a, b);
369 : }
370 12853 : Node* Uint64LessThan(Node* a, Node* b) {
371 25706 : return AddNode(machine()->Uint64LessThan(), a, b);
372 : }
373 43381 : Node* Uint64LessThanOrEqual(Node* a, Node* b) {
374 86762 : return AddNode(machine()->Uint64LessThanOrEqual(), a, b);
375 : }
376 2631 : Node* Int64GreaterThan(Node* a, Node* b) { return Int64LessThan(b, a); }
377 : Node* Int64GreaterThanOrEqual(Node* a, Node* b) {
378 2020 : return Int64LessThanOrEqual(b, a);
379 : }
380 2666 : Node* Uint64GreaterThan(Node* a, Node* b) { return Uint64LessThan(b, a); }
381 : Node* Uint64GreaterThanOrEqual(Node* a, Node* b) {
382 42150 : return Uint64LessThanOrEqual(b, a);
383 : }
384 : Node* Uint64Div(Node* a, Node* b) {
385 : return AddNode(machine()->Uint64Div(), a, b);
386 : }
387 : Node* Uint64Mod(Node* a, Node* b) {
388 : return AddNode(machine()->Uint64Mod(), a, b);
389 : }
390 : Node* Int32PairAdd(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
391 : return AddNode(machine()->Int32PairAdd(), a_low, a_high, b_low, b_high);
392 : }
393 : Node* Int32PairSub(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
394 : return AddNode(machine()->Int32PairSub(), a_low, a_high, b_low, b_high);
395 : }
396 : Node* Int32PairMul(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
397 : return AddNode(machine()->Int32PairMul(), a_low, a_high, b_low, b_high);
398 : }
399 : Node* Word32PairShl(Node* low_word, Node* high_word, Node* shift) {
400 : return AddNode(machine()->Word32PairShl(), low_word, high_word, shift);
401 : }
402 : Node* Word32PairShr(Node* low_word, Node* high_word, Node* shift) {
403 : return AddNode(machine()->Word32PairShr(), low_word, high_word, shift);
404 : }
405 : Node* Word32PairSar(Node* low_word, Node* high_word, Node* shift) {
406 : return AddNode(machine()->Word32PairSar(), low_word, high_word, shift);
407 : }
408 :
409 : #define INTPTR_BINOP(prefix, name) \
410 : Node* IntPtr##name(Node* a, Node* b) { \
411 : return kPointerSize == 8 ? prefix##64##name(a, b) \
412 : : prefix##32##name(a, b); \
413 : }
414 :
415 390868 : INTPTR_BINOP(Int, Add);
416 874 : INTPTR_BINOP(Int, AddWithOverflow);
417 50273 : INTPTR_BINOP(Int, Sub);
418 440 : INTPTR_BINOP(Int, SubWithOverflow);
419 22434 : INTPTR_BINOP(Int, Mul);
420 : INTPTR_BINOP(Int, Div);
421 5489 : INTPTR_BINOP(Int, LessThan);
422 4846 : INTPTR_BINOP(Int, LessThanOrEqual);
423 3005 : INTPTR_BINOP(Word, Equal);
424 30 : INTPTR_BINOP(Word, NotEqual);
425 : INTPTR_BINOP(Int, GreaterThanOrEqual);
426 : INTPTR_BINOP(Int, GreaterThan);
427 :
428 : #undef INTPTR_BINOP
429 :
430 : #define UINTPTR_BINOP(prefix, name) \
431 : Node* UintPtr##name(Node* a, Node* b) { \
432 : return kPointerSize == 8 ? prefix##64##name(a, b) \
433 : : prefix##32##name(a, b); \
434 : }
435 :
436 10186 : UINTPTR_BINOP(Uint, LessThan);
437 1231 : UINTPTR_BINOP(Uint, LessThanOrEqual);
438 : UINTPTR_BINOP(Uint, GreaterThanOrEqual);
439 : UINTPTR_BINOP(Uint, GreaterThan);
440 :
441 : #undef UINTPTR_BINOP
442 :
443 0 : Node* Int32AbsWithOverflow(Node* a) {
444 0 : return AddNode(machine()->Int32AbsWithOverflow().op(), a);
445 : }
446 :
447 0 : Node* Int64AbsWithOverflow(Node* a) {
448 0 : return AddNode(machine()->Int64AbsWithOverflow().op(), a);
449 : }
450 :
451 : Node* IntPtrAbsWithOverflow(Node* a) {
452 : return kPointerSize == 8 ? Int64AbsWithOverflow(a)
453 0 : : Int32AbsWithOverflow(a);
454 : }
455 :
456 15 : Node* Float32Add(Node* a, Node* b) {
457 30 : return AddNode(machine()->Float32Add(), a, b);
458 : }
459 1160 : Node* Float32Sub(Node* a, Node* b) {
460 2320 : return AddNode(machine()->Float32Sub(), a, b);
461 : }
462 10 : Node* Float32Mul(Node* a, Node* b) {
463 20 : return AddNode(machine()->Float32Mul(), a, b);
464 : }
465 10 : Node* Float32Div(Node* a, Node* b) {
466 20 : return AddNode(machine()->Float32Div(), a, b);
467 : }
468 14 : Node* Float32Abs(Node* a) { return AddNode(machine()->Float32Abs(), a); }
469 : Node* Float32Neg(Node* a) { return AddNode(machine()->Float32Neg(), a); }
470 : Node* Float32Sqrt(Node* a) { return AddNode(machine()->Float32Sqrt(), a); }
471 0 : Node* Float32Equal(Node* a, Node* b) {
472 0 : return AddNode(machine()->Float32Equal(), a, b);
473 : }
474 : Node* Float32NotEqual(Node* a, Node* b) {
475 : return Word32BinaryNot(Float32Equal(a, b));
476 : }
477 5 : Node* Float32LessThan(Node* a, Node* b) {
478 10 : return AddNode(machine()->Float32LessThan(), a, b);
479 : }
480 0 : Node* Float32LessThanOrEqual(Node* a, Node* b) {
481 0 : return AddNode(machine()->Float32LessThanOrEqual(), a, b);
482 : }
483 0 : Node* Float32GreaterThan(Node* a, Node* b) { return Float32LessThan(b, a); }
484 : Node* Float32GreaterThanOrEqual(Node* a, Node* b) {
485 0 : return Float32LessThanOrEqual(b, a);
486 : }
487 5 : Node* Float32Max(Node* a, Node* b) {
488 10 : return AddNode(machine()->Float32Max(), a, b);
489 : }
490 5 : Node* Float32Min(Node* a, Node* b) {
491 10 : return AddNode(machine()->Float32Min(), a, b);
492 : }
493 1157 : Node* Float64Add(Node* a, Node* b) {
494 2314 : return AddNode(machine()->Float64Add(), a, b);
495 : }
496 1381 : Node* Float64Sub(Node* a, Node* b) {
497 2762 : return AddNode(machine()->Float64Sub(), a, b);
498 : }
499 1080 : Node* Float64Mul(Node* a, Node* b) {
500 2160 : return AddNode(machine()->Float64Mul(), a, b);
501 : }
502 415 : Node* Float64Div(Node* a, Node* b) {
503 830 : return AddNode(machine()->Float64Div(), a, b);
504 : }
505 364 : Node* Float64Mod(Node* a, Node* b) {
506 728 : return AddNode(machine()->Float64Mod(), a, b);
507 : }
508 41 : Node* Float64Max(Node* a, Node* b) {
509 82 : return AddNode(machine()->Float64Max(), a, b);
510 : }
511 41 : Node* Float64Min(Node* a, Node* b) {
512 82 : return AddNode(machine()->Float64Min(), a, b);
513 : }
514 3796 : Node* Float64Abs(Node* a) { return AddNode(machine()->Float64Abs(), a); }
515 362 : Node* Float64Neg(Node* a) { return AddNode(machine()->Float64Neg(), a); }
516 72 : Node* Float64Acos(Node* a) { return AddNode(machine()->Float64Acos(), a); }
517 72 : Node* Float64Acosh(Node* a) { return AddNode(machine()->Float64Acosh(), a); }
518 72 : Node* Float64Asin(Node* a) { return AddNode(machine()->Float64Asin(), a); }
519 72 : Node* Float64Asinh(Node* a) { return AddNode(machine()->Float64Asinh(), a); }
520 72 : Node* Float64Atan(Node* a) { return AddNode(machine()->Float64Atan(), a); }
521 72 : Node* Float64Atanh(Node* a) { return AddNode(machine()->Float64Atanh(), a); }
522 36 : Node* Float64Atan2(Node* a, Node* b) {
523 72 : return AddNode(machine()->Float64Atan2(), a, b);
524 : }
525 72 : Node* Float64Cbrt(Node* a) { return AddNode(machine()->Float64Cbrt(), a); }
526 72 : Node* Float64Cos(Node* a) { return AddNode(machine()->Float64Cos(), a); }
527 72 : Node* Float64Cosh(Node* a) { return AddNode(machine()->Float64Cosh(), a); }
528 72 : Node* Float64Exp(Node* a) { return AddNode(machine()->Float64Exp(), a); }
529 72 : Node* Float64Expm1(Node* a) { return AddNode(machine()->Float64Expm1(), a); }
530 72 : Node* Float64Log(Node* a) { return AddNode(machine()->Float64Log(), a); }
531 72 : Node* Float64Log1p(Node* a) { return AddNode(machine()->Float64Log1p(), a); }
532 72 : Node* Float64Log10(Node* a) { return AddNode(machine()->Float64Log10(), a); }
533 72 : Node* Float64Log2(Node* a) { return AddNode(machine()->Float64Log2(), a); }
534 31 : Node* Float64Pow(Node* a, Node* b) {
535 62 : return AddNode(machine()->Float64Pow(), a, b);
536 : }
537 72 : Node* Float64Sin(Node* a) { return AddNode(machine()->Float64Sin(), a); }
538 72 : Node* Float64Sinh(Node* a) { return AddNode(machine()->Float64Sinh(), a); }
539 62 : Node* Float64Sqrt(Node* a) { return AddNode(machine()->Float64Sqrt(), a); }
540 72 : Node* Float64Tan(Node* a) { return AddNode(machine()->Float64Tan(), a); }
541 72 : Node* Float64Tanh(Node* a) { return AddNode(machine()->Float64Tanh(), a); }
542 14734 : Node* Float64Equal(Node* a, Node* b) {
543 29468 : return AddNode(machine()->Float64Equal(), a, b);
544 : }
545 360 : Node* Float64NotEqual(Node* a, Node* b) {
546 360 : return Word32BinaryNot(Float64Equal(a, b));
547 : }
548 3206 : Node* Float64LessThan(Node* a, Node* b) {
549 6412 : return AddNode(machine()->Float64LessThan(), a, b);
550 : }
551 1601 : Node* Float64LessThanOrEqual(Node* a, Node* b) {
552 3202 : return AddNode(machine()->Float64LessThanOrEqual(), a, b);
553 : }
554 522 : Node* Float64GreaterThan(Node* a, Node* b) { return Float64LessThan(b, a); }
555 : Node* Float64GreaterThanOrEqual(Node* a, Node* b) {
556 729 : return Float64LessThanOrEqual(b, a);
557 : }
558 :
559 : // Conversions.
560 : Node* BitcastTaggedToWord(Node* a) {
561 : #ifdef ENABLE_VERIFY_CSA
562 : return AddNode(machine()->BitcastTaggedToWord(), a);
563 : #else
564 : return a;
565 : #endif
566 : }
567 37612 : Node* BitcastWordToTagged(Node* a) {
568 75224 : return AddNode(machine()->BitcastWordToTagged(), a);
569 : }
570 : Node* BitcastWordToTaggedSigned(Node* a) {
571 : #ifdef ENABLE_VERIFY_CSA
572 : return AddNode(machine()->BitcastWordToTaggedSigned(), a);
573 : #else
574 : return a;
575 : #endif
576 : }
577 6088 : Node* TruncateFloat64ToWord32(Node* a) {
578 12176 : return AddNode(machine()->TruncateFloat64ToWord32(), a);
579 : }
580 1527 : Node* ChangeFloat32ToFloat64(Node* a) {
581 3054 : return AddNode(machine()->ChangeFloat32ToFloat64(), a);
582 : }
583 18274 : Node* ChangeInt32ToFloat64(Node* a) {
584 36548 : return AddNode(machine()->ChangeInt32ToFloat64(), a);
585 : }
586 824 : Node* ChangeUint32ToFloat64(Node* a) {
587 1648 : return AddNode(machine()->ChangeUint32ToFloat64(), a);
588 : }
589 25 : Node* ChangeFloat64ToInt32(Node* a) {
590 50 : return AddNode(machine()->ChangeFloat64ToInt32(), a);
591 : }
592 17 : Node* ChangeFloat64ToUint32(Node* a) {
593 34 : return AddNode(machine()->ChangeFloat64ToUint32(), a);
594 : }
595 93 : Node* ChangeFloat64ToUint64(Node* a) {
596 186 : return AddNode(machine()->ChangeFloat64ToUint64(), a);
597 : }
598 : Node* TruncateFloat64ToUint32(Node* a) {
599 : return AddNode(machine()->TruncateFloat64ToUint32(), a);
600 : }
601 5 : Node* TruncateFloat32ToInt32(Node* a) {
602 10 : return AddNode(machine()->TruncateFloat32ToInt32(), a);
603 : }
604 5 : Node* TruncateFloat32ToUint32(Node* a) {
605 10 : return AddNode(machine()->TruncateFloat32ToUint32(), a);
606 : }
607 10 : Node* TryTruncateFloat32ToInt64(Node* a) {
608 20 : return AddNode(machine()->TryTruncateFloat32ToInt64(), a);
609 : }
610 10 : Node* TryTruncateFloat64ToInt64(Node* a) {
611 20 : return AddNode(machine()->TryTruncateFloat64ToInt64(), a);
612 : }
613 10 : Node* TryTruncateFloat32ToUint64(Node* a) {
614 20 : return AddNode(machine()->TryTruncateFloat32ToUint64(), a);
615 : }
616 10 : Node* TryTruncateFloat64ToUint64(Node* a) {
617 20 : return AddNode(machine()->TryTruncateFloat64ToUint64(), a);
618 : }
619 44185 : Node* ChangeInt32ToInt64(Node* a) {
620 88370 : return AddNode(machine()->ChangeInt32ToInt64(), a);
621 : }
622 40801 : Node* ChangeUint32ToUint64(Node* a) {
623 81602 : return AddNode(machine()->ChangeUint32ToUint64(), a);
624 : }
625 1396 : Node* TruncateFloat64ToFloat32(Node* a) {
626 2792 : return AddNode(machine()->TruncateFloat64ToFloat32(), a);
627 : }
628 62411 : Node* TruncateInt64ToInt32(Node* a) {
629 124822 : return AddNode(machine()->TruncateInt64ToInt32(), a);
630 : }
631 7632 : Node* RoundFloat64ToInt32(Node* a) {
632 15264 : return AddNode(machine()->RoundFloat64ToInt32(), a);
633 : }
634 158 : Node* RoundInt32ToFloat32(Node* a) {
635 316 : return AddNode(machine()->RoundInt32ToFloat32(), a);
636 : }
637 5 : Node* RoundInt64ToFloat32(Node* a) {
638 10 : return AddNode(machine()->RoundInt64ToFloat32(), a);
639 : }
640 488 : Node* RoundInt64ToFloat64(Node* a) {
641 976 : return AddNode(machine()->RoundInt64ToFloat64(), a);
642 : }
643 5 : Node* RoundUint32ToFloat32(Node* a) {
644 10 : return AddNode(machine()->RoundUint32ToFloat32(), a);
645 : }
646 5 : Node* RoundUint64ToFloat32(Node* a) {
647 10 : return AddNode(machine()->RoundUint64ToFloat32(), a);
648 : }
649 5 : Node* RoundUint64ToFloat64(Node* a) {
650 10 : return AddNode(machine()->RoundUint64ToFloat64(), a);
651 : }
652 5 : Node* BitcastFloat32ToInt32(Node* a) {
653 10 : return AddNode(machine()->BitcastFloat32ToInt32(), a);
654 : }
655 5 : Node* BitcastFloat64ToInt64(Node* a) {
656 10 : return AddNode(machine()->BitcastFloat64ToInt64(), a);
657 : }
658 5 : Node* BitcastInt32ToFloat32(Node* a) {
659 10 : return AddNode(machine()->BitcastInt32ToFloat32(), a);
660 : }
661 5 : Node* BitcastInt64ToFloat64(Node* a) {
662 10 : return AddNode(machine()->BitcastInt64ToFloat64(), a);
663 : }
664 5 : Node* Float32RoundDown(Node* a) {
665 10 : return AddNode(machine()->Float32RoundDown().op(), a);
666 : }
667 70 : Node* Float64RoundDown(Node* a) {
668 140 : return AddNode(machine()->Float64RoundDown().op(), a);
669 : }
670 5 : Node* Float32RoundUp(Node* a) {
671 10 : return AddNode(machine()->Float32RoundUp().op(), a);
672 : }
673 65 : Node* Float64RoundUp(Node* a) {
674 130 : return AddNode(machine()->Float64RoundUp().op(), a);
675 : }
676 5 : Node* Float32RoundTruncate(Node* a) {
677 10 : return AddNode(machine()->Float32RoundTruncate().op(), a);
678 : }
679 1181 : Node* Float64RoundTruncate(Node* a) {
680 2362 : return AddNode(machine()->Float64RoundTruncate().op(), a);
681 : }
682 0 : Node* Float64RoundTiesAway(Node* a) {
683 0 : return AddNode(machine()->Float64RoundTiesAway().op(), a);
684 : }
685 5 : Node* Float32RoundTiesEven(Node* a) {
686 10 : return AddNode(machine()->Float32RoundTiesEven().op(), a);
687 : }
688 145 : Node* Float64RoundTiesEven(Node* a) {
689 290 : return AddNode(machine()->Float64RoundTiesEven().op(), a);
690 : }
691 : Node* Word32ReverseBytes(Node* a) {
692 : return AddNode(machine()->Word32ReverseBytes().op(), a);
693 : }
694 : Node* Word64ReverseBytes(Node* a) {
695 : return AddNode(machine()->Word64ReverseBytes().op(), a);
696 : }
697 :
698 : // Float64 bit operations.
699 5 : Node* Float64ExtractLowWord32(Node* a) {
700 10 : return AddNode(machine()->Float64ExtractLowWord32(), a);
701 : }
702 2100 : Node* Float64ExtractHighWord32(Node* a) {
703 4200 : return AddNode(machine()->Float64ExtractHighWord32(), a);
704 : }
705 5 : Node* Float64InsertLowWord32(Node* a, Node* b) {
706 10 : return AddNode(machine()->Float64InsertLowWord32(), a, b);
707 : }
708 5 : Node* Float64InsertHighWord32(Node* a, Node* b) {
709 10 : return AddNode(machine()->Float64InsertHighWord32(), a, b);
710 : }
711 791 : Node* Float64SilenceNaN(Node* a) {
712 1582 : return AddNode(machine()->Float64SilenceNaN(), a);
713 : }
714 :
715 : // Stack operations.
716 64 : Node* LoadStackPointer() { return AddNode(machine()->LoadStackPointer()); }
717 4234 : Node* LoadFramePointer() { return AddNode(machine()->LoadFramePointer()); }
718 15191 : Node* LoadParentFramePointer() {
719 30382 : return AddNode(machine()->LoadParentFramePointer());
720 : }
721 :
722 : // Parameters.
723 : Node* Parameter(size_t index);
724 :
725 : // Pointer utilities.
726 8882 : Node* LoadFromPointer(void* address, MachineType rep, int32_t offset = 0) {
727 17764 : return Load(rep, PointerConstant(address), Int32Constant(offset));
728 : }
729 130335 : Node* StoreToPointer(void* address, MachineRepresentation rep, Node* node) {
730 130335 : return Store(rep, PointerConstant(address), node, kNoWriteBarrier);
731 : }
732 114 : Node* UnalignedLoadFromPointer(void* address, MachineType rep,
733 : int32_t offset = 0) {
734 228 : return UnalignedLoad(rep, PointerConstant(address), Int32Constant(offset));
735 : }
736 48 : Node* UnalignedStoreToPointer(void* address, MachineRepresentation rep,
737 : Node* node) {
738 48 : return UnalignedStore(rep, PointerConstant(address), node);
739 : }
740 57 : Node* StringConstant(const char* string) {
741 114 : return HeapConstant(isolate()->factory()->InternalizeUtf8String(string));
742 : }
743 :
744 : // Call a given call descriptor and the given arguments.
745 : // The call target is passed as part of the {inputs} array.
746 : Node* CallN(CallDescriptor* desc, int input_count, Node* const* inputs);
747 :
748 : // Call a given call descriptor and the given arguments and frame-state.
749 : // The call target and frame state are passed as part of the {inputs} array.
750 : Node* CallNWithFrameState(CallDescriptor* desc, int input_count,
751 : Node* const* inputs);
752 :
753 : // Tail call a given call descriptor and the given arguments.
754 : // The call target is passed as part of the {inputs} array.
755 : Node* TailCallN(CallDescriptor* desc, int input_count, Node* const* inputs);
756 :
757 : // Call to a C function with zero arguments.
758 : Node* CallCFunction0(MachineType return_type, Node* function);
759 : // Call to a C function with one parameter.
760 : Node* CallCFunction1(MachineType return_type, MachineType arg0_type,
761 : Node* function, Node* arg0);
762 : // Call to a C function with one argument, while saving/restoring caller
763 : // registers.
764 : Node* CallCFunction1WithCallerSavedRegisters(
765 : MachineType return_type, MachineType arg0_type, Node* function,
766 : Node* arg0, SaveFPRegsMode mode = kSaveFPRegs);
767 : // Call to a C function with two arguments.
768 : Node* CallCFunction2(MachineType return_type, MachineType arg0_type,
769 : MachineType arg1_type, Node* function, Node* arg0,
770 : Node* arg1);
771 : // Call to a C function with three arguments.
772 : Node* CallCFunction3(MachineType return_type, MachineType arg0_type,
773 : MachineType arg1_type, MachineType arg2_type,
774 : Node* function, Node* arg0, Node* arg1, Node* arg2);
775 : // Call to a C function with three arguments, while saving/restoring caller
776 : // registers.
777 : Node* CallCFunction3WithCallerSavedRegisters(
778 : MachineType return_type, MachineType arg0_type, MachineType arg1_type,
779 : MachineType arg2_type, Node* function, Node* arg0, Node* arg1, Node* arg2,
780 : SaveFPRegsMode mode = kSaveFPRegs);
781 : // Call to a C function with six arguments.
782 : Node* CallCFunction6(MachineType return_type, MachineType arg0_type,
783 : MachineType arg1_type, MachineType arg2_type,
784 : MachineType arg3_type, MachineType arg4_type,
785 : MachineType arg5_type, Node* function, Node* arg0,
786 : Node* arg1, Node* arg2, Node* arg3, Node* arg4,
787 : Node* arg5);
788 : // Call to a C function with eight arguments.
789 : Node* CallCFunction8(MachineType return_type, MachineType arg0_type,
790 : MachineType arg1_type, MachineType arg2_type,
791 : MachineType arg3_type, MachineType arg4_type,
792 : MachineType arg5_type, MachineType arg6_type,
793 : MachineType arg7_type, Node* function, Node* arg0,
794 : Node* arg1, Node* arg2, Node* arg3, Node* arg4,
795 : Node* arg5, Node* arg6, Node* arg7);
796 : // Call to a C function with nine arguments.
797 : Node* CallCFunction9(MachineType return_type, MachineType arg0_type,
798 : MachineType arg1_type, MachineType arg2_type,
799 : MachineType arg3_type, MachineType arg4_type,
800 : MachineType arg5_type, MachineType arg6_type,
801 : MachineType arg7_type, MachineType arg8_type,
802 : Node* function, Node* arg0, Node* arg1, Node* arg2,
803 : Node* arg3, Node* arg4, Node* arg5, Node* arg6,
804 : Node* arg7, Node* arg8);
805 :
806 : // ===========================================================================
807 : // The following utility methods deal with control flow, hence might switch
808 : // the current basic block or create new basic blocks for labels.
809 :
810 : // Control flow.
811 : void Goto(RawMachineLabel* label);
812 : void Branch(Node* condition, RawMachineLabel* true_val,
813 : RawMachineLabel* false_val);
814 : void Switch(Node* index, RawMachineLabel* default_label,
815 : const int32_t* case_values, RawMachineLabel** case_labels,
816 : size_t case_count);
817 : void Return(Node* value);
818 : void Return(Node* v1, Node* v2);
819 : void Return(Node* v1, Node* v2, Node* v3);
820 : void PopAndReturn(Node* pop, Node* value);
821 : void PopAndReturn(Node* pop, Node* v1, Node* v2);
822 : void PopAndReturn(Node* pop, Node* v1, Node* v2, Node* v3);
823 : void Bind(RawMachineLabel* label);
824 : void Deoptimize(Node* state);
825 : void DebugAbort(Node* message);
826 : void DebugBreak();
827 : void Unreachable();
828 : void Comment(const char* msg);
829 :
830 : #if DEBUG
831 : void Bind(RawMachineLabel* label, AssemblerDebugInfo info);
832 : void SetInitialDebugInformation(AssemblerDebugInfo info);
833 : void PrintCurrentBlock(std::ostream& os);
834 : #endif // DEBUG
835 :
836 : // Add success / exception successor blocks and ends the current block ending
837 : // in a potentially throwing call node.
838 : void Continuations(Node* call, RawMachineLabel* if_success,
839 : RawMachineLabel* if_exception);
840 :
841 : // Variables.
842 193 : Node* Phi(MachineRepresentation rep, Node* n1, Node* n2) {
843 386 : return AddNode(common()->Phi(rep, 2), n1, n2, graph()->start());
844 : }
845 : Node* Phi(MachineRepresentation rep, Node* n1, Node* n2, Node* n3) {
846 : return AddNode(common()->Phi(rep, 3), n1, n2, n3, graph()->start());
847 : }
848 : Node* Phi(MachineRepresentation rep, Node* n1, Node* n2, Node* n3, Node* n4) {
849 : return AddNode(common()->Phi(rep, 4), n1, n2, n3, n4, graph()->start());
850 : }
851 : Node* Phi(MachineRepresentation rep, int input_count, Node* const* inputs);
852 : void AppendPhiInput(Node* phi, Node* new_input);
853 :
854 : // ===========================================================================
855 : // The following generic node creation methods can be used for operators that
856 : // are not covered by the above utility methods. There should rarely be a need
857 : // to do that outside of testing though.
858 :
859 : Node* AddNode(const Operator* op, int input_count, Node* const* inputs);
860 :
861 : Node* AddNode(const Operator* op) {
862 4508541 : return AddNode(op, 0, static_cast<Node* const*>(nullptr));
863 : }
864 :
865 : template <class... TArgs>
866 : Node* AddNode(const Operator* op, Node* n1, TArgs... args) {
867 4366016 : Node* buffer[] = {n1, args...};
868 4366016 : return AddNode(op, sizeof...(args) + 1, buffer);
869 : }
870 :
871 : private:
872 : Node* MakeNode(const Operator* op, int input_count, Node* const* inputs);
873 : BasicBlock* Use(RawMachineLabel* label);
874 : BasicBlock* EnsureBlock(RawMachineLabel* label);
875 : BasicBlock* CurrentBlock();
876 :
877 : Schedule* schedule() { return schedule_; }
878 1329118 : size_t parameter_count() const { return call_descriptor_->ParameterCount(); }
879 :
880 : Isolate* isolate_;
881 : Graph* graph_;
882 : Schedule* schedule_;
883 : MachineOperatorBuilder machine_;
884 : CommonOperatorBuilder common_;
885 : CallDescriptor* call_descriptor_;
886 : NodeVector parameters_;
887 : BasicBlock* current_block_;
888 :
889 : DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler);
890 : };
891 :
892 : class V8_EXPORT_PRIVATE RawMachineLabel final {
893 : public:
894 : enum Type { kDeferred, kNonDeferred };
895 :
896 : explicit RawMachineLabel(Type type = kNonDeferred)
897 1068501 : : deferred_(type == kDeferred) {}
898 : ~RawMachineLabel();
899 :
900 : BasicBlock* block() const { return block_; }
901 :
902 : private:
903 : BasicBlock* block_ = nullptr;
904 : bool used_ = false;
905 : bool bound_ = false;
906 : bool deferred_;
907 : friend class RawMachineAssembler;
908 : DISALLOW_COPY_AND_ASSIGN(RawMachineLabel);
909 : };
910 :
911 : } // namespace compiler
912 : } // namespace internal
913 : } // namespace v8
914 :
915 : #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_
|