Chromium Code Reviews| 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 #ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
| 6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_ | 6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
| 7 | 7 |
| 8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/globals.h" | 9 #include "src/globals.h" |
| 10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 operand_count_(4), | 184 operand_count_(4), |
| 185 operand_scale_(OperandScale::kSingle), | 185 operand_scale_(OperandScale::kSingle), |
| 186 source_info_(source_info) { | 186 source_info_(source_info) { |
| 187 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); | 187 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); |
| 188 SetOperand(0, operand0); | 188 SetOperand(0, operand0); |
| 189 SetOperand(1, operand1); | 189 SetOperand(1, operand1); |
| 190 SetOperand(2, operand2); | 190 SetOperand(2, operand2); |
| 191 SetOperand(3, operand3); | 191 SetOperand(3, operand3); |
| 192 } | 192 } |
| 193 | 193 |
| 194 #define DEFINE_BYTECODE_NODE_CREATOR(Name, ...) \ | |
| 195 template <typename... Operands> \ | |
| 196 INLINE(static BytecodeNode Name(BytecodeSourceInfo source_info, \ | |
| 197 Operands... operands)) { \ | |
| 198 return Create<Bytecode::k##Name, __VA_ARGS__>(source_info, operands...); \ | |
| 199 } | |
| 200 // Create<Bytecode::k##Name, __VA_ARGS__>(operands...); \ | |
| 201 // } | |
|
Leszek Swirski
2016/12/12 14:55:41
remove?
rmcilroy
2016/12/15 07:52:55
Opps good catch - thanks! Done.
| |
| 202 BYTECODE_LIST(DEFINE_BYTECODE_NODE_CREATOR) | |
| 203 #undef DEFINE_BYTECODE_NODE_CREATOR | |
| 204 | |
| 194 // Replace the bytecode of this node with |bytecode| and keep the operands. | 205 // Replace the bytecode of this node with |bytecode| and keep the operands. |
| 195 void replace_bytecode(Bytecode bytecode) { | 206 void replace_bytecode(Bytecode bytecode) { |
| 196 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_), | 207 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_), |
| 197 Bytecodes::NumberOfOperands(bytecode)); | 208 Bytecodes::NumberOfOperands(bytecode)); |
| 198 bytecode_ = bytecode; | 209 bytecode_ = bytecode; |
| 199 } | 210 } |
| 200 | 211 |
| 201 void set_bytecode(Bytecode bytecode) { | 212 void update_operand0(uint32_t operand0) { SetOperand(0, operand0); } |
| 202 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); | |
| 203 bytecode_ = bytecode; | |
| 204 operand_count_ = 0; | |
| 205 operand_scale_ = OperandScale::kSingle; | |
| 206 } | |
| 207 | |
| 208 void set_bytecode(Bytecode bytecode, uint32_t operand0) { | |
| 209 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); | |
| 210 bytecode_ = bytecode; | |
| 211 operand_count_ = 1; | |
| 212 operand_scale_ = OperandScale::kSingle; | |
| 213 SetOperand(0, operand0); | |
| 214 } | |
| 215 | |
| 216 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) { | |
| 217 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2); | |
| 218 bytecode_ = bytecode; | |
| 219 operand_count_ = 2; | |
| 220 operand_scale_ = OperandScale::kSingle; | |
| 221 SetOperand(0, operand0); | |
| 222 SetOperand(1, operand1); | |
| 223 } | |
| 224 | |
| 225 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | |
| 226 uint32_t operand2) { | |
| 227 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); | |
| 228 bytecode_ = bytecode; | |
| 229 operand_count_ = 3; | |
| 230 operand_scale_ = OperandScale::kSingle; | |
| 231 SetOperand(0, operand0); | |
| 232 SetOperand(1, operand1); | |
| 233 SetOperand(2, operand2); | |
| 234 } | |
| 235 | 213 |
| 236 // Print to stream |os|. | 214 // Print to stream |os|. |
| 237 void Print(std::ostream& os) const; | 215 void Print(std::ostream& os) const; |
| 238 | 216 |
| 239 // Transform to a node representing |new_bytecode| which has one | 217 // Transform to a node representing |new_bytecode| which has one |
| 240 // operand more than the current bytecode. | 218 // operand more than the current bytecode. |
| 241 void Transform(Bytecode new_bytecode, uint32_t extra_operand) { | 219 void Transform(Bytecode new_bytecode, uint32_t extra_operand) { |
| 242 DCHECK_EQ(Bytecodes::NumberOfOperands(new_bytecode), | 220 DCHECK_EQ(Bytecodes::NumberOfOperands(new_bytecode), |
| 243 Bytecodes::NumberOfOperands(bytecode()) + 1); | 221 Bytecodes::NumberOfOperands(bytecode()) + 1); |
| 244 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 1 || | 222 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 1 || |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 270 | 248 |
| 271 const BytecodeSourceInfo& source_info() const { return source_info_; } | 249 const BytecodeSourceInfo& source_info() const { return source_info_; } |
| 272 void set_source_info(BytecodeSourceInfo source_info) { | 250 void set_source_info(BytecodeSourceInfo source_info) { |
| 273 source_info_ = source_info; | 251 source_info_ = source_info; |
| 274 } | 252 } |
| 275 | 253 |
| 276 bool operator==(const BytecodeNode& other) const; | 254 bool operator==(const BytecodeNode& other) const; |
| 277 bool operator!=(const BytecodeNode& other) const { return !(*this == other); } | 255 bool operator!=(const BytecodeNode& other) const { return !(*this == other); } |
| 278 | 256 |
| 279 private: | 257 private: |
| 258 template <Bytecode bytecode, AccumulatorUse accumulator_use, | |
| 259 OperandType... operand_types> | |
| 260 friend class BytecodeNodeBuilder; | |
| 261 | |
| 262 INLINE(BytecodeNode(Bytecode bytecode, int operand_count, | |
| 263 OperandScale operand_scale, | |
| 264 BytecodeSourceInfo source_info, uint32_t operand0 = 0, | |
| 265 uint32_t operand1 = 0, uint32_t operand2 = 0, | |
| 266 uint32_t operand3 = 0)) | |
| 267 : bytecode_(bytecode), | |
| 268 operand_count_(operand_count), | |
| 269 operand_scale_(operand_scale), | |
| 270 source_info_(source_info) { | |
| 271 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count); | |
| 272 operands_[0] = operand0; | |
| 273 operands_[1] = operand1; | |
| 274 operands_[2] = operand2; | |
| 275 operands_[3] = operand3; | |
| 276 } | |
| 277 | |
| 278 template <Bytecode bytecode, AccumulatorUse accum_use> | |
| 279 INLINE(static BytecodeNode Create(BytecodeSourceInfo source_info)) { | |
| 280 return BytecodeNode(bytecode, 0, OperandScale::kSingle, source_info); | |
| 281 } | |
| 282 | |
| 283 template <Bytecode bytecode, AccumulatorUse accum_use, | |
| 284 OperandType operand0_type> | |
| 285 INLINE(static BytecodeNode Create(BytecodeSourceInfo source_info, | |
| 286 uint32_t operand0)) { | |
| 287 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type); | |
| 288 OperandScale scale = OperandScale::kSingle; | |
| 289 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0)); | |
| 290 return BytecodeNode(bytecode, 1, scale, source_info, operand0); | |
| 291 } | |
| 292 | |
| 293 template <Bytecode bytecode, AccumulatorUse accum_use, | |
| 294 OperandType operand0_type, OperandType operand1_type> | |
| 295 INLINE(static BytecodeNode Create(BytecodeSourceInfo source_info, | |
| 296 uint32_t operand0, uint32_t operand1)) { | |
| 297 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type); | |
| 298 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 1), operand1_type); | |
| 299 OperandScale scale = OperandScale::kSingle; | |
| 300 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0)); | |
| 301 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1)); | |
| 302 return BytecodeNode(bytecode, 2, scale, source_info, operand0, operand1); | |
| 303 } | |
| 304 | |
| 305 template <Bytecode bytecode, AccumulatorUse accum_use, | |
| 306 OperandType operand0_type, OperandType operand1_type, | |
| 307 OperandType operand2_type> | |
| 308 INLINE(static BytecodeNode Create(BytecodeSourceInfo source_info, | |
| 309 uint32_t operand0, uint32_t operand1, | |
| 310 uint32_t operand2)) { | |
| 311 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type); | |
| 312 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 1), operand1_type); | |
| 313 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 2), operand2_type); | |
| 314 OperandScale scale = OperandScale::kSingle; | |
| 315 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0)); | |
| 316 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1)); | |
| 317 scale = std::max(scale, ScaleForOperand<operand2_type>(operand2)); | |
| 318 return BytecodeNode(bytecode, 3, scale, source_info, operand0, operand1, | |
| 319 operand2); | |
| 320 } | |
| 321 | |
| 322 template <Bytecode bytecode, AccumulatorUse accum_use, | |
| 323 OperandType operand0_type, OperandType operand1_type, | |
| 324 OperandType operand2_type, OperandType operand3_type> | |
| 325 INLINE(static BytecodeNode Create(BytecodeSourceInfo source_info, | |
| 326 uint32_t operand0, uint32_t operand1, | |
| 327 uint32_t operand2, uint32_t operand3)) { | |
| 328 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type); | |
| 329 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 1), operand1_type); | |
| 330 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 2), operand2_type); | |
| 331 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 3), operand3_type); | |
| 332 OperandScale scale = OperandScale::kSingle; | |
| 333 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0)); | |
| 334 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1)); | |
| 335 scale = std::max(scale, ScaleForOperand<operand2_type>(operand2)); | |
| 336 scale = std::max(scale, ScaleForOperand<operand3_type>(operand3)); | |
| 337 return BytecodeNode(bytecode, 4, scale, source_info, operand0, operand1, | |
| 338 operand2, operand3); | |
| 339 } | |
| 340 | |
| 341 template <OperandType operand_type> | |
| 342 INLINE(static OperandScale ScaleForOperand(uint32_t operand)) { | |
| 343 if (BytecodeOperands::IsScalableUnsignedByte(operand_type)) { | |
| 344 return Bytecodes::ScaleForUnsignedOperand(operand); | |
| 345 } else if (BytecodeOperands::IsScalableSignedByte(operand_type)) { | |
| 346 return Bytecodes::ScaleForSignedOperand(operand); | |
| 347 } else { | |
| 348 return OperandScale::kSingle; | |
| 349 } | |
| 350 } | |
| 351 | |
| 280 INLINE(void UpdateScaleForOperand(int operand_index, uint32_t operand)) { | 352 INLINE(void UpdateScaleForOperand(int operand_index, uint32_t operand)) { |
| 281 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) { | 353 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) { |
| 282 operand_scale_ = | 354 operand_scale_ = |
| 283 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand)); | 355 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand)); |
| 284 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(), | 356 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(), |
| 285 operand_index)) { | 357 operand_index)) { |
| 286 operand_scale_ = | 358 operand_scale_ = |
| 287 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand)); | 359 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand)); |
| 288 } | 360 } |
| 289 } | 361 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 303 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, | 375 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, |
| 304 const BytecodeSourceInfo& info); | 376 const BytecodeSourceInfo& info); |
| 305 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, | 377 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, |
| 306 const BytecodeNode& node); | 378 const BytecodeNode& node); |
| 307 | 379 |
| 308 } // namespace interpreter | 380 } // namespace interpreter |
| 309 } // namespace internal | 381 } // namespace internal |
| 310 } // namespace v8 | 382 } // namespace v8 |
| 311 | 383 |
| 312 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ | 384 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
| OLD | NEW |