OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
8 #include "src/compiler/generic-node-inl.h" | 8 #include "src/compiler/generic-node-inl.h" |
9 #include "src/compiler/graph.h" | 9 #include "src/compiler/graph.h" |
10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
11 #include "src/compiler/node.h" | 11 #include "src/compiler/node.h" |
12 #include "src/compiler/operator.h" | 12 #include "src/compiler/operator.h" |
13 #include "src/compiler/schedule.h" | 13 #include "src/compiler/schedule.h" |
14 #include "test/cctest/cctest.h" | 14 #include "test/cctest/cctest.h" |
15 | 15 |
16 using namespace v8::internal; | 16 using namespace v8::internal; |
17 using namespace v8::internal::compiler; | 17 using namespace v8::internal::compiler; |
18 | 18 |
19 static SimpleOperator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, | 19 static SimpleOperator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, |
20 0, 0, "dummy"); | 20 0, 0, "dummy"); |
21 | 21 |
22 TEST(TestScheduleAllocation) { | 22 TEST(TestScheduleAllocation) { |
23 HandleAndZoneScope scope; | 23 HandleAndZoneScope scope; |
24 Schedule schedule(scope.main_zone()); | 24 Schedule schedule(scope.main_zone()); |
25 | 25 |
26 CHECK_NE(NULL, schedule.start()); | 26 CHECK_NE(NULL, schedule.start()); |
27 CHECK_EQ(schedule.start(), *(schedule.all_blocks().begin())); | 27 CHECK_EQ(schedule.start(), schedule.GetBlockById(BasicBlock::Id::FromInt(0))); |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 TEST(TestScheduleAddNode) { | 31 TEST(TestScheduleAddNode) { |
32 HandleAndZoneScope scope; | 32 HandleAndZoneScope scope; |
33 Graph graph(scope.main_zone()); | 33 Graph graph(scope.main_zone()); |
34 Node* n0 = graph.NewNode(&dummy_operator); | 34 Node* n0 = graph.NewNode(&dummy_operator); |
35 Node* n1 = graph.NewNode(&dummy_operator); | 35 Node* n1 = graph.NewNode(&dummy_operator); |
36 | 36 |
37 Schedule schedule(scope.main_zone()); | 37 Schedule schedule(scope.main_zone()); |
(...skipping 13 matching lines...) Expand all Loading... |
51 | 51 |
52 TEST(TestScheduleAddGoto) { | 52 TEST(TestScheduleAddGoto) { |
53 HandleAndZoneScope scope; | 53 HandleAndZoneScope scope; |
54 | 54 |
55 Schedule schedule(scope.main_zone()); | 55 Schedule schedule(scope.main_zone()); |
56 BasicBlock* entry = schedule.start(); | 56 BasicBlock* entry = schedule.start(); |
57 BasicBlock* next = schedule.NewBasicBlock(); | 57 BasicBlock* next = schedule.NewBasicBlock(); |
58 | 58 |
59 schedule.AddGoto(entry, next); | 59 schedule.AddGoto(entry, next); |
60 | 60 |
61 CHECK_EQ(0, entry->PredecessorCount()); | 61 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount())); |
62 CHECK_EQ(1, entry->SuccessorCount()); | 62 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount())); |
63 CHECK_EQ(next, entry->SuccessorAt(0)); | 63 CHECK_EQ(next, entry->SuccessorAt(0)); |
64 | 64 |
65 CHECK_EQ(1, next->PredecessorCount()); | 65 CHECK_EQ(1, static_cast<int>(next->PredecessorCount())); |
66 CHECK_EQ(entry, next->PredecessorAt(0)); | 66 CHECK_EQ(entry, next->PredecessorAt(0)); |
67 CHECK_EQ(0, next->SuccessorCount()); | 67 CHECK_EQ(0, static_cast<int>(next->SuccessorCount())); |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 TEST(TestScheduleAddBranch) { | 71 TEST(TestScheduleAddBranch) { |
72 HandleAndZoneScope scope; | 72 HandleAndZoneScope scope; |
73 Schedule schedule(scope.main_zone()); | 73 Schedule schedule(scope.main_zone()); |
74 | 74 |
75 BasicBlock* entry = schedule.start(); | 75 BasicBlock* entry = schedule.start(); |
76 BasicBlock* tblock = schedule.NewBasicBlock(); | 76 BasicBlock* tblock = schedule.NewBasicBlock(); |
77 BasicBlock* fblock = schedule.NewBasicBlock(); | 77 BasicBlock* fblock = schedule.NewBasicBlock(); |
78 | 78 |
79 Graph graph(scope.main_zone()); | 79 Graph graph(scope.main_zone()); |
80 CommonOperatorBuilder common(scope.main_zone()); | 80 CommonOperatorBuilder common(scope.main_zone()); |
81 Node* n0 = graph.NewNode(&dummy_operator); | 81 Node* n0 = graph.NewNode(&dummy_operator); |
82 Node* b = graph.NewNode(common.Branch(), n0); | 82 Node* b = graph.NewNode(common.Branch(), n0); |
83 | 83 |
84 schedule.AddBranch(entry, b, tblock, fblock); | 84 schedule.AddBranch(entry, b, tblock, fblock); |
85 | 85 |
86 CHECK_EQ(0, entry->PredecessorCount()); | 86 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount())); |
87 CHECK_EQ(2, entry->SuccessorCount()); | 87 CHECK_EQ(2, static_cast<int>(entry->SuccessorCount())); |
88 CHECK_EQ(tblock, entry->SuccessorAt(0)); | 88 CHECK_EQ(tblock, entry->SuccessorAt(0)); |
89 CHECK_EQ(fblock, entry->SuccessorAt(1)); | 89 CHECK_EQ(fblock, entry->SuccessorAt(1)); |
90 | 90 |
91 CHECK_EQ(1, tblock->PredecessorCount()); | 91 CHECK_EQ(1, static_cast<int>(tblock->PredecessorCount())); |
92 CHECK_EQ(entry, tblock->PredecessorAt(0)); | 92 CHECK_EQ(entry, tblock->PredecessorAt(0)); |
93 CHECK_EQ(0, tblock->SuccessorCount()); | 93 CHECK_EQ(0, static_cast<int>(tblock->SuccessorCount())); |
94 | 94 |
95 CHECK_EQ(1, fblock->PredecessorCount()); | 95 CHECK_EQ(1, static_cast<int>(fblock->PredecessorCount())); |
96 CHECK_EQ(entry, fblock->PredecessorAt(0)); | 96 CHECK_EQ(entry, fblock->PredecessorAt(0)); |
97 CHECK_EQ(0, fblock->SuccessorCount()); | 97 CHECK_EQ(0, static_cast<int>(fblock->SuccessorCount())); |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 TEST(TestScheduleAddReturn) { | 101 TEST(TestScheduleAddReturn) { |
102 HandleAndZoneScope scope; | 102 HandleAndZoneScope scope; |
103 Schedule schedule(scope.main_zone()); | 103 Schedule schedule(scope.main_zone()); |
104 Graph graph(scope.main_zone()); | 104 Graph graph(scope.main_zone()); |
105 Node* n0 = graph.NewNode(&dummy_operator); | 105 Node* n0 = graph.NewNode(&dummy_operator); |
106 BasicBlock* entry = schedule.start(); | 106 BasicBlock* entry = schedule.start(); |
107 schedule.AddReturn(entry, n0); | 107 schedule.AddReturn(entry, n0); |
108 | 108 |
109 CHECK_EQ(0, entry->PredecessorCount()); | 109 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount())); |
110 CHECK_EQ(1, entry->SuccessorCount()); | 110 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount())); |
111 CHECK_EQ(schedule.end(), entry->SuccessorAt(0)); | 111 CHECK_EQ(schedule.end(), entry->SuccessorAt(0)); |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 TEST(TestScheduleAddThrow) { | 115 TEST(TestScheduleAddThrow) { |
116 HandleAndZoneScope scope; | 116 HandleAndZoneScope scope; |
117 Schedule schedule(scope.main_zone()); | 117 Schedule schedule(scope.main_zone()); |
118 Graph graph(scope.main_zone()); | 118 Graph graph(scope.main_zone()); |
119 Node* n0 = graph.NewNode(&dummy_operator); | 119 Node* n0 = graph.NewNode(&dummy_operator); |
120 BasicBlock* entry = schedule.start(); | 120 BasicBlock* entry = schedule.start(); |
121 schedule.AddThrow(entry, n0); | 121 schedule.AddThrow(entry, n0); |
122 | 122 |
123 CHECK_EQ(0, entry->PredecessorCount()); | 123 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount())); |
124 CHECK_EQ(1, entry->SuccessorCount()); | 124 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount())); |
125 CHECK_EQ(schedule.end(), entry->SuccessorAt(0)); | 125 CHECK_EQ(schedule.end(), entry->SuccessorAt(0)); |
126 } | 126 } |
127 | 127 |
128 | 128 |
129 TEST(BuildMulNodeGraph) { | 129 TEST(BuildMulNodeGraph) { |
130 HandleAndZoneScope scope; | 130 HandleAndZoneScope scope; |
131 Schedule schedule(scope.main_zone()); | 131 Schedule schedule(scope.main_zone()); |
132 Graph graph(scope.main_zone()); | 132 Graph graph(scope.main_zone()); |
133 CommonOperatorBuilder common(scope.main_zone()); | 133 CommonOperatorBuilder common(scope.main_zone()); |
134 MachineOperatorBuilder machine; | 134 MachineOperatorBuilder machine; |
135 | 135 |
136 Node* start = graph.NewNode(common.Start(0)); | 136 Node* start = graph.NewNode(common.Start(0)); |
137 graph.SetStart(start); | 137 graph.SetStart(start); |
138 Node* param0 = graph.NewNode(common.Parameter(0), graph.start()); | 138 Node* param0 = graph.NewNode(common.Parameter(0), graph.start()); |
139 Node* param1 = graph.NewNode(common.Parameter(1), graph.start()); | 139 Node* param1 = graph.NewNode(common.Parameter(1), graph.start()); |
140 | 140 |
141 Node* mul = graph.NewNode(machine.Int32Mul(), param0, param1); | 141 Node* mul = graph.NewNode(machine.Int32Mul(), param0, param1); |
142 Node* ret = graph.NewNode(common.Return(), mul, start); | 142 Node* ret = graph.NewNode(common.Return(), mul, start); |
143 | 143 |
144 USE(ret); | 144 USE(ret); |
145 } | 145 } |
OLD | NEW |