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
Comment cmnt(masm_, "[ ExpressionStatement");
SetStatementPosition(stmt);
Visit(stmt->expression());
- __ pop();
}
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());
+ }
}
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())));
}
#ifndef V8_AST_H_
#define V8_AST_H_
+#include "location.h"
#include "execution.h"
#include "factory.h"
#include "jsregexp.h"
class Expression: public AstNode {
public:
+ Expression() : location_(Location::Temporary()) {}
+
virtual Expression* AsExpression() { return this; }
virtual bool IsValidJSON() { return false; }
// 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_;
};
void CodeGenSelector::VisitExpressionStatement(ExpressionStatement* stmt) {
- Visit(stmt->expression());
+ Expression* expr = stmt->expression();
+ Visit(expr);
+ CHECK_BAILOUT;
+ expr->set_location(Location::Nowhere());
}
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);
}
Comment cmnt(masm_, "[ ExpressionStatement");
SetStatementPosition(stmt);
Visit(stmt->expression());
- __ pop(eax);
}
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());
+ }
}
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())));
+ }
}
--- /dev/null
+// 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_
Comment cmnt(masm_, "[ ExpressionStatement");
SetStatementPosition(stmt);
Visit(stmt->expression());
- __ pop(rax);
}
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());
+ }
}
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())));
+ }
}
'../../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',
>
</File>
<File
+ RelativePath="..\..\src\location.h"
+ >
+ </File>
+ <File
RelativePath="..\..\src\log.cc"
>
</File>
>
</File>
<File
+ RelativePath="..\..\src\location.h"
+ >
+ </File>
+ <File
RelativePath="..\..\src\log.cc"
>
</File>