blob: 5fcd51928d64307b57bc6f778733d6a21d2a47db [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() &&
349 lhs.flags() == rhs.flags() && lhs.index() == rhs.index();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400350}
351
352
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000353bool operator!=(CreateLiteralParameters const& lhs,
354 CreateLiteralParameters const& rhs) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400355 return !(lhs == rhs);
356}
357
358
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000359size_t hash_value(CreateLiteralParameters const& p) {
360 return base::hash_combine(p.constant().location(), p.flags(), p.index());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400361}
362
363
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000364std::ostream& operator<<(std::ostream& os, CreateLiteralParameters const& p) {
365 return os << Brief(*p.constant()) << ", " << p.flags() << ", " << p.index();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400366}
367
368
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000369const CreateLiteralParameters& CreateLiteralParametersOf(const Operator* op) {
370 DCHECK(op->opcode() == IrOpcode::kJSCreateLiteralArray ||
371 op->opcode() == IrOpcode::kJSCreateLiteralObject ||
372 op->opcode() == IrOpcode::kJSCreateLiteralRegExp);
373 return OpParameter<CreateLiteralParameters>(op);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400374}
375
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000376#define CACHED_OP_LIST(V) \
377 V(Equal, Operator::kNoProperties, 2, 1) \
378 V(NotEqual, Operator::kNoProperties, 2, 1) \
379 V(StrictEqual, Operator::kNoThrow, 2, 1) \
380 V(StrictNotEqual, Operator::kNoThrow, 2, 1) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100381 V(LessThan, Operator::kNoProperties, 2, 1) \
382 V(GreaterThan, Operator::kNoProperties, 2, 1) \
383 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \
384 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000385 V(ToNumber, Operator::kNoProperties, 1, 1) \
386 V(ToString, Operator::kNoProperties, 1, 1) \
387 V(ToName, Operator::kNoProperties, 1, 1) \
388 V(ToObject, Operator::kNoProperties, 1, 1) \
389 V(Yield, Operator::kNoProperties, 1, 1) \
390 V(Create, Operator::kEliminatable, 2, 1) \
391 V(CreateIterResultObject, Operator::kEliminatable, 2, 1) \
392 V(HasProperty, Operator::kNoProperties, 2, 1) \
393 V(TypeOf, Operator::kEliminatable, 1, 1) \
394 V(InstanceOf, Operator::kNoProperties, 2, 1) \
395 V(ForInDone, Operator::kPure, 2, 1) \
396 V(ForInNext, Operator::kNoProperties, 4, 1) \
397 V(ForInPrepare, Operator::kNoProperties, 1, 3) \
398 V(ForInStep, Operator::kPure, 1, 1) \
399 V(LoadMessage, Operator::kNoThrow, 0, 1) \
400 V(StoreMessage, Operator::kNoThrow, 1, 0) \
401 V(StackCheck, Operator::kNoProperties, 0, 0) \
402 V(CreateWithContext, Operator::kNoProperties, 2, 1) \
403 V(CreateModuleContext, Operator::kNoProperties, 2, 1)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400404
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000405struct JSOperatorGlobalCache final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400406#define CACHED(Name, properties, value_input_count, value_output_count) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000407 struct Name##Operator final : public Operator { \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400408 Name##Operator() \
409 : Operator(IrOpcode::kJS##Name, properties, "JS" #Name, \
410 value_input_count, Operator::ZeroIfPure(properties), \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000411 Operator::ZeroIfEliminatable(properties), \
412 value_output_count, Operator::ZeroIfPure(properties), \
413 Operator::ZeroIfNoThrow(properties)) {} \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400414 }; \
415 Name##Operator k##Name##Operator;
416 CACHED_OP_LIST(CACHED)
417#undef CACHED
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400418};
419
420
421static base::LazyInstance<JSOperatorGlobalCache>::type kCache =
422 LAZY_INSTANCE_INITIALIZER;
423
424
425JSOperatorBuilder::JSOperatorBuilder(Zone* zone)
426 : cache_(kCache.Get()), zone_(zone) {}
427
428
429#define CACHED(Name, properties, value_input_count, value_output_count) \
430 const Operator* JSOperatorBuilder::Name() { \
431 return &cache_.k##Name##Operator; \
432 }
433CACHED_OP_LIST(CACHED)
434#undef CACHED
435
Ben Murdoch097c5b22016-05-18 11:27:45 +0100436const Operator* JSOperatorBuilder::BitwiseOr(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000437 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100438 return new (zone()) Operator1<BinaryOperationHints>( //--
439 IrOpcode::kJSBitwiseOr, Operator::kNoProperties, // opcode
440 "JSBitwiseOr", // name
441 2, 1, 1, 1, 1, 2, // inputs/outputs
442 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000443}
444
Ben Murdoch097c5b22016-05-18 11:27:45 +0100445const Operator* JSOperatorBuilder::BitwiseXor(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000446 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100447 return new (zone()) Operator1<BinaryOperationHints>( //--
448 IrOpcode::kJSBitwiseXor, Operator::kNoProperties, // opcode
449 "JSBitwiseXor", // name
450 2, 1, 1, 1, 1, 2, // inputs/outputs
451 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000452}
453
Ben Murdoch097c5b22016-05-18 11:27:45 +0100454const Operator* JSOperatorBuilder::BitwiseAnd(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000455 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100456 return new (zone()) Operator1<BinaryOperationHints>( //--
457 IrOpcode::kJSBitwiseAnd, Operator::kNoProperties, // opcode
458 "JSBitwiseAnd", // name
459 2, 1, 1, 1, 1, 2, // inputs/outputs
460 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000461}
462
Ben Murdoch097c5b22016-05-18 11:27:45 +0100463const Operator* JSOperatorBuilder::ShiftLeft(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000464 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100465 return new (zone()) Operator1<BinaryOperationHints>( //--
466 IrOpcode::kJSShiftLeft, Operator::kNoProperties, // opcode
467 "JSShiftLeft", // name
468 2, 1, 1, 1, 1, 2, // inputs/outputs
469 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000470}
471
Ben Murdoch097c5b22016-05-18 11:27:45 +0100472const Operator* JSOperatorBuilder::ShiftRight(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000473 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100474 return new (zone()) Operator1<BinaryOperationHints>( //--
475 IrOpcode::kJSShiftRight, Operator::kNoProperties, // opcode
476 "JSShiftRight", // name
477 2, 1, 1, 1, 1, 2, // inputs/outputs
478 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000479}
480
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000481const Operator* JSOperatorBuilder::ShiftRightLogical(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100482 BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000483 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100484 return new (zone()) Operator1<BinaryOperationHints>( //--
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000485 IrOpcode::kJSShiftRightLogical, Operator::kNoProperties, // opcode
486 "JSShiftRightLogical", // name
487 2, 1, 1, 1, 1, 2, // inputs/outputs
Ben Murdoch097c5b22016-05-18 11:27:45 +0100488 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000489}
490
Ben Murdoch097c5b22016-05-18 11:27:45 +0100491const Operator* JSOperatorBuilder::Add(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000492 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100493 return new (zone()) Operator1<BinaryOperationHints>( //--
494 IrOpcode::kJSAdd, Operator::kNoProperties, // opcode
495 "JSAdd", // name
496 2, 1, 1, 1, 1, 2, // inputs/outputs
497 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000498}
499
Ben Murdoch097c5b22016-05-18 11:27:45 +0100500const Operator* JSOperatorBuilder::Subtract(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000501 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100502 return new (zone()) Operator1<BinaryOperationHints>( //--
503 IrOpcode::kJSSubtract, Operator::kNoProperties, // opcode
504 "JSSubtract", // name
505 2, 1, 1, 1, 1, 2, // inputs/outputs
506 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000507}
508
Ben Murdoch097c5b22016-05-18 11:27:45 +0100509const Operator* JSOperatorBuilder::Multiply(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000510 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100511 return new (zone()) Operator1<BinaryOperationHints>( //--
512 IrOpcode::kJSMultiply, Operator::kNoProperties, // opcode
513 "JSMultiply", // name
514 2, 1, 1, 1, 1, 2, // inputs/outputs
515 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000516}
517
Ben Murdoch097c5b22016-05-18 11:27:45 +0100518const Operator* JSOperatorBuilder::Divide(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000519 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100520 return new (zone()) Operator1<BinaryOperationHints>( //--
521 IrOpcode::kJSDivide, Operator::kNoProperties, // opcode
522 "JSDivide", // name
523 2, 1, 1, 1, 1, 2, // inputs/outputs
524 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000525}
526
Ben Murdoch097c5b22016-05-18 11:27:45 +0100527const Operator* JSOperatorBuilder::Modulus(BinaryOperationHints hints) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000528 // TODO(turbofan): Cache most important versions of this operator.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100529 return new (zone()) Operator1<BinaryOperationHints>( //--
530 IrOpcode::kJSModulus, Operator::kNoProperties, // opcode
531 "JSModulus", // name
532 2, 1, 1, 1, 1, 2, // inputs/outputs
533 hints); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000534}
535
536
537const Operator* JSOperatorBuilder::ToBoolean(ToBooleanHints hints) {
538 // TODO(turbofan): Cache most important versions of this operator.
539 return new (zone()) Operator1<ToBooleanHints>( //--
540 IrOpcode::kJSToBoolean, Operator::kEliminatable, // opcode
541 "JSToBoolean", // name
542 1, 1, 0, 1, 1, 0, // inputs/outputs
543 hints); // parameter
544}
545
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000546const Operator* JSOperatorBuilder::CallFunction(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100547 size_t arity, VectorSlotPair const& feedback,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000548 ConvertReceiverMode convert_mode, TailCallMode tail_call_mode) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100549 CallFunctionParameters parameters(arity, feedback, tail_call_mode,
550 convert_mode);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400551 return new (zone()) Operator1<CallFunctionParameters>( // --
552 IrOpcode::kJSCallFunction, Operator::kNoProperties, // opcode
553 "JSCallFunction", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000554 parameters.arity(), 1, 1, 1, 1, 2, // inputs/outputs
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400555 parameters); // parameter
556}
557
558
Ben Murdoch097c5b22016-05-18 11:27:45 +0100559const Operator* JSOperatorBuilder::CallRuntime(Runtime::FunctionId id) {
560 const Runtime::Function* f = Runtime::FunctionForId(id);
561 return CallRuntime(f, f->nargs);
562}
563
564
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400565const Operator* JSOperatorBuilder::CallRuntime(Runtime::FunctionId id,
566 size_t arity) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100567 const Runtime::Function* f = Runtime::FunctionForId(id);
568 return CallRuntime(f, arity);
569}
570
571
572const Operator* JSOperatorBuilder::CallRuntime(const Runtime::Function* f,
573 size_t arity) {
574 CallRuntimeParameters parameters(f->function_id, arity);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400575 DCHECK(f->nargs == -1 || f->nargs == static_cast<int>(parameters.arity()));
576 return new (zone()) Operator1<CallRuntimeParameters>( // --
577 IrOpcode::kJSCallRuntime, Operator::kNoProperties, // opcode
578 "JSCallRuntime", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000579 parameters.arity(), 1, 1, f->result_size, 1, 2, // inputs/outputs
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400580 parameters); // parameter
581}
582
583
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000584const Operator* JSOperatorBuilder::CallConstruct(
585 size_t arity, VectorSlotPair const& feedback) {
586 CallConstructParameters parameters(arity, feedback);
587 return new (zone()) Operator1<CallConstructParameters>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400588 IrOpcode::kJSCallConstruct, Operator::kNoProperties, // opcode
589 "JSCallConstruct", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000590 parameters.arity(), 1, 1, 1, 1, 2, // counts
591 parameters); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400592}
593
594
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000595const Operator* JSOperatorBuilder::ConvertReceiver(
596 ConvertReceiverMode convert_mode) {
597 return new (zone()) Operator1<ConvertReceiverMode>( // --
598 IrOpcode::kJSConvertReceiver, Operator::kNoThrow, // opcode
599 "JSConvertReceiver", // name
600 1, 1, 1, 1, 1, 0, // counts
601 convert_mode); // parameter
602}
603
Ben Murdoch097c5b22016-05-18 11:27:45 +0100604const Operator* JSOperatorBuilder::LoadNamed(Handle<Name> name,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000605 const VectorSlotPair& feedback) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100606 NamedAccess access(SLOPPY, name, feedback);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000607 return new (zone()) Operator1<NamedAccess>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400608 IrOpcode::kJSLoadNamed, Operator::kNoProperties, // opcode
609 "JSLoadNamed", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000610 2, 1, 1, 1, 1, 2, // counts
611 access); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400612}
613
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400614const Operator* JSOperatorBuilder::LoadProperty(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100615 VectorSlotPair const& feedback) {
616 PropertyAccess access(SLOPPY, feedback);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000617 return new (zone()) Operator1<PropertyAccess>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400618 IrOpcode::kJSLoadProperty, Operator::kNoProperties, // opcode
619 "JSLoadProperty", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000620 3, 1, 1, 1, 1, 2, // counts
621 access); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400622}
623
624
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000625const Operator* JSOperatorBuilder::StoreNamed(LanguageMode language_mode,
626 Handle<Name> name,
627 VectorSlotPair const& feedback) {
628 NamedAccess access(language_mode, name, feedback);
629 return new (zone()) Operator1<NamedAccess>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400630 IrOpcode::kJSStoreNamed, Operator::kNoProperties, // opcode
631 "JSStoreNamed", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000632 3, 1, 1, 0, 1, 2, // counts
633 access); // parameter
634}
635
636
637const Operator* JSOperatorBuilder::StoreProperty(
638 LanguageMode language_mode, VectorSlotPair const& feedback) {
639 PropertyAccess access(language_mode, feedback);
640 return new (zone()) Operator1<PropertyAccess>( // --
641 IrOpcode::kJSStoreProperty, Operator::kNoProperties, // opcode
642 "JSStoreProperty", // name
643 4, 1, 1, 0, 1, 2, // counts
644 access); // parameter
645}
646
647
648const Operator* JSOperatorBuilder::DeleteProperty(LanguageMode language_mode) {
649 return new (zone()) Operator1<LanguageMode>( // --
650 IrOpcode::kJSDeleteProperty, Operator::kNoProperties, // opcode
651 "JSDeleteProperty", // name
652 2, 1, 1, 1, 1, 2, // counts
653 language_mode); // parameter
654}
655
656
657const Operator* JSOperatorBuilder::LoadGlobal(const Handle<Name>& name,
658 const VectorSlotPair& feedback,
659 TypeofMode typeof_mode) {
660 LoadGlobalParameters parameters(name, feedback, typeof_mode);
661 return new (zone()) Operator1<LoadGlobalParameters>( // --
662 IrOpcode::kJSLoadGlobal, Operator::kNoProperties, // opcode
663 "JSLoadGlobal", // name
664 1, 1, 1, 1, 1, 2, // counts
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400665 parameters); // parameter
666}
667
668
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000669const Operator* JSOperatorBuilder::StoreGlobal(LanguageMode language_mode,
670 const Handle<Name>& name,
671 const VectorSlotPair& feedback) {
672 StoreGlobalParameters parameters(language_mode, feedback, name);
673 return new (zone()) Operator1<StoreGlobalParameters>( // --
674 IrOpcode::kJSStoreGlobal, Operator::kNoProperties, // opcode
675 "JSStoreGlobal", // name
676 2, 1, 1, 0, 1, 2, // counts
677 parameters); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400678}
679
680
681const Operator* JSOperatorBuilder::LoadContext(size_t depth, size_t index,
682 bool immutable) {
683 ContextAccess access(depth, index, immutable);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000684 return new (zone()) Operator1<ContextAccess>( // --
685 IrOpcode::kJSLoadContext, // opcode
686 Operator::kNoWrite | Operator::kNoThrow, // flags
687 "JSLoadContext", // name
688 1, 1, 0, 1, 1, 0, // counts
689 access); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400690}
691
692
693const Operator* JSOperatorBuilder::StoreContext(size_t depth, size_t index) {
694 ContextAccess access(depth, index, false);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000695 return new (zone()) Operator1<ContextAccess>( // --
696 IrOpcode::kJSStoreContext, // opcode
697 Operator::kNoRead | Operator::kNoThrow, // flags
698 "JSStoreContext", // name
699 2, 1, 1, 0, 1, 0, // counts
700 access); // parameter
701}
702
703
Ben Murdoch097c5b22016-05-18 11:27:45 +0100704const Operator* JSOperatorBuilder::CreateArguments(CreateArgumentsType type) {
705 return new (zone()) Operator1<CreateArgumentsType>( // --
706 IrOpcode::kJSCreateArguments, Operator::kNoThrow, // opcode
707 "JSCreateArguments", // name
708 1, 1, 1, 1, 1, 0, // counts
709 type); // parameter
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000710}
711
712
713const Operator* JSOperatorBuilder::CreateArray(size_t arity,
714 Handle<AllocationSite> site) {
715 // constructor, new_target, arg1, ..., argN
716 int const value_input_count = static_cast<int>(arity) + 2;
717 CreateArrayParameters parameters(arity, site);
718 return new (zone()) Operator1<CreateArrayParameters>( // --
719 IrOpcode::kJSCreateArray, Operator::kNoProperties, // opcode
720 "JSCreateArray", // name
721 value_input_count, 1, 1, 1, 1, 2, // counts
722 parameters); // parameter
723}
724
725
726const Operator* JSOperatorBuilder::CreateClosure(
727 Handle<SharedFunctionInfo> shared_info, PretenureFlag pretenure) {
728 CreateClosureParameters parameters(shared_info, pretenure);
729 return new (zone()) Operator1<CreateClosureParameters>( // --
730 IrOpcode::kJSCreateClosure, Operator::kNoThrow, // opcode
731 "JSCreateClosure", // name
732 0, 1, 1, 1, 1, 0, // counts
733 parameters); // parameter
734}
735
736
737const Operator* JSOperatorBuilder::CreateLiteralArray(
738 Handle<FixedArray> constant_elements, int literal_flags,
739 int literal_index) {
740 CreateLiteralParameters parameters(constant_elements, literal_flags,
741 literal_index);
742 return new (zone()) Operator1<CreateLiteralParameters>( // --
743 IrOpcode::kJSCreateLiteralArray, Operator::kNoProperties, // opcode
744 "JSCreateLiteralArray", // name
745 1, 1, 1, 1, 1, 2, // counts
746 parameters); // parameter
747}
748
749
750const Operator* JSOperatorBuilder::CreateLiteralObject(
751 Handle<FixedArray> constant_properties, int literal_flags,
752 int literal_index) {
753 CreateLiteralParameters parameters(constant_properties, literal_flags,
754 literal_index);
755 return new (zone()) Operator1<CreateLiteralParameters>( // --
756 IrOpcode::kJSCreateLiteralObject, Operator::kNoProperties, // opcode
757 "JSCreateLiteralObject", // name
758 1, 1, 1, 1, 1, 2, // counts
759 parameters); // parameter
760}
761
762
763const Operator* JSOperatorBuilder::CreateLiteralRegExp(
764 Handle<String> constant_pattern, int literal_flags, int literal_index) {
765 CreateLiteralParameters parameters(constant_pattern, literal_flags,
766 literal_index);
767 return new (zone()) Operator1<CreateLiteralParameters>( // --
768 IrOpcode::kJSCreateLiteralRegExp, Operator::kNoProperties, // opcode
769 "JSCreateLiteralRegExp", // name
770 1, 1, 1, 1, 1, 2, // counts
771 parameters); // parameter
772}
773
774
775const Operator* JSOperatorBuilder::CreateFunctionContext(int slot_count) {
776 return new (zone()) Operator1<int>( // --
777 IrOpcode::kJSCreateFunctionContext, Operator::kNoProperties, // opcode
778 "JSCreateFunctionContext", // name
779 1, 1, 1, 1, 1, 2, // counts
780 slot_count); // parameter
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400781}
782
783
784const Operator* JSOperatorBuilder::CreateCatchContext(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000785 const Handle<String>& name) {
786 return new (zone()) Operator1<Handle<String>>( // --
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400787 IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, // opcode
788 "JSCreateCatchContext", // name
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000789 2, 1, 1, 1, 1, 2, // counts
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400790 name); // parameter
791}
792
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000793
794const Operator* JSOperatorBuilder::CreateBlockContext(
795 const Handle<ScopeInfo>& scpope_info) {
796 return new (zone()) Operator1<Handle<ScopeInfo>>( // --
797 IrOpcode::kJSCreateBlockContext, Operator::kNoProperties, // opcode
798 "JSCreateBlockContext", // name
799 1, 1, 1, 1, 1, 2, // counts
800 scpope_info); // parameter
801}
802
803
804const Operator* JSOperatorBuilder::CreateScriptContext(
805 const Handle<ScopeInfo>& scpope_info) {
806 return new (zone()) Operator1<Handle<ScopeInfo>>( // --
807 IrOpcode::kJSCreateScriptContext, Operator::kNoProperties, // opcode
808 "JSCreateScriptContext", // name
809 1, 1, 1, 1, 1, 2, // counts
810 scpope_info); // parameter
811}
812
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400813} // namespace compiler
814} // namespace internal
815} // namespace v8