| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/interpreter/bytecode-dead-code-optimizer.h" | 7 #include "src/interpreter/bytecode-dead-code-optimizer.h" |
| 8 #include "src/interpreter/bytecode-label.h" | 8 #include "src/interpreter/bytecode-label.h" |
| 9 #include "src/objects.h" | 9 #include "src/objects.h" |
| 10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 namespace interpreter { | 14 namespace interpreter { |
| 15 | 15 |
| 16 class BytecodeDeadCodeOptimizerTest : public BytecodePipelineStage, | 16 class BytecodeDeadCodeOptimizerTest : public BytecodePipelineStage, |
| 17 public TestWithIsolateAndZone { | 17 public TestWithIsolateAndZone { |
| 18 public: | 18 public: |
| 19 BytecodeDeadCodeOptimizerTest() : dead_code_optimizer_(this) {} | 19 BytecodeDeadCodeOptimizerTest() |
| 20 : dead_code_optimizer_(this), last_written_(Bytecode::kIllegal) {} |
| 20 ~BytecodeDeadCodeOptimizerTest() override {} | 21 ~BytecodeDeadCodeOptimizerTest() override {} |
| 21 | 22 |
| 22 void Write(BytecodeNode* node) override { | 23 void Write(BytecodeNode* node) override { |
| 23 write_count_++; | 24 write_count_++; |
| 24 last_written_.Clone(node); | 25 last_written_.Clone(node); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void WriteJump(BytecodeNode* node, BytecodeLabel* label) override { | 28 void WriteJump(BytecodeNode* node, BytecodeLabel* label) override { |
| 28 write_count_++; | 29 write_count_++; |
| 29 last_written_.Clone(node); | 30 last_written_.Clone(node); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 BytecodeNode last_written_; | 50 BytecodeNode last_written_; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 TEST_F(BytecodeDeadCodeOptimizerTest, LiveCodeKept) { | 53 TEST_F(BytecodeDeadCodeOptimizerTest, LiveCodeKept) { |
| 53 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); | 54 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); |
| 54 optimizer()->Write(&add); | 55 optimizer()->Write(&add); |
| 55 CHECK_EQ(write_count(), 1); | 56 CHECK_EQ(write_count(), 1); |
| 56 CHECK_EQ(add, last_written()); | 57 CHECK_EQ(add, last_written()); |
| 57 | 58 |
| 58 BytecodeLabel target; | 59 BytecodeLabel target; |
| 59 BytecodeNode jump(Bytecode::kJump, 0); | 60 BytecodeNode jump(Bytecode::kJump, 0, nullptr); |
| 60 optimizer()->WriteJump(&jump, &target); | 61 optimizer()->WriteJump(&jump, &target); |
| 61 CHECK_EQ(write_count(), 2); | 62 CHECK_EQ(write_count(), 2); |
| 62 CHECK_EQ(jump, last_written()); | 63 CHECK_EQ(jump, last_written()); |
| 63 } | 64 } |
| 64 | 65 |
| 65 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterReturnEliminated) { | 66 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterReturnEliminated) { |
| 66 BytecodeNode ret(Bytecode::kReturn); | 67 BytecodeNode ret(Bytecode::kReturn); |
| 67 optimizer()->Write(&ret); | 68 optimizer()->Write(&ret); |
| 68 CHECK_EQ(write_count(), 1); | 69 CHECK_EQ(write_count(), 1); |
| 69 CHECK_EQ(ret, last_written()); | 70 CHECK_EQ(ret, last_written()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 93 CHECK_EQ(rethrow, last_written()); | 94 CHECK_EQ(rethrow, last_written()); |
| 94 | 95 |
| 95 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); | 96 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); |
| 96 optimizer()->Write(&add); | 97 optimizer()->Write(&add); |
| 97 CHECK_EQ(write_count(), 1); | 98 CHECK_EQ(write_count(), 1); |
| 98 CHECK_EQ(rethrow, last_written()); | 99 CHECK_EQ(rethrow, last_written()); |
| 99 } | 100 } |
| 100 | 101 |
| 101 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterJumpEliminated) { | 102 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterJumpEliminated) { |
| 102 BytecodeLabel target; | 103 BytecodeLabel target; |
| 103 BytecodeNode jump(Bytecode::kJump, 0); | 104 BytecodeNode jump(Bytecode::kJump, 0, nullptr); |
| 104 optimizer()->WriteJump(&jump, &target); | 105 optimizer()->WriteJump(&jump, &target); |
| 105 CHECK_EQ(write_count(), 1); | 106 CHECK_EQ(write_count(), 1); |
| 106 CHECK_EQ(jump, last_written()); | 107 CHECK_EQ(jump, last_written()); |
| 107 | 108 |
| 108 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); | 109 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); |
| 109 optimizer()->Write(&add); | 110 optimizer()->Write(&add); |
| 110 CHECK_EQ(write_count(), 1); | 111 CHECK_EQ(write_count(), 1); |
| 111 CHECK_EQ(jump, last_written()); | 112 CHECK_EQ(jump, last_written()); |
| 112 } | 113 } |
| 113 | 114 |
| 114 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeStillDeadAfterConditinalJump) { | 115 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeStillDeadAfterConditinalJump) { |
| 115 BytecodeNode ret(Bytecode::kReturn); | 116 BytecodeNode ret(Bytecode::kReturn); |
| 116 optimizer()->Write(&ret); | 117 optimizer()->Write(&ret); |
| 117 CHECK_EQ(write_count(), 1); | 118 CHECK_EQ(write_count(), 1); |
| 118 CHECK_EQ(ret, last_written()); | 119 CHECK_EQ(ret, last_written()); |
| 119 | 120 |
| 120 BytecodeLabel target; | 121 BytecodeLabel target; |
| 121 BytecodeNode jump(Bytecode::kJumpIfTrue, 0); | 122 BytecodeNode jump(Bytecode::kJumpIfTrue, 0, nullptr); |
| 122 optimizer()->WriteJump(&jump, &target); | 123 optimizer()->WriteJump(&jump, &target); |
| 123 CHECK_EQ(write_count(), 1); | 124 CHECK_EQ(write_count(), 1); |
| 124 CHECK_EQ(ret, last_written()); | 125 CHECK_EQ(ret, last_written()); |
| 125 | 126 |
| 126 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); | 127 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); |
| 127 optimizer()->Write(&add); | 128 optimizer()->Write(&add); |
| 128 CHECK_EQ(write_count(), 1); | 129 CHECK_EQ(write_count(), 1); |
| 129 CHECK_EQ(ret, last_written()); | 130 CHECK_EQ(ret, last_written()); |
| 130 } | 131 } |
| 131 | 132 |
| 132 TEST_F(BytecodeDeadCodeOptimizerTest, CodeLiveAfterLabelBind) { | 133 TEST_F(BytecodeDeadCodeOptimizerTest, CodeLiveAfterLabelBind) { |
| 133 BytecodeNode ret(Bytecode::kReturn); | 134 BytecodeNode ret(Bytecode::kReturn); |
| 134 optimizer()->Write(&ret); | 135 optimizer()->Write(&ret); |
| 135 CHECK_EQ(write_count(), 1); | 136 CHECK_EQ(write_count(), 1); |
| 136 CHECK_EQ(ret, last_written()); | 137 CHECK_EQ(ret, last_written()); |
| 137 | 138 |
| 138 BytecodeLabel target; | 139 BytecodeLabel target; |
| 139 optimizer()->BindLabel(&target); | 140 optimizer()->BindLabel(&target); |
| 140 | 141 |
| 141 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); | 142 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); |
| 142 optimizer()->Write(&add); | 143 optimizer()->Write(&add); |
| 143 CHECK_EQ(write_count(), 2); | 144 CHECK_EQ(write_count(), 2); |
| 144 CHECK_EQ(add, last_written()); | 145 CHECK_EQ(add, last_written()); |
| 145 } | 146 } |
| 146 | 147 |
| 147 } // namespace interpreter | 148 } // namespace interpreter |
| 148 } // namespace internal | 149 } // namespace internal |
| 149 } // namespace v8 | 150 } // namespace v8 |
| OLD | NEW |