Chromium Code Reviews| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 SMI_TYPE = 0x01, | 96 SMI_TYPE = 0x01, |
| 97 HEAP_OBJECT_TYPE = 0x02, | 97 HEAP_OBJECT_TYPE = 0x02, |
| 98 STRING_TYPE = 0x04 | HEAP_OBJECT_TYPE | 98 STRING_TYPE = 0x04 | HEAP_OBJECT_TYPE |
| 99 }; | 99 }; |
| 100 explicit StaticType(StaticTypeEnum static_type) : static_type_(static_type) {} | 100 explicit StaticType(StaticTypeEnum static_type) : static_type_(static_type) {} |
| 101 | 101 |
| 102 // StaticTypeEnum static_type_; | 102 // StaticTypeEnum static_type_; |
| 103 StaticTypeEnum static_type_; | 103 StaticTypeEnum static_type_; |
| 104 | 104 |
| 105 friend class FrameElement; | 105 friend class FrameElement; |
| 106 friend class Result; | |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 | 109 |
| 109 // ------------------------------------------------------------------------- | 110 // ------------------------------------------------------------------------- |
| 110 // Results | 111 // Results |
| 111 // | 112 // |
| 112 // Results encapsulate the compile-time values manipulated by the code | 113 // Results encapsulate the compile-time values manipulated by the code |
| 113 // generator. They can represent registers or constants. | 114 // generator. They can represent registers or constants. |
| 114 | 115 |
| 115 class Result BASE_EMBEDDED { | 116 class Result BASE_EMBEDDED { |
| 116 public: | 117 public: |
| 117 enum Type { | 118 enum Type { |
| 118 INVALID, | 119 INVALID, |
| 119 REGISTER, | 120 REGISTER, |
| 120 CONSTANT | 121 CONSTANT |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 // Construct an invalid result. | 124 // Construct an invalid result. |
| 124 explicit Result(CodeGenerator* cgen) | 125 explicit Result() { invalidate(); } |
|
Kevin Millikin (Chromium)
2009/05/15 10:50:49
Doesn't need explicit anymore.
Mads Ager (chromium)
2009/05/15 11:05:25
Done.
| |
| 125 : static_type_(), | |
| 126 type_(INVALID), | |
| 127 cgen_(cgen) {} | |
| 128 | 126 |
| 129 // Construct a register Result. | 127 // Construct a register Result. |
| 130 Result(Register reg, | 128 explicit Result(Register reg); |
| 131 CodeGenerator* cgen); | |
| 132 | 129 |
| 133 // Construct a register Result with a known static type. | 130 // Construct a register Result with a known static type. |
| 134 Result(Register reg, | 131 Result(Register reg, StaticType static_type); |
| 135 CodeGenerator* cgen, | |
| 136 StaticType static_type); | |
| 137 | 132 |
| 138 // Construct a Result whose value is a compile-time constant. | 133 // Construct a Result whose value is a compile-time constant. |
| 139 Result(Handle<Object> value, CodeGenerator * cgen) | 134 explicit Result(Handle<Object> value) { |
| 140 : static_type_(StaticType::TypeOf(*value)), | 135 value_ = StaticTypeField::encode(StaticType::TypeOf(*value).static_type_) |
| 141 type_(CONSTANT), | 136 | TypeField::encode(CONSTANT) |
| 142 cgen_(cgen) { | 137 | DataField::encode(ConstantList()->length()); |
| 143 data_.handle_ = value.location(); | 138 ConstantList()->Add(value); |
| 144 } | 139 } |
| 145 | 140 |
| 146 // The copy constructor and assignment operators could each create a new | 141 // The copy constructor and assignment operators could each create a new |
| 147 // register reference. | 142 // register reference. |
| 148 Result(const Result& other) { | 143 Result(const Result& other) { |
| 149 other.CopyTo(this); | 144 other.CopyTo(this); |
| 150 } | 145 } |
| 151 | 146 |
| 152 Result& operator=(const Result& other) { | 147 Result& operator=(const Result& other) { |
| 153 if (this != &other) { | 148 if (this != &other) { |
| 154 Unuse(); | 149 Unuse(); |
| 155 other.CopyTo(this); | 150 other.CopyTo(this); |
| 156 } | 151 } |
| 157 return *this; | 152 return *this; |
| 158 } | 153 } |
| 159 | 154 |
| 160 inline ~Result(); | 155 inline ~Result(); |
| 161 | 156 |
| 157 // Static indirection table for handles to constants. If a Result | |
| 158 // represents a constant, the data contains an index into this table | |
| 159 // of handles to the actual constants. | |
| 160 typedef ZoneList<Handle<Object> > ZoneObjectList; | |
| 161 | |
| 162 static ZoneObjectList* ConstantList() { | |
| 163 static ZoneObjectList list(10); | |
| 164 return &list; | |
| 165 } | |
| 166 | |
| 167 // Clear the constants indirection table. | |
| 168 static void ClearConstantList() { | |
| 169 ConstantList()->Clear(); | |
| 170 } | |
| 171 | |
| 162 inline void Unuse(); | 172 inline void Unuse(); |
| 163 | 173 |
| 164 StaticType static_type() const { return static_type_; } | 174 StaticType static_type() const { |
| 165 void set_static_type(StaticType static_type) { static_type_ = static_type; } | 175 return StaticType(StaticTypeField::decode(value_)); |
| 176 } | |
| 166 | 177 |
| 167 Type type() const { return static_cast<Type>(type_); } | 178 void set_static_type(StaticType type) { |
| 179 value_ = value_ & ~StaticTypeField::mask(); | |
| 180 value_ = value_ | StaticTypeField::encode(type.static_type_); | |
| 181 } | |
| 182 | |
| 183 Type type() const { return TypeField::decode(value_); } | |
| 184 | |
| 185 void invalidate() { value_ = TypeField::encode(INVALID); } | |
| 168 | 186 |
| 169 bool is_valid() const { return type() != INVALID; } | 187 bool is_valid() const { return type() != INVALID; } |
| 170 bool is_register() const { return type() == REGISTER; } | 188 bool is_register() const { return type() == REGISTER; } |
| 171 bool is_constant() const { return type() == CONSTANT; } | 189 bool is_constant() const { return type() == CONSTANT; } |
| 172 | 190 |
| 173 Register reg() const { | 191 Register reg() const { |
| 174 ASSERT(type() == REGISTER); | 192 ASSERT(is_register()); |
| 175 return data_.reg_; | 193 uint32_t reg = DataField::decode(value_); |
| 194 Register result; | |
| 195 result.code_ = reg; | |
| 196 return result; | |
| 176 } | 197 } |
| 177 | 198 |
| 178 Handle<Object> handle() const { | 199 Handle<Object> handle() const { |
| 179 ASSERT(type() == CONSTANT); | 200 ASSERT(type() == CONSTANT); |
| 180 return Handle<Object>(data_.handle_); | 201 return ConstantList()->at(DataField::decode(value_)); |
| 181 } | 202 } |
| 182 | 203 |
| 183 // Move this result to an arbitrary register. The register is not | 204 // Move this result to an arbitrary register. The register is not |
| 184 // necessarily spilled from the frame or even singly-referenced outside | 205 // necessarily spilled from the frame or even singly-referenced outside |
| 185 // it. | 206 // it. |
| 186 void ToRegister(); | 207 void ToRegister(); |
| 187 | 208 |
| 188 // Move this result to a specified register. The register is spilled from | 209 // Move this result to a specified register. The register is spilled from |
| 189 // the frame, and the register is singly-referenced (by this result) | 210 // the frame, and the register is singly-referenced (by this result) |
| 190 // outside the frame. | 211 // outside the frame. |
| 191 void ToRegister(Register reg); | 212 void ToRegister(Register reg); |
| 192 | 213 |
| 193 private: | 214 private: |
| 194 StaticType static_type_; | 215 uint32_t value_; |
| 195 byte type_; | |
| 196 | 216 |
| 197 union { | 217 class StaticTypeField: public BitField<StaticType::StaticTypeEnum, 0, 3> {}; |
| 198 Register reg_; | 218 class TypeField: public BitField<Type, 3, 2> {}; |
| 199 Object** handle_; | 219 class DataField: public BitField<uint32_t, 5, 32 - 6> {}; |
| 200 } data_; | |
| 201 | 220 |
| 202 CodeGenerator* cgen_; | 221 static CodeGenerator* cgen_; |
| 203 | 222 |
| 204 void CopyTo(Result* destination) const; | 223 inline void CopyTo(Result* destination) const; |
| 224 | |
| 225 friend class CodeGeneratorScope; | |
| 205 }; | 226 }; |
| 206 | 227 |
| 207 | 228 |
| 208 // ------------------------------------------------------------------------- | 229 // ------------------------------------------------------------------------- |
| 209 // Register file | 230 // Register file |
| 210 // | 231 // |
| 211 // The register file tracks reference counts for the processor registers. | 232 // The register file tracks reference counts for the processor registers. |
| 212 // It is used by both the register allocator and the virtual frame. | 233 // It is used by both the register allocator and the virtual frame. |
| 213 | 234 |
| 214 class RegisterFile BASE_EMBEDDED { | 235 class RegisterFile BASE_EMBEDDED { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 } | 356 } |
| 336 | 357 |
| 337 private: | 358 private: |
| 338 CodeGenerator* cgen_; | 359 CodeGenerator* cgen_; |
| 339 RegisterFile registers_; | 360 RegisterFile registers_; |
| 340 }; | 361 }; |
| 341 | 362 |
| 342 } } // namespace v8::internal | 363 } } // namespace v8::internal |
| 343 | 364 |
| 344 #endif // V8_REGISTER_ALLOCATOR_H_ | 365 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |