Recommit "First step in letting Crankshaft inline functions with a different context.""

This reverts r7810, thus recommitting 7807.

BUG=
TEST=

Review URL: http://codereview.chromium.org/6963009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7851 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
whesse@chromium.org 2011-05-11 11:03:12 +00:00
parent 79e76dbd34
commit bf06fbdbf1
6 changed files with 89 additions and 83 deletions

View File

@ -1015,6 +1015,8 @@ LEnvironment* LChunkBuilder::CreateEnvironment(HEnvironment* hydrogen_env) {
outer); outer);
int argument_index = 0; int argument_index = 0;
for (int i = 0; i < value_count; ++i) { for (int i = 0; i < value_count; ++i) {
if (hydrogen_env->is_special_index(i)) continue;
HValue* value = hydrogen_env->values()->at(i); HValue* value = hydrogen_env->values()->at(i);
LOperand* op = NULL; LOperand* op = NULL;
if (value->IsArgumentsObject()) { if (value->IsArgumentsObject()) {

View File

@ -3326,7 +3326,7 @@ class HLoadKeyedSpecializedArrayElement: public HBinaryOperation {
class HLoadKeyedGeneric: public HTemplateInstruction<3> { class HLoadKeyedGeneric: public HTemplateInstruction<3> {
public: public:
HLoadKeyedGeneric(HContext* context, HValue* obj, HValue* key) { HLoadKeyedGeneric(HValue* context, HValue* obj, HValue* key) {
set_representation(Representation::Tagged()); set_representation(Representation::Tagged());
SetOperandAt(0, obj); SetOperandAt(0, obj);
SetOperandAt(1, key); SetOperandAt(1, key);

View File

@ -2229,14 +2229,21 @@ void HGraphBuilder::SetupScope(Scope* scope) {
// Set the initial values of parameters including "this". "This" has // Set the initial values of parameters including "this". "This" has
// parameter index 0. // parameter index 0.
int count = scope->num_parameters() + 1; ASSERT_EQ(scope->num_parameters() + 1, environment()->parameter_count());
for (int i = 0; i < count; ++i) {
for (int i = 0; i < environment()->parameter_count(); ++i) {
HInstruction* parameter = AddInstruction(new(zone()) HParameter(i)); HInstruction* parameter = AddInstruction(new(zone()) HParameter(i));
environment()->Bind(i, parameter); environment()->Bind(i, parameter);
} }
// Set the initial values of stack-allocated locals. // First special is HContext.
for (int i = count; i < environment()->length(); ++i) { HInstruction* context = AddInstruction(new(zone()) HContext);
environment()->BindContext(context);
// Initialize specials and locals to undefined.
for (int i = environment()->parameter_count() + 1;
i < environment()->length();
++i) {
environment()->Bind(i, undefined_constant); environment()->Bind(i, undefined_constant);
} }
@ -2593,17 +2600,18 @@ void HGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) {
int osr_entry_id = statement->OsrEntryId(); int osr_entry_id = statement->OsrEntryId();
// We want the correct environment at the OsrEntry instruction. Build // We want the correct environment at the OsrEntry instruction. Build
// it explicitly. The expression stack should be empty. // it explicitly. The expression stack should be empty.
int count = environment()->length(); ASSERT(environment()->ExpressionStackIsEmpty());
ASSERT(count == for (int i = 0; i < environment()->length(); ++i) {
(environment()->parameter_count() + environment()->local_count())); HUnknownOSRValue* osr_value = new(zone()) HUnknownOSRValue;
for (int i = 0; i < count; ++i) { AddInstruction(osr_value);
HUnknownOSRValue* unknown = new(zone()) HUnknownOSRValue; environment()->Bind(i, osr_value);
AddInstruction(unknown);
environment()->Bind(i, unknown);
} }
AddSimulate(osr_entry_id); AddSimulate(osr_entry_id);
AddInstruction(new(zone()) HOsrEntry(osr_entry_id)); AddInstruction(new(zone()) HOsrEntry(osr_entry_id));
HContext* context = new(zone()) HContext;
AddInstruction(context);
environment()->BindContext(context);
current_block()->Goto(loop_predecessor); current_block()->Goto(loop_predecessor);
loop_predecessor->SetJoinId(statement->EntryId()); loop_predecessor->SetJoinId(statement->EntryId());
set_current_block(loop_predecessor); set_current_block(loop_predecessor);
@ -2886,12 +2894,12 @@ HGraphBuilder::GlobalPropertyAccess HGraphBuilder::LookupGlobalProperty(
HValue* HGraphBuilder::BuildContextChainWalk(Variable* var) { HValue* HGraphBuilder::BuildContextChainWalk(Variable* var) {
ASSERT(var->IsContextSlot()); ASSERT(var->IsContextSlot());
HInstruction* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
int length = info()->scope()->ContextChainLength(var->scope()); int length = info()->scope()->ContextChainLength(var->scope());
while (length-- > 0) { while (length-- > 0) {
context = new(zone()) HOuterContext(context); HInstruction* context_instruction = new(zone()) HOuterContext(context);
AddInstruction(context); AddInstruction(context_instruction);
context = context_instruction;
} }
return context; return context;
} }
@ -2930,8 +2938,7 @@ void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) {
HLoadGlobalCell* instr = new(zone()) HLoadGlobalCell(cell, check_hole); HLoadGlobalCell* instr = new(zone()) HLoadGlobalCell(cell, check_hole);
ast_context()->ReturnInstruction(instr, expr->id()); ast_context()->ReturnInstruction(instr, expr->id());
} else { } else {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HGlobalObject* global_object = new(zone()) HGlobalObject(context); HGlobalObject* global_object = new(zone()) HGlobalObject(context);
AddInstruction(global_object); AddInstruction(global_object);
HLoadGlobalGeneric* instr = HLoadGlobalGeneric* instr =
@ -2974,8 +2981,7 @@ void HGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
ASSERT(!HasStackOverflow()); ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL); ASSERT(current_block() != NULL);
ASSERT(current_block()->HasPredecessor()); ASSERT(current_block()->HasPredecessor());
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HObjectLiteral* literal = HObjectLiteral* literal =
new(zone()) HObjectLiteral(context, new(zone()) HObjectLiteral(context,
expr->constant_properties(), expr->constant_properties(),
@ -3157,8 +3163,7 @@ HInstruction* HGraphBuilder::BuildStoreNamedField(HValue* object,
HInstruction* HGraphBuilder::BuildStoreNamedGeneric(HValue* object, HInstruction* HGraphBuilder::BuildStoreNamedGeneric(HValue* object,
Handle<String> name, Handle<String> name,
HValue* value) { HValue* value) {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
return new(zone()) HStoreNamedGeneric( return new(zone()) HStoreNamedGeneric(
context, context,
object, object,
@ -3334,8 +3339,7 @@ void HGraphBuilder::HandleGlobalVariableAssignment(Variable* var,
AddInstruction(instr); AddInstruction(instr);
if (instr->HasSideEffects()) AddSimulate(ast_id); if (instr->HasSideEffects()) AddSimulate(ast_id);
} else { } else {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HGlobalObject* global_object = new(zone()) HGlobalObject(context); HGlobalObject* global_object = new(zone()) HGlobalObject(context);
AddInstruction(global_object); AddInstruction(global_object);
HStoreGlobalGeneric* instr = HStoreGlobalGeneric* instr =
@ -3560,8 +3564,7 @@ HInstruction* HGraphBuilder::BuildLoadNamedGeneric(HValue* obj,
Property* expr) { Property* expr) {
ASSERT(expr->key()->IsPropertyName()); ASSERT(expr->key()->IsPropertyName());
Handle<Object> name = expr->key()->AsLiteral()->handle(); Handle<Object> name = expr->key()->AsLiteral()->handle();
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
return new(zone()) HLoadNamedGeneric(context, obj, name); return new(zone()) HLoadNamedGeneric(context, obj, name);
} }
@ -3591,8 +3594,7 @@ HInstruction* HGraphBuilder::BuildLoadNamed(HValue* obj,
HInstruction* HGraphBuilder::BuildLoadKeyedGeneric(HValue* object, HInstruction* HGraphBuilder::BuildLoadKeyedGeneric(HValue* object,
HValue* key) { HValue* key) {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
return new(zone()) HLoadKeyedGeneric(context, object, key); return new(zone()) HLoadKeyedGeneric(context, object, key);
} }
@ -3667,8 +3669,7 @@ HInstruction* HGraphBuilder::BuildLoadKeyed(HValue* obj,
HInstruction* HGraphBuilder::BuildStoreKeyedGeneric(HValue* object, HInstruction* HGraphBuilder::BuildStoreKeyedGeneric(HValue* object,
HValue* key, HValue* key,
HValue* value) { HValue* value) {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
return new(zone()) HStoreKeyedGeneric( return new(zone()) HStoreKeyedGeneric(
context, context,
object, object,
@ -3917,8 +3918,7 @@ void HGraphBuilder::HandlePolymorphicCallNamed(Call* expr,
if (count == types->length() && FLAG_deoptimize_uncommon_cases) { if (count == types->length() && FLAG_deoptimize_uncommon_cases) {
current_block()->FinishExitWithDeoptimization(); current_block()->FinishExitWithDeoptimization();
} else { } else {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallNamed* call = new(zone()) HCallNamed(context, name, argument_count); HCallNamed* call = new(zone()) HCallNamed(context, name, argument_count);
call->set_position(expr->position()); call->set_position(expr->position());
PreProcessCall(call); PreProcessCall(call);
@ -4345,8 +4345,7 @@ void HGraphBuilder::VisitCall(Call* expr) {
CHECK_ALIVE(VisitExpressions(expr->arguments())); CHECK_ALIVE(VisitExpressions(expr->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
call = PreProcessCall( call = PreProcessCall(
new(zone()) HCallKeyed(context, key, argument_count)); new(zone()) HCallKeyed(context, key, argument_count));
call->set_position(expr->position()); call->set_position(expr->position());
@ -4385,8 +4384,7 @@ void HGraphBuilder::VisitCall(Call* expr) {
// When the target has a custom call IC generator, use the IC, // When the target has a custom call IC generator, use the IC,
// because it is likely to generate better code. Also use the IC // because it is likely to generate better code. Also use the IC
// when a primitive receiver check is required. // when a primitive receiver check is required.
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
call = PreProcessCall( call = PreProcessCall(
new(zone()) HCallNamed(context, name, argument_count)); new(zone()) HCallNamed(context, name, argument_count));
} else { } else {
@ -4403,8 +4401,7 @@ void HGraphBuilder::VisitCall(Call* expr) {
return; return;
} else { } else {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
call = PreProcessCall( call = PreProcessCall(
new(zone()) HCallNamed(context, name, argument_count)); new(zone()) HCallNamed(context, name, argument_count));
} }
@ -4433,9 +4430,8 @@ void HGraphBuilder::VisitCall(Call* expr) {
if (known_global_function) { if (known_global_function) {
// Push the global object instead of the global receiver because // Push the global object instead of the global receiver because
// code generated by the full code generator expects it. // code generated by the full code generator expects it.
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
HGlobalObject* global_object = new(zone()) HGlobalObject(context); HGlobalObject* global_object = new(zone()) HGlobalObject(context);
AddInstruction(context);
PushAndAdd(global_object); PushAndAdd(global_object);
CHECK_ALIVE(VisitExpressions(expr->arguments())); CHECK_ALIVE(VisitExpressions(expr->arguments()));
@ -4457,8 +4453,7 @@ void HGraphBuilder::VisitCall(Call* expr) {
call = PreProcessCall(new(zone()) HCallKnownGlobal(expr->target(), call = PreProcessCall(new(zone()) HCallKnownGlobal(expr->target(),
argument_count)); argument_count));
} else { } else {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
PushAndAdd(new(zone()) HGlobalObject(context)); PushAndAdd(new(zone()) HGlobalObject(context));
CHECK_ALIVE(VisitExpressions(expr->arguments())); CHECK_ALIVE(VisitExpressions(expr->arguments()));
@ -4468,9 +4463,8 @@ void HGraphBuilder::VisitCall(Call* expr) {
} }
} else { } else {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
HGlobalObject* global_object = new(zone()) HGlobalObject(context); HGlobalObject* global_object = new(zone()) HGlobalObject(context);
AddInstruction(context);
AddInstruction(global_object); AddInstruction(global_object);
PushAndAdd(new(zone()) HGlobalReceiver(global_object)); PushAndAdd(new(zone()) HGlobalReceiver(global_object));
CHECK_ALIVE(VisitExpressions(expr->arguments())); CHECK_ALIVE(VisitExpressions(expr->arguments()));
@ -4493,8 +4487,7 @@ void HGraphBuilder::VisitCallNew(CallNew* expr) {
CHECK_ALIVE(VisitForValue(expr->expression())); CHECK_ALIVE(VisitForValue(expr->expression()));
CHECK_ALIVE(VisitExpressions(expr->arguments())); CHECK_ALIVE(VisitExpressions(expr->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
// The constructor is both an operand to the instruction and an argument // The constructor is both an operand to the instruction and an argument
// to the construct call. // to the construct call.
@ -5137,8 +5130,7 @@ void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
// If the target is not null we have found a known global function that is // If the target is not null we have found a known global function that is
// assumed to stay the same for this instanceof. // assumed to stay the same for this instanceof.
if (target.is_null()) { if (target.is_null()) {
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
instr = new(zone()) HInstanceOf(context, left, right); instr = new(zone()) HInstanceOf(context, left, right);
} else { } else {
AddInstruction(new(zone()) HCheckFunction(right, target)); AddInstruction(new(zone()) HCheckFunction(right, target));
@ -5414,8 +5406,7 @@ void HGraphBuilder::GenerateRandomHeapNumber(CallRuntime* call) {
void HGraphBuilder::GenerateStringAdd(CallRuntime* call) { void HGraphBuilder::GenerateStringAdd(CallRuntime* call) {
ASSERT_EQ(2, call->arguments()->length()); ASSERT_EQ(2, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = new(zone()) HCallStub(context, CodeStub::StringAdd, 2); HCallStub* result = new(zone()) HCallStub(context, CodeStub::StringAdd, 2);
Drop(2); Drop(2);
ast_context()->ReturnInstruction(result, call->id()); ast_context()->ReturnInstruction(result, call->id());
@ -5426,8 +5417,7 @@ void HGraphBuilder::GenerateStringAdd(CallRuntime* call) {
void HGraphBuilder::GenerateSubString(CallRuntime* call) { void HGraphBuilder::GenerateSubString(CallRuntime* call) {
ASSERT_EQ(3, call->arguments()->length()); ASSERT_EQ(3, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = new(zone()) HCallStub(context, CodeStub::SubString, 3); HCallStub* result = new(zone()) HCallStub(context, CodeStub::SubString, 3);
Drop(3); Drop(3);
ast_context()->ReturnInstruction(result, call->id()); ast_context()->ReturnInstruction(result, call->id());
@ -5438,8 +5428,7 @@ void HGraphBuilder::GenerateSubString(CallRuntime* call) {
void HGraphBuilder::GenerateStringCompare(CallRuntime* call) { void HGraphBuilder::GenerateStringCompare(CallRuntime* call) {
ASSERT_EQ(2, call->arguments()->length()); ASSERT_EQ(2, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = HCallStub* result =
new(zone()) HCallStub(context, CodeStub::StringCompare, 2); new(zone()) HCallStub(context, CodeStub::StringCompare, 2);
Drop(2); Drop(2);
@ -5451,8 +5440,7 @@ void HGraphBuilder::GenerateStringCompare(CallRuntime* call) {
void HGraphBuilder::GenerateRegExpExec(CallRuntime* call) { void HGraphBuilder::GenerateRegExpExec(CallRuntime* call) {
ASSERT_EQ(4, call->arguments()->length()); ASSERT_EQ(4, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = new(zone()) HCallStub(context, CodeStub::RegExpExec, 4); HCallStub* result = new(zone()) HCallStub(context, CodeStub::RegExpExec, 4);
Drop(4); Drop(4);
ast_context()->ReturnInstruction(result, call->id()); ast_context()->ReturnInstruction(result, call->id());
@ -5463,8 +5451,7 @@ void HGraphBuilder::GenerateRegExpExec(CallRuntime* call) {
void HGraphBuilder::GenerateRegExpConstructResult(CallRuntime* call) { void HGraphBuilder::GenerateRegExpConstructResult(CallRuntime* call) {
ASSERT_EQ(3, call->arguments()->length()); ASSERT_EQ(3, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = HCallStub* result =
new(zone()) HCallStub(context, CodeStub::RegExpConstructResult, 3); new(zone()) HCallStub(context, CodeStub::RegExpConstructResult, 3);
Drop(3); Drop(3);
@ -5482,8 +5469,7 @@ void HGraphBuilder::GenerateGetFromCache(CallRuntime* call) {
void HGraphBuilder::GenerateNumberToString(CallRuntime* call) { void HGraphBuilder::GenerateNumberToString(CallRuntime* call) {
ASSERT_EQ(1, call->arguments()->length()); ASSERT_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = HCallStub* result =
new(zone()) HCallStub(context, CodeStub::NumberToString, 1); new(zone()) HCallStub(context, CodeStub::NumberToString, 1);
Drop(1); Drop(1);
@ -5510,8 +5496,7 @@ void HGraphBuilder::GenerateCallFunction(CallRuntime* call) {
} }
CHECK_ALIVE(VisitForValue(call->arguments()->last())); CHECK_ALIVE(VisitForValue(call->arguments()->last()));
HValue* function = Pop(); HValue* function = Pop();
HContext* context = new HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HInvokeFunction* result = HInvokeFunction* result =
new(zone()) HInvokeFunction(context, function, arg_count); new(zone()) HInvokeFunction(context, function, arg_count);
Drop(arg_count); Drop(arg_count);
@ -5534,8 +5519,7 @@ void HGraphBuilder::GenerateMathPow(CallRuntime* call) {
void HGraphBuilder::GenerateMathSin(CallRuntime* call) { void HGraphBuilder::GenerateMathSin(CallRuntime* call) {
ASSERT_EQ(1, call->arguments()->length()); ASSERT_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = HCallStub* result =
new(zone()) HCallStub(context, CodeStub::TranscendentalCache, 1); new(zone()) HCallStub(context, CodeStub::TranscendentalCache, 1);
result->set_transcendental_type(TranscendentalCache::SIN); result->set_transcendental_type(TranscendentalCache::SIN);
@ -5547,8 +5531,7 @@ void HGraphBuilder::GenerateMathSin(CallRuntime* call) {
void HGraphBuilder::GenerateMathCos(CallRuntime* call) { void HGraphBuilder::GenerateMathCos(CallRuntime* call) {
ASSERT_EQ(1, call->arguments()->length()); ASSERT_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = HCallStub* result =
new(zone()) HCallStub(context, CodeStub::TranscendentalCache, 1); new(zone()) HCallStub(context, CodeStub::TranscendentalCache, 1);
result->set_transcendental_type(TranscendentalCache::COS); result->set_transcendental_type(TranscendentalCache::COS);
@ -5560,8 +5543,7 @@ void HGraphBuilder::GenerateMathCos(CallRuntime* call) {
void HGraphBuilder::GenerateMathLog(CallRuntime* call) { void HGraphBuilder::GenerateMathLog(CallRuntime* call) {
ASSERT_EQ(1, call->arguments()->length()); ASSERT_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitArgumentList(call->arguments())); CHECK_ALIVE(VisitArgumentList(call->arguments()));
HContext* context = new(zone()) HContext; HValue* context = environment()->LookupContext();
AddInstruction(context);
HCallStub* result = HCallStub* result =
new(zone()) HCallStub(context, CodeStub::TranscendentalCache, 1); new(zone()) HCallStub(context, CodeStub::TranscendentalCache, 1);
result->set_transcendental_type(TranscendentalCache::LOG); result->set_transcendental_type(TranscendentalCache::LOG);
@ -5606,6 +5588,7 @@ HEnvironment::HEnvironment(HEnvironment* outer,
values_(0), values_(0),
assigned_variables_(4), assigned_variables_(4),
parameter_count_(0), parameter_count_(0),
specials_count_(1),
local_count_(0), local_count_(0),
outer_(outer), outer_(outer),
pop_count_(0), pop_count_(0),
@ -5619,6 +5602,7 @@ HEnvironment::HEnvironment(const HEnvironment* other)
: values_(0), : values_(0),
assigned_variables_(0), assigned_variables_(0),
parameter_count_(0), parameter_count_(0),
specials_count_(1),
local_count_(0), local_count_(0),
outer_(NULL), outer_(NULL),
pop_count_(0), pop_count_(0),
@ -5635,7 +5619,7 @@ void HEnvironment::Initialize(int parameter_count,
local_count_ = local_count; local_count_ = local_count;
// Avoid reallocating the temporaries' backing store on the first Push. // Avoid reallocating the temporaries' backing store on the first Push.
int total = parameter_count + local_count + stack_height; int total = parameter_count + specials_count_ + local_count + stack_height;
values_.Initialize(total + 4); values_.Initialize(total + 4);
for (int i = 0; i < total; ++i) values_.Add(NULL); for (int i = 0; i < total; ++i) values_.Add(NULL);
} }
@ -5694,12 +5678,12 @@ void HEnvironment::Bind(int index, HValue* value) {
bool HEnvironment::HasExpressionAt(int index) const { bool HEnvironment::HasExpressionAt(int index) const {
return index >= parameter_count_ + local_count_; return index >= parameter_count_ + specials_count_ + local_count_;
} }
bool HEnvironment::ExpressionStackIsEmpty() const { bool HEnvironment::ExpressionStackIsEmpty() const {
int first_expression = parameter_count() + local_count(); int first_expression = parameter_count() + specials_count() + local_count();
ASSERT(length() >= first_expression); ASSERT(length() >= first_expression);
return length() == first_expression; return length() == first_expression;
} }
@ -5777,12 +5761,9 @@ HEnvironment* HEnvironment::CopyForInlining(Handle<JSFunction> target,
inner->SetValueAt(i, push); inner->SetValueAt(i, push);
} }
} }
inner->SetValueAt(arity + 1, outer->LookupContext());
// Initialize the stack-allocated locals to undefined. for (int i = arity + 2; i < inner->length(); ++i) {
int local_base = arity + 1; inner->SetValueAt(i, undefined);
int local_count = function->scope()->num_stack_slots();
for (int i = 0; i < local_count; ++i) {
inner->SetValueAt(local_base + i, undefined);
} }
inner->set_ast_id(AstNode::kFunctionEntryId); inner->set_ast_id(AstNode::kFunctionEntryId);
@ -5793,8 +5774,11 @@ HEnvironment* HEnvironment::CopyForInlining(Handle<JSFunction> target,
void HEnvironment::PrintTo(StringStream* stream) { void HEnvironment::PrintTo(StringStream* stream) {
for (int i = 0; i < length(); i++) { for (int i = 0; i < length(); i++) {
if (i == 0) stream->Add("parameters\n"); if (i == 0) stream->Add("parameters\n");
if (i == parameter_count()) stream->Add("locals\n"); if (i == parameter_count()) stream->Add("specials\n");
if (i == parameter_count() + local_count()) stream->Add("expressions"); if (i == parameter_count() + specials_count()) stream->Add("locals\n");
if (i == parameter_count() + specials_count() + local_count()) {
stream->Add("expressions");
}
HValue* val = values_.at(i); HValue* val = values_.at(i);
stream->Add("%d: ", i); stream->Add("%d: ", i);
if (val != NULL) { if (val != NULL) {

View File

@ -322,6 +322,7 @@ class HEnvironment: public ZoneObject {
return &assigned_variables_; return &assigned_variables_;
} }
int parameter_count() const { return parameter_count_; } int parameter_count() const { return parameter_count_; }
int specials_count() const { return specials_count_; }
int local_count() const { return local_count_; } int local_count() const { return local_count_; }
HEnvironment* outer() const { return outer_; } HEnvironment* outer() const { return outer_; }
int pop_count() const { return pop_count_; } int pop_count() const { return pop_count_; }
@ -331,6 +332,9 @@ class HEnvironment: public ZoneObject {
void set_ast_id(int id) { ast_id_ = id; } void set_ast_id(int id) { ast_id_ = id; }
int length() const { return values_.length(); } int length() const { return values_.length(); }
bool is_special_index(int i) const {
return i >= parameter_count() && i < parameter_count() + specials_count();
}
void Bind(Variable* variable, HValue* value) { void Bind(Variable* variable, HValue* value) {
Bind(IndexFor(variable), value); Bind(IndexFor(variable), value);
@ -338,6 +342,10 @@ class HEnvironment: public ZoneObject {
void Bind(int index, HValue* value); void Bind(int index, HValue* value);
void BindContext(HValue* value) {
Bind(parameter_count(), value);
}
HValue* Lookup(Variable* variable) const { HValue* Lookup(Variable* variable) const {
return Lookup(IndexFor(variable)); return Lookup(IndexFor(variable));
} }
@ -348,6 +356,11 @@ class HEnvironment: public ZoneObject {
return result; return result;
} }
HValue* LookupContext() const {
// Return first special.
return Lookup(parameter_count());
}
void Push(HValue* value) { void Push(HValue* value) {
ASSERT(value != NULL); ASSERT(value != NULL);
++push_count_; ++push_count_;
@ -368,6 +381,8 @@ class HEnvironment: public ZoneObject {
HValue* Top() const { return ExpressionStackAt(0); } HValue* Top() const { return ExpressionStackAt(0); }
bool ExpressionStackIsEmpty() const;
HValue* ExpressionStackAt(int index_from_top) const { HValue* ExpressionStackAt(int index_from_top) const {
int index = length() - index_from_top - 1; int index = length() - index_from_top - 1;
ASSERT(HasExpressionAt(index)); ASSERT(HasExpressionAt(index));
@ -412,8 +427,6 @@ class HEnvironment: public ZoneObject {
// True if index is included in the expression stack part of the environment. // True if index is included in the expression stack part of the environment.
bool HasExpressionAt(int index) const; bool HasExpressionAt(int index) const;
bool ExpressionStackIsEmpty() const;
void Initialize(int parameter_count, int local_count, int stack_height); void Initialize(int parameter_count, int local_count, int stack_height);
void Initialize(const HEnvironment* other); void Initialize(const HEnvironment* other);
@ -423,15 +436,18 @@ class HEnvironment: public ZoneObject {
int IndexFor(Variable* variable) const { int IndexFor(Variable* variable) const {
Slot* slot = variable->AsSlot(); Slot* slot = variable->AsSlot();
ASSERT(slot != NULL && slot->IsStackAllocated()); ASSERT(slot != NULL && slot->IsStackAllocated());
int shift = (slot->type() == Slot::PARAMETER) ? 1 : parameter_count_; int shift = (slot->type() == Slot::PARAMETER)
? 1
: parameter_count_ + specials_count_;
return slot->index() + shift; return slot->index() + shift;
} }
Handle<JSFunction> closure_; Handle<JSFunction> closure_;
// Value array [parameters] [locals] [temporaries]. // Value array [parameters] [specials] [locals] [temporaries].
ZoneList<HValue*> values_; ZoneList<HValue*> values_;
ZoneList<int> assigned_variables_; ZoneList<int> assigned_variables_;
int parameter_count_; int parameter_count_;
int specials_count_;
int local_count_; int local_count_;
HEnvironment* outer_; HEnvironment* outer_;
int pop_count_; int pop_count_;

View File

@ -1010,6 +1010,8 @@ LEnvironment* LChunkBuilder::CreateEnvironment(HEnvironment* hydrogen_env) {
outer); outer);
int argument_index = 0; int argument_index = 0;
for (int i = 0; i < value_count; ++i) { for (int i = 0; i < value_count; ++i) {
if (hydrogen_env->is_special_index(i)) continue;
HValue* value = hydrogen_env->values()->at(i); HValue* value = hydrogen_env->values()->at(i);
LOperand* op = NULL; LOperand* op = NULL;
if (value->IsArgumentsObject()) { if (value->IsArgumentsObject()) {

View File

@ -1010,6 +1010,8 @@ LEnvironment* LChunkBuilder::CreateEnvironment(HEnvironment* hydrogen_env) {
outer); outer);
int argument_index = 0; int argument_index = 0;
for (int i = 0; i < value_count; ++i) { for (int i = 0; i < value_count; ++i) {
if (hydrogen_env->is_special_index(i)) continue;
HValue* value = hydrogen_env->values()->at(i); HValue* value = hydrogen_env->values()->at(i);
LOperand* op = NULL; LOperand* op = NULL;
if (value->IsArgumentsObject()) { if (value->IsArgumentsObject()) {