From c7c578f34f4fbd3bb987593ffdccdfb6b356b9f7 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Thu, 25 May 2017 12:41:19 -0700 Subject: Fix performance bug in ZeroWidth (#594) We were recursing on Types of Expressions which not only is super inefficient (especially since we are already calling InferTypes afterward), but also duplicates each of the Type objects that need changing.--- src/main/scala/firrtl/passes/ZeroWidth.scala | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/scala/firrtl/passes/ZeroWidth.scala b/src/main/scala/firrtl/passes/ZeroWidth.scala index 2472a0e5..6d7766d1 100644 --- a/src/main/scala/firrtl/passes/ZeroWidth.scala +++ b/src/main/scala/firrtl/passes/ZeroWidth.scala @@ -40,15 +40,10 @@ object ZeroWidth extends Transform { case VectorType(t, size) => removeZero(t) map (VectorType(_, size)) case x => Some(x) } - private def onExp(e: Expression): Expression = removeZero(e.tpe) match { - case None => e.tpe match { - case UIntType(x) => UIntLiteral(ZERO, IntWidth(BigInt(1))) - case SIntType(x) => SIntLiteral(ZERO, IntWidth(BigInt(1))) - case _ => throwInternalError - } - case Some(t) => - def replaceType(x: Type): Type = t - (e map replaceType) map onExp + private def onExp(e: Expression): Expression = e.tpe match { + case UIntType(IntWidth(ZERO)) => UIntLiteral(ZERO, IntWidth(BigInt(1))) + case SIntType(IntWidth(ZERO)) => SIntLiteral(ZERO, IntWidth(BigInt(1))) + case other => e map onExp } private def onStmt(renames: RenameMap)(s: Statement): Statement = s match { case (_: DefWire| _: DefRegister| _: DefMemory) => -- cgit v1.2.3