[mlir] Expose region utils functions

As discussed in D109579, this patch exposes `runRegionDCE` and
`eraseUnreachableBlocks` so they can be used as separate utilities in
other passes.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D114160
This commit is contained in:
Valentin Clement 2021-11-19 09:24:11 +01:00
parent 8fb3f84484
commit 78d69182b7
No known key found for this signature in database
GPG Key ID: 086D54783C928776
2 changed files with 14 additions and 4 deletions

View File

@ -59,6 +59,16 @@ void getUsedValuesDefinedAbove(MutableArrayRef<Region> regions,
LogicalResult simplifyRegions(RewriterBase &rewriter,
MutableArrayRef<Region> regions);
/// Erase the unreachable blocks within the provided regions. Returns success
/// if any blocks were erased, failure otherwise.
LogicalResult eraseUnreachableBlocks(RewriterBase &rewriter,
MutableArrayRef<Region> regions);
/// This function returns success if any operations or arguments were deleted,
/// failure otherwise.
LogicalResult runRegionDCE(RewriterBase &rewriter,
MutableArrayRef<Region> regions);
} // namespace mlir
#endif // MLIR_TRANSFORMS_REGIONUTILS_H_

View File

@ -76,8 +76,8 @@ void mlir::getUsedValuesDefinedAbove(MutableArrayRef<Region> regions,
/// Erase the unreachable blocks within the provided regions. Returns success
/// if any blocks were erased, failure otherwise.
// TODO: We could likely merge this with the DCE algorithm below.
static LogicalResult eraseUnreachableBlocks(RewriterBase &rewriter,
MutableArrayRef<Region> regions) {
LogicalResult mlir::eraseUnreachableBlocks(RewriterBase &rewriter,
MutableArrayRef<Region> regions) {
// Set of blocks found to be reachable within a given region.
llvm::df_iterator_default_set<Block *, 16> reachable;
// If any blocks were found to be dead.
@ -364,8 +364,8 @@ static LogicalResult deleteDeadness(RewriterBase &rewriter,
//
// This function returns success if any operations or arguments were deleted,
// failure otherwise.
static LogicalResult runRegionDCE(RewriterBase &rewriter,
MutableArrayRef<Region> regions) {
LogicalResult mlir::runRegionDCE(RewriterBase &rewriter,
MutableArrayRef<Region> regions) {
LiveMap liveMap;
do {
liveMap.resetChanged();