Skip to content

Commit 3eb49c4

Browse files
authored
[mlir][NFC] Use hasOneBlock instead of llvm::hasSingleElement(region) (#149809)
1 parent 5024fc1 commit 3eb49c4

File tree

19 files changed

+27
-33
lines changed

19 files changed

+27
-33
lines changed

mlir/include/mlir/IR/OpDefinition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ struct SingleBlock : public TraitBase<ConcreteType, SingleBlock> {
889889
continue;
890890

891891
// Non-empty regions must contain a single basic block.
892-
if (!llvm::hasSingleElement(region))
892+
if (!region.hasOneBlock())
893893
return op->emitOpError("expects region #")
894894
<< i << " to have 0 or 1 blocks";
895895

mlir/include/mlir/Parser/Parser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ inline OwningOpRef<ContainerOpT> constructContainerOpForParserIfNecessary(
6666
OpBuilder builder(context);
6767
ContainerOpT op = ContainerOpT::create(builder, sourceFileLoc);
6868
OwningOpRef<ContainerOpT> opRef(op);
69-
assert(op->getNumRegions() == 1 &&
70-
llvm::hasSingleElement(op->getRegion(0)) &&
69+
assert(op->getNumRegions() == 1 && op->getRegion(0).hasOneBlock() &&
7170
"expected generated operation to have a single region with a single "
7271
"block");
7372
Block *opBlock = &op->getRegion(0).front();

mlir/lib/Analysis/SliceAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
137137
// into us. For now, just bail.
138138
if (parentOp && backwardSlice->count(parentOp) == 0) {
139139
if (parentOp->getNumRegions() == 1 &&
140-
llvm::hasSingleElement(parentOp->getRegion(0).getBlocks())) {
140+
parentOp->getRegion(0).hasOneBlock()) {
141141
return getBackwardSliceImpl(parentOp, visited, backwardSlice,
142142
options);
143143
}

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct AffineInlinerInterface : public DialectInlinerInterface {
169169

170170
// Multi-block regions cannot be inlined into affine constructs, all of
171171
// which require single-block regions.
172-
if (!llvm::hasSingleElement(*src))
172+
if (!src->hasOneBlock())
173173
return false;
174174

175175
// Side-effecting operations that the affine dialect cannot understand

mlir/lib/Dialect/GPU/Transforms/EliminateBarriers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ getEffectsBefore(Operation *op,
158158

159159
// If there is a non-structured control flow, bail.
160160
Region *region = op->getBlock()->getParent();
161-
if (region && !llvm::hasSingleElement(region->getBlocks())) {
161+
if (region && !region->hasOneBlock()) {
162162
addAllValuelessEffects(effects);
163163
return false;
164164
}
@@ -250,7 +250,7 @@ getEffectsAfter(Operation *op,
250250

251251
// If there is a non-structured control flow, bail.
252252
Region *region = op->getBlock()->getParent();
253-
if (region && !llvm::hasSingleElement(region->getBlocks())) {
253+
if (region && !region->hasOneBlock()) {
254254
addAllValuelessEffects(effects);
255255
return false;
256256
}

mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ static void insertCopies(Region &region, Location loc, Value from, Value to) {
124124
(void)toType;
125125
assert(fromType.getShape() == toType.getShape());
126126
assert(fromType.getRank() != 0);
127-
assert(llvm::hasSingleElement(region) &&
128-
"unstructured control flow not supported");
127+
assert(region.hasOneBlock() && "unstructured control flow not supported");
129128

130129
auto b = ImplicitLocOpBuilder::atBlockBegin(loc, &region.front());
131130
insertCopyLoops(b, from, to);

mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,7 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
12771277
return op->emitOpError("expected the shape-to-loops map to be non-null");
12781278

12791279
// Check the region has exactly one block.
1280-
if (linalgOp->getNumRegions() != 1 ||
1281-
!llvm::hasSingleElement(linalgOp->getRegion(0)))
1280+
if (linalgOp->getNumRegions() != 1 || !linalgOp->getRegion(0).hasOneBlock())
12821281
return op->emitOpError("expects to have 1 region with 1 block");
12831282

12841283
// Simplifying assumption: bbargs match 1-1 with shape operands elemental

mlir/lib/Dialect/Linalg/Utils/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static bool isTiled(AffineMap map, ArrayRef<OpFoldResult> tileSizes) {
9292
std::optional<RegionMatcher::BinaryOpKind>
9393
RegionMatcher::matchAsScalarBinaryOp(GenericOp op) {
9494
auto &region = op.getRegion();
95-
if (!llvm::hasSingleElement(region))
95+
if (!region.hasOneBlock())
9696
return std::nullopt;
9797

9898
Block &block = region.front();
@@ -204,7 +204,7 @@ bool allIndexingsAreProjectedPermutation(LinalgOp op) {
204204
}
205205

206206
bool hasOnlyScalarElementwiseOp(Region &r) {
207-
if (!llvm::hasSingleElement(r))
207+
if (!r.hasOneBlock())
208208
return false;
209209
for (Operation &op : r.front()) {
210210
if (!(isa<arith::ConstantOp, func::ConstantOp, tensor::ExtractOp,

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ struct RemoveConstantIfCondition : public OpRewritePattern<OpTy> {
859859
/// using the operands of the block terminator to replace operation results.
860860
static void replaceOpWithRegion(PatternRewriter &rewriter, Operation *op,
861861
Region &region, ValueRange blockArgs = {}) {
862-
assert(llvm::hasSingleElement(region) && "expected single-region block");
862+
assert(region.hasOneBlock() && "expected single-block region");
863863
Block *block = &region.front();
864864
Operation *terminator = block->getTerminator();
865865
ValueRange results = terminator->getOperands();

mlir/lib/Dialect/SCF/IR/SCF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static TerminatorTy verifyAndGetTerminator(Operation *op, Region &region,
112112
/// using the operands of the block terminator to replace operation results.
113113
static void replaceOpWithRegion(PatternRewriter &rewriter, Operation *op,
114114
Region &region, ValueRange blockArgs = {}) {
115-
assert(llvm::hasSingleElement(region) && "expected single-region block");
115+
assert(region.hasOneBlock() && "expected single-block region");
116116
Block *block = &region.front();
117117
Operation *terminator = block->getTerminator();
118118
ValueRange results = terminator->getOperands();
@@ -184,7 +184,7 @@ struct SingleBlockExecuteInliner : public OpRewritePattern<ExecuteRegionOp> {
184184

185185
LogicalResult matchAndRewrite(ExecuteRegionOp op,
186186
PatternRewriter &rewriter) const override {
187-
if (!llvm::hasSingleElement(op.getRegion()))
187+
if (!op.getRegion().hasOneBlock())
188188
return failure();
189189
replaceOpWithRegion(rewriter, op, op.getRegion());
190190
return success();

0 commit comments

Comments
 (0)