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

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

Issue 2118183002: [interpeter] Move to table based peephole optimizer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Undo experimental in last patch set. Created 4 years, 5 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/factory.h" 7 #include "src/factory.h"
8 #include "src/interpreter/bytecode-label.h" 8 #include "src/interpreter/bytecode-label.h"
9 #include "src/interpreter/bytecode-peephole-optimizer.h" 9 #include "src/interpreter/bytecode-peephole-optimizer.h"
10 #include "src/interpreter/constant-array-builder.h" 10 #include "src/interpreter/constant-array-builder.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 Flush(); 122 Flush();
123 CHECK_EQ(write_count(), 2); 123 CHECK_EQ(write_count(), 2);
124 CHECK_EQ(add, last_written()); 124 CHECK_EQ(add, last_written());
125 } 125 }
126 126
127 // Tests covering BytecodePeepholeOptimizer::UpdateCurrentBytecode(). 127 // Tests covering BytecodePeepholeOptimizer::UpdateCurrentBytecode().
128 128
129 TEST_F(BytecodePeepholeOptimizerTest, KeepJumpIfToBooleanTrue) { 129 TEST_F(BytecodePeepholeOptimizerTest, KeepJumpIfToBooleanTrue) {
130 BytecodeNode first(Bytecode::kLdaNull); 130 BytecodeNode first(Bytecode::kLdaNull);
131 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3); 131 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3);
132 BytecodeLabel label;
132 optimizer()->Write(&first); 133 optimizer()->Write(&first);
133 CHECK_EQ(write_count(), 0); 134 CHECK_EQ(write_count(), 0);
134 optimizer()->Write(&second); 135 optimizer()->WriteJump(&second, &label);
135 CHECK_EQ(write_count(), 1);
136 CHECK_EQ(last_written(), first);
137 Flush();
138 CHECK_EQ(write_count(), 2); 136 CHECK_EQ(write_count(), 2);
139 CHECK_EQ(last_written(), second); 137 CHECK_EQ(last_written(), second);
140 } 138 }
141 139
142 TEST_F(BytecodePeepholeOptimizerTest, ElideJumpIfToBooleanTrue) { 140 TEST_F(BytecodePeepholeOptimizerTest, ElideJumpIfToBooleanTrue) {
143 BytecodeNode first(Bytecode::kLdaTrue); 141 BytecodeNode first(Bytecode::kLdaTrue);
144 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3); 142 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3);
143 BytecodeLabel label;
145 optimizer()->Write(&first); 144 optimizer()->Write(&first);
146 CHECK_EQ(write_count(), 0); 145 CHECK_EQ(write_count(), 0);
147 optimizer()->Write(&second); 146 optimizer()->WriteJump(&second, &label);
148 CHECK_EQ(write_count(), 1);
149 CHECK_EQ(last_written(), first);
150 Flush();
151 CHECK_EQ(write_count(), 2); 147 CHECK_EQ(write_count(), 2);
152 CHECK_EQ(last_written().bytecode(), Bytecode::kJumpIfTrue); 148 CHECK_EQ(last_written(), second);
153 CHECK_EQ(last_written().operand(0), second.operand(0));
154 } 149 }
155 150
156 TEST_F(BytecodePeepholeOptimizerTest, KeepToBooleanLogicalNot) { 151 TEST_F(BytecodePeepholeOptimizerTest, KeepToBooleanLogicalNot) {
157 BytecodeNode first(Bytecode::kLdaNull); 152 BytecodeNode first(Bytecode::kLdaNull);
158 BytecodeNode second(Bytecode::kToBooleanLogicalNot); 153 BytecodeNode second(Bytecode::kToBooleanLogicalNot);
159 optimizer()->Write(&first); 154 optimizer()->Write(&first);
160 CHECK_EQ(write_count(), 0); 155 CHECK_EQ(write_count(), 0);
161 optimizer()->Write(&second); 156 optimizer()->Write(&second);
162 CHECK_EQ(write_count(), 1); 157 CHECK_EQ(write_count(), 1);
163 CHECK_EQ(last_written(), first); 158 CHECK_EQ(last_written(), first);
(...skipping 28 matching lines...) Expand all
192 Flush(); 187 Flush();
193 CHECK_EQ(write_count(), 2); 188 CHECK_EQ(write_count(), 2);
194 CHECK_EQ(last_written(), second); 189 CHECK_EQ(last_written(), second);
195 } 190 }
196 191
197 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRx) { 192 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRx) {
198 BytecodeLabel label; 193 BytecodeLabel label;
199 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand()); 194 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand());
200 BytecodeNode second(Bytecode::kLdar, Register(0).ToOperand()); 195 BytecodeNode second(Bytecode::kLdar, Register(0).ToOperand());
201 optimizer()->Write(&first); 196 optimizer()->Write(&first);
197 optimizer()->Write(&second);
202 CHECK_EQ(write_count(), 0); 198 CHECK_EQ(write_count(), 0);
203 optimizer()->Write(&second); 199 Flush();
204 CHECK_EQ(write_count(), 1); 200 CHECK_EQ(write_count(), 1);
205 CHECK_EQ(last_written(), first); 201 CHECK_EQ(last_written(), first);
206 Flush();
207 CHECK_EQ(write_count(), 1);
208 } 202 }
209 203
210 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRxStatement) { 204 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRxStatement) {
211 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand()); 205 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand());
212 BytecodeNode second(Bytecode::kLdar, Register(0).ToOperand()); 206 BytecodeNode second(Bytecode::kLdar, Register(0).ToOperand());
213 second.source_info().MakeStatementPosition(0); 207 second.source_info().MakeStatementPosition(0);
214 optimizer()->Write(&first); 208 optimizer()->Write(&first);
215 CHECK_EQ(write_count(), 0); 209 CHECK_EQ(write_count(), 0);
216 optimizer()->Write(&second); 210 optimizer()->Write(&second);
217 CHECK_EQ(write_count(), 1); 211 CHECK_EQ(write_count(), 1);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 CHECK_EQ(last_written(), first); 244 CHECK_EQ(last_written(), first);
251 Flush(); 245 Flush();
252 CHECK_EQ(write_count(), 2); 246 CHECK_EQ(write_count(), 2);
253 CHECK_EQ(last_written(), second); 247 CHECK_EQ(last_written(), second);
254 } 248 }
255 249
256 TEST_F(BytecodePeepholeOptimizerTest, ToNameToName) { 250 TEST_F(BytecodePeepholeOptimizerTest, ToNameToName) {
257 BytecodeNode first(Bytecode::kToName); 251 BytecodeNode first(Bytecode::kToName);
258 BytecodeNode second(Bytecode::kToName); 252 BytecodeNode second(Bytecode::kToName);
259 optimizer()->Write(&first); 253 optimizer()->Write(&first);
254 optimizer()->Write(&second);
260 CHECK_EQ(write_count(), 0); 255 CHECK_EQ(write_count(), 0);
261 optimizer()->Write(&second); 256 Flush();
262 CHECK_EQ(write_count(), 1);
263 CHECK_EQ(last_written(), first); 257 CHECK_EQ(last_written(), first);
264 Flush();
265 CHECK_EQ(write_count(), 1); 258 CHECK_EQ(write_count(), 1);
266 } 259 }
267 260
268 TEST_F(BytecodePeepholeOptimizerTest, TypeOfToName) { 261 TEST_F(BytecodePeepholeOptimizerTest, TypeOfToName) {
269 BytecodeNode first(Bytecode::kTypeOf); 262 BytecodeNode first(Bytecode::kTypeOf);
270 BytecodeNode second(Bytecode::kToName); 263 BytecodeNode second(Bytecode::kToName);
271 optimizer()->Write(&first); 264 optimizer()->Write(&first);
265 optimizer()->Write(&second);
272 CHECK_EQ(write_count(), 0); 266 CHECK_EQ(write_count(), 0);
273 optimizer()->Write(&second); 267 Flush();
274 CHECK_EQ(write_count(), 1); 268 CHECK_EQ(write_count(), 1);
275 CHECK_EQ(last_written(), first); 269 CHECK_EQ(last_written(), first);
276 Flush();
277 CHECK_EQ(write_count(), 1);
278 } 270 }
279 271
280 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantStringToName) { 272 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantStringToName) {
281 Handle<Object> word = 273 Handle<Object> word =
282 isolate()->factory()->NewStringFromStaticChars("optimizing"); 274 isolate()->factory()->NewStringFromStaticChars("optimizing");
283 size_t index = constant_array()->Insert(word); 275 size_t index = constant_array()->Insert(word);
284 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index)); 276 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index));
285 BytecodeNode second(Bytecode::kToName); 277 BytecodeNode second(Bytecode::kToName);
286 optimizer()->Write(&first); 278 optimizer()->Write(&first);
279 optimizer()->Write(&second);
287 CHECK_EQ(write_count(), 0); 280 CHECK_EQ(write_count(), 0);
288 optimizer()->Write(&second); 281 Flush();
289 CHECK_EQ(write_count(), 1); 282 CHECK_EQ(write_count(), 1);
290 CHECK_EQ(last_written(), first); 283 CHECK_EQ(last_written(), first);
291 Flush();
292 CHECK_EQ(write_count(), 1);
293 } 284 }
294 285
295 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantNumberToName) { 286 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantNumberToName) {
296 Handle<Object> word = isolate()->factory()->NewNumber(0.380); 287 Handle<Object> word = isolate()->factory()->NewNumber(0.380);
297 size_t index = constant_array()->Insert(word); 288 size_t index = constant_array()->Insert(word);
298 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index)); 289 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index));
299 BytecodeNode second(Bytecode::kToName); 290 BytecodeNode second(Bytecode::kToName);
300 optimizer()->Write(&first); 291 optimizer()->Write(&first);
301 CHECK_EQ(write_count(), 0); 292 CHECK_EQ(write_count(), 0);
302 optimizer()->Write(&second); 293 optimizer()->Write(&second);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 CHECK_EQ(write_count(), 2); 476 CHECK_EQ(write_count(), 2);
486 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); 477 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar);
487 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); 478 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]);
488 Flush(); 479 Flush();
489 CHECK_EQ(last_written().bytecode(), third.bytecode()); 480 CHECK_EQ(last_written().bytecode(), third.bytecode());
490 } 481 }
491 482
492 } // namespace interpreter 483 } // namespace interpreter
493 } // namespace internal 484 } // namespace internal
494 } // namespace v8 485 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698