Simplify deferred code by removing some unneeded or redundant stuff.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2065 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2e37ebe1
......@@ -289,9 +289,7 @@ void CodeGenerator::GenCode(FunctionLiteral* fun) {
DeleteFrame();
// Process any deferred code using the register allocator.
if (HasStackOverflow()) {
ClearDeferred();
} else {
if (!HasStackOverflow()) {
ProcessDeferred();
}
......@@ -757,13 +755,11 @@ void CodeGenerator::GenericBinaryOperation(Token::Value op,
class DeferredInlineSmiOperation: public DeferredCode {
public:
DeferredInlineSmiOperation(CodeGenerator* generator,
Token::Value op,
DeferredInlineSmiOperation(Token::Value op,
int value,
bool reversed,
OverwriteMode overwrite_mode)
: DeferredCode(generator),
op_(op),
: op_(op),
value_(value),
reversed_(reversed),
overwrite_mode_(overwrite_mode) {
......@@ -780,7 +776,12 @@ class DeferredInlineSmiOperation: public DeferredCode {
};
#undef __
#define __ ACCESS_MASM(masm)
void DeferredInlineSmiOperation::Generate() {
MacroAssembler* masm = cgen()->masm();
enter()->Bind();
VirtualFrame::SpilledScope spilled_scope;
......@@ -841,15 +842,19 @@ void DeferredInlineSmiOperation::Generate() {
}
GenericBinaryOpStub igostub(op_, overwrite_mode_);
Result arg0 = generator()->allocator()->Allocate(r1);
Result arg0 = cgen()->allocator()->Allocate(r1);
ASSERT(arg0.is_valid());
Result arg1 = generator()->allocator()->Allocate(r0);
Result arg1 = cgen()->allocator()->Allocate(r0);
ASSERT(arg1.is_valid());
generator()->frame()->CallStub(&igostub, &arg0, &arg1);
cgen()->frame()->CallStub(&igostub, &arg0, &arg1);
exit_.Jump();
}
#undef __
#define __ ACCESS_MASM(masm_)
void CodeGenerator::SmiOperation(Token::Value op,
Handle<Object> value,
bool reversed,
......@@ -872,7 +877,7 @@ void CodeGenerator::SmiOperation(Token::Value op,
switch (op) {
case Token::ADD: {
DeferredCode* deferred =
new DeferredInlineSmiOperation(this, op, int_value, reversed, mode);
new DeferredInlineSmiOperation(op, int_value, reversed, mode);
__ add(r0, r0, Operand(value), SetCC);
deferred->enter()->Branch(vs);
......@@ -884,7 +889,7 @@ void CodeGenerator::SmiOperation(Token::Value op,
case Token::SUB: {
DeferredCode* deferred =
new DeferredInlineSmiOperation(this, op, int_value, reversed, mode);
new DeferredInlineSmiOperation(op, int_value, reversed, mode);
if (!reversed) {
__ sub(r0, r0, Operand(value), SetCC);
......@@ -902,7 +907,7 @@ void CodeGenerator::SmiOperation(Token::Value op,
case Token::BIT_XOR:
case Token::BIT_AND: {
DeferredCode* deferred =
new DeferredInlineSmiOperation(this, op, int_value, reversed, mode);
new DeferredInlineSmiOperation(op, int_value, reversed, mode);
__ tst(r0, Operand(kSmiTagMask));
deferred->enter()->Branch(ne);
switch (op) {
......@@ -927,7 +932,7 @@ void CodeGenerator::SmiOperation(Token::Value op,
} else {
int shift_value = int_value & 0x1f; // least significant 5 bits
DeferredCode* deferred =
new DeferredInlineSmiOperation(this, op, shift_value, false, mode);
new DeferredInlineSmiOperation(op, shift_value, false, mode);
__ tst(r0, Operand(kSmiTagMask));
deferred->enter()->Branch(ne);
__ mov(r2, Operand(r0, ASR, kSmiTagSize)); // remove tags
......@@ -2654,8 +2659,7 @@ void CodeGenerator::VisitRegExpLiteral(RegExpLiteral* node) {
// therefore context dependent.
class DeferredObjectLiteral: public DeferredCode {
public:
DeferredObjectLiteral(CodeGenerator* generator, ObjectLiteral* node)
: DeferredCode(generator), node_(node) {
explicit DeferredObjectLiteral(ObjectLiteral* node) : node_(node) {
set_comment("[ DeferredObjectLiteral");
}
......@@ -2666,7 +2670,12 @@ class DeferredObjectLiteral: public DeferredCode {
};
#undef __
#define __ ACCESS_MASM(masm)
void DeferredObjectLiteral::Generate() {
MacroAssembler* masm = cgen()->masm();
// Argument is passed in r1.
enter()->Bind();
VirtualFrame::SpilledScope spilled_scope;
......@@ -2674,7 +2683,7 @@ void DeferredObjectLiteral::Generate() {
// If the entry is undefined we call the runtime system to compute
// the literal.
VirtualFrame* frame = generator()->frame();
VirtualFrame* frame = cgen()->frame();
// Literal array (0).
frame->EmitPush(r1);
// Literal index (1).
......@@ -2691,6 +2700,10 @@ void DeferredObjectLiteral::Generate() {
}
#undef __
#define __ ACCESS_MASM(masm_)
void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) {
#ifdef DEBUG
int original_height = frame_->height();
......@@ -2698,7 +2711,7 @@ void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) {
VirtualFrame::SpilledScope spilled_scope;
Comment cmnt(masm_, "[ ObjectLiteral");
DeferredObjectLiteral* deferred = new DeferredObjectLiteral(this, node);
DeferredObjectLiteral* deferred = new DeferredObjectLiteral(node);
// Retrieve the literal array and check the allocated entry.
......@@ -2783,8 +2796,7 @@ void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) {
// therefore context dependent.
class DeferredArrayLiteral: public DeferredCode {
public:
DeferredArrayLiteral(CodeGenerator* generator, ArrayLiteral* node)
: DeferredCode(generator), node_(node) {
explicit DeferredArrayLiteral(ArrayLiteral* node) : node_(node) {
set_comment("[ DeferredArrayLiteral");
}
......@@ -2795,7 +2807,12 @@ class DeferredArrayLiteral: public DeferredCode {
};
#undef __
#define __ ACCESS_MASM(masm)
void DeferredArrayLiteral::Generate() {
MacroAssembler* masm = cgen()->masm();
// Argument is passed in r1.
enter()->Bind();
VirtualFrame::SpilledScope spilled_scope;
......@@ -2803,7 +2820,7 @@ void DeferredArrayLiteral::Generate() {
// If the entry is undefined we call the runtime system to computed
// the literal.
VirtualFrame* frame = generator()->frame();
VirtualFrame* frame = cgen()->frame();
// Literal array (0).
frame->EmitPush(r1);
// Literal index (1).
......@@ -2820,6 +2837,10 @@ void DeferredArrayLiteral::Generate() {
}
#undef __
#define __ ACCESS_MASM(masm_)
void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) {
#ifdef DEBUG
int original_height = frame_->height();
......@@ -2827,7 +2848,7 @@ void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) {
VirtualFrame::SpilledScope spilled_scope;
Comment cmnt(masm_, "[ ArrayLiteral");
DeferredArrayLiteral* deferred = new DeferredArrayLiteral(this, node);
DeferredArrayLiteral* deferred = new DeferredArrayLiteral(node);
// Retrieve the literal array and check the allocated entry.
......
......@@ -194,8 +194,7 @@ class CodeGenerator: public AstVisitor {
// Accessors
Scope* scope() const { return scope_; }
// Clearing and generating deferred code.
void ClearDeferred();
// Generating deferred code.
void ProcessDeferred();
bool is_eval() { return is_eval_; }
......
......@@ -37,20 +37,20 @@ namespace internal {
void DeferredCode::SetEntryFrame(Result* arg) {
ASSERT(generator()->has_valid_frame());
generator()->frame()->Push(arg);
enter()->set_entry_frame(new VirtualFrame(generator()->frame()));
*arg = generator()->frame()->Pop();
ASSERT(cgen()->has_valid_frame());
cgen()->frame()->Push(arg);
enter()->set_entry_frame(new VirtualFrame(cgen()->frame()));
*arg = cgen()->frame()->Pop();
}
void DeferredCode::SetEntryFrame(Result* arg0, Result* arg1) {
ASSERT(generator()->has_valid_frame());
generator()->frame()->Push(arg0);
generator()->frame()->Push(arg1);
enter()->set_entry_frame(new VirtualFrame(generator()->frame()));
*arg1 = generator()->frame()->Pop();
*arg0 = generator()->frame()->Pop();
ASSERT(cgen()->has_valid_frame());
cgen()->frame()->Push(arg0);
cgen()->frame()->Push(arg1);
enter()->set_entry_frame(new VirtualFrame(cgen()->frame()));
*arg1 = cgen()->frame()->Pop();
*arg0 = cgen()->frame()->Pop();
}
......
......@@ -45,32 +45,24 @@ namespace internal {
CodeGenerator* CodeGeneratorScope::top_ = NULL;
DeferredCode::DeferredCode(CodeGenerator* generator)
: generator_(generator),
masm_(generator->masm()),
exit_(JumpTarget::BIDIRECTIONAL),
statement_position_(masm_->current_statement_position()),
position_(masm_->current_position()) {
generator->AddDeferred(this);
DeferredCode::DeferredCode() : exit_(JumpTarget::BIDIRECTIONAL) {
MacroAssembler* masm = cgen()->masm();
statement_position_ = masm->current_statement_position();
position_ = masm->current_position();
ASSERT(statement_position_ != RelocInfo::kNoPosition);
ASSERT(position_ != RelocInfo::kNoPosition);
cgen()->AddDeferred(this);
#ifdef DEBUG
comment_ = "";
#endif
}
void CodeGenerator::ClearDeferred() {
for (int i = 0; i < deferred_.length(); i++) {
deferred_[i]->Clear();
}
}
void CodeGenerator::ProcessDeferred() {
while (!deferred_.is_empty()) {
DeferredCode* code = deferred_.RemoveLast();
MacroAssembler* masm = code->masm();
MacroAssembler* masm = code->cgen()->masm();
// Record position of deferred code stub.
masm->RecordStatementPosition(code->statement_position());
if (code->position() != RelocInfo::kNoPosition) {
......@@ -80,7 +72,6 @@ void CodeGenerator::ProcessDeferred() {
Comment cmnt(masm, code->comment());
code->Generate();
ASSERT(code->enter()->is_bound());
code->Clear();
}
}
......
......@@ -52,7 +52,6 @@
// CodeGenerator
// ~CodeGenerator
// ProcessDeferred
// ClearDeferred
// GenCode
// BuildBoilerplate
// ComputeCallInitialize
......@@ -116,33 +115,17 @@ class CodeGeneratorScope BASE_EMBEDDED {
};
// Use lazy compilation; defaults to true.
// NOTE: Do not remove non-lazy compilation until we can properly
// install extensions with lazy compilation enabled. At the
// moment, this doesn't work for the extensions in Google3,
// and we can only run the tests with --nolazy.
// Deferred code objects are small pieces of code that are compiled
// out of line. They are used to defer the compilation of uncommon
// paths thereby avoiding expensive jumps around uncommon code parts.
class DeferredCode: public ZoneObject {
public:
explicit DeferredCode(CodeGenerator* generator);
DeferredCode();
virtual ~DeferredCode() { }
virtual void Generate() = 0;
// Unuse the entry and exit targets, deallocating all virtual frames
// held by them. It will be impossible to emit a (correct) jump
// into or out of the deferred code after clearing.
void Clear() {
enter_.Unuse();
exit_.Unuse();
}
MacroAssembler* masm() const { return masm_; }
CodeGenerator* generator() const { return generator_; }
CodeGenerator* cgen() const { return CodeGeneratorScope::Current(); }
// Set the virtual frame for entry to the deferred code as a
// snapshot of the code generator's current frame (plus additional
......@@ -169,13 +152,11 @@ class DeferredCode: public ZoneObject {
void set_comment(const char* comment) { comment_ = comment; }
const char* comment() const { return comment_; }
#else
inline void set_comment(const char* comment) { }
void set_comment(const char* comment) { }
const char* comment() const { return ""; }
#endif
protected:
CodeGenerator* const generator_;
MacroAssembler* const masm_;
JumpTarget enter_;
JumpTarget exit_;
......
This diff is collapsed.
......@@ -333,8 +333,7 @@ class CodeGenerator: public AstVisitor {
// Accessors
Scope* scope() const { return scope_; }
// Clearing and generating deferred code.
void ClearDeferred();
// Generating deferred code.
void ProcessDeferred();
bool is_eval() { return is_eval_; }
......
......@@ -333,8 +333,7 @@ class CodeGenerator: public AstVisitor {
// Accessors
Scope* scope() const { return scope_; }
// Clearing and generating deferred code.
void ClearDeferred();
// Generating deferred code.
void ProcessDeferred();
bool is_eval() { return is_eval_; }
......
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