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