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

Side by Side Diff: test/unittests/interpreter/bytecode-dead-code-optimizer-unittest.cc

Issue 2393683004: [Interpreter] Optimize the Register Optimizer. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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() 19 BytecodeDeadCodeOptimizerTest()
20 : dead_code_optimizer_(this), last_written_(Bytecode::kIllegal) {} 20 : dead_code_optimizer_(this), last_written_(Bytecode::kIllegal) {}
21 ~BytecodeDeadCodeOptimizerTest() override {} 21 ~BytecodeDeadCodeOptimizerTest() override {}
22 22
23 void Write(BytecodeNode* node) override { 23 void Write(BytecodeNode* node) override {
24 write_count_++; 24 write_count_++;
25 last_written_.Clone(node); 25 last_written_ = *node;
26 } 26 }
27 27
28 void WriteJump(BytecodeNode* node, BytecodeLabel* label) override { 28 void WriteJump(BytecodeNode* node, BytecodeLabel* label) override {
29 write_count_++; 29 write_count_++;
30 last_written_.Clone(node); 30 last_written_ = *node;
31 } 31 }
32 32
33 void BindLabel(BytecodeLabel* label) override {} 33 void BindLabel(BytecodeLabel* label) override {}
34 void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override {} 34 void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override {}
35 Handle<BytecodeArray> ToBytecodeArray( 35 Handle<BytecodeArray> ToBytecodeArray(
36 Isolate* isolate, int fixed_register_count, int parameter_count, 36 Isolate* isolate, int fixed_register_count, int parameter_count,
37 Handle<FixedArray> handle_table) override { 37 Handle<FixedArray> handle_table) override {
38 return Handle<BytecodeArray>(); 38 return Handle<BytecodeArray>();
39 } 39 }
40 40
41 BytecodeDeadCodeOptimizer* optimizer() { return &dead_code_optimizer_; } 41 BytecodeDeadCodeOptimizer* optimizer() { return &dead_code_optimizer_; }
42 42
43 int write_count() const { return write_count_; } 43 int write_count() const { return write_count_; }
44 const BytecodeNode& last_written() const { return last_written_; } 44 const BytecodeNode& last_written() const { return last_written_; }
45 45
46 private: 46 private:
47 BytecodeDeadCodeOptimizer dead_code_optimizer_; 47 BytecodeDeadCodeOptimizer dead_code_optimizer_;
48 48
49 int write_count_ = 0; 49 int write_count_ = 0;
50 BytecodeNode last_written_; 50 BytecodeNode last_written_;
51 }; 51 };
52 52
53 TEST_F(BytecodeDeadCodeOptimizerTest, LiveCodeKept) { 53 TEST_F(BytecodeDeadCodeOptimizerTest, LiveCodeKept) {
54 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 54 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
55 optimizer()->Write(&add); 55 optimizer()->Write(&add);
56 CHECK_EQ(write_count(), 1); 56 CHECK_EQ(write_count(), 1);
57 CHECK_EQ(add, last_written()); 57 CHECK_EQ(add, last_written());
58 58
59 BytecodeLabel target; 59 BytecodeLabel target;
60 BytecodeNode jump(Bytecode::kJump, 0, nullptr); 60 BytecodeNode jump(Bytecode::kJump, 0);
61 optimizer()->WriteJump(&jump, &target); 61 optimizer()->WriteJump(&jump, &target);
62 CHECK_EQ(write_count(), 2); 62 CHECK_EQ(write_count(), 2);
63 CHECK_EQ(jump, last_written()); 63 CHECK_EQ(jump, last_written());
64 } 64 }
65 65
66 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterReturnEliminated) { 66 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterReturnEliminated) {
67 BytecodeNode ret(Bytecode::kReturn); 67 BytecodeNode ret(Bytecode::kReturn);
68 optimizer()->Write(&ret); 68 optimizer()->Write(&ret);
69 CHECK_EQ(write_count(), 1); 69 CHECK_EQ(write_count(), 1);
70 CHECK_EQ(ret, last_written()); 70 CHECK_EQ(ret, last_written());
(...skipping 23 matching lines...) Expand all
94 CHECK_EQ(rethrow, last_written()); 94 CHECK_EQ(rethrow, last_written());
95 95
96 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 96 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
97 optimizer()->Write(&add); 97 optimizer()->Write(&add);
98 CHECK_EQ(write_count(), 1); 98 CHECK_EQ(write_count(), 1);
99 CHECK_EQ(rethrow, last_written()); 99 CHECK_EQ(rethrow, last_written());
100 } 100 }
101 101
102 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterJumpEliminated) { 102 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterJumpEliminated) {
103 BytecodeLabel target; 103 BytecodeLabel target;
104 BytecodeNode jump(Bytecode::kJump, 0, nullptr); 104 BytecodeNode jump(Bytecode::kJump, 0);
105 optimizer()->WriteJump(&jump, &target); 105 optimizer()->WriteJump(&jump, &target);
106 CHECK_EQ(write_count(), 1); 106 CHECK_EQ(write_count(), 1);
107 CHECK_EQ(jump, last_written()); 107 CHECK_EQ(jump, last_written());
108 108
109 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 109 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
110 optimizer()->Write(&add); 110 optimizer()->Write(&add);
111 CHECK_EQ(write_count(), 1); 111 CHECK_EQ(write_count(), 1);
112 CHECK_EQ(jump, last_written()); 112 CHECK_EQ(jump, last_written());
113 } 113 }
114 114
115 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeStillDeadAfterConditinalJump) { 115 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeStillDeadAfterConditinalJump) {
116 BytecodeNode ret(Bytecode::kReturn); 116 BytecodeNode ret(Bytecode::kReturn);
117 optimizer()->Write(&ret); 117 optimizer()->Write(&ret);
118 CHECK_EQ(write_count(), 1); 118 CHECK_EQ(write_count(), 1);
119 CHECK_EQ(ret, last_written()); 119 CHECK_EQ(ret, last_written());
120 120
121 BytecodeLabel target; 121 BytecodeLabel target;
122 BytecodeNode jump(Bytecode::kJumpIfTrue, 0, nullptr); 122 BytecodeNode jump(Bytecode::kJumpIfTrue, 0);
123 optimizer()->WriteJump(&jump, &target); 123 optimizer()->WriteJump(&jump, &target);
124 CHECK_EQ(write_count(), 1); 124 CHECK_EQ(write_count(), 1);
125 CHECK_EQ(ret, last_written()); 125 CHECK_EQ(ret, last_written());
126 126
127 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 127 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
128 optimizer()->Write(&add); 128 optimizer()->Write(&add);
129 CHECK_EQ(write_count(), 1); 129 CHECK_EQ(write_count(), 1);
130 CHECK_EQ(ret, last_written()); 130 CHECK_EQ(ret, last_written());
131 } 131 }
132 132
133 TEST_F(BytecodeDeadCodeOptimizerTest, CodeLiveAfterLabelBind) { 133 TEST_F(BytecodeDeadCodeOptimizerTest, CodeLiveAfterLabelBind) {
134 BytecodeNode ret(Bytecode::kReturn); 134 BytecodeNode ret(Bytecode::kReturn);
135 optimizer()->Write(&ret); 135 optimizer()->Write(&ret);
136 CHECK_EQ(write_count(), 1); 136 CHECK_EQ(write_count(), 1);
137 CHECK_EQ(ret, last_written()); 137 CHECK_EQ(ret, last_written());
138 138
139 BytecodeLabel target; 139 BytecodeLabel target;
140 optimizer()->BindLabel(&target); 140 optimizer()->BindLabel(&target);
141 141
142 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 142 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
143 optimizer()->Write(&add); 143 optimizer()->Write(&add);
144 CHECK_EQ(write_count(), 2); 144 CHECK_EQ(write_count(), 2);
145 CHECK_EQ(add, last_written()); 145 CHECK_EQ(add, last_written());
146 } 146 }
147 147
148 } // namespace interpreter 148 } // namespace interpreter
149 } // namespace internal 149 } // namespace internal
150 } // namespace v8 150 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698