Skip to content

Commit

Permalink
[ExportVerilog] Refactor isExpressionEmittedInline to be faster, NFC.
Browse files Browse the repository at this point in the history
isExpressionUnableToInline is expensive: it walks the entire use-list
of an operation, which for some things can be a lot of stuff to sort
through.  However, most things that have more than one use can't
be inlined anyway.  Rearrange the control flow to only do the heavy
lifting in cases where it is needed.

This is a small but measurable speedup in ExportVerilog.
  • Loading branch information
lattner committed Oct 26, 2021
1 parent 13e34a8 commit ebdb20c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/Conversion/ExportVerilog/ExportVerilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,17 +1909,16 @@ static bool isExpressionEmittedInline(Operation *op) {
if (op->hasOneUse() && isa<hw::OutputOp>(*op->getUsers().begin()))
return true;

// If this operation has multiple uses, we can't generally inline it.
if (!op->getResult(0).hasOneUse()) {
// ... unless it is nullary and duplicable, then we can emit it inline.
if (op->getNumOperands() != 0 || !isDuplicatableNullaryExpression(op))
return false;
}

// If it isn't structurally possible to inline this expression, emit it out
// of line.
if (isExpressionUnableToInline(op))
return false;

// If it has a single use, emit it inline.
if (op->getResult(0).hasOneUse())
return true;

// If it is nullary and duplicable, then we can emit it inline.
return op->getNumOperands() == 0 && isDuplicatableNullaryExpression(op);
return !isExpressionUnableToInline(op);
}

namespace {
Expand Down

0 comments on commit ebdb20c

Please sign in to comment.