From: kmillikin@chromium.org Date: Thu, 15 Oct 2009 16:42:22 +0000 (+0000) Subject: Added first support for tracking locations of expressions in the X-Git-Tag: upstream/4.7.83~23137 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=339e49c0b2637400f893e7e6d1dca1908133e8ca;p=platform%2Fupstream%2Fv8.git Added first support for tracking locations of expressions in the fast-mode code generator. AST expression nodes are annotated with a location when doing the initial syntactic check of the AST. In the current implementation, expression locations are 'temporary' (ie, allocated to the stack) or 'nowhere' (ie, the expression's value is not needed though it must be evaluated for side effects). For the assignment '.result = true' on IA32, we had before (with the true value already on top of the stack): 32 mov eax,[esp] 35 mov [ebp+0xf4],eax 38 pop eax Now: 32 pop [ebp+0xf4] ======== On x64, before: 37 movq rax,[rsp] 41 movq [rbp-0x18],rax 45 pop rax Now: 37 pop [rbp-0x18] ======== On ARM, before (with the true value in register ip): 36 str ip, [sp, #-4]! 40 ldr ip, [sp, #+0] 44 str ip, [fp, #-12] 48 add sp, sp, #4 Now: 36 str ip, [fp, #-12] Review URL: http://codereview.chromium.org/267118 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3076 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/arm/fast-codegen-arm.cc b/src/arm/fast-codegen-arm.cc index e358711..4f897b9 100644 --- a/src/arm/fast-codegen-arm.cc +++ b/src/arm/fast-codegen-arm.cc @@ -108,7 +108,6 @@ void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { Comment cmnt(masm_, "[ ExpressionStatement"); SetStatementPosition(stmt); Visit(stmt->expression()); - __ pop(); } @@ -128,15 +127,23 @@ void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { void FastCodeGenerator::VisitSlot(Slot* expr) { Comment cmnt(masm_, "[ Slot"); - __ ldr(ip, MemOperand(fp, SlotOffset(expr))); - __ push(ip); + if (expr->location().is_temporary()) { + __ ldr(ip, MemOperand(fp, SlotOffset(expr))); + __ push(ip); + } else { + ASSERT(expr->location().is_nowhere()); + } } void FastCodeGenerator::VisitLiteral(Literal* expr) { Comment cmnt(masm_, "[ Literal"); - __ mov(ip, Operand(expr->handle())); - __ push(ip); + if (expr->location().is_temporary()) { + __ mov(ip, Operand(expr->handle())); + __ push(ip); + } else { + ASSERT(expr->location().is_nowhere()); + } } @@ -148,7 +155,13 @@ void FastCodeGenerator::VisitAssignment(Assignment* expr) { Variable* var = expr->target()->AsVariableProxy()->AsVariable(); ASSERT(var != NULL && var->slot() != NULL); - __ ldr(ip, MemOperand(sp)); + + if (expr->location().is_temporary()) { + __ ldr(ip, MemOperand(sp)); + } else { + ASSERT(expr->location().is_nowhere()); + __ pop(ip); + } __ str(ip, MemOperand(fp, SlotOffset(var->slot()))); } diff --git a/src/ast.h b/src/ast.h index 4222216..42154f6 100644 --- a/src/ast.h +++ b/src/ast.h @@ -28,6 +28,7 @@ #ifndef V8_AST_H_ #define V8_AST_H_ +#include "location.h" #include "execution.h" #include "factory.h" #include "jsregexp.h" @@ -161,6 +162,8 @@ class Statement: public AstNode { class Expression: public AstNode { public: + Expression() : location_(Location::Temporary()) {} + virtual Expression* AsExpression() { return this; } virtual bool IsValidJSON() { return false; } @@ -174,8 +177,12 @@ class Expression: public AstNode { // Static type information for this expression. SmiAnalysis* type() { return &type_; } + Location location() { return location_; } + void set_location(Location loc) { location_ = loc; } + private: SmiAnalysis type_; + Location location_; }; diff --git a/src/compiler.cc b/src/compiler.cc index 2fc41de..2e55683 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -499,7 +499,10 @@ void CodeGenSelector::VisitBlock(Block* stmt) { void CodeGenSelector::VisitExpressionStatement(ExpressionStatement* stmt) { - Visit(stmt->expression()); + Expression* expr = stmt->expression(); + Visit(expr); + CHECK_BAILOUT; + expr->set_location(Location::Nowhere()); } diff --git a/src/fast-codegen.cc b/src/fast-codegen.cc index e4a407d..169520c 100644 --- a/src/fast-codegen.cc +++ b/src/fast-codegen.cc @@ -194,6 +194,9 @@ void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { Comment cmnt(masm_, "[ VariableProxy"); Expression* rewrite = expr->var()->rewrite(); ASSERT(rewrite != NULL); + + // Forward to the proxy's rewrite. + rewrite->set_location(expr->location()); Visit(rewrite); } diff --git a/src/ia32/fast-codegen-ia32.cc b/src/ia32/fast-codegen-ia32.cc index 2b612a5..c84173b 100644 --- a/src/ia32/fast-codegen-ia32.cc +++ b/src/ia32/fast-codegen-ia32.cc @@ -98,7 +98,6 @@ void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { Comment cmnt(masm_, "[ ExpressionStatement"); SetStatementPosition(stmt); Visit(stmt->expression()); - __ pop(eax); } @@ -118,13 +117,21 @@ void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { void FastCodeGenerator::VisitSlot(Slot* expr) { Comment cmnt(masm_, "[ Slot"); - __ push(Operand(ebp, SlotOffset(expr))); + if (expr->location().is_temporary()) { + __ push(Operand(ebp, SlotOffset(expr))); + } else { + ASSERT(expr->location().is_nowhere()); + } } void FastCodeGenerator::VisitLiteral(Literal* expr) { Comment cmnt(masm_, "[ Literal"); - __ push(Immediate(expr->handle())); + if (expr->location().is_temporary()) { + __ push(Immediate(expr->handle())); + } else { + ASSERT(expr->location().is_nowhere()); + } } @@ -135,8 +142,14 @@ void FastCodeGenerator::VisitAssignment(Assignment* expr) { Variable* var = expr->target()->AsVariableProxy()->AsVariable(); ASSERT(var != NULL && var->slot() != NULL); - __ mov(eax, Operand(esp, 0)); - __ mov(Operand(ebp, SlotOffset(var->slot())), eax); + + if (expr->location().is_temporary()) { + __ mov(eax, Operand(esp, 0)); + __ mov(Operand(ebp, SlotOffset(var->slot())), eax); + } else { + ASSERT(expr->location().is_nowhere()); + __ pop(Operand(ebp, SlotOffset(var->slot()))); + } } diff --git a/src/location.h b/src/location.h new file mode 100644 index 0000000..59cd88a --- /dev/null +++ b/src/location.h @@ -0,0 +1,56 @@ +// Copyright 2009 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef V8_LOCATION_H_ +#define V8_LOCATION_H_ + +#include "utils.h" + +namespace v8 { +namespace internal { + +class Location BASE_EMBEDDED { + public: + static Location Temporary() { return Location(TEMP); } + static Location Nowhere() { return Location(NOWHERE); } + static Location Constant() { return Location(CONSTANT); } + + bool is_temporary() { return type_ == TEMP; } + bool is_nowhere() { return type_ == NOWHERE; } + + private: + enum Type { TEMP, NOWHERE, CONSTANT }; + + explicit Location(Type type) : type_(type) {} + + Type type_; +}; + + +} } // namespace v8::internal + +#endif // V8_LOCATION_H_ diff --git a/src/x64/fast-codegen-x64.cc b/src/x64/fast-codegen-x64.cc index dcf826e..53de859 100644 --- a/src/x64/fast-codegen-x64.cc +++ b/src/x64/fast-codegen-x64.cc @@ -106,7 +106,6 @@ void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { Comment cmnt(masm_, "[ ExpressionStatement"); SetStatementPosition(stmt); Visit(stmt->expression()); - __ pop(rax); } @@ -135,13 +134,21 @@ void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { void FastCodeGenerator::VisitSlot(Slot* expr) { Comment cmnt(masm_, "[ Slot"); - __ push(Operand(rbp, SlotOffset(expr))); + if (expr->location().is_temporary()) { + __ push(Operand(rbp, SlotOffset(expr))); + } else { + ASSERT(expr->location().is_nowhere()); + } } void FastCodeGenerator::VisitLiteral(Literal* expr) { Comment cmnt(masm_, "[ Literal"); - __ Push(expr->handle()); + if (expr->location().is_temporary()) { + __ Push(expr->handle()); + } else { + ASSERT(expr->location().is_nowhere()); + } } @@ -153,8 +160,14 @@ void FastCodeGenerator::VisitAssignment(Assignment* expr) { Variable* var = expr->target()->AsVariableProxy()->AsVariable(); ASSERT(var != NULL && var->slot() != NULL); - __ movq(rax, Operand(rsp, 0)); - __ movq(Operand(rbp, SlotOffset(var->slot())), rax); + + if (expr->location().is_temporary()) { + __ movq(rax, Operand(rsp, 0)); + __ movq(Operand(rbp, SlotOffset(var->slot())), rax); + } else { + ASSERT(expr->location().is_nowhere()); + __ pop(Operand(rbp, SlotOffset(var->slot()))); + } } diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 4114fcf..5e2bb88 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -293,11 +293,12 @@ '../../src/jsregexp.h', '../../src/list-inl.h', '../../src/list.h', - '../../src/log.cc', + '../../src/location.h', '../../src/log-inl.h', - '../../src/log.h', '../../src/log-utils.cc', '../../src/log-utils.h', + '../../src/log.cc', + '../../src/log.h', '../../src/macro-assembler.h', '../../src/mark-compact.cc', '../../src/mark-compact.h', diff --git a/tools/visual_studio/v8_base.vcproj b/tools/visual_studio/v8_base.vcproj index 6b47359..fc7402a 100644 --- a/tools/visual_studio/v8_base.vcproj +++ b/tools/visual_studio/v8_base.vcproj @@ -557,6 +557,10 @@ > + + diff --git a/tools/visual_studio/v8_base_arm.vcproj b/tools/visual_studio/v8_base_arm.vcproj index afb4f74..fca4a96 100644 --- a/tools/visual_studio/v8_base_arm.vcproj +++ b/tools/visual_studio/v8_base_arm.vcproj @@ -561,6 +561,10 @@ > + +