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 #include "src/basic-block-profiler.h" | 5 #include "src/basic-block-profiler.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 #include "test/cctest/compiler/codegen-tester.h" | 7 #include "test/cctest/compiler/codegen-tester.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 namespace compiler { | 11 namespace compiler { |
12 | 12 |
13 class BasicBlockProfilerTest : public RawMachineAssemblerTester<int32_t> { | 13 class BasicBlockProfilerTest : public RawMachineAssemblerTester<int32_t> { |
14 public: | 14 public: |
15 BasicBlockProfilerTest() : RawMachineAssemblerTester<int32_t>(kMachInt32) { | 15 BasicBlockProfilerTest() |
| 16 : RawMachineAssemblerTester<int32_t>(MachineType::Int32()) { |
16 FLAG_turbo_profiling = true; | 17 FLAG_turbo_profiling = true; |
17 } | 18 } |
18 | 19 |
19 void ResetCounts() { isolate()->basic_block_profiler()->ResetCounts(); } | 20 void ResetCounts() { isolate()->basic_block_profiler()->ResetCounts(); } |
20 | 21 |
21 void Expect(size_t size, uint32_t* expected) { | 22 void Expect(size_t size, uint32_t* expected) { |
22 CHECK(isolate()->basic_block_profiler()); | 23 CHECK(isolate()->basic_block_profiler()); |
23 const BasicBlockProfiler::DataList* l = | 24 const BasicBlockProfiler::DataList* l = |
24 isolate()->basic_block_profiler()->data_list(); | 25 isolate()->basic_block_profiler()->data_list(); |
25 CHECK_NE(0, static_cast<int>(l->size())); | 26 CHECK_NE(0, static_cast<int>(l->size())); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 75 |
75 | 76 |
76 TEST(ProfileLoop) { | 77 TEST(ProfileLoop) { |
77 BasicBlockProfilerTest m; | 78 BasicBlockProfilerTest m; |
78 | 79 |
79 RawMachineLabel header, body, end; | 80 RawMachineLabel header, body, end; |
80 Node* one = m.Int32Constant(1); | 81 Node* one = m.Int32Constant(1); |
81 m.Goto(&header); | 82 m.Goto(&header); |
82 | 83 |
83 m.Bind(&header); | 84 m.Bind(&header); |
84 Node* count = m.Phi(kMachInt32, m.Parameter(0), one); | 85 Node* count = m.Phi(MachineRepresentation::kWord32, m.Parameter(0), one); |
85 m.Branch(count, &body, &end); | 86 m.Branch(count, &body, &end); |
86 | 87 |
87 m.Bind(&body); | 88 m.Bind(&body); |
88 count->ReplaceInput(1, m.Int32Sub(count, one)); | 89 count->ReplaceInput(1, m.Int32Sub(count, one)); |
89 m.Goto(&header); | 90 m.Goto(&header); |
90 | 91 |
91 m.Bind(&end); | 92 m.Bind(&end); |
92 m.Return(one); | 93 m.Return(one); |
93 | 94 |
94 m.GenerateCode(); | 95 m.GenerateCode(); |
95 { | 96 { |
96 uint32_t expected[] = {0, 0, 0, 0}; | 97 uint32_t expected[] = {0, 0, 0, 0}; |
97 m.Expect(arraysize(expected), expected); | 98 m.Expect(arraysize(expected), expected); |
98 } | 99 } |
99 | 100 |
100 uint32_t runs[] = {0, 1, 500, 10000}; | 101 uint32_t runs[] = {0, 1, 500, 10000}; |
101 for (size_t i = 0; i < arraysize(runs); i++) { | 102 for (size_t i = 0; i < arraysize(runs); i++) { |
102 m.ResetCounts(); | 103 m.ResetCounts(); |
103 CHECK_EQ(1, m.Call(static_cast<int>(runs[i]))); | 104 CHECK_EQ(1, m.Call(static_cast<int>(runs[i]))); |
104 uint32_t expected[] = {1, runs[i] + 1, runs[i], 1}; | 105 uint32_t expected[] = {1, runs[i] + 1, runs[i], 1}; |
105 m.Expect(arraysize(expected), expected); | 106 m.Expect(arraysize(expected), expected); |
106 } | 107 } |
107 } | 108 } |
108 | 109 |
109 } // namespace compiler | 110 } // namespace compiler |
110 } // namespace internal | 111 } // namespace internal |
111 } // namespace v8 | 112 } // namespace v8 |
OLD | NEW |