| 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 <iosfwd> |
| 9 #include <map> | 10 #include <map> |
| 10 #include <set> | 11 #include <set> |
| 11 | 12 |
| 12 #include "src/compiler/common-operator.h" | 13 #include "src/compiler/common-operator.h" |
| 13 #include "src/compiler/frame.h" | 14 #include "src/compiler/frame.h" |
| 14 #include "src/compiler/graph.h" | 15 #include "src/compiler/graph.h" |
| 15 #include "src/compiler/instruction-codes.h" | 16 #include "src/compiler/instruction-codes.h" |
| 16 #include "src/compiler/opcodes.h" | 17 #include "src/compiler/opcodes.h" |
| 17 #include "src/compiler/schedule.h" | 18 #include "src/compiler/schedule.h" |
| 18 // TODO(titzer): don't include the macro-assembler? | 19 // TODO(titzer): don't include the macro-assembler? |
| 19 #include "src/macro-assembler.h" | 20 #include "src/macro-assembler.h" |
| 20 #include "src/zone-allocator.h" | 21 #include "src/zone-allocator.h" |
| 21 | 22 |
| 22 namespace v8 { | 23 namespace v8 { |
| 23 namespace internal { | 24 namespace internal { |
| 24 | |
| 25 // Forward declarations. | |
| 26 class OStream; | |
| 27 | |
| 28 namespace compiler { | 25 namespace compiler { |
| 29 | 26 |
| 30 // Forward declarations. | 27 // Forward declarations. |
| 31 class Linkage; | 28 class Linkage; |
| 32 | 29 |
| 33 // A couple of reserved opcodes are used for internal use. | 30 // A couple of reserved opcodes are used for internal use. |
| 34 const InstructionCode kGapInstruction = -1; | 31 const InstructionCode kGapInstruction = -1; |
| 35 const InstructionCode kBlockStartInstruction = -2; | 32 const InstructionCode kBlockStartInstruction = -2; |
| 36 const InstructionCode kSourcePositionInstruction = -3; | 33 const InstructionCode kSourcePositionInstruction = -3; |
| 37 | 34 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 static void TearDownCaches(); | 81 static void TearDownCaches(); |
| 85 | 82 |
| 86 protected: | 83 protected: |
| 87 typedef BitField<Kind, 0, 3> KindField; | 84 typedef BitField<Kind, 0, 3> KindField; |
| 88 | 85 |
| 89 unsigned value_; | 86 unsigned value_; |
| 90 }; | 87 }; |
| 91 | 88 |
| 92 typedef ZoneVector<InstructionOperand*> InstructionOperandVector; | 89 typedef ZoneVector<InstructionOperand*> InstructionOperandVector; |
| 93 | 90 |
| 94 OStream& operator<<(OStream& os, const InstructionOperand& op); | 91 std::ostream& operator<<(std::ostream& os, const InstructionOperand& op); |
| 95 | 92 |
| 96 class UnallocatedOperand : public InstructionOperand { | 93 class UnallocatedOperand : public InstructionOperand { |
| 97 public: | 94 public: |
| 98 enum BasicPolicy { FIXED_SLOT, EXTENDED_POLICY }; | 95 enum BasicPolicy { FIXED_SLOT, EXTENDED_POLICY }; |
| 99 | 96 |
| 100 enum ExtendedPolicy { | 97 enum ExtendedPolicy { |
| 101 NONE, | 98 NONE, |
| 102 ANY, | 99 ANY, |
| 103 FIXED_REGISTER, | 100 FIXED_REGISTER, |
| 104 FIXED_DOUBLE_REGISTER, | 101 FIXED_DOUBLE_REGISTER, |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 bool IsEliminated() const { | 300 bool IsEliminated() const { |
| 304 DCHECK(source_ != NULL || destination_ == NULL); | 301 DCHECK(source_ != NULL || destination_ == NULL); |
| 305 return source_ == NULL; | 302 return source_ == NULL; |
| 306 } | 303 } |
| 307 | 304 |
| 308 private: | 305 private: |
| 309 InstructionOperand* source_; | 306 InstructionOperand* source_; |
| 310 InstructionOperand* destination_; | 307 InstructionOperand* destination_; |
| 311 }; | 308 }; |
| 312 | 309 |
| 313 OStream& operator<<(OStream& os, const MoveOperands& mo); | 310 std::ostream& operator<<(std::ostream& os, const MoveOperands& mo); |
| 314 | 311 |
| 315 template <InstructionOperand::Kind kOperandKind, int kNumCachedOperands> | 312 template <InstructionOperand::Kind kOperandKind, int kNumCachedOperands> |
| 316 class SubKindOperand FINAL : public InstructionOperand { | 313 class SubKindOperand FINAL : public InstructionOperand { |
| 317 public: | 314 public: |
| 318 static SubKindOperand* Create(int index, Zone* zone) { | 315 static SubKindOperand* Create(int index, Zone* zone) { |
| 319 DCHECK(index >= 0); | 316 DCHECK(index >= 0); |
| 320 if (index < kNumCachedOperands) return &cache[index]; | 317 if (index < kNumCachedOperands) return &cache[index]; |
| 321 return new (zone) SubKindOperand(index); | 318 return new (zone) SubKindOperand(index); |
| 322 } | 319 } |
| 323 | 320 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 353 |
| 357 ZoneList<MoveOperands>* move_operands() { return &move_operands_; } | 354 ZoneList<MoveOperands>* move_operands() { return &move_operands_; } |
| 358 const ZoneList<MoveOperands>* move_operands() const { | 355 const ZoneList<MoveOperands>* move_operands() const { |
| 359 return &move_operands_; | 356 return &move_operands_; |
| 360 } | 357 } |
| 361 | 358 |
| 362 private: | 359 private: |
| 363 ZoneList<MoveOperands> move_operands_; | 360 ZoneList<MoveOperands> move_operands_; |
| 364 }; | 361 }; |
| 365 | 362 |
| 366 OStream& operator<<(OStream& os, const ParallelMove& pm); | 363 std::ostream& operator<<(std::ostream& os, const ParallelMove& pm); |
| 367 | 364 |
| 368 class PointerMap FINAL : public ZoneObject { | 365 class PointerMap FINAL : public ZoneObject { |
| 369 public: | 366 public: |
| 370 explicit PointerMap(Zone* zone) | 367 explicit PointerMap(Zone* zone) |
| 371 : pointer_operands_(8, zone), | 368 : pointer_operands_(8, zone), |
| 372 untagged_operands_(0, zone), | 369 untagged_operands_(0, zone), |
| 373 instruction_position_(-1) {} | 370 instruction_position_(-1) {} |
| 374 | 371 |
| 375 const ZoneList<InstructionOperand*>* GetNormalizedOperands() { | 372 const ZoneList<InstructionOperand*>* GetNormalizedOperands() { |
| 376 for (int i = 0; i < untagged_operands_.length(); ++i) { | 373 for (int i = 0; i < untagged_operands_.length(); ++i) { |
| 377 RemovePointer(untagged_operands_[i]); | 374 RemovePointer(untagged_operands_[i]); |
| 378 } | 375 } |
| 379 untagged_operands_.Clear(); | 376 untagged_operands_.Clear(); |
| 380 return &pointer_operands_; | 377 return &pointer_operands_; |
| 381 } | 378 } |
| 382 int instruction_position() const { return instruction_position_; } | 379 int instruction_position() const { return instruction_position_; } |
| 383 | 380 |
| 384 void set_instruction_position(int pos) { | 381 void set_instruction_position(int pos) { |
| 385 DCHECK(instruction_position_ == -1); | 382 DCHECK(instruction_position_ == -1); |
| 386 instruction_position_ = pos; | 383 instruction_position_ = pos; |
| 387 } | 384 } |
| 388 | 385 |
| 389 void RecordPointer(InstructionOperand* op, Zone* zone); | 386 void RecordPointer(InstructionOperand* op, Zone* zone); |
| 390 void RemovePointer(InstructionOperand* op); | 387 void RemovePointer(InstructionOperand* op); |
| 391 void RecordUntagged(InstructionOperand* op, Zone* zone); | 388 void RecordUntagged(InstructionOperand* op, Zone* zone); |
| 392 | 389 |
| 393 private: | 390 private: |
| 394 friend OStream& operator<<(OStream& os, const PointerMap& pm); | 391 friend std::ostream& operator<<(std::ostream& os, const PointerMap& pm); |
| 395 | 392 |
| 396 ZoneList<InstructionOperand*> pointer_operands_; | 393 ZoneList<InstructionOperand*> pointer_operands_; |
| 397 ZoneList<InstructionOperand*> untagged_operands_; | 394 ZoneList<InstructionOperand*> untagged_operands_; |
| 398 int instruction_position_; | 395 int instruction_position_; |
| 399 }; | 396 }; |
| 400 | 397 |
| 401 OStream& operator<<(OStream& os, const PointerMap& pm); | 398 std::ostream& operator<<(std::ostream& os, const PointerMap& pm); |
| 402 | 399 |
| 403 // TODO(titzer): s/PointerMap/ReferenceMap/ | 400 // TODO(titzer): s/PointerMap/ReferenceMap/ |
| 404 class Instruction : public ZoneObject { | 401 class Instruction : public ZoneObject { |
| 405 public: | 402 public: |
| 406 size_t OutputCount() const { return OutputCountField::decode(bit_field_); } | 403 size_t OutputCount() const { return OutputCountField::decode(bit_field_); } |
| 407 InstructionOperand* OutputAt(size_t i) const { | 404 InstructionOperand* OutputAt(size_t i) const { |
| 408 DCHECK(i < OutputCount()); | 405 DCHECK(i < OutputCount()); |
| 409 return operands_[i]; | 406 return operands_[i]; |
| 410 } | 407 } |
| 411 | 408 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 typedef BitField<size_t, 24, 6> TempCountField; | 528 typedef BitField<size_t, 24, 6> TempCountField; |
| 532 typedef BitField<bool, 30, 1> IsCallField; | 529 typedef BitField<bool, 30, 1> IsCallField; |
| 533 typedef BitField<bool, 31, 1> IsControlField; | 530 typedef BitField<bool, 31, 1> IsControlField; |
| 534 | 531 |
| 535 InstructionCode opcode_; | 532 InstructionCode opcode_; |
| 536 uint32_t bit_field_; | 533 uint32_t bit_field_; |
| 537 PointerMap* pointer_map_; | 534 PointerMap* pointer_map_; |
| 538 InstructionOperand* operands_[1]; | 535 InstructionOperand* operands_[1]; |
| 539 }; | 536 }; |
| 540 | 537 |
| 541 OStream& operator<<(OStream& os, const Instruction& instr); | 538 std::ostream& operator<<(std::ostream& os, const Instruction& instr); |
| 542 | 539 |
| 543 // Represents moves inserted before an instruction due to register allocation. | 540 // Represents moves inserted before an instruction due to register allocation. |
| 544 // TODO(titzer): squash GapInstruction back into Instruction, since essentially | 541 // TODO(titzer): squash GapInstruction back into Instruction, since essentially |
| 545 // every instruction can possibly have moves inserted before it. | 542 // every instruction can possibly have moves inserted before it. |
| 546 class GapInstruction : public Instruction { | 543 class GapInstruction : public Instruction { |
| 547 public: | 544 public: |
| 548 enum InnerPosition { | 545 enum InnerPosition { |
| 549 BEFORE, | 546 BEFORE, |
| 550 START, | 547 START, |
| 551 END, | 548 END, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 582 | 579 |
| 583 protected: | 580 protected: |
| 584 explicit GapInstruction(InstructionCode opcode) : Instruction(opcode) { | 581 explicit GapInstruction(InstructionCode opcode) : Instruction(opcode) { |
| 585 parallel_moves_[BEFORE] = NULL; | 582 parallel_moves_[BEFORE] = NULL; |
| 586 parallel_moves_[START] = NULL; | 583 parallel_moves_[START] = NULL; |
| 587 parallel_moves_[END] = NULL; | 584 parallel_moves_[END] = NULL; |
| 588 parallel_moves_[AFTER] = NULL; | 585 parallel_moves_[AFTER] = NULL; |
| 589 } | 586 } |
| 590 | 587 |
| 591 private: | 588 private: |
| 592 friend OStream& operator<<(OStream& os, const Instruction& instr); | 589 friend std::ostream& operator<<(std::ostream& os, const Instruction& instr); |
| 593 ParallelMove* parallel_moves_[LAST_INNER_POSITION + 1]; | 590 ParallelMove* parallel_moves_[LAST_INNER_POSITION + 1]; |
| 594 }; | 591 }; |
| 595 | 592 |
| 596 | 593 |
| 597 // This special kind of gap move instruction represents the beginning of a | 594 // This special kind of gap move instruction represents the beginning of a |
| 598 // block of code. | 595 // block of code. |
| 599 // TODO(titzer): move code_start and code_end from BasicBlock to here. | 596 // TODO(titzer): move code_start and code_end from BasicBlock to here. |
| 600 class BlockStartInstruction FINAL : public GapInstruction { | 597 class BlockStartInstruction FINAL : public GapInstruction { |
| 601 public: | 598 public: |
| 602 BasicBlock* block() const { return block_; } | 599 BasicBlock* block() const { return block_; } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 FrameStateType type_; | 782 FrameStateType type_; |
| 786 BailoutId bailout_id_; | 783 BailoutId bailout_id_; |
| 787 OutputFrameStateCombine frame_state_combine_; | 784 OutputFrameStateCombine frame_state_combine_; |
| 788 size_t parameters_count_; | 785 size_t parameters_count_; |
| 789 size_t locals_count_; | 786 size_t locals_count_; |
| 790 size_t stack_count_; | 787 size_t stack_count_; |
| 791 FrameStateDescriptor* outer_state_; | 788 FrameStateDescriptor* outer_state_; |
| 792 MaybeHandle<JSFunction> jsfunction_; | 789 MaybeHandle<JSFunction> jsfunction_; |
| 793 }; | 790 }; |
| 794 | 791 |
| 795 OStream& operator<<(OStream& os, const Constant& constant); | 792 std::ostream& operator<<(std::ostream& os, const Constant& constant); |
| 796 | 793 |
| 797 typedef ZoneDeque<Constant> ConstantDeque; | 794 typedef ZoneDeque<Constant> ConstantDeque; |
| 798 typedef std::map<int, Constant, std::less<int>, | 795 typedef std::map<int, Constant, std::less<int>, |
| 799 zone_allocator<std::pair<int, Constant> > > ConstantMap; | 796 zone_allocator<std::pair<int, Constant> > > ConstantMap; |
| 800 | 797 |
| 801 typedef ZoneDeque<Instruction*> InstructionDeque; | 798 typedef ZoneDeque<Instruction*> InstructionDeque; |
| 802 typedef ZoneDeque<PointerMap*> PointerMapDeque; | 799 typedef ZoneDeque<PointerMap*> PointerMapDeque; |
| 803 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; | 800 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; |
| 804 | 801 |
| 805 // Represents architecture-specific generated code before, during, and after | 802 // Represents architecture-specific generated code before, during, and after |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 private: | 913 private: |
| 917 explicit StateId(int id) : id_(id) {} | 914 explicit StateId(int id) : id_(id) {} |
| 918 int id_; | 915 int id_; |
| 919 }; | 916 }; |
| 920 | 917 |
| 921 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor); | 918 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor); |
| 922 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); | 919 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); |
| 923 int GetFrameStateDescriptorCount(); | 920 int GetFrameStateDescriptorCount(); |
| 924 | 921 |
| 925 private: | 922 private: |
| 926 friend OStream& operator<<(OStream& os, const InstructionSequence& code); | 923 friend std::ostream& operator<<(std::ostream& os, |
| 924 const InstructionSequence& code); |
| 927 | 925 |
| 928 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; | 926 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; |
| 929 | 927 |
| 930 Graph* graph_; | 928 Graph* graph_; |
| 931 Linkage* linkage_; | 929 Linkage* linkage_; |
| 932 Schedule* schedule_; | 930 Schedule* schedule_; |
| 933 ConstantMap constants_; | 931 ConstantMap constants_; |
| 934 ConstantDeque immediates_; | 932 ConstantDeque immediates_; |
| 935 InstructionDeque instructions_; | 933 InstructionDeque instructions_; |
| 936 int next_virtual_register_; | 934 int next_virtual_register_; |
| 937 PointerMapDeque pointer_maps_; | 935 PointerMapDeque pointer_maps_; |
| 938 VirtualRegisterSet doubles_; | 936 VirtualRegisterSet doubles_; |
| 939 VirtualRegisterSet references_; | 937 VirtualRegisterSet references_; |
| 940 Frame frame_; | 938 Frame frame_; |
| 941 DeoptimizationVector deoptimization_entries_; | 939 DeoptimizationVector deoptimization_entries_; |
| 942 }; | 940 }; |
| 943 | 941 |
| 944 OStream& operator<<(OStream& os, const InstructionSequence& code); | 942 std::ostream& operator<<(std::ostream& os, const InstructionSequence& code); |
| 945 | 943 |
| 946 } // namespace compiler | 944 } // namespace compiler |
| 947 } // namespace internal | 945 } // namespace internal |
| 948 } // namespace v8 | 946 } // namespace v8 |
| 949 | 947 |
| 950 #endif // V8_COMPILER_INSTRUCTION_H_ | 948 #endif // V8_COMPILER_INSTRUCTION_H_ |
| OLD | NEW |