Revision: 4396
Author: [email protected]
Date: Tue Apr 13 04:34:14 2010
Log: X64: Add smi-type to loop variable of simple smi for-loops.
Review URL: http://codereview.chromium.org/1642003
http://code.google.com/p/v8/source/detail?r=4396
Modified:
/branches/bleeding_edge/src/x64/codegen-x64.cc
/branches/bleeding_edge/src/x64/codegen-x64.h
=======================================
--- /branches/bleeding_edge/src/x64/codegen-x64.cc Tue Apr 13 02:31:03 2010
+++ /branches/bleeding_edge/src/x64/codegen-x64.cc Tue Apr 13 04:34:14 2010
@@ -1492,6 +1492,26 @@
}
DecrementLoopNesting();
}
+
+
+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) {
@@ -1587,6 +1607,17 @@
}
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());
// If there is an update expression, compile it if necessary.
@@ -1605,6 +1636,13 @@
Visit(node->next());
}
}
+
+ // 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
// necessary.
=======================================
--- /branches/bleeding_edge/src/x64/codegen-x64.h Tue Apr 13 02:31:03 2010
+++ /branches/bleeding_edge/src/x64/codegen-x64.h Tue Apr 13 04:34:14 2010
@@ -613,6 +613,8 @@
void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
void CodeForSourcePosition(int pos);
+ void SetTypeForStackSlot(Slot* slot, TypeInfo info);
+
#ifdef DEBUG
// True if the registers are valid for entry to a block. There should
// be no frame-external references to (non-reserved) registers.
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
To unsubscribe, reply using "remove me" as the subject.