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

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

Issue 2360193003: Revert of [Interpreter] Optimize BytecodeArrayBuilder and BytecodeArrayWriter. (Closed)
Patch Set: 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 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() : dead_code_optimizer_(this) {}
20 : dead_code_optimizer_(this), last_written_(Bytecode::kIllegal) {}
21 ~BytecodeDeadCodeOptimizerTest() override {} 20 ~BytecodeDeadCodeOptimizerTest() override {}
22 21
23 void Write(BytecodeNode* node) override { 22 void Write(BytecodeNode* node) override {
24 write_count_++; 23 write_count_++;
25 last_written_.Clone(node); 24 last_written_.Clone(node);
26 } 25 }
27 26
28 void WriteJump(BytecodeNode* node, BytecodeLabel* label) override { 27 void WriteJump(BytecodeNode* node, BytecodeLabel* label) override {
29 write_count_++; 28 write_count_++;
30 last_written_.Clone(node); 29 last_written_.Clone(node);
(...skipping 19 matching lines...) Expand all
50 BytecodeNode last_written_; 49 BytecodeNode last_written_;
51 }; 50 };
52 51
53 TEST_F(BytecodeDeadCodeOptimizerTest, LiveCodeKept) { 52 TEST_F(BytecodeDeadCodeOptimizerTest, LiveCodeKept) {
54 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 53 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
55 optimizer()->Write(&add); 54 optimizer()->Write(&add);
56 CHECK_EQ(write_count(), 1); 55 CHECK_EQ(write_count(), 1);
57 CHECK_EQ(add, last_written()); 56 CHECK_EQ(add, last_written());
58 57
59 BytecodeLabel target; 58 BytecodeLabel target;
60 BytecodeNode jump(Bytecode::kJump, 0, nullptr); 59 BytecodeNode jump(Bytecode::kJump, 0);
61 optimizer()->WriteJump(&jump, &target); 60 optimizer()->WriteJump(&jump, &target);
62 CHECK_EQ(write_count(), 2); 61 CHECK_EQ(write_count(), 2);
63 CHECK_EQ(jump, last_written()); 62 CHECK_EQ(jump, last_written());
64 } 63 }
65 64
66 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterReturnEliminated) { 65 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterReturnEliminated) {
67 BytecodeNode ret(Bytecode::kReturn); 66 BytecodeNode ret(Bytecode::kReturn);
68 optimizer()->Write(&ret); 67 optimizer()->Write(&ret);
69 CHECK_EQ(write_count(), 1); 68 CHECK_EQ(write_count(), 1);
70 CHECK_EQ(ret, last_written()); 69 CHECK_EQ(ret, last_written());
(...skipping 23 matching lines...) Expand all
94 CHECK_EQ(rethrow, last_written()); 93 CHECK_EQ(rethrow, last_written());
95 94
96 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 95 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
97 optimizer()->Write(&add); 96 optimizer()->Write(&add);
98 CHECK_EQ(write_count(), 1); 97 CHECK_EQ(write_count(), 1);
99 CHECK_EQ(rethrow, last_written()); 98 CHECK_EQ(rethrow, last_written());
100 } 99 }
101 100
102 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterJumpEliminated) { 101 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeAfterJumpEliminated) {
103 BytecodeLabel target; 102 BytecodeLabel target;
104 BytecodeNode jump(Bytecode::kJump, 0, nullptr); 103 BytecodeNode jump(Bytecode::kJump, 0);
105 optimizer()->WriteJump(&jump, &target); 104 optimizer()->WriteJump(&jump, &target);
106 CHECK_EQ(write_count(), 1); 105 CHECK_EQ(write_count(), 1);
107 CHECK_EQ(jump, last_written()); 106 CHECK_EQ(jump, last_written());
108 107
109 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 108 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
110 optimizer()->Write(&add); 109 optimizer()->Write(&add);
111 CHECK_EQ(write_count(), 1); 110 CHECK_EQ(write_count(), 1);
112 CHECK_EQ(jump, last_written()); 111 CHECK_EQ(jump, last_written());
113 } 112 }
114 113
115 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeStillDeadAfterConditinalJump) { 114 TEST_F(BytecodeDeadCodeOptimizerTest, DeadCodeStillDeadAfterConditinalJump) {
116 BytecodeNode ret(Bytecode::kReturn); 115 BytecodeNode ret(Bytecode::kReturn);
117 optimizer()->Write(&ret); 116 optimizer()->Write(&ret);
118 CHECK_EQ(write_count(), 1); 117 CHECK_EQ(write_count(), 1);
119 CHECK_EQ(ret, last_written()); 118 CHECK_EQ(ret, last_written());
120 119
121 BytecodeLabel target; 120 BytecodeLabel target;
122 BytecodeNode jump(Bytecode::kJumpIfTrue, 0, nullptr); 121 BytecodeNode jump(Bytecode::kJumpIfTrue, 0);
123 optimizer()->WriteJump(&jump, &target); 122 optimizer()->WriteJump(&jump, &target);
124 CHECK_EQ(write_count(), 1); 123 CHECK_EQ(write_count(), 1);
125 CHECK_EQ(ret, last_written()); 124 CHECK_EQ(ret, last_written());
126 125
127 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 126 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
128 optimizer()->Write(&add); 127 optimizer()->Write(&add);
129 CHECK_EQ(write_count(), 1); 128 CHECK_EQ(write_count(), 1);
130 CHECK_EQ(ret, last_written()); 129 CHECK_EQ(ret, last_written());
131 } 130 }
132 131
133 TEST_F(BytecodeDeadCodeOptimizerTest, CodeLiveAfterLabelBind) { 132 TEST_F(BytecodeDeadCodeOptimizerTest, CodeLiveAfterLabelBind) {
134 BytecodeNode ret(Bytecode::kReturn); 133 BytecodeNode ret(Bytecode::kReturn);
135 optimizer()->Write(&ret); 134 optimizer()->Write(&ret);
136 CHECK_EQ(write_count(), 1); 135 CHECK_EQ(write_count(), 1);
137 CHECK_EQ(ret, last_written()); 136 CHECK_EQ(ret, last_written());
138 137
139 BytecodeLabel target; 138 BytecodeLabel target;
140 optimizer()->BindLabel(&target); 139 optimizer()->BindLabel(&target);
141 140
142 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1); 141 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1);
143 optimizer()->Write(&add); 142 optimizer()->Write(&add);
144 CHECK_EQ(write_count(), 2); 143 CHECK_EQ(write_count(), 2);
145 CHECK_EQ(add, last_written()); 144 CHECK_EQ(add, last_written());
146 } 145 }
147 146
148 } // namespace interpreter 147 } // namespace interpreter
149 } // namespace internal 148 } // namespace internal
150 } // namespace v8 149 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698