Skip to content

Commit

Permalink
[FIRRTL] Optimize foldFlow, NFC.
Browse files Browse the repository at this point in the history
Instead of scanning the results of an instance to find the result
number (which is O(n) in # results) use OpResult to get it directly.

This is pretty hot in the profile because it is invoked frequently
by the verifier.  This change sped the full end to end (chirrtl to
verilog) time on a large testcase by 3%.
  • Loading branch information
lattner committed Oct 24, 2021
1 parent 7208a9f commit 3e613ff
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/Dialect/FIRRTL/FIRRTLOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,10 @@ Flow firrtl::foldFlow(Value val, Flow accumulatedFlow) {
.Case<RegOp, RegResetOp, WireOp, MemoryPortOp>(
[](auto) { return Flow::Duplex; })
.Case<InstanceOp>([&](auto inst) {
for (auto arg : llvm::enumerate(inst.getResults()))
if (arg.value() == val) {
if (inst.getPortDirection(arg.index()) == Direction::Out)
return accumulatedFlow;
else
return swap();
}
llvm_unreachable("couldn't find result in results");
auto resultNo = val.cast<OpResult>().getResultNumber();
if (inst.getPortDirection(resultNo) == Direction::Out)
return accumulatedFlow;
return swap();
})
.Case<MemOp>([&](auto op) { return swap(); })
// Anything else acts like a universal source.
Expand Down

0 comments on commit 3e613ff

Please sign in to comment.