OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/interpreter/bytecode-array-builder.h" | 5 #include "src/interpreter/bytecode-array-builder.h" |
6 | |
6 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-writer.h" | |
9 #include "src/interpreter/bytecode-peephole-optimizer.h" | |
7 #include "src/interpreter/interpreter-intrinsics.h" | 10 #include "src/interpreter/interpreter-intrinsics.h" |
8 | 11 |
9 namespace v8 { | 12 namespace v8 { |
10 namespace internal { | 13 namespace internal { |
11 namespace interpreter { | 14 namespace interpreter { |
12 | 15 |
13 class BytecodeArrayBuilder::PreviousBytecodeHelper BASE_EMBEDDED { | |
14 public: | |
15 explicit PreviousBytecodeHelper(const BytecodeArrayBuilder& array_builder) | |
16 : array_builder_(array_builder), | |
17 previous_bytecode_start_(array_builder_.last_bytecode_start_) { | |
18 // This helper is expected to be instantiated only when the last bytecode is | |
19 // in the same basic block. | |
20 DCHECK(array_builder_.LastBytecodeInSameBlock()); | |
21 bytecode_ = Bytecodes::FromByte( | |
22 array_builder_.bytecodes()->at(previous_bytecode_start_)); | |
23 operand_scale_ = OperandScale::kSingle; | |
24 if (Bytecodes::IsPrefixScalingBytecode(bytecode_)) { | |
25 operand_scale_ = Bytecodes::PrefixBytecodeToOperandScale(bytecode_); | |
26 bytecode_ = Bytecodes::FromByte( | |
27 array_builder_.bytecodes()->at(previous_bytecode_start_ + 1)); | |
28 } | |
29 } | |
30 | |
31 // Returns the previous bytecode in the same basic block. | |
32 MUST_USE_RESULT Bytecode GetBytecode() const { | |
33 DCHECK_EQ(array_builder_.last_bytecode_start_, previous_bytecode_start_); | |
34 return bytecode_; | |
35 } | |
36 | |
37 MUST_USE_RESULT Register GetRegisterOperand(int operand_index) const { | |
38 return Register::FromOperand(GetSignedOperand(operand_index)); | |
39 } | |
40 | |
41 MUST_USE_RESULT uint32_t GetIndexOperand(int operand_index) const { | |
42 return GetUnsignedOperand(operand_index); | |
43 } | |
44 | |
45 Handle<Object> GetConstantForIndexOperand(int operand_index) const { | |
46 return array_builder_.constant_array_builder()->At( | |
47 GetIndexOperand(operand_index)); | |
48 } | |
49 | |
50 private: | |
51 // Returns the signed operand at operand_index for the previous | |
52 // bytecode in the same basic block. | |
53 MUST_USE_RESULT int32_t GetSignedOperand(int operand_index) const { | |
54 DCHECK_EQ(array_builder_.last_bytecode_start_, previous_bytecode_start_); | |
55 OperandType operand_type = | |
56 Bytecodes::GetOperandType(bytecode_, operand_index); | |
57 DCHECK(!Bytecodes::IsUnsignedOperandType(operand_type)); | |
58 const uint8_t* operand_start = GetOperandStart(operand_index); | |
59 return Bytecodes::DecodeSignedOperand(operand_start, operand_type, | |
60 operand_scale_); | |
61 } | |
62 | |
63 // Returns the unsigned operand at operand_index for the previous | |
64 // bytecode in the same basic block. | |
65 MUST_USE_RESULT uint32_t GetUnsignedOperand(int operand_index) const { | |
66 DCHECK_EQ(array_builder_.last_bytecode_start_, previous_bytecode_start_); | |
67 OperandType operand_type = | |
68 Bytecodes::GetOperandType(bytecode_, operand_index); | |
69 DCHECK(Bytecodes::IsUnsignedOperandType(operand_type)); | |
70 const uint8_t* operand_start = GetOperandStart(operand_index); | |
71 return Bytecodes::DecodeUnsignedOperand(operand_start, operand_type, | |
72 operand_scale_); | |
73 } | |
74 | |
75 const uint8_t* GetOperandStart(int operand_index) const { | |
76 size_t operand_offset = | |
77 previous_bytecode_start_ + prefix_offset() + | |
78 Bytecodes::GetOperandOffset(bytecode_, operand_index, operand_scale_); | |
79 return &(*array_builder_.bytecodes())[0] + operand_offset; | |
80 } | |
81 | |
82 int prefix_offset() const { | |
83 return Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_) ? 1 | |
84 : 0; | |
85 } | |
86 | |
87 const BytecodeArrayBuilder& array_builder_; | |
88 OperandScale operand_scale_; | |
89 Bytecode bytecode_; | |
90 size_t previous_bytecode_start_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(PreviousBytecodeHelper); | |
93 }; | |
94 | |
95 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone, | 16 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone, |
96 int parameter_count, | 17 int parameter_count, |
97 int context_count, int locals_count, | 18 int context_count, int locals_count, |
98 FunctionLiteral* literal) | 19 FunctionLiteral* literal) |
99 : isolate_(isolate), | 20 : isolate_(isolate), |
100 zone_(zone), | 21 zone_(zone), |
101 bytecodes_(zone), | |
102 bytecode_generated_(false), | 22 bytecode_generated_(false), |
103 constant_array_builder_(isolate, zone), | 23 constant_array_builder_(isolate, zone), |
104 handler_table_builder_(isolate, zone), | 24 handler_table_builder_(isolate, zone), |
105 source_position_table_builder_(isolate, zone), | 25 source_position_table_builder_(isolate, zone), |
106 last_block_end_(0), | |
107 last_bytecode_start_(~0), | |
108 exit_seen_in_block_(false), | 26 exit_seen_in_block_(false), |
109 unbound_jumps_(0), | 27 unbound_jumps_(0), |
110 parameter_count_(parameter_count), | 28 parameter_count_(parameter_count), |
111 local_register_count_(locals_count), | 29 local_register_count_(locals_count), |
112 context_register_count_(context_count), | 30 context_register_count_(context_count), |
113 temporary_allocator_(zone, fixed_register_count()) { | 31 temporary_allocator_(zone, fixed_register_count()), |
32 bytecode_node_allocator_(zone), | |
33 bytecode_array_writer_(zone, &source_position_table_builder_), | |
34 pipeline_(&bytecode_array_writer_) { | |
35 current_node_ = bytecode_node_allocator()->Allocate(); | |
114 DCHECK_GE(parameter_count_, 0); | 36 DCHECK_GE(parameter_count_, 0); |
115 DCHECK_GE(context_register_count_, 0); | 37 DCHECK_GE(context_register_count_, 0); |
116 DCHECK_GE(local_register_count_, 0); | 38 DCHECK_GE(local_register_count_, 0); |
39 | |
40 if (FLAG_ignition_peephole) { | |
41 pipeline_ = new (zone) | |
42 BytecodePeepholeOptimizer(&constant_array_builder_, pipeline_); | |
43 } | |
44 | |
117 return_position_ = | 45 return_position_ = |
118 literal ? std::max(literal->start_position(), literal->end_position() - 1) | 46 literal ? std::max(literal->start_position(), literal->end_position() - 1) |
119 : RelocInfo::kNoPosition; | 47 : RelocInfo::kNoPosition; |
120 LOG_CODE_EVENT(isolate_, CodeStartLinePosInfoRecordEvent( | 48 LOG_CODE_EVENT(isolate_, CodeStartLinePosInfoRecordEvent( |
121 source_position_table_builder())); | 49 source_position_table_builder())); |
122 } | 50 } |
123 | 51 |
124 Register BytecodeArrayBuilder::first_context_register() const { | 52 Register BytecodeArrayBuilder::first_context_register() const { |
125 DCHECK_GT(context_register_count_, 0); | 53 DCHECK_GT(context_register_count_, 0); |
126 return Register(local_register_count_); | 54 return Register(local_register_count_); |
(...skipping 15 matching lines...) Expand all Loading... | |
142 bool BytecodeArrayBuilder::RegisterIsParameterOrLocal(Register reg) const { | 70 bool BytecodeArrayBuilder::RegisterIsParameterOrLocal(Register reg) const { |
143 return reg.is_parameter() || reg.index() < locals_count(); | 71 return reg.is_parameter() || reg.index() < locals_count(); |
144 } | 72 } |
145 | 73 |
146 | 74 |
147 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 75 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { |
148 DCHECK_EQ(0, unbound_jumps_); | 76 DCHECK_EQ(0, unbound_jumps_); |
149 DCHECK_EQ(bytecode_generated_, false); | 77 DCHECK_EQ(bytecode_generated_, false); |
150 DCHECK(exit_seen_in_block_); | 78 DCHECK(exit_seen_in_block_); |
151 | 79 |
152 int bytecode_size = static_cast<int>(bytecodes_.size()); | 80 pipeline()->LeaveBasicBlock(); |
153 int register_count = fixed_and_temporary_register_count(); | 81 const ZoneVector<uint8_t>* bytecodes = bytecode_array_writer()->bytecodes(); |
154 int frame_size = register_count * kPointerSize; | 82 |
83 int bytecode_size = static_cast<int>(bytecodes->size()); | |
84 | |
85 // All locals need a frame slot for the debugger, but may not be | |
86 // present in generated code. | |
87 int frame_size_for_locals = fixed_register_count() * kPointerSize; | |
88 int frame_size_measured = bytecode_array_writer()->GetMeasuredFrameSize(); | |
89 int frame_size = std::max(frame_size_for_locals, frame_size_measured); | |
155 Handle<FixedArray> constant_pool = constant_array_builder()->ToFixedArray(); | 90 Handle<FixedArray> constant_pool = constant_array_builder()->ToFixedArray(); |
156 Handle<FixedArray> handler_table = handler_table_builder()->ToHandlerTable(); | 91 Handle<FixedArray> handler_table = handler_table_builder()->ToHandlerTable(); |
157 Handle<ByteArray> source_position_table = | 92 Handle<ByteArray> source_position_table = |
158 source_position_table_builder()->ToSourcePositionTable(); | 93 source_position_table_builder()->ToSourcePositionTable(); |
159 Handle<BytecodeArray> bytecode_array = isolate_->factory()->NewBytecodeArray( | 94 Handle<BytecodeArray> bytecode_array = isolate_->factory()->NewBytecodeArray( |
160 bytecode_size, &bytecodes_.front(), frame_size, parameter_count(), | 95 bytecode_size, &bytecodes->front(), frame_size, parameter_count(), |
161 constant_pool); | 96 constant_pool); |
162 bytecode_array->set_handler_table(*handler_table); | 97 bytecode_array->set_handler_table(*handler_table); |
163 bytecode_array->set_source_position_table(*source_position_table); | 98 bytecode_array->set_source_position_table(*source_position_table); |
164 | 99 |
165 void* line_info = source_position_table_builder()->DetachJITHandlerData(); | 100 void* line_info = source_position_table_builder()->DetachJITHandlerData(); |
166 LOG_CODE_EVENT(isolate_, CodeEndLinePosInfoRecordEvent( | 101 LOG_CODE_EVENT(isolate_, CodeEndLinePosInfoRecordEvent( |
167 AbstractCode::cast(*bytecode_array), line_info)); | 102 AbstractCode::cast(*bytecode_array), line_info)); |
168 | 103 |
169 bytecode_generated_ = true; | 104 bytecode_generated_ = true; |
170 return bytecode_array; | 105 return bytecode_array; |
171 } | 106 } |
172 | 107 |
173 template <size_t N> | |
174 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t (&operands)[N], | |
175 OperandScale operand_scale) { | |
176 // Don't output dead code. | |
177 if (exit_seen_in_block_) return; | |
178 | |
179 int operand_count = static_cast<int>(N); | |
180 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count); | |
181 | |
182 last_bytecode_start_ = bytecodes()->size(); | |
183 // Emit prefix bytecode for scale if required. | |
184 if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale)) { | |
185 bytecodes()->push_back(Bytecodes::ToByte( | |
186 Bytecodes::OperandScaleToPrefixBytecode(operand_scale))); | |
187 } | |
188 | |
189 // Emit bytecode. | |
190 bytecodes()->push_back(Bytecodes::ToByte(bytecode)); | |
191 | |
192 // Emit operands. | |
193 for (int i = 0; i < operand_count; i++) { | |
194 DCHECK(OperandIsValid(bytecode, operand_scale, i, operands[i])); | |
195 switch (Bytecodes::GetOperandSize(bytecode, i, operand_scale)) { | |
196 case OperandSize::kNone: | |
197 UNREACHABLE(); | |
198 break; | |
199 case OperandSize::kByte: | |
200 bytecodes()->push_back(static_cast<uint8_t>(operands[i])); | |
201 break; | |
202 case OperandSize::kShort: { | |
203 uint8_t operand_bytes[2]; | |
204 WriteUnalignedUInt16(operand_bytes, operands[i]); | |
205 bytecodes()->insert(bytecodes()->end(), operand_bytes, | |
206 operand_bytes + 2); | |
207 break; | |
208 } | |
209 case OperandSize::kQuad: { | |
210 uint8_t operand_bytes[4]; | |
211 WriteUnalignedUInt32(operand_bytes, operands[i]); | |
212 bytecodes()->insert(bytecodes()->end(), operand_bytes, | |
213 operand_bytes + 4); | |
214 break; | |
215 } | |
216 } | |
217 } | |
218 } | |
219 | |
220 void BytecodeArrayBuilder::Output(Bytecode bytecode) { | 108 void BytecodeArrayBuilder::Output(Bytecode bytecode) { |
221 // Don't output dead code. | 109 // Don't output dead code. |
222 if (exit_seen_in_block_) return; | 110 if (exit_seen_in_block_) return; |
223 | 111 |
224 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); | 112 current_node_->set_bytecode(bytecode); |
225 last_bytecode_start_ = bytecodes()->size(); | 113 pipeline()->Write(current_node_); |
rmcilroy
2016/05/10 11:14:09
I'm not super keen on the current_node_ field whic
oth
2016/05/11 13:17:30
Done. And measured and moved over to stack allocat
| |
226 bytecodes()->push_back(Bytecodes::ToByte(bytecode)); | 114 current_node_ = bytecode_node_allocator()->Allocate(); |
227 } | 115 } |
228 | 116 |
229 void BytecodeArrayBuilder::OutputScaled(Bytecode bytecode, | 117 void BytecodeArrayBuilder::OutputScaled(Bytecode bytecode, |
230 OperandScale operand_scale, | 118 OperandScale operand_scale, |
231 uint32_t operand0, uint32_t operand1, | 119 uint32_t operand0, uint32_t operand1, |
232 uint32_t operand2, uint32_t operand3) { | 120 uint32_t operand2, uint32_t operand3) { |
233 uint32_t operands[] = {operand0, operand1, operand2, operand3}; | 121 // Don't output dead code. |
234 Output(bytecode, operands, operand_scale); | 122 if (exit_seen_in_block_) return; |
123 DCHECK(OperandIsValid(bytecode, operand_scale, 0, operand0)); | |
124 DCHECK(OperandIsValid(bytecode, operand_scale, 1, operand1)); | |
125 DCHECK(OperandIsValid(bytecode, operand_scale, 2, operand2)); | |
126 DCHECK(OperandIsValid(bytecode, operand_scale, 3, operand3)); | |
127 current_node_->set_bytecode(bytecode, operand0, operand1, operand2, operand3, | |
128 operand_scale); | |
129 pipeline()->Write(current_node_); | |
130 current_node_ = bytecode_node_allocator()->Allocate(); | |
235 } | 131 } |
236 | 132 |
237 void BytecodeArrayBuilder::OutputScaled(Bytecode bytecode, | 133 void BytecodeArrayBuilder::OutputScaled(Bytecode bytecode, |
238 OperandScale operand_scale, | 134 OperandScale operand_scale, |
239 uint32_t operand0, uint32_t operand1, | 135 uint32_t operand0, uint32_t operand1, |
240 uint32_t operand2) { | 136 uint32_t operand2) { |
241 uint32_t operands[] = {operand0, operand1, operand2}; | 137 // Don't output dead code. |
242 Output(bytecode, operands, operand_scale); | 138 if (exit_seen_in_block_) return; |
139 DCHECK(OperandIsValid(bytecode, operand_scale, 0, operand0)); | |
140 DCHECK(OperandIsValid(bytecode, operand_scale, 1, operand1)); | |
141 DCHECK(OperandIsValid(bytecode, operand_scale, 2, operand2)); | |
142 current_node_->set_bytecode(bytecode, operand0, operand1, operand2, | |
143 operand_scale); | |
144 pipeline()->Write(current_node_); | |
145 current_node_ = bytecode_node_allocator()->Allocate(); | |
243 } | 146 } |
244 | 147 |
245 void BytecodeArrayBuilder::OutputScaled(Bytecode bytecode, | 148 void BytecodeArrayBuilder::OutputScaled(Bytecode bytecode, |
246 OperandScale operand_scale, | 149 OperandScale operand_scale, |
247 uint32_t operand0, uint32_t operand1) { | 150 uint32_t operand0, uint32_t operand1) { |
248 uint32_t operands[] = {operand0, operand1}; | 151 // Don't output dead code. |
249 Output(bytecode, operands, operand_scale); | 152 if (exit_seen_in_block_) return; |
153 DCHECK(OperandIsValid(bytecode, operand_scale, 0, operand0)); | |
154 DCHECK(OperandIsValid(bytecode, operand_scale, 1, operand1)); | |
155 current_node_->set_bytecode(bytecode, operand0, operand1, operand_scale); | |
156 pipeline()->Write(current_node_); | |
157 current_node_ = bytecode_node_allocator()->Allocate(); | |
250 } | 158 } |
251 | 159 |
252 void BytecodeArrayBuilder::OutputScaled(Bytecode bytecode, | 160 void BytecodeArrayBuilder::OutputScaled(Bytecode bytecode, |
253 OperandScale operand_scale, | 161 OperandScale operand_scale, |
254 uint32_t operand0) { | 162 uint32_t operand0) { |
255 uint32_t operands[] = {operand0}; | 163 // Don't output dead code. |
256 Output(bytecode, operands, operand_scale); | 164 if (exit_seen_in_block_) return; |
165 DCHECK(OperandIsValid(bytecode, operand_scale, 0, operand0)); | |
166 current_node_->set_bytecode(bytecode, operand0, operand_scale); | |
167 pipeline()->Write(current_node_); | |
168 current_node_ = bytecode_node_allocator()->Allocate(); | |
257 } | 169 } |
258 | 170 |
259 BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value op, | 171 BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value op, |
260 Register reg) { | 172 Register reg) { |
261 OperandScale operand_scale = OperandSizesToScale(reg.SizeOfOperand()); | 173 OperandScale operand_scale = |
174 Bytecodes::OperandSizesToScale(reg.SizeOfOperand()); | |
262 OutputScaled(BytecodeForBinaryOperation(op), operand_scale, | 175 OutputScaled(BytecodeForBinaryOperation(op), operand_scale, |
263 RegisterOperand(reg)); | 176 RegisterOperand(reg)); |
264 return *this; | 177 return *this; |
265 } | 178 } |
266 | 179 |
267 BytecodeArrayBuilder& BytecodeArrayBuilder::CountOperation(Token::Value op) { | 180 BytecodeArrayBuilder& BytecodeArrayBuilder::CountOperation(Token::Value op) { |
268 Output(BytecodeForCountOperation(op)); | 181 Output(BytecodeForCountOperation(op)); |
269 return *this; | 182 return *this; |
270 } | 183 } |
271 | 184 |
272 | 185 |
273 BytecodeArrayBuilder& BytecodeArrayBuilder::LogicalNot() { | 186 BytecodeArrayBuilder& BytecodeArrayBuilder::LogicalNot() { |
274 Output(Bytecode::kLogicalNot); | 187 Output(Bytecode::kLogicalNot); |
275 return *this; | 188 return *this; |
276 } | 189 } |
277 | 190 |
278 | 191 |
279 BytecodeArrayBuilder& BytecodeArrayBuilder::TypeOf() { | 192 BytecodeArrayBuilder& BytecodeArrayBuilder::TypeOf() { |
280 Output(Bytecode::kTypeOf); | 193 Output(Bytecode::kTypeOf); |
281 return *this; | 194 return *this; |
282 } | 195 } |
283 | 196 |
284 BytecodeArrayBuilder& BytecodeArrayBuilder::CompareOperation(Token::Value op, | 197 BytecodeArrayBuilder& BytecodeArrayBuilder::CompareOperation(Token::Value op, |
285 Register reg) { | 198 Register reg) { |
286 OperandScale operand_scale = OperandSizesToScale(reg.SizeOfOperand()); | 199 OperandScale operand_scale = |
200 Bytecodes::OperandSizesToScale(reg.SizeOfOperand()); | |
287 OutputScaled(BytecodeForCompareOperation(op), operand_scale, | 201 OutputScaled(BytecodeForCompareOperation(op), operand_scale, |
288 RegisterOperand(reg)); | 202 RegisterOperand(reg)); |
289 return *this; | 203 return *this; |
290 } | 204 } |
291 | 205 |
292 | 206 |
293 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral( | 207 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral( |
294 v8::internal::Smi* smi) { | 208 v8::internal::Smi* smi) { |
295 int32_t raw_smi = smi->value(); | 209 int32_t raw_smi = smi->value(); |
296 if (raw_smi == 0) { | 210 if (raw_smi == 0) { |
297 Output(Bytecode::kLdaZero); | 211 Output(Bytecode::kLdaZero); |
298 } else { | 212 } else { |
299 OperandSize operand_size = SizeForSignedOperand(raw_smi); | 213 OperandSize operand_size = Bytecodes::SizeForSignedOperand(raw_smi); |
300 OperandScale operand_scale = OperandSizesToScale(operand_size); | 214 OperandScale operand_scale = Bytecodes::OperandSizesToScale(operand_size); |
301 OutputScaled(Bytecode::kLdaSmi, operand_scale, | 215 OutputScaled(Bytecode::kLdaSmi, operand_scale, |
302 SignedOperand(raw_smi, operand_size)); | 216 SignedOperand(raw_smi, operand_size)); |
303 } | 217 } |
304 return *this; | 218 return *this; |
305 } | 219 } |
306 | 220 |
307 | 221 |
308 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral(Handle<Object> object) { | 222 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral(Handle<Object> object) { |
309 size_t entry = GetConstantPoolEntry(object); | 223 size_t entry = GetConstantPoolEntry(object); |
310 OperandScale operand_scale = | 224 OperandScale operand_scale = |
311 OperandSizesToScale(SizeForUnsignedOperand(entry)); | 225 Bytecodes::OperandSizesToScale(Bytecodes::SizeForUnsignedOperand(entry)); |
312 OutputScaled(Bytecode::kLdaConstant, operand_scale, UnsignedOperand(entry)); | 226 OutputScaled(Bytecode::kLdaConstant, operand_scale, UnsignedOperand(entry)); |
313 return *this; | 227 return *this; |
314 } | 228 } |
315 | 229 |
316 | 230 |
317 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadUndefined() { | 231 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadUndefined() { |
318 Output(Bytecode::kLdaUndefined); | 232 Output(Bytecode::kLdaUndefined); |
319 return *this; | 233 return *this; |
320 } | 234 } |
321 | 235 |
(...skipping 16 matching lines...) Expand all Loading... | |
338 } | 252 } |
339 | 253 |
340 | 254 |
341 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadFalse() { | 255 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadFalse() { |
342 Output(Bytecode::kLdaFalse); | 256 Output(Bytecode::kLdaFalse); |
343 return *this; | 257 return *this; |
344 } | 258 } |
345 | 259 |
346 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadAccumulatorWithRegister( | 260 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadAccumulatorWithRegister( |
347 Register reg) { | 261 Register reg) { |
348 if (!IsRegisterInAccumulator(reg)) { | 262 OperandScale operand_scale = |
349 OperandScale operand_scale = OperandSizesToScale(reg.SizeOfOperand()); | 263 Bytecodes::OperandSizesToScale(reg.SizeOfOperand()); |
350 OutputScaled(Bytecode::kLdar, operand_scale, RegisterOperand(reg)); | 264 OutputScaled(Bytecode::kLdar, operand_scale, RegisterOperand(reg)); |
351 } | |
352 return *this; | 265 return *this; |
353 } | 266 } |
354 | 267 |
355 | 268 |
356 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreAccumulatorInRegister( | 269 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreAccumulatorInRegister( |
357 Register reg) { | 270 Register reg) { |
358 if (!IsRegisterInAccumulator(reg)) { | 271 OperandScale operand_scale = |
359 OperandScale operand_scale = OperandSizesToScale(reg.SizeOfOperand()); | 272 Bytecodes::OperandSizesToScale(reg.SizeOfOperand()); |
360 OutputScaled(Bytecode::kStar, operand_scale, RegisterOperand(reg)); | 273 OutputScaled(Bytecode::kStar, operand_scale, RegisterOperand(reg)); |
361 } | |
362 return *this; | 274 return *this; |
363 } | 275 } |
364 | 276 |
365 | 277 |
366 BytecodeArrayBuilder& BytecodeArrayBuilder::MoveRegister(Register from, | 278 BytecodeArrayBuilder& BytecodeArrayBuilder::MoveRegister(Register from, |
367 Register to) { | 279 Register to) { |
368 DCHECK(from != to); | 280 DCHECK(from != to); |
369 OperandScale operand_scale = | 281 OperandScale operand_scale = |
370 OperandSizesToScale(from.SizeOfOperand(), to.SizeOfOperand()); | 282 Bytecodes::OperandSizesToScale(from.SizeOfOperand(), to.SizeOfOperand()); |
371 OutputScaled(Bytecode::kMov, operand_scale, RegisterOperand(from), | 283 OutputScaled(Bytecode::kMov, operand_scale, RegisterOperand(from), |
372 RegisterOperand(to)); | 284 RegisterOperand(to)); |
373 return *this; | 285 return *this; |
374 } | 286 } |
375 | 287 |
376 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal( | 288 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal( |
377 const Handle<String> name, int feedback_slot, TypeofMode typeof_mode) { | 289 const Handle<String> name, int feedback_slot, TypeofMode typeof_mode) { |
378 // TODO(rmcilroy): Potentially store typeof information in an | 290 // TODO(rmcilroy): Potentially store typeof information in an |
379 // operand rather than having extra bytecodes. | 291 // operand rather than having extra bytecodes. |
380 Bytecode bytecode = BytecodeForLoadGlobal(typeof_mode); | 292 Bytecode bytecode = BytecodeForLoadGlobal(typeof_mode); |
381 size_t name_index = GetConstantPoolEntry(name); | 293 size_t name_index = GetConstantPoolEntry(name); |
382 OperandScale operand_scale = | 294 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
383 OperandSizesToScale(SizeForUnsignedOperand(name_index), | 295 Bytecodes::SizeForUnsignedOperand(name_index), |
384 SizeForUnsignedOperand(feedback_slot)); | 296 Bytecodes::SizeForUnsignedOperand(feedback_slot)); |
385 OutputScaled(bytecode, operand_scale, UnsignedOperand(name_index), | 297 OutputScaled(bytecode, operand_scale, UnsignedOperand(name_index), |
386 UnsignedOperand(feedback_slot)); | 298 UnsignedOperand(feedback_slot)); |
387 return *this; | 299 return *this; |
388 } | 300 } |
389 | 301 |
390 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreGlobal( | 302 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreGlobal( |
391 const Handle<String> name, int feedback_slot, LanguageMode language_mode) { | 303 const Handle<String> name, int feedback_slot, LanguageMode language_mode) { |
392 Bytecode bytecode = BytecodeForStoreGlobal(language_mode); | 304 Bytecode bytecode = BytecodeForStoreGlobal(language_mode); |
393 size_t name_index = GetConstantPoolEntry(name); | 305 size_t name_index = GetConstantPoolEntry(name); |
394 OperandScale operand_scale = | 306 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
395 OperandSizesToScale(SizeForUnsignedOperand(name_index), | 307 Bytecodes::SizeForUnsignedOperand(name_index), |
396 SizeForUnsignedOperand(feedback_slot)); | 308 Bytecodes::SizeForUnsignedOperand(feedback_slot)); |
397 OutputScaled(bytecode, operand_scale, UnsignedOperand(name_index), | 309 OutputScaled(bytecode, operand_scale, UnsignedOperand(name_index), |
398 UnsignedOperand(feedback_slot)); | 310 UnsignedOperand(feedback_slot)); |
399 return *this; | 311 return *this; |
400 } | 312 } |
401 | 313 |
402 | 314 |
403 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadContextSlot(Register context, | 315 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadContextSlot(Register context, |
404 int slot_index) { | 316 int slot_index) { |
405 OperandScale operand_scale = OperandSizesToScale( | 317 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
406 context.SizeOfOperand(), SizeForUnsignedOperand(slot_index)); | 318 context.SizeOfOperand(), Bytecodes::SizeForUnsignedOperand(slot_index)); |
407 OutputScaled(Bytecode::kLdaContextSlot, operand_scale, | 319 OutputScaled(Bytecode::kLdaContextSlot, operand_scale, |
408 RegisterOperand(context), UnsignedOperand(slot_index)); | 320 RegisterOperand(context), UnsignedOperand(slot_index)); |
409 return *this; | 321 return *this; |
410 } | 322 } |
411 | 323 |
412 | 324 |
413 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreContextSlot(Register context, | 325 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreContextSlot(Register context, |
414 int slot_index) { | 326 int slot_index) { |
415 OperandScale operand_scale = OperandSizesToScale( | 327 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
416 context.SizeOfOperand(), SizeForUnsignedOperand(slot_index)); | 328 context.SizeOfOperand(), Bytecodes::SizeForUnsignedOperand(slot_index)); |
417 OutputScaled(Bytecode::kStaContextSlot, operand_scale, | 329 OutputScaled(Bytecode::kStaContextSlot, operand_scale, |
418 RegisterOperand(context), UnsignedOperand(slot_index)); | 330 RegisterOperand(context), UnsignedOperand(slot_index)); |
419 return *this; | 331 return *this; |
420 } | 332 } |
421 | 333 |
422 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLookupSlot( | 334 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLookupSlot( |
423 const Handle<String> name, TypeofMode typeof_mode) { | 335 const Handle<String> name, TypeofMode typeof_mode) { |
424 Bytecode bytecode = (typeof_mode == INSIDE_TYPEOF) | 336 Bytecode bytecode = (typeof_mode == INSIDE_TYPEOF) |
425 ? Bytecode::kLdaLookupSlotInsideTypeof | 337 ? Bytecode::kLdaLookupSlotInsideTypeof |
426 : Bytecode::kLdaLookupSlot; | 338 : Bytecode::kLdaLookupSlot; |
427 size_t name_index = GetConstantPoolEntry(name); | 339 size_t name_index = GetConstantPoolEntry(name); |
428 OperandScale operand_scale = | 340 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
429 OperandSizesToScale(SizeForUnsignedOperand(name_index)); | 341 Bytecodes::SizeForUnsignedOperand(name_index)); |
430 OutputScaled(bytecode, operand_scale, UnsignedOperand(name_index)); | 342 OutputScaled(bytecode, operand_scale, UnsignedOperand(name_index)); |
431 return *this; | 343 return *this; |
432 } | 344 } |
433 | 345 |
434 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreLookupSlot( | 346 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreLookupSlot( |
435 const Handle<String> name, LanguageMode language_mode) { | 347 const Handle<String> name, LanguageMode language_mode) { |
436 Bytecode bytecode = BytecodeForStoreLookupSlot(language_mode); | 348 Bytecode bytecode = BytecodeForStoreLookupSlot(language_mode); |
437 size_t name_index = GetConstantPoolEntry(name); | 349 size_t name_index = GetConstantPoolEntry(name); |
438 OperandScale operand_scale = | 350 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
439 OperandSizesToScale(SizeForUnsignedOperand(name_index)); | 351 Bytecodes::SizeForUnsignedOperand(name_index)); |
440 OutputScaled(bytecode, operand_scale, UnsignedOperand(name_index)); | 352 OutputScaled(bytecode, operand_scale, UnsignedOperand(name_index)); |
441 return *this; | 353 return *this; |
442 } | 354 } |
443 | 355 |
444 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadNamedProperty( | 356 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadNamedProperty( |
445 Register object, const Handle<Name> name, int feedback_slot) { | 357 Register object, const Handle<Name> name, int feedback_slot) { |
446 size_t name_index = GetConstantPoolEntry(name); | 358 size_t name_index = GetConstantPoolEntry(name); |
447 OperandScale operand_scale = OperandSizesToScale( | 359 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
448 object.SizeOfOperand(), SizeForUnsignedOperand(name_index), | 360 object.SizeOfOperand(), Bytecodes::SizeForUnsignedOperand(name_index), |
449 SizeForUnsignedOperand(feedback_slot)); | 361 Bytecodes::SizeForUnsignedOperand(feedback_slot)); |
450 OutputScaled(Bytecode::kLoadIC, operand_scale, RegisterOperand(object), | 362 OutputScaled(Bytecode::kLoadIC, operand_scale, RegisterOperand(object), |
451 UnsignedOperand(name_index), UnsignedOperand(feedback_slot)); | 363 UnsignedOperand(name_index), UnsignedOperand(feedback_slot)); |
452 return *this; | 364 return *this; |
453 } | 365 } |
454 | 366 |
455 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadKeyedProperty( | 367 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadKeyedProperty( |
456 Register object, int feedback_slot) { | 368 Register object, int feedback_slot) { |
457 OperandScale operand_scale = OperandSizesToScale( | 369 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
458 object.SizeOfOperand(), SizeForUnsignedOperand(feedback_slot)); | 370 object.SizeOfOperand(), Bytecodes::SizeForUnsignedOperand(feedback_slot)); |
459 OutputScaled(Bytecode::kKeyedLoadIC, operand_scale, RegisterOperand(object), | 371 OutputScaled(Bytecode::kKeyedLoadIC, operand_scale, RegisterOperand(object), |
460 UnsignedOperand(feedback_slot)); | 372 UnsignedOperand(feedback_slot)); |
461 return *this; | 373 return *this; |
462 } | 374 } |
463 | 375 |
464 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreNamedProperty( | 376 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreNamedProperty( |
465 Register object, const Handle<Name> name, int feedback_slot, | 377 Register object, const Handle<Name> name, int feedback_slot, |
466 LanguageMode language_mode) { | 378 LanguageMode language_mode) { |
467 Bytecode bytecode = BytecodeForStoreIC(language_mode); | 379 Bytecode bytecode = BytecodeForStoreIC(language_mode); |
468 size_t name_index = GetConstantPoolEntry(name); | 380 size_t name_index = GetConstantPoolEntry(name); |
469 OperandScale operand_scale = OperandSizesToScale( | 381 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
470 object.SizeOfOperand(), SizeForUnsignedOperand(name_index), | 382 object.SizeOfOperand(), Bytecodes::SizeForUnsignedOperand(name_index), |
471 SizeForUnsignedOperand(feedback_slot)); | 383 Bytecodes::SizeForUnsignedOperand(feedback_slot)); |
472 OutputScaled(bytecode, operand_scale, RegisterOperand(object), | 384 OutputScaled(bytecode, operand_scale, RegisterOperand(object), |
473 UnsignedOperand(name_index), UnsignedOperand(feedback_slot)); | 385 UnsignedOperand(name_index), UnsignedOperand(feedback_slot)); |
474 return *this; | 386 return *this; |
475 } | 387 } |
476 | 388 |
477 | 389 |
478 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreKeyedProperty( | 390 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreKeyedProperty( |
479 Register object, Register key, int feedback_slot, | 391 Register object, Register key, int feedback_slot, |
480 LanguageMode language_mode) { | 392 LanguageMode language_mode) { |
481 Bytecode bytecode = BytecodeForKeyedStoreIC(language_mode); | 393 Bytecode bytecode = BytecodeForKeyedStoreIC(language_mode); |
482 OperandScale operand_scale = | 394 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
483 OperandSizesToScale(object.SizeOfOperand(), key.SizeOfOperand(), | 395 object.SizeOfOperand(), key.SizeOfOperand(), |
484 SizeForUnsignedOperand(feedback_slot)); | 396 Bytecodes::SizeForUnsignedOperand(feedback_slot)); |
485 OutputScaled(bytecode, operand_scale, RegisterOperand(object), | 397 OutputScaled(bytecode, operand_scale, RegisterOperand(object), |
486 RegisterOperand(key), UnsignedOperand(feedback_slot)); | 398 RegisterOperand(key), UnsignedOperand(feedback_slot)); |
487 return *this; | 399 return *this; |
488 } | 400 } |
489 | 401 |
490 | 402 |
491 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateClosure( | 403 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateClosure( |
492 Handle<SharedFunctionInfo> shared_info, PretenureFlag tenured) { | 404 Handle<SharedFunctionInfo> shared_info, PretenureFlag tenured) { |
493 size_t entry = GetConstantPoolEntry(shared_info); | 405 size_t entry = GetConstantPoolEntry(shared_info); |
494 OperandScale operand_scale = | 406 OperandScale operand_scale = |
495 OperandSizesToScale(SizeForUnsignedOperand(entry)); | 407 Bytecodes::OperandSizesToScale(Bytecodes::SizeForUnsignedOperand(entry)); |
496 OutputScaled(Bytecode::kCreateClosure, operand_scale, UnsignedOperand(entry), | 408 OutputScaled(Bytecode::kCreateClosure, operand_scale, UnsignedOperand(entry), |
497 UnsignedOperand(static_cast<size_t>(tenured))); | 409 UnsignedOperand(static_cast<size_t>(tenured))); |
498 return *this; | 410 return *this; |
499 } | 411 } |
500 | 412 |
501 | 413 |
502 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateArguments( | 414 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateArguments( |
503 CreateArgumentsType type) { | 415 CreateArgumentsType type) { |
504 // TODO(rmcilroy): Consider passing the type as a bytecode operand rather | 416 // TODO(rmcilroy): Consider passing the type as a bytecode operand rather |
505 // than having two different bytecodes once we have better support for | 417 // than having two different bytecodes once we have better support for |
506 // branches in the InterpreterAssembler. | 418 // branches in the InterpreterAssembler. |
507 Bytecode bytecode = BytecodeForCreateArguments(type); | 419 Bytecode bytecode = BytecodeForCreateArguments(type); |
508 Output(bytecode); | 420 Output(bytecode); |
509 return *this; | 421 return *this; |
510 } | 422 } |
511 | 423 |
512 | 424 |
513 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateRegExpLiteral( | 425 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateRegExpLiteral( |
514 Handle<String> pattern, int literal_index, int flags) { | 426 Handle<String> pattern, int literal_index, int flags) { |
515 size_t pattern_entry = GetConstantPoolEntry(pattern); | 427 size_t pattern_entry = GetConstantPoolEntry(pattern); |
516 OperandScale operand_scale = OperandSizesToScale( | 428 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
517 SizeForUnsignedOperand(pattern_entry), | 429 Bytecodes::SizeForUnsignedOperand(pattern_entry), |
518 SizeForUnsignedOperand(literal_index), SizeForUnsignedOperand(flags)); | 430 Bytecodes::SizeForUnsignedOperand(literal_index), |
431 Bytecodes::SizeForUnsignedOperand(flags)); | |
519 OutputScaled(Bytecode::kCreateRegExpLiteral, operand_scale, | 432 OutputScaled(Bytecode::kCreateRegExpLiteral, operand_scale, |
520 UnsignedOperand(pattern_entry), UnsignedOperand(literal_index), | 433 UnsignedOperand(pattern_entry), UnsignedOperand(literal_index), |
521 UnsignedOperand(flags)); | 434 UnsignedOperand(flags)); |
522 return *this; | 435 return *this; |
523 } | 436 } |
524 | 437 |
525 | 438 |
526 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateArrayLiteral( | 439 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateArrayLiteral( |
527 Handle<FixedArray> constant_elements, int literal_index, int flags) { | 440 Handle<FixedArray> constant_elements, int literal_index, int flags) { |
528 size_t constant_elements_entry = GetConstantPoolEntry(constant_elements); | 441 size_t constant_elements_entry = GetConstantPoolEntry(constant_elements); |
529 OperandScale operand_scale = OperandSizesToScale( | 442 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
530 SizeForUnsignedOperand(constant_elements_entry), | 443 Bytecodes::SizeForUnsignedOperand(constant_elements_entry), |
531 SizeForUnsignedOperand(literal_index), SizeForUnsignedOperand(flags)); | 444 Bytecodes::SizeForUnsignedOperand(literal_index), |
445 Bytecodes::SizeForUnsignedOperand(flags)); | |
532 OutputScaled(Bytecode::kCreateArrayLiteral, operand_scale, | 446 OutputScaled(Bytecode::kCreateArrayLiteral, operand_scale, |
533 UnsignedOperand(constant_elements_entry), | 447 UnsignedOperand(constant_elements_entry), |
534 UnsignedOperand(literal_index), UnsignedOperand(flags)); | 448 UnsignedOperand(literal_index), UnsignedOperand(flags)); |
535 return *this; | 449 return *this; |
536 } | 450 } |
537 | 451 |
538 | 452 |
539 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateObjectLiteral( | 453 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateObjectLiteral( |
540 Handle<FixedArray> constant_properties, int literal_index, int flags) { | 454 Handle<FixedArray> constant_properties, int literal_index, int flags) { |
541 size_t constant_properties_entry = GetConstantPoolEntry(constant_properties); | 455 size_t constant_properties_entry = GetConstantPoolEntry(constant_properties); |
542 OperandScale operand_scale = OperandSizesToScale( | 456 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
543 SizeForUnsignedOperand(constant_properties_entry), | 457 Bytecodes::SizeForUnsignedOperand(constant_properties_entry), |
544 SizeForUnsignedOperand(literal_index), SizeForUnsignedOperand(flags)); | 458 Bytecodes::SizeForUnsignedOperand(literal_index), |
459 Bytecodes::SizeForUnsignedOperand(flags)); | |
545 OutputScaled(Bytecode::kCreateObjectLiteral, operand_scale, | 460 OutputScaled(Bytecode::kCreateObjectLiteral, operand_scale, |
546 UnsignedOperand(constant_properties_entry), | 461 UnsignedOperand(constant_properties_entry), |
547 UnsignedOperand(literal_index), UnsignedOperand(flags)); | 462 UnsignedOperand(literal_index), UnsignedOperand(flags)); |
548 return *this; | 463 return *this; |
549 } | 464 } |
550 | 465 |
551 | 466 |
552 BytecodeArrayBuilder& BytecodeArrayBuilder::PushContext(Register context) { | 467 BytecodeArrayBuilder& BytecodeArrayBuilder::PushContext(Register context) { |
553 OperandScale operand_scale = OperandSizesToScale(context.SizeOfOperand()); | 468 OperandScale operand_scale = |
469 Bytecodes::OperandSizesToScale(context.SizeOfOperand()); | |
554 OutputScaled(Bytecode::kPushContext, operand_scale, RegisterOperand(context)); | 470 OutputScaled(Bytecode::kPushContext, operand_scale, RegisterOperand(context)); |
555 return *this; | 471 return *this; |
556 } | 472 } |
557 | 473 |
558 | 474 |
559 BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) { | 475 BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) { |
560 OperandScale operand_scale = OperandSizesToScale(context.SizeOfOperand()); | 476 OperandScale operand_scale = |
477 Bytecodes::OperandSizesToScale(context.SizeOfOperand()); | |
561 OutputScaled(Bytecode::kPopContext, operand_scale, RegisterOperand(context)); | 478 OutputScaled(Bytecode::kPopContext, operand_scale, RegisterOperand(context)); |
562 return *this; | 479 return *this; |
563 } | 480 } |
564 | 481 |
565 | 482 |
566 bool BytecodeArrayBuilder::NeedToBooleanCast() { | |
567 if (!LastBytecodeInSameBlock()) { | |
568 return true; | |
569 } | |
570 PreviousBytecodeHelper previous_bytecode(*this); | |
571 switch (previous_bytecode.GetBytecode()) { | |
572 // If the previous bytecode puts a boolean in the accumulator return true. | |
573 case Bytecode::kLdaTrue: | |
574 case Bytecode::kLdaFalse: | |
575 case Bytecode::kLogicalNot: | |
576 case Bytecode::kTestEqual: | |
577 case Bytecode::kTestNotEqual: | |
578 case Bytecode::kTestEqualStrict: | |
579 case Bytecode::kTestLessThan: | |
580 case Bytecode::kTestLessThanOrEqual: | |
581 case Bytecode::kTestGreaterThan: | |
582 case Bytecode::kTestGreaterThanOrEqual: | |
583 case Bytecode::kTestInstanceOf: | |
584 case Bytecode::kTestIn: | |
585 case Bytecode::kForInDone: | |
586 return false; | |
587 default: | |
588 return true; | |
589 } | |
590 } | |
591 | |
592 | |
593 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() { | 483 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() { |
594 Output(Bytecode::kToObject); | 484 Output(Bytecode::kToObject); |
595 return *this; | 485 return *this; |
596 } | 486 } |
597 | 487 |
598 | 488 |
599 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() { | 489 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() { |
600 if (LastBytecodeInSameBlock()) { | |
601 PreviousBytecodeHelper previous_bytecode(*this); | |
602 switch (previous_bytecode.GetBytecode()) { | |
603 case Bytecode::kToName: | |
604 case Bytecode::kTypeOf: | |
605 return *this; | |
606 case Bytecode::kLdaConstant: { | |
607 Handle<Object> object = previous_bytecode.GetConstantForIndexOperand(0); | |
608 if (object->IsName()) return *this; | |
609 break; | |
610 } | |
611 default: | |
612 break; | |
613 } | |
614 } | |
615 Output(Bytecode::kToName); | 490 Output(Bytecode::kToName); |
616 return *this; | 491 return *this; |
617 } | 492 } |
618 | 493 |
619 | |
620 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() { | 494 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() { |
621 // TODO(rmcilroy): consider omitting if the preceeding bytecode always returns | 495 // TODO(rmcilroy): consider omitting if the preceeding bytecode always returns |
622 // a number. | 496 // a number. |
623 Output(Bytecode::kToNumber); | 497 Output(Bytecode::kToNumber); |
624 return *this; | 498 return *this; |
625 } | 499 } |
626 | 500 |
627 | 501 |
628 BytecodeArrayBuilder& BytecodeArrayBuilder::Bind(BytecodeLabel* label) { | 502 BytecodeArrayBuilder& BytecodeArrayBuilder::Bind(BytecodeLabel* label) { |
503 size_t current_offset = pipeline()->FlushForOffset(); | |
rmcilroy
2016/05/10 11:14:09
I'm a bit wary of this. You call this FlushForOffs
oth
2016/05/11 13:17:30
Emitting a jump entails writing the jump into the
| |
629 if (label->is_forward_target()) { | 504 if (label->is_forward_target()) { |
505 ZoneVector<uint8_t>* bytecodes = bytecode_array_writer()->bytecodes(); | |
630 // An earlier jump instruction refers to this label. Update it's location. | 506 // An earlier jump instruction refers to this label. Update it's location. |
631 PatchJump(bytecodes()->end(), bytecodes()->begin() + label->offset()); | 507 PatchJump(bytecodes, current_offset, label->offset()); |
632 // Now treat as if the label will only be back referred to. | 508 // Now treat as if the label will only be back referred to. |
633 } | 509 } |
634 label->bind_to(bytecodes()->size()); | 510 label->bind_to(current_offset); |
635 LeaveBasicBlock(); | 511 LeaveBasicBlock(); |
636 return *this; | 512 return *this; |
637 } | 513 } |
638 | 514 |
639 | 515 |
640 BytecodeArrayBuilder& BytecodeArrayBuilder::Bind(const BytecodeLabel& target, | 516 BytecodeArrayBuilder& BytecodeArrayBuilder::Bind(const BytecodeLabel& target, |
641 BytecodeLabel* label) { | 517 BytecodeLabel* label) { |
642 DCHECK(!label->is_bound()); | 518 DCHECK(!label->is_bound()); |
643 DCHECK(target.is_bound()); | 519 DCHECK(target.is_bound()); |
520 pipeline()->FlushForOffset(); | |
644 if (label->is_forward_target()) { | 521 if (label->is_forward_target()) { |
522 ZoneVector<uint8_t>* bytecodes = bytecode_array_writer()->bytecodes(); | |
645 // An earlier jump instruction refers to this label. Update it's location. | 523 // An earlier jump instruction refers to this label. Update it's location. |
646 PatchJump(bytecodes()->begin() + target.offset(), | 524 PatchJump(bytecodes, target.offset(), label->offset()); |
647 bytecodes()->begin() + label->offset()); | |
648 // Now treat as if the label will only be back referred to. | 525 // Now treat as if the label will only be back referred to. |
649 } | 526 } |
650 label->bind_to(target.offset()); | 527 label->bind_to(target.offset()); |
651 LeaveBasicBlock(); | 528 LeaveBasicBlock(); |
652 return *this; | 529 return *this; |
653 } | 530 } |
654 | 531 |
655 | 532 |
656 // static | 533 // static |
657 Bytecode BytecodeArrayBuilder::GetJumpWithConstantOperand( | 534 Bytecode BytecodeArrayBuilder::GetJumpWithConstantOperand( |
(...skipping 27 matching lines...) Expand all Loading... | |
685 case Bytecode::kJump: | 562 case Bytecode::kJump: |
686 case Bytecode::kJumpIfNull: | 563 case Bytecode::kJumpIfNull: |
687 case Bytecode::kJumpIfUndefined: | 564 case Bytecode::kJumpIfUndefined: |
688 case Bytecode::kJumpIfNotHole: | 565 case Bytecode::kJumpIfNotHole: |
689 return jump_bytecode; | 566 return jump_bytecode; |
690 case Bytecode::kJumpIfTrue: | 567 case Bytecode::kJumpIfTrue: |
691 return Bytecode::kJumpIfToBooleanTrue; | 568 return Bytecode::kJumpIfToBooleanTrue; |
692 case Bytecode::kJumpIfFalse: | 569 case Bytecode::kJumpIfFalse: |
693 return Bytecode::kJumpIfToBooleanFalse; | 570 return Bytecode::kJumpIfToBooleanFalse; |
694 default: | 571 default: |
695 UNREACHABLE(); | 572 return jump_bytecode; |
rmcilroy
2016/05/10 11:14:09
Why isn't this still UNREACHABLE?
oth
2016/05/11 13:17:30
Done.
| |
696 } | 573 } |
697 return Bytecode::kIllegal; | |
698 } | 574 } |
699 | 575 |
700 | 576 void BytecodeArrayBuilder::PatchJumpWith8BitOperand( |
701 void BytecodeArrayBuilder::PatchIndirectJumpWith8BitOperand( | 577 ZoneVector<uint8_t>* bytecodes, size_t jump_location, int delta) { |
702 const ZoneVector<uint8_t>::iterator& jump_location, int delta) { | 578 Bytecode jump_bytecode = Bytecodes::FromByte(bytecodes->at(jump_location)); |
703 Bytecode jump_bytecode = Bytecodes::FromByte(*jump_location); | |
704 DCHECK(Bytecodes::IsJumpImmediate(jump_bytecode)); | 579 DCHECK(Bytecodes::IsJumpImmediate(jump_bytecode)); |
705 ZoneVector<uint8_t>::iterator operand_location = jump_location + 1; | 580 size_t operand_location = jump_location + 1; |
706 DCHECK_EQ(*operand_location, 0); | 581 DCHECK_EQ(bytecodes->at(operand_location), 0); |
707 if (SizeForSignedOperand(delta) == OperandSize::kByte) { | 582 if (Bytecodes::SizeForSignedOperand(delta) == OperandSize::kByte) { |
708 // The jump fits within the range of an Imm operand, so cancel | 583 // The jump fits within the range of an Imm operand, so cancel |
709 // the reservation and jump directly. | 584 // the reservation and jump directly. |
710 constant_array_builder()->DiscardReservedEntry(OperandSize::kByte); | 585 constant_array_builder()->DiscardReservedEntry(OperandSize::kByte); |
711 *operand_location = static_cast<uint8_t>(delta); | 586 bytecodes->at(operand_location) = static_cast<uint8_t>(delta); |
712 } else { | 587 } else { |
713 // The jump does not fit within the range of an Imm operand, so | 588 // The jump does not fit within the range of an Imm operand, so |
714 // commit reservation putting the offset into the constant pool, | 589 // commit reservation putting the offset into the constant pool, |
715 // and update the jump instruction and operand. | 590 // and update the jump instruction and operand. |
716 size_t entry = constant_array_builder()->CommitReservedEntry( | 591 size_t entry = constant_array_builder()->CommitReservedEntry( |
717 OperandSize::kByte, handle(Smi::FromInt(delta), isolate())); | 592 OperandSize::kByte, handle(Smi::FromInt(delta), isolate())); |
718 DCHECK(SizeForUnsignedOperand(entry) == OperandSize::kByte); | 593 DCHECK(Bytecodes::SizeForUnsignedOperand(entry) == OperandSize::kByte); |
719 jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); | 594 jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); |
720 *jump_location = Bytecodes::ToByte(jump_bytecode); | 595 bytecodes->at(jump_location) = Bytecodes::ToByte(jump_bytecode); |
721 *operand_location = static_cast<uint8_t>(entry); | 596 bytecodes->at(operand_location) = static_cast<uint8_t>(entry); |
722 } | 597 } |
723 } | 598 } |
724 | 599 |
725 void BytecodeArrayBuilder::PatchIndirectJumpWith16BitOperand( | 600 void BytecodeArrayBuilder::PatchJumpWith16BitOperand( |
726 const ZoneVector<uint8_t>::iterator& jump_location, int delta) { | 601 ZoneVector<uint8_t>* bytecodes, size_t jump_location, int delta) { |
727 Bytecode jump_bytecode = Bytecodes::FromByte(*jump_location); | 602 Bytecode jump_bytecode = Bytecodes::FromByte(bytecodes->at(jump_location)); |
728 DCHECK(Bytecodes::IsJumpImmediate(jump_bytecode)); | 603 DCHECK(Bytecodes::IsJumpImmediate(jump_bytecode)); |
729 ZoneVector<uint8_t>::iterator operand_location = jump_location + 1; | 604 size_t operand_location = jump_location + 1; |
730 uint8_t operand_bytes[2]; | 605 uint8_t operand_bytes[2]; |
731 if (SizeForSignedOperand(delta) <= OperandSize::kShort) { | 606 if (Bytecodes::SizeForSignedOperand(delta) <= OperandSize::kShort) { |
732 constant_array_builder()->DiscardReservedEntry(OperandSize::kShort); | 607 constant_array_builder()->DiscardReservedEntry(OperandSize::kShort); |
733 WriteUnalignedUInt16(operand_bytes, static_cast<uint16_t>(delta)); | 608 WriteUnalignedUInt16(operand_bytes, static_cast<uint16_t>(delta)); |
734 } else { | 609 } else { |
735 jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); | 610 jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); |
736 *jump_location = Bytecodes::ToByte(jump_bytecode); | 611 bytecodes->at(jump_location) = Bytecodes::ToByte(jump_bytecode); |
737 size_t entry = constant_array_builder()->CommitReservedEntry( | 612 size_t entry = constant_array_builder()->CommitReservedEntry( |
738 OperandSize::kShort, handle(Smi::FromInt(delta), isolate())); | 613 OperandSize::kShort, handle(Smi::FromInt(delta), isolate())); |
739 WriteUnalignedUInt16(operand_bytes, static_cast<uint16_t>(entry)); | 614 WriteUnalignedUInt16(operand_bytes, static_cast<uint16_t>(entry)); |
740 } | 615 } |
741 DCHECK(*operand_location == 0 && *(operand_location + 1) == 0); | 616 DCHECK(bytecodes->at(operand_location) == 0 && |
742 *operand_location++ = operand_bytes[0]; | 617 bytecodes->at(operand_location + 1) == 0); |
743 *operand_location = operand_bytes[1]; | 618 bytecodes->at(operand_location++) = operand_bytes[0]; |
619 bytecodes->at(operand_location) = operand_bytes[1]; | |
744 } | 620 } |
745 | 621 |
746 void BytecodeArrayBuilder::PatchIndirectJumpWith32BitOperand( | 622 void BytecodeArrayBuilder::PatchJumpWith32BitOperand( |
747 const ZoneVector<uint8_t>::iterator& jump_location, int delta) { | 623 ZoneVector<uint8_t>* bytecodes, size_t jump_location, int delta) { |
748 DCHECK(Bytecodes::IsJumpImmediate(Bytecodes::FromByte(*jump_location))); | 624 DCHECK(Bytecodes::IsJumpImmediate( |
625 Bytecodes::FromByte(bytecodes->at(jump_location)))); | |
749 constant_array_builder()->DiscardReservedEntry(OperandSize::kQuad); | 626 constant_array_builder()->DiscardReservedEntry(OperandSize::kQuad); |
750 ZoneVector<uint8_t>::iterator operand_location = jump_location + 1; | |
751 uint8_t operand_bytes[4]; | 627 uint8_t operand_bytes[4]; |
752 WriteUnalignedUInt32(operand_bytes, static_cast<uint32_t>(delta)); | 628 WriteUnalignedUInt32(operand_bytes, static_cast<uint32_t>(delta)); |
753 DCHECK(*operand_location == 0 && *(operand_location + 1) == 0 && | 629 size_t operand_location = jump_location + 1; |
754 *(operand_location + 2) == 0 && *(operand_location + 3) == 0); | 630 DCHECK(bytecodes->at(operand_location) == 0 && |
755 *operand_location++ = operand_bytes[0]; | 631 bytecodes->at(operand_location + 1) == 0 && |
756 *operand_location++ = operand_bytes[1]; | 632 bytecodes->at(operand_location + 2) == 0 && |
757 *operand_location++ = operand_bytes[2]; | 633 bytecodes->at(operand_location + 3) == 0); |
758 *operand_location = operand_bytes[3]; | 634 bytecodes->at(operand_location++) = operand_bytes[0]; |
635 bytecodes->at(operand_location++) = operand_bytes[1]; | |
636 bytecodes->at(operand_location++) = operand_bytes[2]; | |
637 bytecodes->at(operand_location) = operand_bytes[3]; | |
759 } | 638 } |
760 | 639 |
761 void BytecodeArrayBuilder::PatchJump( | 640 void BytecodeArrayBuilder::PatchJump(ZoneVector<uint8_t>* bytecodes, |
762 const ZoneVector<uint8_t>::iterator& jump_target, | 641 size_t jump_target, size_t jump_location) { |
763 const ZoneVector<uint8_t>::iterator& jump_location) { | |
764 int delta = static_cast<int>(jump_target - jump_location); | 642 int delta = static_cast<int>(jump_target - jump_location); |
rmcilroy
2016/05/10 11:14:09
nit - personally I think it would be clearer to ha
oth
2016/05/11 13:17:30
There is no problem getting the vector here => Don
| |
765 Bytecode jump_bytecode = Bytecodes::FromByte(*jump_location); | 643 Bytecode jump_bytecode = Bytecodes::FromByte(bytecodes->at(jump_location)); |
766 int prefix_offset = 0; | 644 int prefix_offset = 0; |
767 OperandScale operand_scale = OperandScale::kSingle; | 645 OperandScale operand_scale = OperandScale::kSingle; |
768 if (Bytecodes::IsPrefixScalingBytecode(jump_bytecode)) { | 646 if (Bytecodes::IsPrefixScalingBytecode(jump_bytecode)) { |
769 // If a prefix scaling bytecode is emitted the target offset is one | 647 // If a prefix scaling bytecode is emitted the target offset is one |
770 // less than the case of no prefix scaling bytecode. | 648 // less than the case of no prefix scaling bytecode. |
771 delta -= 1; | 649 delta -= 1; |
772 prefix_offset = 1; | 650 prefix_offset = 1; |
773 operand_scale = Bytecodes::PrefixBytecodeToOperandScale(jump_bytecode); | 651 operand_scale = Bytecodes::PrefixBytecodeToOperandScale(jump_bytecode); |
774 jump_bytecode = Bytecodes::FromByte(*(jump_location + prefix_offset)); | 652 jump_bytecode = |
653 Bytecodes::FromByte(bytecodes->at(jump_location + prefix_offset)); | |
775 } | 654 } |
776 | 655 |
777 DCHECK(Bytecodes::IsJump(jump_bytecode)); | 656 DCHECK(Bytecodes::IsJump(jump_bytecode)); |
778 switch (operand_scale) { | 657 switch (operand_scale) { |
779 case OperandScale::kSingle: | 658 case OperandScale::kSingle: |
780 PatchIndirectJumpWith8BitOperand(jump_location, delta); | 659 PatchJumpWith8BitOperand(bytecodes, jump_location, delta); |
781 break; | 660 break; |
782 case OperandScale::kDouble: | 661 case OperandScale::kDouble: |
783 PatchIndirectJumpWith16BitOperand(jump_location + prefix_offset, delta); | 662 PatchJumpWith16BitOperand(bytecodes, jump_location + prefix_offset, |
663 delta); | |
784 break; | 664 break; |
785 case OperandScale::kQuadruple: | 665 case OperandScale::kQuadruple: |
786 PatchIndirectJumpWith32BitOperand(jump_location + prefix_offset, delta); | 666 PatchJumpWith32BitOperand(bytecodes, jump_location + prefix_offset, |
667 delta); | |
787 break; | 668 break; |
788 default: | 669 default: |
789 UNREACHABLE(); | 670 UNREACHABLE(); |
790 } | 671 } |
791 unbound_jumps_--; | 672 unbound_jumps_--; |
792 } | 673 } |
793 | 674 |
794 | 675 |
795 BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode, | 676 BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode, |
796 BytecodeLabel* label) { | 677 BytecodeLabel* label) { |
797 // Don't emit dead code. | 678 // Don't emit dead code. |
798 if (exit_seen_in_block_) return *this; | 679 if (exit_seen_in_block_) return *this; |
799 | 680 |
800 // Check if the value in accumulator is boolean, if not choose an | 681 // Peephole optimizer will strip this out. |
801 // appropriate JumpIfToBoolean bytecode. | 682 jump_bytecode = GetJumpWithToBoolean(jump_bytecode); |
rmcilroy
2016/05/10 11:14:09
We should just explicitly always call OutputJump w
oth
2016/05/11 13:17:30
Done.
| |
802 if (NeedToBooleanCast()) { | |
803 jump_bytecode = GetJumpWithToBoolean(jump_bytecode); | |
804 } | |
805 | 683 |
806 if (label->is_bound()) { | 684 if (label->is_bound()) { |
807 // Label has been bound already so this is a backwards jump. | 685 // Label has been bound already so this is a backwards jump. |
808 CHECK_GE(bytecodes()->size(), label->offset()); | 686 size_t current_offset = pipeline()->FlushForOffset(); |
rmcilroy
2016/05/10 11:14:09
nit - move FlushForOffset out of the if / else bra
oth
2016/05/11 13:17:30
Not possible in the latest revision as the FlushFo
| |
809 CHECK_LE(bytecodes()->size(), static_cast<size_t>(kMaxInt)); | 687 CHECK_GE(current_offset, label->offset()); |
810 size_t abs_delta = bytecodes()->size() - label->offset(); | 688 CHECK_LE(current_offset, static_cast<size_t>(kMaxInt)); |
689 size_t abs_delta = current_offset - label->offset(); | |
811 int delta = -static_cast<int>(abs_delta); | 690 int delta = -static_cast<int>(abs_delta); |
812 OperandSize operand_size = SizeForSignedOperand(delta); | 691 OperandSize operand_size = Bytecodes::SizeForSignedOperand(delta); |
813 if (operand_size > OperandSize::kByte) { | 692 if (operand_size > OperandSize::kByte) { |
814 // Adjust for scaling byte prefix for wide jump offset. | 693 // Adjust for scaling byte prefix for wide jump offset. |
815 DCHECK_LE(delta, 0); | 694 DCHECK_LE(delta, 0); |
816 delta -= 1; | 695 delta -= 1; |
817 } | 696 } |
818 OutputScaled(jump_bytecode, OperandSizesToScale(operand_size), | 697 OutputScaled(jump_bytecode, Bytecodes::OperandSizesToScale(operand_size), |
819 SignedOperand(delta, operand_size)); | 698 SignedOperand(delta, operand_size)); |
820 } else { | 699 } else { |
821 // The label has not yet been bound so this is a forward reference | 700 // The label has not yet been bound so this is a forward reference |
822 // that will be patched when the label is bound. We create a | 701 // that will be patched when the label is bound. We create a |
823 // reservation in the constant pool so the jump can be patched | 702 // reservation in the constant pool so the jump can be patched |
824 // when the label is bound. The reservation means the maximum size | 703 // when the label is bound. The reservation means the maximum size |
825 // of the operand for the constant is known and the jump can | 704 // of the operand for the constant is known and the jump can |
826 // be emitted into the bytecode stream with space for the operand. | 705 // be emitted into the bytecode stream with space for the operand. |
827 label->set_referrer(bytecodes()->size()); | 706 size_t offset = pipeline()->FlushForOffset(); |
707 label->set_referrer(offset); | |
828 unbound_jumps_++; | 708 unbound_jumps_++; |
829 OperandSize reserved_operand_size = | 709 OperandSize reserved_operand_size = |
830 constant_array_builder()->CreateReservedEntry(); | 710 constant_array_builder()->CreateReservedEntry(); |
831 OutputScaled(jump_bytecode, OperandSizesToScale(reserved_operand_size), 0); | 711 OutputScaled(jump_bytecode, |
712 Bytecodes::OperandSizesToScale(reserved_operand_size), 0); | |
832 } | 713 } |
833 LeaveBasicBlock(); | 714 LeaveBasicBlock(); |
834 return *this; | 715 return *this; |
835 } | 716 } |
836 | 717 |
837 | 718 |
838 BytecodeArrayBuilder& BytecodeArrayBuilder::Jump(BytecodeLabel* label) { | 719 BytecodeArrayBuilder& BytecodeArrayBuilder::Jump(BytecodeLabel* label) { |
839 return OutputJump(Bytecode::kJump, label); | 720 return OutputJump(Bytecode::kJump, label); |
840 } | 721 } |
841 | 722 |
(...skipping 15 matching lines...) Expand all Loading... | |
857 | 738 |
858 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfUndefined( | 739 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfUndefined( |
859 BytecodeLabel* label) { | 740 BytecodeLabel* label) { |
860 return OutputJump(Bytecode::kJumpIfUndefined, label); | 741 return OutputJump(Bytecode::kJumpIfUndefined, label); |
861 } | 742 } |
862 | 743 |
863 BytecodeArrayBuilder& BytecodeArrayBuilder::StackCheck(int position) { | 744 BytecodeArrayBuilder& BytecodeArrayBuilder::StackCheck(int position) { |
864 if (position != RelocInfo::kNoPosition) { | 745 if (position != RelocInfo::kNoPosition) { |
865 // We need to attach a non-breakable source position to a stack check, | 746 // We need to attach a non-breakable source position to a stack check, |
866 // so we simply add it as expression position. | 747 // so we simply add it as expression position. |
867 source_position_table_builder_.AddExpressionPosition(bytecodes_.size(), | 748 current_node()->source_info().Update({position, false}); |
868 position); | |
869 } | 749 } |
870 Output(Bytecode::kStackCheck); | 750 Output(Bytecode::kStackCheck); |
871 return *this; | 751 return *this; |
872 } | 752 } |
873 | 753 |
874 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNotHole( | 754 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNotHole( |
875 BytecodeLabel* label) { | 755 BytecodeLabel* label) { |
876 return OutputJump(Bytecode::kJumpIfNotHole, label); | 756 return OutputJump(Bytecode::kJumpIfNotHole, label); |
877 } | 757 } |
878 | 758 |
(...skipping 24 matching lines...) Expand all Loading... | |
903 } | 783 } |
904 | 784 |
905 BytecodeArrayBuilder& BytecodeArrayBuilder::Debugger() { | 785 BytecodeArrayBuilder& BytecodeArrayBuilder::Debugger() { |
906 Output(Bytecode::kDebugger); | 786 Output(Bytecode::kDebugger); |
907 return *this; | 787 return *this; |
908 } | 788 } |
909 | 789 |
910 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInPrepare( | 790 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInPrepare( |
911 Register cache_info_triple) { | 791 Register cache_info_triple) { |
912 OperandScale operand_scale = | 792 OperandScale operand_scale = |
913 OperandSizesToScale(cache_info_triple.SizeOfOperand()); | 793 Bytecodes::OperandSizesToScale(cache_info_triple.SizeOfOperand()); |
914 OutputScaled(Bytecode::kForInPrepare, operand_scale, | 794 OutputScaled(Bytecode::kForInPrepare, operand_scale, |
915 RegisterOperand(cache_info_triple)); | 795 RegisterOperand(cache_info_triple)); |
916 return *this; | 796 return *this; |
917 } | 797 } |
918 | 798 |
919 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInDone(Register index, | 799 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInDone(Register index, |
920 Register cache_length) { | 800 Register cache_length) { |
921 OperandScale operand_scale = | 801 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
922 OperandSizesToScale(index.SizeOfOperand(), cache_length.SizeOfOperand()); | 802 index.SizeOfOperand(), cache_length.SizeOfOperand()); |
923 OutputScaled(Bytecode::kForInDone, operand_scale, RegisterOperand(index), | 803 OutputScaled(Bytecode::kForInDone, operand_scale, RegisterOperand(index), |
924 RegisterOperand(cache_length)); | 804 RegisterOperand(cache_length)); |
925 return *this; | 805 return *this; |
926 } | 806 } |
927 | 807 |
928 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInNext( | 808 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInNext( |
929 Register receiver, Register index, Register cache_type_array_pair, | 809 Register receiver, Register index, Register cache_type_array_pair, |
930 int feedback_slot) { | 810 int feedback_slot) { |
931 OperandScale operand_scale = | 811 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
932 OperandSizesToScale(receiver.SizeOfOperand(), index.SizeOfOperand(), | 812 receiver.SizeOfOperand(), index.SizeOfOperand(), |
933 cache_type_array_pair.SizeOfOperand(), | 813 cache_type_array_pair.SizeOfOperand(), |
934 SizeForUnsignedOperand(feedback_slot)); | 814 Bytecodes::SizeForUnsignedOperand(feedback_slot)); |
935 OutputScaled(Bytecode::kForInNext, operand_scale, RegisterOperand(receiver), | 815 OutputScaled(Bytecode::kForInNext, operand_scale, RegisterOperand(receiver), |
936 RegisterOperand(index), RegisterOperand(cache_type_array_pair), | 816 RegisterOperand(index), RegisterOperand(cache_type_array_pair), |
937 UnsignedOperand(feedback_slot)); | 817 UnsignedOperand(feedback_slot)); |
938 return *this; | 818 return *this; |
939 } | 819 } |
940 | 820 |
941 | 821 |
942 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInStep(Register index) { | 822 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInStep(Register index) { |
943 OperandScale operand_scale = OperandSizesToScale(index.SizeOfOperand()); | 823 OperandScale operand_scale = |
824 Bytecodes::OperandSizesToScale(index.SizeOfOperand()); | |
944 OutputScaled(Bytecode::kForInStep, operand_scale, RegisterOperand(index)); | 825 OutputScaled(Bytecode::kForInStep, operand_scale, RegisterOperand(index)); |
945 return *this; | 826 return *this; |
946 } | 827 } |
947 | 828 |
948 | 829 |
949 BytecodeArrayBuilder& BytecodeArrayBuilder::SuspendGenerator( | 830 BytecodeArrayBuilder& BytecodeArrayBuilder::SuspendGenerator( |
950 Register generator) { | 831 Register generator) { |
951 OperandScale operand_scale = OperandSizesToScale(generator.SizeOfOperand()); | 832 OperandScale operand_scale = |
833 Bytecodes::OperandSizesToScale(generator.SizeOfOperand()); | |
952 OutputScaled(Bytecode::kSuspendGenerator, operand_scale, | 834 OutputScaled(Bytecode::kSuspendGenerator, operand_scale, |
953 RegisterOperand(generator)); | 835 RegisterOperand(generator)); |
954 return *this; | 836 return *this; |
955 } | 837 } |
956 | 838 |
957 | 839 |
958 BytecodeArrayBuilder& BytecodeArrayBuilder::ResumeGenerator( | 840 BytecodeArrayBuilder& BytecodeArrayBuilder::ResumeGenerator( |
959 Register generator) { | 841 Register generator) { |
960 OperandScale operand_scale = OperandSizesToScale(generator.SizeOfOperand()); | 842 OperandScale operand_scale = |
843 Bytecodes::OperandSizesToScale(generator.SizeOfOperand()); | |
961 OutputScaled(Bytecode::kResumeGenerator, operand_scale, | 844 OutputScaled(Bytecode::kResumeGenerator, operand_scale, |
962 RegisterOperand(generator)); | 845 RegisterOperand(generator)); |
963 return *this; | 846 return *this; |
964 } | 847 } |
965 | 848 |
966 | 849 |
967 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkHandler(int handler_id, | 850 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkHandler(int handler_id, |
968 bool will_catch) { | 851 bool will_catch) { |
969 handler_table_builder()->SetHandlerTarget(handler_id, bytecodes()->size()); | 852 size_t offset = pipeline()->FlushForOffset(); |
853 handler_table_builder()->SetHandlerTarget(handler_id, offset); | |
970 handler_table_builder()->SetPrediction(handler_id, will_catch); | 854 handler_table_builder()->SetPrediction(handler_id, will_catch); |
971 return *this; | 855 return *this; |
972 } | 856 } |
973 | 857 |
974 | 858 |
975 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkTryBegin(int handler_id, | 859 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkTryBegin(int handler_id, |
976 Register context) { | 860 Register context) { |
977 handler_table_builder()->SetTryRegionStart(handler_id, bytecodes()->size()); | 861 size_t offset = pipeline()->FlushForOffset(); |
862 handler_table_builder()->SetTryRegionStart(handler_id, offset); | |
978 handler_table_builder()->SetContextRegister(handler_id, context); | 863 handler_table_builder()->SetContextRegister(handler_id, context); |
979 return *this; | 864 return *this; |
980 } | 865 } |
981 | 866 |
982 | 867 |
983 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkTryEnd(int handler_id) { | 868 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkTryEnd(int handler_id) { |
984 handler_table_builder()->SetTryRegionEnd(handler_id, bytecodes()->size()); | 869 size_t offset = pipeline()->FlushForOffset(); |
870 handler_table_builder()->SetTryRegionEnd(handler_id, offset); | |
985 return *this; | 871 return *this; |
986 } | 872 } |
987 | 873 |
988 | 874 |
989 void BytecodeArrayBuilder::LeaveBasicBlock() { | 875 void BytecodeArrayBuilder::LeaveBasicBlock() { |
990 last_block_end_ = bytecodes()->size(); | |
991 exit_seen_in_block_ = false; | 876 exit_seen_in_block_ = false; |
877 pipeline()->LeaveBasicBlock(); | |
992 } | 878 } |
993 | 879 |
994 void BytecodeArrayBuilder::EnsureReturn() { | 880 void BytecodeArrayBuilder::EnsureReturn() { |
995 if (!exit_seen_in_block_) { | 881 if (!exit_seen_in_block_) { |
996 LoadUndefined(); | 882 LoadUndefined(); |
997 Return(); | 883 Return(); |
998 } | 884 } |
999 DCHECK(exit_seen_in_block_); | 885 DCHECK(exit_seen_in_block_); |
1000 } | 886 } |
1001 | 887 |
1002 BytecodeArrayBuilder& BytecodeArrayBuilder::Call(Register callable, | 888 BytecodeArrayBuilder& BytecodeArrayBuilder::Call(Register callable, |
1003 Register receiver_args, | 889 Register receiver_args, |
1004 size_t receiver_args_count, | 890 size_t receiver_args_count, |
1005 int feedback_slot, | 891 int feedback_slot, |
1006 TailCallMode tail_call_mode) { | 892 TailCallMode tail_call_mode) { |
1007 Bytecode bytecode = BytecodeForCall(tail_call_mode); | 893 Bytecode bytecode = BytecodeForCall(tail_call_mode); |
1008 OperandScale operand_scale = OperandSizesToScale( | 894 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
1009 callable.SizeOfOperand(), receiver_args.SizeOfOperand(), | 895 callable.SizeOfOperand(), receiver_args.SizeOfOperand(), |
1010 SizeForUnsignedOperand(receiver_args_count), | 896 Bytecodes::SizeForUnsignedOperand(receiver_args_count), |
1011 SizeForUnsignedOperand(feedback_slot)); | 897 Bytecodes::SizeForUnsignedOperand(feedback_slot)); |
1012 OutputScaled(bytecode, operand_scale, RegisterOperand(callable), | 898 OutputScaled(bytecode, operand_scale, RegisterOperand(callable), |
1013 RegisterOperand(receiver_args), | 899 RegisterOperand(receiver_args), |
1014 UnsignedOperand(receiver_args_count), | 900 UnsignedOperand(receiver_args_count), |
1015 UnsignedOperand(feedback_slot)); | 901 UnsignedOperand(feedback_slot)); |
1016 return *this; | 902 return *this; |
1017 } | 903 } |
1018 | 904 |
1019 BytecodeArrayBuilder& BytecodeArrayBuilder::New(Register constructor, | 905 BytecodeArrayBuilder& BytecodeArrayBuilder::New(Register constructor, |
1020 Register first_arg, | 906 Register first_arg, |
1021 size_t arg_count) { | 907 size_t arg_count) { |
1022 if (!first_arg.is_valid()) { | 908 if (!first_arg.is_valid()) { |
1023 DCHECK_EQ(0u, arg_count); | 909 DCHECK_EQ(0u, arg_count); |
1024 first_arg = Register(0); | 910 first_arg = Register(0); |
1025 } | 911 } |
1026 OperandScale operand_scale = OperandSizesToScale( | 912 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
1027 constructor.SizeOfOperand(), first_arg.SizeOfOperand(), | 913 constructor.SizeOfOperand(), first_arg.SizeOfOperand(), |
1028 SizeForUnsignedOperand(arg_count)); | 914 Bytecodes::SizeForUnsignedOperand(arg_count)); |
1029 OutputScaled(Bytecode::kNew, operand_scale, RegisterOperand(constructor), | 915 OutputScaled(Bytecode::kNew, operand_scale, RegisterOperand(constructor), |
1030 RegisterOperand(first_arg), UnsignedOperand(arg_count)); | 916 RegisterOperand(first_arg), UnsignedOperand(arg_count)); |
1031 return *this; | 917 return *this; |
1032 } | 918 } |
1033 | 919 |
1034 | 920 |
1035 BytecodeArrayBuilder& BytecodeArrayBuilder::CallRuntime( | 921 BytecodeArrayBuilder& BytecodeArrayBuilder::CallRuntime( |
1036 Runtime::FunctionId function_id, Register first_arg, size_t arg_count) { | 922 Runtime::FunctionId function_id, Register first_arg, size_t arg_count) { |
1037 DCHECK_EQ(1, Runtime::FunctionForId(function_id)->result_size); | 923 DCHECK_EQ(1, Runtime::FunctionForId(function_id)->result_size); |
1038 DCHECK(SizeForUnsignedOperand(function_id) <= OperandSize::kShort); | 924 DCHECK(Bytecodes::SizeForUnsignedOperand(function_id) <= OperandSize::kShort); |
1039 if (!first_arg.is_valid()) { | 925 if (!first_arg.is_valid()) { |
1040 DCHECK_EQ(0u, arg_count); | 926 DCHECK_EQ(0u, arg_count); |
1041 first_arg = Register(0); | 927 first_arg = Register(0); |
1042 } | 928 } |
1043 Bytecode bytecode = IntrinsicsHelper::IsSupported(function_id) | 929 Bytecode bytecode = IntrinsicsHelper::IsSupported(function_id) |
1044 ? Bytecode::kInvokeIntrinsic | 930 ? Bytecode::kInvokeIntrinsic |
1045 : Bytecode::kCallRuntime; | 931 : Bytecode::kCallRuntime; |
1046 OperandScale operand_scale = OperandSizesToScale( | 932 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
1047 first_arg.SizeOfOperand(), SizeForUnsignedOperand(arg_count)); | 933 first_arg.SizeOfOperand(), Bytecodes::SizeForUnsignedOperand(arg_count)); |
1048 OutputScaled(bytecode, operand_scale, static_cast<uint16_t>(function_id), | 934 OutputScaled(bytecode, operand_scale, static_cast<uint16_t>(function_id), |
1049 RegisterOperand(first_arg), UnsignedOperand(arg_count)); | 935 RegisterOperand(first_arg), UnsignedOperand(arg_count)); |
1050 return *this; | 936 return *this; |
1051 } | 937 } |
1052 | 938 |
1053 | 939 |
1054 BytecodeArrayBuilder& BytecodeArrayBuilder::CallRuntimeForPair( | 940 BytecodeArrayBuilder& BytecodeArrayBuilder::CallRuntimeForPair( |
1055 Runtime::FunctionId function_id, Register first_arg, size_t arg_count, | 941 Runtime::FunctionId function_id, Register first_arg, size_t arg_count, |
1056 Register first_return) { | 942 Register first_return) { |
1057 DCHECK_EQ(2, Runtime::FunctionForId(function_id)->result_size); | 943 DCHECK_EQ(2, Runtime::FunctionForId(function_id)->result_size); |
1058 DCHECK(SizeForUnsignedOperand(function_id) <= OperandSize::kShort); | 944 DCHECK(Bytecodes::SizeForUnsignedOperand(function_id) <= OperandSize::kShort); |
1059 if (!first_arg.is_valid()) { | 945 if (!first_arg.is_valid()) { |
1060 DCHECK_EQ(0u, arg_count); | 946 DCHECK_EQ(0u, arg_count); |
1061 first_arg = Register(0); | 947 first_arg = Register(0); |
1062 } | 948 } |
1063 OperandScale operand_scale = OperandSizesToScale( | 949 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
1064 first_arg.SizeOfOperand(), SizeForUnsignedOperand(arg_count), | 950 first_arg.SizeOfOperand(), Bytecodes::SizeForUnsignedOperand(arg_count), |
1065 first_return.SizeOfOperand()); | 951 first_return.SizeOfOperand()); |
1066 OutputScaled(Bytecode::kCallRuntimeForPair, operand_scale, | 952 OutputScaled(Bytecode::kCallRuntimeForPair, operand_scale, |
1067 static_cast<uint16_t>(function_id), RegisterOperand(first_arg), | 953 static_cast<uint16_t>(function_id), RegisterOperand(first_arg), |
1068 UnsignedOperand(arg_count), RegisterOperand(first_return)); | 954 UnsignedOperand(arg_count), RegisterOperand(first_return)); |
1069 return *this; | 955 return *this; |
1070 } | 956 } |
1071 | 957 |
1072 BytecodeArrayBuilder& BytecodeArrayBuilder::CallJSRuntime( | 958 BytecodeArrayBuilder& BytecodeArrayBuilder::CallJSRuntime( |
1073 int context_index, Register receiver_args, size_t receiver_args_count) { | 959 int context_index, Register receiver_args, size_t receiver_args_count) { |
1074 OperandScale operand_scale = OperandSizesToScale( | 960 OperandScale operand_scale = Bytecodes::OperandSizesToScale( |
1075 SizeForUnsignedOperand(context_index), receiver_args.SizeOfOperand(), | 961 Bytecodes::SizeForUnsignedOperand(context_index), |
1076 SizeForUnsignedOperand(receiver_args_count)); | 962 receiver_args.SizeOfOperand(), |
963 Bytecodes::SizeForUnsignedOperand(receiver_args_count)); | |
1077 OutputScaled(Bytecode::kCallJSRuntime, operand_scale, | 964 OutputScaled(Bytecode::kCallJSRuntime, operand_scale, |
1078 UnsignedOperand(context_index), RegisterOperand(receiver_args), | 965 UnsignedOperand(context_index), RegisterOperand(receiver_args), |
1079 UnsignedOperand(receiver_args_count)); | 966 UnsignedOperand(receiver_args_count)); |
1080 return *this; | 967 return *this; |
1081 } | 968 } |
1082 | 969 |
1083 | 970 |
1084 BytecodeArrayBuilder& BytecodeArrayBuilder::Delete(Register object, | 971 BytecodeArrayBuilder& BytecodeArrayBuilder::Delete(Register object, |
1085 LanguageMode language_mode) { | 972 LanguageMode language_mode) { |
1086 OperandScale operand_scale = OperandSizesToScale(object.SizeOfOperand()); | 973 OperandScale operand_scale = |
974 Bytecodes::OperandSizesToScale(object.SizeOfOperand()); | |
1087 OutputScaled(BytecodeForDelete(language_mode), operand_scale, | 975 OutputScaled(BytecodeForDelete(language_mode), operand_scale, |
1088 RegisterOperand(object)); | 976 RegisterOperand(object)); |
1089 return *this; | 977 return *this; |
1090 } | 978 } |
1091 | 979 |
1092 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { | 980 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { |
1093 return constant_array_builder()->Insert(object); | 981 return constant_array_builder()->Insert(object); |
1094 } | 982 } |
1095 | 983 |
1096 void BytecodeArrayBuilder::SetReturnPosition() { | 984 void BytecodeArrayBuilder::SetReturnPosition() { |
1097 if (return_position_ == RelocInfo::kNoPosition) return; | 985 if (return_position_ == RelocInfo::kNoPosition) return; |
1098 if (exit_seen_in_block_) return; | 986 if (exit_seen_in_block_) return; |
1099 source_position_table_builder_.AddStatementPosition(bytecodes_.size(), | 987 current_node()->source_info().Update({return_position_, true}); |
1100 return_position_); | |
1101 } | 988 } |
1102 | 989 |
1103 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { | 990 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { |
1104 if (stmt->position() == RelocInfo::kNoPosition) return; | 991 if (stmt->position() == RelocInfo::kNoPosition) return; |
1105 if (exit_seen_in_block_) return; | 992 if (exit_seen_in_block_) return; |
1106 source_position_table_builder_.AddStatementPosition(bytecodes_.size(), | 993 current_node()->source_info().Update({stmt->position(), true}); |
1107 stmt->position()); | |
1108 } | 994 } |
1109 | 995 |
1110 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { | 996 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { |
1111 if (expr->position() == RelocInfo::kNoPosition) return; | 997 if (expr->position() == RelocInfo::kNoPosition) return; |
1112 if (exit_seen_in_block_) return; | 998 if (exit_seen_in_block_) return; |
1113 source_position_table_builder_.AddExpressionPosition(bytecodes_.size(), | 999 current_node()->source_info().Update({expr->position(), false}); |
1114 expr->position()); | |
1115 } | 1000 } |
1116 | 1001 |
1117 void BytecodeArrayBuilder::SetExpressionAsStatementPosition(Expression* expr) { | 1002 void BytecodeArrayBuilder::SetExpressionAsStatementPosition(Expression* expr) { |
1118 if (expr->position() == RelocInfo::kNoPosition) return; | 1003 if (expr->position() == RelocInfo::kNoPosition) return; |
1119 if (exit_seen_in_block_) return; | 1004 if (exit_seen_in_block_) return; |
1120 source_position_table_builder_.AddStatementPosition(bytecodes_.size(), | 1005 current_node()->source_info().Update({expr->position(), true}); |
1121 expr->position()); | |
1122 } | 1006 } |
1123 | 1007 |
1124 bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const { | 1008 bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const { |
1125 return temporary_register_allocator()->RegisterIsLive(reg); | 1009 return temporary_register_allocator()->RegisterIsLive(reg); |
1126 } | 1010 } |
1127 | 1011 |
1128 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, | 1012 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, |
1129 OperandScale operand_scale, | 1013 OperandScale operand_scale, |
1130 int operand_index, | 1014 int operand_index, |
1131 uint32_t operand_value) const { | 1015 uint32_t operand_value) const { |
(...skipping 11 matching lines...) Expand all Loading... | |
1143 previous_operand_type != OperandType::kReg) { | 1027 previous_operand_type != OperandType::kReg) { |
1144 return false; | 1028 return false; |
1145 } | 1029 } |
1146 } | 1030 } |
1147 } // Fall-through | 1031 } // Fall-through |
1148 case OperandType::kFlag8: | 1032 case OperandType::kFlag8: |
1149 case OperandType::kIdx: | 1033 case OperandType::kIdx: |
1150 case OperandType::kRuntimeId: | 1034 case OperandType::kRuntimeId: |
1151 case OperandType::kImm: { | 1035 case OperandType::kImm: { |
1152 size_t unsigned_value = static_cast<size_t>(operand_value); | 1036 size_t unsigned_value = static_cast<size_t>(operand_value); |
1153 return SizeForUnsignedOperand(unsigned_value) <= operand_size; | 1037 return Bytecodes::SizeForUnsignedOperand(unsigned_value) <= operand_size; |
1154 } | 1038 } |
1155 case OperandType::kMaybeReg: | 1039 case OperandType::kMaybeReg: |
1156 if (RegisterFromOperand(operand_value) == Register(0)) { | 1040 if (RegisterFromOperand(operand_value) == Register(0)) { |
1157 return true; | 1041 return true; |
1158 } | 1042 } |
1159 // Fall-through to kReg case. | 1043 // Fall-through to kReg case. |
1160 case OperandType::kReg: | 1044 case OperandType::kReg: |
1161 case OperandType::kRegOut: { | 1045 case OperandType::kRegOut: { |
1162 Register reg = RegisterFromOperand(operand_value); | 1046 Register reg = RegisterFromOperand(operand_value); |
1163 return RegisterIsValid(reg, operand_size); | 1047 return RegisterIsValid(reg, operand_size); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1200 } else if (reg.is_parameter()) { | 1084 } else if (reg.is_parameter()) { |
1201 int parameter_index = reg.ToParameterIndex(parameter_count()); | 1085 int parameter_index = reg.ToParameterIndex(parameter_count()); |
1202 return parameter_index >= 0 && parameter_index < parameter_count(); | 1086 return parameter_index >= 0 && parameter_index < parameter_count(); |
1203 } else if (reg.index() < fixed_register_count()) { | 1087 } else if (reg.index() < fixed_register_count()) { |
1204 return true; | 1088 return true; |
1205 } else { | 1089 } else { |
1206 return TemporaryRegisterIsLive(reg); | 1090 return TemporaryRegisterIsLive(reg); |
1207 } | 1091 } |
1208 } | 1092 } |
1209 | 1093 |
1210 | |
1211 bool BytecodeArrayBuilder::LastBytecodeInSameBlock() const { | |
1212 return last_bytecode_start_ < bytecodes()->size() && | |
1213 last_bytecode_start_ >= last_block_end_; | |
1214 } | |
1215 | |
1216 | |
1217 bool BytecodeArrayBuilder::IsRegisterInAccumulator(Register reg) { | |
1218 if (LastBytecodeInSameBlock()) { | |
1219 PreviousBytecodeHelper previous_bytecode(*this); | |
1220 Bytecode bytecode = previous_bytecode.GetBytecode(); | |
1221 if (bytecode == Bytecode::kLdar || bytecode == Bytecode::kStar) { | |
1222 return previous_bytecode.GetRegisterOperand(0) == reg; | |
1223 } | |
1224 } | |
1225 return false; | |
1226 } | |
1227 | |
1228 | |
1229 // static | 1094 // static |
1230 Bytecode BytecodeArrayBuilder::BytecodeForBinaryOperation(Token::Value op) { | 1095 Bytecode BytecodeArrayBuilder::BytecodeForBinaryOperation(Token::Value op) { |
1231 switch (op) { | 1096 switch (op) { |
1232 case Token::Value::ADD: | 1097 case Token::Value::ADD: |
1233 return Bytecode::kAdd; | 1098 return Bytecode::kAdd; |
1234 case Token::Value::SUB: | 1099 case Token::Value::SUB: |
1235 return Bytecode::kSub; | 1100 return Bytecode::kSub; |
1236 case Token::Value::MUL: | 1101 case Token::Value::MUL: |
1237 return Bytecode::kMul; | 1102 return Bytecode::kMul; |
1238 case Token::Value::DIV: | 1103 case Token::Value::DIV: |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1400 case TailCallMode::kDisallow: | 1265 case TailCallMode::kDisallow: |
1401 return Bytecode::kCall; | 1266 return Bytecode::kCall; |
1402 case TailCallMode::kAllow: | 1267 case TailCallMode::kAllow: |
1403 return Bytecode::kTailCall; | 1268 return Bytecode::kTailCall; |
1404 default: | 1269 default: |
1405 UNREACHABLE(); | 1270 UNREACHABLE(); |
1406 } | 1271 } |
1407 return Bytecode::kIllegal; | 1272 return Bytecode::kIllegal; |
1408 } | 1273 } |
1409 | 1274 |
1410 // static | |
1411 OperandSize BytecodeArrayBuilder::SizeForSignedOperand(int value) { | |
1412 if (kMinInt8 <= value && value <= kMaxInt8) { | |
1413 return OperandSize::kByte; | |
1414 } else if (kMinInt16 <= value && value <= kMaxInt16) { | |
1415 return OperandSize::kShort; | |
1416 } else { | |
1417 return OperandSize::kQuad; | |
1418 } | |
1419 } | |
1420 | |
1421 // static | |
1422 OperandSize BytecodeArrayBuilder::SizeForUnsignedOperand(int value) { | |
1423 DCHECK_GE(value, 0); | |
1424 if (value <= kMaxUInt8) { | |
1425 return OperandSize::kByte; | |
1426 } else if (value <= kMaxUInt16) { | |
1427 return OperandSize::kShort; | |
1428 } else { | |
1429 return OperandSize::kQuad; | |
1430 } | |
1431 } | |
1432 | |
1433 OperandSize BytecodeArrayBuilder::SizeForUnsignedOperand(size_t value) { | |
1434 if (value <= static_cast<size_t>(kMaxUInt8)) { | |
1435 return OperandSize::kByte; | |
1436 } else if (value <= static_cast<size_t>(kMaxUInt16)) { | |
1437 return OperandSize::kShort; | |
1438 } else if (value <= kMaxUInt32) { | |
1439 return OperandSize::kQuad; | |
1440 } else { | |
1441 UNREACHABLE(); | |
1442 return OperandSize::kQuad; | |
1443 } | |
1444 } | |
1445 | |
1446 OperandScale BytecodeArrayBuilder::OperandSizesToScale(OperandSize size0, | |
1447 OperandSize size1, | |
1448 OperandSize size2, | |
1449 OperandSize size3) { | |
1450 OperandSize upper = std::max(size0, size1); | |
1451 OperandSize lower = std::max(size2, size3); | |
1452 OperandSize result = std::max(upper, lower); | |
1453 // Operand sizes have been scaled before calling this function. | |
1454 // Currently all scalable operands are byte sized at | |
1455 // OperandScale::kSingle. | |
1456 STATIC_ASSERT(static_cast<int>(OperandSize::kByte) == | |
1457 static_cast<int>(OperandScale::kSingle) && | |
1458 static_cast<int>(OperandSize::kShort) == | |
1459 static_cast<int>(OperandScale::kDouble) && | |
1460 static_cast<int>(OperandSize::kQuad) == | |
1461 static_cast<int>(OperandScale::kQuadruple)); | |
1462 OperandScale operand_scale = static_cast<OperandScale>(result); | |
1463 DCHECK(operand_scale == OperandScale::kSingle || | |
1464 operand_scale == OperandScale::kDouble || | |
1465 operand_scale == OperandScale::kQuadruple); | |
1466 return operand_scale; | |
1467 } | |
1468 | |
1469 uint32_t BytecodeArrayBuilder::RegisterOperand(Register reg) { | 1275 uint32_t BytecodeArrayBuilder::RegisterOperand(Register reg) { |
1470 return static_cast<uint32_t>(reg.ToOperand()); | 1276 return static_cast<uint32_t>(reg.ToOperand()); |
1471 } | 1277 } |
1472 | 1278 |
1473 Register BytecodeArrayBuilder::RegisterFromOperand(uint32_t operand) { | 1279 Register BytecodeArrayBuilder::RegisterFromOperand(uint32_t operand) { |
1474 return Register::FromOperand(static_cast<int32_t>(operand)); | 1280 return Register::FromOperand(static_cast<int32_t>(operand)); |
1475 } | 1281 } |
1476 | 1282 |
1477 uint32_t BytecodeArrayBuilder::SignedOperand(int value, OperandSize size) { | 1283 uint32_t BytecodeArrayBuilder::SignedOperand(int value, OperandSize size) { |
1478 switch (size) { | 1284 switch (size) { |
(...skipping 15 matching lines...) Expand all Loading... | |
1494 } | 1300 } |
1495 | 1301 |
1496 uint32_t BytecodeArrayBuilder::UnsignedOperand(size_t value) { | 1302 uint32_t BytecodeArrayBuilder::UnsignedOperand(size_t value) { |
1497 DCHECK_LE(value, kMaxUInt32); | 1303 DCHECK_LE(value, kMaxUInt32); |
1498 return static_cast<uint32_t>(value); | 1304 return static_cast<uint32_t>(value); |
1499 } | 1305 } |
1500 | 1306 |
1501 } // namespace interpreter | 1307 } // namespace interpreter |
1502 } // namespace internal | 1308 } // namespace internal |
1503 } // namespace v8 | 1309 } // namespace v8 |
OLD | NEW |