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

Side by Side Diff: test/cctest/compiler/test-schedule.cc

Issue 675983002: Add Schedule::InsertBranch to fuse control flow graphs. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Jaro. Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/schedule.cc ('k') | test/cctest/compiler/test-scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 12 matching lines...) Expand all
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.GetBlockById(BasicBlock::Id::FromInt(0))); 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 Schedule schedule(scope.main_zone());
33 Graph graph(scope.main_zone()); 34 Graph graph(scope.main_zone());
34 Node* n0 = graph.NewNode(&dummy_operator); 35 Node* n0 = graph.NewNode(&dummy_operator);
35 Node* n1 = graph.NewNode(&dummy_operator); 36 Node* n1 = graph.NewNode(&dummy_operator);
36 37
37 Schedule schedule(scope.main_zone());
38
39 BasicBlock* entry = schedule.start(); 38 BasicBlock* entry = schedule.start();
40 schedule.AddNode(entry, n0); 39 schedule.AddNode(entry, n0);
41 schedule.AddNode(entry, n1); 40 schedule.AddNode(entry, n1);
42 41
43 CHECK_EQ(entry, schedule.block(n0)); 42 CHECK_EQ(entry, schedule.block(n0));
44 CHECK_EQ(entry, schedule.block(n1)); 43 CHECK_EQ(entry, schedule.block(n1));
45 CHECK(schedule.SameBasicBlock(n0, n1)); 44 CHECK(schedule.SameBasicBlock(n0, n1));
46 45
47 Node* n2 = graph.NewNode(&dummy_operator); 46 Node* n2 = graph.NewNode(&dummy_operator);
48 CHECK_EQ(NULL, schedule.block(n2)); 47 CHECK_EQ(NULL, schedule.block(n2));
49 } 48 }
50 49
51 50
52 TEST(TestScheduleAddGoto) { 51 TEST(TestScheduleAddGoto) {
53 HandleAndZoneScope scope; 52 HandleAndZoneScope scope;
53 Schedule schedule(scope.main_zone());
54 54
55 Schedule schedule(scope.main_zone());
56 BasicBlock* entry = schedule.start(); 55 BasicBlock* entry = schedule.start();
57 BasicBlock* next = schedule.NewBasicBlock(); 56 BasicBlock* next = schedule.NewBasicBlock();
58 57
59 schedule.AddGoto(entry, next); 58 schedule.AddGoto(entry, next);
60 59
61 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount())); 60 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
62 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount())); 61 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount()));
63 CHECK_EQ(next, entry->SuccessorAt(0)); 62 CHECK_EQ(next, entry->SuccessorAt(0));
64 63
65 CHECK_EQ(1, static_cast<int>(next->PredecessorCount())); 64 CHECK_EQ(1, static_cast<int>(next->PredecessorCount()));
66 CHECK_EQ(entry, next->PredecessorAt(0)); 65 CHECK_EQ(entry, next->PredecessorAt(0));
67 CHECK_EQ(0, static_cast<int>(next->SuccessorCount())); 66 CHECK_EQ(0, static_cast<int>(next->SuccessorCount()));
68 } 67 }
69 68
70 69
71 TEST(TestScheduleAddBranch) { 70 TEST(TestScheduleAddBranch) {
72 HandleAndZoneScope scope; 71 HandleAndZoneScope scope;
73 Schedule schedule(scope.main_zone()); 72 Schedule schedule(scope.main_zone());
73 Graph graph(scope.main_zone());
74 CommonOperatorBuilder common(scope.main_zone());
75 Node* n0 = graph.NewNode(&dummy_operator);
76 Node* b = graph.NewNode(common.Branch(), n0);
74 77
75 BasicBlock* entry = schedule.start(); 78 BasicBlock* entry = schedule.start();
76 BasicBlock* tblock = schedule.NewBasicBlock(); 79 BasicBlock* tblock = schedule.NewBasicBlock();
77 BasicBlock* fblock = schedule.NewBasicBlock(); 80 BasicBlock* fblock = schedule.NewBasicBlock();
78 81
79 Graph graph(scope.main_zone());
80 CommonOperatorBuilder common(scope.main_zone());
81 Node* n0 = graph.NewNode(&dummy_operator);
82 Node* b = graph.NewNode(common.Branch(), n0);
83
84 schedule.AddBranch(entry, b, tblock, fblock); 82 schedule.AddBranch(entry, b, tblock, fblock);
85 83
86 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount())); 84 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
87 CHECK_EQ(2, static_cast<int>(entry->SuccessorCount())); 85 CHECK_EQ(2, static_cast<int>(entry->SuccessorCount()));
88 CHECK_EQ(tblock, entry->SuccessorAt(0)); 86 CHECK_EQ(tblock, entry->SuccessorAt(0));
89 CHECK_EQ(fblock, entry->SuccessorAt(1)); 87 CHECK_EQ(fblock, entry->SuccessorAt(1));
90 88
91 CHECK_EQ(1, static_cast<int>(tblock->PredecessorCount())); 89 CHECK_EQ(1, static_cast<int>(tblock->PredecessorCount()));
92 CHECK_EQ(entry, tblock->PredecessorAt(0)); 90 CHECK_EQ(entry, tblock->PredecessorAt(0));
93 CHECK_EQ(0, static_cast<int>(tblock->SuccessorCount())); 91 CHECK_EQ(0, static_cast<int>(tblock->SuccessorCount()));
(...skipping 25 matching lines...) Expand all
119 Node* n0 = graph.NewNode(&dummy_operator); 117 Node* n0 = graph.NewNode(&dummy_operator);
120 BasicBlock* entry = schedule.start(); 118 BasicBlock* entry = schedule.start();
121 schedule.AddThrow(entry, n0); 119 schedule.AddThrow(entry, n0);
122 120
123 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount())); 121 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
124 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount())); 122 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount()));
125 CHECK_EQ(schedule.end(), entry->SuccessorAt(0)); 123 CHECK_EQ(schedule.end(), entry->SuccessorAt(0));
126 } 124 }
127 125
128 126
127 TEST(TestScheduleInsertBranch) {
128 HandleAndZoneScope scope;
129 Schedule schedule(scope.main_zone());
130 Graph graph(scope.main_zone());
131 CommonOperatorBuilder common(scope.main_zone());
132 Node* n0 = graph.NewNode(&dummy_operator);
133 Node* n1 = graph.NewNode(&dummy_operator);
134 Node* b = graph.NewNode(common.Branch(), n1);
135
136 BasicBlock* entry = schedule.start();
137 BasicBlock* tblock = schedule.NewBasicBlock();
138 BasicBlock* fblock = schedule.NewBasicBlock();
139 BasicBlock* merge = schedule.NewBasicBlock();
140 schedule.AddReturn(entry, n0);
141 schedule.AddGoto(tblock, merge);
142 schedule.AddGoto(fblock, merge);
143
144 schedule.InsertBranch(entry, merge, b, tblock, fblock);
145
146 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
147 CHECK_EQ(2, static_cast<int>(entry->SuccessorCount()));
148 CHECK_EQ(tblock, entry->SuccessorAt(0));
149 CHECK_EQ(fblock, entry->SuccessorAt(1));
150
151 CHECK_EQ(2, static_cast<int>(merge->PredecessorCount()));
152 CHECK_EQ(1, static_cast<int>(merge->SuccessorCount()));
153 CHECK_EQ(schedule.end(), merge->SuccessorAt(0));
154
155 CHECK_EQ(1, static_cast<int>(schedule.end()->PredecessorCount()));
156 CHECK_EQ(0, static_cast<int>(schedule.end()->SuccessorCount()));
157 CHECK_EQ(merge, schedule.end()->PredecessorAt(0));
158 }
159
160
129 TEST(BuildMulNodeGraph) { 161 TEST(BuildMulNodeGraph) {
130 HandleAndZoneScope scope; 162 HandleAndZoneScope scope;
131 Schedule schedule(scope.main_zone()); 163 Schedule schedule(scope.main_zone());
132 Graph graph(scope.main_zone()); 164 Graph graph(scope.main_zone());
133 CommonOperatorBuilder common(scope.main_zone()); 165 CommonOperatorBuilder common(scope.main_zone());
134 MachineOperatorBuilder machine; 166 MachineOperatorBuilder machine;
135 167
136 Node* start = graph.NewNode(common.Start(0)); 168 Node* start = graph.NewNode(common.Start(0));
137 graph.SetStart(start); 169 graph.SetStart(start);
138 Node* param0 = graph.NewNode(common.Parameter(0), graph.start()); 170 Node* param0 = graph.NewNode(common.Parameter(0), graph.start());
139 Node* param1 = graph.NewNode(common.Parameter(1), graph.start()); 171 Node* param1 = graph.NewNode(common.Parameter(1), graph.start());
140 172
141 Node* mul = graph.NewNode(machine.Int32Mul(), param0, param1); 173 Node* mul = graph.NewNode(machine.Int32Mul(), param0, param1);
142 Node* ret = graph.NewNode(common.Return(), mul, start); 174 Node* ret = graph.NewNode(common.Return(), mul, start);
143 175
144 USE(ret); 176 USE(ret);
145 } 177 }
OLDNEW
« no previous file with comments | « src/compiler/schedule.cc ('k') | test/cctest/compiler/test-scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698