OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_JS_OPERATOR_H_ | 5 #ifndef V8_COMPILER_JS_OPERATOR_H_ |
6 #define V8_COMPILER_JS_OPERATOR_H_ | 6 #define V8_COMPILER_JS_OPERATOR_H_ |
7 | 7 |
8 #include "src/runtime/runtime.h" | 8 #include "src/runtime/runtime.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 26 matching lines...) Expand all Loading... |
37 }; | 37 }; |
38 | 38 |
39 bool operator==(VectorSlotPair const&, VectorSlotPair const&); | 39 bool operator==(VectorSlotPair const&, VectorSlotPair const&); |
40 bool operator!=(VectorSlotPair const&, VectorSlotPair const&); | 40 bool operator!=(VectorSlotPair const&, VectorSlotPair const&); |
41 | 41 |
42 size_t hash_value(VectorSlotPair const&); | 42 size_t hash_value(VectorSlotPair const&); |
43 | 43 |
44 | 44 |
45 // Defines hints about receiver values based on structural knowledge. This is | 45 // Defines hints about receiver values based on structural knowledge. This is |
46 // used as a parameter by JSConvertReceiver operators. | 46 // used as a parameter by JSConvertReceiver operators. |
47 enum class ConvertReceiverMode : int { | 47 enum class ConvertReceiverMode : unsigned { |
48 kNullOrUndefined, // Guaranteed to be null or undefined. | 48 kNullOrUndefined, // Guaranteed to be null or undefined. |
49 kNotNullOrUndefined, // Guaranteed to never be null or undefined. | 49 kNotNullOrUndefined, // Guaranteed to never be null or undefined. |
50 kAny // No specific knowledge about receiver. | 50 kAny // No specific knowledge about receiver. |
51 }; | 51 }; |
52 | 52 |
53 size_t hash_value(ConvertReceiverMode); | 53 size_t hash_value(ConvertReceiverMode); |
54 | 54 |
55 std::ostream& operator<<(std::ostream&, ConvertReceiverMode); | 55 std::ostream& operator<<(std::ostream&, ConvertReceiverMode); |
56 | 56 |
57 ConvertReceiverMode ConvertReceiverModeOf(const Operator* op); | 57 ConvertReceiverMode ConvertReceiverModeOf(const Operator* op); |
58 | 58 |
59 | 59 |
60 // Defines whether tail call optimization is allowed. | 60 // Defines whether tail call optimization is allowed. |
61 enum TailCallMode { NO_TAIL_CALLS, ALLOW_TAIL_CALLS }; | 61 enum class TailCallMode : unsigned { kAllow, kDisallow }; |
| 62 |
| 63 size_t hash_value(TailCallMode); |
| 64 |
| 65 std::ostream& operator<<(std::ostream&, TailCallMode); |
62 | 66 |
63 | 67 |
64 // Defines the arity and the call flags for a JavaScript function call. This is | 68 // Defines the arity and the call flags for a JavaScript function call. This is |
65 // used as a parameter by JSCallFunction operators. | 69 // used as a parameter by JSCallFunction operators. |
66 class CallFunctionParameters final { | 70 class CallFunctionParameters final { |
67 public: | 71 public: |
68 CallFunctionParameters(size_t arity, CallFunctionFlags flags, | 72 CallFunctionParameters(size_t arity, LanguageMode language_mode, |
69 LanguageMode language_mode, | |
70 VectorSlotPair const& feedback, | 73 VectorSlotPair const& feedback, |
71 TailCallMode tail_call_mode, | 74 TailCallMode tail_call_mode, |
72 ConvertReceiverMode convert_mode) | 75 ConvertReceiverMode convert_mode) |
73 : bit_field_(ArityField::encode(arity) | FlagsField::encode(flags) | | 76 : bit_field_(ArityField::encode(arity) | |
74 LanguageModeField::encode(language_mode)), | 77 ConvertReceiverModeField::encode(convert_mode) | |
75 feedback_(feedback), | 78 LanguageModeField::encode(language_mode) | |
76 tail_call_mode_(tail_call_mode), | 79 TailCallModeField::encode(tail_call_mode)), |
77 convert_mode_(convert_mode) {} | 80 feedback_(feedback) {} |
78 | 81 |
79 size_t arity() const { return ArityField::decode(bit_field_); } | 82 size_t arity() const { return ArityField::decode(bit_field_); } |
80 CallFunctionFlags flags() const { return FlagsField::decode(bit_field_); } | |
81 LanguageMode language_mode() const { | 83 LanguageMode language_mode() const { |
82 return LanguageModeField::decode(bit_field_); | 84 return LanguageModeField::decode(bit_field_); |
83 } | 85 } |
84 ConvertReceiverMode convert_mode() const { return convert_mode_; } | 86 ConvertReceiverMode convert_mode() const { |
| 87 return ConvertReceiverModeField::decode(bit_field_); |
| 88 } |
| 89 TailCallMode tail_call_mode() const { |
| 90 return TailCallModeField::decode(bit_field_); |
| 91 } |
85 VectorSlotPair const& feedback() const { return feedback_; } | 92 VectorSlotPair const& feedback() const { return feedback_; } |
86 | 93 |
87 bool operator==(CallFunctionParameters const& that) const { | 94 bool operator==(CallFunctionParameters const& that) const { |
88 return this->bit_field_ == that.bit_field_ && | 95 return this->bit_field_ == that.bit_field_ && |
89 this->feedback_ == that.feedback_ && | 96 this->feedback_ == that.feedback_; |
90 this->tail_call_mode_ == that.tail_call_mode_ && | |
91 this->convert_mode_ == that.convert_mode_; | |
92 } | 97 } |
93 bool operator!=(CallFunctionParameters const& that) const { | 98 bool operator!=(CallFunctionParameters const& that) const { |
94 return !(*this == that); | 99 return !(*this == that); |
95 } | 100 } |
96 | 101 |
97 bool AllowTailCalls() const { return tail_call_mode_ == ALLOW_TAIL_CALLS; } | |
98 | |
99 private: | 102 private: |
100 friend size_t hash_value(CallFunctionParameters const& p) { | 103 friend size_t hash_value(CallFunctionParameters const& p) { |
101 return base::hash_combine(p.bit_field_, p.feedback_, p.convert_mode_); | 104 return base::hash_combine(p.bit_field_, p.feedback_); |
102 } | 105 } |
103 | 106 |
104 typedef BitField<size_t, 0, 28> ArityField; | 107 typedef BitField<size_t, 0, 27> ArityField; |
105 typedef BitField<CallFunctionFlags, 28, 2> FlagsField; | 108 typedef BitField<ConvertReceiverMode, 27, 2> ConvertReceiverModeField; |
106 typedef BitField<LanguageMode, 30, 2> LanguageModeField; | 109 typedef BitField<LanguageMode, 29, 2> LanguageModeField; |
| 110 typedef BitField<TailCallMode, 31, 1> TailCallModeField; |
107 | 111 |
108 const uint32_t bit_field_; | 112 const uint32_t bit_field_; |
109 const VectorSlotPair feedback_; | 113 const VectorSlotPair feedback_; |
110 TailCallMode tail_call_mode_; | |
111 ConvertReceiverMode convert_mode_; | |
112 }; | 114 }; |
113 | 115 |
114 size_t hash_value(CallFunctionParameters const&); | 116 size_t hash_value(CallFunctionParameters const&); |
115 | 117 |
116 std::ostream& operator<<(std::ostream&, CallFunctionParameters const&); | 118 std::ostream& operator<<(std::ostream&, CallFunctionParameters const&); |
117 | 119 |
118 const CallFunctionParameters& CallFunctionParametersOf(const Operator* op); | 120 const CallFunctionParameters& CallFunctionParametersOf(const Operator* op); |
119 | 121 |
120 | 122 |
121 // Defines the arity and the ID for a runtime function call. This is used as a | 123 // Defines the arity and the ID for a runtime function call. This is used as a |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 401 |
400 const Operator* Create(); | 402 const Operator* Create(); |
401 const Operator* CreateArguments(CreateArgumentsParameters::Type type, | 403 const Operator* CreateArguments(CreateArgumentsParameters::Type type, |
402 int start_index); | 404 int start_index); |
403 const Operator* CreateClosure(Handle<SharedFunctionInfo> shared_info, | 405 const Operator* CreateClosure(Handle<SharedFunctionInfo> shared_info, |
404 PretenureFlag pretenure); | 406 PretenureFlag pretenure); |
405 const Operator* CreateLiteralArray(int literal_flags); | 407 const Operator* CreateLiteralArray(int literal_flags); |
406 const Operator* CreateLiteralObject(int literal_flags); | 408 const Operator* CreateLiteralObject(int literal_flags); |
407 | 409 |
408 const Operator* CallFunction( | 410 const Operator* CallFunction( |
409 size_t arity, CallFunctionFlags flags, LanguageMode language_mode, | 411 size_t arity, LanguageMode language_mode, |
410 VectorSlotPair const& feedback = VectorSlotPair(), | 412 VectorSlotPair const& feedback = VectorSlotPair(), |
411 ConvertReceiverMode convert_mode = ConvertReceiverMode::kAny, | 413 ConvertReceiverMode convert_mode = ConvertReceiverMode::kAny, |
412 TailCallMode tail_call_mode = NO_TAIL_CALLS); | 414 TailCallMode tail_call_mode = TailCallMode::kDisallow); |
413 const Operator* CallRuntime(Runtime::FunctionId id, size_t arity); | 415 const Operator* CallRuntime(Runtime::FunctionId id, size_t arity); |
414 const Operator* CallConstruct(int arguments); | 416 const Operator* CallConstruct(int arguments); |
415 | 417 |
416 const Operator* ConvertReceiver(ConvertReceiverMode convert_mode); | 418 const Operator* ConvertReceiver(ConvertReceiverMode convert_mode); |
417 | 419 |
418 const Operator* LoadProperty(LanguageMode language_mode, | 420 const Operator* LoadProperty(LanguageMode language_mode, |
419 VectorSlotPair const& feedback); | 421 VectorSlotPair const& feedback); |
420 const Operator* LoadNamed(LanguageMode language_mode, Handle<Name> name, | 422 const Operator* LoadNamed(LanguageMode language_mode, Handle<Name> name, |
421 VectorSlotPair const& feedback); | 423 VectorSlotPair const& feedback); |
422 | 424 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 Zone* const zone_; | 468 Zone* const zone_; |
467 | 469 |
468 DISALLOW_COPY_AND_ASSIGN(JSOperatorBuilder); | 470 DISALLOW_COPY_AND_ASSIGN(JSOperatorBuilder); |
469 }; | 471 }; |
470 | 472 |
471 } // namespace compiler | 473 } // namespace compiler |
472 } // namespace internal | 474 } // namespace internal |
473 } // namespace v8 | 475 } // namespace v8 |
474 | 476 |
475 #endif // V8_COMPILER_JS_OPERATOR_H_ | 477 #endif // V8_COMPILER_JS_OPERATOR_H_ |
OLD | NEW |