V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
raw-machine-assembler.h
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/globals.h"
16 #include "src/heap/factory.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:
41  Isolate* isolate, Graph* graph, CallDescriptor* call_descriptor,
42  MachineRepresentation word = MachineType::PointerRepresentation(),
44  MachineOperatorBuilder::Flag::kNoFlags,
45  MachineOperatorBuilder::AlignmentRequirements alignment_requirements =
47  FullUnalignedAccessSupport(),
48  PoisoningMitigationLevel poisoning_level =
49  PoisoningMitigationLevel::kPoisonCriticalOnly);
50  ~RawMachineAssembler() = default;
51 
52  Isolate* isolate() const { return isolate_; }
53  Graph* graph() const { return graph_; }
54  Zone* zone() const { return graph()->zone(); }
55  MachineOperatorBuilder* machine() { return &machine_; }
56  CommonOperatorBuilder* common() { return &common_; }
57  CallDescriptor* call_descriptor() const { return call_descriptor_; }
58  PoisoningMitigationLevel poisoning_level() const { return poisoning_level_; }
59 
60  // Finalizes the schedule and exports it to be used for code generation. Note
61  // that this RawMachineAssembler becomes invalid after export.
62  Schedule* Export();
63  // Finalizes the schedule and transforms it into a graph that's suitable for
64  // it to be used for Turbofan optimization and re-scheduling. Note that this
65  // RawMachineAssembler becomes invalid after export.
66  Graph* ExportForOptimization();
67 
68  // ===========================================================================
69  // The following utility methods create new nodes with specific operators and
70  // place them into the current basic block. They don't perform control flow,
71  // hence will not switch the current basic block.
72 
73  Node* NullConstant();
74  Node* UndefinedConstant();
75 
76  // Constants.
77  Node* PointerConstant(void* value) {
78  return IntPtrConstant(reinterpret_cast<intptr_t>(value));
79  }
80  Node* IntPtrConstant(intptr_t value) {
81  // TODO(dcarney): mark generated code as unserializable if value != 0.
82  return kPointerSize == 8 ? Int64Constant(value)
83  : Int32Constant(static_cast<int>(value));
84  }
85  Node* RelocatableIntPtrConstant(intptr_t value, RelocInfo::Mode rmode);
86  Node* Int32Constant(int32_t value) {
87  return AddNode(common()->Int32Constant(value));
88  }
89  Node* StackSlot(MachineRepresentation rep, int alignment = 0) {
90  return AddNode(machine()->StackSlot(rep, alignment));
91  }
92  Node* Int64Constant(int64_t value) {
93  return AddNode(common()->Int64Constant(value));
94  }
95  Node* NumberConstant(double value) {
96  return AddNode(common()->NumberConstant(value));
97  }
98  Node* Float32Constant(float value) {
99  return AddNode(common()->Float32Constant(value));
100  }
101  Node* Float64Constant(double value) {
102  return AddNode(common()->Float64Constant(value));
103  }
104  Node* HeapConstant(Handle<HeapObject> object) {
105  return AddNode(common()->HeapConstant(object));
106  }
107  Node* ExternalConstant(ExternalReference address) {
108  return AddNode(common()->ExternalConstant(address));
109  }
110  Node* RelocatableInt32Constant(int32_t value, RelocInfo::Mode rmode) {
111  return AddNode(common()->RelocatableInt32Constant(value, rmode));
112  }
113  Node* RelocatableInt64Constant(int64_t value, RelocInfo::Mode rmode) {
114  return AddNode(common()->RelocatableInt64Constant(value, rmode));
115  }
116 
117  Node* Projection(int index, Node* a) {
118  return AddNode(common()->Projection(index), a);
119  }
120 
121  // Memory Operations.
122  Node* Load(MachineType rep, Node* base,
123  LoadSensitivity needs_poisoning = LoadSensitivity::kSafe) {
124  return Load(rep, base, IntPtrConstant(0), needs_poisoning);
125  }
126  Node* Load(MachineType rep, Node* base, Node* index,
127  LoadSensitivity needs_poisoning = LoadSensitivity::kSafe) {
128  const Operator* op = machine()->Load(rep);
129  CHECK_NE(PoisoningMitigationLevel::kPoisonAll, poisoning_level_);
130  if (needs_poisoning == LoadSensitivity::kCritical &&
131  poisoning_level_ == PoisoningMitigationLevel::kPoisonCriticalOnly) {
132  op = machine()->PoisonedLoad(rep);
133  }
134  return AddNode(op, base, index);
135  }
136  Node* Store(MachineRepresentation rep, Node* base, Node* value,
137  WriteBarrierKind write_barrier) {
138  return Store(rep, base, IntPtrConstant(0), value, write_barrier);
139  }
140  Node* Store(MachineRepresentation rep, Node* base, Node* index, Node* value,
141  WriteBarrierKind write_barrier) {
142  return AddNode(machine()->Store(StoreRepresentation(rep, write_barrier)),
143  base, index, value);
144  }
145  Node* Retain(Node* value) { return AddNode(common()->Retain(), value); }
146 
147  // Unaligned memory operations
148  Node* UnalignedLoad(MachineType type, Node* base) {
149  return UnalignedLoad(type, base, IntPtrConstant(0));
150  }
151  Node* UnalignedLoad(MachineType type, Node* base, Node* index) {
152  if (machine()->UnalignedLoadSupported(type.representation())) {
153  return AddNode(machine()->Load(type), base, index);
154  } else {
155  return AddNode(machine()->UnalignedLoad(type), base, index);
156  }
157  }
158  Node* UnalignedStore(MachineRepresentation rep, Node* base, Node* value) {
159  return UnalignedStore(rep, base, IntPtrConstant(0), value);
160  }
161  Node* UnalignedStore(MachineRepresentation rep, Node* base, Node* index,
162  Node* value) {
163  if (machine()->UnalignedStoreSupported(rep)) {
164  return AddNode(machine()->Store(StoreRepresentation(
165  rep, WriteBarrierKind::kNoWriteBarrier)),
166  base, index, value);
167  } else {
168  return AddNode(
169  machine()->UnalignedStore(UnalignedStoreRepresentation(rep)), base,
170  index, value);
171  }
172  }
173 
174  // Atomic memory operations.
175  Node* AtomicLoad(MachineType type, Node* base, Node* index) {
176  if (type.representation() == MachineRepresentation::kWord64) {
177  if (machine()->Is64()) {
178  return AddNode(machine()->Word64AtomicLoad(type), base, index);
179  } else {
180  return AddNode(machine()->Word32AtomicPairLoad(), base, index);
181  }
182  }
183  return AddNode(machine()->Word32AtomicLoad(type), base, index);
184  }
185 
186 #if defined(V8_TARGET_BIG_ENDIAN)
187 #define VALUE_HALVES value_high, value
188 #else
189 #define VALUE_HALVES value, value_high
190 #endif
191 
192  Node* AtomicStore(MachineRepresentation rep, Node* base, Node* index,
193  Node* value, Node* value_high) {
194  if (rep == MachineRepresentation::kWord64) {
195  if (machine()->Is64()) {
196  DCHECK_NULL(value_high);
197  return AddNode(machine()->Word64AtomicStore(rep), base, index, value);
198  } else {
199  return AddNode(machine()->Word32AtomicPairStore(), base, index,
200  VALUE_HALVES);
201  }
202  }
203  DCHECK_NULL(value_high);
204  return AddNode(machine()->Word32AtomicStore(rep), base, index, value);
205  }
206 #define ATOMIC_FUNCTION(name) \
207  Node* Atomic##name(MachineType rep, Node* base, Node* index, Node* value, \
208  Node* value_high) { \
209  if (rep.representation() == MachineRepresentation::kWord64) { \
210  if (machine()->Is64()) { \
211  DCHECK_NULL(value_high); \
212  return AddNode(machine()->Word64Atomic##name(rep), base, index, \
213  value); \
214  } else { \
215  return AddNode(machine()->Word32AtomicPair##name(), base, index, \
216  VALUE_HALVES); \
217  } \
218  } \
219  DCHECK_NULL(value_high); \
220  return AddNode(machine()->Word32Atomic##name(rep), base, index, value); \
221  }
222  ATOMIC_FUNCTION(Exchange);
223  ATOMIC_FUNCTION(Add);
224  ATOMIC_FUNCTION(Sub);
225  ATOMIC_FUNCTION(And);
226  ATOMIC_FUNCTION(Or);
227  ATOMIC_FUNCTION(Xor);
228 #undef ATOMIC_FUNCTION
229 #undef VALUE_HALVES
230 
231  Node* AtomicCompareExchange(MachineType rep, Node* base, Node* index,
232  Node* old_value, Node* old_value_high,
233  Node* new_value, Node* new_value_high) {
234  if (rep.representation() == MachineRepresentation::kWord64) {
235  if (machine()->Is64()) {
236  DCHECK_NULL(old_value_high);
237  DCHECK_NULL(new_value_high);
238  return AddNode(machine()->Word64AtomicCompareExchange(rep), base, index,
239  old_value, new_value);
240  } else {
241  return AddNode(machine()->Word32AtomicPairCompareExchange(), base,
242  index, old_value, old_value_high, new_value,
243  new_value_high);
244  }
245  }
246  DCHECK_NULL(old_value_high);
247  DCHECK_NULL(new_value_high);
248  return AddNode(machine()->Word32AtomicCompareExchange(rep), base, index,
249  old_value, new_value);
250  }
251 
252  Node* SpeculationFence() {
253  return AddNode(machine()->SpeculationFence().op());
254  }
255 
256  // Arithmetic Operations.
257  Node* WordAnd(Node* a, Node* b) {
258  return AddNode(machine()->WordAnd(), a, b);
259  }
260  Node* WordOr(Node* a, Node* b) { return AddNode(machine()->WordOr(), a, b); }
261  Node* WordXor(Node* a, Node* b) {
262  return AddNode(machine()->WordXor(), a, b);
263  }
264  Node* WordShl(Node* a, Node* b) {
265  return AddNode(machine()->WordShl(), a, b);
266  }
267  Node* WordShr(Node* a, Node* b) {
268  return AddNode(machine()->WordShr(), a, b);
269  }
270  Node* WordSar(Node* a, Node* b) {
271  return AddNode(machine()->WordSar(), a, b);
272  }
273  Node* WordRor(Node* a, Node* b) {
274  return AddNode(machine()->WordRor(), a, b);
275  }
276  Node* WordEqual(Node* a, Node* b) {
277  return AddNode(machine()->WordEqual(), a, b);
278  }
279  Node* WordNotEqual(Node* a, Node* b) {
280  return Word32BinaryNot(WordEqual(a, b));
281  }
282  Node* WordNot(Node* a) {
283  if (machine()->Is32()) {
284  return Word32BitwiseNot(a);
285  } else {
286  return Word64Not(a);
287  }
288  }
289 
290  Node* Word32And(Node* a, Node* b) {
291  return AddNode(machine()->Word32And(), a, b);
292  }
293  Node* Word32Or(Node* a, Node* b) {
294  return AddNode(machine()->Word32Or(), a, b);
295  }
296  Node* Word32Xor(Node* a, Node* b) {
297  return AddNode(machine()->Word32Xor(), a, b);
298  }
299  Node* Word32Shl(Node* a, Node* b) {
300  return AddNode(machine()->Word32Shl(), a, b);
301  }
302  Node* Word32Shr(Node* a, Node* b) {
303  return AddNode(machine()->Word32Shr(), a, b);
304  }
305  Node* Word32Sar(Node* a, Node* b) {
306  return AddNode(machine()->Word32Sar(), a, b);
307  }
308  Node* Word32Ror(Node* a, Node* b) {
309  return AddNode(machine()->Word32Ror(), a, b);
310  }
311  Node* Word32Clz(Node* a) { return AddNode(machine()->Word32Clz(), a); }
312  Node* Word32Equal(Node* a, Node* b) {
313  return AddNode(machine()->Word32Equal(), a, b);
314  }
315  Node* Word32NotEqual(Node* a, Node* b) {
316  return Word32BinaryNot(Word32Equal(a, b));
317  }
318  Node* Word32BitwiseNot(Node* a) { return Word32Xor(a, Int32Constant(-1)); }
319  Node* Word32BinaryNot(Node* a) { return Word32Equal(a, Int32Constant(0)); }
320 
321  Node* Word64And(Node* a, Node* b) {
322  return AddNode(machine()->Word64And(), a, b);
323  }
324  Node* Word64Or(Node* a, Node* b) {
325  return AddNode(machine()->Word64Or(), a, b);
326  }
327  Node* Word64Xor(Node* a, Node* b) {
328  return AddNode(machine()->Word64Xor(), a, b);
329  }
330  Node* Word64Shl(Node* a, Node* b) {
331  return AddNode(machine()->Word64Shl(), a, b);
332  }
333  Node* Word64Shr(Node* a, Node* b) {
334  return AddNode(machine()->Word64Shr(), a, b);
335  }
336  Node* Word64Sar(Node* a, Node* b) {
337  return AddNode(machine()->Word64Sar(), a, b);
338  }
339  Node* Word64Ror(Node* a, Node* b) {
340  return AddNode(machine()->Word64Ror(), a, b);
341  }
342  Node* Word64Clz(Node* a) { return AddNode(machine()->Word64Clz(), a); }
343  Node* Word64Equal(Node* a, Node* b) {
344  return AddNode(machine()->Word64Equal(), a, b);
345  }
346  Node* Word64NotEqual(Node* a, Node* b) {
347  return Word32BinaryNot(Word64Equal(a, b));
348  }
349  Node* Word64Not(Node* a) { return Word64Xor(a, Int64Constant(-1)); }
350 
351  Node* Int32Add(Node* a, Node* b) {
352  return AddNode(machine()->Int32Add(), a, b);
353  }
354  Node* Int32AddWithOverflow(Node* a, Node* b) {
355  return AddNode(machine()->Int32AddWithOverflow(), a, b);
356  }
357  Node* Int32Sub(Node* a, Node* b) {
358  return AddNode(machine()->Int32Sub(), a, b);
359  }
360  Node* Int32SubWithOverflow(Node* a, Node* b) {
361  return AddNode(machine()->Int32SubWithOverflow(), a, b);
362  }
363  Node* Int32Mul(Node* a, Node* b) {
364  return AddNode(machine()->Int32Mul(), a, b);
365  }
366  Node* Int32MulHigh(Node* a, Node* b) {
367  return AddNode(machine()->Int32MulHigh(), a, b);
368  }
369  Node* Int32MulWithOverflow(Node* a, Node* b) {
370  return AddNode(machine()->Int32MulWithOverflow(), a, b);
371  }
372  Node* Int32Div(Node* a, Node* b) {
373  return AddNode(machine()->Int32Div(), a, b);
374  }
375  Node* Int32Mod(Node* a, Node* b) {
376  return AddNode(machine()->Int32Mod(), a, b);
377  }
378  Node* Int32LessThan(Node* a, Node* b) {
379  return AddNode(machine()->Int32LessThan(), a, b);
380  }
381  Node* Int32LessThanOrEqual(Node* a, Node* b) {
382  return AddNode(machine()->Int32LessThanOrEqual(), a, b);
383  }
384  Node* Uint32Div(Node* a, Node* b) {
385  return AddNode(machine()->Uint32Div(), a, b);
386  }
387  Node* Uint32LessThan(Node* a, Node* b) {
388  return AddNode(machine()->Uint32LessThan(), a, b);
389  }
390  Node* Uint32LessThanOrEqual(Node* a, Node* b) {
391  return AddNode(machine()->Uint32LessThanOrEqual(), a, b);
392  }
393  Node* Uint32Mod(Node* a, Node* b) {
394  return AddNode(machine()->Uint32Mod(), a, b);
395  }
396  Node* Uint32MulHigh(Node* a, Node* b) {
397  return AddNode(machine()->Uint32MulHigh(), a, b);
398  }
399  Node* Int32GreaterThan(Node* a, Node* b) { return Int32LessThan(b, a); }
400  Node* Int32GreaterThanOrEqual(Node* a, Node* b) {
401  return Int32LessThanOrEqual(b, a);
402  }
403  Node* Uint32GreaterThan(Node* a, Node* b) { return Uint32LessThan(b, a); }
404  Node* Uint32GreaterThanOrEqual(Node* a, Node* b) {
405  return Uint32LessThanOrEqual(b, a);
406  }
407  Node* Int32Neg(Node* a) { return Int32Sub(Int32Constant(0), a); }
408 
409  Node* Int64Add(Node* a, Node* b) {
410  return AddNode(machine()->Int64Add(), a, b);
411  }
412  Node* Int64AddWithOverflow(Node* a, Node* b) {
413  return AddNode(machine()->Int64AddWithOverflow(), a, b);
414  }
415  Node* Int64Sub(Node* a, Node* b) {
416  return AddNode(machine()->Int64Sub(), a, b);
417  }
418  Node* Int64SubWithOverflow(Node* a, Node* b) {
419  return AddNode(machine()->Int64SubWithOverflow(), a, b);
420  }
421  Node* Int64Mul(Node* a, Node* b) {
422  return AddNode(machine()->Int64Mul(), a, b);
423  }
424  Node* Int64Div(Node* a, Node* b) {
425  return AddNode(machine()->Int64Div(), a, b);
426  }
427  Node* Int64Mod(Node* a, Node* b) {
428  return AddNode(machine()->Int64Mod(), a, b);
429  }
430  Node* Int64Neg(Node* a) { return Int64Sub(Int64Constant(0), a); }
431  Node* Int64LessThan(Node* a, Node* b) {
432  return AddNode(machine()->Int64LessThan(), a, b);
433  }
434  Node* Int64LessThanOrEqual(Node* a, Node* b) {
435  return AddNode(machine()->Int64LessThanOrEqual(), a, b);
436  }
437  Node* Uint64LessThan(Node* a, Node* b) {
438  return AddNode(machine()->Uint64LessThan(), a, b);
439  }
440  Node* Uint64LessThanOrEqual(Node* a, Node* b) {
441  return AddNode(machine()->Uint64LessThanOrEqual(), a, b);
442  }
443  Node* Int64GreaterThan(Node* a, Node* b) { return Int64LessThan(b, a); }
444  Node* Int64GreaterThanOrEqual(Node* a, Node* b) {
445  return Int64LessThanOrEqual(b, a);
446  }
447  Node* Uint64GreaterThan(Node* a, Node* b) { return Uint64LessThan(b, a); }
448  Node* Uint64GreaterThanOrEqual(Node* a, Node* b) {
449  return Uint64LessThanOrEqual(b, a);
450  }
451  Node* Uint64Div(Node* a, Node* b) {
452  return AddNode(machine()->Uint64Div(), a, b);
453  }
454  Node* Uint64Mod(Node* a, Node* b) {
455  return AddNode(machine()->Uint64Mod(), a, b);
456  }
457  Node* Int32PairAdd(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
458  return AddNode(machine()->Int32PairAdd(), a_low, a_high, b_low, b_high);
459  }
460  Node* Int32PairSub(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
461  return AddNode(machine()->Int32PairSub(), a_low, a_high, b_low, b_high);
462  }
463  Node* Int32PairMul(Node* a_low, Node* a_high, Node* b_low, Node* b_high) {
464  return AddNode(machine()->Int32PairMul(), a_low, a_high, b_low, b_high);
465  }
466  Node* Word32PairShl(Node* low_word, Node* high_word, Node* shift) {
467  return AddNode(machine()->Word32PairShl(), low_word, high_word, shift);
468  }
469  Node* Word32PairShr(Node* low_word, Node* high_word, Node* shift) {
470  return AddNode(machine()->Word32PairShr(), low_word, high_word, shift);
471  }
472  Node* Word32PairSar(Node* low_word, Node* high_word, Node* shift) {
473  return AddNode(machine()->Word32PairSar(), low_word, high_word, shift);
474  }
475 
476 #define INTPTR_BINOP(prefix, name) \
477  Node* IntPtr##name(Node* a, Node* b) { \
478  return kPointerSize == 8 ? prefix##64##name(a, b) \
479  : prefix##32##name(a, b); \
480  }
481 
482  INTPTR_BINOP(Int, Add);
483  INTPTR_BINOP(Int, AddWithOverflow);
484  INTPTR_BINOP(Int, Sub);
485  INTPTR_BINOP(Int, SubWithOverflow);
486  INTPTR_BINOP(Int, Mul);
487  INTPTR_BINOP(Int, Div);
488  INTPTR_BINOP(Int, LessThan);
489  INTPTR_BINOP(Int, LessThanOrEqual);
490  INTPTR_BINOP(Word, Equal);
491  INTPTR_BINOP(Word, NotEqual);
492  INTPTR_BINOP(Int, GreaterThanOrEqual);
493  INTPTR_BINOP(Int, GreaterThan);
494 
495 #undef INTPTR_BINOP
496 
497 #define UINTPTR_BINOP(prefix, name) \
498  Node* UintPtr##name(Node* a, Node* b) { \
499  return kPointerSize == 8 ? prefix##64##name(a, b) \
500  : prefix##32##name(a, b); \
501  }
502 
503  UINTPTR_BINOP(Uint, LessThan);
504  UINTPTR_BINOP(Uint, LessThanOrEqual);
505  UINTPTR_BINOP(Uint, GreaterThanOrEqual);
506  UINTPTR_BINOP(Uint, GreaterThan);
507 
508 #undef UINTPTR_BINOP
509 
510  Node* Int32AbsWithOverflow(Node* a) {
511  return AddNode(machine()->Int32AbsWithOverflow().op(), a);
512  }
513 
514  Node* Int64AbsWithOverflow(Node* a) {
515  return AddNode(machine()->Int64AbsWithOverflow().op(), a);
516  }
517 
518  Node* IntPtrAbsWithOverflow(Node* a) {
519  return kPointerSize == 8 ? Int64AbsWithOverflow(a)
520  : Int32AbsWithOverflow(a);
521  }
522 
523  Node* Float32Add(Node* a, Node* b) {
524  return AddNode(machine()->Float32Add(), a, b);
525  }
526  Node* Float32Sub(Node* a, Node* b) {
527  return AddNode(machine()->Float32Sub(), a, b);
528  }
529  Node* Float32Mul(Node* a, Node* b) {
530  return AddNode(machine()->Float32Mul(), a, b);
531  }
532  Node* Float32Div(Node* a, Node* b) {
533  return AddNode(machine()->Float32Div(), a, b);
534  }
535  Node* Float32Abs(Node* a) { return AddNode(machine()->Float32Abs(), a); }
536  Node* Float32Neg(Node* a) { return AddNode(machine()->Float32Neg(), a); }
537  Node* Float32Sqrt(Node* a) { return AddNode(machine()->Float32Sqrt(), a); }
538  Node* Float32Equal(Node* a, Node* b) {
539  return AddNode(machine()->Float32Equal(), a, b);
540  }
541  Node* Float32NotEqual(Node* a, Node* b) {
542  return Word32BinaryNot(Float32Equal(a, b));
543  }
544  Node* Float32LessThan(Node* a, Node* b) {
545  return AddNode(machine()->Float32LessThan(), a, b);
546  }
547  Node* Float32LessThanOrEqual(Node* a, Node* b) {
548  return AddNode(machine()->Float32LessThanOrEqual(), a, b);
549  }
550  Node* Float32GreaterThan(Node* a, Node* b) { return Float32LessThan(b, a); }
551  Node* Float32GreaterThanOrEqual(Node* a, Node* b) {
552  return Float32LessThanOrEqual(b, a);
553  }
554  Node* Float32Max(Node* a, Node* b) {
555  return AddNode(machine()->Float32Max(), a, b);
556  }
557  Node* Float32Min(Node* a, Node* b) {
558  return AddNode(machine()->Float32Min(), a, b);
559  }
560  Node* Float64Add(Node* a, Node* b) {
561  return AddNode(machine()->Float64Add(), a, b);
562  }
563  Node* Float64Sub(Node* a, Node* b) {
564  return AddNode(machine()->Float64Sub(), a, b);
565  }
566  Node* Float64Mul(Node* a, Node* b) {
567  return AddNode(machine()->Float64Mul(), a, b);
568  }
569  Node* Float64Div(Node* a, Node* b) {
570  return AddNode(machine()->Float64Div(), a, b);
571  }
572  Node* Float64Mod(Node* a, Node* b) {
573  return AddNode(machine()->Float64Mod(), a, b);
574  }
575  Node* Float64Max(Node* a, Node* b) {
576  return AddNode(machine()->Float64Max(), a, b);
577  }
578  Node* Float64Min(Node* a, Node* b) {
579  return AddNode(machine()->Float64Min(), a, b);
580  }
581  Node* Float64Abs(Node* a) { return AddNode(machine()->Float64Abs(), a); }
582  Node* Float64Neg(Node* a) { return AddNode(machine()->Float64Neg(), a); }
583  Node* Float64Acos(Node* a) { return AddNode(machine()->Float64Acos(), a); }
584  Node* Float64Acosh(Node* a) { return AddNode(machine()->Float64Acosh(), a); }
585  Node* Float64Asin(Node* a) { return AddNode(machine()->Float64Asin(), a); }
586  Node* Float64Asinh(Node* a) { return AddNode(machine()->Float64Asinh(), a); }
587  Node* Float64Atan(Node* a) { return AddNode(machine()->Float64Atan(), a); }
588  Node* Float64Atanh(Node* a) { return AddNode(machine()->Float64Atanh(), a); }
589  Node* Float64Atan2(Node* a, Node* b) {
590  return AddNode(machine()->Float64Atan2(), a, b);
591  }
592  Node* Float64Cbrt(Node* a) { return AddNode(machine()->Float64Cbrt(), a); }
593  Node* Float64Cos(Node* a) { return AddNode(machine()->Float64Cos(), a); }
594  Node* Float64Cosh(Node* a) { return AddNode(machine()->Float64Cosh(), a); }
595  Node* Float64Exp(Node* a) { return AddNode(machine()->Float64Exp(), a); }
596  Node* Float64Expm1(Node* a) { return AddNode(machine()->Float64Expm1(), a); }
597  Node* Float64Log(Node* a) { return AddNode(machine()->Float64Log(), a); }
598  Node* Float64Log1p(Node* a) { return AddNode(machine()->Float64Log1p(), a); }
599  Node* Float64Log10(Node* a) { return AddNode(machine()->Float64Log10(), a); }
600  Node* Float64Log2(Node* a) { return AddNode(machine()->Float64Log2(), a); }
601  Node* Float64Pow(Node* a, Node* b) {
602  return AddNode(machine()->Float64Pow(), a, b);
603  }
604  Node* Float64Sin(Node* a) { return AddNode(machine()->Float64Sin(), a); }
605  Node* Float64Sinh(Node* a) { return AddNode(machine()->Float64Sinh(), a); }
606  Node* Float64Sqrt(Node* a) { return AddNode(machine()->Float64Sqrt(), a); }
607  Node* Float64Tan(Node* a) { return AddNode(machine()->Float64Tan(), a); }
608  Node* Float64Tanh(Node* a) { return AddNode(machine()->Float64Tanh(), a); }
609  Node* Float64Equal(Node* a, Node* b) {
610  return AddNode(machine()->Float64Equal(), a, b);
611  }
612  Node* Float64NotEqual(Node* a, Node* b) {
613  return Word32BinaryNot(Float64Equal(a, b));
614  }
615  Node* Float64LessThan(Node* a, Node* b) {
616  return AddNode(machine()->Float64LessThan(), a, b);
617  }
618  Node* Float64LessThanOrEqual(Node* a, Node* b) {
619  return AddNode(machine()->Float64LessThanOrEqual(), a, b);
620  }
621  Node* Float64GreaterThan(Node* a, Node* b) { return Float64LessThan(b, a); }
622  Node* Float64GreaterThanOrEqual(Node* a, Node* b) {
623  return Float64LessThanOrEqual(b, a);
624  }
625 
626  // Conversions.
627  Node* BitcastTaggedToWord(Node* a) {
628  if (FLAG_verify_csa || FLAG_optimize_csa) {
629  return AddNode(machine()->BitcastTaggedToWord(), a);
630  }
631  return a;
632  }
633  Node* BitcastMaybeObjectToWord(Node* a) {
634  if (FLAG_verify_csa || FLAG_optimize_csa) {
635  return AddNode(machine()->BitcastMaybeObjectToWord(), a);
636  }
637  return a;
638  }
639  Node* BitcastWordToTagged(Node* a) {
640  return AddNode(machine()->BitcastWordToTagged(), a);
641  }
642  Node* BitcastWordToTaggedSigned(Node* a) {
643  if (FLAG_verify_csa || FLAG_optimize_csa) {
644  return AddNode(machine()->BitcastWordToTaggedSigned(), a);
645  }
646  return a;
647  }
648  Node* TruncateFloat64ToWord32(Node* a) {
649  return AddNode(machine()->TruncateFloat64ToWord32(), a);
650  }
651  Node* ChangeFloat32ToFloat64(Node* a) {
652  return AddNode(machine()->ChangeFloat32ToFloat64(), a);
653  }
654  Node* ChangeInt32ToFloat64(Node* a) {
655  return AddNode(machine()->ChangeInt32ToFloat64(), a);
656  }
657  Node* ChangeInt64ToFloat64(Node* a) {
658  return AddNode(machine()->ChangeInt64ToFloat64(), a);
659  }
660  Node* ChangeUint32ToFloat64(Node* a) {
661  return AddNode(machine()->ChangeUint32ToFloat64(), a);
662  }
663  Node* ChangeFloat64ToInt32(Node* a) {
664  return AddNode(machine()->ChangeFloat64ToInt32(), a);
665  }
666  Node* ChangeFloat64ToInt64(Node* a) {
667  return AddNode(machine()->ChangeFloat64ToInt64(), a);
668  }
669  Node* ChangeFloat64ToUint32(Node* a) {
670  return AddNode(machine()->ChangeFloat64ToUint32(), a);
671  }
672  Node* ChangeFloat64ToUint64(Node* a) {
673  return AddNode(machine()->ChangeFloat64ToUint64(), a);
674  }
675  Node* TruncateFloat64ToUint32(Node* a) {
676  return AddNode(machine()->TruncateFloat64ToUint32(), a);
677  }
678  Node* TruncateFloat32ToInt32(Node* a) {
679  return AddNode(machine()->TruncateFloat32ToInt32(), a);
680  }
681  Node* TruncateFloat32ToUint32(Node* a) {
682  return AddNode(machine()->TruncateFloat32ToUint32(), a);
683  }
684  Node* TryTruncateFloat32ToInt64(Node* a) {
685  return AddNode(machine()->TryTruncateFloat32ToInt64(), a);
686  }
687  Node* TryTruncateFloat64ToInt64(Node* a) {
688  return AddNode(machine()->TryTruncateFloat64ToInt64(), a);
689  }
690  Node* TryTruncateFloat32ToUint64(Node* a) {
691  return AddNode(machine()->TryTruncateFloat32ToUint64(), a);
692  }
693  Node* TryTruncateFloat64ToUint64(Node* a) {
694  return AddNode(machine()->TryTruncateFloat64ToUint64(), a);
695  }
696  Node* ChangeInt32ToInt64(Node* a) {
697  return AddNode(machine()->ChangeInt32ToInt64(), a);
698  }
699  Node* ChangeUint32ToUint64(Node* a) {
700  return AddNode(machine()->ChangeUint32ToUint64(), a);
701  }
702  Node* TruncateFloat64ToFloat32(Node* a) {
703  return AddNode(machine()->TruncateFloat64ToFloat32(), a);
704  }
705  Node* TruncateInt64ToInt32(Node* a) {
706  return AddNode(machine()->TruncateInt64ToInt32(), a);
707  }
708  Node* RoundFloat64ToInt32(Node* a) {
709  return AddNode(machine()->RoundFloat64ToInt32(), a);
710  }
711  Node* RoundInt32ToFloat32(Node* a) {
712  return AddNode(machine()->RoundInt32ToFloat32(), a);
713  }
714  Node* RoundInt64ToFloat32(Node* a) {
715  return AddNode(machine()->RoundInt64ToFloat32(), a);
716  }
717  Node* RoundInt64ToFloat64(Node* a) {
718  return AddNode(machine()->RoundInt64ToFloat64(), a);
719  }
720  Node* RoundUint32ToFloat32(Node* a) {
721  return AddNode(machine()->RoundUint32ToFloat32(), a);
722  }
723  Node* RoundUint64ToFloat32(Node* a) {
724  return AddNode(machine()->RoundUint64ToFloat32(), a);
725  }
726  Node* RoundUint64ToFloat64(Node* a) {
727  return AddNode(machine()->RoundUint64ToFloat64(), a);
728  }
729  Node* BitcastFloat32ToInt32(Node* a) {
730  return AddNode(machine()->BitcastFloat32ToInt32(), a);
731  }
732  Node* BitcastFloat64ToInt64(Node* a) {
733  return AddNode(machine()->BitcastFloat64ToInt64(), a);
734  }
735  Node* BitcastInt32ToFloat32(Node* a) {
736  return AddNode(machine()->BitcastInt32ToFloat32(), a);
737  }
738  Node* BitcastInt64ToFloat64(Node* a) {
739  return AddNode(machine()->BitcastInt64ToFloat64(), a);
740  }
741  Node* Float32RoundDown(Node* a) {
742  return AddNode(machine()->Float32RoundDown().op(), a);
743  }
744  Node* Float64RoundDown(Node* a) {
745  return AddNode(machine()->Float64RoundDown().op(), a);
746  }
747  Node* Float32RoundUp(Node* a) {
748  return AddNode(machine()->Float32RoundUp().op(), a);
749  }
750  Node* Float64RoundUp(Node* a) {
751  return AddNode(machine()->Float64RoundUp().op(), a);
752  }
753  Node* Float32RoundTruncate(Node* a) {
754  return AddNode(machine()->Float32RoundTruncate().op(), a);
755  }
756  Node* Float64RoundTruncate(Node* a) {
757  return AddNode(machine()->Float64RoundTruncate().op(), a);
758  }
759  Node* Float64RoundTiesAway(Node* a) {
760  return AddNode(machine()->Float64RoundTiesAway().op(), a);
761  }
762  Node* Float32RoundTiesEven(Node* a) {
763  return AddNode(machine()->Float32RoundTiesEven().op(), a);
764  }
765  Node* Float64RoundTiesEven(Node* a) {
766  return AddNode(machine()->Float64RoundTiesEven().op(), a);
767  }
768  Node* Word32ReverseBytes(Node* a) {
769  return AddNode(machine()->Word32ReverseBytes(), a);
770  }
771  Node* Word64ReverseBytes(Node* a) {
772  return AddNode(machine()->Word64ReverseBytes(), a);
773  }
774 
775  // Float64 bit operations.
776  Node* Float64ExtractLowWord32(Node* a) {
777  return AddNode(machine()->Float64ExtractLowWord32(), a);
778  }
779  Node* Float64ExtractHighWord32(Node* a) {
780  return AddNode(machine()->Float64ExtractHighWord32(), a);
781  }
782  Node* Float64InsertLowWord32(Node* a, Node* b) {
783  return AddNode(machine()->Float64InsertLowWord32(), a, b);
784  }
785  Node* Float64InsertHighWord32(Node* a, Node* b) {
786  return AddNode(machine()->Float64InsertHighWord32(), a, b);
787  }
788  Node* Float64SilenceNaN(Node* a) {
789  return AddNode(machine()->Float64SilenceNaN(), a);
790  }
791 
792  // Stack operations.
793  Node* LoadStackPointer() { return AddNode(machine()->LoadStackPointer()); }
794  Node* LoadFramePointer() { return AddNode(machine()->LoadFramePointer()); }
795  Node* LoadParentFramePointer() {
796  return AddNode(machine()->LoadParentFramePointer());
797  }
798 
799  // Parameters.
800  Node* TargetParameter();
801  Node* Parameter(size_t index);
802 
803  // Pointer utilities.
804  Node* LoadFromPointer(void* address, MachineType rep, int32_t offset = 0) {
805  return Load(rep, PointerConstant(address), Int32Constant(offset));
806  }
807  Node* StoreToPointer(void* address, MachineRepresentation rep, Node* node) {
808  return Store(rep, PointerConstant(address), node, kNoWriteBarrier);
809  }
810  Node* UnalignedLoadFromPointer(void* address, MachineType rep,
811  int32_t offset = 0) {
812  return UnalignedLoad(rep, PointerConstant(address), Int32Constant(offset));
813  }
814  Node* UnalignedStoreToPointer(void* address, MachineRepresentation rep,
815  Node* node) {
816  return UnalignedStore(rep, PointerConstant(address), node);
817  }
818  Node* StringConstant(const char* string) {
819  return HeapConstant(isolate()->factory()->InternalizeUtf8String(string));
820  }
821 
822  Node* TaggedPoisonOnSpeculation(Node* value) {
823  if (poisoning_level_ != PoisoningMitigationLevel::kDontPoison) {
824  return AddNode(machine()->TaggedPoisonOnSpeculation(), value);
825  }
826  return value;
827  }
828 
829  Node* WordPoisonOnSpeculation(Node* value) {
830  if (poisoning_level_ != PoisoningMitigationLevel::kDontPoison) {
831  return AddNode(machine()->WordPoisonOnSpeculation(), value);
832  }
833  return value;
834  }
835 
836  // Call a given call descriptor and the given arguments.
837  // The call target is passed as part of the {inputs} array.
838  Node* CallN(CallDescriptor* call_descriptor, int input_count,
839  Node* const* inputs);
840 
841  // Call a given call descriptor and the given arguments and frame-state.
842  // The call target and frame state are passed as part of the {inputs} array.
843  Node* CallNWithFrameState(CallDescriptor* call_descriptor, int input_count,
844  Node* const* inputs);
845 
846  // Tail call a given call descriptor and the given arguments.
847  // The call target is passed as part of the {inputs} array.
848  Node* TailCallN(CallDescriptor* call_descriptor, int input_count,
849  Node* const* inputs);
850 
851  // Call to a C function with zero arguments.
852  Node* CallCFunction0(MachineType return_type, Node* function);
853  // Call to a C function with one parameter.
854  Node* CallCFunction1(MachineType return_type, MachineType arg0_type,
855  Node* function, Node* arg0);
856  // Call to a C function with one argument, while saving/restoring caller
857  // registers.
858  Node* CallCFunction1WithCallerSavedRegisters(
859  MachineType return_type, MachineType arg0_type, Node* function,
860  Node* arg0, SaveFPRegsMode mode = kSaveFPRegs);
861  // Call to a C function with two arguments.
862  Node* CallCFunction2(MachineType return_type, MachineType arg0_type,
863  MachineType arg1_type, Node* function, Node* arg0,
864  Node* arg1);
865  // Call to a C function with three arguments.
866  Node* CallCFunction3(MachineType return_type, MachineType arg0_type,
867  MachineType arg1_type, MachineType arg2_type,
868  Node* function, Node* arg0, Node* arg1, Node* arg2);
869  // Call to a C function with three arguments, while saving/restoring caller
870  // registers.
871  Node* CallCFunction3WithCallerSavedRegisters(
872  MachineType return_type, MachineType arg0_type, MachineType arg1_type,
873  MachineType arg2_type, Node* function, Node* arg0, Node* arg1, Node* arg2,
874  SaveFPRegsMode mode = kSaveFPRegs);
875  // Call to a C function with four arguments.
876  Node* CallCFunction4(MachineType return_type, MachineType arg0_type,
877  MachineType arg1_type, MachineType arg2_type,
878  MachineType arg3_type, Node* function, Node* arg0,
879  Node* arg1, Node* arg2, Node* arg3);
880  // Call to a C function with five arguments.
881  Node* CallCFunction5(MachineType return_type, MachineType arg0_type,
882  MachineType arg1_type, MachineType arg2_type,
883  MachineType arg3_type, MachineType arg4_type,
884  Node* function, Node* arg0, Node* arg1, Node* arg2,
885  Node* arg3, Node* arg4);
886  // Call to a C function with six arguments.
887  Node* CallCFunction6(MachineType return_type, MachineType arg0_type,
888  MachineType arg1_type, MachineType arg2_type,
889  MachineType arg3_type, MachineType arg4_type,
890  MachineType arg5_type, Node* function, Node* arg0,
891  Node* arg1, Node* arg2, Node* arg3, Node* arg4,
892  Node* arg5);
893  // Call to a C function with eight arguments.
894  Node* CallCFunction8(MachineType return_type, MachineType arg0_type,
895  MachineType arg1_type, MachineType arg2_type,
896  MachineType arg3_type, MachineType arg4_type,
897  MachineType arg5_type, MachineType arg6_type,
898  MachineType arg7_type, Node* function, Node* arg0,
899  Node* arg1, Node* arg2, Node* arg3, Node* arg4,
900  Node* arg5, Node* arg6, Node* arg7);
901  // Call to a C function with nine arguments.
902  Node* CallCFunction9(MachineType return_type, MachineType arg0_type,
903  MachineType arg1_type, MachineType arg2_type,
904  MachineType arg3_type, MachineType arg4_type,
905  MachineType arg5_type, MachineType arg6_type,
906  MachineType arg7_type, MachineType arg8_type,
907  Node* function, Node* arg0, Node* arg1, Node* arg2,
908  Node* arg3, Node* arg4, Node* arg5, Node* arg6,
909  Node* arg7, Node* arg8);
910 
911  // ===========================================================================
912  // The following utility methods deal with control flow, hence might switch
913  // the current basic block or create new basic blocks for labels.
914 
915  // Control flow.
916  void Goto(RawMachineLabel* label);
917  void Branch(Node* condition, RawMachineLabel* true_val,
918  RawMachineLabel* false_val);
919  void Switch(Node* index, RawMachineLabel* default_label,
920  const int32_t* case_values, RawMachineLabel** case_labels,
921  size_t case_count);
922  void Return(Node* value);
923  void Return(Node* v1, Node* v2);
924  void Return(Node* v1, Node* v2, Node* v3);
925  void Return(Node* v1, Node* v2, Node* v3, Node* v4);
926  void Return(int count, Node* v[]);
927  void PopAndReturn(Node* pop, Node* value);
928  void PopAndReturn(Node* pop, Node* v1, Node* v2);
929  void PopAndReturn(Node* pop, Node* v1, Node* v2, Node* v3);
930  void PopAndReturn(Node* pop, Node* v1, Node* v2, Node* v3, Node* v4);
931  void Bind(RawMachineLabel* label);
932  void Deoptimize(Node* state);
933  void DebugAbort(Node* message);
934  void DebugBreak();
935  void Unreachable();
936  void Comment(const char* msg);
937 
938 #if DEBUG
939  void Bind(RawMachineLabel* label, AssemblerDebugInfo info);
940  void SetInitialDebugInformation(AssemblerDebugInfo info);
941  void PrintCurrentBlock(std::ostream& os);
942 #endif // DEBUG
943  bool InsideBlock();
944 
945  // Add success / exception successor blocks and ends the current block ending
946  // in a potentially throwing call node.
947  void Continuations(Node* call, RawMachineLabel* if_success,
948  RawMachineLabel* if_exception);
949 
950  // Variables.
951  Node* Phi(MachineRepresentation rep, Node* n1, Node* n2) {
952  return AddNode(common()->Phi(rep, 2), n1, n2, graph()->start());
953  }
954  Node* Phi(MachineRepresentation rep, Node* n1, Node* n2, Node* n3) {
955  return AddNode(common()->Phi(rep, 3), n1, n2, n3, graph()->start());
956  }
957  Node* Phi(MachineRepresentation rep, Node* n1, Node* n2, Node* n3, Node* n4) {
958  return AddNode(common()->Phi(rep, 4), n1, n2, n3, n4, graph()->start());
959  }
960  Node* Phi(MachineRepresentation rep, int input_count, Node* const* inputs);
961  void AppendPhiInput(Node* phi, Node* new_input);
962 
963  // ===========================================================================
964  // The following generic node creation methods can be used for operators that
965  // are not covered by the above utility methods. There should rarely be a need
966  // to do that outside of testing though.
967 
968  Node* AddNode(const Operator* op, int input_count, Node* const* inputs);
969 
970  Node* AddNode(const Operator* op) {
971  return AddNode(op, 0, static_cast<Node* const*>(nullptr));
972  }
973 
974  template <class... TArgs>
975  Node* AddNode(const Operator* op, Node* n1, TArgs... args) {
976  Node* buffer[] = {n1, args...};
977  return AddNode(op, sizeof...(args) + 1, buffer);
978  }
979 
980  private:
981  Node* MakeNode(const Operator* op, int input_count, Node* const* inputs);
982  BasicBlock* Use(RawMachineLabel* label);
983  BasicBlock* EnsureBlock(RawMachineLabel* label);
984  BasicBlock* CurrentBlock();
985 
986  // A post-processing pass to add effect and control edges so that the graph
987  // can be optimized and re-scheduled.
988  // TODO(tebbi): Move this to a separate class.
989  void MakeReschedulable();
990  Node* CreateNodeFromPredecessors(const std::vector<BasicBlock*>& predecessors,
991  const std::vector<Node*>& sidetable,
992  const Operator* op,
993  const std::vector<Node*>& additional_inputs);
994  void MakePhiBinary(Node* phi, int split_point, Node* left_control,
995  Node* right_control);
996  void MarkControlDeferred(Node* control_input);
997 
998  Schedule* schedule() { return schedule_; }
999  size_t parameter_count() const { return call_descriptor_->ParameterCount(); }
1000 
1001  Isolate* isolate_;
1002  Graph* graph_;
1003  Schedule* schedule_;
1004  MachineOperatorBuilder machine_;
1005  CommonOperatorBuilder common_;
1006  CallDescriptor* call_descriptor_;
1007  Node* target_parameter_;
1008  NodeVector parameters_;
1009  BasicBlock* current_block_;
1010  PoisoningMitigationLevel poisoning_level_;
1011 
1012  DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler);
1013 };
1014 
1015 class V8_EXPORT_PRIVATE RawMachineLabel final {
1016  public:
1017  enum Type { kDeferred, kNonDeferred };
1018 
1019  explicit RawMachineLabel(Type type = kNonDeferred)
1020  : deferred_(type == kDeferred) {}
1021  ~RawMachineLabel();
1022 
1023  BasicBlock* block() const { return block_; }
1024 
1025  private:
1026  BasicBlock* block_ = nullptr;
1027  bool used_ = false;
1028  bool bound_ = false;
1029  bool deferred_;
1030  friend class RawMachineAssembler;
1031  DISALLOW_COPY_AND_ASSIGN(RawMachineLabel);
1032 };
1033 
1034 } // namespace compiler
1035 } // namespace internal
1036 } // namespace v8
1037 
1038 #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_
Definition: libplatform.h:13