-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #361 from hkapp/topic/optimizations/gvn
Add GlobalValueNumbering pass
- Loading branch information
Showing
6 changed files
with
300 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tools/src/main/scala/scala/scalanative/compiler/analysis/Shows.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package scala.scalanative | ||
package compiler | ||
package analysis | ||
|
||
import ControlFlow.Block | ||
import nir.Shows._ | ||
|
||
object Shows { | ||
|
||
private def blockToString(block: Block): String = | ||
showLocal(block.name).toString | ||
|
||
def showCFG(cfg: ControlFlow.Graph): String = { | ||
cfg.all.map { block => | ||
val succStr = | ||
block.succ.map(blockToString).mkString("(", ",", ")") | ||
val predStr = | ||
block.pred.map(blockToString).mkString("(", ",", ")") | ||
s"${blockToString(block)} -> ${succStr}, pred = ${predStr}" | ||
}.mkString("\n") | ||
} | ||
|
||
def showDominatorTree(domination: Map[Block, Set[Block]]): String = { | ||
domination.toSeq | ||
.sortBy(_._1.name.id) | ||
.map { | ||
case (block, set) => | ||
s"${blockToString(block)} -> ${set.map(blockToString).mkString("(", ",", ")")}" | ||
} | ||
.mkString("\n") | ||
} | ||
|
||
def cfgToDot(cfg: ControlFlow.Graph): String = { | ||
def blockToDot(block: Block): String = { | ||
val successors = block.succ | ||
val blockID = block.name.id | ||
if (successors.nonEmpty) | ||
successors | ||
.map(succ => succ.name.id.toString) | ||
.mkString(s"${blockID} -> {", " ", "};") | ||
else | ||
s"${blockID} [ shape=doublecircle ];" | ||
} | ||
|
||
s""" | ||
|digraph { | ||
| node [shape=circle, width=0.6, fixedsize=true]; | ||
|${cfg.map(blockToDot).mkString("\n")} | ||
|} | ||
""".stripMargin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters