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

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

Issue 2238853002: [Interpreter] Remove LdaConstant+ToName peephole optimization. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_internalize
Patch Set: Created 4 years, 4 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"
Michael Starzinger 2016/08/11 13:19:15 nit: Header file inclusion is obsolete. Lets drop
rmcilroy 2016/08/11 14:46:17 Done.
11 #include "src/objects-inl.h" 11 #include "src/objects-inl.h"
12 #include "src/objects.h" 12 #include "src/objects.h"
13 #include "test/unittests/test-utils.h" 13 #include "test/unittests/test-utils.h"
14 14
15 namespace v8 { 15 namespace v8 {
16 namespace internal { 16 namespace internal {
17 namespace interpreter { 17 namespace interpreter {
18 18
19 class BytecodePeepholeOptimizerTest : public BytecodePipelineStage, 19 class BytecodePeepholeOptimizerTest : public BytecodePipelineStage,
20 public TestWithIsolateAndZone { 20 public TestWithIsolateAndZone {
21 public: 21 public:
22 BytecodePeepholeOptimizerTest() 22 BytecodePeepholeOptimizerTest() : peephole_optimizer_(this) {}
23 : constant_array_builder_(isolate(), zone()),
24 peephole_optimizer_(&constant_array_builder_, this) {}
25 ~BytecodePeepholeOptimizerTest() override {} 23 ~BytecodePeepholeOptimizerTest() override {}
26 24
27 void Reset() { 25 void Reset() {
28 last_written_.set_bytecode(Bytecode::kIllegal); 26 last_written_.set_bytecode(Bytecode::kIllegal);
29 write_count_ = 0; 27 write_count_ = 0;
30 } 28 }
31 29
32 void Write(BytecodeNode* node) override { 30 void Write(BytecodeNode* node) override {
33 write_count_++; 31 write_count_++;
34 last_written_.Clone(node); 32 last_written_.Clone(node);
(...skipping 10 matching lines...) Expand all
45 int fixed_register_count, int parameter_count, 43 int fixed_register_count, int parameter_count,
46 Handle<FixedArray> handle_table) override { 44 Handle<FixedArray> handle_table) override {
47 return Handle<BytecodeArray>(); 45 return Handle<BytecodeArray>();
48 } 46 }
49 47
50 void Flush() { 48 void Flush() {
51 optimizer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array()); 49 optimizer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array());
52 } 50 }
53 51
54 BytecodePeepholeOptimizer* optimizer() { return &peephole_optimizer_; } 52 BytecodePeepholeOptimizer* optimizer() { return &peephole_optimizer_; }
55 ConstantArrayBuilder* constant_array() { return &constant_array_builder_; }
56 53
57 int write_count() const { return write_count_; } 54 int write_count() const { return write_count_; }
58 const BytecodeNode& last_written() const { return last_written_; } 55 const BytecodeNode& last_written() const { return last_written_; }
59 56
60 private: 57 private:
61 ConstantArrayBuilder constant_array_builder_;
62 BytecodePeepholeOptimizer peephole_optimizer_; 58 BytecodePeepholeOptimizer peephole_optimizer_;
63 59
64 int write_count_ = 0; 60 int write_count_ = 0;
65 BytecodeNode last_written_; 61 BytecodeNode last_written_;
66 }; 62 };
67 63
68 // Sanity tests. 64 // Sanity tests.
69 65
70 TEST_F(BytecodePeepholeOptimizerTest, FlushOnJump) { 66 TEST_F(BytecodePeepholeOptimizerTest, FlushOnJump) {
71 CHECK_EQ(write_count(), 0); 67 CHECK_EQ(write_count(), 0);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 CHECK_EQ(write_count(), 0); 255 CHECK_EQ(write_count(), 0);
260 optimizer()->Write(&second); 256 optimizer()->Write(&second);
261 CHECK_EQ(write_count(), 1); 257 CHECK_EQ(write_count(), 1);
262 CHECK_EQ(last_written(), first); 258 CHECK_EQ(last_written(), first);
263 Flush(); 259 Flush();
264 CHECK_EQ(write_count(), 2); 260 CHECK_EQ(write_count(), 2);
265 CHECK_EQ(last_written(), second); 261 CHECK_EQ(last_written(), second);
266 CHECK_EQ(last_written().bytecode(), Bytecode::kStar); 262 CHECK_EQ(last_written().bytecode(), Bytecode::kStar);
267 } 263 }
268 264
269 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantStringToName) {
270 Handle<Object> word =
271 isolate()->factory()->NewStringFromStaticChars("optimizing");
272 size_t index = constant_array()->Insert(word);
273 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index));
274 BytecodeNode second(Bytecode::kToName, Register(0).ToOperand());
275 optimizer()->Write(&first);
276 CHECK_EQ(write_count(), 0);
277 optimizer()->Write(&second);
278 CHECK_EQ(write_count(), 1);
279 CHECK_EQ(last_written(), first);
280 Flush();
281 CHECK_EQ(write_count(), 2);
282 CHECK_EQ(last_written(), second);
283 CHECK_EQ(last_written().bytecode(), Bytecode::kStar);
284 }
285
286 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantNumberToName) {
287 Handle<Object> word = isolate()->factory()->NewNumber(0.380);
288 size_t index = constant_array()->Insert(word);
289 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index));
290 BytecodeNode second(Bytecode::kToName, Register(0).ToOperand());
291 optimizer()->Write(&first);
292 CHECK_EQ(write_count(), 0);
293 optimizer()->Write(&second);
294 CHECK_EQ(write_count(), 1);
295 CHECK_EQ(last_written(), first);
296 Flush();
297 CHECK_EQ(write_count(), 2);
298 CHECK_EQ(last_written(), second);
299 }
300
301 // Tests covering BytecodePeepholeOptimizer::CanElideLast(). 265 // Tests covering BytecodePeepholeOptimizer::CanElideLast().
302 266
303 TEST_F(BytecodePeepholeOptimizerTest, LdaTrueLdaFalse) { 267 TEST_F(BytecodePeepholeOptimizerTest, LdaTrueLdaFalse) {
304 BytecodeNode first(Bytecode::kLdaTrue); 268 BytecodeNode first(Bytecode::kLdaTrue);
305 BytecodeNode second(Bytecode::kLdaFalse); 269 BytecodeNode second(Bytecode::kLdaFalse);
306 optimizer()->Write(&first); 270 optimizer()->Write(&first);
307 CHECK_EQ(write_count(), 0); 271 CHECK_EQ(write_count(), 0);
308 optimizer()->Write(&second); 272 optimizer()->Write(&second);
309 CHECK_EQ(write_count(), 0); 273 CHECK_EQ(write_count(), 0);
310 Flush(); 274 Flush();
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 CHECK_EQ(last_written().operand_count(), 2); 518 CHECK_EQ(last_written().operand_count(), 2);
555 CHECK_EQ(last_written().operand(0), 0); 519 CHECK_EQ(last_written().operand(0), 0);
556 CHECK_EQ(last_written().operand(1), reg_operand); 520 CHECK_EQ(last_written().operand(1), reg_operand);
557 Reset(); 521 Reset();
558 } 522 }
559 } 523 }
560 524
561 } // namespace interpreter 525 } // namespace interpreter
562 } // namespace internal 526 } // namespace internal
563 } // namespace v8 527 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698