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 #include "src/compiler/common-operator.h"
6 
7 #include "src/base/lazy-instance.h"
8 #include "src/compiler/linkage.h"
9 #include "src/compiler/node.h"
10 #include "src/compiler/opcodes.h"
11 #include "src/compiler/operator.h"
12 #include "src/handles/handles-inl.h"
13 #include "src/zone/zone.h"
14 
15 namespace v8 {
16 namespace internal {
17 namespace compiler {
18 
operator <<(std::ostream & os,BranchHint hint)19 std::ostream& operator<<(std::ostream& os, BranchHint hint) {
20   switch (hint) {
21     case BranchHint::kNone:
22       return os << "None";
23     case BranchHint::kTrue:
24       return os << "True";
25     case BranchHint::kFalse:
26       return os << "False";
27   }
28   UNREACHABLE();
29 }
30 
operator <<(std::ostream & os,TrapId trap_id)31 std::ostream& operator<<(std::ostream& os, TrapId trap_id) {
32   switch (trap_id) {
33 #define TRAP_CASE(Name) \
34   case TrapId::k##Name: \
35     return os << #Name;
36     FOREACH_WASM_TRAPREASON(TRAP_CASE)
37 #undef TRAP_CASE
38     case TrapId::kInvalid:
39       return os << "Invalid";
40   }
41   UNREACHABLE();
42 }
43 
TrapIdOf(const Operator * const op)44 TrapId TrapIdOf(const Operator* const op) {
45   DCHECK(op->opcode() == IrOpcode::kTrapIf ||
46          op->opcode() == IrOpcode::kTrapUnless);
47   return OpParameter<TrapId>(op);
48 }
49 
BranchHintOf(const Operator * const op)50 BranchHint BranchHintOf(const Operator* const op) {
51   switch (op->opcode()) {
52     case IrOpcode::kIfValue:
53       return IfValueParametersOf(op).hint();
54     case IrOpcode::kIfDefault:
55     case IrOpcode::kBranch:
56       return OpParameter<BranchHint>(op);
57     default:
58       UNREACHABLE();
59   }
60 }
61 
ValueInputCountOfReturn(Operator const * const op)62 int ValueInputCountOfReturn(Operator const* const op) {
63   DCHECK_EQ(IrOpcode::kReturn, op->opcode());
64   // Return nodes have a hidden input at index 0 which we ignore in the value
65   // input count.
66   return op->ValueInputCount() - 1;
67 }
68 
operator ==(DeoptimizeParameters lhs,DeoptimizeParameters rhs)69 bool operator==(DeoptimizeParameters lhs, DeoptimizeParameters rhs) {
70   return lhs.kind() == rhs.kind() && lhs.reason() == rhs.reason() &&
71          lhs.feedback() == rhs.feedback();
72 }
73 
operator !=(DeoptimizeParameters lhs,DeoptimizeParameters rhs)74 bool operator!=(DeoptimizeParameters lhs, DeoptimizeParameters rhs) {
75   return !(lhs == rhs);
76 }
77 
hash_value(DeoptimizeParameters p)78 size_t hash_value(DeoptimizeParameters p) {
79   FeedbackSource::Hash feebdack_hash;
80   return base::hash_combine(p.kind(), p.reason(), feebdack_hash(p.feedback()));
81 }
82 
operator <<(std::ostream & os,DeoptimizeParameters p)83 std::ostream& operator<<(std::ostream& os, DeoptimizeParameters p) {
84   return os << p.kind() << ", " << p.reason() << ", " << p.feedback();
85 }
86 
DeoptimizeParametersOf(Operator const * const op)87 DeoptimizeParameters const& DeoptimizeParametersOf(Operator const* const op) {
88   DCHECK(op->opcode() == IrOpcode::kDeoptimize ||
89          op->opcode() == IrOpcode::kDeoptimizeIf ||
90          op->opcode() == IrOpcode::kDeoptimizeUnless ||
91          op->opcode() == IrOpcode::kDynamicCheckMapsWithDeoptUnless);
92   return OpParameter<DeoptimizeParameters>(op);
93 }
94 
DelayedStringConstant(const StringConstantBase * str)95 const Operator* CommonOperatorBuilder::DelayedStringConstant(
96     const StringConstantBase* str) {
97   return zone()->New<Operator1<const StringConstantBase*>>(
98       IrOpcode::kDelayedStringConstant, Operator::kPure,
99       "DelayedStringConstant", 0, 0, 0, 1, 0, 0, str);
100 }
101 
operator ==(SelectParameters const & lhs,SelectParameters const & rhs)102 bool operator==(SelectParameters const& lhs, SelectParameters const& rhs) {
103   return lhs.representation() == rhs.representation() &&
104          lhs.hint() == rhs.hint();
105 }
106 
107 
operator !=(SelectParameters const & lhs,SelectParameters const & rhs)108 bool operator!=(SelectParameters const& lhs, SelectParameters const& rhs) {
109   return !(lhs == rhs);
110 }
111 
112 
hash_value(SelectParameters const & p)113 size_t hash_value(SelectParameters const& p) {
114   return base::hash_combine(p.representation(), p.hint());
115 }
116 
117 
operator <<(std::ostream & os,SelectParameters const & p)118 std::ostream& operator<<(std::ostream& os, SelectParameters const& p) {
119   return os << p.representation() << ", " << p.hint();
120 }
121 
122 
SelectParametersOf(const Operator * const op)123 SelectParameters const& SelectParametersOf(const Operator* const op) {
124   DCHECK_EQ(IrOpcode::kSelect, op->opcode());
125   return OpParameter<SelectParameters>(op);
126 }
127 
CallDescriptorOf(const Operator * const op)128 CallDescriptor const* CallDescriptorOf(const Operator* const op) {
129   DCHECK(op->opcode() == IrOpcode::kCall ||
130          op->opcode() == IrOpcode::kTailCall);
131   return OpParameter<CallDescriptor const*>(op);
132 }
133 
ProjectionIndexOf(const Operator * const op)134 size_t ProjectionIndexOf(const Operator* const op) {
135   DCHECK_EQ(IrOpcode::kProjection, op->opcode());
136   return OpParameter<size_t>(op);
137 }
138 
139 
PhiRepresentationOf(const Operator * const op)140 MachineRepresentation PhiRepresentationOf(const Operator* const op) {
141   DCHECK_EQ(IrOpcode::kPhi, op->opcode());
142   return OpParameter<MachineRepresentation>(op);
143 }
144 
LoopExitValueRepresentationOf(const Operator * const op)145 MachineRepresentation LoopExitValueRepresentationOf(const Operator* const op) {
146   DCHECK_EQ(IrOpcode::kLoopExitValue, op->opcode());
147   return OpParameter<MachineRepresentation>(op);
148 }
149 
ParameterIndexOf(const Operator * const op)150 int ParameterIndexOf(const Operator* const op) {
151   DCHECK_EQ(IrOpcode::kParameter, op->opcode());
152   return OpParameter<ParameterInfo>(op).index();
153 }
154 
155 
ParameterInfoOf(const Operator * const op)156 const ParameterInfo& ParameterInfoOf(const Operator* const op) {
157   DCHECK_EQ(IrOpcode::kParameter, op->opcode());
158   return OpParameter<ParameterInfo>(op);
159 }
160 
161 
operator ==(ParameterInfo const & lhs,ParameterInfo const & rhs)162 bool operator==(ParameterInfo const& lhs, ParameterInfo const& rhs) {
163   return lhs.index() == rhs.index();
164 }
165 
166 
operator !=(ParameterInfo const & lhs,ParameterInfo const & rhs)167 bool operator!=(ParameterInfo const& lhs, ParameterInfo const& rhs) {
168   return !(lhs == rhs);
169 }
170 
171 
hash_value(ParameterInfo const & p)172 size_t hash_value(ParameterInfo const& p) { return p.index(); }
173 
174 
operator <<(std::ostream & os,ParameterInfo const & i)175 std::ostream& operator<<(std::ostream& os, ParameterInfo const& i) {
176   os << i.index();
177   if (i.debug_name()) os << ", debug name: " << i.debug_name();
178   return os;
179 }
180 
operator <<(std::ostream & os,ObjectStateInfo const & i)181 std::ostream& operator<<(std::ostream& os, ObjectStateInfo const& i) {
182   return os << "id:" << i.object_id() << ", size:" << i.size();
183 }
184 
hash_value(ObjectStateInfo const & p)185 size_t hash_value(ObjectStateInfo const& p) {
186   return base::hash_combine(p.object_id(), p.size());
187 }
188 
operator <<(std::ostream & os,TypedObjectStateInfo const & i)189 std::ostream& operator<<(std::ostream& os, TypedObjectStateInfo const& i) {
190   return os << "id:" << i.object_id() << ", " << i.machine_types();
191 }
192 
hash_value(TypedObjectStateInfo const & p)193 size_t hash_value(TypedObjectStateInfo const& p) {
194   return base::hash_combine(p.object_id(), p.machine_types());
195 }
196 
operator ==(RelocatablePtrConstantInfo const & lhs,RelocatablePtrConstantInfo const & rhs)197 bool operator==(RelocatablePtrConstantInfo const& lhs,
198                 RelocatablePtrConstantInfo const& rhs) {
199   return lhs.rmode() == rhs.rmode() && lhs.value() == rhs.value() &&
200          lhs.type() == rhs.type();
201 }
202 
operator !=(RelocatablePtrConstantInfo const & lhs,RelocatablePtrConstantInfo const & rhs)203 bool operator!=(RelocatablePtrConstantInfo const& lhs,
204                 RelocatablePtrConstantInfo const& rhs) {
205   return !(lhs == rhs);
206 }
207 
hash_value(RelocatablePtrConstantInfo const & p)208 size_t hash_value(RelocatablePtrConstantInfo const& p) {
209   return base::hash_combine(p.value(), int8_t{p.rmode()}, p.type());
210 }
211 
operator <<(std::ostream & os,RelocatablePtrConstantInfo const & p)212 std::ostream& operator<<(std::ostream& os,
213                          RelocatablePtrConstantInfo const& p) {
214   return os << p.value() << ", " << static_cast<int>(p.rmode()) << ", "
215             << p.type();
216 }
217 
InputIterator(SparseInputMask::BitMaskType bit_mask,Node * parent)218 SparseInputMask::InputIterator::InputIterator(
219     SparseInputMask::BitMaskType bit_mask, Node* parent)
220     : bit_mask_(bit_mask), parent_(parent), real_index_(0) {
221 #if DEBUG
222   if (bit_mask_ != SparseInputMask::kDenseBitMask) {
223     DCHECK_EQ(base::bits::CountPopulation(bit_mask_) -
224                   base::bits::CountPopulation(kEndMarker),
225               parent->InputCount());
226   }
227 #endif
228 }
229 
Advance()230 void SparseInputMask::InputIterator::Advance() {
231   DCHECK(!IsEnd());
232 
233   if (IsReal()) {
234     ++real_index_;
235   }
236   bit_mask_ >>= 1;
237 }
238 
AdvanceToNextRealOrEnd()239 size_t SparseInputMask::InputIterator::AdvanceToNextRealOrEnd() {
240   DCHECK_NE(bit_mask_, SparseInputMask::kDenseBitMask);
241 
242   size_t count = base::bits::CountTrailingZeros(bit_mask_);
243   bit_mask_ >>= count;
244   DCHECK(IsReal() || IsEnd());
245   return count;
246 }
247 
GetReal() const248 Node* SparseInputMask::InputIterator::GetReal() const {
249   DCHECK(IsReal());
250   return parent_->InputAt(real_index_);
251 }
252 
IsReal() const253 bool SparseInputMask::InputIterator::IsReal() const {
254   return bit_mask_ == SparseInputMask::kDenseBitMask ||
255          (bit_mask_ & kEntryMask);
256 }
257 
IsEnd() const258 bool SparseInputMask::InputIterator::IsEnd() const {
259   return (bit_mask_ == kEndMarker) ||
260          (bit_mask_ == SparseInputMask::kDenseBitMask &&
261           real_index_ >= parent_->InputCount());
262 }
263 
CountReal() const264 int SparseInputMask::CountReal() const {
265   DCHECK(!IsDense());
266   return base::bits::CountPopulation(bit_mask_) -
267          base::bits::CountPopulation(kEndMarker);
268 }
269 
IterateOverInputs(Node * node)270 SparseInputMask::InputIterator SparseInputMask::IterateOverInputs(Node* node) {
271   DCHECK(IsDense() || CountReal() == node->InputCount());
272   return InputIterator(bit_mask_, node);
273 }
274 
operator ==(SparseInputMask const & lhs,SparseInputMask const & rhs)275 bool operator==(SparseInputMask const& lhs, SparseInputMask const& rhs) {
276   return lhs.mask() == rhs.mask();
277 }
278 
operator !=(SparseInputMask const & lhs,SparseInputMask const & rhs)279 bool operator!=(SparseInputMask const& lhs, SparseInputMask const& rhs) {
280   return !(lhs == rhs);
281 }
282 
hash_value(SparseInputMask const & p)283 size_t hash_value(SparseInputMask const& p) {
284   return base::hash_value(p.mask());
285 }
286 
operator <<(std::ostream & os,SparseInputMask const & p)287 std::ostream& operator<<(std::ostream& os, SparseInputMask const& p) {
288   if (p.IsDense()) {
289     return os << "dense";
290   } else {
291     SparseInputMask::BitMaskType mask = p.mask();
292     DCHECK_NE(mask, SparseInputMask::kDenseBitMask);
293 
294     os << "sparse:";
295 
296     while (mask != SparseInputMask::kEndMarker) {
297       if (mask & SparseInputMask::kEntryMask) {
298         os << "^";
299       } else {
300         os << ".";
301       }
302       mask >>= 1;
303     }
304     return os;
305   }
306 }
307 
operator ==(TypedStateValueInfo const & lhs,TypedStateValueInfo const & rhs)308 bool operator==(TypedStateValueInfo const& lhs,
309                 TypedStateValueInfo const& rhs) {
310   return lhs.machine_types() == rhs.machine_types() &&
311          lhs.sparse_input_mask() == rhs.sparse_input_mask();
312 }
313 
operator !=(TypedStateValueInfo const & lhs,TypedStateValueInfo const & rhs)314 bool operator!=(TypedStateValueInfo const& lhs,
315                 TypedStateValueInfo const& rhs) {
316   return !(lhs == rhs);
317 }
318 
hash_value(TypedStateValueInfo const & p)319 size_t hash_value(TypedStateValueInfo const& p) {
320   return base::hash_combine(p.machine_types(), p.sparse_input_mask());
321 }
322 
operator <<(std::ostream & os,TypedStateValueInfo const & p)323 std::ostream& operator<<(std::ostream& os, TypedStateValueInfo const& p) {
324   return os << p.machine_types() << ", " << p.sparse_input_mask();
325 }
326 
hash_value(RegionObservability observability)327 size_t hash_value(RegionObservability observability) {
328   return static_cast<size_t>(observability);
329 }
330 
operator <<(std::ostream & os,RegionObservability observability)331 std::ostream& operator<<(std::ostream& os, RegionObservability observability) {
332   switch (observability) {
333     case RegionObservability::kObservable:
334       return os << "observable";
335     case RegionObservability::kNotObservable:
336       return os << "not-observable";
337   }
338   UNREACHABLE();
339 }
340 
RegionObservabilityOf(Operator const * op)341 RegionObservability RegionObservabilityOf(Operator const* op) {
342   DCHECK_EQ(IrOpcode::kBeginRegion, op->opcode());
343   return OpParameter<RegionObservability>(op);
344 }
345 
TypeGuardTypeOf(Operator const * op)346 Type TypeGuardTypeOf(Operator const* op) {
347   DCHECK_EQ(IrOpcode::kTypeGuard, op->opcode());
348   return OpParameter<Type>(op);
349 }
350 
operator <<(std::ostream & os,const ZoneVector<MachineType> * types)351 std::ostream& operator<<(std::ostream& os,
352                          const ZoneVector<MachineType>* types) {
353   // Print all the MachineTypes, separated by commas.
354   bool first = true;
355   for (MachineType elem : *types) {
356     if (!first) {
357       os << ", ";
358     }
359     first = false;
360     os << elem;
361   }
362   return os;
363 }
364 
OsrValueIndexOf(Operator const * op)365 int OsrValueIndexOf(Operator const* op) {
366   DCHECK_EQ(IrOpcode::kOsrValue, op->opcode());
367   return OpParameter<int>(op);
368 }
369 
SparseInputMaskOf(Operator const * op)370 SparseInputMask SparseInputMaskOf(Operator const* op) {
371   DCHECK(op->opcode() == IrOpcode::kStateValues ||
372          op->opcode() == IrOpcode::kTypedStateValues);
373 
374   if (op->opcode() == IrOpcode::kTypedStateValues) {
375     return OpParameter<TypedStateValueInfo>(op).sparse_input_mask();
376   }
377   return OpParameter<SparseInputMask>(op);
378 }
379 
MachineTypesOf(Operator const * op)380 ZoneVector<MachineType> const* MachineTypesOf(Operator const* op) {
381   DCHECK(op->opcode() == IrOpcode::kTypedObjectState ||
382          op->opcode() == IrOpcode::kTypedStateValues);
383 
384   if (op->opcode() == IrOpcode::kTypedStateValues) {
385     return OpParameter<TypedStateValueInfo>(op).machine_types();
386   }
387   return OpParameter<TypedObjectStateInfo>(op).machine_types();
388 }
389 
operator ==(IfValueParameters const & l,IfValueParameters const & r)390 V8_EXPORT_PRIVATE bool operator==(IfValueParameters const& l,
391                                   IfValueParameters const& r) {
392   return l.value() == r.value() &&
393          l.comparison_order() == r.comparison_order() && l.hint() == r.hint();
394 }
395 
hash_value(IfValueParameters const & p)396 size_t hash_value(IfValueParameters const& p) {
397   return base::hash_combine(p.value(), p.comparison_order(), p.hint());
398 }
399 
operator <<(std::ostream & out,IfValueParameters const & p)400 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& out,
401                                            IfValueParameters const& p) {
402   out << p.value() << " (order " << p.comparison_order() << ", hint "
403       << p.hint() << ")";
404   return out;
405 }
406 
IfValueParametersOf(const Operator * op)407 IfValueParameters const& IfValueParametersOf(const Operator* op) {
408   DCHECK(op->opcode() == IrOpcode::kIfValue);
409   return OpParameter<IfValueParameters>(op);
410 }
411 
412 #define COMMON_CACHED_OP_LIST(V)                          \
413   V(Plug, Operator::kNoProperties, 0, 0, 0, 1, 0, 0)      \
414   V(Dead, Operator::kFoldable, 0, 0, 0, 1, 1, 1)          \
415   V(Unreachable, Operator::kFoldable, 0, 1, 1, 1, 1, 0)   \
416   V(IfTrue, Operator::kKontrol, 0, 0, 1, 0, 0, 1)         \
417   V(IfFalse, Operator::kKontrol, 0, 0, 1, 0, 0, 1)        \
418   V(IfSuccess, Operator::kKontrol, 0, 0, 1, 0, 0, 1)      \
419   V(IfException, Operator::kKontrol, 0, 1, 1, 1, 1, 1)    \
420   V(Throw, Operator::kKontrol, 0, 1, 1, 0, 0, 1)          \
421   V(Terminate, Operator::kKontrol, 0, 1, 1, 0, 0, 1)      \
422   V(LoopExit, Operator::kKontrol, 0, 0, 2, 0, 0, 1)       \
423   V(LoopExitEffect, Operator::kNoThrow, 0, 1, 1, 0, 1, 0) \
424   V(Checkpoint, Operator::kKontrol, 0, 1, 1, 0, 1, 0)     \
425   V(FinishRegion, Operator::kKontrol, 1, 1, 0, 1, 1, 0)   \
426   V(Retain, Operator::kKontrol, 1, 1, 0, 0, 1, 0)
427 
428 #define CACHED_LOOP_EXIT_VALUE_LIST(V) V(kTagged)
429 
430 #define CACHED_BRANCH_LIST(V) \
431   V(None)                     \
432   V(True)                     \
433   V(False)
434 
435 #define CACHED_RETURN_LIST(V) \
436   V(1)                        \
437   V(2)                        \
438   V(3)                        \
439   V(4)
440 
441 #define CACHED_END_LIST(V) \
442   V(1)                     \
443   V(2)                     \
444   V(3)                     \
445   V(4)                     \
446   V(5)                     \
447   V(6)                     \
448   V(7)                     \
449   V(8)
450 
451 
452 #define CACHED_EFFECT_PHI_LIST(V) \
453   V(1)                            \
454   V(2)                            \
455   V(3)                            \
456   V(4)                            \
457   V(5)                            \
458   V(6)
459 
460 #define CACHED_INDUCTION_VARIABLE_PHI_LIST(V) \
461   V(4)                                        \
462   V(5)                                        \
463   V(6)                                        \
464   V(7)
465 
466 #define CACHED_LOOP_LIST(V) \
467   V(1)                      \
468   V(2)
469 
470 
471 #define CACHED_MERGE_LIST(V) \
472   V(1)                       \
473   V(2)                       \
474   V(3)                       \
475   V(4)                       \
476   V(5)                       \
477   V(6)                       \
478   V(7)                       \
479   V(8)
480 
481 #define CACHED_DEOPTIMIZE_LIST(V)                        \
482   V(Eager, MinusZero)                                    \
483   V(Eager, WrongMap)                                     \
484   V(Soft, InsufficientTypeFeedbackForGenericKeyedAccess) \
485   V(Soft, InsufficientTypeFeedbackForGenericNamedAccess)
486 
487 #define CACHED_DEOPTIMIZE_IF_LIST(V) \
488   V(Eager, DivisionByZero)           \
489   V(Eager, Hole)                     \
490   V(Eager, MinusZero)                \
491   V(Eager, Overflow)                 \
492   V(Eager, Smi)
493 
494 #define CACHED_DEOPTIMIZE_UNLESS_LIST(V) \
495   V(Eager, LostPrecision)                \
496   V(Eager, LostPrecisionOrNaN)           \
497   V(Eager, NotAHeapNumber)               \
498   V(Eager, NotANumberOrOddball)          \
499   V(Eager, NotASmi)                      \
500   V(Eager, OutOfBounds)                  \
501   V(Eager, WrongInstanceType)            \
502   V(Eager, WrongMap)
503 
504 #define CACHED_DYNAMIC_CHECK_MAPS_LIST(V) \
505   V(DynamicCheckMaps)                     \
506   V(DynamicCheckMapsInlined)
507 
508 #define CACHED_TRAP_IF_LIST(V) \
509   V(TrapDivUnrepresentable)    \
510   V(TrapFloatUnrepresentable)
511 
512 // The reason for a trap.
513 #define CACHED_TRAP_UNLESS_LIST(V) \
514   V(TrapUnreachable)               \
515   V(TrapMemOutOfBounds)            \
516   V(TrapDivByZero)                 \
517   V(TrapDivUnrepresentable)        \
518   V(TrapRemByZero)                 \
519   V(TrapFloatUnrepresentable)      \
520   V(TrapTableOutOfBounds)          \
521   V(TrapFuncSigMismatch)
522 
523 #define CACHED_PARAMETER_LIST(V) \
524   V(0)                           \
525   V(1)                           \
526   V(2)                           \
527   V(3)                           \
528   V(4)                           \
529   V(5)                           \
530   V(6)
531 
532 
533 #define CACHED_PHI_LIST(V) \
534   V(kTagged, 1)            \
535   V(kTagged, 2)            \
536   V(kTagged, 3)            \
537   V(kTagged, 4)            \
538   V(kTagged, 5)            \
539   V(kTagged, 6)            \
540   V(kBit, 2)               \
541   V(kFloat64, 2)           \
542   V(kWord32, 2)
543 
544 
545 #define CACHED_PROJECTION_LIST(V) \
546   V(0)                            \
547   V(1)
548 
549 
550 #define CACHED_STATE_VALUES_LIST(V) \
551   V(0)                              \
552   V(1)                              \
553   V(2)                              \
554   V(3)                              \
555   V(4)                              \
556   V(5)                              \
557   V(6)                              \
558   V(7)                              \
559   V(8)                              \
560   V(10)                             \
561   V(11)                             \
562   V(12)                             \
563   V(13)                             \
564   V(14)
565 
566 
567 struct CommonOperatorGlobalCache final {
568 #define CACHED(Name, properties, value_input_count, effect_input_count,      \
569                control_input_count, value_output_count, effect_output_count, \
570                control_output_count)                                         \
571   struct Name##Operator final : public Operator {                            \
572     Name##Operator()                                                         \
573         : Operator(IrOpcode::k##Name, properties, #Name, value_input_count,  \
574                    effect_input_count, control_input_count,                  \
575                    value_output_count, effect_output_count,                  \
576                    control_output_count) {}                                  \
577   };                                                                         \
578   Name##Operator k##Name##Operator;
579   COMMON_CACHED_OP_LIST(CACHED)
580 #undef CACHED
581 
582   template <size_t kInputCount>
583   struct EndOperator final : public Operator {
EndOperatorv8::internal::compiler::CommonOperatorGlobalCache::EndOperator584     EndOperator()
585         : Operator(                                // --
586               IrOpcode::kEnd, Operator::kKontrol,  // opcode
587               "End",                               // name
588               0, 0, kInputCount, 0, 0, 0) {}       // counts
589   };
590 #define CACHED_END(input_count) \
591   EndOperator<input_count> kEnd##input_count##Operator;
592   CACHED_END_LIST(CACHED_END)
593 #undef CACHED_END
594 
595   template <size_t kValueInputCount>
596   struct ReturnOperator final : public Operator {
ReturnOperatorv8::internal::compiler::CommonOperatorGlobalCache::ReturnOperator597     ReturnOperator()
598         : Operator(                                    // --
599               IrOpcode::kReturn, Operator::kNoThrow,   // opcode
600               "Return",                                // name
601               kValueInputCount + 1, 1, 1, 0, 0, 1) {}  // counts
602   };
603 #define CACHED_RETURN(value_input_count) \
604   ReturnOperator<value_input_count> kReturn##value_input_count##Operator;
605   CACHED_RETURN_LIST(CACHED_RETURN)
606 #undef CACHED_RETURN
607 
608   template <BranchHint hint>
609   struct BranchOperator final : public Operator1<BranchHint> {
BranchOperatorv8::internal::compiler::CommonOperatorGlobalCache::BranchOperator610     BranchOperator()
611         : Operator1<BranchHint>(                      // --
612               IrOpcode::kBranch, Operator::kKontrol,  // opcode
613               "Branch",                               // name
614               1, 0, 1, 0, 0, 2,                       // counts
615               hint) {}                                // parameter
616   };
617 #define CACHED_BRANCH(Hint) \
618   BranchOperator<BranchHint::k##Hint> kBranch##Hint##Operator;
619   CACHED_BRANCH_LIST(CACHED_BRANCH)
620 #undef CACHED_BRANCH
621 
622   template <int kEffectInputCount>
623   struct EffectPhiOperator final : public Operator {
EffectPhiOperatorv8::internal::compiler::CommonOperatorGlobalCache::EffectPhiOperator624     EffectPhiOperator()
625         : Operator(                                      // --
626               IrOpcode::kEffectPhi, Operator::kKontrol,  // opcode
627               "EffectPhi",                               // name
628               0, kEffectInputCount, 1, 0, 1, 0) {}       // counts
629   };
630 #define CACHED_EFFECT_PHI(input_count) \
631   EffectPhiOperator<input_count> kEffectPhi##input_count##Operator;
632   CACHED_EFFECT_PHI_LIST(CACHED_EFFECT_PHI)
633 #undef CACHED_EFFECT_PHI
634 
635   template <RegionObservability kRegionObservability>
636   struct BeginRegionOperator final : public Operator1<RegionObservability> {
BeginRegionOperatorv8::internal::compiler::CommonOperatorGlobalCache::BeginRegionOperator637     BeginRegionOperator()
638         : Operator1<RegionObservability>(                  // --
639               IrOpcode::kBeginRegion, Operator::kKontrol,  // opcode
640               "BeginRegion",                               // name
641               0, 1, 0, 0, 1, 0,                            // counts
642               kRegionObservability) {}                     // parameter
643   };
644   BeginRegionOperator<RegionObservability::kObservable>
645       kBeginRegionObservableOperator;
646   BeginRegionOperator<RegionObservability::kNotObservable>
647       kBeginRegionNotObservableOperator;
648 
649   template <size_t kInputCount>
650   struct LoopOperator final : public Operator {
LoopOperatorv8::internal::compiler::CommonOperatorGlobalCache::LoopOperator651     LoopOperator()
652         : Operator(                                 // --
653               IrOpcode::kLoop, Operator::kKontrol,  // opcode
654               "Loop",                               // name
655               0, 0, kInputCount, 0, 0, 1) {}        // counts
656   };
657 #define CACHED_LOOP(input_count) \
658   LoopOperator<input_count> kLoop##input_count##Operator;
659   CACHED_LOOP_LIST(CACHED_LOOP)
660 #undef CACHED_LOOP
661 
662   template <size_t kInputCount>
663   struct MergeOperator final : public Operator {
MergeOperatorv8::internal::compiler::CommonOperatorGlobalCache::MergeOperator664     MergeOperator()
665         : Operator(                                  // --
666               IrOpcode::kMerge, Operator::kKontrol,  // opcode
667               "Merge",                               // name
668               0, 0, kInputCount, 0, 0, 1) {}         // counts
669   };
670 #define CACHED_MERGE(input_count) \
671   MergeOperator<input_count> kMerge##input_count##Operator;
672   CACHED_MERGE_LIST(CACHED_MERGE)
673 #undef CACHED_MERGE
674 
675   template <MachineRepresentation kRep>
676   struct LoopExitValueOperator final : public Operator1<MachineRepresentation> {
LoopExitValueOperatorv8::internal::compiler::CommonOperatorGlobalCache::LoopExitValueOperator677     LoopExitValueOperator()
678         : Operator1<MachineRepresentation>(IrOpcode::kLoopExitValue,
679                                            Operator::kPure, "LoopExitValue", 1,
680                                            0, 1, 1, 0, 0, kRep) {}
681   };
682 #define CACHED_LOOP_EXIT_VALUE(rep)                 \
683   LoopExitValueOperator<MachineRepresentation::rep> \
684       kLoopExitValue##rep##Operator;
685   CACHED_LOOP_EXIT_VALUE_LIST(CACHED_LOOP_EXIT_VALUE)
686 #undef CACHED_LOOP_EXIT_VALUE
687 
688   template <DeoptimizeKind kKind, DeoptimizeReason kReason>
689   struct DeoptimizeOperator final : public Operator1<DeoptimizeParameters> {
DeoptimizeOperatorv8::internal::compiler::CommonOperatorGlobalCache::DeoptimizeOperator690     DeoptimizeOperator()
691         : Operator1<DeoptimizeParameters>(               // --
692               IrOpcode::kDeoptimize,                     // opcode
693               Operator::kFoldable | Operator::kNoThrow,  // properties
694               "Deoptimize",                              // name
695               1, 1, 1, 0, 0, 1,                          // counts
696               DeoptimizeParameters(kKind, kReason, FeedbackSource())) {}
697   };
698 #define CACHED_DEOPTIMIZE(Kind, Reason)                                    \
699   DeoptimizeOperator<DeoptimizeKind::k##Kind, DeoptimizeReason::k##Reason> \
700       kDeoptimize##Kind##Reason##Operator;
701   CACHED_DEOPTIMIZE_LIST(CACHED_DEOPTIMIZE)
702 #undef CACHED_DEOPTIMIZE
703 
704   template <DeoptimizeKind kKind, DeoptimizeReason kReason>
705   struct DeoptimizeIfOperator final : public Operator1<DeoptimizeParameters> {
DeoptimizeIfOperatorv8::internal::compiler::CommonOperatorGlobalCache::DeoptimizeIfOperator706     DeoptimizeIfOperator()
707         : Operator1<DeoptimizeParameters>(               // --
708               IrOpcode::kDeoptimizeIf,                   // opcode
709               Operator::kFoldable | Operator::kNoThrow,  // properties
710               "DeoptimizeIf",                            // name
711               2, 1, 1, 0, 1, 1,                          // counts
712               DeoptimizeParameters(kKind, kReason, FeedbackSource())) {}
713   };
714 #define CACHED_DEOPTIMIZE_IF(Kind, Reason)                                   \
715   DeoptimizeIfOperator<DeoptimizeKind::k##Kind, DeoptimizeReason::k##Reason> \
716       kDeoptimizeIf##Kind##Reason##Operator;
717   CACHED_DEOPTIMIZE_IF_LIST(CACHED_DEOPTIMIZE_IF)
718 #undef CACHED_DEOPTIMIZE_IF
719 
720   template <DeoptimizeKind kKind, DeoptimizeReason kReason>
721   struct DeoptimizeUnlessOperator final
722       : public Operator1<DeoptimizeParameters> {
DeoptimizeUnlessOperatorv8::internal::compiler::CommonOperatorGlobalCache::DeoptimizeUnlessOperator723     DeoptimizeUnlessOperator()
724         : Operator1<DeoptimizeParameters>(               // --
725               IrOpcode::kDeoptimizeUnless,               // opcode
726               Operator::kFoldable | Operator::kNoThrow,  // properties
727               "DeoptimizeUnless",                        // name
728               2, 1, 1, 0, 1, 1,                          // counts
729               DeoptimizeParameters(kKind, kReason, FeedbackSource())) {}
730   };
731 #define CACHED_DEOPTIMIZE_UNLESS(Kind, Reason)          \
732   DeoptimizeUnlessOperator<DeoptimizeKind::k##Kind,     \
733                            DeoptimizeReason::k##Reason> \
734       kDeoptimizeUnless##Kind##Reason##Operator;
735   CACHED_DEOPTIMIZE_UNLESS_LIST(CACHED_DEOPTIMIZE_UNLESS)
736 #undef CACHED_DEOPTIMIZE_UNLESS
737 
738   template <DeoptimizeReason kReason>
739   struct DynamicMapCheckOperator final : Operator1<DeoptimizeParameters> {
DynamicMapCheckOperatorv8::internal::compiler::CommonOperatorGlobalCache::DynamicMapCheckOperator740     DynamicMapCheckOperator()
741         : Operator1<DeoptimizeParameters>(                 // --
742               IrOpcode::kDynamicCheckMapsWithDeoptUnless,  // opcode
743               Operator::kFoldable | Operator::kNoThrow,    // properties
744               "DynamicCheckMapsWithDeoptUnless",           // name
745               6, 1, 1, 0, 1, 1,                            // counts
746               DeoptimizeParameters(DeoptimizeKind::kEagerWithResume, kReason,
747                                    FeedbackSource())) {}
748   };
749 #define CACHED_DYNAMIC_CHECK_MAPS(Reason) \
750   DynamicMapCheckOperator<DeoptimizeReason::k##Reason> k##Reason##Operator;
751   CACHED_DYNAMIC_CHECK_MAPS_LIST(CACHED_DYNAMIC_CHECK_MAPS)
752 #undef CACHED_DYNAMIC_CHECK_MAPS
753 
754   template <TrapId trap_id>
755   struct TrapIfOperator final : public Operator1<TrapId> {
TrapIfOperatorv8::internal::compiler::CommonOperatorGlobalCache::TrapIfOperator756     TrapIfOperator()
757         : Operator1<TrapId>(                             // --
758               IrOpcode::kTrapIf,                         // opcode
759               Operator::kFoldable | Operator::kNoThrow,  // properties
760               "TrapIf",                                  // name
761               1, 1, 1, 0, 0, 1,                          // counts
762               trap_id) {}                                // parameter
763   };
764 #define CACHED_TRAP_IF(Trap) \
765   TrapIfOperator<TrapId::k##Trap> kTrapIf##Trap##Operator;
766   CACHED_TRAP_IF_LIST(CACHED_TRAP_IF)
767 #undef CACHED_TRAP_IF
768 
769   template <TrapId trap_id>
770   struct TrapUnlessOperator final : public Operator1<TrapId> {
TrapUnlessOperatorv8::internal::compiler::CommonOperatorGlobalCache::TrapUnlessOperator771     TrapUnlessOperator()
772         : Operator1<TrapId>(                             // --
773               IrOpcode::kTrapUnless,                     // opcode
774               Operator::kFoldable | Operator::kNoThrow,  // properties
775               "TrapUnless",                              // name
776               1, 1, 1, 0, 0, 1,                          // counts
777               trap_id) {}                                // parameter
778   };
779 #define CACHED_TRAP_UNLESS(Trap) \
780   TrapUnlessOperator<TrapId::k##Trap> kTrapUnless##Trap##Operator;
781   CACHED_TRAP_UNLESS_LIST(CACHED_TRAP_UNLESS)
782 #undef CACHED_TRAP_UNLESS
783 
784   template <MachineRepresentation kRep, int kInputCount>
785   struct PhiOperator final : public Operator1<MachineRepresentation> {
PhiOperatorv8::internal::compiler::CommonOperatorGlobalCache::PhiOperator786     PhiOperator()
787         : Operator1<MachineRepresentation>(     //--
788               IrOpcode::kPhi, Operator::kPure,  // opcode
789               "Phi",                            // name
790               kInputCount, 0, 1, 1, 0, 0,       // counts
791               kRep) {}                          // parameter
792   };
793 #define CACHED_PHI(rep, input_count)                   \
794   PhiOperator<MachineRepresentation::rep, input_count> \
795       kPhi##rep##input_count##Operator;
796   CACHED_PHI_LIST(CACHED_PHI)
797 #undef CACHED_PHI
798 
799   template <int kInputCount>
800   struct InductionVariablePhiOperator final : public Operator {
InductionVariablePhiOperatorv8::internal::compiler::CommonOperatorGlobalCache::InductionVariablePhiOperator801     InductionVariablePhiOperator()
802         : Operator(                                              //--
803               IrOpcode::kInductionVariablePhi, Operator::kPure,  // opcode
804               "InductionVariablePhi",                            // name
805               kInputCount, 0, 1, 1, 0, 0) {}                     // counts
806   };
807 #define CACHED_INDUCTION_VARIABLE_PHI(input_count) \
808   InductionVariablePhiOperator<input_count>        \
809       kInductionVariablePhi##input_count##Operator;
810   CACHED_INDUCTION_VARIABLE_PHI_LIST(CACHED_INDUCTION_VARIABLE_PHI)
811 #undef CACHED_INDUCTION_VARIABLE_PHI
812 
813   template <int kIndex>
814   struct ParameterOperator final : public Operator1<ParameterInfo> {
ParameterOperatorv8::internal::compiler::CommonOperatorGlobalCache::ParameterOperator815     ParameterOperator()
816         : Operator1<ParameterInfo>(                   // --
817               IrOpcode::kParameter, Operator::kPure,  // opcode
818               "Parameter",                            // name
819               1, 0, 0, 1, 0, 0,                       // counts,
820               ParameterInfo(kIndex, nullptr)) {}      // parameter and name
821   };
822 #define CACHED_PARAMETER(index) \
823   ParameterOperator<index> kParameter##index##Operator;
824   CACHED_PARAMETER_LIST(CACHED_PARAMETER)
825 #undef CACHED_PARAMETER
826 
827   template <size_t kIndex>
828   struct ProjectionOperator final : public Operator1<size_t> {
ProjectionOperatorv8::internal::compiler::CommonOperatorGlobalCache::ProjectionOperator829     ProjectionOperator()
830         : Operator1<size_t>(          // --
831               IrOpcode::kProjection,  // opcode
832               Operator::kPure,        // flags
833               "Projection",           // name
834               1, 0, 1, 1, 0, 0,       // counts,
835               kIndex) {}              // parameter
836   };
837 #define CACHED_PROJECTION(index) \
838   ProjectionOperator<index> kProjection##index##Operator;
839   CACHED_PROJECTION_LIST(CACHED_PROJECTION)
840 #undef CACHED_PROJECTION
841 
842   template <int kInputCount>
843   struct StateValuesOperator final : public Operator1<SparseInputMask> {
StateValuesOperatorv8::internal::compiler::CommonOperatorGlobalCache::StateValuesOperator844     StateValuesOperator()
845         : Operator1<SparseInputMask>(       // --
846               IrOpcode::kStateValues,       // opcode
847               Operator::kPure,              // flags
848               "StateValues",                // name
849               kInputCount, 0, 0, 1, 0, 0,   // counts
850               SparseInputMask::Dense()) {}  // parameter
851   };
852 #define CACHED_STATE_VALUES(input_count) \
853   StateValuesOperator<input_count> kStateValues##input_count##Operator;
854   CACHED_STATE_VALUES_LIST(CACHED_STATE_VALUES)
855 #undef CACHED_STATE_VALUES
856 };
857 
858 namespace {
859 DEFINE_LAZY_LEAKY_OBJECT_GETTER(CommonOperatorGlobalCache,
860                                 GetCommonOperatorGlobalCache)
861 }  // namespace
862 
CommonOperatorBuilder(Zone * zone)863 CommonOperatorBuilder::CommonOperatorBuilder(Zone* zone)
864     : cache_(*GetCommonOperatorGlobalCache()), zone_(zone) {}
865 
866 #define CACHED(Name, properties, value_input_count, effect_input_count,      \
867                control_input_count, value_output_count, effect_output_count, \
868                control_output_count)                                         \
869   const Operator* CommonOperatorBuilder::Name() {                            \
870     return &cache_.k##Name##Operator;                                        \
871   }
COMMON_CACHED_OP_LIST(CACHED) const872 COMMON_CACHED_OP_LIST(CACHED)
873 #undef CACHED
874 
875 
876 const Operator* CommonOperatorBuilder::End(size_t control_input_count) {
877   switch (control_input_count) {
878 #define CACHED_END(input_count) \
879   case input_count:             \
880     return &cache_.kEnd##input_count##Operator;
881     CACHED_END_LIST(CACHED_END)
882 #undef CACHED_END
883     default:
884       break;
885   }
886   // Uncached.
887   return zone()->New<Operator>(             //--
888       IrOpcode::kEnd, Operator::kKontrol,   // opcode
889       "End",                                // name
890       0, 0, control_input_count, 0, 0, 0);  // counts
891 }
892 
Return(int value_input_count)893 const Operator* CommonOperatorBuilder::Return(int value_input_count) {
894   switch (value_input_count) {
895 #define CACHED_RETURN(input_count) \
896   case input_count:                \
897     return &cache_.kReturn##input_count##Operator;
898     CACHED_RETURN_LIST(CACHED_RETURN)
899 #undef CACHED_RETURN
900     default:
901       break;
902   }
903   // Uncached.
904   return zone()->New<Operator>(               //--
905       IrOpcode::kReturn, Operator::kNoThrow,  // opcode
906       "Return",                               // name
907       value_input_count + 1, 1, 1, 0, 0, 1);  // counts
908 }
909 
StaticAssert(const char * source)910 const Operator* CommonOperatorBuilder::StaticAssert(const char* source) {
911   return zone()->New<Operator1<const char*>>(
912       IrOpcode::kStaticAssert, Operator::kFoldable, "StaticAssert", 1, 1, 0, 0,
913       1, 0, source);
914 }
915 
Branch(BranchHint hint)916 const Operator* CommonOperatorBuilder::Branch(BranchHint hint) {
917 #define CACHED_BRANCH(Hint)                 \
918   if (hint == BranchHint::k##Hint) {        \
919     return &cache_.kBranch##Hint##Operator; \
920   }
921   CACHED_BRANCH_LIST(CACHED_BRANCH)
922 #undef CACHED_BRANCH
923   UNREACHABLE();
924 }
925 
Deoptimize(DeoptimizeKind kind,DeoptimizeReason reason,FeedbackSource const & feedback)926 const Operator* CommonOperatorBuilder::Deoptimize(
927     DeoptimizeKind kind, DeoptimizeReason reason,
928     FeedbackSource const& feedback) {
929 #define CACHED_DEOPTIMIZE(Kind, Reason)                               \
930   if (kind == DeoptimizeKind::k##Kind &&                              \
931       reason == DeoptimizeReason::k##Reason && !feedback.IsValid()) { \
932     return &cache_.kDeoptimize##Kind##Reason##Operator;               \
933   }
934   CACHED_DEOPTIMIZE_LIST(CACHED_DEOPTIMIZE)
935 #undef CACHED_DEOPTIMIZE
936   // Uncached
937   DeoptimizeParameters parameter(kind, reason, feedback);
938   return zone()->New<Operator1<DeoptimizeParameters>>(  // --
939       IrOpcode::kDeoptimize,                            // opcodes
940       Operator::kFoldable | Operator::kNoThrow,         // properties
941       "Deoptimize",                                     // name
942       1, 1, 1, 0, 0, 1,                                 // counts
943       parameter);                                       // parameter
944 }
945 
DeoptimizeIf(DeoptimizeKind kind,DeoptimizeReason reason,FeedbackSource const & feedback)946 const Operator* CommonOperatorBuilder::DeoptimizeIf(
947     DeoptimizeKind kind, DeoptimizeReason reason,
948     FeedbackSource const& feedback) {
949 #define CACHED_DEOPTIMIZE_IF(Kind, Reason)                            \
950   if (kind == DeoptimizeKind::k##Kind &&                              \
951       reason == DeoptimizeReason::k##Reason && !feedback.IsValid()) { \
952     return &cache_.kDeoptimizeIf##Kind##Reason##Operator;             \
953   }
954   CACHED_DEOPTIMIZE_IF_LIST(CACHED_DEOPTIMIZE_IF)
955 #undef CACHED_DEOPTIMIZE_IF
956   // Uncached
957   DeoptimizeParameters parameter(kind, reason, feedback);
958   return zone()->New<Operator1<DeoptimizeParameters>>(  // --
959       IrOpcode::kDeoptimizeIf,                          // opcode
960       Operator::kFoldable | Operator::kNoThrow,         // properties
961       "DeoptimizeIf",                                   // name
962       2, 1, 1, 0, 1, 1,                                 // counts
963       parameter);                                       // parameter
964 }
965 
DeoptimizeUnless(DeoptimizeKind kind,DeoptimizeReason reason,FeedbackSource const & feedback)966 const Operator* CommonOperatorBuilder::DeoptimizeUnless(
967     DeoptimizeKind kind, DeoptimizeReason reason,
968     FeedbackSource const& feedback) {
969 #define CACHED_DEOPTIMIZE_UNLESS(Kind, Reason)                        \
970   if (kind == DeoptimizeKind::k##Kind &&                              \
971       reason == DeoptimizeReason::k##Reason && !feedback.IsValid()) { \
972     return &cache_.kDeoptimizeUnless##Kind##Reason##Operator;         \
973   }
974   CACHED_DEOPTIMIZE_UNLESS_LIST(CACHED_DEOPTIMIZE_UNLESS)
975 #undef CACHED_DEOPTIMIZE_UNLESS
976   // Uncached
977   DeoptimizeParameters parameter(kind, reason, feedback);
978   return zone()->New<Operator1<DeoptimizeParameters>>(  // --
979       IrOpcode::kDeoptimizeUnless,                      // opcode
980       Operator::kFoldable | Operator::kNoThrow,         // properties
981       "DeoptimizeUnless",                               // name
982       2, 1, 1, 0, 1, 1,                                 // counts
983       parameter);                                       // parameter
984 }
985 
DynamicCheckMapsWithDeoptUnless(bool is_inlined_frame_state)986 const Operator* CommonOperatorBuilder::DynamicCheckMapsWithDeoptUnless(
987     bool is_inlined_frame_state) {
988   if (is_inlined_frame_state) {
989     return &cache_.kDynamicCheckMapsInlinedOperator;
990   } else {
991     return &cache_.kDynamicCheckMapsOperator;
992   }
993 }
994 
TrapIf(TrapId trap_id)995 const Operator* CommonOperatorBuilder::TrapIf(TrapId trap_id) {
996   switch (trap_id) {
997 #define CACHED_TRAP_IF(Trap) \
998   case TrapId::k##Trap:      \
999     return &cache_.kTrapIf##Trap##Operator;
1000     CACHED_TRAP_IF_LIST(CACHED_TRAP_IF)
1001 #undef CACHED_TRAP_IF
1002     default:
1003       break;
1004   }
1005   // Uncached
1006   return zone()->New<Operator1<TrapId>>(         // --
1007       IrOpcode::kTrapIf,                         // opcode
1008       Operator::kFoldable | Operator::kNoThrow,  // properties
1009       "TrapIf",                                  // name
1010       1, 1, 1, 0, 0, 1,                          // counts
1011       trap_id);                                  // parameter
1012 }
1013 
TrapUnless(TrapId trap_id)1014 const Operator* CommonOperatorBuilder::TrapUnless(TrapId trap_id) {
1015   switch (trap_id) {
1016 #define CACHED_TRAP_UNLESS(Trap) \
1017   case TrapId::k##Trap:          \
1018     return &cache_.kTrapUnless##Trap##Operator;
1019     CACHED_TRAP_UNLESS_LIST(CACHED_TRAP_UNLESS)
1020 #undef CACHED_TRAP_UNLESS
1021     default:
1022       break;
1023   }
1024   // Uncached
1025   return zone()->New<Operator1<TrapId>>(         // --
1026       IrOpcode::kTrapUnless,                     // opcode
1027       Operator::kFoldable | Operator::kNoThrow,  // properties
1028       "TrapUnless",                              // name
1029       1, 1, 1, 0, 0, 1,                          // counts
1030       trap_id);                                  // parameter
1031 }
1032 
Switch(size_t control_output_count)1033 const Operator* CommonOperatorBuilder::Switch(size_t control_output_count) {
1034   return zone()->New<Operator>(               // --
1035       IrOpcode::kSwitch, Operator::kKontrol,  // opcode
1036       "Switch",                               // name
1037       1, 0, 1, 0, 0, control_output_count);   // counts
1038 }
1039 
IfValue(int32_t index,int32_t comparison_order,BranchHint hint)1040 const Operator* CommonOperatorBuilder::IfValue(int32_t index,
1041                                                int32_t comparison_order,
1042                                                BranchHint hint) {
1043   return zone()->New<Operator1<IfValueParameters>>(       // --
1044       IrOpcode::kIfValue, Operator::kKontrol,             // opcode
1045       "IfValue",                                          // name
1046       0, 0, 1, 0, 0, 1,                                   // counts
1047       IfValueParameters(index, comparison_order, hint));  // parameter
1048 }
1049 
IfDefault(BranchHint hint)1050 const Operator* CommonOperatorBuilder::IfDefault(BranchHint hint) {
1051   return zone()->New<Operator1<BranchHint>>(     // --
1052       IrOpcode::kIfDefault, Operator::kKontrol,  // opcode
1053       "IfDefault",                               // name
1054       0, 0, 1, 0, 0, 1,                          // counts
1055       hint);                                     // parameter
1056 }
1057 
Start(int value_output_count)1058 const Operator* CommonOperatorBuilder::Start(int value_output_count) {
1059   return zone()->New<Operator>(                                    // --
1060       IrOpcode::kStart, Operator::kFoldable | Operator::kNoThrow,  // opcode
1061       "Start",                                                     // name
1062       0, 0, 0, value_output_count, 1, 1);                          // counts
1063 }
1064 
1065 
Loop(int control_input_count)1066 const Operator* CommonOperatorBuilder::Loop(int control_input_count) {
1067   switch (control_input_count) {
1068 #define CACHED_LOOP(input_count) \
1069   case input_count:              \
1070     return &cache_.kLoop##input_count##Operator;
1071     CACHED_LOOP_LIST(CACHED_LOOP)
1072 #undef CACHED_LOOP
1073     default:
1074       break;
1075   }
1076   // Uncached.
1077   return zone()->New<Operator>(             // --
1078       IrOpcode::kLoop, Operator::kKontrol,  // opcode
1079       "Loop",                               // name
1080       0, 0, control_input_count, 0, 0, 1);  // counts
1081 }
1082 
1083 
Merge(int control_input_count)1084 const Operator* CommonOperatorBuilder::Merge(int control_input_count) {
1085   switch (control_input_count) {
1086 #define CACHED_MERGE(input_count) \
1087   case input_count:               \
1088     return &cache_.kMerge##input_count##Operator;
1089     CACHED_MERGE_LIST(CACHED_MERGE)
1090 #undef CACHED_MERGE
1091     default:
1092       break;
1093   }
1094   // Uncached.
1095   return zone()->New<Operator>(              // --
1096       IrOpcode::kMerge, Operator::kKontrol,  // opcode
1097       "Merge",                               // name
1098       0, 0, control_input_count, 0, 0, 1);   // counts
1099 }
1100 
LoopExitValue(MachineRepresentation rep)1101 const Operator* CommonOperatorBuilder::LoopExitValue(
1102     MachineRepresentation rep) {
1103   switch (rep) {
1104 #define CACHED_LOOP_EXIT_VALUE(kRep) \
1105   case MachineRepresentation::kRep:  \
1106     return &cache_.kLoopExitValue##kRep##Operator;
1107 
1108     CACHED_LOOP_EXIT_VALUE_LIST(CACHED_LOOP_EXIT_VALUE)
1109 #undef CACHED_LOOP_EXIT_VALUE
1110     default:
1111       // Uncached.
1112       return zone()->New<Operator1<MachineRepresentation>>(  // --
1113           IrOpcode::kLoopExitValue, Operator::kPure,         // opcode
1114           "LoopExitValue",                                   // name
1115           1, 0, 1, 1, 0, 0,                                  // counts
1116           rep);                                              // parameter
1117   }
1118 }
1119 
Parameter(int index,const char * debug_name)1120 const Operator* CommonOperatorBuilder::Parameter(int index,
1121                                                  const char* debug_name) {
1122   if (!debug_name) {
1123     switch (index) {
1124 #define CACHED_PARAMETER(index) \
1125   case index:                   \
1126     return &cache_.kParameter##index##Operator;
1127       CACHED_PARAMETER_LIST(CACHED_PARAMETER)
1128 #undef CACHED_PARAMETER
1129       default:
1130         break;
1131     }
1132   }
1133   // Uncached.
1134   return zone()->New<Operator1<ParameterInfo>>(  // --
1135       IrOpcode::kParameter, Operator::kPure,     // opcode
1136       "Parameter",                               // name
1137       1, 0, 0, 1, 0, 0,                          // counts
1138       ParameterInfo(index, debug_name));         // parameter info
1139 }
1140 
OsrValue(int index)1141 const Operator* CommonOperatorBuilder::OsrValue(int index) {
1142   return zone()->New<Operator1<int>>(                // --
1143       IrOpcode::kOsrValue, Operator::kNoProperties,  // opcode
1144       "OsrValue",                                    // name
1145       0, 0, 1, 1, 0, 0,                              // counts
1146       index);                                        // parameter
1147 }
1148 
Int32Constant(int32_t value)1149 const Operator* CommonOperatorBuilder::Int32Constant(int32_t value) {
1150   return zone()->New<Operator1<int32_t>>(         // --
1151       IrOpcode::kInt32Constant, Operator::kPure,  // opcode
1152       "Int32Constant",                            // name
1153       0, 0, 0, 1, 0, 0,                           // counts
1154       value);                                     // parameter
1155 }
1156 
1157 
Int64Constant(int64_t value)1158 const Operator* CommonOperatorBuilder::Int64Constant(int64_t value) {
1159   return zone()->New<Operator1<int64_t>>(         // --
1160       IrOpcode::kInt64Constant, Operator::kPure,  // opcode
1161       "Int64Constant",                            // name
1162       0, 0, 0, 1, 0, 0,                           // counts
1163       value);                                     // parameter
1164 }
1165 
TaggedIndexConstant(int32_t value)1166 const Operator* CommonOperatorBuilder::TaggedIndexConstant(int32_t value) {
1167   return zone()->New<Operator1<int32_t>>(               // --
1168       IrOpcode::kTaggedIndexConstant, Operator::kPure,  // opcode
1169       "TaggedIndexConstant",                            // name
1170       0, 0, 0, 1, 0, 0,                                 // counts
1171       value);                                           // parameter
1172 }
1173 
Float32Constant(volatile float value)1174 const Operator* CommonOperatorBuilder::Float32Constant(volatile float value) {
1175   return zone()->New<Operator1<float>>(             // --
1176       IrOpcode::kFloat32Constant, Operator::kPure,  // opcode
1177       "Float32Constant",                            // name
1178       0, 0, 0, 1, 0, 0,                             // counts
1179       value);                                       // parameter
1180 }
1181 
1182 
Float64Constant(volatile double value)1183 const Operator* CommonOperatorBuilder::Float64Constant(volatile double value) {
1184   return zone()->New<Operator1<double>>(            // --
1185       IrOpcode::kFloat64Constant, Operator::kPure,  // opcode
1186       "Float64Constant",                            // name
1187       0, 0, 0, 1, 0, 0,                             // counts
1188       value);                                       // parameter
1189 }
1190 
1191 
ExternalConstant(const ExternalReference & value)1192 const Operator* CommonOperatorBuilder::ExternalConstant(
1193     const ExternalReference& value) {
1194   return zone()->New<Operator1<ExternalReference>>(  // --
1195       IrOpcode::kExternalConstant, Operator::kPure,  // opcode
1196       "ExternalConstant",                            // name
1197       0, 0, 0, 1, 0, 0,                              // counts
1198       value);                                        // parameter
1199 }
1200 
1201 
NumberConstant(volatile double value)1202 const Operator* CommonOperatorBuilder::NumberConstant(volatile double value) {
1203   return zone()->New<Operator1<double>>(           // --
1204       IrOpcode::kNumberConstant, Operator::kPure,  // opcode
1205       "NumberConstant",                            // name
1206       0, 0, 0, 1, 0, 0,                            // counts
1207       value);                                      // parameter
1208 }
1209 
PointerConstant(intptr_t value)1210 const Operator* CommonOperatorBuilder::PointerConstant(intptr_t value) {
1211   return zone()->New<Operator1<intptr_t>>(          // --
1212       IrOpcode::kPointerConstant, Operator::kPure,  // opcode
1213       "PointerConstant",                            // name
1214       0, 0, 0, 1, 0, 0,                             // counts
1215       value);                                       // parameter
1216 }
1217 
HeapConstant(const Handle<HeapObject> & value)1218 const Operator* CommonOperatorBuilder::HeapConstant(
1219     const Handle<HeapObject>& value) {
1220   return zone()->New<Operator1<Handle<HeapObject>>>(  // --
1221       IrOpcode::kHeapConstant, Operator::kPure,       // opcode
1222       "HeapConstant",                                 // name
1223       0, 0, 0, 1, 0, 0,                               // counts
1224       value);                                         // parameter
1225 }
1226 
CompressedHeapConstant(const Handle<HeapObject> & value)1227 const Operator* CommonOperatorBuilder::CompressedHeapConstant(
1228     const Handle<HeapObject>& value) {
1229   return zone()->New<Operator1<Handle<HeapObject>>>(       // --
1230       IrOpcode::kCompressedHeapConstant, Operator::kPure,  // opcode
1231       "CompressedHeapConstant",                            // name
1232       0, 0, 0, 1, 0, 0,                                    // counts
1233       value);                                              // parameter
1234 }
1235 
HeapConstantOf(const Operator * op)1236 Handle<HeapObject> HeapConstantOf(const Operator* op) {
1237   DCHECK(IrOpcode::kHeapConstant == op->opcode() ||
1238          IrOpcode::kCompressedHeapConstant == op->opcode());
1239   return OpParameter<Handle<HeapObject>>(op);
1240 }
1241 
StringConstantBaseOf(const Operator * op)1242 const StringConstantBase* StringConstantBaseOf(const Operator* op) {
1243   DCHECK_EQ(IrOpcode::kDelayedStringConstant, op->opcode());
1244   return OpParameter<const StringConstantBase*>(op);
1245 }
1246 
StaticAssertSourceOf(const Operator * op)1247 const char* StaticAssertSourceOf(const Operator* op) {
1248   DCHECK_EQ(IrOpcode::kStaticAssert, op->opcode());
1249   return OpParameter<const char*>(op);
1250 }
1251 
RelocatableInt32Constant(int32_t value,RelocInfo::Mode rmode)1252 const Operator* CommonOperatorBuilder::RelocatableInt32Constant(
1253     int32_t value, RelocInfo::Mode rmode) {
1254   return zone()->New<Operator1<RelocatablePtrConstantInfo>>(  // --
1255       IrOpcode::kRelocatableInt32Constant, Operator::kPure,   // opcode
1256       "RelocatableInt32Constant",                             // name
1257       0, 0, 0, 1, 0, 0,                                       // counts
1258       RelocatablePtrConstantInfo(value, rmode));              // parameter
1259 }
1260 
RelocatableInt64Constant(int64_t value,RelocInfo::Mode rmode)1261 const Operator* CommonOperatorBuilder::RelocatableInt64Constant(
1262     int64_t value, RelocInfo::Mode rmode) {
1263   return zone()->New<Operator1<RelocatablePtrConstantInfo>>(  // --
1264       IrOpcode::kRelocatableInt64Constant, Operator::kPure,   // opcode
1265       "RelocatableInt64Constant",                             // name
1266       0, 0, 0, 1, 0, 0,                                       // counts
1267       RelocatablePtrConstantInfo(value, rmode));              // parameter
1268 }
1269 
ObjectId(uint32_t object_id)1270 const Operator* CommonOperatorBuilder::ObjectId(uint32_t object_id) {
1271   return zone()->New<Operator1<uint32_t>>(   // --
1272       IrOpcode::kObjectId, Operator::kPure,  // opcode
1273       "ObjectId",                            // name
1274       0, 0, 0, 1, 0, 0,                      // counts
1275       object_id);                            // parameter
1276 }
1277 
Select(MachineRepresentation rep,BranchHint hint)1278 const Operator* CommonOperatorBuilder::Select(MachineRepresentation rep,
1279                                               BranchHint hint) {
1280   return zone()->New<Operator1<SelectParameters>>(  // --
1281       IrOpcode::kSelect, Operator::kPure,           // opcode
1282       "Select",                                     // name
1283       3, 0, 0, 1, 0, 0,                             // counts
1284       SelectParameters(rep, hint));                 // parameter
1285 }
1286 
1287 
Phi(MachineRepresentation rep,int value_input_count)1288 const Operator* CommonOperatorBuilder::Phi(MachineRepresentation rep,
1289                                            int value_input_count) {
1290   DCHECK_LT(0, value_input_count);  // Disallow empty phis.
1291 #define CACHED_PHI(kRep, kValueInputCount)                 \
1292   if (MachineRepresentation::kRep == rep &&                \
1293       kValueInputCount == value_input_count) {             \
1294     return &cache_.kPhi##kRep##kValueInputCount##Operator; \
1295   }
1296   CACHED_PHI_LIST(CACHED_PHI)
1297 #undef CACHED_PHI
1298   // Uncached.
1299   return zone()->New<Operator1<MachineRepresentation>>(  // --
1300       IrOpcode::kPhi, Operator::kPure,                   // opcode
1301       "Phi",                                             // name
1302       value_input_count, 0, 1, 1, 0, 0,                  // counts
1303       rep);                                              // parameter
1304 }
1305 
TypeGuard(Type type)1306 const Operator* CommonOperatorBuilder::TypeGuard(Type type) {
1307   return zone()->New<Operator1<Type>>(        // --
1308       IrOpcode::kTypeGuard, Operator::kPure,  // opcode
1309       "TypeGuard",                            // name
1310       1, 1, 1, 1, 1, 0,                       // counts
1311       type);                                  // parameter
1312 }
1313 
FoldConstant()1314 const Operator* CommonOperatorBuilder::FoldConstant() {
1315   return zone()->New<Operator>(                  // --
1316       IrOpcode::kFoldConstant, Operator::kPure,  // opcode
1317       "FoldConstant",                            // name
1318       2, 0, 0, 1, 0, 0);                         // counts
1319 }
1320 
EffectPhi(int effect_input_count)1321 const Operator* CommonOperatorBuilder::EffectPhi(int effect_input_count) {
1322   DCHECK_LT(0, effect_input_count);  // Disallow empty effect phis.
1323   switch (effect_input_count) {
1324 #define CACHED_EFFECT_PHI(input_count) \
1325   case input_count:                    \
1326     return &cache_.kEffectPhi##input_count##Operator;
1327     CACHED_EFFECT_PHI_LIST(CACHED_EFFECT_PHI)
1328 #undef CACHED_EFFECT_PHI
1329     default:
1330       break;
1331   }
1332   // Uncached.
1333   return zone()->New<Operator>(                  // --
1334       IrOpcode::kEffectPhi, Operator::kKontrol,  // opcode
1335       "EffectPhi",                               // name
1336       0, effect_input_count, 1, 0, 1, 0);        // counts
1337 }
1338 
InductionVariablePhi(int input_count)1339 const Operator* CommonOperatorBuilder::InductionVariablePhi(int input_count) {
1340   DCHECK_LE(4, input_count);  // There must be always the entry, backedge,
1341                               // increment and at least one bound.
1342   switch (input_count) {
1343 #define CACHED_INDUCTION_VARIABLE_PHI(input_count) \
1344   case input_count:                                \
1345     return &cache_.kInductionVariablePhi##input_count##Operator;
1346     CACHED_INDUCTION_VARIABLE_PHI_LIST(CACHED_INDUCTION_VARIABLE_PHI)
1347 #undef CACHED_INDUCTION_VARIABLE_PHI
1348     default:
1349       break;
1350   }
1351   // Uncached.
1352   return zone()->New<Operator>(                          // --
1353       IrOpcode::kInductionVariablePhi, Operator::kPure,  // opcode
1354       "InductionVariablePhi",                            // name
1355       input_count, 0, 1, 1, 0, 0);                       // counts
1356 }
1357 
BeginRegion(RegionObservability region_observability)1358 const Operator* CommonOperatorBuilder::BeginRegion(
1359     RegionObservability region_observability) {
1360   switch (region_observability) {
1361     case RegionObservability::kObservable:
1362       return &cache_.kBeginRegionObservableOperator;
1363     case RegionObservability::kNotObservable:
1364       return &cache_.kBeginRegionNotObservableOperator;
1365   }
1366   UNREACHABLE();
1367 }
1368 
StateValues(int arguments,SparseInputMask bitmask)1369 const Operator* CommonOperatorBuilder::StateValues(int arguments,
1370                                                    SparseInputMask bitmask) {
1371   if (bitmask.IsDense()) {
1372     switch (arguments) {
1373 #define CACHED_STATE_VALUES(arguments) \
1374   case arguments:                      \
1375     return &cache_.kStateValues##arguments##Operator;
1376       CACHED_STATE_VALUES_LIST(CACHED_STATE_VALUES)
1377 #undef CACHED_STATE_VALUES
1378       default:
1379         break;
1380     }
1381   }
1382 
1383 #if DEBUG
1384   DCHECK(bitmask.IsDense() || bitmask.CountReal() == arguments);
1385 #endif
1386 
1387   // Uncached.
1388   return zone()->New<Operator1<SparseInputMask>>(  // --
1389       IrOpcode::kStateValues, Operator::kPure,     // opcode
1390       "StateValues",                               // name
1391       arguments, 0, 0, 1, 0, 0,                    // counts
1392       bitmask);                                    // parameter
1393 }
1394 
TypedStateValues(const ZoneVector<MachineType> * types,SparseInputMask bitmask)1395 const Operator* CommonOperatorBuilder::TypedStateValues(
1396     const ZoneVector<MachineType>* types, SparseInputMask bitmask) {
1397 #if DEBUG
1398   DCHECK(bitmask.IsDense() ||
1399          bitmask.CountReal() == static_cast<int>(types->size()));
1400 #endif
1401 
1402   return zone()->New<Operator1<TypedStateValueInfo>>(  // --
1403       IrOpcode::kTypedStateValues, Operator::kPure,    // opcode
1404       "TypedStateValues",                              // name
1405       static_cast<int>(types->size()), 0, 0, 1, 0, 0,  // counts
1406       TypedStateValueInfo(types, bitmask));            // parameters
1407 }
1408 
ArgumentsElementsState(ArgumentsStateType type)1409 const Operator* CommonOperatorBuilder::ArgumentsElementsState(
1410     ArgumentsStateType type) {
1411   return zone()->New<Operator1<ArgumentsStateType>>(       // --
1412       IrOpcode::kArgumentsElementsState, Operator::kPure,  // opcode
1413       "ArgumentsElementsState",                            // name
1414       0, 0, 0, 1, 0, 0,                                    // counts
1415       type);                                               // parameter
1416 }
1417 
ArgumentsLengthState()1418 const Operator* CommonOperatorBuilder::ArgumentsLengthState() {
1419   return zone()->New<Operator>(                          // --
1420       IrOpcode::kArgumentsLengthState, Operator::kPure,  // opcode
1421       "ArgumentsLengthState",                            // name
1422       0, 0, 0, 1, 0, 0);                                 // counts
1423 }
1424 
ArgumentsStateTypeOf(Operator const * op)1425 ArgumentsStateType ArgumentsStateTypeOf(Operator const* op) {
1426   DCHECK(op->opcode() == IrOpcode::kArgumentsElementsState);
1427   return OpParameter<ArgumentsStateType>(op);
1428 }
1429 
ObjectState(uint32_t object_id,int pointer_slots)1430 const Operator* CommonOperatorBuilder::ObjectState(uint32_t object_id,
1431                                                    int pointer_slots) {
1432   return zone()->New<Operator1<ObjectStateInfo>>(  // --
1433       IrOpcode::kObjectState, Operator::kPure,     // opcode
1434       "ObjectState",                               // name
1435       pointer_slots, 0, 0, 1, 0, 0,                // counts
1436       ObjectStateInfo{object_id, pointer_slots});  // parameter
1437 }
1438 
TypedObjectState(uint32_t object_id,const ZoneVector<MachineType> * types)1439 const Operator* CommonOperatorBuilder::TypedObjectState(
1440     uint32_t object_id, const ZoneVector<MachineType>* types) {
1441   return zone()->New<Operator1<TypedObjectStateInfo>>(  // --
1442       IrOpcode::kTypedObjectState, Operator::kPure,     // opcode
1443       "TypedObjectState",                               // name
1444       static_cast<int>(types->size()), 0, 0, 1, 0, 0,   // counts
1445       TypedObjectStateInfo(object_id, types));          // parameter
1446 }
1447 
ObjectIdOf(Operator const * op)1448 uint32_t ObjectIdOf(Operator const* op) {
1449   switch (op->opcode()) {
1450     case IrOpcode::kObjectState:
1451       return OpParameter<ObjectStateInfo>(op).object_id();
1452     case IrOpcode::kTypedObjectState:
1453       return OpParameter<TypedObjectStateInfo>(op).object_id();
1454     case IrOpcode::kObjectId:
1455       return OpParameter<uint32_t>(op);
1456     default:
1457       UNREACHABLE();
1458   }
1459 }
1460 
DeadValueRepresentationOf(Operator const * op)1461 MachineRepresentation DeadValueRepresentationOf(Operator const* op) {
1462   DCHECK_EQ(IrOpcode::kDeadValue, op->opcode());
1463   return OpParameter<MachineRepresentation>(op);
1464 }
1465 
FrameState(BytecodeOffset bailout_id,OutputFrameStateCombine state_combine,const FrameStateFunctionInfo * function_info)1466 const Operator* CommonOperatorBuilder::FrameState(
1467     BytecodeOffset bailout_id, OutputFrameStateCombine state_combine,
1468     const FrameStateFunctionInfo* function_info) {
1469   FrameStateInfo state_info(bailout_id, state_combine, function_info);
1470   return zone()->New<Operator1<FrameStateInfo>>(  // --
1471       IrOpcode::kFrameState, Operator::kPure,     // opcode
1472       "FrameState",                               // name
1473       5, 0, 0, 1, 0, 0,                           // counts
1474       state_info);                                // parameter
1475 }
1476 
Call(const CallDescriptor * call_descriptor)1477 const Operator* CommonOperatorBuilder::Call(
1478     const CallDescriptor* call_descriptor) {
1479   class CallOperator final : public Operator1<const CallDescriptor*> {
1480    public:
1481     explicit CallOperator(const CallDescriptor* call_descriptor)
1482         : Operator1<const CallDescriptor*>(
1483               IrOpcode::kCall, call_descriptor->properties(), "Call",
1484               call_descriptor->InputCount() +
1485                   call_descriptor->FrameStateCount(),
1486               Operator::ZeroIfPure(call_descriptor->properties()),
1487               Operator::ZeroIfEliminatable(call_descriptor->properties()),
1488               call_descriptor->ReturnCount(),
1489               Operator::ZeroIfPure(call_descriptor->properties()),
1490               Operator::ZeroIfNoThrow(call_descriptor->properties()),
1491               call_descriptor) {}
1492 
1493     void PrintParameter(std::ostream& os,
1494                         PrintVerbosity verbose) const override {
1495       os << "[" << *parameter() << "]";
1496     }
1497   };
1498   return zone()->New<CallOperator>(call_descriptor);
1499 }
1500 
TailCall(const CallDescriptor * call_descriptor)1501 const Operator* CommonOperatorBuilder::TailCall(
1502     const CallDescriptor* call_descriptor) {
1503   class TailCallOperator final : public Operator1<const CallDescriptor*> {
1504    public:
1505     explicit TailCallOperator(const CallDescriptor* call_descriptor)
1506         : Operator1<const CallDescriptor*>(
1507               IrOpcode::kTailCall,
1508               call_descriptor->properties() | Operator::kNoThrow, "TailCall",
1509               call_descriptor->InputCount() +
1510                   call_descriptor->FrameStateCount(),
1511               1, 1, 0, 0, 1, call_descriptor) {}
1512 
1513     void PrintParameter(std::ostream& os,
1514                         PrintVerbosity verbose) const override {
1515       os << "[" << *parameter() << "]";
1516     }
1517   };
1518   return zone()->New<TailCallOperator>(call_descriptor);
1519 }
1520 
Projection(size_t index)1521 const Operator* CommonOperatorBuilder::Projection(size_t index) {
1522   switch (index) {
1523 #define CACHED_PROJECTION(index) \
1524   case index:                    \
1525     return &cache_.kProjection##index##Operator;
1526     CACHED_PROJECTION_LIST(CACHED_PROJECTION)
1527 #undef CACHED_PROJECTION
1528     default:
1529       break;
1530   }
1531   // Uncached.
1532   return zone()->New<Operator1<size_t>>(  // --
1533       IrOpcode::kProjection,              // opcode
1534       Operator::kPure,                    // flags
1535       "Projection",                       // name
1536       1, 0, 1, 1, 0, 0,                   // counts
1537       index);                             // parameter
1538 }
1539 
1540 
ResizeMergeOrPhi(const Operator * op,int size)1541 const Operator* CommonOperatorBuilder::ResizeMergeOrPhi(const Operator* op,
1542                                                         int size) {
1543   if (op->opcode() == IrOpcode::kPhi) {
1544     return Phi(PhiRepresentationOf(op), size);
1545   } else if (op->opcode() == IrOpcode::kEffectPhi) {
1546     return EffectPhi(size);
1547   } else if (op->opcode() == IrOpcode::kMerge) {
1548     return Merge(size);
1549   } else if (op->opcode() == IrOpcode::kLoop) {
1550     return Loop(size);
1551   } else {
1552     UNREACHABLE();
1553   }
1554 }
1555 
1556 const FrameStateFunctionInfo*
CreateFrameStateFunctionInfo(FrameStateType type,int parameter_count,int local_count,Handle<SharedFunctionInfo> shared_info)1557 CommonOperatorBuilder::CreateFrameStateFunctionInfo(
1558     FrameStateType type, int parameter_count, int local_count,
1559     Handle<SharedFunctionInfo> shared_info) {
1560   return zone()->New<FrameStateFunctionInfo>(type, parameter_count, local_count,
1561                                              shared_info);
1562 }
1563 
1564 #if V8_ENABLE_WEBASSEMBLY
1565 const FrameStateFunctionInfo*
CreateJSToWasmFrameStateFunctionInfo(FrameStateType type,int parameter_count,int local_count,Handle<SharedFunctionInfo> shared_info,const wasm::FunctionSig * signature)1566 CommonOperatorBuilder::CreateJSToWasmFrameStateFunctionInfo(
1567     FrameStateType type, int parameter_count, int local_count,
1568     Handle<SharedFunctionInfo> shared_info,
1569     const wasm::FunctionSig* signature) {
1570   DCHECK_EQ(type, FrameStateType::kJSToWasmBuiltinContinuation);
1571   DCHECK_NOT_NULL(signature);
1572   return zone()->New<JSToWasmFrameStateFunctionInfo>(
1573       type, parameter_count, local_count, shared_info, signature);
1574 }
1575 #endif  // V8_ENABLE_WEBASSEMBLY
1576 
DeadValue(MachineRepresentation rep)1577 const Operator* CommonOperatorBuilder::DeadValue(MachineRepresentation rep) {
1578   return zone()->New<Operator1<MachineRepresentation>>(  // --
1579       IrOpcode::kDeadValue, Operator::kPure,             // opcode
1580       "DeadValue",                                       // name
1581       1, 0, 0, 1, 0, 0,                                  // counts
1582       rep);                                              // parameter
1583 }
1584 
FrameStateInfoOf(const Operator * op)1585 const FrameStateInfo& FrameStateInfoOf(const Operator* op) {
1586   DCHECK_EQ(IrOpcode::kFrameState, op->opcode());
1587   return OpParameter<FrameStateInfo>(op);
1588 }
1589 
1590 #undef COMMON_CACHED_OP_LIST
1591 #undef CACHED_BRANCH_LIST
1592 #undef CACHED_RETURN_LIST
1593 #undef CACHED_END_LIST
1594 #undef CACHED_EFFECT_PHI_LIST
1595 #undef CACHED_INDUCTION_VARIABLE_PHI_LIST
1596 #undef CACHED_LOOP_LIST
1597 #undef CACHED_MERGE_LIST
1598 #undef CACHED_DEOPTIMIZE_LIST
1599 #undef CACHED_DEOPTIMIZE_IF_LIST
1600 #undef CACHED_DEOPTIMIZE_UNLESS_LIST
1601 #undef CACHED_TRAP_IF_LIST
1602 #undef CACHED_TRAP_UNLESS_LIST
1603 #undef CACHED_PARAMETER_LIST
1604 #undef CACHED_PHI_LIST
1605 #undef CACHED_PROJECTION_LIST
1606 #undef CACHED_STATE_VALUES_LIST
1607 
1608 }  // namespace compiler
1609 }  // namespace internal
1610 }  // namespace v8
1611