| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_REGISTER_ALLOCATOR_H_ | 28 #ifndef V8_REGISTER_ALLOCATOR_H_ |
| 29 #define V8_REGISTER_ALLOCATOR_H_ | 29 #define V8_REGISTER_ALLOCATOR_H_ |
| 30 | 30 |
| 31 #include "macro-assembler.h" | 31 #include "macro-assembler.h" |
| 32 #include "number-info.h" |
| 32 | 33 |
| 33 #if V8_TARGET_ARCH_IA32 | 34 #if V8_TARGET_ARCH_IA32 |
| 34 #include "ia32/register-allocator-ia32.h" | 35 #include "ia32/register-allocator-ia32.h" |
| 35 #elif V8_TARGET_ARCH_X64 | 36 #elif V8_TARGET_ARCH_X64 |
| 36 #include "x64/register-allocator-x64.h" | 37 #include "x64/register-allocator-x64.h" |
| 37 #elif V8_TARGET_ARCH_ARM | 38 #elif V8_TARGET_ARCH_ARM |
| 38 #include "arm/register-allocator-arm.h" | 39 #include "arm/register-allocator-arm.h" |
| 39 #elif V8_TARGET_ARCH_MIPS | 40 #elif V8_TARGET_ARCH_MIPS |
| 40 #include "mips/register-allocator-mips.h" | 41 #include "mips/register-allocator-mips.h" |
| 41 #else | 42 #else |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 enum Type { | 58 enum Type { |
| 58 INVALID, | 59 INVALID, |
| 59 REGISTER, | 60 REGISTER, |
| 60 CONSTANT | 61 CONSTANT |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 // Construct an invalid result. | 64 // Construct an invalid result. |
| 64 Result() { invalidate(); } | 65 Result() { invalidate(); } |
| 65 | 66 |
| 66 // Construct a register Result. | 67 // Construct a register Result. |
| 67 explicit Result(Register reg); | 68 explicit Result(Register reg, NumberInfo::Type info = NumberInfo::kUnknown); |
| 68 | 69 |
| 69 // Construct a Result whose value is a compile-time constant. | 70 // Construct a Result whose value is a compile-time constant. |
| 70 explicit Result(Handle<Object> value) { | 71 explicit Result(Handle<Object> value) { |
| 71 value_ = TypeField::encode(CONSTANT) | 72 value_ = TypeField::encode(CONSTANT) |
| 73 | NumberInfoField::encode(NumberInfo::kUninitialized) |
| 72 | DataField::encode(ConstantList()->length()); | 74 | DataField::encode(ConstantList()->length()); |
| 73 ConstantList()->Add(value); | 75 ConstantList()->Add(value); |
| 74 } | 76 } |
| 75 | 77 |
| 76 // The copy constructor and assignment operators could each create a new | 78 // The copy constructor and assignment operators could each create a new |
| 77 // register reference. | 79 // register reference. |
| 78 Result(const Result& other) { | 80 inline Result(const Result& other); |
| 79 other.CopyTo(this); | |
| 80 } | |
| 81 | 81 |
| 82 Result& operator=(const Result& other) { | 82 inline Result& operator=(const Result& other); |
| 83 if (this != &other) { | |
| 84 Unuse(); | |
| 85 other.CopyTo(this); | |
| 86 } | |
| 87 return *this; | |
| 88 } | |
| 89 | 83 |
| 90 inline ~Result(); | 84 inline ~Result(); |
| 91 | 85 |
| 92 // Static indirection table for handles to constants. If a Result | 86 // Static indirection table for handles to constants. If a Result |
| 93 // represents a constant, the data contains an index into this table | 87 // represents a constant, the data contains an index into this table |
| 94 // of handles to the actual constants. | 88 // of handles to the actual constants. |
| 95 typedef ZoneList<Handle<Object> > ZoneObjectList; | 89 typedef ZoneList<Handle<Object> > ZoneObjectList; |
| 96 | 90 |
| 97 static ZoneObjectList* ConstantList(); | 91 static ZoneObjectList* ConstantList(); |
| 98 | 92 |
| 99 // Clear the constants indirection table. | 93 // Clear the constants indirection table. |
| 100 static void ClearConstantList() { | 94 static void ClearConstantList() { |
| 101 ConstantList()->Clear(); | 95 ConstantList()->Clear(); |
| 102 } | 96 } |
| 103 | 97 |
| 104 inline void Unuse(); | 98 inline void Unuse(); |
| 105 | 99 |
| 106 Type type() const { return TypeField::decode(value_); } | 100 Type type() const { return TypeField::decode(value_); } |
| 107 | 101 |
| 108 void invalidate() { value_ = TypeField::encode(INVALID); } | 102 void invalidate() { value_ = TypeField::encode(INVALID); } |
| 109 | 103 |
| 104 NumberInfo::Type number_info(); |
| 105 void set_number_info(NumberInfo::Type info); |
| 106 bool is_number() { |
| 107 return (number_info() & NumberInfo::kNumber) != 0; |
| 108 } |
| 109 bool is_smi() { return number_info() == NumberInfo::kSmi; } |
| 110 bool is_heap_number() { return number_info() == NumberInfo::kHeapNumber; } |
| 111 |
| 110 bool is_valid() const { return type() != INVALID; } | 112 bool is_valid() const { return type() != INVALID; } |
| 111 bool is_register() const { return type() == REGISTER; } | 113 bool is_register() const { return type() == REGISTER; } |
| 112 bool is_constant() const { return type() == CONSTANT; } | 114 bool is_constant() const { return type() == CONSTANT; } |
| 113 | 115 |
| 114 Register reg() const { | 116 Register reg() const { |
| 115 ASSERT(is_register()); | 117 ASSERT(is_register()); |
| 116 uint32_t reg = DataField::decode(value_); | 118 uint32_t reg = DataField::decode(value_); |
| 117 Register result; | 119 Register result; |
| 118 result.code_ = reg; | 120 result.code_ = reg; |
| 119 return result; | 121 return result; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 131 | 133 |
| 132 // Move this result to a specified register. The register is spilled from | 134 // Move this result to a specified register. The register is spilled from |
| 133 // the frame, and the register is singly-referenced (by this result) | 135 // the frame, and the register is singly-referenced (by this result) |
| 134 // outside the frame. | 136 // outside the frame. |
| 135 void ToRegister(Register reg); | 137 void ToRegister(Register reg); |
| 136 | 138 |
| 137 private: | 139 private: |
| 138 uint32_t value_; | 140 uint32_t value_; |
| 139 | 141 |
| 140 class TypeField: public BitField<Type, 0, 2> {}; | 142 class TypeField: public BitField<Type, 0, 2> {}; |
| 141 class DataField: public BitField<uint32_t, 2, 32 - 3> {}; | 143 class NumberInfoField : public BitField<NumberInfo::Type, 2, 3> {}; |
| 144 class DataField: public BitField<uint32_t, 5, 32 - 5> {}; |
| 142 | 145 |
| 143 inline void CopyTo(Result* destination) const; | 146 inline void CopyTo(Result* destination) const; |
| 144 | 147 |
| 145 friend class CodeGeneratorScope; | 148 friend class CodeGeneratorScope; |
| 146 }; | 149 }; |
| 147 | 150 |
| 148 | 151 |
| 149 // ------------------------------------------------------------------------- | 152 // ------------------------------------------------------------------------- |
| 150 // Register file | 153 // Register file |
| 151 // | 154 // |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // platform-specific XXX-inl.h files.. | 233 // platform-specific XXX-inl.h files.. |
| 231 static inline bool IsReserved(Register reg); | 234 static inline bool IsReserved(Register reg); |
| 232 | 235 |
| 233 // Convert between (unreserved) assembler registers and allocator | 236 // Convert between (unreserved) assembler registers and allocator |
| 234 // numbers. Defined in the platform-specific XXX-inl.h files. | 237 // numbers. Defined in the platform-specific XXX-inl.h files. |
| 235 static inline int ToNumber(Register reg); | 238 static inline int ToNumber(Register reg); |
| 236 static inline Register ToRegister(int num); | 239 static inline Register ToRegister(int num); |
| 237 | 240 |
| 238 // Predicates and accessors for the registers' reference counts. | 241 // Predicates and accessors for the registers' reference counts. |
| 239 bool is_used(int num) { return registers_.is_used(num); } | 242 bool is_used(int num) { return registers_.is_used(num); } |
| 240 bool is_used(Register reg) { return registers_.is_used(ToNumber(reg)); } | 243 inline bool is_used(Register reg); |
| 241 | 244 |
| 242 int count(int num) { return registers_.count(num); } | 245 int count(int num) { return registers_.count(num); } |
| 243 int count(Register reg) { return registers_.count(ToNumber(reg)); } | 246 inline int count(Register reg); |
| 244 | 247 |
| 245 // Explicitly record a reference to a register. | 248 // Explicitly record a reference to a register. |
| 246 void Use(int num) { registers_.Use(num); } | 249 void Use(int num) { registers_.Use(num); } |
| 247 void Use(Register reg) { registers_.Use(ToNumber(reg)); } | 250 inline void Use(Register reg); |
| 248 | 251 |
| 249 // Explicitly record that a register will no longer be used. | 252 // Explicitly record that a register will no longer be used. |
| 250 void Unuse(int num) { registers_.Unuse(num); } | 253 void Unuse(int num) { registers_.Unuse(num); } |
| 251 void Unuse(Register reg) { registers_.Unuse(ToNumber(reg)); } | 254 inline void Unuse(Register reg); |
| 252 | 255 |
| 253 // Reset the register reference counts to free all non-reserved registers. | 256 // Reset the register reference counts to free all non-reserved registers. |
| 254 void Reset() { registers_.Reset(); } | 257 void Reset() { registers_.Reset(); } |
| 255 | 258 |
| 256 // Initialize the register allocator for entry to a JS function. On | 259 // Initialize the register allocator for entry to a JS function. On |
| 257 // entry, the (non-reserved) registers used by the JS calling | 260 // entry, the (non-reserved) registers used by the JS calling |
| 258 // convention are referenced and the other (non-reserved) registers | 261 // convention are referenced and the other (non-reserved) registers |
| 259 // are free. | 262 // are free. |
| 260 inline void Initialize(); | 263 inline void Initialize(); |
| 261 | 264 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 288 } | 291 } |
| 289 | 292 |
| 290 private: | 293 private: |
| 291 CodeGenerator* cgen_; | 294 CodeGenerator* cgen_; |
| 292 RegisterFile registers_; | 295 RegisterFile registers_; |
| 293 }; | 296 }; |
| 294 | 297 |
| 295 } } // namespace v8::internal | 298 } } // namespace v8::internal |
| 296 | 299 |
| 297 #endif // V8_REGISTER_ALLOCATOR_H_ | 300 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |