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

Side by Side Diff: test/unittests/compiler/move-optimizer-unittest.cc

Issue 1041163002: [turbofan] smash GapInstruction into Instruction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: arm compile Created 5 years, 8 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
« no previous file with comments | « test/cctest/compiler/test-jump-threading.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/compiler/move-optimizer.h" 5 #include "src/compiler/move-optimizer.h"
6 #include "test/unittests/compiler/instruction-sequence-unittest.h" 6 #include "test/unittests/compiler/instruction-sequence-unittest.h"
7 7
8 namespace v8 { 8 namespace v8 {
9 namespace internal { 9 namespace internal {
10 namespace compiler { 10 namespace compiler {
11 11
12 class MoveOptimizerTest : public InstructionSequenceTest { 12 class MoveOptimizerTest : public InstructionSequenceTest {
13 public: 13 public:
14 GapInstruction* LastGap() { 14 Instruction* LastInstruction() { return sequence()->instructions().back(); }
15 return GapInstruction::cast(*(sequence()->instructions().rbegin() + 1));
16 }
17 15
18 void AddMove(GapInstruction* gap, TestOperand from, TestOperand to, 16 void AddMove(Instruction* instr, TestOperand from, TestOperand to,
19 GapInstruction::InnerPosition pos = GapInstruction::START) { 17 Instruction::GapPosition pos = Instruction::START) {
20 auto parallel_move = gap->GetOrCreateParallelMove(pos, zone()); 18 auto parallel_move = instr->GetOrCreateParallelMove(pos, zone());
21 parallel_move->AddMove(ConvertMoveArg(from), ConvertMoveArg(to), zone()); 19 parallel_move->AddMove(ConvertMoveArg(from), ConvertMoveArg(to), zone());
22 } 20 }
23 21
24 int NonRedundantSize(ParallelMove* move) { 22 int NonRedundantSize(ParallelMove* move) {
25 int i = 0; 23 int i = 0;
26 auto ops = move->move_operands(); 24 auto ops = move->move_operands();
27 for (auto op = ops->begin(); op != ops->end(); ++op) { 25 for (auto op = ops->begin(); op != ops->end(); ++op) {
28 if (op->IsRedundant()) continue; 26 if (op->IsRedundant()) continue;
29 i++; 27 i++;
30 } 28 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 break; 77 break;
80 } 78 }
81 CHECK(false); 79 CHECK(false);
82 return nullptr; 80 return nullptr;
83 } 81 }
84 }; 82 };
85 83
86 84
87 TEST_F(MoveOptimizerTest, RemovesRedundant) { 85 TEST_F(MoveOptimizerTest, RemovesRedundant) {
88 StartBlock(); 86 StartBlock();
89 EmitNop(); 87 auto first_instr = EmitNop();
90 AddMove(LastGap(), Reg(0), Reg(1)); 88 AddMove(first_instr, Reg(0), Reg(1));
91 EmitNop(); 89 auto last_instr = EmitNop();
92 AddMove(LastGap(), Reg(1), Reg(0)); 90 AddMove(last_instr, Reg(1), Reg(0));
93 EndBlock(Last()); 91 EndBlock(Last());
94 92
95 Optimize(); 93 Optimize();
96 94
97 auto gap = LastGap(); 95 CHECK_EQ(0, NonRedundantSize(first_instr->parallel_moves()[0]));
98 auto move = gap->parallel_moves()[0]; 96 auto move = last_instr->parallel_moves()[0];
99 CHECK_EQ(1, NonRedundantSize(move)); 97 CHECK_EQ(1, NonRedundantSize(move));
100 CHECK(Contains(move, Reg(0), Reg(1))); 98 CHECK(Contains(move, Reg(0), Reg(1)));
101 } 99 }
102 100
103 101
104 TEST_F(MoveOptimizerTest, SplitsConstants) { 102 TEST_F(MoveOptimizerTest, SplitsConstants) {
105 StartBlock(); 103 StartBlock();
106 EndBlock(Last()); 104 EndBlock(Last());
107 105
108 auto gap = LastGap(); 106 auto gap = LastInstruction();
109 AddMove(gap, Const(1), Slot(0)); 107 AddMove(gap, Const(1), Slot(0));
110 AddMove(gap, Const(1), Slot(1)); 108 AddMove(gap, Const(1), Slot(1));
111 AddMove(gap, Const(1), Reg(0)); 109 AddMove(gap, Const(1), Reg(0));
112 AddMove(gap, Const(1), Slot(2)); 110 AddMove(gap, Const(1), Slot(2));
113 111
114 Optimize(); 112 Optimize();
115 113
116 auto move = gap->parallel_moves()[0]; 114 auto move = gap->parallel_moves()[0];
117 CHECK_EQ(1, NonRedundantSize(move)); 115 CHECK_EQ(1, NonRedundantSize(move));
118 CHECK(Contains(move, Const(1), Reg(0))); 116 CHECK(Contains(move, Const(1), Reg(0)));
119 117
120 move = gap->parallel_moves()[1]; 118 move = gap->parallel_moves()[1];
121 CHECK_EQ(3, NonRedundantSize(move)); 119 CHECK_EQ(3, NonRedundantSize(move));
122 CHECK(Contains(move, Reg(0), Slot(0))); 120 CHECK(Contains(move, Reg(0), Slot(0)));
123 CHECK(Contains(move, Reg(0), Slot(1))); 121 CHECK(Contains(move, Reg(0), Slot(1)));
124 CHECK(Contains(move, Reg(0), Slot(2))); 122 CHECK(Contains(move, Reg(0), Slot(2)));
125 } 123 }
126 124
127 125
128 TEST_F(MoveOptimizerTest, SimpleMerge) { 126 TEST_F(MoveOptimizerTest, SimpleMerge) {
129 StartBlock(); 127 StartBlock();
130 EndBlock(Branch(Imm(), 1, 2)); 128 EndBlock(Branch(Imm(), 1, 2));
131 129
132 StartBlock(); 130 StartBlock();
133 EndBlock(Jump(2)); 131 EndBlock(Jump(2));
134 AddMove(LastGap(), Reg(0), Reg(1)); 132 AddMove(LastInstruction(), Reg(0), Reg(1));
135 133
136 StartBlock(); 134 StartBlock();
137 EndBlock(Jump(1)); 135 EndBlock(Jump(1));
138 AddMove(LastGap(), Reg(0), Reg(1)); 136 AddMove(LastInstruction(), Reg(0), Reg(1));
139 137
140 StartBlock(); 138 StartBlock();
141 EndBlock(Last()); 139 EndBlock(Last());
142 140
143 Optimize(); 141 Optimize();
144 142
145 auto move = LastGap()->parallel_moves()[0]; 143 auto move = LastInstruction()->parallel_moves()[0];
146 CHECK_EQ(1, NonRedundantSize(move)); 144 CHECK_EQ(1, NonRedundantSize(move));
147 CHECK(Contains(move, Reg(0), Reg(1))); 145 CHECK(Contains(move, Reg(0), Reg(1)));
148 } 146 }
149 147
150 148
151 TEST_F(MoveOptimizerTest, SimpleMergeCycle) { 149 TEST_F(MoveOptimizerTest, SimpleMergeCycle) {
152 StartBlock(); 150 StartBlock();
153 EndBlock(Branch(Imm(), 1, 2)); 151 EndBlock(Branch(Imm(), 1, 2));
154 152
155 StartBlock(); 153 StartBlock();
156 EndBlock(Jump(2)); 154 EndBlock(Jump(2));
157 auto gap_0 = LastGap(); 155 auto gap_0 = LastInstruction();
158 AddMove(gap_0, Reg(0), Reg(1)); 156 AddMove(gap_0, Reg(0), Reg(1));
159 AddMove(LastGap(), Reg(1), Reg(0)); 157 AddMove(LastInstruction(), Reg(1), Reg(0));
160 158
161 StartBlock(); 159 StartBlock();
162 EndBlock(Jump(1)); 160 EndBlock(Jump(1));
163 auto gap_1 = LastGap(); 161 auto gap_1 = LastInstruction();
164 AddMove(gap_1, Reg(0), Reg(1)); 162 AddMove(gap_1, Reg(0), Reg(1));
165 AddMove(gap_1, Reg(1), Reg(0)); 163 AddMove(gap_1, Reg(1), Reg(0));
166 164
167 StartBlock(); 165 StartBlock();
168 EndBlock(Last()); 166 EndBlock(Last());
169 167
170 Optimize(); 168 Optimize();
171 169
172 CHECK(gap_0->IsRedundant()); 170 CHECK(gap_0->AreMovesRedundant());
173 CHECK(gap_1->IsRedundant()); 171 CHECK(gap_1->AreMovesRedundant());
174 auto move = LastGap()->parallel_moves()[0]; 172 auto move = LastInstruction()->parallel_moves()[0];
175 CHECK_EQ(2, NonRedundantSize(move)); 173 CHECK_EQ(2, NonRedundantSize(move));
176 CHECK(Contains(move, Reg(0), Reg(1))); 174 CHECK(Contains(move, Reg(0), Reg(1)));
177 CHECK(Contains(move, Reg(1), Reg(0))); 175 CHECK(Contains(move, Reg(1), Reg(0)));
178 } 176 }
179 177
180 } // namespace compiler 178 } // namespace compiler
181 } // namespace internal 179 } // namespace internal
182 } // namespace v8 180 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-jump-threading.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698