Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return blocks.map {
- val block = it
- block to liveVariables[it.label]!!.map {
- val variable = it
- val isDeadInBlock = block.nextBlocks.all { variable !in liveVariables[it.label]!! }
- variable to LiveRange(
- block.instructions.indexOfFirst {
- it !is Phi && it is AssignInstruction && it.lhs.toString() == variable ||
- it is BranchInstruction && run {
- val branch = it
- val destBlock = blocks.first { it.label == branch.label }
- destBlock.instructions
- .filterIsInstance<Phi>()
- .any { "${it.lhs}" == variable }
- }
- }.let { if (it == -1) 0 else it },
- if (isDeadInBlock)
- block.instructions.indexOfLast {
- it.usedValues.any { it is Variable && it.toString() == variable } ||
- it is BranchInstruction && run {
- val branch = it
- val destBlock = blocks.first { it.label == branch.label }
- destBlock.instructions
- .filterIsInstance<Phi>()
- .any {
- it.pairs.firstOrNull {
- it.second is Variable && "$it" == variable
- } != null
- }
- }
- }
- else
- block.instructions.size,
- isDeadInBlock
- )
- }.toMap()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement