Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mlir/include/mlir/Analysis/SliceAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ struct BackwardSliceOptions : public SliceOptions {
/// backward slice computation traverses block arguments and asserts that the
/// parent op has a single region with a single block.
bool omitBlockArguments = false;

/// When omitUsesFromAbove is true, the backward slice computation omits
/// traversing values that are captured from above.
/// TODO: this should default to `false` after users have been updated.
bool omitUsesFromAbove = true;
};

using ForwardSliceOptions = SliceOptions;
Expand Down
14 changes: 14 additions & 0 deletions mlir/lib/Analysis/SliceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"

Expand Down Expand Up @@ -115,6 +116,19 @@ static void getBackwardSliceImpl(Operation *op,
}
}

// Visit values that are defined above.
if (!options.omitUsesFromAbove) {
visitUsedValuesDefinedAbove(op->getRegions(), [&](OpOperand *operand) {
if (Operation *definingOp = operand->get().getDefiningOp()) {
getBackwardSliceImpl(definingOp, backwardSlice, options);
return;
}
Operation *bbAargOwner =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Operation *bbAargOwner =
if (options.omitBlockArguments)
return;
Operation *bbAargOwner =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that I was duplicating all the logic within the for loop going over the operands. Instead, I changed it to iterate over a SetVector of the operands + used values defined above, which decreases logic duplication. However, this does mean we have to allocate space to store the operands in the SetVector. But maybe this is fine?

cast<BlockArgument>(operand->get()).getOwner()->getParentOp();
getBackwardSliceImpl(bbAargOwner, backwardSlice, options);
});
}

backwardSlice->insert(op);
}

Expand Down
Loading