Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.00 KB | None | 0 0
  1. return blocks.map {
  2.         val block = it
  3.         block to liveVariables[it.label]!!.map {
  4.             val variable = it
  5.             val isDeadInBlock = block.nextBlocks.all { variable !in liveVariables[it.label]!! }
  6.             variable to LiveRange(
  7.                     block.instructions.indexOfFirst {
  8.                         it !is Phi && it is AssignInstruction && it.lhs.toString() == variable ||
  9.                                 it is BranchInstruction && run {
  10.                                     val branch = it
  11.                                     val destBlock = blocks.first { it.label == branch.label }
  12.                                     destBlock.instructions
  13.                                             .filterIsInstance<Phi>()
  14.                                             .any { "${it.lhs}" == variable }
  15.                                 }
  16.                     }.let { if (it == -1) 0 else it },
  17.                     if (isDeadInBlock)
  18.                         block.instructions.indexOfLast {
  19.                             it.usedValues.any { it is Variable && it.toString() == variable } ||
  20.                                     it is BranchInstruction && run {
  21.                                         val branch = it
  22.                                         val destBlock = blocks.first { it.label == branch.label }
  23.                                         destBlock.instructions
  24.                                                 .filterIsInstance<Phi>()
  25.                                                 .any {
  26.                                                     it.pairs.firstOrNull {
  27.                                                         it.second is Variable && "$it" == variable
  28.                                                     } != null
  29.                                                 }
  30.                                     }
  31.                         }
  32.                     else
  33.                         block.instructions.size,
  34.                     isDeadInBlock
  35.             )
  36.         }.toMap()
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement