diff options
| author | Jack Koenig | 2018-03-28 10:48:54 -0700 |
|---|---|---|
| committer | GitHub | 2018-03-28 10:48:54 -0700 |
| commit | fd8feb55cfa55e2c270d11c1a6ae60ba1950be59 (patch) | |
| tree | 82d90510de252da6e3b7587b735fa80744f4b8ef /src/main | |
| parent | cf0d971beda33a1802c384bd8d5eebb150d9d578 (diff) | |
Replace unconnected registers with 0 in Constant Propagation (#776)
Moved from RemoveValidIf
Also Make RemoveValidIf.getGroundZero public and support Fixed
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/scala/firrtl/passes/RemoveValidIf.scala | 32 | ||||
| -rw-r--r-- | src/main/scala/firrtl/transforms/ConstantPropagation.scala | 2 |
2 files changed, 19 insertions, 15 deletions
diff --git a/src/main/scala/firrtl/passes/RemoveValidIf.scala b/src/main/scala/firrtl/passes/RemoveValidIf.scala index 7d714be7..5338a911 100644 --- a/src/main/scala/firrtl/passes/RemoveValidIf.scala +++ b/src/main/scala/firrtl/passes/RemoveValidIf.scala @@ -9,6 +9,23 @@ import WrappedExpression.weq /** Remove ValidIf and replace IsInvalid with a connection to zero */ object RemoveValidIf extends Pass { + + val UIntZero = Utils.zero + val SIntZero = SIntLiteral(BigInt(0), IntWidth(1)) + val ClockZero = DoPrim(PrimOps.AsClock, Seq(UIntZero), Seq.empty, ClockType) + val FixedZero = FixedLiteral(BigInt(0), IntWidth(1), IntWidth(0)) + + /** Returns an [[Expression]] equal to zero for a given [[GroundType]] + * @note Accepts [[Type]] but dyanmically expects [[GroundType]] + */ + def getGroundZero(tpe: Type): Expression = tpe match { + case _: UIntType => UIntZero + case _: SIntType => SIntZero + case ClockType => ClockZero + case _: FixedType => FixedZero + case other => throwInternalError(s"Unexpected type $other") + } + // Recursive. Removes ValidIfs private def onExp(e: Expression): Expression = { e map onExp match { @@ -16,16 +33,6 @@ object RemoveValidIf extends Pass { case x => x } } - private val UIntZero = Utils.zero - private val SIntZero = SIntLiteral(BigInt(0), IntWidth(1)) - private val ClockZero = DoPrim(PrimOps.AsClock, Seq(UIntZero), Seq.empty, UIntZero.tpe) - - private def getGroundZero(tpe: Type): Expression = tpe match { - case _: UIntType => UIntZero - case _: SIntType => SIntZero - case ClockType => ClockZero - case other => throwInternalError() - } // Recursive. Replaces IsInvalid with connecting zero private def onStmt(s: Statement): Statement = s map onStmt map onExp match { @@ -33,11 +40,6 @@ object RemoveValidIf extends Pass { case _: AnalogType => EmptyStmt case tpe => Connect(info, loc, getGroundZero(tpe)) } - // Register connected to itself (since reset has been made explicit) is a register with no reset - // and no connections, connect it to zero (to be constant propped later) - case Connect(info, lref: WRef, rref: WRef) if weq(lref, rref) => - // We can't have an Analog reg so just get a zero - Connect(info, lref, getGroundZero(lref.tpe)) case other => other } diff --git a/src/main/scala/firrtl/transforms/ConstantPropagation.scala b/src/main/scala/firrtl/transforms/ConstantPropagation.scala index 8217a9bd..2def130c 100644 --- a/src/main/scala/firrtl/transforms/ConstantPropagation.scala +++ b/src/main/scala/firrtl/transforms/ConstantPropagation.scala @@ -378,6 +378,8 @@ class ConstantPropagation extends Transform { nodeMap(lname) = constPropExpression(nodeMap, instMap, constSubOutputs)(pad(fval, ltpe)) case Mux(_, tval: Literal, fval: WRef, _) if weq(lref, fval) => nodeMap(lname) = constPropExpression(nodeMap, instMap, constSubOutputs)(pad(tval, ltpe)) + case WRef(`lname`, _,_,_) => // If a register is connected to itself, propagate zero + nodeMap(lname) = passes.RemoveValidIf.getGroundZero(ltpe) case _ => } // Mark instance inputs connected to a constant |
