Skip to content

Commit fa3bebd

Browse files
Apply suggestions from code review
Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
1 parent f7686bd commit fa3bebd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,9 +3309,12 @@ LogicalResult OperationConverter::convertOperations(ArrayRef<Operation *> ops) {
33093309
/// Try to reconcile all given UnrealizedConversionCastOps and store the
33103310
/// left-over ops in `remainingCastOps` (if provided). See documentation in
33113311
/// DialectConversion.h for more details.
3312+
/// The `isCastOpOfInterestFn` is used to filter the cast ops to proceed: the algorithm may
3313+
/// visit an operand (or user) which is a cast op, but will not try to reconcile it if not in the
3314+
/// filtered set.
33123315
template <typename RangeT>
33133316
static void reconcileUnrealizedCastsImpl(
3314-
RangeT castOps, function_ref<bool(UnrealizedConversionCastOp)> isCastOpFn,
3317+
RangeT castOps, function_ref<bool(UnrealizedConversionCastOp)> isCastOpOfInterestFn,
33153318
SmallVectorImpl<UnrealizedConversionCastOp> *remainingCastOps) {
33163319
// A worklist of cast ops to process.
33173320
SetVector<UnrealizedConversionCastOp> worklist(llvm::from_range, castOps);
@@ -3363,9 +3366,9 @@ static void reconcileUnrealizedCastsImpl(
33633366

33643367
// Helper function that marks the given op and transitively reachable input
33653368
// cast ops as alive.
3366-
auto markOpLive = [&](Operation *op) {
3369+
auto markOpLive = [&](Operation *rootOp) {
33673370
SmallVector<Operation *> worklist;
3368-
worklist.push_back(op);
3371+
worklist.push_back(rootOp);
33693372
while (!worklist.empty()) {
33703373
Operation *op = worklist.pop_back_val();
33713374
if (liveOps.insert(op).second) {
@@ -3380,6 +3383,8 @@ static void reconcileUnrealizedCastsImpl(
33803383

33813384
// Find all alive cast ops.
33823385
for (UnrealizedConversionCastOp op : castOps) {
3386+
// The op may have been marked live already as being an operand of another live cast op.
3387+
if (liveOps.contains(op.getOperation()) continue;
33833388
// If any of the users is not a cast op, mark the current op (and its
33843389
// input ops) as live.
33853390
if (llvm::any_of(op->getUsers(), [&](Operation *user) {

0 commit comments

Comments
 (0)