| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #ifndef V8_LITHIUM_H_ | 28 #ifndef V8_LITHIUM_H_ |
| 29 #define V8_LITHIUM_H_ | 29 #define V8_LITHIUM_H_ |
| 30 | 30 |
| 31 #include "allocation.h" | 31 #include "allocation.h" |
| 32 #include "hydrogen.h" | 32 #include "hydrogen.h" |
| 33 #include "safepoint-table.h" | 33 #include "safepoint-table.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 #define LITHIUM_OPERAND_LIST(V) \ | 38 #define LITHIUM_OPERAND_LIST(V) \ |
| 39 V(ConstantOperand, CONSTANT_OPERAND) \ | 39 V(ConstantOperand, CONSTANT_OPERAND, 128) \ |
| 40 V(StackSlot, STACK_SLOT) \ | 40 V(StackSlot, STACK_SLOT, 128) \ |
| 41 V(DoubleStackSlot, DOUBLE_STACK_SLOT) \ | 41 V(DoubleStackSlot, DOUBLE_STACK_SLOT, 128) \ |
| 42 V(Register, REGISTER) \ | 42 V(Register, REGISTER, 16) \ |
| 43 V(DoubleRegister, DOUBLE_REGISTER) | 43 V(DoubleRegister, DOUBLE_REGISTER, 16) |
| 44 | 44 |
| 45 | 45 |
| 46 class LOperand : public ZoneObject { | 46 class LOperand : public ZoneObject { |
| 47 public: | 47 public: |
| 48 enum Kind { | 48 enum Kind { |
| 49 INVALID, | 49 INVALID, |
| 50 UNALLOCATED, | 50 UNALLOCATED, |
| 51 CONSTANT_OPERAND, | 51 CONSTANT_OPERAND, |
| 52 STACK_SLOT, | 52 STACK_SLOT, |
| 53 DOUBLE_STACK_SLOT, | 53 DOUBLE_STACK_SLOT, |
| 54 REGISTER, | 54 REGISTER, |
| 55 DOUBLE_REGISTER, | 55 DOUBLE_REGISTER |
| 56 ARGUMENT | |
| 57 }; | 56 }; |
| 58 | 57 |
| 59 LOperand() : value_(KindField::encode(INVALID)) { } | 58 LOperand() : value_(KindField::encode(INVALID)) { } |
| 60 | 59 |
| 61 Kind kind() const { return KindField::decode(value_); } | 60 Kind kind() const { return KindField::decode(value_); } |
| 62 int index() const { return static_cast<int>(value_) >> kKindFieldWidth; } | 61 int index() const { return static_cast<int>(value_) >> kKindFieldWidth; } |
| 63 #define LITHIUM_OPERAND_PREDICATE(name, type) \ | 62 #define LITHIUM_OPERAND_PREDICATE(name, type, number) \ |
| 64 bool Is##name() const { return kind() == type; } | 63 bool Is##name() const { return kind() == type; } |
| 65 LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE) | 64 LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE) |
| 66 LITHIUM_OPERAND_PREDICATE(Argument, ARGUMENT) | 65 LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED, 0) |
| 67 LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED) | 66 LITHIUM_OPERAND_PREDICATE(Ignored, INVALID, 0) |
| 68 LITHIUM_OPERAND_PREDICATE(Ignored, INVALID) | |
| 69 #undef LITHIUM_OPERAND_PREDICATE | 67 #undef LITHIUM_OPERAND_PREDICATE |
| 70 bool Equals(LOperand* other) const { return value_ == other->value_; } | 68 bool Equals(LOperand* other) const { return value_ == other->value_; } |
| 71 | 69 |
| 72 void PrintTo(StringStream* stream); | 70 void PrintTo(StringStream* stream); |
| 73 void ConvertTo(Kind kind, int index) { | 71 void ConvertTo(Kind kind, int index) { |
| 74 value_ = KindField::encode(kind); | 72 value_ = KindField::encode(kind); |
| 75 value_ |= index << kKindFieldWidth; | 73 value_ |= index << kKindFieldWidth; |
| 76 ASSERT(this->index() == index); | 74 ASSERT(this->index() == index); |
| 77 } | 75 } |
| 78 | 76 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 ASSERT(source_ != NULL || destination_ == NULL); | 308 ASSERT(source_ != NULL || destination_ == NULL); |
| 311 return source_ == NULL; | 309 return source_ == NULL; |
| 312 } | 310 } |
| 313 | 311 |
| 314 private: | 312 private: |
| 315 LOperand* source_; | 313 LOperand* source_; |
| 316 LOperand* destination_; | 314 LOperand* destination_; |
| 317 }; | 315 }; |
| 318 | 316 |
| 319 | 317 |
| 320 class LConstantOperand V8_FINAL : public LOperand { | 318 template<LOperand::Kind kOperandKind, int kNumCachedOperands> |
| 319 class LSubKindOperand V8_FINAL : public LOperand { |
| 321 public: | 320 public: |
| 322 static LConstantOperand* Create(int index, Zone* zone) { | 321 static LSubKindOperand* Create(int index, Zone* zone) { |
| 323 ASSERT(index >= 0); | 322 ASSERT(index >= 0); |
| 324 if (index < kNumCachedOperands) return &cache[index]; | 323 if (index < kNumCachedOperands) return &cache[index]; |
| 325 return new(zone) LConstantOperand(index); | 324 return new(zone) LSubKindOperand(index); |
| 326 } | 325 } |
| 327 | 326 |
| 328 static LConstantOperand* cast(LOperand* op) { | 327 static LSubKindOperand* cast(LOperand* op) { |
| 329 ASSERT(op->IsConstantOperand()); | 328 ASSERT(op->kind() == kOperandKind); |
| 330 return reinterpret_cast<LConstantOperand*>(op); | 329 return reinterpret_cast<LSubKindOperand*>(op); |
| 331 } | 330 } |
| 332 | 331 |
| 333 static void SetUpCache(); | 332 static void SetUpCache(); |
| 334 static void TearDownCache(); | 333 static void TearDownCache(); |
| 335 | 334 |
| 336 private: | 335 private: |
| 337 static const int kNumCachedOperands = 128; | 336 static LSubKindOperand* cache; |
| 338 static LConstantOperand* cache; | |
| 339 | 337 |
| 340 LConstantOperand() : LOperand() { } | 338 LSubKindOperand() : LOperand() { } |
| 341 explicit LConstantOperand(int index) : LOperand(CONSTANT_OPERAND, index) { } | 339 explicit LSubKindOperand(int index) : LOperand(kOperandKind, index) { } |
| 342 }; | 340 }; |
| 343 | 341 |
| 344 | 342 |
| 345 class LArgument V8_FINAL : public LOperand { | 343 #define LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS(name, type, number) \ |
| 346 public: | 344 typedef LSubKindOperand<LOperand::type, number> L##name; |
| 347 explicit LArgument(int index) : LOperand(ARGUMENT, index) { } | 345 LITHIUM_OPERAND_LIST(LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS) |
| 348 | 346 #undef LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS |
| 349 static LArgument* cast(LOperand* op) { | |
| 350 ASSERT(op->IsArgument()); | |
| 351 return reinterpret_cast<LArgument*>(op); | |
| 352 } | |
| 353 }; | |
| 354 | |
| 355 | |
| 356 class LStackSlot V8_FINAL : public LOperand { | |
| 357 public: | |
| 358 static LStackSlot* Create(int index, Zone* zone) { | |
| 359 ASSERT(index >= 0); | |
| 360 if (index < kNumCachedOperands) return &cache[index]; | |
| 361 return new(zone) LStackSlot(index); | |
| 362 } | |
| 363 | |
| 364 static LStackSlot* cast(LOperand* op) { | |
| 365 ASSERT(op->IsStackSlot()); | |
| 366 return reinterpret_cast<LStackSlot*>(op); | |
| 367 } | |
| 368 | |
| 369 static void SetUpCache(); | |
| 370 static void TearDownCache(); | |
| 371 | |
| 372 private: | |
| 373 static const int kNumCachedOperands = 128; | |
| 374 static LStackSlot* cache; | |
| 375 | |
| 376 LStackSlot() : LOperand() { } | |
| 377 explicit LStackSlot(int index) : LOperand(STACK_SLOT, index) { } | |
| 378 }; | |
| 379 | |
| 380 | |
| 381 class LDoubleStackSlot V8_FINAL : public LOperand { | |
| 382 public: | |
| 383 static LDoubleStackSlot* Create(int index, Zone* zone) { | |
| 384 ASSERT(index >= 0); | |
| 385 if (index < kNumCachedOperands) return &cache[index]; | |
| 386 return new(zone) LDoubleStackSlot(index); | |
| 387 } | |
| 388 | |
| 389 static LDoubleStackSlot* cast(LOperand* op) { | |
| 390 ASSERT(op->IsStackSlot()); | |
| 391 return reinterpret_cast<LDoubleStackSlot*>(op); | |
| 392 } | |
| 393 | |
| 394 static void SetUpCache(); | |
| 395 static void TearDownCache(); | |
| 396 | |
| 397 private: | |
| 398 static const int kNumCachedOperands = 128; | |
| 399 static LDoubleStackSlot* cache; | |
| 400 | |
| 401 LDoubleStackSlot() : LOperand() { } | |
| 402 explicit LDoubleStackSlot(int index) : LOperand(DOUBLE_STACK_SLOT, index) { } | |
| 403 }; | |
| 404 | |
| 405 | |
| 406 class LRegister V8_FINAL : public LOperand { | |
| 407 public: | |
| 408 static LRegister* Create(int index, Zone* zone) { | |
| 409 ASSERT(index >= 0); | |
| 410 if (index < kNumCachedOperands) return &cache[index]; | |
| 411 return new(zone) LRegister(index); | |
| 412 } | |
| 413 | |
| 414 static LRegister* cast(LOperand* op) { | |
| 415 ASSERT(op->IsRegister()); | |
| 416 return reinterpret_cast<LRegister*>(op); | |
| 417 } | |
| 418 | |
| 419 static void SetUpCache(); | |
| 420 static void TearDownCache(); | |
| 421 | |
| 422 private: | |
| 423 static const int kNumCachedOperands = 16; | |
| 424 static LRegister* cache; | |
| 425 | |
| 426 LRegister() : LOperand() { } | |
| 427 explicit LRegister(int index) : LOperand(REGISTER, index) { } | |
| 428 }; | |
| 429 | |
| 430 | |
| 431 class LDoubleRegister V8_FINAL : public LOperand { | |
| 432 public: | |
| 433 static LDoubleRegister* Create(int index, Zone* zone) { | |
| 434 ASSERT(index >= 0); | |
| 435 if (index < kNumCachedOperands) return &cache[index]; | |
| 436 return new(zone) LDoubleRegister(index); | |
| 437 } | |
| 438 | |
| 439 static LDoubleRegister* cast(LOperand* op) { | |
| 440 ASSERT(op->IsDoubleRegister()); | |
| 441 return reinterpret_cast<LDoubleRegister*>(op); | |
| 442 } | |
| 443 | |
| 444 static void SetUpCache(); | |
| 445 static void TearDownCache(); | |
| 446 | |
| 447 private: | |
| 448 static const int kNumCachedOperands = 16; | |
| 449 static LDoubleRegister* cache; | |
| 450 | |
| 451 LDoubleRegister() : LOperand() { } | |
| 452 explicit LDoubleRegister(int index) : LOperand(DOUBLE_REGISTER, index) { } | |
| 453 }; | |
| 454 | 347 |
| 455 | 348 |
| 456 class LParallelMove V8_FINAL : public ZoneObject { | 349 class LParallelMove V8_FINAL : public ZoneObject { |
| 457 public: | 350 public: |
| 458 explicit LParallelMove(Zone* zone) : move_operands_(4, zone) { } | 351 explicit LParallelMove(Zone* zone) : move_operands_(4, zone) { } |
| 459 | 352 |
| 460 void AddMove(LOperand* from, LOperand* to, Zone* zone) { | 353 void AddMove(LOperand* from, LOperand* to, Zone* zone) { |
| 461 move_operands_.Add(LMoveOperands(from, to), zone); | 354 move_operands_.Add(LMoveOperands(from, to), zone); |
| 462 } | 355 } |
| 463 | 356 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 void Advance() { | 565 void Advance() { |
| 673 ASSERT(!Done()); | 566 ASSERT(!Done()); |
| 674 ++current_; | 567 ++current_; |
| 675 SkipUninteresting(); | 568 SkipUninteresting(); |
| 676 } | 569 } |
| 677 | 570 |
| 678 LEnvironment* env() { return env_; } | 571 LEnvironment* env() { return env_; } |
| 679 | 572 |
| 680 private: | 573 private: |
| 681 bool ShouldSkip(LOperand* op) { | 574 bool ShouldSkip(LOperand* op) { |
| 682 return op == NULL || op->IsConstantOperand() || op->IsArgument(); | 575 return op == NULL || op->IsConstantOperand(); |
| 683 } | 576 } |
| 684 | 577 |
| 685 // Skip until something interesting, beginning with and including current_. | 578 // Skip until something interesting, beginning with and including current_. |
| 686 void SkipUninteresting() { | 579 void SkipUninteresting() { |
| 687 while (current_ < limit_ && ShouldSkip(env_->values()->at(current_))) { | 580 while (current_ < limit_ && ShouldSkip(env_->values()->at(current_))) { |
| 688 ++current_; | 581 ++current_; |
| 689 } | 582 } |
| 690 } | 583 } |
| 691 | 584 |
| 692 LEnvironment* env_; | 585 LEnvironment* env_; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 private: | 731 private: |
| 839 LChunk* chunk_; | 732 LChunk* chunk_; |
| 840 | 733 |
| 841 DISALLOW_COPY_AND_ASSIGN(LPhase); | 734 DISALLOW_COPY_AND_ASSIGN(LPhase); |
| 842 }; | 735 }; |
| 843 | 736 |
| 844 | 737 |
| 845 } } // namespace v8::internal | 738 } } // namespace v8::internal |
| 846 | 739 |
| 847 #endif // V8_LITHIUM_H_ | 740 #endif // V8_LITHIUM_H_ |
| OLD | NEW |