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

Unified Diff: src/ast/variables.h

Issue 2257493002: Better pack fields in Variable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Merged master Created 4 years, 4 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
« no previous file with comments | « no previous file | src/ast/variables.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/variables.h
diff --git a/src/ast/variables.h b/src/ast/variables.h
index f1f63b8a14cb8f9bf151dc3e2c7f9db248995486..f76d4d7bea254f5bff47ba753db9ffd9a085e8be 100644
--- a/src/ast/variables.h
+++ b/src/ast/variables.h
@@ -17,7 +17,13 @@ namespace internal {
// after binding and variable allocation.
class Variable final : public ZoneObject {
public:
- enum Kind { NORMAL, FUNCTION, THIS, ARGUMENTS };
+ enum Kind : uint8_t {
+ NORMAL,
+ FUNCTION,
+ THIS,
+ ARGUMENTS,
+ kLastKind = ARGUMENTS
+ };
Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind,
InitializationFlag initialization_flag,
@@ -38,51 +44,54 @@ class Variable final : public ZoneObject {
Handle<String> name() const { return name_->string(); }
const AstRawString* raw_name() const { return name_; }
- VariableMode mode() const { return mode_; }
+ VariableMode mode() const { return VariableModeField::decode(bit_field_); }
bool has_forced_context_allocation() const {
- return force_context_allocation_;
+ return ForceContextAllocationField::decode(bit_field_);
}
void ForceContextAllocation() {
- DCHECK(IsUnallocated() || IsContextSlot());
- force_context_allocation_ = true;
+ bit_field_ = ForceContextAllocationField::update(bit_field_, true);
neis 2016/08/25 08:57:20 Was the DCHECK removed by accident?
+ }
+ bool is_used() { return IsUsedField::decode(bit_field_); }
+ void set_is_used() { bit_field_ = IsUsedField::update(bit_field_, true); }
+ MaybeAssignedFlag maybe_assigned() const {
+ return MaybeAssignedFlagField::decode(bit_field_);
+ }
+ void set_maybe_assigned() {
+ bit_field_ = MaybeAssignedFlagField::update(bit_field_, kMaybeAssigned);
}
- bool is_used() { return is_used_; }
- void set_is_used() { is_used_ = true; }
- MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; }
- void set_maybe_assigned() { maybe_assigned_ = kMaybeAssigned; }
int initializer_position() { return initializer_position_; }
void set_initializer_position(int pos) { initializer_position_ = pos; }
bool IsUnallocated() const {
- return location_ == VariableLocation::UNALLOCATED;
+ return location() == VariableLocation::UNALLOCATED;
}
- bool IsParameter() const { return location_ == VariableLocation::PARAMETER; }
- bool IsStackLocal() const { return location_ == VariableLocation::LOCAL; }
+ bool IsParameter() const { return location() == VariableLocation::PARAMETER; }
+ bool IsStackLocal() const { return location() == VariableLocation::LOCAL; }
bool IsStackAllocated() const { return IsParameter() || IsStackLocal(); }
- bool IsContextSlot() const { return location_ == VariableLocation::CONTEXT; }
- bool IsGlobalSlot() const { return location_ == VariableLocation::GLOBAL; }
+ bool IsContextSlot() const { return location() == VariableLocation::CONTEXT; }
+ bool IsGlobalSlot() const { return location() == VariableLocation::GLOBAL; }
bool IsUnallocatedOrGlobalSlot() const {
return IsUnallocated() || IsGlobalSlot();
}
- bool IsLookupSlot() const { return location_ == VariableLocation::LOOKUP; }
+ bool IsLookupSlot() const { return location() == VariableLocation::LOOKUP; }
bool IsGlobalObjectProperty() const;
bool IsStaticGlobalObjectProperty() const;
- bool is_dynamic() const { return IsDynamicVariableMode(mode_); }
- bool is_const_mode() const { return IsImmutableVariableMode(mode_); }
+ bool is_dynamic() const { return IsDynamicVariableMode(mode()); }
+ bool is_const_mode() const { return IsImmutableVariableMode(mode()); }
bool binding_needs_init() const {
- DCHECK(initialization_flag_ != kNeedsInitialization ||
- IsLexicalVariableMode(mode_));
- return initialization_flag_ == kNeedsInitialization;
+ DCHECK(initialization_flag() != kNeedsInitialization ||
+ IsLexicalVariableMode(mode()));
+ return initialization_flag() == kNeedsInitialization;
}
- bool is_function() const { return kind_ == FUNCTION; }
- bool is_this() const { return kind_ == THIS; }
- bool is_arguments() const { return kind_ == ARGUMENTS; }
+ bool is_function() const { return kind() == FUNCTION; }
+ bool is_this() const { return kind() == THIS; }
+ bool is_arguments() const { return kind() == ARGUMENTS; }
Variable* local_if_not_shadowed() const {
- DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL);
+ DCHECK(mode() == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL);
return local_if_not_shadowed_;
}
@@ -90,15 +99,21 @@ class Variable final : public ZoneObject {
local_if_not_shadowed_ = local;
}
- VariableLocation location() const { return location_; }
- int index() const { return index_; }
+ VariableLocation location() const {
+ return LocationField::decode(bit_field_);
+ }
+ Kind kind() const { return KindField::decode(bit_field_); }
InitializationFlag initialization_flag() const {
- return initialization_flag_;
+ return InitializationFlagField::decode(bit_field_);
}
+ int index() const { return index_; }
+
void AllocateTo(VariableLocation location, int index) {
- DCHECK(IsUnallocated() || (location_ == location && index_ == index));
- location_ = location;
+ DCHECK(IsUnallocated() ||
+ (this->location() == location && this->index() == index));
+ bit_field_ = LocationField::update(bit_field_, location);
+ DCHECK_EQ(location, this->location());
index_ = index;
}
@@ -107,23 +122,29 @@ class Variable final : public ZoneObject {
private:
Scope* scope_;
const AstRawString* name_;
- VariableMode mode_;
- Kind kind_;
- VariableLocation location_;
- int index_;
- int initializer_position_;
// If this field is set, this variable references the stored locally bound
// variable, but it might be shadowed by variable bindings introduced by
// sloppy 'eval' calls between the reference scope (inclusive) and the
// binding scope (exclusive).
Variable* local_if_not_shadowed_;
-
- // Usage info.
- bool force_context_allocation_; // set by variable resolver
- bool is_used_;
- InitializationFlag initialization_flag_;
- MaybeAssignedFlag maybe_assigned_;
+ int index_;
+ int initializer_position_;
+ uint16_t bit_field_;
+
+ class VariableModeField : public BitField16<VariableMode, 0, 3> {};
+ class KindField : public BitField16<Kind, VariableModeField::kNext, 2> {};
+ class LocationField
+ : public BitField16<VariableLocation, KindField::kNext, 3> {};
+ class ForceContextAllocationField
+ : public BitField16<bool, LocationField::kNext, 1> {};
+ class IsUsedField
+ : public BitField16<bool, ForceContextAllocationField::kNext, 1> {};
+ class InitializationFlagField
+ : public BitField16<InitializationFlag, IsUsedField::kNext, 2> {};
+ class MaybeAssignedFlagField
+ : public BitField16<MaybeAssignedFlag, InitializationFlagField::kNext,
+ 2> {};
};
} // namespace internal
} // namespace v8
« no previous file with comments | « no previous file | src/ast/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698