Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Unified Diff: src/register-allocator.h

Issue 113455: Clean up the Result class. Reduce the size of Result from four words... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/register-allocator.h
===================================================================
--- src/register-allocator.h (revision 1960)
+++ src/register-allocator.h (working copy)
@@ -103,6 +103,7 @@
StaticTypeEnum static_type_;
friend class FrameElement;
+ friend class Result;
};
@@ -121,26 +122,20 @@
};
// Construct an invalid result.
- explicit Result(CodeGenerator* cgen)
- : static_type_(),
- type_(INVALID),
- cgen_(cgen) {}
+ 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.
// Construct a register Result.
- Result(Register reg,
- CodeGenerator* cgen);
+ explicit Result(Register reg);
// Construct a register Result with a known static type.
- Result(Register reg,
- CodeGenerator* cgen,
- StaticType static_type);
+ Result(Register reg, StaticType static_type);
// Construct a Result whose value is a compile-time constant.
- Result(Handle<Object> value, CodeGenerator * cgen)
- : static_type_(StaticType::TypeOf(*value)),
- type_(CONSTANT),
- cgen_(cgen) {
- data_.handle_ = value.location();
+ explicit Result(Handle<Object> value) {
+ value_ = StaticTypeField::encode(StaticType::TypeOf(*value).static_type_)
+ | TypeField::encode(CONSTANT)
+ | DataField::encode(ConstantList()->length());
+ ConstantList()->Add(value);
}
// The copy constructor and assignment operators could each create a new
@@ -159,25 +154,51 @@
inline ~Result();
+ // Static indirection table for handles to constants. If a Result
+ // represents a constant, the data contains an index into this table
+ // of handles to the actual constants.
+ typedef ZoneList<Handle<Object> > ZoneObjectList;
+
+ static ZoneObjectList* ConstantList() {
+ static ZoneObjectList list(10);
+ return &list;
+ }
+
+ // Clear the constants indirection table.
+ static void ClearConstantList() {
+ ConstantList()->Clear();
+ }
+
inline void Unuse();
- StaticType static_type() const { return static_type_; }
- void set_static_type(StaticType static_type) { static_type_ = static_type; }
+ StaticType static_type() const {
+ return StaticType(StaticTypeField::decode(value_));
+ }
- Type type() const { return static_cast<Type>(type_); }
+ void set_static_type(StaticType type) {
+ value_ = value_ & ~StaticTypeField::mask();
+ value_ = value_ | StaticTypeField::encode(type.static_type_);
+ }
+ Type type() const { return TypeField::decode(value_); }
+
+ void invalidate() { value_ = TypeField::encode(INVALID); }
+
bool is_valid() const { return type() != INVALID; }
bool is_register() const { return type() == REGISTER; }
bool is_constant() const { return type() == CONSTANT; }
Register reg() const {
- ASSERT(type() == REGISTER);
- return data_.reg_;
+ ASSERT(is_register());
+ uint32_t reg = DataField::decode(value_);
+ Register result;
+ result.code_ = reg;
+ return result;
}
Handle<Object> handle() const {
ASSERT(type() == CONSTANT);
- return Handle<Object>(data_.handle_);
+ return ConstantList()->at(DataField::decode(value_));
}
// Move this result to an arbitrary register. The register is not
@@ -191,17 +212,17 @@
void ToRegister(Register reg);
private:
- StaticType static_type_;
- byte type_;
+ uint32_t value_;
- union {
- Register reg_;
- Object** handle_;
- } data_;
+ class StaticTypeField: public BitField<StaticType::StaticTypeEnum, 0, 3> {};
+ class TypeField: public BitField<Type, 3, 2> {};
+ class DataField: public BitField<uint32_t, 5, 32 - 6> {};
- CodeGenerator* cgen_;
+ static CodeGenerator* cgen_;
- void CopyTo(Result* destination) const;
+ inline void CopyTo(Result* destination) const;
+
+ friend class CodeGeneratorScope;
};

Powered by Google App Engine
This is Rietveld 408576698