| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
| 6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 7 | 7 |
| 8 #include "src/basic-block-profiler.h" | 8 #include "src/basic-block-profiler.h" |
| 9 #include "test/cctest/cctest.h" | 9 #include "test/cctest/cctest.h" |
| 10 #include "test/cctest/compiler/codegen-tester.h" | 10 #include "test/cctest/compiler/codegen-tester.h" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 namespace compiler { | 14 namespace compiler { |
| 15 | 15 |
| 16 typedef RawMachineAssembler::Label MLabel; | |
| 17 | |
| 18 class BasicBlockProfilerTest : public RawMachineAssemblerTester<int32_t> { | 16 class BasicBlockProfilerTest : public RawMachineAssemblerTester<int32_t> { |
| 19 public: | 17 public: |
| 20 BasicBlockProfilerTest() : RawMachineAssemblerTester<int32_t>(kMachInt32) { | 18 BasicBlockProfilerTest() : RawMachineAssemblerTester<int32_t>(kMachInt32) { |
| 21 FLAG_turbo_profiling = true; | 19 FLAG_turbo_profiling = true; |
| 22 } | 20 } |
| 23 | 21 |
| 24 void ResetCounts() { isolate()->basic_block_profiler()->ResetCounts(); } | 22 void ResetCounts() { isolate()->basic_block_profiler()->ResetCounts(); } |
| 25 | 23 |
| 26 void Expect(size_t size, uint32_t* expected) { | 24 void Expect(size_t size, uint32_t* expected) { |
| 27 CHECK(isolate()->basic_block_profiler()); | 25 CHECK(isolate()->basic_block_profiler()); |
| 28 const BasicBlockProfiler::DataList* l = | 26 const BasicBlockProfiler::DataList* l = |
| 29 isolate()->basic_block_profiler()->data_list(); | 27 isolate()->basic_block_profiler()->data_list(); |
| 30 CHECK_NE(0, static_cast<int>(l->size())); | 28 CHECK_NE(0, static_cast<int>(l->size())); |
| 31 const BasicBlockProfiler::Data* data = l->back(); | 29 const BasicBlockProfiler::Data* data = l->back(); |
| 32 CHECK_EQ(static_cast<int>(size), static_cast<int>(data->n_blocks())); | 30 CHECK_EQ(static_cast<int>(size), static_cast<int>(data->n_blocks())); |
| 33 const uint32_t* counts = data->counts(); | 31 const uint32_t* counts = data->counts(); |
| 34 for (size_t i = 0; i < size; ++i) { | 32 for (size_t i = 0; i < size; ++i) { |
| 35 CHECK_EQ(static_cast<int>(expected[i]), static_cast<int>(counts[i])); | 33 CHECK_EQ(static_cast<int>(expected[i]), static_cast<int>(counts[i])); |
| 36 } | 34 } |
| 37 } | 35 } |
| 38 }; | 36 }; |
| 39 | 37 |
| 40 | 38 |
| 41 TEST(ProfileDiamond) { | 39 TEST(ProfileDiamond) { |
| 42 BasicBlockProfilerTest m; | 40 BasicBlockProfilerTest m; |
| 43 | 41 |
| 44 MLabel blocka, blockb, end; | 42 RawMachineLabel blocka, blockb, end; |
| 45 m.Branch(m.Parameter(0), &blocka, &blockb); | 43 m.Branch(m.Parameter(0), &blocka, &blockb); |
| 46 m.Bind(&blocka); | 44 m.Bind(&blocka); |
| 47 m.Goto(&end); | 45 m.Goto(&end); |
| 48 m.Bind(&blockb); | 46 m.Bind(&blockb); |
| 49 m.Goto(&end); | 47 m.Goto(&end); |
| 50 m.Bind(&end); | 48 m.Bind(&end); |
| 51 m.Return(m.Int32Constant(0)); | 49 m.Return(m.Int32Constant(0)); |
| 52 | 50 |
| 53 m.GenerateCode(); | 51 m.GenerateCode(); |
| 54 { | 52 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 74 { | 72 { |
| 75 uint32_t expected[] = {2, 1, 1, 2}; | 73 uint32_t expected[] = {2, 1, 1, 2}; |
| 76 m.Expect(arraysize(expected), expected); | 74 m.Expect(arraysize(expected), expected); |
| 77 } | 75 } |
| 78 } | 76 } |
| 79 | 77 |
| 80 | 78 |
| 81 TEST(ProfileLoop) { | 79 TEST(ProfileLoop) { |
| 82 BasicBlockProfilerTest m; | 80 BasicBlockProfilerTest m; |
| 83 | 81 |
| 84 MLabel header, body, end; | 82 RawMachineLabel header, body, end; |
| 85 Node* one = m.Int32Constant(1); | 83 Node* one = m.Int32Constant(1); |
| 86 m.Goto(&header); | 84 m.Goto(&header); |
| 87 | 85 |
| 88 m.Bind(&header); | 86 m.Bind(&header); |
| 89 Node* count = m.Phi(kMachInt32, m.Parameter(0), one); | 87 Node* count = m.Phi(kMachInt32, m.Parameter(0), one); |
| 90 m.Branch(count, &body, &end); | 88 m.Branch(count, &body, &end); |
| 91 | 89 |
| 92 m.Bind(&body); | 90 m.Bind(&body); |
| 93 count->ReplaceInput(1, m.Int32Sub(count, one)); | 91 count->ReplaceInput(1, m.Int32Sub(count, one)); |
| 94 m.Goto(&header); | 92 m.Goto(&header); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 107 m.ResetCounts(); | 105 m.ResetCounts(); |
| 108 CHECK_EQ(1, m.Call(static_cast<int>(runs[i]))); | 106 CHECK_EQ(1, m.Call(static_cast<int>(runs[i]))); |
| 109 uint32_t expected[] = {1, runs[i] + 1, runs[i], 1}; | 107 uint32_t expected[] = {1, runs[i] + 1, runs[i], 1}; |
| 110 m.Expect(arraysize(expected), expected); | 108 m.Expect(arraysize(expected), expected); |
| 111 } | 109 } |
| 112 } | 110 } |
| 113 | 111 |
| 114 } // namespace compiler | 112 } // namespace compiler |
| 115 } // namespace internal | 113 } // namespace internal |
| 116 } // namespace v8 | 114 } // namespace v8 |
| OLD | NEW |