Revision: 23408
Author: [email protected]
Date: Tue Aug 26 14:41:58 2014 UTC
Log: Use an enum of Flags internally in CompilationInfo.
This is a first step in cleaning up CompilationInfo; a subsequent logical
step
would be to inline most is_* and Set* and Mark* calls so that most callers
can use call info.SetFlag(CompilationInfo::kMyFlag), or at the very least,
rename them all to be consistent with their enum flag names.
[email protected], [email protected]
BUG=
Review URL: https://codereview.chromium.org/504163002
https://code.google.com/p/v8/source/detail?r=23408
Modified:
/branches/bleeding_edge/src/compiler.cc
/branches/bleeding_edge/src/compiler.h
=======================================
--- /branches/bleeding_edge/src/compiler.cc Mon Aug 25 13:07:09 2014 UTC
+++ /branches/bleeding_edge/src/compiler.cc Tue Aug 26 14:41:58 2014 UTC
@@ -45,11 +45,10 @@
CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
- : flags_(StrictModeField::encode(SLOPPY)),
+ : flags_(kThisHasUses),
script_(script),
osr_ast_id_(BailoutId::None()),
parameter_count_(0),
- this_has_uses_(true),
optimization_id_(-1),
ast_value_factory_(NULL),
ast_value_factory_owned_(false) {
@@ -58,11 +57,10 @@
CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone)
- : flags_(StrictModeField::encode(SLOPPY)),
+ : flags_(kThisHasUses),
script_(Handle<Script>::null()),
osr_ast_id_(BailoutId::None()),
parameter_count_(0),
- this_has_uses_(true),
optimization_id_(-1),
ast_value_factory_(NULL),
ast_value_factory_owned_(false) {
@@ -72,12 +70,11 @@
CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
Zone* zone)
- : flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)),
+ : flags_(kLazy | kThisHasUses),
shared_info_(shared_info),
script_(Handle<Script>(Script::cast(shared_info->script()))),
osr_ast_id_(BailoutId::None()),
parameter_count_(0),
- this_has_uses_(true),
optimization_id_(-1),
ast_value_factory_(NULL),
ast_value_factory_owned_(false) {
@@ -86,14 +83,13 @@
CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
- : flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)),
+ : flags_(kLazy | kThisHasUses),
closure_(closure),
shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
script_(Handle<Script>(Script::cast(shared_info_->script()))),
context_(closure->context()),
osr_ast_id_(BailoutId::None()),
parameter_count_(0),
- this_has_uses_(true),
optimization_id_(-1),
ast_value_factory_(NULL),
ast_value_factory_owned_(false) {
@@ -103,10 +99,9 @@
CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate,
Zone* zone)
- : flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)),
+ : flags_(kLazy | kThisHasUses),
osr_ast_id_(BailoutId::None()),
parameter_count_(0),
- this_has_uses_(true),
optimization_id_(-1),
ast_value_factory_(NULL),
ast_value_factory_owned_(false) {
=======================================
--- /branches/bleeding_edge/src/compiler.h Fri Aug 22 11:12:29 2014 UTC
+++ /branches/bleeding_edge/src/compiler.h Tue Aug 26 14:41:58 2014 UTC
@@ -57,11 +57,31 @@
DISALLOW_COPY_AND_ASSIGN(ScriptData);
};
-
// CompilationInfo encapsulates some information known at compile time. It
// is constructed based on the resources available at compile-time.
class CompilationInfo {
public:
+ // Various configuration flags for a compilation, as well as some
properties
+ // of the compiled code produced by a compilation.
+ enum Flag {
+ kLazy = 1 << 0,
+ kEval = 1 << 1,
+ kGlobal = 1 << 2,
+ kStrictMode = 1 << 3,
+ kThisHasUses = 1 << 4,
+ kNative = 1 << 5,
+ kDeferredCalling = 1 << 6,
+ kNonDeferredCalling = 1 << 7,
+ kSavesCallerDoubles = 1 << 8,
+ kRequiresFrame = 1 << 9,
+ kMustNotHaveEagerFrame = 1 << 10,
+ kDeoptimizationSupport = 1 << 11,
+ kDebug = 1 << 12,
+ kCompilingForDebugging = 1 << 13,
+ kParseRestriction = 1 << 14,
+ kSerializing = 1 << 15
+ };
+
CompilationInfo(Handle<JSFunction> closure, Zone* zone);
CompilationInfo(Isolate* isolate, Zone* zone);
virtual ~CompilationInfo();
@@ -71,10 +91,12 @@
}
Zone* zone() { return zone_; }
bool is_osr() const { return !osr_ast_id_.IsNone(); }
- bool is_lazy() const { return IsLazy::decode(flags_); }
- bool is_eval() const { return IsEval::decode(flags_); }
- bool is_global() const { return IsGlobal::decode(flags_); }
- StrictMode strict_mode() const { return StrictModeField::decode(flags_);
}
+ bool is_lazy() const { return GetFlag(kLazy); }
+ bool is_eval() const { return GetFlag(kEval); }
+ bool is_global() const { return GetFlag(kGlobal); }
+ StrictMode strict_mode() const {
+ return GetFlag(kStrictMode) ? STRICT : SLOPPY;
+ }
FunctionLiteral* function() const { return function_; }
Scope* scope() const { return scope_; }
Scope* global_scope() const { return global_scope_; }
@@ -98,12 +120,12 @@
void MarkAsEval() {
DCHECK(!is_lazy());
- flags_ |= IsEval::encode(true);
+ SetFlag(kEval);
}
void MarkAsGlobal() {
DCHECK(!is_lazy());
- flags_ |= IsGlobal::encode(true);
+ SetFlag(kGlobal);
}
void set_parameter_count(int parameter_count) {
@@ -112,83 +134,52 @@
}
void set_this_has_uses(bool has_no_uses) {
- this_has_uses_ = has_no_uses;
+ SetFlag(kThisHasUses, has_no_uses);
}
- bool this_has_uses() {
- return this_has_uses_;
- }
+ bool this_has_uses() { return GetFlag(kThisHasUses); }
void SetStrictMode(StrictMode strict_mode) {
- DCHECK(this->strict_mode() == SLOPPY || this->strict_mode() ==
strict_mode);
- flags_ = StrictModeField::update(flags_, strict_mode);
+ SetFlag(kStrictMode, strict_mode == STRICT);
}
- void MarkAsNative() {
- flags_ |= IsNative::encode(true);
- }
+ void MarkAsNative() { SetFlag(kNative); }
- bool is_native() const {
- return IsNative::decode(flags_);
- }
+ bool is_native() const { return GetFlag(kNative); }
bool is_calling() const {
- return is_deferred_calling() || is_non_deferred_calling();
+ return GetFlag(kDeferredCalling) || GetFlag(kNonDeferredCalling);
}
- void MarkAsDeferredCalling() {
- flags_ |= IsDeferredCalling::encode(true);
- }
+ void MarkAsDeferredCalling() { SetFlag(kDeferredCalling); }
- bool is_deferred_calling() const {
- return IsDeferredCalling::decode(flags_);
- }
+ bool is_deferred_calling() const { return GetFlag(kDeferredCalling); }
- void MarkAsNonDeferredCalling() {
- flags_ |= IsNonDeferredCalling::encode(true);
- }
+ void MarkAsNonDeferredCalling() { SetFlag(kNonDeferredCalling); }
- bool is_non_deferred_calling() const {
- return IsNonDeferredCalling::decode(flags_);
- }
+ bool is_non_deferred_calling() const { return
GetFlag(kNonDeferredCalling); }
- void MarkAsSavesCallerDoubles() {
- flags_ |= SavesCallerDoubles::encode(true);
- }
+ void MarkAsSavesCallerDoubles() { SetFlag(kSavesCallerDoubles); }
- bool saves_caller_doubles() const {
- return SavesCallerDoubles::decode(flags_);
- }
+ bool saves_caller_doubles() const { return GetFlag(kSavesCallerDoubles);
}
- void MarkAsRequiresFrame() {
- flags_ |= RequiresFrame::encode(true);
- }
+ void MarkAsRequiresFrame() { SetFlag(kRequiresFrame); }
- bool requires_frame() const {
- return RequiresFrame::decode(flags_);
- }
+ bool requires_frame() const { return GetFlag(kRequiresFrame); }
- void MarkMustNotHaveEagerFrame() {
- flags_ |= MustNotHaveEagerFrame::encode(true);
- }
+ void MarkMustNotHaveEagerFrame() { SetFlag(kMustNotHaveEagerFrame); }
bool GetMustNotHaveEagerFrame() const {
- return MustNotHaveEagerFrame::decode(flags_);
+ return GetFlag(kMustNotHaveEagerFrame);
}
- void MarkAsDebug() {
- flags_ |= IsDebug::encode(true);
- }
+ void MarkAsDebug() { SetFlag(kDebug); }
- bool is_debug() const {
- return IsDebug::decode(flags_);
- }
+ bool is_debug() const { return GetFlag(kDebug); }
- void PrepareForSerializing() {
- flags_ |= PrepareForSerializing::encode(true);
- }
+ void PrepareForSerializing() { SetFlag(kSerializing); }
- bool will_serialize() const { return
PrepareForSerializing::decode(flags_); }
+ bool will_serialize() const { return GetFlag(kSerializing); }
bool IsCodePreAgingActive() const {
return FLAG_optimize_for_size && FLAG_age_code && !will_serialize() &&
@@ -196,11 +187,12 @@
}
void SetParseRestriction(ParseRestriction restriction) {
- flags_ = ParseRestricitonField::update(flags_, restriction);
+ SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION);
}
ParseRestriction parse_restriction() const {
- return ParseRestricitonField::decode(flags_);
+ return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL
+ : NO_PARSE_RESTRICTION;
}
void SetFunction(FunctionLiteral* literal) {
@@ -234,12 +226,8 @@
context_ = context;
}
- void MarkCompilingForDebugging() {
- flags_ |= IsCompilingForDebugging::encode(true);
- }
- bool IsCompilingForDebugging() {
- return IsCompilingForDebugging::decode(flags_);
- }
+ void MarkCompilingForDebugging() { SetFlag(kCompilingForDebugging); }
+ bool IsCompilingForDebugging() { return GetFlag(kCompilingForDebugging);
}
void MarkNonOptimizable() {
SetMode(CompilationInfo::NONOPT);
}
@@ -273,11 +261,11 @@
// Deoptimization support.
bool HasDeoptimizationSupport() const {
- return SupportsDeoptimization::decode(flags_);
+ return GetFlag(kDeoptimizationSupport);
}
void EnableDeoptimizationSupport() {
DCHECK(IsOptimizable());
- flags_ |= SupportsDeoptimization::encode(true);
+ SetFlag(kDeoptimizationSupport);
}
// Determines whether or not to insert a self-optimization header.
@@ -397,41 +385,13 @@
mode_ = mode;
}
- // Flags using template class BitField<type, start, length>. All are
- // false by default.
- //
- // Compilation is either eager or lazy.
- class IsLazy: public BitField<bool, 0, 1> {};
- // Flags that can be set for eager compilation.
- class IsEval: public BitField<bool, 1, 1> {};
- class IsGlobal: public BitField<bool, 2, 1> {};
- // If the function is being compiled for the debugger.
- class IsDebug: public BitField<bool, 3, 1> {};
- // Strict mode - used in eager compilation.
- class StrictModeField: public BitField<StrictMode, 4, 1> {};
- // Is this a function from our natives.
- class IsNative: public BitField<bool, 5, 1> {};
- // Is this code being compiled with support for deoptimization..
- class SupportsDeoptimization: public BitField<bool, 6, 1> {};
- // If compiling for debugging produce just full code matching the
- // initial mode setting.
- class IsCompilingForDebugging: public BitField<bool, 7, 1> {};
- // If the compiled code contains calls that require building a frame
- class IsCalling: public BitField<bool, 8, 1> {};
- // If the compiled code contains calls that require building a frame
- class IsDeferredCalling: public BitField<bool, 9, 1> {};
- // If the compiled code contains calls that require building a frame
- class IsNonDeferredCalling: public BitField<bool, 10, 1> {};
- // If the compiled code saves double caller registers that it clobbers.
- class SavesCallerDoubles: public BitField<bool, 11, 1> {};
- // If the set of valid statements is restricted.
- class ParseRestricitonField: public BitField<ParseRestriction, 12, 1> {};
- // If the function requires a frame (for unspecified reasons)
- class RequiresFrame: public BitField<bool, 13, 1> {};
- // If the function cannot build a frame (for unspecified reasons)
- class MustNotHaveEagerFrame: public BitField<bool, 14, 1> {};
- // If we plan to serialize the compiled code.
- class PrepareForSerializing : public BitField<bool, 15, 1> {};
+ void SetFlag(Flag flag) { flags_ |= flag; }
+
+ void SetFlag(Flag flag, bool value) {
+ flags_ = value ? flags_ | flag : flags_ & ~flag;
+ }
+
+ bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
unsigned flags_;
@@ -505,8 +465,6 @@
// Number of parameters used for compilation of stubs that require
arguments.
int parameter_count_;
- bool this_has_uses_;
-
Handle<Foreign> object_wrapper_;
int optimization_id_;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.