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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 310 |
311 INSTRUCTION_OPERAND_CASTS(ConstantOperand, CONSTANT); | 311 INSTRUCTION_OPERAND_CASTS(ConstantOperand, CONSTANT); |
312 | 312 |
313 STATIC_ASSERT(KindField::kSize == 3); | 313 STATIC_ASSERT(KindField::kSize == 3); |
314 class VirtualRegisterField : public BitField64<uint32_t, 3, 32> {}; | 314 class VirtualRegisterField : public BitField64<uint32_t, 3, 32> {}; |
315 }; | 315 }; |
316 | 316 |
317 | 317 |
318 class ImmediateOperand : public InstructionOperand { | 318 class ImmediateOperand : public InstructionOperand { |
319 public: | 319 public: |
320 explicit ImmediateOperand(int index) : InstructionOperand(IMMEDIATE) { | 320 enum ImmediateType { INLINE, INDEXED }; |
321 value_ |= static_cast<int64_t>(index) << IndexField::kShift; | 321 |
| 322 explicit ImmediateOperand(ImmediateType type, int32_t value) |
| 323 : InstructionOperand(IMMEDIATE) { |
| 324 value_ |= TypeField::encode(type); |
| 325 value_ |= static_cast<int64_t>(value) << ValueField::kShift; |
322 } | 326 } |
323 | 327 |
324 int index() const { | 328 ImmediateType type() const { return TypeField::decode(value_); } |
325 return static_cast<int64_t>(value_) >> IndexField::kShift; | 329 |
| 330 int32_t inline_value() const { |
| 331 DCHECK_EQ(INLINE, type()); |
| 332 return static_cast<int64_t>(value_) >> ValueField::kShift; |
326 } | 333 } |
327 | 334 |
328 static ImmediateOperand* New(Zone* zone, int index) { | 335 int32_t indexed_value() const { |
329 return InstructionOperand::New(zone, ImmediateOperand(index)); | 336 DCHECK_EQ(INDEXED, type()); |
| 337 return static_cast<int64_t>(value_) >> ValueField::kShift; |
| 338 } |
| 339 |
| 340 static ImmediateOperand* New(Zone* zone, ImmediateType type, int32_t value) { |
| 341 return InstructionOperand::New(zone, ImmediateOperand(type, value)); |
330 } | 342 } |
331 | 343 |
332 INSTRUCTION_OPERAND_CASTS(ImmediateOperand, IMMEDIATE); | 344 INSTRUCTION_OPERAND_CASTS(ImmediateOperand, IMMEDIATE); |
333 | 345 |
334 STATIC_ASSERT(KindField::kSize == 3); | 346 STATIC_ASSERT(KindField::kSize == 3); |
335 class IndexField : public BitField64<int32_t, 35, 29> {}; | 347 class TypeField : public BitField64<ImmediateType, 3, 1> {}; |
| 348 class ValueField : public BitField64<int32_t, 32, 32> {}; |
336 }; | 349 }; |
337 | 350 |
338 | 351 |
339 class AllocatedOperand : public InstructionOperand { | 352 class AllocatedOperand : public InstructionOperand { |
340 public: | 353 public: |
341 enum AllocatedKind { | 354 enum AllocatedKind { |
342 STACK_SLOT, | 355 STACK_SLOT, |
343 DOUBLE_STACK_SLOT, | 356 DOUBLE_STACK_SLOT, |
344 REGISTER, | 357 REGISTER, |
345 DOUBLE_REGISTER | 358 DOUBLE_REGISTER |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 Constant GetConstant(int virtual_register) const { | 1072 Constant GetConstant(int virtual_register) const { |
1060 ConstantMap::const_iterator it = constants_.find(virtual_register); | 1073 ConstantMap::const_iterator it = constants_.find(virtual_register); |
1061 DCHECK(it != constants_.end()); | 1074 DCHECK(it != constants_.end()); |
1062 DCHECK_EQ(virtual_register, it->first); | 1075 DCHECK_EQ(virtual_register, it->first); |
1063 return it->second; | 1076 return it->second; |
1064 } | 1077 } |
1065 | 1078 |
1066 typedef ZoneVector<Constant> Immediates; | 1079 typedef ZoneVector<Constant> Immediates; |
1067 Immediates& immediates() { return immediates_; } | 1080 Immediates& immediates() { return immediates_; } |
1068 | 1081 |
1069 int AddImmediate(Constant constant) { | 1082 ImmediateOperand AddImmediate(const Constant& constant) { |
| 1083 if (constant.type() == Constant::kInt32) { |
| 1084 return ImmediateOperand(ImmediateOperand::INLINE, constant.ToInt32()); |
| 1085 } |
1070 int index = static_cast<int>(immediates_.size()); | 1086 int index = static_cast<int>(immediates_.size()); |
1071 immediates_.push_back(constant); | 1087 immediates_.push_back(constant); |
1072 return index; | 1088 return ImmediateOperand(ImmediateOperand::INDEXED, index); |
1073 } | 1089 } |
1074 Constant GetImmediate(int index) const { | 1090 |
1075 DCHECK(index >= 0); | 1091 Constant GetImmediate(const ImmediateOperand* op) const { |
1076 DCHECK(index < static_cast<int>(immediates_.size())); | 1092 switch (op->type()) { |
1077 return immediates_[index]; | 1093 case ImmediateOperand::INLINE: |
| 1094 return Constant(op->inline_value()); |
| 1095 case ImmediateOperand::INDEXED: { |
| 1096 int index = op->indexed_value(); |
| 1097 DCHECK(index >= 0); |
| 1098 DCHECK(index < static_cast<int>(immediates_.size())); |
| 1099 return immediates_[index]; |
| 1100 } |
| 1101 } |
| 1102 UNREACHABLE(); |
| 1103 return Constant(static_cast<int32_t>(0)); |
1078 } | 1104 } |
1079 | 1105 |
1080 class StateId { | 1106 class StateId { |
1081 public: | 1107 public: |
1082 static StateId FromInt(int id) { return StateId(id); } | 1108 static StateId FromInt(int id) { return StateId(id); } |
1083 int ToInt() const { return id_; } | 1109 int ToInt() const { return id_; } |
1084 | 1110 |
1085 private: | 1111 private: |
1086 explicit StateId(int id) : id_(id) {} | 1112 explicit StateId(int id) : id_(id) {} |
1087 int id_; | 1113 int id_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 | 1149 |
1124 | 1150 |
1125 std::ostream& operator<<(std::ostream& os, | 1151 std::ostream& operator<<(std::ostream& os, |
1126 const PrintableInstructionSequence& code); | 1152 const PrintableInstructionSequence& code); |
1127 | 1153 |
1128 } // namespace compiler | 1154 } // namespace compiler |
1129 } // namespace internal | 1155 } // namespace internal |
1130 } // namespace v8 | 1156 } // namespace v8 |
1131 | 1157 |
1132 #endif // V8_COMPILER_INSTRUCTION_H_ | 1158 #endif // V8_COMPILER_INSTRUCTION_H_ |
OLD | NEW |