OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_INSTRUCTION_H_ | 5 #ifndef V8_COMPILER_INSTRUCTION_H_ |
6 #define V8_COMPILER_INSTRUCTION_H_ | 6 #define V8_COMPILER_INSTRUCTION_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 260 } |
261 | 261 |
262 // [lifetime]: Only for non-FIXED_SLOT. | 262 // [lifetime]: Only for non-FIXED_SLOT. |
263 bool IsUsedAtStart() { | 263 bool IsUsedAtStart() { |
264 DCHECK(basic_policy() == EXTENDED_POLICY); | 264 DCHECK(basic_policy() == EXTENDED_POLICY); |
265 return LifetimeField::decode(value_) == USED_AT_START; | 265 return LifetimeField::decode(value_) == USED_AT_START; |
266 } | 266 } |
267 }; | 267 }; |
268 | 268 |
269 | 269 |
270 class MoveOperands V8_FINAL { | 270 class MoveOperands FINAL { |
271 public: | 271 public: |
272 MoveOperands(InstructionOperand* source, InstructionOperand* destination) | 272 MoveOperands(InstructionOperand* source, InstructionOperand* destination) |
273 : source_(source), destination_(destination) {} | 273 : source_(source), destination_(destination) {} |
274 | 274 |
275 InstructionOperand* source() const { return source_; } | 275 InstructionOperand* source() const { return source_; } |
276 void set_source(InstructionOperand* operand) { source_ = operand; } | 276 void set_source(InstructionOperand* operand) { source_ = operand; } |
277 | 277 |
278 InstructionOperand* destination() const { return destination_; } | 278 InstructionOperand* destination() const { return destination_; } |
279 void set_destination(InstructionOperand* operand) { destination_ = operand; } | 279 void set_destination(InstructionOperand* operand) { destination_ = operand; } |
280 | 280 |
(...skipping 25 matching lines...) Expand all Loading... |
306 } | 306 } |
307 | 307 |
308 private: | 308 private: |
309 InstructionOperand* source_; | 309 InstructionOperand* source_; |
310 InstructionOperand* destination_; | 310 InstructionOperand* destination_; |
311 }; | 311 }; |
312 | 312 |
313 OStream& operator<<(OStream& os, const MoveOperands& mo); | 313 OStream& operator<<(OStream& os, const MoveOperands& mo); |
314 | 314 |
315 template <InstructionOperand::Kind kOperandKind, int kNumCachedOperands> | 315 template <InstructionOperand::Kind kOperandKind, int kNumCachedOperands> |
316 class SubKindOperand V8_FINAL : public InstructionOperand { | 316 class SubKindOperand FINAL : public InstructionOperand { |
317 public: | 317 public: |
318 static SubKindOperand* Create(int index, Zone* zone) { | 318 static SubKindOperand* Create(int index, Zone* zone) { |
319 DCHECK(index >= 0); | 319 DCHECK(index >= 0); |
320 if (index < kNumCachedOperands) return &cache[index]; | 320 if (index < kNumCachedOperands) return &cache[index]; |
321 return new (zone) SubKindOperand(index); | 321 return new (zone) SubKindOperand(index); |
322 } | 322 } |
323 | 323 |
324 static SubKindOperand* cast(InstructionOperand* op) { | 324 static SubKindOperand* cast(InstructionOperand* op) { |
325 DCHECK(op->kind() == kOperandKind); | 325 DCHECK(op->kind() == kOperandKind); |
326 return reinterpret_cast<SubKindOperand*>(op); | 326 return reinterpret_cast<SubKindOperand*>(op); |
(...skipping 10 matching lines...) Expand all Loading... |
337 : InstructionOperand(kOperandKind, index) {} | 337 : InstructionOperand(kOperandKind, index) {} |
338 }; | 338 }; |
339 | 339 |
340 | 340 |
341 #define INSTRUCTION_TYPEDEF_SUBKIND_OPERAND_CLASS(name, type, number) \ | 341 #define INSTRUCTION_TYPEDEF_SUBKIND_OPERAND_CLASS(name, type, number) \ |
342 typedef SubKindOperand<InstructionOperand::type, number> name##Operand; | 342 typedef SubKindOperand<InstructionOperand::type, number> name##Operand; |
343 INSTRUCTION_OPERAND_LIST(INSTRUCTION_TYPEDEF_SUBKIND_OPERAND_CLASS) | 343 INSTRUCTION_OPERAND_LIST(INSTRUCTION_TYPEDEF_SUBKIND_OPERAND_CLASS) |
344 #undef INSTRUCTION_TYPEDEF_SUBKIND_OPERAND_CLASS | 344 #undef INSTRUCTION_TYPEDEF_SUBKIND_OPERAND_CLASS |
345 | 345 |
346 | 346 |
347 class ParallelMove V8_FINAL : public ZoneObject { | 347 class ParallelMove FINAL : public ZoneObject { |
348 public: | 348 public: |
349 explicit ParallelMove(Zone* zone) : move_operands_(4, zone) {} | 349 explicit ParallelMove(Zone* zone) : move_operands_(4, zone) {} |
350 | 350 |
351 void AddMove(InstructionOperand* from, InstructionOperand* to, Zone* zone) { | 351 void AddMove(InstructionOperand* from, InstructionOperand* to, Zone* zone) { |
352 move_operands_.Add(MoveOperands(from, to), zone); | 352 move_operands_.Add(MoveOperands(from, to), zone); |
353 } | 353 } |
354 | 354 |
355 bool IsRedundant() const; | 355 bool IsRedundant() const; |
356 | 356 |
357 ZoneList<MoveOperands>* move_operands() { return &move_operands_; } | 357 ZoneList<MoveOperands>* move_operands() { return &move_operands_; } |
358 const ZoneList<MoveOperands>* move_operands() const { | 358 const ZoneList<MoveOperands>* move_operands() const { |
359 return &move_operands_; | 359 return &move_operands_; |
360 } | 360 } |
361 | 361 |
362 private: | 362 private: |
363 ZoneList<MoveOperands> move_operands_; | 363 ZoneList<MoveOperands> move_operands_; |
364 }; | 364 }; |
365 | 365 |
366 OStream& operator<<(OStream& os, const ParallelMove& pm); | 366 OStream& operator<<(OStream& os, const ParallelMove& pm); |
367 | 367 |
368 class PointerMap V8_FINAL : public ZoneObject { | 368 class PointerMap FINAL : public ZoneObject { |
369 public: | 369 public: |
370 explicit PointerMap(Zone* zone) | 370 explicit PointerMap(Zone* zone) |
371 : pointer_operands_(8, zone), | 371 : pointer_operands_(8, zone), |
372 untagged_operands_(0, zone), | 372 untagged_operands_(0, zone), |
373 instruction_position_(-1) {} | 373 instruction_position_(-1) {} |
374 | 374 |
375 const ZoneList<InstructionOperand*>* GetNormalizedOperands() { | 375 const ZoneList<InstructionOperand*>* GetNormalizedOperands() { |
376 for (int i = 0; i < untagged_operands_.length(); ++i) { | 376 for (int i = 0; i < untagged_operands_.length(); ++i) { |
377 RemovePointer(untagged_operands_[i]); | 377 RemovePointer(untagged_operands_[i]); |
378 } | 378 } |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 590 |
591 private: | 591 private: |
592 friend OStream& operator<<(OStream& os, const Instruction& instr); | 592 friend OStream& operator<<(OStream& os, const Instruction& instr); |
593 ParallelMove* parallel_moves_[LAST_INNER_POSITION + 1]; | 593 ParallelMove* parallel_moves_[LAST_INNER_POSITION + 1]; |
594 }; | 594 }; |
595 | 595 |
596 | 596 |
597 // This special kind of gap move instruction represents the beginning of a | 597 // This special kind of gap move instruction represents the beginning of a |
598 // block of code. | 598 // block of code. |
599 // TODO(titzer): move code_start and code_end from BasicBlock to here. | 599 // TODO(titzer): move code_start and code_end from BasicBlock to here. |
600 class BlockStartInstruction V8_FINAL : public GapInstruction { | 600 class BlockStartInstruction FINAL : public GapInstruction { |
601 public: | 601 public: |
602 BasicBlock* block() const { return block_; } | 602 BasicBlock* block() const { return block_; } |
603 Label* label() { return &label_; } | 603 Label* label() { return &label_; } |
604 | 604 |
605 static BlockStartInstruction* New(Zone* zone, BasicBlock* block) { | 605 static BlockStartInstruction* New(Zone* zone, BasicBlock* block) { |
606 void* buffer = zone->New(sizeof(BlockStartInstruction)); | 606 void* buffer = zone->New(sizeof(BlockStartInstruction)); |
607 return new (buffer) BlockStartInstruction(block); | 607 return new (buffer) BlockStartInstruction(block); |
608 } | 608 } |
609 | 609 |
610 static BlockStartInstruction* cast(Instruction* instr) { | 610 static BlockStartInstruction* cast(Instruction* instr) { |
611 DCHECK(instr->IsBlockStart()); | 611 DCHECK(instr->IsBlockStart()); |
612 return static_cast<BlockStartInstruction*>(instr); | 612 return static_cast<BlockStartInstruction*>(instr); |
613 } | 613 } |
614 | 614 |
615 private: | 615 private: |
616 explicit BlockStartInstruction(BasicBlock* block) | 616 explicit BlockStartInstruction(BasicBlock* block) |
617 : GapInstruction(kBlockStartInstruction), block_(block) {} | 617 : GapInstruction(kBlockStartInstruction), block_(block) {} |
618 | 618 |
619 BasicBlock* block_; | 619 BasicBlock* block_; |
620 Label label_; | 620 Label label_; |
621 }; | 621 }; |
622 | 622 |
623 | 623 |
624 class SourcePositionInstruction V8_FINAL : public Instruction { | 624 class SourcePositionInstruction FINAL : public Instruction { |
625 public: | 625 public: |
626 static SourcePositionInstruction* New(Zone* zone, SourcePosition position) { | 626 static SourcePositionInstruction* New(Zone* zone, SourcePosition position) { |
627 void* buffer = zone->New(sizeof(SourcePositionInstruction)); | 627 void* buffer = zone->New(sizeof(SourcePositionInstruction)); |
628 return new (buffer) SourcePositionInstruction(position); | 628 return new (buffer) SourcePositionInstruction(position); |
629 } | 629 } |
630 | 630 |
631 SourcePosition source_position() const { return source_position_; } | 631 SourcePosition source_position() const { return source_position_; } |
632 | 632 |
633 static SourcePositionInstruction* cast(Instruction* instr) { | 633 static SourcePositionInstruction* cast(Instruction* instr) { |
634 DCHECK(instr->IsSourcePosition()); | 634 DCHECK(instr->IsSourcePosition()); |
(...skipping 10 matching lines...) Expand all Loading... |
645 : Instruction(kSourcePositionInstruction), | 645 : Instruction(kSourcePositionInstruction), |
646 source_position_(source_position) { | 646 source_position_(source_position) { |
647 DCHECK(!source_position_.IsInvalid()); | 647 DCHECK(!source_position_.IsInvalid()); |
648 DCHECK(!source_position_.IsUnknown()); | 648 DCHECK(!source_position_.IsUnknown()); |
649 } | 649 } |
650 | 650 |
651 SourcePosition source_position_; | 651 SourcePosition source_position_; |
652 }; | 652 }; |
653 | 653 |
654 | 654 |
655 class Constant V8_FINAL { | 655 class Constant FINAL { |
656 public: | 656 public: |
657 enum Type { kInt32, kInt64, kFloat64, kExternalReference, kHeapObject }; | 657 enum Type { kInt32, kInt64, kFloat64, kExternalReference, kHeapObject }; |
658 | 658 |
659 explicit Constant(int32_t v) : type_(kInt32), value_(v) {} | 659 explicit Constant(int32_t v) : type_(kInt32), value_(v) {} |
660 explicit Constant(int64_t v) : type_(kInt64), value_(v) {} | 660 explicit Constant(int64_t v) : type_(kInt64), value_(v) {} |
661 explicit Constant(double v) : type_(kFloat64), value_(BitCast<int64_t>(v)) {} | 661 explicit Constant(double v) : type_(kFloat64), value_(BitCast<int64_t>(v)) {} |
662 explicit Constant(ExternalReference ref) | 662 explicit Constant(ExternalReference ref) |
663 : type_(kExternalReference), value_(BitCast<intptr_t>(ref)) {} | 663 : type_(kExternalReference), value_(BitCast<intptr_t>(ref)) {} |
664 explicit Constant(Handle<HeapObject> obj) | 664 explicit Constant(Handle<HeapObject> obj) |
665 : type_(kHeapObject), value_(BitCast<intptr_t>(obj)) {} | 665 : type_(kHeapObject), value_(BitCast<intptr_t>(obj)) {} |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 typedef std::map<int, Constant, std::less<int>, | 734 typedef std::map<int, Constant, std::less<int>, |
735 zone_allocator<std::pair<int, Constant> > > ConstantMap; | 735 zone_allocator<std::pair<int, Constant> > > ConstantMap; |
736 | 736 |
737 typedef ZoneDeque<Instruction*> InstructionDeque; | 737 typedef ZoneDeque<Instruction*> InstructionDeque; |
738 typedef ZoneDeque<PointerMap*> PointerMapDeque; | 738 typedef ZoneDeque<PointerMap*> PointerMapDeque; |
739 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; | 739 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; |
740 | 740 |
741 // Represents architecture-specific generated code before, during, and after | 741 // Represents architecture-specific generated code before, during, and after |
742 // register allocation. | 742 // register allocation. |
743 // TODO(titzer): s/IsDouble/IsFloat64/ | 743 // TODO(titzer): s/IsDouble/IsFloat64/ |
744 class InstructionSequence V8_FINAL { | 744 class InstructionSequence FINAL { |
745 public: | 745 public: |
746 InstructionSequence(Linkage* linkage, Graph* graph, Schedule* schedule) | 746 InstructionSequence(Linkage* linkage, Graph* graph, Schedule* schedule) |
747 : graph_(graph), | 747 : graph_(graph), |
748 linkage_(linkage), | 748 linkage_(linkage), |
749 schedule_(schedule), | 749 schedule_(schedule), |
750 constants_(ConstantMap::key_compare(), | 750 constants_(ConstantMap::key_compare(), |
751 ConstantMap::allocator_type(zone())), | 751 ConstantMap::allocator_type(zone())), |
752 immediates_(zone()), | 752 immediates_(zone()), |
753 instructions_(zone()), | 753 instructions_(zone()), |
754 next_virtual_register_(graph->NodeCount()), | 754 next_virtual_register_(graph->NodeCount()), |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 DeoptimizationVector deoptimization_entries_; | 877 DeoptimizationVector deoptimization_entries_; |
878 }; | 878 }; |
879 | 879 |
880 OStream& operator<<(OStream& os, const InstructionSequence& code); | 880 OStream& operator<<(OStream& os, const InstructionSequence& code); |
881 | 881 |
882 } // namespace compiler | 882 } // namespace compiler |
883 } // namespace internal | 883 } // namespace internal |
884 } // namespace v8 | 884 } // namespace v8 |
885 | 885 |
886 #endif // V8_COMPILER_INSTRUCTION_H_ | 886 #endif // V8_COMPILER_INSTRUCTION_H_ |
OLD | NEW |