Commit 2716660d authored by lrn@chromium.org's avatar lrn@chromium.org

X64: Add smi-type to loop variable of simple smi for-loops.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4396 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 285d5bc4
...@@ -1494,6 +1494,26 @@ void CodeGenerator::VisitWhileStatement(WhileStatement* node) { ...@@ -1494,6 +1494,26 @@ void CodeGenerator::VisitWhileStatement(WhileStatement* node) {
} }
void CodeGenerator::SetTypeForStackSlot(Slot* slot, TypeInfo info) {
ASSERT(slot->type() == Slot::LOCAL || slot->type() == Slot::PARAMETER);
if (slot->type() == Slot::LOCAL) {
frame_->SetTypeForLocalAt(slot->index(), info);
} else {
frame_->SetTypeForParamAt(slot->index(), info);
}
if (FLAG_debug_code && info.IsSmi()) {
if (slot->type() == Slot::LOCAL) {
frame_->PushLocalAt(slot->index());
} else {
frame_->PushParameterAt(slot->index());
}
Result var = frame_->Pop();
var.ToRegister();
__ AbortIfNotSmi(var.reg(), "Non-smi value in smi-typed stack slot.");
}
}
void CodeGenerator::VisitForStatement(ForStatement* node) { void CodeGenerator::VisitForStatement(ForStatement* node) {
ASSERT(!in_spilled_code()); ASSERT(!in_spilled_code());
Comment cmnt(masm_, "[ ForStatement"); Comment cmnt(masm_, "[ ForStatement");
...@@ -1587,6 +1607,17 @@ void CodeGenerator::VisitForStatement(ForStatement* node) { ...@@ -1587,6 +1607,17 @@ void CodeGenerator::VisitForStatement(ForStatement* node) {
} }
CheckStack(); // TODO(1222600): ignore if body contains calls. CheckStack(); // TODO(1222600): ignore if body contains calls.
// We know that the loop index is a smi if it is not modified in the
// loop body and it is checked against a constant limit in the loop
// condition. In this case, we reset the static type information of the
// loop index to smi before compiling the body, the update expression, and
// the bottom check of the loop condition.
if (node->is_fast_smi_loop()) {
// Set number type of the loop variable to smi.
SetTypeForStackSlot(node->loop_variable()->slot(), TypeInfo::Smi());
}
Visit(node->body()); Visit(node->body());
// If there is an update expression, compile it if necessary. // If there is an update expression, compile it if necessary.
...@@ -1606,6 +1637,13 @@ void CodeGenerator::VisitForStatement(ForStatement* node) { ...@@ -1606,6 +1637,13 @@ void CodeGenerator::VisitForStatement(ForStatement* node) {
} }
} }
// Set the type of the loop variable to smi before compiling the test
// expression if we are in a fast smi loop condition.
if (node->is_fast_smi_loop() && has_valid_frame()) {
// Set number type of the loop variable to smi.
SetTypeForStackSlot(node->loop_variable()->slot(), TypeInfo::Smi());
}
// Based on the condition analysis, compile the backward jump as // Based on the condition analysis, compile the backward jump as
// necessary. // necessary.
switch (info) { switch (info) {
......
...@@ -613,6 +613,8 @@ class CodeGenerator: public AstVisitor { ...@@ -613,6 +613,8 @@ class CodeGenerator: public AstVisitor {
void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
void CodeForSourcePosition(int pos); void CodeForSourcePosition(int pos);
void SetTypeForStackSlot(Slot* slot, TypeInfo info);
#ifdef DEBUG #ifdef DEBUG
// True if the registers are valid for entry to a block. There should // True if the registers are valid for entry to a block. There should
// be no frame-external references to (non-reserved) registers. // be no frame-external references to (non-reserved) registers.
......
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