blob: 4f5ead89eb02b2d41a159a7a1a69e24426e3a949 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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/assembler.h"
8#include "src/base/lazy-instance.h"
9#include "src/compiler/linkage.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010#include "src/compiler/opcodes.h"
11#include "src/compiler/operator.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/handles-inl.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013#include "src/zone.h"
14
15namespace v8 {
16namespace internal {
17namespace compiler {
18
Emily Bernierd0a1eb72015-03-24 16:35:39 -040019std::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";
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040028 UNREACHABLE();
29 return os;
30}
31
32
33BranchHint BranchHintOf(const Operator* const op) {
34 DCHECK_EQ(IrOpcode::kBranch, op->opcode());
35 return OpParameter<BranchHint>(op);
36}
37
38
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039size_t hash_value(DeoptimizeKind kind) { return static_cast<size_t>(kind); }
40
41
42std::ostream& operator<<(std::ostream& os, DeoptimizeKind kind) {
43 switch (kind) {
44 case DeoptimizeKind::kEager:
45 return os << "Eager";
46 case DeoptimizeKind::kSoft:
47 return os << "Soft";
48 }
49 UNREACHABLE();
50 return os;
51}
52
53
54DeoptimizeKind DeoptimizeKindOf(const Operator* const op) {
55 DCHECK_EQ(IrOpcode::kDeoptimize, op->opcode());
56 return OpParameter<DeoptimizeKind>(op);
57}
58
59
60size_t hash_value(IfExceptionHint hint) { return static_cast<size_t>(hint); }
61
62
63std::ostream& operator<<(std::ostream& os, IfExceptionHint hint) {
64 switch (hint) {
65 case IfExceptionHint::kLocallyCaught:
66 return os << "Caught";
67 case IfExceptionHint::kLocallyUncaught:
68 return os << "Uncaught";
69 }
70 UNREACHABLE();
71 return os;
72}
73
74
Emily Bernierd0a1eb72015-03-24 16:35:39 -040075bool operator==(SelectParameters const& lhs, SelectParameters const& rhs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000076 return lhs.representation() == rhs.representation() &&
77 lhs.hint() == rhs.hint();
Emily Bernierd0a1eb72015-03-24 16:35:39 -040078}
79
80
81bool operator!=(SelectParameters const& lhs, SelectParameters const& rhs) {
82 return !(lhs == rhs);
83}
84
85
86size_t hash_value(SelectParameters const& p) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000087 return base::hash_combine(p.representation(), p.hint());
Emily Bernierd0a1eb72015-03-24 16:35:39 -040088}
89
90
91std::ostream& operator<<(std::ostream& os, SelectParameters const& p) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092 return os << p.representation() << "|" << p.hint();
Emily Bernierd0a1eb72015-03-24 16:35:39 -040093}
94
95
96SelectParameters const& SelectParametersOf(const Operator* const op) {
97 DCHECK_EQ(IrOpcode::kSelect, op->opcode());
98 return OpParameter<SelectParameters>(op);
99}
100
Ben Murdochc5610432016-08-08 18:44:38 +0100101CallDescriptor const* CallDescriptorOf(const Operator* const op) {
102 DCHECK(op->opcode() == IrOpcode::kCall ||
103 op->opcode() == IrOpcode::kTailCall);
104 return OpParameter<CallDescriptor const*>(op);
105}
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400106
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000107size_t ProjectionIndexOf(const Operator* const op) {
108 DCHECK_EQ(IrOpcode::kProjection, op->opcode());
109 return OpParameter<size_t>(op);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400110}
111
112
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000113MachineRepresentation PhiRepresentationOf(const Operator* const op) {
114 DCHECK_EQ(IrOpcode::kPhi, op->opcode());
115 return OpParameter<MachineRepresentation>(op);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400116}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000117
118
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000119int ParameterIndexOf(const Operator* const op) {
120 DCHECK_EQ(IrOpcode::kParameter, op->opcode());
121 return OpParameter<ParameterInfo>(op).index();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400122}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000123
124
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000125const ParameterInfo& ParameterInfoOf(const Operator* const op) {
126 DCHECK_EQ(IrOpcode::kParameter, op->opcode());
127 return OpParameter<ParameterInfo>(op);
128}
129
130
131bool operator==(ParameterInfo const& lhs, ParameterInfo const& rhs) {
132 return lhs.index() == rhs.index();
133}
134
135
136bool operator!=(ParameterInfo const& lhs, ParameterInfo const& rhs) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400137 return !(lhs == rhs);
138}
139
140
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141size_t hash_value(ParameterInfo const& p) { return p.index(); }
142
143
144std::ostream& operator<<(std::ostream& os, ParameterInfo const& i) {
145 if (i.debug_name()) os << i.debug_name() << '#';
146 os << i.index();
147 return os;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400148}
149
Ben Murdochc5610432016-08-08 18:44:38 +0100150bool operator==(RelocatablePtrConstantInfo const& lhs,
151 RelocatablePtrConstantInfo const& rhs) {
152 return lhs.rmode() == rhs.rmode() && lhs.value() == rhs.value() &&
153 lhs.type() == rhs.type();
154}
155
156bool operator!=(RelocatablePtrConstantInfo const& lhs,
157 RelocatablePtrConstantInfo const& rhs) {
158 return !(lhs == rhs);
159}
160
161size_t hash_value(RelocatablePtrConstantInfo const& p) {
162 return base::hash_combine(p.value(), p.rmode(), p.type());
163}
164
165std::ostream& operator<<(std::ostream& os,
166 RelocatablePtrConstantInfo const& p) {
167 return os << p.value() << "|" << p.rmode() << "|" << p.type();
168}
169
Ben Murdoch61f157c2016-09-16 13:49:30 +0100170size_t hash_value(RegionObservability observability) {
171 return static_cast<size_t>(observability);
172}
173
174std::ostream& operator<<(std::ostream& os, RegionObservability observability) {
175 switch (observability) {
176 case RegionObservability::kObservable:
177 return os << "observable";
178 case RegionObservability::kNotObservable:
179 return os << "not-observable";
180 }
181 UNREACHABLE();
182 return os;
183}
184
185RegionObservability RegionObservabilityOf(Operator const* op) {
186 DCHECK_EQ(IrOpcode::kBeginRegion, op->opcode());
187 return OpParameter<RegionObservability>(op);
188}
189
190std::ostream& operator<<(std::ostream& os,
191 const ZoneVector<MachineType>* types) {
192 // Print all the MachineTypes, separated by commas.
193 bool first = true;
194 for (MachineType elem : *types) {
195 if (!first) {
196 os << ", ";
197 }
198 first = false;
199 os << elem;
200 }
201 return os;
202}
203
Ben Murdochda12d292016-06-02 14:46:10 +0100204#define CACHED_OP_LIST(V) \
205 V(Dead, Operator::kFoldable, 0, 0, 0, 1, 1, 1) \
Ben Murdoch61f157c2016-09-16 13:49:30 +0100206 V(DeoptimizeIf, Operator::kFoldable, 2, 1, 1, 0, 1, 1) \
207 V(DeoptimizeUnless, Operator::kFoldable, 2, 1, 1, 0, 1, 1) \
Ben Murdochda12d292016-06-02 14:46:10 +0100208 V(IfTrue, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \
209 V(IfFalse, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \
210 V(IfSuccess, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \
211 V(IfDefault, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \
212 V(Throw, Operator::kKontrol, 1, 1, 1, 0, 0, 1) \
213 V(Terminate, Operator::kKontrol, 0, 1, 1, 0, 0, 1) \
214 V(OsrNormalEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) \
215 V(OsrLoopEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) \
Ben Murdoch61f157c2016-09-16 13:49:30 +0100216 V(Checkpoint, Operator::kKontrol, 0, 1, 1, 0, 1, 0) \
217 V(FinishRegion, Operator::kKontrol, 1, 1, 0, 1, 1, 0)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400218
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000219#define CACHED_RETURN_LIST(V) \
220 V(1) \
221 V(2) \
222 V(3)
223
224
225#define CACHED_END_LIST(V) \
226 V(1) \
227 V(2) \
228 V(3) \
229 V(4) \
230 V(5) \
231 V(6) \
232 V(7) \
233 V(8)
234
235
236#define CACHED_EFFECT_PHI_LIST(V) \
237 V(1) \
238 V(2) \
239 V(3) \
240 V(4) \
241 V(5) \
242 V(6)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400243
244
245#define CACHED_LOOP_LIST(V) \
246 V(1) \
247 V(2)
248
249
250#define CACHED_MERGE_LIST(V) \
251 V(1) \
252 V(2) \
253 V(3) \
254 V(4) \
255 V(5) \
256 V(6) \
257 V(7) \
258 V(8)
259
260
261#define CACHED_PARAMETER_LIST(V) \
262 V(0) \
263 V(1) \
264 V(2) \
265 V(3) \
266 V(4) \
267 V(5) \
268 V(6)
269
270
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000271#define CACHED_PHI_LIST(V) \
272 V(kTagged, 1) \
273 V(kTagged, 2) \
274 V(kTagged, 3) \
275 V(kTagged, 4) \
276 V(kTagged, 5) \
277 V(kTagged, 6) \
278 V(kBit, 2) \
279 V(kFloat64, 2) \
280 V(kWord32, 2)
281
282
283#define CACHED_PROJECTION_LIST(V) \
284 V(0) \
285 V(1)
286
287
288#define CACHED_STATE_VALUES_LIST(V) \
289 V(0) \
290 V(1) \
291 V(2) \
292 V(3) \
293 V(4) \
294 V(5) \
295 V(6) \
296 V(7) \
297 V(8) \
298 V(10) \
299 V(11) \
300 V(12) \
301 V(13) \
302 V(14)
303
304
305struct CommonOperatorGlobalCache final {
306#define CACHED(Name, properties, value_input_count, effect_input_count, \
307 control_input_count, value_output_count, effect_output_count, \
308 control_output_count) \
309 struct Name##Operator final : public Operator { \
310 Name##Operator() \
311 : Operator(IrOpcode::k##Name, properties, #Name, value_input_count, \
312 effect_input_count, control_input_count, \
313 value_output_count, effect_output_count, \
314 control_output_count) {} \
315 }; \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000316 Name##Operator k##Name##Operator;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400317 CACHED_OP_LIST(CACHED)
318#undef CACHED
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000319
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000320 template <DeoptimizeKind kKind>
321 struct DeoptimizeOperator final : public Operator1<DeoptimizeKind> {
322 DeoptimizeOperator()
323 : Operator1<DeoptimizeKind>( // --
324 IrOpcode::kDeoptimize, Operator::kNoThrow, // opcode
325 "Deoptimize", // name
326 1, 1, 1, 0, 0, 1, // counts
327 kKind) {} // parameter
328 };
329 DeoptimizeOperator<DeoptimizeKind::kEager> kDeoptimizeEagerOperator;
330 DeoptimizeOperator<DeoptimizeKind::kSoft> kDeoptimizeSoftOperator;
331
332 template <IfExceptionHint kCaughtLocally>
333 struct IfExceptionOperator final : public Operator1<IfExceptionHint> {
334 IfExceptionOperator()
335 : Operator1<IfExceptionHint>( // --
336 IrOpcode::kIfException, Operator::kKontrol, // opcode
337 "IfException", // name
338 0, 1, 1, 1, 1, 1, // counts
339 kCaughtLocally) {} // parameter
340 };
341 IfExceptionOperator<IfExceptionHint::kLocallyCaught> kIfExceptionCOperator;
342 IfExceptionOperator<IfExceptionHint::kLocallyUncaught> kIfExceptionUOperator;
343
344 template <size_t kInputCount>
345 struct EndOperator final : public Operator {
346 EndOperator()
347 : Operator( // --
348 IrOpcode::kEnd, Operator::kKontrol, // opcode
349 "End", // name
350 0, 0, kInputCount, 0, 0, 0) {} // counts
351 };
352#define CACHED_END(input_count) \
353 EndOperator<input_count> kEnd##input_count##Operator;
354 CACHED_END_LIST(CACHED_END)
355#undef CACHED_END
356
357 template <size_t kInputCount>
358 struct ReturnOperator final : public Operator {
359 ReturnOperator()
360 : Operator( // --
361 IrOpcode::kReturn, Operator::kNoThrow, // opcode
362 "Return", // name
363 kInputCount, 1, 1, 0, 0, 1) {} // counts
364 };
365#define CACHED_RETURN(input_count) \
366 ReturnOperator<input_count> kReturn##input_count##Operator;
367 CACHED_RETURN_LIST(CACHED_RETURN)
368#undef CACHED_RETURN
369
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400370 template <BranchHint kBranchHint>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000371 struct BranchOperator final : public Operator1<BranchHint> {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400372 BranchOperator()
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000373 : Operator1<BranchHint>( // --
374 IrOpcode::kBranch, Operator::kKontrol, // opcode
375 "Branch", // name
376 1, 0, 1, 0, 0, 2, // counts
377 kBranchHint) {} // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000378 };
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400379 BranchOperator<BranchHint::kNone> kBranchNoneOperator;
380 BranchOperator<BranchHint::kTrue> kBranchTrueOperator;
381 BranchOperator<BranchHint::kFalse> kBranchFalseOperator;
382
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000383 template <int kEffectInputCount>
384 struct EffectPhiOperator final : public Operator {
385 EffectPhiOperator()
386 : Operator( // --
387 IrOpcode::kEffectPhi, Operator::kPure, // opcode
388 "EffectPhi", // name
389 0, kEffectInputCount, 1, 0, 1, 0) {} // counts
390 };
391#define CACHED_EFFECT_PHI(input_count) \
392 EffectPhiOperator<input_count> kEffectPhi##input_count##Operator;
393 CACHED_EFFECT_PHI_LIST(CACHED_EFFECT_PHI)
394#undef CACHED_EFFECT_PHI
395
Ben Murdoch61f157c2016-09-16 13:49:30 +0100396 template <RegionObservability kRegionObservability>
397 struct BeginRegionOperator final : public Operator1<RegionObservability> {
398 BeginRegionOperator()
399 : Operator1<RegionObservability>( // --
400 IrOpcode::kBeginRegion, Operator::kKontrol, // opcode
401 "BeginRegion", // name
402 0, 1, 0, 0, 1, 0, // counts
403 kRegionObservability) {} // parameter
404 };
405 BeginRegionOperator<RegionObservability::kObservable>
406 kBeginRegionObservableOperator;
407 BeginRegionOperator<RegionObservability::kNotObservable>
408 kBeginRegionNotObservableOperator;
409
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400410 template <size_t kInputCount>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000411 struct LoopOperator final : public Operator {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400412 LoopOperator()
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000413 : Operator( // --
414 IrOpcode::kLoop, Operator::kKontrol, // opcode
415 "Loop", // name
416 0, 0, kInputCount, 0, 0, 1) {} // counts
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400417 };
418#define CACHED_LOOP(input_count) \
419 LoopOperator<input_count> kLoop##input_count##Operator;
420 CACHED_LOOP_LIST(CACHED_LOOP)
421#undef CACHED_LOOP
422
423 template <size_t kInputCount>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000424 struct MergeOperator final : public Operator {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400425 MergeOperator()
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000426 : Operator( // --
427 IrOpcode::kMerge, Operator::kKontrol, // opcode
428 "Merge", // name
429 0, 0, kInputCount, 0, 0, 1) {} // counts
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400430 };
431#define CACHED_MERGE(input_count) \
432 MergeOperator<input_count> kMerge##input_count##Operator;
433 CACHED_MERGE_LIST(CACHED_MERGE)
434#undef CACHED_MERGE
435
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000436 template <MachineRepresentation kRep, int kInputCount>
437 struct PhiOperator final : public Operator1<MachineRepresentation> {
438 PhiOperator()
439 : Operator1<MachineRepresentation>( //--
440 IrOpcode::kPhi, Operator::kPure, // opcode
441 "Phi", // name
442 kInputCount, 0, 1, 1, 0, 0, // counts
443 kRep) {} // parameter
444 };
445#define CACHED_PHI(rep, input_count) \
446 PhiOperator<MachineRepresentation::rep, input_count> \
447 kPhi##rep##input_count##Operator;
448 CACHED_PHI_LIST(CACHED_PHI)
449#undef CACHED_PHI
450
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400451 template <int kIndex>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000452 struct ParameterOperator final : public Operator1<ParameterInfo> {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400453 ParameterOperator()
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000454 : Operator1<ParameterInfo>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400455 IrOpcode::kParameter, Operator::kPure, // opcode
456 "Parameter", // name
457 1, 0, 0, 1, 0, 0, // counts,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000458 ParameterInfo(kIndex, nullptr)) {} // parameter and name
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400459 };
460#define CACHED_PARAMETER(index) \
461 ParameterOperator<index> kParameter##index##Operator;
462 CACHED_PARAMETER_LIST(CACHED_PARAMETER)
463#undef CACHED_PARAMETER
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000464
465 template <size_t kIndex>
466 struct ProjectionOperator final : public Operator1<size_t> {
467 ProjectionOperator()
468 : Operator1<size_t>( // --
469 IrOpcode::kProjection, // opcode
470 Operator::kPure, // flags
471 "Projection", // name
Ben Murdoch61f157c2016-09-16 13:49:30 +0100472 1, 0, 1, 1, 0, 0, // counts,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000473 kIndex) {} // parameter
474 };
475#define CACHED_PROJECTION(index) \
476 ProjectionOperator<index> kProjection##index##Operator;
477 CACHED_PROJECTION_LIST(CACHED_PROJECTION)
478#undef CACHED_PROJECTION
479
480 template <int kInputCount>
481 struct StateValuesOperator final : public Operator {
482 StateValuesOperator()
483 : Operator( // --
484 IrOpcode::kStateValues, // opcode
485 Operator::kPure, // flags
486 "StateValues", // name
487 kInputCount, 0, 0, 1, 0, 0) {} // counts
488 };
489#define CACHED_STATE_VALUES(input_count) \
490 StateValuesOperator<input_count> kStateValues##input_count##Operator;
491 CACHED_STATE_VALUES_LIST(CACHED_STATE_VALUES)
492#undef CACHED_STATE_VALUES
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000493};
494
495
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400496static base::LazyInstance<CommonOperatorGlobalCache>::type kCache =
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000497 LAZY_INSTANCE_INITIALIZER;
498
499
500CommonOperatorBuilder::CommonOperatorBuilder(Zone* zone)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400501 : cache_(kCache.Get()), zone_(zone) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000502
503
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000504#define CACHED(Name, properties, value_input_count, effect_input_count, \
505 control_input_count, value_output_count, effect_output_count, \
506 control_output_count) \
507 const Operator* CommonOperatorBuilder::Name() { \
508 return &cache_.k##Name##Operator; \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000509 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400510CACHED_OP_LIST(CACHED)
511#undef CACHED
512
513
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000514const Operator* CommonOperatorBuilder::End(size_t control_input_count) {
515 switch (control_input_count) {
516#define CACHED_END(input_count) \
517 case input_count: \
518 return &cache_.kEnd##input_count##Operator;
519 CACHED_END_LIST(CACHED_END)
520#undef CACHED_END
521 default:
522 break;
523 }
524 // Uncached.
525 return new (zone()) Operator( //--
526 IrOpcode::kEnd, Operator::kKontrol, // opcode
527 "End", // name
528 0, 0, control_input_count, 0, 0, 0); // counts
529}
530
531
532const Operator* CommonOperatorBuilder::Return(int value_input_count) {
533 switch (value_input_count) {
534#define CACHED_RETURN(input_count) \
535 case input_count: \
536 return &cache_.kReturn##input_count##Operator;
537 CACHED_RETURN_LIST(CACHED_RETURN)
538#undef CACHED_RETURN
539 default:
540 break;
541 }
542 // Uncached.
543 return new (zone()) Operator( //--
544 IrOpcode::kReturn, Operator::kNoThrow, // opcode
545 "Return", // name
546 value_input_count, 1, 1, 0, 0, 1); // counts
547}
548
549
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400550const Operator* CommonOperatorBuilder::Branch(BranchHint hint) {
551 switch (hint) {
552 case BranchHint::kNone:
553 return &cache_.kBranchNoneOperator;
554 case BranchHint::kTrue:
555 return &cache_.kBranchTrueOperator;
556 case BranchHint::kFalse:
557 return &cache_.kBranchFalseOperator;
558 }
559 UNREACHABLE();
560 return nullptr;
561}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000562
563
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000564const Operator* CommonOperatorBuilder::Deoptimize(DeoptimizeKind kind) {
565 switch (kind) {
566 case DeoptimizeKind::kEager:
567 return &cache_.kDeoptimizeEagerOperator;
568 case DeoptimizeKind::kSoft:
569 return &cache_.kDeoptimizeSoftOperator;
570 }
571 UNREACHABLE();
572 return nullptr;
573}
574
575
576const Operator* CommonOperatorBuilder::IfException(IfExceptionHint hint) {
577 switch (hint) {
578 case IfExceptionHint::kLocallyCaught:
579 return &cache_.kIfExceptionCOperator;
580 case IfExceptionHint::kLocallyUncaught:
581 return &cache_.kIfExceptionUOperator;
582 }
583 UNREACHABLE();
584 return nullptr;
585}
586
587
588const Operator* CommonOperatorBuilder::Switch(size_t control_output_count) {
589 return new (zone()) Operator( // --
590 IrOpcode::kSwitch, Operator::kKontrol, // opcode
591 "Switch", // name
592 1, 0, 1, 0, 0, control_output_count); // counts
593}
594
595
596const Operator* CommonOperatorBuilder::IfValue(int32_t index) {
597 return new (zone()) Operator1<int32_t>( // --
598 IrOpcode::kIfValue, Operator::kKontrol, // opcode
599 "IfValue", // name
600 0, 0, 1, 0, 0, 1, // counts
601 index); // parameter
602}
603
604
605const Operator* CommonOperatorBuilder::Start(int value_output_count) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400606 return new (zone()) Operator( // --
607 IrOpcode::kStart, Operator::kFoldable, // opcode
608 "Start", // name
609 0, 0, 0, value_output_count, 1, 1); // counts
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000610}
611
612
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400613const Operator* CommonOperatorBuilder::Loop(int control_input_count) {
614 switch (control_input_count) {
615#define CACHED_LOOP(input_count) \
616 case input_count: \
617 return &cache_.kLoop##input_count##Operator;
618 CACHED_LOOP_LIST(CACHED_LOOP)
619#undef CACHED_LOOP
620 default:
621 break;
622 }
623 // Uncached.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000624 return new (zone()) Operator( // --
625 IrOpcode::kLoop, Operator::kKontrol, // opcode
626 "Loop", // name
627 0, 0, control_input_count, 0, 0, 1); // counts
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000628}
629
630
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400631const Operator* CommonOperatorBuilder::Merge(int control_input_count) {
632 switch (control_input_count) {
633#define CACHED_MERGE(input_count) \
634 case input_count: \
635 return &cache_.kMerge##input_count##Operator;
636 CACHED_MERGE_LIST(CACHED_MERGE)
637#undef CACHED_MERGE
638 default:
639 break;
640 }
641 // Uncached.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000642 return new (zone()) Operator( // --
643 IrOpcode::kMerge, Operator::kKontrol, // opcode
644 "Merge", // name
645 0, 0, control_input_count, 0, 0, 1); // counts
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400646}
647
648
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000649const Operator* CommonOperatorBuilder::Parameter(int index,
650 const char* debug_name) {
651 if (!debug_name) {
652 switch (index) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400653#define CACHED_PARAMETER(index) \
654 case index: \
655 return &cache_.kParameter##index##Operator;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000656 CACHED_PARAMETER_LIST(CACHED_PARAMETER)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400657#undef CACHED_PARAMETER
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000658 default:
659 break;
660 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400661 }
662 // Uncached.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000663 return new (zone()) Operator1<ParameterInfo>( // --
664 IrOpcode::kParameter, Operator::kPure, // opcode
665 "Parameter", // name
666 1, 0, 0, 1, 0, 0, // counts
667 ParameterInfo(index, debug_name)); // parameter info
668}
669
670
671const Operator* CommonOperatorBuilder::OsrValue(int index) {
672 return new (zone()) Operator1<int>( // --
673 IrOpcode::kOsrValue, Operator::kNoProperties, // opcode
674 "OsrValue", // name
675 0, 0, 1, 1, 0, 0, // counts
676 index); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000677}
678
679
680const Operator* CommonOperatorBuilder::Int32Constant(int32_t value) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400681 return new (zone()) Operator1<int32_t>( // --
682 IrOpcode::kInt32Constant, Operator::kPure, // opcode
683 "Int32Constant", // name
684 0, 0, 0, 1, 0, 0, // counts
685 value); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000686}
687
688
689const Operator* CommonOperatorBuilder::Int64Constant(int64_t value) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400690 return new (zone()) Operator1<int64_t>( // --
691 IrOpcode::kInt64Constant, Operator::kPure, // opcode
692 "Int64Constant", // name
693 0, 0, 0, 1, 0, 0, // counts
694 value); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000695}
696
697
698const Operator* CommonOperatorBuilder::Float32Constant(volatile float value) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000699 return new (zone()) Operator1<float>( // --
700 IrOpcode::kFloat32Constant, Operator::kPure, // opcode
701 "Float32Constant", // name
702 0, 0, 0, 1, 0, 0, // counts
703 value); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000704}
705
706
707const Operator* CommonOperatorBuilder::Float64Constant(volatile double value) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000708 return new (zone()) Operator1<double>( // --
709 IrOpcode::kFloat64Constant, Operator::kPure, // opcode
710 "Float64Constant", // name
711 0, 0, 0, 1, 0, 0, // counts
712 value); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000713}
714
715
716const Operator* CommonOperatorBuilder::ExternalConstant(
717 const ExternalReference& value) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400718 return new (zone()) Operator1<ExternalReference>( // --
719 IrOpcode::kExternalConstant, Operator::kPure, // opcode
720 "ExternalConstant", // name
721 0, 0, 0, 1, 0, 0, // counts
722 value); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000723}
724
725
726const Operator* CommonOperatorBuilder::NumberConstant(volatile double value) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000727 return new (zone()) Operator1<double>( // --
728 IrOpcode::kNumberConstant, Operator::kPure, // opcode
729 "NumberConstant", // name
730 0, 0, 0, 1, 0, 0, // counts
731 value); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000732}
733
734
735const Operator* CommonOperatorBuilder::HeapConstant(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000736 const Handle<HeapObject>& value) {
737 return new (zone()) Operator1<Handle<HeapObject>>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400738 IrOpcode::kHeapConstant, Operator::kPure, // opcode
739 "HeapConstant", // name
740 0, 0, 0, 1, 0, 0, // counts
741 value); // parameter
742}
743
Ben Murdochc5610432016-08-08 18:44:38 +0100744const Operator* CommonOperatorBuilder::RelocatableInt32Constant(
745 int32_t value, RelocInfo::Mode rmode) {
746 return new (zone()) Operator1<RelocatablePtrConstantInfo>( // --
747 IrOpcode::kRelocatableInt32Constant, Operator::kPure, // opcode
748 "RelocatableInt32Constant", // name
749 0, 0, 0, 1, 0, 0, // counts
750 RelocatablePtrConstantInfo(value, rmode)); // parameter
751}
752
753const Operator* CommonOperatorBuilder::RelocatableInt64Constant(
754 int64_t value, RelocInfo::Mode rmode) {
755 return new (zone()) Operator1<RelocatablePtrConstantInfo>( // --
756 IrOpcode::kRelocatableInt64Constant, Operator::kPure, // opcode
757 "RelocatableInt64Constant", // name
758 0, 0, 0, 1, 0, 0, // counts
759 RelocatablePtrConstantInfo(value, rmode)); // parameter
760}
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400761
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000762const Operator* CommonOperatorBuilder::Select(MachineRepresentation rep,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400763 BranchHint hint) {
764 return new (zone()) Operator1<SelectParameters>( // --
765 IrOpcode::kSelect, Operator::kPure, // opcode
766 "Select", // name
767 3, 0, 0, 1, 0, 0, // counts
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000768 SelectParameters(rep, hint)); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000769}
770
771
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000772const Operator* CommonOperatorBuilder::Phi(MachineRepresentation rep,
773 int value_input_count) {
774 DCHECK(value_input_count > 0); // Disallow empty phis.
775#define CACHED_PHI(kRep, kValueInputCount) \
776 if (MachineRepresentation::kRep == rep && \
777 kValueInputCount == value_input_count) { \
778 return &cache_.kPhi##kRep##kValueInputCount##Operator; \
779 }
780 CACHED_PHI_LIST(CACHED_PHI)
781#undef CACHED_PHI
782 // Uncached.
783 return new (zone()) Operator1<MachineRepresentation>( // --
784 IrOpcode::kPhi, Operator::kPure, // opcode
785 "Phi", // name
786 value_input_count, 0, 1, 1, 0, 0, // counts
787 rep); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000788}
789
790
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000791const Operator* CommonOperatorBuilder::EffectPhi(int effect_input_count) {
792 DCHECK(effect_input_count > 0); // Disallow empty effect phis.
793 switch (effect_input_count) {
794#define CACHED_EFFECT_PHI(input_count) \
795 case input_count: \
796 return &cache_.kEffectPhi##input_count##Operator;
797 CACHED_EFFECT_PHI_LIST(CACHED_EFFECT_PHI)
798#undef CACHED_EFFECT_PHI
799 default:
800 break;
801 }
802 // Uncached.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400803 return new (zone()) Operator( // --
804 IrOpcode::kEffectPhi, Operator::kPure, // opcode
805 "EffectPhi", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000806 0, effect_input_count, 1, 0, 1, 0); // counts
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000807}
808
Ben Murdoch61f157c2016-09-16 13:49:30 +0100809const Operator* CommonOperatorBuilder::BeginRegion(
810 RegionObservability region_observability) {
811 switch (region_observability) {
812 case RegionObservability::kObservable:
813 return &cache_.kBeginRegionObservableOperator;
814 case RegionObservability::kNotObservable:
815 return &cache_.kBeginRegionNotObservableOperator;
816 }
817 UNREACHABLE();
818 return nullptr;
819}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000820
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000821const Operator* CommonOperatorBuilder::StateValues(int arguments) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000822 switch (arguments) {
823#define CACHED_STATE_VALUES(arguments) \
824 case arguments: \
825 return &cache_.kStateValues##arguments##Operator;
826 CACHED_STATE_VALUES_LIST(CACHED_STATE_VALUES)
827#undef CACHED_STATE_VALUES
828 default:
829 break;
830 }
831 // Uncached.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400832 return new (zone()) Operator( // --
833 IrOpcode::kStateValues, Operator::kPure, // opcode
834 "StateValues", // name
835 arguments, 0, 0, 1, 0, 0); // counts
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000836}
837
838
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000839const Operator* CommonOperatorBuilder::ObjectState(int pointer_slots, int id) {
840 return new (zone()) Operator1<int>( // --
841 IrOpcode::kObjectState, Operator::kPure, // opcode
842 "ObjectState", // name
843 pointer_slots, 0, 0, 1, 0, 0, id); // counts
844}
845
846
847const Operator* CommonOperatorBuilder::TypedStateValues(
848 const ZoneVector<MachineType>* types) {
849 return new (zone()) Operator1<const ZoneVector<MachineType>*>( // --
850 IrOpcode::kTypedStateValues, Operator::kPure, // opcode
851 "TypedStateValues", // name
852 static_cast<int>(types->size()), 0, 0, 1, 0, 0, types); // counts
853}
854
855
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000856const Operator* CommonOperatorBuilder::FrameState(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000857 BailoutId bailout_id, OutputFrameStateCombine state_combine,
858 const FrameStateFunctionInfo* function_info) {
859 FrameStateInfo state_info(bailout_id, state_combine, function_info);
860 return new (zone()) Operator1<FrameStateInfo>( // --
861 IrOpcode::kFrameState, Operator::kPure, // opcode
862 "FrameState", // name
863 5, 0, 0, 1, 0, 0, // counts
864 state_info); // parameter
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000865}
866
867
868const Operator* CommonOperatorBuilder::Call(const CallDescriptor* descriptor) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000869 class CallOperator final : public Operator1<const CallDescriptor*> {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000870 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000871 explicit CallOperator(const CallDescriptor* descriptor)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000872 : Operator1<const CallDescriptor*>(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000873 IrOpcode::kCall, descriptor->properties(), "Call",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400874 descriptor->InputCount() + descriptor->FrameStateCount(),
875 Operator::ZeroIfPure(descriptor->properties()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000876 Operator::ZeroIfEliminatable(descriptor->properties()),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400877 descriptor->ReturnCount(),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000878 Operator::ZeroIfPure(descriptor->properties()),
879 Operator::ZeroIfNoThrow(descriptor->properties()), descriptor) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000880
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000881 void PrintParameter(std::ostream& os) const override {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400882 os << "[" << *parameter() << "]";
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000883 }
884 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000885 return new (zone()) CallOperator(descriptor);
886}
887
888
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000889const Operator* CommonOperatorBuilder::TailCall(
890 const CallDescriptor* descriptor) {
891 class TailCallOperator final : public Operator1<const CallDescriptor*> {
892 public:
893 explicit TailCallOperator(const CallDescriptor* descriptor)
894 : Operator1<const CallDescriptor*>(
895 IrOpcode::kTailCall, descriptor->properties(), "TailCall",
896 descriptor->InputCount() + descriptor->FrameStateCount(), 1, 1, 0,
897 0, 1, descriptor) {}
898
899 void PrintParameter(std::ostream& os) const override {
900 os << "[" << *parameter() << "]";
901 }
902 };
903 return new (zone()) TailCallOperator(descriptor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000904}
905
906
907const Operator* CommonOperatorBuilder::Projection(size_t index) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000908 switch (index) {
909#define CACHED_PROJECTION(index) \
910 case index: \
911 return &cache_.kProjection##index##Operator;
912 CACHED_PROJECTION_LIST(CACHED_PROJECTION)
913#undef CACHED_PROJECTION
914 default:
915 break;
916 }
917 // Uncached.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100918 return new (zone()) Operator1<size_t>( // --
919 IrOpcode::kProjection, // opcode
920 Operator::kPure, // flags
921 "Projection", // name
922 1, 0, 1, 1, 0, 0, // counts
923 index); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000924}
925
926
927const Operator* CommonOperatorBuilder::ResizeMergeOrPhi(const Operator* op,
928 int size) {
929 if (op->opcode() == IrOpcode::kPhi) {
930 return Phi(PhiRepresentationOf(op), size);
931 } else if (op->opcode() == IrOpcode::kEffectPhi) {
932 return EffectPhi(size);
933 } else if (op->opcode() == IrOpcode::kMerge) {
934 return Merge(size);
935 } else if (op->opcode() == IrOpcode::kLoop) {
936 return Loop(size);
937 } else {
938 UNREACHABLE();
939 return nullptr;
940 }
941}
942
943
944const FrameStateFunctionInfo*
945CommonOperatorBuilder::CreateFrameStateFunctionInfo(
946 FrameStateType type, int parameter_count, int local_count,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100947 Handle<SharedFunctionInfo> shared_info) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000948 return new (zone()->New(sizeof(FrameStateFunctionInfo)))
Ben Murdoch097c5b22016-05-18 11:27:45 +0100949 FrameStateFunctionInfo(type, parameter_count, local_count, shared_info);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000950}
951
952} // namespace compiler
953} // namespace internal
954} // namespace v8