aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Waterman2019-03-28 18:28:38 -0700
committerGitHub2019-03-28 18:28:38 -0700
commit883548c673ef6496c3b281b0011153a11541584d (patch)
tree204105111d1f2c1b41dabdea0618477d631e4a86 /src
parent97e132e24226e69afc3a52d88c4a591b0678f816 (diff)
parent43768b5a9fcf0f9808a62401b2d4fdfbad7597c2 (diff)
Merge pull request #1065 from freechipsproject/dce-printf-stop
DCE printf and stop statements with constant-0 enables
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/transforms/DeadCodeElimination.scala7
-rw-r--r--src/test/scala/firrtlTests/DCETests.scala17
2 files changed, 24 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/transforms/DeadCodeElimination.scala b/src/main/scala/firrtl/transforms/DeadCodeElimination.scala
index 8f9fad46..deb7299d 100644
--- a/src/main/scala/firrtl/transforms/DeadCodeElimination.scala
+++ b/src/main/scala/firrtl/transforms/DeadCodeElimination.scala
@@ -212,6 +212,11 @@ class DeadCodeElimination extends Transform with ResolvedAnnotationPaths with Re
var emptyBody = true
renames.setModule(mod.name)
+ def deleteIfNotEnabled(stmt: Statement, en: Expression): Statement = en match {
+ case UIntLiteral(v, _) if v == BigInt(0) => EmptyStmt
+ case _ => stmt
+ }
+
def onStmt(stmt: Statement): Statement = {
val stmtx = stmt match {
case inst: WDefInstance =>
@@ -230,6 +235,8 @@ class DeadCodeElimination extends Transform with ResolvedAnnotationPaths with Re
EmptyStmt
}
else decl
+ case print: Print => deleteIfNotEnabled(print, print.en)
+ case stop: Stop => deleteIfNotEnabled(stop, stop.en)
case con: Connect =>
val node = getDeps(con.loc) match { case Seq(elt) => elt }
if (deadNodes.contains(node)) EmptyStmt else con
diff --git a/src/test/scala/firrtlTests/DCETests.scala b/src/test/scala/firrtlTests/DCETests.scala
index a6def402..620cc5f3 100644
--- a/src/test/scala/firrtlTests/DCETests.scala
+++ b/src/test/scala/firrtlTests/DCETests.scala
@@ -449,6 +449,23 @@ class DCETests extends FirrtlFlatSpec {
// Check for register update
verilog should include regex ("""(?m)if \(a\) begin\n\s*r <= x;\s*end""")
}
+
+ "Emitted Verilog" should "not contain dead print or stop statements" in {
+ val input = parse(
+ """circuit test :
+ | module test :
+ | input clock : Clock
+ | when UInt<1>(0) :
+ | printf(clock, UInt<1>(1), "o hai")
+ | stop(clock, UInt<1>(1), 1)""".stripMargin
+ )
+
+ val state = CircuitState(input, ChirrtlForm)
+ val result = (new VerilogCompiler).compileAndEmit(state, List.empty)
+ val verilog = result.getEmittedCircuit.value
+ verilog shouldNot include regex ("""fwrite""")
+ verilog shouldNot include regex ("""fatal""")
+ }
}
class DCECommandLineSpec extends FirrtlFlatSpec {