Add tracking of loop nesting to ARM code.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4429 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
sgjesse@chromium.org 2010-04-15 14:06:57 +00:00
parent f6cce43255
commit 88fc8f1fb5
4 changed files with 29 additions and 6 deletions

View File

@ -133,6 +133,7 @@ CodeGenerator::CodeGenerator(MacroAssembler* masm)
allocator_(NULL),
cc_reg_(al),
state_(NULL),
loop_nesting_(0),
function_return_is_shadowed_(false) {
}
@ -156,6 +157,11 @@ void CodeGenerator::Generate(CompilationInfo* info) {
ASSERT(frame_ == NULL);
frame_ = new VirtualFrame();
cc_reg_ = al;
// Adjust for function-level loop nesting.
ASSERT_EQ(0, loop_nesting_);
loop_nesting_ = info->loop_nesting();
{
CodeGenState state(this);
@ -380,6 +386,10 @@ void CodeGenerator::Generate(CompilationInfo* info) {
masm_->InstructionsGeneratedSince(&check_exit_codesize));
}
// Adjust for function-level loop nesting.
ASSERT(loop_nesting_ == info->loop_nesting());
loop_nesting_ = 0;
// Code generation state must be reset.
ASSERT(!has_cc());
ASSERT(state_ == NULL);
@ -1885,6 +1895,7 @@ void CodeGenerator::VisitDoWhileStatement(DoWhileStatement* node) {
CodeForStatementPosition(node);
node->break_target()->set_direction(JumpTarget::FORWARD_ONLY);
JumpTarget body(JumpTarget::BIDIRECTIONAL);
IncrementLoopNesting();
// Label the top of the loop for the backward CFG edge. If the test
// is always true we can use the continue target, and if the test is
@ -1945,6 +1956,7 @@ void CodeGenerator::VisitDoWhileStatement(DoWhileStatement* node) {
if (node->break_target()->is_linked()) {
node->break_target()->Bind();
}
DecrementLoopNesting();
ASSERT(!has_valid_frame() || frame_->height() == original_height);
}
@ -1963,6 +1975,7 @@ void CodeGenerator::VisitWhileStatement(WhileStatement* node) {
if (info == ALWAYS_FALSE) return;
node->break_target()->set_direction(JumpTarget::FORWARD_ONLY);
IncrementLoopNesting();
// Label the top of the loop with the continue target for the backward
// CFG edge.
@ -1994,6 +2007,7 @@ void CodeGenerator::VisitWhileStatement(WhileStatement* node) {
if (node->break_target()->is_linked()) {
node->break_target()->Bind();
}
DecrementLoopNesting();
ASSERT(!has_valid_frame() || frame_->height() == original_height);
}
@ -2015,6 +2029,7 @@ void CodeGenerator::VisitForStatement(ForStatement* node) {
if (info == ALWAYS_FALSE) return;
node->break_target()->set_direction(JumpTarget::FORWARD_ONLY);
IncrementLoopNesting();
// If there is no update statement, label the top of the loop with the
// continue target, otherwise with the loop target.
@ -2069,6 +2084,7 @@ void CodeGenerator::VisitForStatement(ForStatement* node) {
if (node->break_target()->is_linked()) {
node->break_target()->Bind();
}
DecrementLoopNesting();
ASSERT(!has_valid_frame() || frame_->height() == original_height);
}

View File

@ -215,8 +215,10 @@ class CodeGenerator: public AstVisitor {
JumpTarget* true_target() const { return state_->true_target(); }
JumpTarget* false_target() const { return state_->false_target(); }
// We don't track loop nesting level on ARM yet.
int loop_nesting() const { return 0; }
// Track loop nesting level.
int loop_nesting() const { return loop_nesting_; }
void IncrementLoopNesting() { loop_nesting_++; }
void DecrementLoopNesting() { loop_nesting_--; }
// Node visitors.
void VisitStatements(ZoneList<Statement*>* statements);
@ -284,6 +286,7 @@ class CodeGenerator: public AstVisitor {
void LoadFromSlot(Slot* slot, TypeofState typeof_state);
// Store the value on top of the stack to a slot.
void StoreToSlot(Slot* slot, InitState init_state);
// Load a keyed property, leaving it in r0. The receiver and key are
// passed on the stack, and remain there.
void EmitKeyedLoad(bool is_global);
@ -458,6 +461,7 @@ class CodeGenerator: public AstVisitor {
RegisterAllocator* allocator_;
Condition cc_reg_;
CodeGenState* state_;
int loop_nesting_;
// Jump targets
BreakTarget function_return_;

View File

@ -140,7 +140,8 @@ void CodeGenerator::Generate(CompilationInfo* info) {
set_in_spilled_code(false);
// Adjust for function-level loop nesting.
loop_nesting_ += info->loop_nesting();
ASSERT_EQ(0, loop_nesting_);
loop_nesting_ = info->loop_nesting();
JumpTarget::set_compiling_deferred_code(false);
@ -333,7 +334,8 @@ void CodeGenerator::Generate(CompilationInfo* info) {
}
// Adjust for function-level loop nesting.
loop_nesting_ -= info->loop_nesting();
ASSERT_EQ(info->loop_nesting(), loop_nesting_);
loop_nesting_ = 0;
// Code generation state must be reset.
ASSERT(state_ == NULL);

View File

@ -290,6 +290,7 @@ void CodeGenerator::Generate(CompilationInfo* info) {
set_in_spilled_code(false);
// Adjust for function-level loop nesting.
ASSERT_EQ(0, loop_nesting_);
loop_nesting_ += info->loop_nesting();
JumpTarget::set_compiling_deferred_code(false);
@ -483,11 +484,11 @@ void CodeGenerator::Generate(CompilationInfo* info) {
}
// Adjust for function-level loop nesting.
loop_nesting_ -= info->loop_nesting();
ASSERT_EQ(loop_nesting_, info->loop_nesting());
loop_nesting_ = 0;
// Code generation state must be reset.
ASSERT(state_ == NULL);
ASSERT(loop_nesting() == 0);
ASSERT(!function_return_is_shadowed_);
function_return_.Unuse();
DeleteFrame();