blob: 98e090b509424212910590f3699487188c9e900b [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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/js-operator.h"
6
7#include <limits>
8
9#include "src/base/lazy-instance.h"
10#include "src/compiler/opcodes.h"
11#include "src/compiler/operator.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker!
13#include "src/type-feedback-vector-inl.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040014
15namespace v8 {
16namespace internal {
17namespace compiler {
18
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019VectorSlotPair::VectorSlotPair() {}
20
21
22int VectorSlotPair::index() const {
23 return vector_.is_null() ? -1 : vector_->GetIndex(slot_);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040024}
25
26
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027bool operator==(VectorSlotPair const& lhs, VectorSlotPair const& rhs) {
28 return lhs.slot() == rhs.slot() &&
29 lhs.vector().location() == rhs.vector().location();
30}
31
32
33bool operator!=(VectorSlotPair const& lhs, VectorSlotPair const& rhs) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040034 return !(lhs == rhs);
35}
36
37
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038size_t hash_value(VectorSlotPair const& p) {
39 return base::hash_combine(p.slot(), p.vector().location());
40}
41
42
43ConvertReceiverMode ConvertReceiverModeOf(Operator const* op) {
44 DCHECK_EQ(IrOpcode::kJSConvertReceiver, op->opcode());
45 return OpParameter<ConvertReceiverMode>(op);
46}
47
48
49ToBooleanHints ToBooleanHintsOf(Operator const* op) {
50 DCHECK_EQ(IrOpcode::kJSToBoolean, op->opcode());
51 return OpParameter<ToBooleanHints>(op);
52}
53
54
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000055bool operator==(CallConstructParameters const& lhs,
56 CallConstructParameters const& rhs) {
57 return lhs.arity() == rhs.arity() && lhs.feedback() == rhs.feedback();
58}
59
60
61bool operator!=(CallConstructParameters const& lhs,
62 CallConstructParameters const& rhs) {
63 return !(lhs == rhs);
64}
65
66
67size_t hash_value(CallConstructParameters const& p) {
68 return base::hash_combine(p.arity(), p.feedback());
69}
70
71
72std::ostream& operator<<(std::ostream& os, CallConstructParameters const& p) {
73 return os << p.arity();
74}
75
76
77CallConstructParameters const& CallConstructParametersOf(Operator const* op) {
78 DCHECK_EQ(IrOpcode::kJSCallConstruct, op->opcode());
79 return OpParameter<CallConstructParameters>(op);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040080}
81
82
83std::ostream& operator<<(std::ostream& os, CallFunctionParameters const& p) {
Ben Murdoch097c5b22016-05-18 11:27:45 +010084 os << p.arity() << ", " << p.convert_mode() << ", " << p.tail_call_mode();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000085 return os;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040086}
87
88
89const CallFunctionParameters& CallFunctionParametersOf(const Operator* op) {
90 DCHECK_EQ(IrOpcode::kJSCallFunction, op->opcode());
91 return OpParameter<CallFunctionParameters>(op);
92}
93
94
95bool operator==(CallRuntimeParameters const& lhs,
96 CallRuntimeParameters const& rhs) {
97 return lhs.id() == rhs.id() && lhs.arity() == rhs.arity();
98}
99
100
101bool operator!=(CallRuntimeParameters const& lhs,
102 CallRuntimeParameters const& rhs) {
103 return !(lhs == rhs);
104}
105
106
107size_t hash_value(CallRuntimeParameters const& p) {
108 return base::hash_combine(p.id(), p.arity());
109}
110
111
112std::ostream& operator<<(std::ostream& os, CallRuntimeParameters const& p) {
113 return os << p.id() << ", " << p.arity();
114}
115
116
117const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op) {
118 DCHECK_EQ(IrOpcode::kJSCallRuntime, op->opcode());
119 return OpParameter<CallRuntimeParameters>(op);
120}
121
122
123ContextAccess::ContextAccess(size_t depth, size_t index, bool immutable)
124 : immutable_(immutable),
125 depth_(static_cast<uint16_t>(depth)),
126 index_(static_cast<uint32_t>(index)) {
127 DCHECK(depth <= std::numeric_limits<uint16_t>::max());
128 DCHECK(index <= std::numeric_limits<uint32_t>::max());
129}
130
131
132bool operator==(ContextAccess const& lhs, ContextAccess const& rhs) {
133 return lhs.depth() == rhs.depth() && lhs.index() == rhs.index() &&
134 lhs.immutable() == rhs.immutable();
135}
136
137
138bool operator!=(ContextAccess const& lhs, ContextAccess const& rhs) {
139 return !(lhs == rhs);
140}
141
142
143size_t hash_value(ContextAccess const& access) {
144 return base::hash_combine(access.depth(), access.index(), access.immutable());
145}
146
147
148std::ostream& operator<<(std::ostream& os, ContextAccess const& access) {
149 return os << access.depth() << ", " << access.index() << ", "
150 << access.immutable();
151}
152
153
154ContextAccess const& ContextAccessOf(Operator const* op) {
155 DCHECK(op->opcode() == IrOpcode::kJSLoadContext ||
156 op->opcode() == IrOpcode::kJSStoreContext);
157 return OpParameter<ContextAccess>(op);
158}
159
160
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000161bool operator==(NamedAccess const& lhs, NamedAccess const& rhs) {
162 return lhs.name().location() == rhs.name().location() &&
163 lhs.language_mode() == rhs.language_mode() &&
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400164 lhs.feedback() == rhs.feedback();
165}
166
167
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000168bool operator!=(NamedAccess const& lhs, NamedAccess const& rhs) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400169 return !(lhs == rhs);
170}
171
172
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000173size_t hash_value(NamedAccess const& p) {
174 return base::hash_combine(p.name().location(), p.language_mode(),
175 p.feedback());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400176}
177
178
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000179std::ostream& operator<<(std::ostream& os, NamedAccess const& p) {
180 return os << Brief(*p.name()) << ", " << p.language_mode();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400181}
182
183
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000184NamedAccess const& NamedAccessOf(const Operator* op) {
185 DCHECK(op->opcode() == IrOpcode::kJSLoadNamed ||
186 op->opcode() == IrOpcode::kJSStoreNamed);
187 return OpParameter<NamedAccess>(op);
188}
189
190
191std::ostream& operator<<(std::ostream& os, PropertyAccess const& p) {
192 return os << p.language_mode();
193}
194
195
196bool operator==(PropertyAccess const& lhs, PropertyAccess const& rhs) {
197 return lhs.language_mode() == rhs.language_mode() &&
198 lhs.feedback() == rhs.feedback();
199}
200
201
202bool operator!=(PropertyAccess const& lhs, PropertyAccess const& rhs) {
203 return !(lhs == rhs);
204}
205
206
207PropertyAccess const& PropertyAccessOf(const Operator* op) {
208 DCHECK(op->opcode() == IrOpcode::kJSLoadProperty ||
209 op->opcode() == IrOpcode::kJSStoreProperty);
210 return OpParameter<PropertyAccess>(op);
211}
212
213
214size_t hash_value(PropertyAccess const& p) {
215 return base::hash_combine(p.language_mode(), p.feedback());
216}
217
218
219bool operator==(LoadGlobalParameters const& lhs,
220 LoadGlobalParameters const& rhs) {
221 return lhs.name().location() == rhs.name().location() &&
222 lhs.feedback() == rhs.feedback() &&
223 lhs.typeof_mode() == rhs.typeof_mode();
224}
225
226
227bool operator!=(LoadGlobalParameters const& lhs,
228 LoadGlobalParameters const& rhs) {
229 return !(lhs == rhs);
230}
231
232
233size_t hash_value(LoadGlobalParameters const& p) {
234 return base::hash_combine(p.name().location(), p.typeof_mode());
235}
236
237
238std::ostream& operator<<(std::ostream& os, LoadGlobalParameters const& p) {
239 return os << Brief(*p.name()) << ", " << p.typeof_mode();
240}
241
242
243const LoadGlobalParameters& LoadGlobalParametersOf(const Operator* op) {
244 DCHECK_EQ(IrOpcode::kJSLoadGlobal, op->opcode());
245 return OpParameter<LoadGlobalParameters>(op);
246}
247
248
249bool operator==(StoreGlobalParameters const& lhs,
250 StoreGlobalParameters const& rhs) {
251 return lhs.language_mode() == rhs.language_mode() &&
252 lhs.name().location() == rhs.name().location() &&
253 lhs.feedback() == rhs.feedback();
254}
255
256
257bool operator!=(StoreGlobalParameters const& lhs,
258 StoreGlobalParameters const& rhs) {
259 return !(lhs == rhs);
260}
261
262
263size_t hash_value(StoreGlobalParameters const& p) {
264 return base::hash_combine(p.language_mode(), p.name().location(),
265 p.feedback());
266}
267
268
269std::ostream& operator<<(std::ostream& os, StoreGlobalParameters const& p) {
270 return os << p.language_mode() << ", " << Brief(*p.name());
271}
272
273
274const StoreGlobalParameters& StoreGlobalParametersOf(const Operator* op) {
275 DCHECK_EQ(IrOpcode::kJSStoreGlobal, op->opcode());
276 return OpParameter<StoreGlobalParameters>(op);
277}
278
279
Ben Murdoch097c5b22016-05-18 11:27:45 +0100280CreateArgumentsType const& CreateArgumentsTypeOf(const Operator* op) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000281 DCHECK_EQ(IrOpcode::kJSCreateArguments, op->opcode());
Ben Murdoch097c5b22016-05-18 11:27:45 +0100282 return OpParameter<CreateArgumentsType>(op);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000283}
284
285
286bool operator==(CreateArrayParameters const& lhs,
287 CreateArrayParameters const& rhs) {
288 return lhs.arity() == rhs.arity() &&
289 lhs.site().location() == rhs.site().location();
290}
291
292
293bool operator!=(CreateArrayParameters const& lhs,
294 CreateArrayParameters const& rhs) {
295 return !(lhs == rhs);
296}
297
298
299size_t hash_value(CreateArrayParameters const& p) {
300 return base::hash_combine(p.arity(), p.site().location());
301}
302
303
304std::ostream& operator<<(std::ostream& os, CreateArrayParameters const& p) {
305 os << p.arity();
306 if (!p.site().is_null()) os << ", " << Brief(*p.site());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400307 return os;
308}
309
310
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000311const CreateArrayParameters& CreateArrayParametersOf(const Operator* op) {
312 DCHECK_EQ(IrOpcode::kJSCreateArray, op->opcode());
313 return OpParameter<CreateArrayParameters>(op);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400314}
315
316
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000317bool operator==(CreateClosureParameters const& lhs,
318 CreateClosureParameters const& rhs) {
319 return lhs.pretenure() == rhs.pretenure() &&
320 lhs.shared_info().location() == rhs.shared_info().location();
321}
322
323
324bool operator!=(CreateClosureParameters const& lhs,
325 CreateClosureParameters const& rhs) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400326 return !(lhs == rhs);
327}
328
329
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000330size_t hash_value(CreateClosureParameters const& p) {
331 return base::hash_combine(p.pretenure(), p.shared_info().location());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400332}
333
334
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000335std::ostream& operator<<(std::ostream& os, CreateClosureParameters const& p) {
336 return os << p.pretenure() << ", " << Brief(*p.shared_info());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400337}
338
339
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000340const CreateClosureParameters& CreateClosureParametersOf(const Operator* op) {
341 DCHECK_EQ(IrOpcode::kJSCreateClosure, op->opcode());
342 return OpParameter<CreateClosureParameters>(op);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400343}
344
345
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000346bool operator==(CreateLiteralParameters const& lhs,
347 CreateLiteralParameters const& rhs) {
348 return lhs.constant().location() == rhs.constant().location() &&
Ben Murdochda12d292016-06-02 14:46:10 +0100349 lhs.length() == rhs.length() && lhs.flags() == rhs.flags() &&
350 lhs.index() == rhs.index();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400351}
352
353
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000354bool operator!=(CreateLiteralParameters const& lhs,
355 CreateLiteralParameters const& rhs) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400356 return !(lhs == rhs);
357}
358
359
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000360size_t hash_value(CreateLiteralParameters const& p) {
Ben Murdochda12d292016-06-02 14:46:10 +0100361 return base::hash_combine(p.constant().location(), p.length(), p.flags(),
362 p.index());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400363}
364
365
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000366std::ostream& operator<<(std::ostream& os, CreateLiteralParameters const& p) {
Ben Murdochda12d292016-06-02 14:46:10 +0100367 return os << Brief(*p.constant()) << ", " << p.length() << ", " << p.flags()
368 << ", " << p.index();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400369}
370
371
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000372const CreateLiteralParameters& CreateLiteralParametersOf(const Operator* op) {
373 DCHECK(op->opcode() == IrOpcode::kJSCreateLiteralArray ||
374 op->opcode() == IrOpcode::kJSCreateLiteralObject ||
375 op->opcode() == IrOpcode::kJSCreateLiteralRegExp);
376 return OpParameter<CreateLiteralParameters>(op);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400377}
378
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000379#define CACHED_OP_LIST(V) \
380 V(Equal, Operator::kNoProperties, 2, 1) \
381 V(NotEqual, Operator::kNoProperties, 2, 1) \
382 V(StrictEqual, Operator::kNoThrow, 2, 1) \
383 V(StrictNotEqual, Operator::kNoThrow, 2, 1) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100384 V(LessThan, Operator::kNoProperties, 2, 1) \
385 V(GreaterThan, Operator::kNoProperties, 2, 1) \
386 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \
387 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \
Ben Murdochda12d292016-06-02 14:46:10 +0100388 V(ToInteger, Operator::kNoProperties, 1, 1) \
389 V(ToLength, Operator::kNoProperties, 1, 1) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000390 V(ToName, Operator::kNoProperties, 1, 1) \
Ben Murdochda12d292016-06-02 14:46:10 +0100391 V(ToNumber, Operator::kNoProperties, 1, 1) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000392 V(ToObject, Operator::kNoProperties, 1, 1) \
Ben Murdochda12d292016-06-02 14:46:10 +0100393 V(ToString, Operator::kNoProperties, 1, 1) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000394 V(Yield, Operator::kNoProperties, 1, 1) \
395 V(Create, Operator::kEliminatable, 2, 1) \
396 V(CreateIterResultObject, Operator::kEliminatable, 2, 1) \
397 V(HasProperty, Operator::kNoProperties, 2, 1) \
398 V(TypeOf, Operator::kEliminatable, 1, 1) \
399 V(InstanceOf, Operator::kNoProperties, 2, 1) \
400 V(ForInDone, Operator::kPure, 2, 1) \
401 V(ForInNext, Operator::kNoProperties, 4, 1) \
402 V(ForInPrepare, Operator::kNoProperties, 1, 3) \
403 V(ForInStep, Operator::kPure, 1, 1) \
404 V(LoadMessage, Operator::kNoThrow, 0, 1) \
405 V(StoreMessage, Operator::kNoThrow, 1, 0) \
406 V(StackCheck, Operator::kNoProperties, 0, 0) \
407 V(CreateWithContext, Operator::kNoProperties, 2, 1) \
408 V(CreateModuleContext, Operator::kNoProperties, 2, 1)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400409
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000410struct JSOperatorGlobalCache final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400411#define CACHED(Name, properties, value_input_count, value_output_count) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412 struct Name##Operator final : public Operator { \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400413 Name##Operator() \
414 : Operator(IrOpcode::kJS##Name, properties, "JS" #Name, \
415 value_input_count, Operator::ZeroIfPure(properties), \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000416 Operator::ZeroIfEliminatable(properties), \
417 value_output_count, Operator::ZeroIfPure(properties), \
418 Operator::ZeroIfNoThrow(properties)) {} \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400419 }; \
420 Name##Operator k##Name##Operator;
421 CACHED_OP_LIST(CACHED)
422#undef CACHED
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400423};
424
425
426static base::LazyInstance<JSOperatorGlobalCache>::type kCache =
427 LAZY_INSTANCE_INITIALIZER;
428
429
430JSOperatorBuilder::JSOperatorBuilder(Zone* zone)
431 : cache_(kCache.Get()), zone_(zone) {}
432
433
434#define CACHED(Name, properties, value_input_count, value_output_count) \
435 const Operator* JSOperatorBuilder::Name() { \
436 return &cache_.k##Name##Operator; \
437 }
438CACHED_OP_LIST(CACHED)
439#undef CACHED
440
Ben Murdoch097c5b22016-05-18 11:27:45 +0100441const Operator* JSOperatorBuilder::BitwiseOr(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000442 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100443 return new (zone()) Operator1<BinaryOperationHints>( //--
444 IrOpcode::kJSBitwiseOr, Operator::kNoProperties, // opcode
445 "JSBitwiseOr", // name
446 2, 1, 1, 1, 1, 2, // inputs/outputs
447 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448}
449
Ben Murdoch097c5b22016-05-18 11:27:45 +0100450const Operator* JSOperatorBuilder::BitwiseXor(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000451 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100452 return new (zone()) Operator1<BinaryOperationHints>( //--
453 IrOpcode::kJSBitwiseXor, Operator::kNoProperties, // opcode
454 "JSBitwiseXor", // name
455 2, 1, 1, 1, 1, 2, // inputs/outputs
456 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000457}
458
Ben Murdoch097c5b22016-05-18 11:27:45 +0100459const Operator* JSOperatorBuilder::BitwiseAnd(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000460 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100461 return new (zone()) Operator1<BinaryOperationHints>( //--
462 IrOpcode::kJSBitwiseAnd, Operator::kNoProperties, // opcode
463 "JSBitwiseAnd", // name
464 2, 1, 1, 1, 1, 2, // inputs/outputs
465 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000466}
467
Ben Murdoch097c5b22016-05-18 11:27:45 +0100468const Operator* JSOperatorBuilder::ShiftLeft(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000469 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100470 return new (zone()) Operator1<BinaryOperationHints>( //--
471 IrOpcode::kJSShiftLeft, Operator::kNoProperties, // opcode
472 "JSShiftLeft", // name
473 2, 1, 1, 1, 1, 2, // inputs/outputs
474 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000475}
476
Ben Murdoch097c5b22016-05-18 11:27:45 +0100477const Operator* JSOperatorBuilder::ShiftRight(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000478 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100479 return new (zone()) Operator1<BinaryOperationHints>( //--
480 IrOpcode::kJSShiftRight, Operator::kNoProperties, // opcode
481 "JSShiftRight", // name
482 2, 1, 1, 1, 1, 2, // inputs/outputs
483 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000484}
485
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000486const Operator* JSOperatorBuilder::ShiftRightLogical(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100487 BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000488 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100489 return new (zone()) Operator1<BinaryOperationHints>( //--
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000490 IrOpcode::kJSShiftRightLogical, Operator::kNoProperties, // opcode
491 "JSShiftRightLogical", // name
492 2, 1, 1, 1, 1, 2, // inputs/outputs
Ben Murdoch097c5b22016-05-18 11:27:45 +0100493 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000494}
495
Ben Murdoch097c5b22016-05-18 11:27:45 +0100496const Operator* JSOperatorBuilder::Add(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000497 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100498 return new (zone()) Operator1<BinaryOperationHints>( //--
499 IrOpcode::kJSAdd, Operator::kNoProperties, // opcode
500 "JSAdd", // name
501 2, 1, 1, 1, 1, 2, // inputs/outputs
502 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000503}
504
Ben Murdoch097c5b22016-05-18 11:27:45 +0100505const Operator* JSOperatorBuilder::Subtract(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000506 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100507 return new (zone()) Operator1<BinaryOperationHints>( //--
508 IrOpcode::kJSSubtract, Operator::kNoProperties, // opcode
509 "JSSubtract", // name
510 2, 1, 1, 1, 1, 2, // inputs/outputs
511 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000512}
513
Ben Murdoch097c5b22016-05-18 11:27:45 +0100514const Operator* JSOperatorBuilder::Multiply(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000515 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100516 return new (zone()) Operator1<BinaryOperationHints>( //--
517 IrOpcode::kJSMultiply, Operator::kNoProperties, // opcode
518 "JSMultiply", // name
519 2, 1, 1, 1, 1, 2, // inputs/outputs
520 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000521}
522
Ben Murdoch097c5b22016-05-18 11:27:45 +0100523const Operator* JSOperatorBuilder::Divide(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000524 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100525 return new (zone()) Operator1<BinaryOperationHints>( //--
526 IrOpcode::kJSDivide, Operator::kNoProperties, // opcode
527 "JSDivide", // name
528 2, 1, 1, 1, 1, 2, // inputs/outputs
529 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000530}
531
Ben Murdoch097c5b22016-05-18 11:27:45 +0100532const Operator* JSOperatorBuilder::Modulus(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000533 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100534 return new (zone()) Operator1<BinaryOperationHints>( //--
535 IrOpcode::kJSModulus, Operator::kNoProperties, // opcode
536 "JSModulus", // name
537 2, 1, 1, 1, 1, 2, // inputs/outputs
538 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000539}
540
541
542const Operator* JSOperatorBuilder::ToBoolean(ToBooleanHints hints) {
543 // TODO(turbofan): Cache most important versions of this operator.
544 return new (zone()) Operator1<ToBooleanHints>( //--
545 IrOpcode::kJSToBoolean, Operator::kEliminatable, // opcode
546 "JSToBoolean", // name
547 1, 1, 0, 1, 1, 0, // inputs/outputs
548 hints); // parameter
549}
550
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000551const Operator* JSOperatorBuilder::CallFunction(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100552 size_t arity, VectorSlotPair const& feedback,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000553 ConvertReceiverMode convert_mode, TailCallMode tail_call_mode) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100554 CallFunctionParameters parameters(arity, feedback, tail_call_mode,
555 convert_mode);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400556 return new (zone()) Operator1<CallFunctionParameters>( // --
557 IrOpcode::kJSCallFunction, Operator::kNoProperties, // opcode
558 "JSCallFunction", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000559 parameters.arity(), 1, 1, 1, 1, 2, // inputs/outputs
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400560 parameters); // parameter
561}
562
563
Ben Murdoch097c5b22016-05-18 11:27:45 +0100564const Operator* JSOperatorBuilder::CallRuntime(Runtime::FunctionId id) {
565 const Runtime::Function* f = Runtime::FunctionForId(id);
566 return CallRuntime(f, f->nargs);
567}
568
569
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400570const Operator* JSOperatorBuilder::CallRuntime(Runtime::FunctionId id,
571 size_t arity) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100572 const Runtime::Function* f = Runtime::FunctionForId(id);
573 return CallRuntime(f, arity);
574}
575
576
577const Operator* JSOperatorBuilder::CallRuntime(const Runtime::Function* f,
578 size_t arity) {
579 CallRuntimeParameters parameters(f->function_id, arity);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400580 DCHECK(f->nargs == -1 || f->nargs == static_cast<int>(parameters.arity()));
581 return new (zone()) Operator1<CallRuntimeParameters>( // --
582 IrOpcode::kJSCallRuntime, Operator::kNoProperties, // opcode
583 "JSCallRuntime", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000584 parameters.arity(), 1, 1, f->result_size, 1, 2, // inputs/outputs
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400585 parameters); // parameter
586}
587
588
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000589const Operator* JSOperatorBuilder::CallConstruct(
590 size_t arity, VectorSlotPair const& feedback) {
591 CallConstructParameters parameters(arity, feedback);
592 return new (zone()) Operator1<CallConstructParameters>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400593 IrOpcode::kJSCallConstruct, Operator::kNoProperties, // opcode
594 "JSCallConstruct", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000595 parameters.arity(), 1, 1, 1, 1, 2, // counts
596 parameters); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400597}
598
599
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000600const Operator* JSOperatorBuilder::ConvertReceiver(
601 ConvertReceiverMode convert_mode) {
602 return new (zone()) Operator1<ConvertReceiverMode>( // --
603 IrOpcode::kJSConvertReceiver, Operator::kNoThrow, // opcode
604 "JSConvertReceiver", // name
605 1, 1, 1, 1, 1, 0, // counts
606 convert_mode); // parameter
607}
608
Ben Murdoch097c5b22016-05-18 11:27:45 +0100609const Operator* JSOperatorBuilder::LoadNamed(Handle<Name> name,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000610 const VectorSlotPair& feedback) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100611 NamedAccess access(SLOPPY, name, feedback);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000612 return new (zone()) Operator1<NamedAccess>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400613 IrOpcode::kJSLoadNamed, Operator::kNoProperties, // opcode
614 "JSLoadNamed", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000615 2, 1, 1, 1, 1, 2, // counts
616 access); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400617}
618
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400619const Operator* JSOperatorBuilder::LoadProperty(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100620 VectorSlotPair const& feedback) {
621 PropertyAccess access(SLOPPY, feedback);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000622 return new (zone()) Operator1<PropertyAccess>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400623 IrOpcode::kJSLoadProperty, Operator::kNoProperties, // opcode
624 "JSLoadProperty", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000625 3, 1, 1, 1, 1, 2, // counts
626 access); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400627}
628
629
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000630const Operator* JSOperatorBuilder::StoreNamed(LanguageMode language_mode,
631 Handle<Name> name,
632 VectorSlotPair const& feedback) {
633 NamedAccess access(language_mode, name, feedback);
634 return new (zone()) Operator1<NamedAccess>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400635 IrOpcode::kJSStoreNamed, Operator::kNoProperties, // opcode
636 "JSStoreNamed", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000637 3, 1, 1, 0, 1, 2, // counts
638 access); // parameter
639}
640
641
642const Operator* JSOperatorBuilder::StoreProperty(
643 LanguageMode language_mode, VectorSlotPair const& feedback) {
644 PropertyAccess access(language_mode, feedback);
645 return new (zone()) Operator1<PropertyAccess>( // --
646 IrOpcode::kJSStoreProperty, Operator::kNoProperties, // opcode
647 "JSStoreProperty", // name
648 4, 1, 1, 0, 1, 2, // counts
649 access); // parameter
650}
651
652
653const Operator* JSOperatorBuilder::DeleteProperty(LanguageMode language_mode) {
654 return new (zone()) Operator1<LanguageMode>( // --
655 IrOpcode::kJSDeleteProperty, Operator::kNoProperties, // opcode
656 "JSDeleteProperty", // name
657 2, 1, 1, 1, 1, 2, // counts
658 language_mode); // parameter
659}
660
661
662const Operator* JSOperatorBuilder::LoadGlobal(const Handle<Name>& name,
663 const VectorSlotPair& feedback,
664 TypeofMode typeof_mode) {
665 LoadGlobalParameters parameters(name, feedback, typeof_mode);
666 return new (zone()) Operator1<LoadGlobalParameters>( // --
667 IrOpcode::kJSLoadGlobal, Operator::kNoProperties, // opcode
668 "JSLoadGlobal", // name
669 1, 1, 1, 1, 1, 2, // counts
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400670 parameters); // parameter
671}
672
673
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000674const Operator* JSOperatorBuilder::StoreGlobal(LanguageMode language_mode,
675 const Handle<Name>& name,
676 const VectorSlotPair& feedback) {
677 StoreGlobalParameters parameters(language_mode, feedback, name);
678 return new (zone()) Operator1<StoreGlobalParameters>( // --
679 IrOpcode::kJSStoreGlobal, Operator::kNoProperties, // opcode
680 "JSStoreGlobal", // name
681 2, 1, 1, 0, 1, 2, // counts
682 parameters); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400683}
684
685
686const Operator* JSOperatorBuilder::LoadContext(size_t depth, size_t index,
687 bool immutable) {
688 ContextAccess access(depth, index, immutable);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000689 return new (zone()) Operator1<ContextAccess>( // --
690 IrOpcode::kJSLoadContext, // opcode
691 Operator::kNoWrite | Operator::kNoThrow, // flags
692 "JSLoadContext", // name
693 1, 1, 0, 1, 1, 0, // counts
694 access); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400695}
696
697
698const Operator* JSOperatorBuilder::StoreContext(size_t depth, size_t index) {
699 ContextAccess access(depth, index, false);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000700 return new (zone()) Operator1<ContextAccess>( // --
701 IrOpcode::kJSStoreContext, // opcode
702 Operator::kNoRead | Operator::kNoThrow, // flags
703 "JSStoreContext", // name
704 2, 1, 1, 0, 1, 0, // counts
705 access); // parameter
706}
707
708
Ben Murdoch097c5b22016-05-18 11:27:45 +0100709const Operator* JSOperatorBuilder::CreateArguments(CreateArgumentsType type) {
710 return new (zone()) Operator1<CreateArgumentsType>( // --
711 IrOpcode::kJSCreateArguments, Operator::kNoThrow, // opcode
712 "JSCreateArguments", // name
713 1, 1, 1, 1, 1, 0, // counts
714 type); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000715}
716
717
718const Operator* JSOperatorBuilder::CreateArray(size_t arity,
719 Handle<AllocationSite> site) {
720 // constructor, new_target, arg1, ..., argN
721 int const value_input_count = static_cast<int>(arity) + 2;
722 CreateArrayParameters parameters(arity, site);
723 return new (zone()) Operator1<CreateArrayParameters>( // --
724 IrOpcode::kJSCreateArray, Operator::kNoProperties, // opcode
725 "JSCreateArray", // name
726 value_input_count, 1, 1, 1, 1, 2, // counts
727 parameters); // parameter
728}
729
730
731const Operator* JSOperatorBuilder::CreateClosure(
732 Handle<SharedFunctionInfo> shared_info, PretenureFlag pretenure) {
733 CreateClosureParameters parameters(shared_info, pretenure);
734 return new (zone()) Operator1<CreateClosureParameters>( // --
735 IrOpcode::kJSCreateClosure, Operator::kNoThrow, // opcode
736 "JSCreateClosure", // name
737 0, 1, 1, 1, 1, 0, // counts
738 parameters); // parameter
739}
740
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000741const Operator* JSOperatorBuilder::CreateLiteralArray(
Ben Murdochda12d292016-06-02 14:46:10 +0100742 Handle<FixedArray> constant_elements, int literal_flags, int literal_index,
743 int number_of_elements) {
744 CreateLiteralParameters parameters(constant_elements, number_of_elements,
745 literal_flags, literal_index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000746 return new (zone()) Operator1<CreateLiteralParameters>( // --
747 IrOpcode::kJSCreateLiteralArray, Operator::kNoProperties, // opcode
748 "JSCreateLiteralArray", // name
749 1, 1, 1, 1, 1, 2, // counts
750 parameters); // parameter
751}
752
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000753const Operator* JSOperatorBuilder::CreateLiteralObject(
754 Handle<FixedArray> constant_properties, int literal_flags,
Ben Murdochda12d292016-06-02 14:46:10 +0100755 int literal_index, int number_of_properties) {
756 CreateLiteralParameters parameters(constant_properties, number_of_properties,
757 literal_flags, literal_index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000758 return new (zone()) Operator1<CreateLiteralParameters>( // --
759 IrOpcode::kJSCreateLiteralObject, Operator::kNoProperties, // opcode
760 "JSCreateLiteralObject", // name
761 1, 1, 1, 1, 1, 2, // counts
762 parameters); // parameter
763}
764
765
766const Operator* JSOperatorBuilder::CreateLiteralRegExp(
767 Handle<String> constant_pattern, int literal_flags, int literal_index) {
Ben Murdochda12d292016-06-02 14:46:10 +0100768 CreateLiteralParameters parameters(constant_pattern, -1, literal_flags,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000769 literal_index);
770 return new (zone()) Operator1<CreateLiteralParameters>( // --
771 IrOpcode::kJSCreateLiteralRegExp, Operator::kNoProperties, // opcode
772 "JSCreateLiteralRegExp", // name
773 1, 1, 1, 1, 1, 2, // counts
774 parameters); // parameter
775}
776
777
778const Operator* JSOperatorBuilder::CreateFunctionContext(int slot_count) {
779 return new (zone()) Operator1<int>( // --
780 IrOpcode::kJSCreateFunctionContext, Operator::kNoProperties, // opcode
781 "JSCreateFunctionContext", // name
782 1, 1, 1, 1, 1, 2, // counts
783 slot_count); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400784}
785
786
787const Operator* JSOperatorBuilder::CreateCatchContext(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000788 const Handle<String>& name) {
789 return new (zone()) Operator1<Handle<String>>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400790 IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, // opcode
791 "JSCreateCatchContext", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000792 2, 1, 1, 1, 1, 2, // counts
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400793 name); // parameter
794}
795
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000796
797const Operator* JSOperatorBuilder::CreateBlockContext(
798 const Handle<ScopeInfo>& scpope_info) {
799 return new (zone()) Operator1<Handle<ScopeInfo>>( // --
800 IrOpcode::kJSCreateBlockContext, Operator::kNoProperties, // opcode
801 "JSCreateBlockContext", // name
802 1, 1, 1, 1, 1, 2, // counts
803 scpope_info); // parameter
804}
805
806
807const Operator* JSOperatorBuilder::CreateScriptContext(
808 const Handle<ScopeInfo>& scpope_info) {
809 return new (zone()) Operator1<Handle<ScopeInfo>>( // --
810 IrOpcode::kJSCreateScriptContext, Operator::kNoProperties, // opcode
811 "JSCreateScriptContext", // name
812 1, 1, 1, 1, 1, 2, // counts
813 scpope_info); // parameter
814}
815
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400816} // namespace compiler
817} // namespace internal
818} // namespace v8