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

Side by Side Diff: src/compiler/move-optimizer.cc

Issue 1111323003: Reland: [turbofan] add MachineType to AllocatedOperand (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 5 years, 7 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 | « src/compiler/instruction-selector-impl.h ('k') | src/compiler/register-allocator.h » ('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 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 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace compiler { 9 namespace compiler {
10 10
11 namespace { 11 namespace {
12 12
13 typedef std::pair<InstructionOperand, InstructionOperand> MoveKey; 13 typedef std::pair<InstructionOperand, InstructionOperand> MoveKey;
14 typedef ZoneMap<MoveKey, unsigned> MoveMap; 14
15 typedef ZoneSet<InstructionOperand> OperandSet; 15 struct MoveKeyCompare {
16 bool operator()(const MoveKey& a, const MoveKey& b) const {
17 if (a.first.EqualsModuloType(b.first)) {
18 return a.second.CompareModuloType(b.second);
19 }
20 return a.first.CompareModuloType(b.first);
21 }
22 };
23
24 typedef ZoneMap<MoveKey, unsigned, MoveKeyCompare> MoveMap;
25 typedef ZoneSet<InstructionOperand, CompareOperandModuloType> OperandSet;
16 26
17 27
18 bool GapsCanMoveOver(Instruction* instr) { return instr->IsNop(); } 28 bool GapsCanMoveOver(Instruction* instr) { return instr->IsNop(); }
19 29
20 30
21 int FindFirstNonEmptySlot(Instruction* instr) { 31 int FindFirstNonEmptySlot(Instruction* instr) {
22 int i = Instruction::FIRST_GAP_POSITION; 32 int i = Instruction::FIRST_GAP_POSITION;
23 for (; i <= Instruction::LAST_GAP_POSITION; i++) { 33 for (; i <= Instruction::LAST_GAP_POSITION; i++) {
24 auto moves = instr->parallel_moves()[i]; 34 auto moves = instr->parallel_moves()[i];
25 if (moves == nullptr) continue; 35 if (moves == nullptr) continue;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 227
218 228
219 namespace { 229 namespace {
220 230
221 bool IsSlot(const InstructionOperand& op) { 231 bool IsSlot(const InstructionOperand& op) {
222 return op.IsStackSlot() || op.IsDoubleStackSlot(); 232 return op.IsStackSlot() || op.IsDoubleStackSlot();
223 } 233 }
224 234
225 235
226 bool LoadCompare(const MoveOperands* a, const MoveOperands* b) { 236 bool LoadCompare(const MoveOperands* a, const MoveOperands* b) {
227 if (a->source() != b->source()) return a->source() < b->source(); 237 if (!a->source().EqualsModuloType(b->source())) {
238 return a->source().CompareModuloType(b->source());
239 }
228 if (IsSlot(a->destination()) && !IsSlot(b->destination())) return false; 240 if (IsSlot(a->destination()) && !IsSlot(b->destination())) return false;
229 if (!IsSlot(a->destination()) && IsSlot(b->destination())) return true; 241 if (!IsSlot(a->destination()) && IsSlot(b->destination())) return true;
230 return a->destination() < b->destination(); 242 return a->destination().CompareModuloType(b->destination());
231 } 243 }
232 244
233 } // namespace 245 } // namespace
234 246
235 247
236 // Split multiple loads of the same constant or stack slot off into the second 248 // Split multiple loads of the same constant or stack slot off into the second
237 // slot and keep remaining moves in the first slot. 249 // slot and keep remaining moves in the first slot.
238 void MoveOptimizer::FinalizeMoves(Instruction* instr) { 250 void MoveOptimizer::FinalizeMoves(Instruction* instr) {
239 auto loads = temp_vector_0(); 251 auto loads = temp_vector_0();
240 DCHECK(loads.empty()); 252 DCHECK(loads.empty());
241 // Find all the loads. 253 // Find all the loads.
242 for (auto move : *instr->parallel_moves()[0]) { 254 for (auto move : *instr->parallel_moves()[0]) {
243 if (move->IsRedundant()) continue; 255 if (move->IsRedundant()) continue;
244 if (move->source().IsConstant() || IsSlot(move->source())) { 256 if (move->source().IsConstant() || IsSlot(move->source())) {
245 loads.push_back(move); 257 loads.push_back(move);
246 } 258 }
247 } 259 }
248 if (loads.empty()) return; 260 if (loads.empty()) return;
249 // Group the loads by source, moving the preferred destination to the 261 // Group the loads by source, moving the preferred destination to the
250 // beginning of the group. 262 // beginning of the group.
251 std::sort(loads.begin(), loads.end(), LoadCompare); 263 std::sort(loads.begin(), loads.end(), LoadCompare);
252 MoveOperands* group_begin = nullptr; 264 MoveOperands* group_begin = nullptr;
253 for (auto load : loads) { 265 for (auto load : loads) {
254 // New group. 266 // New group.
255 if (group_begin == nullptr || load->source() != group_begin->source()) { 267 if (group_begin == nullptr ||
268 !load->source().EqualsModuloType(group_begin->source())) {
256 group_begin = load; 269 group_begin = load;
257 continue; 270 continue;
258 } 271 }
259 // Nothing to be gained from splitting here. 272 // Nothing to be gained from splitting here.
260 if (IsSlot(group_begin->destination())) continue; 273 if (IsSlot(group_begin->destination())) continue;
261 // Insert new move into slot 1. 274 // Insert new move into slot 1.
262 auto slot_1 = instr->GetOrCreateParallelMove( 275 auto slot_1 = instr->GetOrCreateParallelMove(
263 static_cast<Instruction::GapPosition>(1), code_zone()); 276 static_cast<Instruction::GapPosition>(1), code_zone());
264 slot_1->AddMove(group_begin->destination(), load->destination()); 277 slot_1->AddMove(group_begin->destination(), load->destination());
265 load->Eliminate(); 278 load->Eliminate();
266 } 279 }
267 loads.clear(); 280 loads.clear();
268 } 281 }
269 282
270 } // namespace compiler 283 } // namespace compiler
271 } // namespace internal 284 } // namespace internal
272 } // namespace v8 285 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/instruction-selector-impl.h ('k') | src/compiler/register-allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698