Skip to content

Commit

Permalink
change consumers into a set to make addConsumers in Node.scala fast
Browse files Browse the repository at this point in the history
  • Loading branch information
donggyukim committed Sep 23, 2014
1 parent a39c41a commit d7e9130
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ abstract class Backend extends FileSystemUtilities{

for ((name, i) <- inputs) {
if (i.inputs.length == 0 && m != Driver.topComponent)
if (i.consumers.length > 0) {
if (i.consumers.size > 0) {
if (Driver.warnInputs)
ChiselError.warning({"UNCONNECTED INPUT " + emitRef(i) + " in COMPONENT " + i.component +
" has consumers"})
Expand All @@ -315,10 +315,10 @@ abstract class Backend extends FileSystemUtilities{

for ((name, o) <- outputs) {
if (o.inputs.length == 0 && !o.component.isInstanceOf[BlackBox]) {
if (o.consumers.length > 0) {
if (o.consumers.size > 0) {
if (Driver.warnOutputs)
ChiselError.warning({"UNCONNECTED OUTPUT " + emitRef(o) + " in component " + o.component +
" has consumers on line " + o.consumers(0).line})
" has consumers on line " + o.consumers.head.line})
o.driveRand = true
} else {
if (Driver.warnOutputs)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Cpp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ class CppBackend extends Backend {
w match {
case io: Bits =>
if (io.dir == OUTPUT) {
res += " " + emitRef(io.consumers(0)) + " = " + emitRef(c) + "->" + n + ";\n";
res += " " + emitRef(io.consumers.head) + " = " + emitRef(c) + "->" + n + ";\n";
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ModularCpp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ModularCppBackend extends CppBackend {
val roots = new ArrayBuffer[Node]
val walked = new ArrayBuffer[Node]
for (node <- module.nodes) {
if (node.isIo && node.asInstanceOf[Bits].dir == OUTPUT && node.consumers.length == 0)
if (node.isIo && node.asInstanceOf[Bits].dir == OUTPUT && node.consumers.size == 0)
roots += node
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/scala/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ package Chisel
import scala.collection.immutable.Vector
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.Stack
import scala.collection.mutable.LinkedHashSet
import java.io.PrintStream

import Node._;
Expand Down Expand Up @@ -143,9 +144,9 @@ abstract class Node extends nameable {
// The semantics of width are sufficiently complicated that
// it deserves its own class
var width_ = Width()
val consumers = new ArrayBuffer[Node]; // mods that consume one of my outputs
val inputs = new ArrayBuffer[Node];
var inferWidth: (=> Node) => Width = maxWidth
val inputs = ArrayBuffer[Node]()
val consumers = LinkedHashSet[Node]() // nodes that consume one of my outputs

var nameHolder: nameable = null;
val line: StackTraceElement =
Expand Down Expand Up @@ -300,7 +301,7 @@ abstract class Node extends nameable {
writer.println("depth: " + depth)
writer.println("width: " + width_)
writer.println("index: " + emitIndex)
writer.println("consumers.length: " + consumers.length)
writer.println("consumers.size: " + consumers.size)
writer.println("nameHolder: " + nameHolder)
writer.println("line: " + line)
for (in <- inputs) {
Expand Down Expand Up @@ -385,9 +386,7 @@ abstract class Node extends nameable {
/* By construction we should not end-up with null inputs. */
assert(i != null, ChiselError.error("input " + off
+ " of " + inputs.length + " for node " + this + " is null"))
if(!i.consumers.contains(this)) {
i.consumers += this;
}
i.consumers += this
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/Verilog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class VerilogBackend extends Backend {
portDec += emitRef(io.inputs(0));
}
} else if(io.dir == OUTPUT) {
if (io.consumers.length == 0) {
if (io.consumers.size == 0) {
// if (Driver.saveConnectionWarnings) {
// ChiselError.warning("" + io + " UNCONNECTED IN " + io.component + " BINDING " + c.findBinding(io));
// } removed this warning because pruneUnconnectedsIOs should have picked it up
Expand All @@ -216,7 +216,7 @@ class VerilogBackend extends Backend {
var consumer: Node = c.parent.findBinding(io);
if (consumer == null) {
if (Driver.saveConnectionWarnings) {
ChiselError.warning("" + io + "(" + io.component + ") OUTPUT UNCONNECTED (" + io.consumers.length + ") IN " + c.parent);
ChiselError.warning("" + io + "(" + io.component + ") OUTPUT UNCONNECTED (" + io.consumers.size + ") IN " + c.parent);
}
portDec = "//" + portDec
} else {
Expand Down Expand Up @@ -525,7 +525,7 @@ class VerilogBackend extends Backend {
included = false
}
else if (io.dir == OUTPUT) {
if (io.consumers.length == 0 || m.parent.findBinding(io) == null || io.prune)
if (io.consumers.size == 0 || m.parent.findBinding(io) == null || io.prune)
included = false
}
if (included) wires += io
Expand All @@ -543,7 +543,7 @@ class VerilogBackend extends Backend {
included = false
}
else if (io.dir == OUTPUT) {
if (io.consumers.length == 0 || m.parent.findBinding(io) == null || io.prune)
if (io.consumers.size == 0 || m.parent.findBinding(io) == null || io.prune)
included = false
}
if (included) dumpvars += io
Expand Down

0 comments on commit d7e9130

Please sign in to comment.