Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(908)

Unified Diff: src/interpreter/bytecode-peephole-optimizer.cc

Issue 2542903003: [Interpreter] Templatize AccumulatorUsage and OperandType for bytecode creation. (Closed)
Patch Set: Remove commented code and rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/bytecode-operands.h ('k') | src/interpreter/bytecode-pipeline.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-peephole-optimizer.cc
diff --git a/src/interpreter/bytecode-peephole-optimizer.cc b/src/interpreter/bytecode-peephole-optimizer.cc
index dfc40a2c194ec18892d52215c645ea5cda3d38da..887f9ce9737525c9e12231d4f1dcfac796cb7016 100644
--- a/src/interpreter/bytecode-peephole-optimizer.cc
+++ b/src/interpreter/bytecode-peephole-optimizer.cc
@@ -13,7 +13,8 @@ namespace interpreter {
BytecodePeepholeOptimizer::BytecodePeepholeOptimizer(
BytecodePipelineStage* next_stage)
- : next_stage_(next_stage), last_(Bytecode::kIllegal, BytecodeSourceInfo()) {
+ : next_stage_(next_stage),
+ last_(BytecodeNode::Illegal(BytecodeSourceInfo())) {
InvalidateLast();
}
@@ -65,7 +66,7 @@ void BytecodePeepholeOptimizer::Flush() {
}
void BytecodePeepholeOptimizer::InvalidateLast() {
- last_.set_bytecode(Bytecode::kIllegal);
+ last_ = BytecodeNode::Illegal(BytecodeSourceInfo());
}
bool BytecodePeepholeOptimizer::LastIsValid() const {
@@ -116,37 +117,41 @@ bool BytecodePeepholeOptimizer::CanElideLastBasedOnSourcePosition(
namespace {
-void TransformLdaSmiBinaryOpToBinaryOpWithSmi(Bytecode new_bytecode,
- BytecodeNode* const last,
- BytecodeNode* const current) {
+BytecodeNode TransformLdaSmiBinaryOpToBinaryOpWithSmi(
+ Bytecode new_bytecode, BytecodeNode* const last,
+ BytecodeNode* const current) {
DCHECK_EQ(last->bytecode(), Bytecode::kLdaSmi);
- current->set_bytecode(new_bytecode, last->operand(0), current->operand(0),
- current->operand(1));
+ BytecodeNode node(new_bytecode, last->operand(0), current->operand(0),
+ current->operand(1), current->source_info());
if (last->source_info().is_valid()) {
- current->set_source_info(last->source_info());
+ node.set_source_info(last->source_info());
}
+ return node;
}
-void TransformLdaZeroBinaryOpToBinaryOpWithZero(Bytecode new_bytecode,
- BytecodeNode* const last,
- BytecodeNode* const current) {
+BytecodeNode TransformLdaZeroBinaryOpToBinaryOpWithZero(
+ Bytecode new_bytecode, BytecodeNode* const last,
+ BytecodeNode* const current) {
DCHECK_EQ(last->bytecode(), Bytecode::kLdaZero);
- current->set_bytecode(new_bytecode, 0, current->operand(0),
- current->operand(1));
+ BytecodeNode node(new_bytecode, 0, current->operand(0), current->operand(1),
+ current->source_info());
if (last->source_info().is_valid()) {
- current->set_source_info(last->source_info());
+ node.set_source_info(last->source_info());
}
+ return node;
}
-void TransformEqualityWithNullOrUndefinedToTestUndetectable(
+BytecodeNode TransformEqualityWithNullOrUndefinedToTestUndetectable(
BytecodeNode* const last, BytecodeNode* const current) {
DCHECK((last->bytecode() == Bytecode::kLdaNull) ||
(last->bytecode() == Bytecode::kLdaUndefined));
DCHECK_EQ(current->bytecode(), Bytecode::kTestEqual);
- current->set_bytecode(Bytecode::kTestUndetectable, current->operand(0));
+ BytecodeNode node(BytecodeNode::TestUndetectable(current->source_info(),
+ current->operand(0)));
if (last->source_info().is_valid()) {
- current->set_source_info(last->source_info());
+ node.set_source_info(last->source_info());
}
+ return node;
}
} // namespace
@@ -186,8 +191,8 @@ void BytecodePeepholeOptimizer::ElideCurrentAction(
if (node->source_info().is_valid()) {
// Preserve the source information by replacing the node bytecode
// with a no op bytecode.
- node->set_bytecode(Bytecode::kNop);
- DefaultAction(node);
+ BytecodeNode new_node(BytecodeNode::Nop(node->source_info()));
+ DefaultAction(&new_node);
} else {
// Nothing to do, keep last and wait for next bytecode to pair with it.
}
@@ -239,9 +244,9 @@ void BytecodePeepholeOptimizer::TransformLdaSmiBinaryOpToBinaryOpWithSmiAction(
if (!node->source_info().is_valid() || !last()->source_info().is_valid()) {
// Fused last and current into current.
- TransformLdaSmiBinaryOpToBinaryOpWithSmi(action_data->bytecode, last(),
- node);
- SetLast(node);
+ BytecodeNode new_node(TransformLdaSmiBinaryOpToBinaryOpWithSmi(
+ action_data->bytecode, last(), node));
+ SetLast(&new_node);
} else {
DefaultAction(node);
}
@@ -254,9 +259,9 @@ void BytecodePeepholeOptimizer::
DCHECK(!Bytecodes::IsJump(node->bytecode()));
if (!node->source_info().is_valid() || !last()->source_info().is_valid()) {
// Fused last and current into current.
- TransformLdaZeroBinaryOpToBinaryOpWithZero(action_data->bytecode, last(),
- node);
- SetLast(node);
+ BytecodeNode new_node(TransformLdaZeroBinaryOpToBinaryOpWithZero(
+ action_data->bytecode, last(), node));
+ SetLast(&new_node);
} else {
DefaultAction(node);
}
@@ -268,8 +273,9 @@ void BytecodePeepholeOptimizer::
DCHECK(LastIsValid());
DCHECK(!Bytecodes::IsJump(node->bytecode()));
// Fused last and current into current.
- TransformEqualityWithNullOrUndefinedToTestUndetectable(last(), node);
- SetLast(node);
+ BytecodeNode new_node(
+ TransformEqualityWithNullOrUndefinedToTestUndetectable(last(), node));
+ SetLast(&new_node);
}
void BytecodePeepholeOptimizer::DefaultJumpAction(
@@ -294,7 +300,7 @@ void BytecodePeepholeOptimizer::ChangeJumpBytecodeAction(
next_stage()->Write(last());
InvalidateLast();
- node->set_bytecode(action_data->bytecode, node->operand(0));
+ node->replace_bytecode(action_data->bytecode);
}
void BytecodePeepholeOptimizer::ElideLastBeforeJumpAction(
« no previous file with comments | « src/interpreter/bytecode-operands.h ('k') | src/interpreter/bytecode-pipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698