aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/options/DependencyManager.scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2020-04-21 23:21:45 -0400
committerSchuyler Eldridge2020-04-22 19:55:56 -0400
commit26e1eec14cdb71cd2dccc510c7f4eaea171be7c4 (patch)
treec05663a6b8ebf88380e7698c46a13364f846f537 /src/main/scala/firrtl/options/DependencyManager.scala
parent65360f886f9b92438d1b6fe609120b34ebb413cf (diff)
Add optionalPrerequisiteOf, deprecate dependents
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/main/scala/firrtl/options/DependencyManager.scala')
-rw-r--r--src/main/scala/firrtl/options/DependencyManager.scala37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/main/scala/firrtl/options/DependencyManager.scala b/src/main/scala/firrtl/options/DependencyManager.scala
index 537f87bd..910d44bb 100644
--- a/src/main/scala/firrtl/options/DependencyManager.scala
+++ b/src/main/scala/firrtl/options/DependencyManager.scala
@@ -22,10 +22,11 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
override def prerequisites = currentState
- override def dependents = Seq.empty
override def optionalPrerequisites = Seq.empty
+ override def optionalPrerequisiteOf = Seq.empty
+
override def invalidates(a: B): Boolean = (_currentState &~ _targets)(oToD(a))
/** Requested [[firrtl.options.TransformLike TransformLike]]s that should be run. Internally, this will be converted to
@@ -121,11 +122,11 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
}
/** A directed graph consisting of prerequisites derived from only those transforms which are supposed to run. This
- * pulls in dependents for transforms which are not in the target set.
+ * pulls in optionalPrerequisiteOf for transforms which are not in the target set.
*/
- private lazy val dependentsGraph: DiGraph[B] = {
+ private lazy val optionalPrerequisiteOfGraph: DiGraph[B] = {
val v = new LinkedHashSet() ++ prerequisiteGraph.getVertices
- DiGraph(new LinkedHashMap() ++ v.map(vv => vv -> (v & (vv._dependents).map(dToO)))).reverse
+ DiGraph(new LinkedHashMap() ++ v.map(vv => vv -> (v & (vv._optionalPrerequisiteOf.toSet).map(dToO)))).reverse
}
/** A directed graph of *optional* prerequisites. Each optional prerequisite is promoted to a full prerequisite if the
@@ -139,11 +140,11 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
/** A directed graph consisting of prerequisites derived from ALL targets. This is necessary for defining targets for
* [[DependencyManager]] sub-problems.
*/
- private lazy val otherDependents: DiGraph[B] = {
+ private lazy val otherPrerequisites: DiGraph[B] = {
val edges = {
val x = new LinkedHashMap ++ _targets
.map(dependencyToObject)
- .map{ a => a -> prerequisiteGraph.getVertices.filter(a._dependents(_)) }
+ .map{ a => a -> prerequisiteGraph.getVertices.filter(a._optionalPrerequisiteOf(_)) }
x
.values
.reduce(_ ++ _)
@@ -152,8 +153,10 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
DiGraph(edges).reverse
}
- /** A directed graph consisting of all prerequisites, including prerequisites derived from dependents */
- lazy val dependencyGraph: DiGraph[B] = prerequisiteGraph + dependentsGraph + optionalPrerequisitesGraph
+ /** A directed graph consisting of all prerequisites, including prerequisites derived from optionalPrerequisites and
+ * optionalPrerequisiteOf
+ */
+ lazy val dependencyGraph: DiGraph[B] = prerequisiteGraph + optionalPrerequisiteOfGraph + optionalPrerequisitesGraph
/** A directed graph consisting of invalidation edges */
lazy val invalidateGraph: DiGraph[B] = {
@@ -178,9 +181,9 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
/** An ordering of [[firrtl.options.TransformLike TransformLike]]s that causes the requested [[DependencyManager.targets
* targets]] to be executed starting from the [[DependencyManager.currentState currentState]]. This ordering respects
- * prerequisites, dependents, and invalidates of all constituent [[firrtl.options.TransformLike TransformLike]]s.
- * This uses an algorithm that attempts to reduce the number of re-lowerings due to invalidations. Re-lowerings are
- * implemented as new [[DependencyManager]]s.
+ * prerequisites, optionalPrerequisites, optionalPrerequisiteOf, and invalidates of all constituent
+ * [[firrtl.options.TransformLike TransformLike]]s. This uses an algorithm that attempts to reduce the number of
+ * re-lowerings due to invalidations. Re-lowerings are implemented as new [[DependencyManager]]s.
* @throws DependencyManagerException if a cycle exists in either the [[DependencyManager.dependencyGraph
* dependencyGraph]] or the [[DependencyManager.invalidateGraph invalidateGraph]].
*/
@@ -199,7 +202,7 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
v.map(vv => vv -> (new LinkedHashSet() ++ (dependencyGraph.getEdges(vv).toSeq.sortWith(cmp))))
}
- cyclePossible("prerequisites/dependents", dependencyGraph) {
+ cyclePossible("prerequisites", dependencyGraph) {
DiGraph(edges)
.linearize
.reverse
@@ -209,10 +212,9 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
/* [todo] Seq is inefficient here, but Array has ClassTag problems. Use something else? */
val (s, l) = sorted.foldLeft((_currentState, Seq[B]())){ case ((state, out), in) =>
- /* The prerequisites are both prerequisites AND dependents. */
val prereqs = in._prerequisites ++
dependencyGraph.getEdges(in).toSeq.map(oToD) ++
- otherDependents.getEdges(in).toSeq.map(oToD)
+ otherPrerequisites.getEdges(in).toSeq.map(oToD)
val preprocessing: Option[B] = {
if ((prereqs -- state).nonEmpty) { Some(this.copy(prereqs.toSeq, state.toSeq)) }
else { None }
@@ -267,7 +269,8 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
/** Get a name of some [[firrtl.options.TransformLike TransformLike]] */
private def transformName(transform: B, suffix: String = ""): String = s""""${transform.name}$suffix""""
- /** Convert all prerequisites, dependents, and invalidates to a Graphviz representation.
+ /** Convert all prerequisites, optionalPrerequisites, optionalPrerequisiteOf, and invalidates to a Graphviz
+ * representation.
* @param file the name of the output file
*/
def dependenciesToGraphviz: String = {
@@ -291,14 +294,14 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends
val connections =
Seq( (prerequisiteGraph, "edge []"),
- (dependentsGraph, """edge [style=bold color="#4292c6"]"""),
+ (optionalPrerequisiteOfGraph, """edge [style=bold color="#4292c6"]"""),
(invalidateGraph, """edge [minlen=2 style=dashed constraint=false color="#fb6a4a"]"""),
(optionalPrerequisitesGraph, """edge [style=dotted color="#a1d99b"]""") )
.flatMap{ case (a, b) => toGraphviz(a, b) }
.mkString("\n")
val nodes =
- (prerequisiteGraph + dependentsGraph + invalidateGraph + otherDependents)
+ (prerequisiteGraph + optionalPrerequisiteOfGraph + invalidateGraph + otherPrerequisites)
.getVertices
.map(v => s"""${transformName(v)} [label="${v.name}"]""")