| 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 <iosfwd> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 INSTRUCTION_OPERAND_LIST(INSTRUCTION_OPERAND_PREDICATE) | 57 INSTRUCTION_OPERAND_LIST(INSTRUCTION_OPERAND_PREDICATE) |
| 58 INSTRUCTION_OPERAND_PREDICATE(Unallocated, UNALLOCATED, 0) | 58 INSTRUCTION_OPERAND_PREDICATE(Unallocated, UNALLOCATED, 0) |
| 59 #undef INSTRUCTION_OPERAND_PREDICATE | 59 #undef INSTRUCTION_OPERAND_PREDICATE |
| 60 bool Equals(const InstructionOperand* other) const { | 60 bool Equals(const InstructionOperand* other) const { |
| 61 return value_ == other->value_; | 61 return value_ == other->value_; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ConvertTo(Kind kind, int index) { | 64 void ConvertTo(Kind kind, int index) { |
| 65 if (kind == REGISTER || kind == DOUBLE_REGISTER) DCHECK(index >= 0); | 65 if (kind == REGISTER || kind == DOUBLE_REGISTER) DCHECK(index >= 0); |
| 66 value_ = KindField::encode(kind); | 66 value_ = KindField::encode(kind); |
| 67 value_ |= index << KindField::kSize; | 67 value_ |= bit_cast<unsigned>(index << KindField::kSize); |
| 68 DCHECK(this->index() == index); | 68 DCHECK(this->index() == index); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Calls SetUpCache()/TearDownCache() for each subclass. | 71 // Calls SetUpCache()/TearDownCache() for each subclass. |
| 72 static void SetUpCaches(); | 72 static void SetUpCaches(); |
| 73 static void TearDownCaches(); | 73 static void TearDownCaches(); |
| 74 | 74 |
| 75 protected: | 75 protected: |
| 76 typedef BitField<Kind, 0, 3> KindField; | 76 typedef BitField64<Kind, 0, 3> KindField; |
| 77 | 77 |
| 78 unsigned value_; | 78 uint64_t value_; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 typedef ZoneVector<InstructionOperand*> InstructionOperandVector; | 81 typedef ZoneVector<InstructionOperand*> InstructionOperandVector; |
| 82 | 82 |
| 83 struct PrintableInstructionOperand { | 83 struct PrintableInstructionOperand { |
| 84 const RegisterConfiguration* register_configuration_; | 84 const RegisterConfiguration* register_configuration_; |
| 85 const InstructionOperand* op_; | 85 const InstructionOperand* op_; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 std::ostream& operator<<(std::ostream& os, | 88 std::ostream& operator<<(std::ostream& os, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 value_ |= BasicPolicyField::encode(EXTENDED_POLICY); | 121 value_ |= BasicPolicyField::encode(EXTENDED_POLICY); |
| 122 value_ |= ExtendedPolicyField::encode(policy); | 122 value_ |= ExtendedPolicyField::encode(policy); |
| 123 value_ |= LifetimeField::encode(USED_AT_END); | 123 value_ |= LifetimeField::encode(USED_AT_END); |
| 124 } | 124 } |
| 125 | 125 |
| 126 UnallocatedOperand(BasicPolicy policy, int index) | 126 UnallocatedOperand(BasicPolicy policy, int index) |
| 127 : InstructionOperand(UNALLOCATED, 0) { | 127 : InstructionOperand(UNALLOCATED, 0) { |
| 128 DCHECK(policy == FIXED_SLOT); | 128 DCHECK(policy == FIXED_SLOT); |
| 129 value_ |= VirtualRegisterField::encode(kInvalidVirtualRegister); | 129 value_ |= VirtualRegisterField::encode(kInvalidVirtualRegister); |
| 130 value_ |= BasicPolicyField::encode(policy); | 130 value_ |= BasicPolicyField::encode(policy); |
| 131 value_ |= index << FixedSlotIndexField::kShift; | 131 value_ |= static_cast<int64_t>(index) << FixedSlotIndexField::kShift; |
| 132 // TODO(dcarney): 2^10 is not enough for the fixed slot index. | 132 DCHECK(this->fixed_slot_index() == index); |
| 133 CHECK(this->fixed_slot_index() == index); | |
| 134 } | 133 } |
| 135 | 134 |
| 136 UnallocatedOperand(ExtendedPolicy policy, int index) | 135 UnallocatedOperand(ExtendedPolicy policy, int index) |
| 137 : InstructionOperand(UNALLOCATED, 0) { | 136 : InstructionOperand(UNALLOCATED, 0) { |
| 138 DCHECK(policy == FIXED_REGISTER || policy == FIXED_DOUBLE_REGISTER); | 137 DCHECK(policy == FIXED_REGISTER || policy == FIXED_DOUBLE_REGISTER); |
| 139 value_ |= VirtualRegisterField::encode(kInvalidVirtualRegister); | 138 value_ |= VirtualRegisterField::encode(kInvalidVirtualRegister); |
| 140 value_ |= BasicPolicyField::encode(EXTENDED_POLICY); | 139 value_ |= BasicPolicyField::encode(EXTENDED_POLICY); |
| 141 value_ |= ExtendedPolicyField::encode(policy); | 140 value_ |= ExtendedPolicyField::encode(policy); |
| 142 value_ |= LifetimeField::encode(USED_AT_END); | 141 value_ |= LifetimeField::encode(USED_AT_END); |
| 143 value_ |= FixedRegisterField::encode(index); | 142 value_ |= FixedRegisterField::encode(index); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // +------------------------------------------+ | 175 // +------------------------------------------+ |
| 177 // | slot_index | vreg | 0 | 001 | | 176 // | slot_index | vreg | 0 | 001 | |
| 178 // +------------------------------------------+ | 177 // +------------------------------------------+ |
| 179 // | 178 // |
| 180 // For all other (extended) policies: | 179 // For all other (extended) policies: |
| 181 // +------------------------------------------+ | 180 // +------------------------------------------+ |
| 182 // | reg_index | L | PPP | vreg | 1 | 001 | L ... Lifetime | 181 // | reg_index | L | PPP | vreg | 1 | 001 | L ... Lifetime |
| 183 // +------------------------------------------+ P ... Policy | 182 // +------------------------------------------+ P ... Policy |
| 184 // | 183 // |
| 185 // The slot index is a signed value which requires us to decode it manually | 184 // The slot index is a signed value which requires us to decode it manually |
| 186 // instead of using the BitField utility class. | 185 // instead of using the BitField64 utility class. |
| 187 | 186 |
| 188 // The superclass has a KindField. | 187 // The superclass has a KindField. |
| 189 STATIC_ASSERT(KindField::kSize == 3); | 188 STATIC_ASSERT(KindField::kSize == 3); |
| 190 | 189 |
| 191 // BitFields for all unallocated operands. | 190 // BitFields for all unallocated operands. |
| 192 class BasicPolicyField : public BitField<BasicPolicy, 3, 1> {}; | 191 class BasicPolicyField : public BitField64<BasicPolicy, 3, 1> {}; |
| 193 class VirtualRegisterField : public BitField<unsigned, 4, 18> {}; | 192 class VirtualRegisterField : public BitField64<unsigned, 4, 30> {}; |
| 194 | 193 |
| 195 // BitFields specific to BasicPolicy::FIXED_SLOT. | 194 // BitFields specific to BasicPolicy::FIXED_SLOT. |
| 196 class FixedSlotIndexField : public BitField<int, 22, 10> {}; | 195 class FixedSlotIndexField : public BitField64<int, 34, 30> {}; |
| 197 | 196 |
| 198 // BitFields specific to BasicPolicy::EXTENDED_POLICY. | 197 // BitFields specific to BasicPolicy::EXTENDED_POLICY. |
| 199 class ExtendedPolicyField : public BitField<ExtendedPolicy, 22, 3> {}; | 198 class ExtendedPolicyField : public BitField64<ExtendedPolicy, 34, 3> {}; |
| 200 class LifetimeField : public BitField<Lifetime, 25, 1> {}; | 199 class LifetimeField : public BitField64<Lifetime, 37, 1> {}; |
| 201 class FixedRegisterField : public BitField<int, 26, 6> {}; | 200 class FixedRegisterField : public BitField64<int, 38, 6> {}; |
| 202 | 201 |
| 203 static const int kInvalidVirtualRegister = VirtualRegisterField::kMax; | 202 static const int kInvalidVirtualRegister = VirtualRegisterField::kMax; |
| 204 static const int kMaxVirtualRegisters = VirtualRegisterField::kMax; | 203 static const int kMaxVirtualRegisters = VirtualRegisterField::kMax; |
| 205 static const int kFixedSlotIndexWidth = FixedSlotIndexField::kSize; | 204 static const int kFixedSlotIndexWidth = FixedSlotIndexField::kSize; |
| 206 static const int kMaxFixedSlotIndex = (1 << (kFixedSlotIndexWidth - 1)) - 1; | 205 static const int kMaxFixedSlotIndex = (1 << (kFixedSlotIndexWidth - 1)) - 1; |
| 207 static const int kMinFixedSlotIndex = -(1 << (kFixedSlotIndexWidth - 1)); | 206 static const int kMinFixedSlotIndex = -(1 << (kFixedSlotIndexWidth - 1)); |
| 208 | 207 |
| 209 // Predicates for the operand policy. | 208 // Predicates for the operand policy. |
| 210 bool HasAnyPolicy() const { | 209 bool HasAnyPolicy() const { |
| 211 return basic_policy() == EXTENDED_POLICY && extended_policy() == ANY; | 210 return basic_policy() == EXTENDED_POLICY && extended_policy() == ANY; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 238 | 237 |
| 239 // [extended_policy]: Only for non-FIXED_SLOT. The finer-grained policy. | 238 // [extended_policy]: Only for non-FIXED_SLOT. The finer-grained policy. |
| 240 ExtendedPolicy extended_policy() const { | 239 ExtendedPolicy extended_policy() const { |
| 241 DCHECK(basic_policy() == EXTENDED_POLICY); | 240 DCHECK(basic_policy() == EXTENDED_POLICY); |
| 242 return ExtendedPolicyField::decode(value_); | 241 return ExtendedPolicyField::decode(value_); |
| 243 } | 242 } |
| 244 | 243 |
| 245 // [fixed_slot_index]: Only for FIXED_SLOT. | 244 // [fixed_slot_index]: Only for FIXED_SLOT. |
| 246 int fixed_slot_index() const { | 245 int fixed_slot_index() const { |
| 247 DCHECK(HasFixedSlotPolicy()); | 246 DCHECK(HasFixedSlotPolicy()); |
| 248 return static_cast<int>(value_) >> FixedSlotIndexField::kShift; | 247 return static_cast<int>(bit_cast<int64_t>(value_) >> |
| 248 FixedSlotIndexField::kShift); |
| 249 } | 249 } |
| 250 | 250 |
| 251 // [fixed_register_index]: Only for FIXED_REGISTER or FIXED_DOUBLE_REGISTER. | 251 // [fixed_register_index]: Only for FIXED_REGISTER or FIXED_DOUBLE_REGISTER. |
| 252 int fixed_register_index() const { | 252 int fixed_register_index() const { |
| 253 DCHECK(HasFixedRegisterPolicy() || HasFixedDoubleRegisterPolicy()); | 253 DCHECK(HasFixedRegisterPolicy() || HasFixedDoubleRegisterPolicy()); |
| 254 return FixedRegisterField::decode(value_); | 254 return FixedRegisterField::decode(value_); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // [virtual_register]: The virtual register ID for this operand. | 257 // [virtual_register]: The virtual register ID for this operand. |
| 258 int virtual_register() const { return VirtualRegisterField::decode(value_); } | 258 int virtual_register() const { return VirtualRegisterField::decode(value_); } |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 | 1087 |
| 1088 | 1088 |
| 1089 std::ostream& operator<<(std::ostream& os, | 1089 std::ostream& operator<<(std::ostream& os, |
| 1090 const PrintableInstructionSequence& code); | 1090 const PrintableInstructionSequence& code); |
| 1091 | 1091 |
| 1092 } // namespace compiler | 1092 } // namespace compiler |
| 1093 } // namespace internal | 1093 } // namespace internal |
| 1094 } // namespace v8 | 1094 } // namespace v8 |
| 1095 | 1095 |
| 1096 #endif // V8_COMPILER_INSTRUCTION_H_ | 1096 #endif // V8_COMPILER_INSTRUCTION_H_ |
| OLD | NEW |