From 113a4aa3641c49b4c86e0cc23b3897b935c9b445 Mon Sep 17 00:00:00 2001 From: David Biancolin Date: Mon, 9 Mar 2020 17:53:11 -0700 Subject: Provide an annotation mix-in that marks RTs as dontTouch (#1433) * Provide an annotation mix-in that marks RTs as dontTouch * Update src/main/scala/firrtl/transforms/OptimizationAnnotations.scala Co-Authored-By: Albert Magyar * Update src/test/scala/firrtlTests/DCETests.scala Co-Authored-By: Albert Magyar * Update src/main/scala/firrtl/transforms/OptimizationAnnotations.scala * Update OptimizationAnnotations.scala Co-authored-by: Albert Magyar --- .../firrtlTests/ConstantPropagationTests.scala | 15 ++++++++++++- src/test/scala/firrtlTests/DCETests.scala | 25 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/scala/firrtlTests/ConstantPropagationTests.scala b/src/test/scala/firrtlTests/ConstantPropagationTests.scala index 18579ca8..189809a6 100644 --- a/src/test/scala/firrtlTests/ConstantPropagationTests.scala +++ b/src/test/scala/firrtlTests/ConstantPropagationTests.scala @@ -792,7 +792,20 @@ class ConstantPropagationIntegrationSpec extends LowTransformSpec { execute(input, check, Seq(dontTouch("Top.z"))) } - "ConstProp" should "NOT optimize across dontTouch on registers" in { + it should "NOT optimize across nodes marked dontTouch by other annotations" in { + val input = + """circuit Top : + | module Top : + | input x : UInt<1> + | output y : UInt<1> + | node z = x + | y <= z""".stripMargin + val check = input + val dontTouchRT = annotations.ModuleTarget("Top", "Top").ref("z") + execute(input, check, Seq(AnnotationWithDontTouches(dontTouchRT))) + } + + it should "NOT optimize across dontTouch on registers" in { val input = """circuit Top : | module Top : diff --git a/src/test/scala/firrtlTests/DCETests.scala b/src/test/scala/firrtlTests/DCETests.scala index a9dbdda2..bfd47042 100644 --- a/src/test/scala/firrtlTests/DCETests.scala +++ b/src/test/scala/firrtlTests/DCETests.scala @@ -11,6 +11,13 @@ import firrtl.passes.memlib.SimpleTransform import java.io.File import java.nio.file.Paths +case class AnnotationWithDontTouches(target: ReferenceTarget) + extends SingleTargetAnnotation[ReferenceTarget] with HasDontTouches { + def targets = Seq(target) + def duplicate(n: ReferenceTarget) = this.copy(n) + def dontTouches: Seq[ReferenceTarget] = targets +} + class DCETests extends FirrtlFlatSpec { // Not using executeTest because it is for positive testing, we need to check that stuff got // deleted @@ -63,6 +70,24 @@ class DCETests extends FirrtlFlatSpec { | z <= x""".stripMargin exec(input, check, Seq(dontTouch("Top.a"))) } + "Unread wire marked dont touch by another annotation" should "NOT be deleted" in { + val input = + """circuit Top : + | module Top : + | input x : UInt<1> + | output z : UInt<1> + | wire a : UInt<1> + | z <= x + | a <= x""".stripMargin + val check = + """circuit Top : + | module Top : + | input x : UInt<1> + | output z : UInt<1> + | node a = x + | z <= x""".stripMargin + exec(input, check, Seq(AnnotationWithDontTouches(ModuleTarget("Top", "Top").ref("a")))) + } "Unread register" should "be deleted" in { val input = """circuit Top : -- cgit v1.2.3