aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/transforms/OptimizationAnnotations.scala
blob: a66bd4ce075d773d38bdd9f0125d4f04bee343ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package firrtl
package transforms

import firrtl.annotations._
import firrtl.passes.PassException
import firrtl.transforms

/** Indicate that DCE should not be run */
case object NoDCEAnnotation extends NoTargetAnnotation

/** A component that should be preserved
  *
  * DCE treats the component as a top-level sink of the circuit
  */
case class DontTouchAnnotation(target: ReferenceTarget) extends SingleTargetAnnotation[ReferenceTarget] {
  def targets = Seq(target)
  def duplicate(n: ReferenceTarget) = this.copy(n)
}

object DontTouchAnnotation {
  class DontTouchNotFoundException(module: String, component: String) extends PassException(
    s"Target marked dontTouch ($module.$component) not found!\n" +
    "It was probably accidentally deleted. Please check that your custom transforms are not" +
    "responsible and then file an issue on Github."
  )

  def errorNotFound(module: String, component: String) =
    throw new DontTouchNotFoundException(module, component)
}

/** An [[firrtl.ir.ExtModule]] that can be optimized
  *
  * Firrtl does not know the semantics of an external module. This annotation provides some
  * "greybox" information that the external module does not have any side effects. In particular,
  * this means that the external module can be Dead Code Eliminated.
  *
  * @note Unlike [[DontTouchAnnotation]], we don't care if the annotation is deleted
  */
case class OptimizableExtModuleAnnotation(target: ModuleName) extends
    SingleTargetAnnotation[ModuleName] {
  def duplicate(n: ModuleName) = this.copy(n)
}