Commit a4cdbfc4 authored by titzer@chromium.org's avatar titzer@chromium.org

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.

R=yangguo@chromium.org, bmeuer@chromium.org
BUG=

Review URL: https://codereview.chromium.org/504163002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23408 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 102b3bda
...@@ -45,11 +45,10 @@ ScriptData::ScriptData(const byte* data, int length) ...@@ -45,11 +45,10 @@ ScriptData::ScriptData(const byte* data, int length)
CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
: flags_(StrictModeField::encode(SLOPPY)), : flags_(kThisHasUses),
script_(script), script_(script),
osr_ast_id_(BailoutId::None()), osr_ast_id_(BailoutId::None()),
parameter_count_(0), parameter_count_(0),
this_has_uses_(true),
optimization_id_(-1), optimization_id_(-1),
ast_value_factory_(NULL), ast_value_factory_(NULL),
ast_value_factory_owned_(false) { ast_value_factory_owned_(false) {
...@@ -58,11 +57,10 @@ CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) ...@@ -58,11 +57,10 @@ CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone) CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone)
: flags_(StrictModeField::encode(SLOPPY)), : flags_(kThisHasUses),
script_(Handle<Script>::null()), script_(Handle<Script>::null()),
osr_ast_id_(BailoutId::None()), osr_ast_id_(BailoutId::None()),
parameter_count_(0), parameter_count_(0),
this_has_uses_(true),
optimization_id_(-1), optimization_id_(-1),
ast_value_factory_(NULL), ast_value_factory_(NULL),
ast_value_factory_owned_(false) { ast_value_factory_owned_(false) {
...@@ -72,12 +70,11 @@ CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone) ...@@ -72,12 +70,11 @@ CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone)
CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
Zone* zone) Zone* zone)
: flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)), : flags_(kLazy | kThisHasUses),
shared_info_(shared_info), shared_info_(shared_info),
script_(Handle<Script>(Script::cast(shared_info->script()))), script_(Handle<Script>(Script::cast(shared_info->script()))),
osr_ast_id_(BailoutId::None()), osr_ast_id_(BailoutId::None()),
parameter_count_(0), parameter_count_(0),
this_has_uses_(true),
optimization_id_(-1), optimization_id_(-1),
ast_value_factory_(NULL), ast_value_factory_(NULL),
ast_value_factory_owned_(false) { ast_value_factory_owned_(false) {
...@@ -86,14 +83,13 @@ CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, ...@@ -86,14 +83,13 @@ CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
: flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)), : flags_(kLazy | kThisHasUses),
closure_(closure), closure_(closure),
shared_info_(Handle<SharedFunctionInfo>(closure->shared())), shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
script_(Handle<Script>(Script::cast(shared_info_->script()))), script_(Handle<Script>(Script::cast(shared_info_->script()))),
context_(closure->context()), context_(closure->context()),
osr_ast_id_(BailoutId::None()), osr_ast_id_(BailoutId::None()),
parameter_count_(0), parameter_count_(0),
this_has_uses_(true),
optimization_id_(-1), optimization_id_(-1),
ast_value_factory_(NULL), ast_value_factory_(NULL),
ast_value_factory_owned_(false) { ast_value_factory_owned_(false) {
...@@ -103,10 +99,9 @@ CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) ...@@ -103,10 +99,9 @@ CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate,
Zone* zone) Zone* zone)
: flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)), : flags_(kLazy | kThisHasUses),
osr_ast_id_(BailoutId::None()), osr_ast_id_(BailoutId::None()),
parameter_count_(0), parameter_count_(0),
this_has_uses_(true),
optimization_id_(-1), optimization_id_(-1),
ast_value_factory_(NULL), ast_value_factory_(NULL),
ast_value_factory_owned_(false) { ast_value_factory_owned_(false) {
......
...@@ -57,11 +57,31 @@ class ScriptData { ...@@ -57,11 +57,31 @@ class ScriptData {
DISALLOW_COPY_AND_ASSIGN(ScriptData); DISALLOW_COPY_AND_ASSIGN(ScriptData);
}; };
// CompilationInfo encapsulates some information known at compile time. It // CompilationInfo encapsulates some information known at compile time. It
// is constructed based on the resources available at compile-time. // is constructed based on the resources available at compile-time.
class CompilationInfo { class CompilationInfo {
public: 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(Handle<JSFunction> closure, Zone* zone);
CompilationInfo(Isolate* isolate, Zone* zone); CompilationInfo(Isolate* isolate, Zone* zone);
virtual ~CompilationInfo(); virtual ~CompilationInfo();
...@@ -71,10 +91,12 @@ class CompilationInfo { ...@@ -71,10 +91,12 @@ class CompilationInfo {
} }
Zone* zone() { return zone_; } Zone* zone() { return zone_; }
bool is_osr() const { return !osr_ast_id_.IsNone(); } bool is_osr() const { return !osr_ast_id_.IsNone(); }
bool is_lazy() const { return IsLazy::decode(flags_); } bool is_lazy() const { return GetFlag(kLazy); }
bool is_eval() const { return IsEval::decode(flags_); } bool is_eval() const { return GetFlag(kEval); }
bool is_global() const { return IsGlobal::decode(flags_); } bool is_global() const { return GetFlag(kGlobal); }
StrictMode strict_mode() const { return StrictModeField::decode(flags_); } StrictMode strict_mode() const {
return GetFlag(kStrictMode) ? STRICT : SLOPPY;
}
FunctionLiteral* function() const { return function_; } FunctionLiteral* function() const { return function_; }
Scope* scope() const { return scope_; } Scope* scope() const { return scope_; }
Scope* global_scope() const { return global_scope_; } Scope* global_scope() const { return global_scope_; }
...@@ -98,12 +120,12 @@ class CompilationInfo { ...@@ -98,12 +120,12 @@ class CompilationInfo {
void MarkAsEval() { void MarkAsEval() {
DCHECK(!is_lazy()); DCHECK(!is_lazy());
flags_ |= IsEval::encode(true); SetFlag(kEval);
} }
void MarkAsGlobal() { void MarkAsGlobal() {
DCHECK(!is_lazy()); DCHECK(!is_lazy());
flags_ |= IsGlobal::encode(true); SetFlag(kGlobal);
} }
void set_parameter_count(int parameter_count) { void set_parameter_count(int parameter_count) {
...@@ -112,83 +134,52 @@ class CompilationInfo { ...@@ -112,83 +134,52 @@ class CompilationInfo {
} }
void set_this_has_uses(bool has_no_uses) { void set_this_has_uses(bool has_no_uses) {
this_has_uses_ = has_no_uses; SetFlag(kThisHasUses, has_no_uses);
} }
bool this_has_uses() { bool this_has_uses() { return GetFlag(kThisHasUses); }
return this_has_uses_;
}
void SetStrictMode(StrictMode strict_mode) { void SetStrictMode(StrictMode strict_mode) {
DCHECK(this->strict_mode() == SLOPPY || this->strict_mode() == strict_mode); SetFlag(kStrictMode, strict_mode == STRICT);
flags_ = StrictModeField::update(flags_, strict_mode);
} }
void MarkAsNative() { void MarkAsNative() { SetFlag(kNative); }
flags_ |= IsNative::encode(true);
}
bool is_native() const { bool is_native() const { return GetFlag(kNative); }
return IsNative::decode(flags_);
}
bool is_calling() const { bool is_calling() const {
return is_deferred_calling() || is_non_deferred_calling(); return GetFlag(kDeferredCalling) || GetFlag(kNonDeferredCalling);
} }
void MarkAsDeferredCalling() { void MarkAsDeferredCalling() { SetFlag(kDeferredCalling); }
flags_ |= IsDeferredCalling::encode(true);
}
bool is_deferred_calling() const { bool is_deferred_calling() const { return GetFlag(kDeferredCalling); }
return IsDeferredCalling::decode(flags_);
}
void MarkAsNonDeferredCalling() { void MarkAsNonDeferredCalling() { SetFlag(kNonDeferredCalling); }
flags_ |= IsNonDeferredCalling::encode(true);
}
bool is_non_deferred_calling() const { bool is_non_deferred_calling() const { return GetFlag(kNonDeferredCalling); }
return IsNonDeferredCalling::decode(flags_);
}
void MarkAsSavesCallerDoubles() { void MarkAsSavesCallerDoubles() { SetFlag(kSavesCallerDoubles); }
flags_ |= SavesCallerDoubles::encode(true);
}
bool saves_caller_doubles() const { bool saves_caller_doubles() const { return GetFlag(kSavesCallerDoubles); }
return SavesCallerDoubles::decode(flags_);
}
void MarkAsRequiresFrame() { void MarkAsRequiresFrame() { SetFlag(kRequiresFrame); }
flags_ |= RequiresFrame::encode(true);
}
bool requires_frame() const { bool requires_frame() const { return GetFlag(kRequiresFrame); }
return RequiresFrame::decode(flags_);
}
void MarkMustNotHaveEagerFrame() { void MarkMustNotHaveEagerFrame() { SetFlag(kMustNotHaveEagerFrame); }
flags_ |= MustNotHaveEagerFrame::encode(true);
}
bool GetMustNotHaveEagerFrame() const { bool GetMustNotHaveEagerFrame() const {
return MustNotHaveEagerFrame::decode(flags_); return GetFlag(kMustNotHaveEagerFrame);
} }
void MarkAsDebug() { void MarkAsDebug() { SetFlag(kDebug); }
flags_ |= IsDebug::encode(true);
}
bool is_debug() const { bool is_debug() const { return GetFlag(kDebug); }
return IsDebug::decode(flags_);
}
void PrepareForSerializing() { void PrepareForSerializing() { SetFlag(kSerializing); }
flags_ |= PrepareForSerializing::encode(true);
}
bool will_serialize() const { return PrepareForSerializing::decode(flags_); } bool will_serialize() const { return GetFlag(kSerializing); }
bool IsCodePreAgingActive() const { bool IsCodePreAgingActive() const {
return FLAG_optimize_for_size && FLAG_age_code && !will_serialize() && return FLAG_optimize_for_size && FLAG_age_code && !will_serialize() &&
...@@ -196,11 +187,12 @@ class CompilationInfo { ...@@ -196,11 +187,12 @@ class CompilationInfo {
} }
void SetParseRestriction(ParseRestriction restriction) { void SetParseRestriction(ParseRestriction restriction) {
flags_ = ParseRestricitonField::update(flags_, restriction); SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION);
} }
ParseRestriction parse_restriction() const { ParseRestriction parse_restriction() const {
return ParseRestricitonField::decode(flags_); return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL
: NO_PARSE_RESTRICTION;
} }
void SetFunction(FunctionLiteral* literal) { void SetFunction(FunctionLiteral* literal) {
...@@ -234,12 +226,8 @@ class CompilationInfo { ...@@ -234,12 +226,8 @@ class CompilationInfo {
context_ = context; context_ = context;
} }
void MarkCompilingForDebugging() { void MarkCompilingForDebugging() { SetFlag(kCompilingForDebugging); }
flags_ |= IsCompilingForDebugging::encode(true); bool IsCompilingForDebugging() { return GetFlag(kCompilingForDebugging); }
}
bool IsCompilingForDebugging() {
return IsCompilingForDebugging::decode(flags_);
}
void MarkNonOptimizable() { void MarkNonOptimizable() {
SetMode(CompilationInfo::NONOPT); SetMode(CompilationInfo::NONOPT);
} }
...@@ -273,11 +261,11 @@ class CompilationInfo { ...@@ -273,11 +261,11 @@ class CompilationInfo {
// Deoptimization support. // Deoptimization support.
bool HasDeoptimizationSupport() const { bool HasDeoptimizationSupport() const {
return SupportsDeoptimization::decode(flags_); return GetFlag(kDeoptimizationSupport);
} }
void EnableDeoptimizationSupport() { void EnableDeoptimizationSupport() {
DCHECK(IsOptimizable()); DCHECK(IsOptimizable());
flags_ |= SupportsDeoptimization::encode(true); SetFlag(kDeoptimizationSupport);
} }
// Determines whether or not to insert a self-optimization header. // Determines whether or not to insert a self-optimization header.
...@@ -397,41 +385,13 @@ class CompilationInfo { ...@@ -397,41 +385,13 @@ class CompilationInfo {
mode_ = mode; mode_ = mode;
} }
// Flags using template class BitField<type, start, length>. All are void SetFlag(Flag flag) { flags_ |= flag; }
// false by default.
// void SetFlag(Flag flag, bool value) {
// Compilation is either eager or lazy. flags_ = value ? flags_ | flag : flags_ & ~flag;
class IsLazy: public BitField<bool, 0, 1> {}; }
// Flags that can be set for eager compilation.
class IsEval: public BitField<bool, 1, 1> {}; bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
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> {};
unsigned flags_; unsigned flags_;
...@@ -505,8 +465,6 @@ class CompilationInfo { ...@@ -505,8 +465,6 @@ class CompilationInfo {
// Number of parameters used for compilation of stubs that require arguments. // Number of parameters used for compilation of stubs that require arguments.
int parameter_count_; int parameter_count_;
bool this_has_uses_;
Handle<Foreign> object_wrapper_; Handle<Foreign> object_wrapper_;
int optimization_id_; int optimization_id_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment