| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * The [LiveRange] class covers a range where an instruction is live. | 6 * The [LiveRange] class covers a range where an instruction is live. |
| 7 */ | 7 */ |
| 8 class LiveRange { | 8 class LiveRange { |
| 9 final int start; | 9 final int start; |
| 10 // [end] is not final because it can be updated due to loops. | 10 // [end] is not final because it can be updated due to loops. |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 362 } |
| 363 | 363 |
| 364 /** | 364 /** |
| 365 * Contains the mapping between instructions and their names for code | 365 * Contains the mapping between instructions and their names for code |
| 366 * generation, as well as the [CopyHandler] for each basic block. | 366 * generation, as well as the [CopyHandler] for each basic block. |
| 367 */ | 367 */ |
| 368 class VariableNames { | 368 class VariableNames { |
| 369 final Map<HInstruction, String> ownName; | 369 final Map<HInstruction, String> ownName; |
| 370 final Map<HBasicBlock, CopyHandler> copyHandlers; | 370 final Map<HBasicBlock, CopyHandler> copyHandlers; |
| 371 /** | 371 /** |
| 372 * Name that is being used as a temporary to break cycles in | 372 * Name that is used as a temporary to break cycles in |
| 373 * parallel copies. We make sure this name is not being used | 373 * parallel copies. We make sure this name is not being used |
| 374 * anywhere by reserving it when we allocate names for instructions. | 374 * anywhere by reserving it when we allocate names for instructions. |
| 375 */ | 375 */ |
| 376 final String swapTemp; | 376 final String swapTemp; |
| 377 /** |
| 378 * Name that is used in bailout code. We make sure this name is not being used |
| 379 * anywhere by reserving it when we allocate names for instructions. |
| 380 */ |
| 381 final String stateName; |
| 377 | 382 |
| 378 VariableNames(Map<Element, String> parameterNames) | 383 VariableNames(Map<Element, String> parameterNames) |
| 379 : ownName = new Map<HInstruction, String>(), | 384 : ownName = new Map<HInstruction, String>(), |
| 380 copyHandlers = new Map<HBasicBlock, CopyHandler>(), | 385 copyHandlers = new Map<HBasicBlock, CopyHandler>(), |
| 381 swapTemp = computeSwapTemp(parameterNames); | 386 swapTemp = computeFreshWithPrefix("t", parameterNames), |
| 387 stateName = computeFreshWithPrefix("state", parameterNames); |
| 382 | 388 |
| 383 static String computeSwapTemp(Map<Element, String> parameterNames) { | 389 /** Returns a fresh variable with the given prefix. */ |
| 390 static String computeFreshWithPrefix(String prefix, |
| 391 Map<Element, String> parameterNames) { |
| 384 Set<String> parameters = new Set<String>.from(parameterNames.getValues()); | 392 Set<String> parameters = new Set<String>.from(parameterNames.getValues()); |
| 385 String name = 't0'; | 393 String name = '${prefix}0'; |
| 386 int i = 1; | 394 int i = 1; |
| 387 while (parameters.contains(name)) name = 't${i++}'; | 395 while (parameters.contains(name)) name = '$prefix${i++}'; |
| 388 return name; | 396 return name; |
| 389 } | 397 } |
| 390 | 398 |
| 391 String getName(HInstruction instruction) { | 399 String getName(HInstruction instruction) { |
| 392 return ownName[instruction]; | 400 return ownName[instruction]; |
| 393 } | 401 } |
| 394 | 402 |
| 395 CopyHandler getCopyHandler(HBasicBlock block) { | 403 CopyHandler getCopyHandler(HBasicBlock block) { |
| 396 return copyHandlers[block]; | 404 return copyHandlers[block]; |
| 397 } | 405 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 417 class VariableNamer { | 425 class VariableNamer { |
| 418 final VariableNames names; | 426 final VariableNames names; |
| 419 final Set<String> usedNames; | 427 final Set<String> usedNames; |
| 420 final Map<Element, String> parameterNames; | 428 final Map<Element, String> parameterNames; |
| 421 final List<String> freeTemporaryNames; | 429 final List<String> freeTemporaryNames; |
| 422 int temporaryIndex = 0; | 430 int temporaryIndex = 0; |
| 423 | 431 |
| 424 VariableNamer(LiveEnvironment environment, this.names, this.parameterNames) | 432 VariableNamer(LiveEnvironment environment, this.names, this.parameterNames) |
| 425 : usedNames = new Set<String>(), | 433 : usedNames = new Set<String>(), |
| 426 freeTemporaryNames = new List<String>() { | 434 freeTemporaryNames = new List<String>() { |
| 427 // [VariableNames.swapTemp] is being used when there is a cycle | 435 // [VariableNames.swapTemp] and [VariableNames.stateName] are being used |
| 428 // in a copy handler. Therefore we make sure no one will use it. | 436 // throughout the function. Therefore we make sure no one uses it at any |
| 437 // time. |
| 429 usedNames.add(names.swapTemp); | 438 usedNames.add(names.swapTemp); |
| 439 usedNames.add(names.stateName); |
| 430 | 440 |
| 431 // All liveIns instructions must have a name at this point, so we | 441 // All liveIns instructions must have a name at this point, so we |
| 432 // add them to the list of used names. | 442 // add them to the list of used names. |
| 433 environment.liveInstructions.forEach((HInstruction instruction, int index) { | 443 environment.liveInstructions.forEach((HInstruction instruction, int index) { |
| 434 String name = names.getName(instruction); | 444 String name = names.getName(instruction); |
| 435 if (name !== null) { | 445 if (name !== null) { |
| 436 usedNames.add(name); | 446 usedNames.add(name); |
| 437 } | 447 } |
| 438 }); | 448 }); |
| 439 } | 449 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 if (!needsName(input)) { | 650 if (!needsName(input)) { |
| 641 names.addAssignment(predecessor, input, phi); | 651 names.addAssignment(predecessor, input, phi); |
| 642 } else { | 652 } else { |
| 643 names.addCopy(predecessor, input, phi); | 653 names.addCopy(predecessor, input, phi); |
| 644 } | 654 } |
| 645 } | 655 } |
| 646 | 656 |
| 647 namer.allocateName(phi); | 657 namer.allocateName(phi); |
| 648 } | 658 } |
| 649 } | 659 } |
| OLD | NEW |