Skip to content

Commit

Permalink
[FIRRTL] Use the class map in ObjectOp parser.
Browse files Browse the repository at this point in the history
We already store a mapping from class name to ClassOp when we parse
the ClassOp signatures, in case the class name is referenced in any
ClassOp port types. This re-uses the same data structure when parsing
an ObjectOp to a) ensure the class exists, and b) construct the
ObjectOp using the ClassOp.

The previous implementation would look up the ClassOp symbol in the
circuit, but this would simply scan the circuit body again and
again. This change makes a significant difference for performance, on
the order of 90% overall parsing time reduction for large designs with
many objects.
  • Loading branch information
mikeurbach committed Mar 1, 2024
1 parent d5c4b70 commit 0d92e13
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Dialect/FIRRTL/Import/FIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3981,12 +3981,12 @@ ParseResult FIRStmtParser::parseObject() {
locationProcessor.setLoc(startTok.getLoc());

// Look up the class that is being referenced.
auto circuit =
builder.getBlock()->getParentOp()->getParentOfType<CircuitOp>();
auto referencedClass = circuit.lookupSymbol<ClassLike>(className);
if (!referencedClass)
const auto &classMap = getConstants().classMap;
auto lookup = classMap.find(className);
if (lookup == classMap.end())
return emitError(startTok.getLoc(), "use of undefined class name '" +
className + "' in object");
auto referencedClass = lookup->getSecond();
auto result = builder.create<ObjectOp>(referencedClass, id);
return moduleContext.addSymbolEntry(id, result, startTok.getLoc());
}
Expand Down

0 comments on commit 0d92e13

Please sign in to comment.