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

Unified Diff: test/unittests/interpreter/bytecode-register-optimizer-unittest.cc

Issue 2393683004: [Interpreter] Optimize the Register Optimizer. (Closed)
Patch Set: Rebase Created 4 years, 2 months 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
Index: test/unittests/interpreter/bytecode-register-optimizer-unittest.cc
diff --git a/test/unittests/interpreter/bytecode-register-optimizer-unittest.cc b/test/unittests/interpreter/bytecode-register-optimizer-unittest.cc
index ae7c159563cd9eb9fdc3845aee65a2219d7326ae..17ab8e190c840958d52abf340033d095c20360fa 100644
--- a/test/unittests/interpreter/bytecode-register-optimizer-unittest.cc
+++ b/test/unittests/interpreter/bytecode-register-optimizer-unittest.cc
@@ -62,55 +62,23 @@ class BytecodeRegisterOptimizerTest : public BytecodePipelineStage,
// Sanity tests.
-TEST_F(BytecodeRegisterOptimizerTest, WriteNop) {
- Initialize(1, 1);
- BytecodeNode node(Bytecode::kNop);
- optimizer()->Write(&node);
- CHECK_EQ(write_count(), 1);
- CHECK_EQ(node, last_written());
-}
-
-TEST_F(BytecodeRegisterOptimizerTest, WriteNopExpression) {
- Initialize(1, 1);
- BytecodeSourceInfo source_info(3, false);
- BytecodeNode node(Bytecode::kNop, &source_info);
- optimizer()->Write(&node);
- CHECK_EQ(write_count(), 1);
- CHECK_EQ(node, last_written());
-}
-
-TEST_F(BytecodeRegisterOptimizerTest, WriteNopStatement) {
- Initialize(1, 1);
- BytecodeSourceInfo source_info(3, true);
- BytecodeNode node(Bytecode::kNop);
- optimizer()->Write(&node);
- CHECK_EQ(write_count(), 1);
- CHECK_EQ(node, last_written());
-}
-
-TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForJump) {
+TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForFlush) {
Initialize(1, 1);
Register temp = NewTemporary();
- BytecodeNode node(Bytecode::kStar, temp.ToOperand());
- optimizer()->Write(&node);
+ optimizer()->DoStar(temp, BytecodeSourceInfo());
CHECK_EQ(write_count(), 0);
- BytecodeLabel label;
- BytecodeNode jump(Bytecode::kJump, 0, nullptr);
- optimizer()->WriteJump(&jump, &label);
- CHECK_EQ(write_count(), 2);
+ optimizer()->Flush();
+ CHECK_EQ(write_count(), 1);
CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar);
CHECK_EQ(output()->at(0).operand(0), temp.ToOperand());
- CHECK_EQ(output()->at(1).bytecode(), Bytecode::kJump);
}
-TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForBind) {
+TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForJump) {
Initialize(1, 1);
Register temp = NewTemporary();
- BytecodeNode node(Bytecode::kStar, temp.ToOperand());
- optimizer()->Write(&node);
+ optimizer()->DoStar(temp, BytecodeSourceInfo());
CHECK_EQ(write_count(), 0);
- BytecodeLabel label;
- optimizer()->BindLabel(&label);
+ optimizer()->PrepareForBytecode(Bytecode::kJump);
CHECK_EQ(write_count(), 1);
CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar);
CHECK_EQ(output()->at(0).operand(0), temp.ToOperand());
@@ -121,117 +89,91 @@ TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForBind) {
TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotEmitted) {
Initialize(3, 1);
Register parameter = Register::FromParameterIndex(1, 3);
- BytecodeNode node0(Bytecode::kLdar, parameter.ToOperand());
- optimizer()->Write(&node0);
+ optimizer()->DoLdar(parameter, BytecodeSourceInfo());
CHECK_EQ(write_count(), 0);
Register temp = NewTemporary();
+ optimizer()->DoStar(temp, BytecodeSourceInfo());
BytecodeNode node1(Bytecode::kStar, NewTemporary().ToOperand());
- optimizer()->Write(&node1);
- CHECK_EQ(write_count(), 0);
ReleaseTemporaries(temp);
CHECK_EQ(write_count(), 0);
- BytecodeNode node2(Bytecode::kReturn);
- optimizer()->Write(&node2);
- CHECK_EQ(write_count(), 2);
+ optimizer()->PrepareForBytecode(Bytecode::kReturn);
CHECK_EQ(output()->at(0).bytecode(), Bytecode::kLdar);
CHECK_EQ(output()->at(0).operand(0), parameter.ToOperand());
- CHECK_EQ(output()->at(1).bytecode(), Bytecode::kReturn);
}
TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterUsed) {
Initialize(3, 1);
- BytecodeNode node0(Bytecode::kLdaSmi, 3);
- optimizer()->Write(&node0);
- CHECK_EQ(write_count(), 1);
+ optimizer()->PrepareForBytecode(Bytecode::kLdaSmi);
Register temp0 = NewTemporary();
Register temp1 = NewTemporary();
- BytecodeNode node1(Bytecode::kStar, temp1.ToOperand());
- optimizer()->Write(&node1);
+ optimizer()->DoStar(temp1, BytecodeSourceInfo());
+ CHECK_EQ(write_count(), 0);
+ optimizer()->PrepareForBytecode(Bytecode::kLdaSmi);
+ CHECK_EQ(write_count(), 1);
+ CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar);
+ CHECK_EQ(output()->at(0).operand(0), temp1.ToOperand());
+ optimizer()->DoMov(temp1, temp0, BytecodeSourceInfo());
CHECK_EQ(write_count(), 1);
- BytecodeNode node2(Bytecode::kLdaSmi, 1);
- optimizer()->Write(&node2);
- CHECK_EQ(write_count(), 3);
- BytecodeNode node3(Bytecode::kMov, temp1.ToOperand(), temp0.ToOperand());
- optimizer()->Write(&node3);
- CHECK_EQ(write_count(), 3);
ReleaseTemporaries(temp1);
- CHECK_EQ(write_count(), 3);
- BytecodeNode node4(Bytecode::kLdar, temp0.ToOperand());
- optimizer()->Write(&node4);
- CHECK_EQ(write_count(), 3);
- BytecodeNode node5(Bytecode::kReturn);
- optimizer()->Write(&node5);
- CHECK_EQ(write_count(), 5);
- CHECK_EQ(output()->at(3).bytecode(), Bytecode::kLdar);
- CHECK_EQ(output()->at(3).operand(0), temp1.ToOperand());
- CHECK_EQ(output()->at(4).bytecode(), Bytecode::kReturn);
+ CHECK_EQ(write_count(), 1);
+ optimizer()->DoLdar(temp0, BytecodeSourceInfo());
+ CHECK_EQ(write_count(), 1);
+ optimizer()->PrepareForBytecode(Bytecode::kReturn);
+ CHECK_EQ(write_count(), 2);
+ CHECK_EQ(output()->at(1).bytecode(), Bytecode::kLdar);
+ CHECK_EQ(output()->at(1).operand(0), temp1.ToOperand());
}
TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterNotFlushed) {
Initialize(3, 1);
- BytecodeNode node0(Bytecode::kLdaSmi, 3);
- optimizer()->Write(&node0);
- CHECK_EQ(write_count(), 1);
+ optimizer()->PrepareForBytecode(Bytecode::kLdaSmi);
Register temp0 = NewTemporary();
Register temp1 = NewTemporary();
- BytecodeNode node1(Bytecode::kStar, temp0.ToOperand());
- optimizer()->Write(&node1);
- CHECK_EQ(write_count(), 1);
- BytecodeNode node2(Bytecode::kStar, temp1.ToOperand());
- optimizer()->Write(&node2);
- CHECK_EQ(write_count(), 1);
+ optimizer()->DoStar(temp0, BytecodeSourceInfo());
+ CHECK_EQ(write_count(), 0);
+ optimizer()->DoStar(temp1, BytecodeSourceInfo());
+ CHECK_EQ(write_count(), 0);
ReleaseTemporaries(temp1);
- BytecodeLabel label;
- BytecodeNode jump(Bytecode::kJump, 0, nullptr);
- optimizer()->WriteJump(&jump, &label);
- BytecodeNode node3(Bytecode::kReturn);
- optimizer()->Write(&node3);
- CHECK_EQ(write_count(), 4);
- CHECK_EQ(output()->at(1).bytecode(), Bytecode::kStar);
- CHECK_EQ(output()->at(1).operand(0), temp0.ToOperand());
- CHECK_EQ(output()->at(2).bytecode(), Bytecode::kJump);
- CHECK_EQ(output()->at(3).bytecode(), Bytecode::kReturn);
+ optimizer()->Flush();
+ CHECK_EQ(write_count(), 1);
+ CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar);
+ CHECK_EQ(output()->at(0).operand(0), temp0.ToOperand());
}
TEST_F(BytecodeRegisterOptimizerTest, StoresToLocalsImmediate) {
Initialize(3, 1);
Register parameter = Register::FromParameterIndex(1, 3);
- BytecodeNode node0(Bytecode::kLdar, parameter.ToOperand());
- optimizer()->Write(&node0);
+ optimizer()->DoLdar(parameter, BytecodeSourceInfo());
CHECK_EQ(write_count(), 0);
Register local = Register(0);
- BytecodeNode node1(Bytecode::kStar, local.ToOperand());
- optimizer()->Write(&node1);
+ optimizer()->DoStar(local, BytecodeSourceInfo());
CHECK_EQ(write_count(), 1);
CHECK_EQ(output()->at(0).bytecode(), Bytecode::kMov);
CHECK_EQ(output()->at(0).operand(0), parameter.ToOperand());
CHECK_EQ(output()->at(0).operand(1), local.ToOperand());
- BytecodeNode node2(Bytecode::kReturn);
- optimizer()->Write(&node2);
- CHECK_EQ(write_count(), 3);
+ optimizer()->PrepareForBytecode(Bytecode::kReturn);
+ CHECK_EQ(write_count(), 2);
CHECK_EQ(output()->at(1).bytecode(), Bytecode::kLdar);
CHECK_EQ(output()->at(1).operand(0), local.ToOperand());
- CHECK_EQ(output()->at(2).bytecode(), Bytecode::kReturn);
}
-TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotMaterializedForInput) {
+TEST_F(BytecodeRegisterOptimizerTest, SingleTemporaryNotMaterializedForInput) {
Initialize(3, 1);
Register parameter = Register::FromParameterIndex(1, 3);
Register temp0 = NewTemporary();
Register temp1 = NewTemporary();
- BytecodeNode node0(Bytecode::kMov, parameter.ToOperand(), temp0.ToOperand());
- optimizer()->Write(&node0);
- BytecodeNode node1(Bytecode::kMov, parameter.ToOperand(), temp1.ToOperand());
- optimizer()->Write(&node1);
+ optimizer()->DoMov(parameter, temp0, BytecodeSourceInfo());
+ optimizer()->DoMov(parameter, temp1, BytecodeSourceInfo());
CHECK_EQ(write_count(), 0);
- BytecodeNode node2(Bytecode::kCallJSRuntime, 0, temp0.ToOperand(), 1);
- optimizer()->Write(&node2);
- CHECK_EQ(write_count(), 1);
- CHECK_EQ(output()->at(0).bytecode(), Bytecode::kCallJSRuntime);
- CHECK_EQ(output()->at(0).operand(0), 0);
- CHECK_EQ(output()->at(0).operand(1), parameter.ToOperand());
- CHECK_EQ(output()->at(0).operand(2), 1);
+
+ Register reg = optimizer()->GetInputRegister(temp0);
+ RegisterList reg_list =
+ optimizer()->GetInputRegisterList(RegisterList(temp0.index(), 1));
+ CHECK_EQ(write_count(), 0);
+ CHECK_EQ(parameter.index(), reg.index());
+ CHECK_EQ(parameter.index(), reg_list.first_register().index());
+ CHECK_EQ(1, reg_list.register_count());
}
TEST_F(BytecodeRegisterOptimizerTest, RangeOfTemporariesMaterializedForInput) {
@@ -239,32 +181,22 @@ TEST_F(BytecodeRegisterOptimizerTest, RangeOfTemporariesMaterializedForInput) {
Register parameter = Register::FromParameterIndex(1, 3);
Register temp0 = NewTemporary();
Register temp1 = NewTemporary();
- BytecodeNode node0(Bytecode::kLdaSmi, 3);
- optimizer()->Write(&node0);
- CHECK_EQ(write_count(), 1);
- BytecodeNode node1(Bytecode::kStar, temp0.ToOperand());
- optimizer()->Write(&node1);
- BytecodeNode node2(Bytecode::kMov, parameter.ToOperand(), temp1.ToOperand());
- optimizer()->Write(&node2);
- CHECK_EQ(write_count(), 1);
- BytecodeNode node3(Bytecode::kCallJSRuntime, 0, temp0.ToOperand(), 2);
- optimizer()->Write(&node3);
- CHECK_EQ(write_count(), 4);
-
- CHECK_EQ(output()->at(0).bytecode(), Bytecode::kLdaSmi);
- CHECK_EQ(output()->at(0).operand(0), 3);
-
- CHECK_EQ(output()->at(1).bytecode(), Bytecode::kStar);
- CHECK_EQ(output()->at(1).operand(0), temp0.ToOperand());
-
- CHECK_EQ(output()->at(2).bytecode(), Bytecode::kMov);
- CHECK_EQ(output()->at(2).operand(0), parameter.ToOperand());
- CHECK_EQ(output()->at(2).operand(1), temp1.ToOperand());
+ optimizer()->PrepareForBytecode(Bytecode::kLdaSmi);
+ optimizer()->DoStar(temp0, BytecodeSourceInfo());
+ optimizer()->DoMov(parameter, temp1, BytecodeSourceInfo());
+ CHECK_EQ(write_count(), 0);
- CHECK_EQ(output()->at(3).bytecode(), Bytecode::kCallJSRuntime);
- CHECK_EQ(output()->at(3).operand(0), 0);
- CHECK_EQ(output()->at(3).operand(1), temp0.ToOperand());
- CHECK_EQ(output()->at(3).operand(2), 2);
+ optimizer()->PrepareForBytecode(Bytecode::kCallJSRuntime);
+ RegisterList reg_list =
+ optimizer()->GetInputRegisterList(RegisterList(temp0.index(), 2));
+ CHECK_EQ(temp0.index(), reg_list.first_register().index());
+ CHECK_EQ(2, reg_list.register_count());
+ CHECK_EQ(write_count(), 2);
+ CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar);
+ CHECK_EQ(output()->at(0).operand(0), temp0.ToOperand());
+ CHECK_EQ(output()->at(1).bytecode(), Bytecode::kMov);
+ CHECK_EQ(output()->at(1).operand(0), parameter.ToOperand());
+ CHECK_EQ(output()->at(1).operand(1), temp1.ToOperand());
}
} // namespace interpreter
« no previous file with comments | « test/unittests/interpreter/bytecode-pipeline-unittest.cc ('k') | test/unittests/interpreter/bytecodes-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698