Skip to content

Commit fcb1591

Browse files
[IR] Migrate away from PointerUnion::{is,get} (NFC) (#119802)
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
1 parent 1da0730 commit fcb1591

File tree

7 files changed

+16
-17
lines changed

7 files changed

+16
-17
lines changed

mlir/lib/IR/AffineMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ AffineMap mlir::foldAttributesIntoMap(Builder &b, AffineMap map,
753753
b.getAffineConstantExpr(cast<IntegerAttr>(attr).getInt()));
754754
} else {
755755
dimReplacements.push_back(b.getAffineDimExpr(numDims++));
756-
remainingValues.push_back(operands[i].get<Value>());
756+
remainingValues.push_back(cast<Value>(operands[i]));
757757
}
758758
}
759759
int64_t numSymbols = 0;
@@ -763,7 +763,7 @@ AffineMap mlir::foldAttributesIntoMap(Builder &b, AffineMap map,
763763
b.getAffineConstantExpr(cast<IntegerAttr>(attr).getInt()));
764764
} else {
765765
symReplacements.push_back(b.getAffineSymbolExpr(numSymbols++));
766-
remainingValues.push_back(operands[i + map.getNumDims()].get<Value>());
766+
remainingValues.push_back(cast<Value>(operands[i + map.getNumDims()]));
767767
}
768768
}
769769
return map.replaceDimsAndSymbols(dimReplacements, symReplacements, numDims,

mlir/lib/IR/Builders.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ LogicalResult OpBuilder::tryFold(Operation *op,
553553
return cleanupFailure();
554554

555555
// Ask the dialect to materialize a constant operation for this value.
556-
Attribute attr = foldResult.get<Attribute>();
556+
Attribute attr = cast<Attribute>(foldResult);
557557
auto *constOp = dialect->materializeConstant(cstBuilder, attr, expectedType,
558558
op->getLoc());
559559
if (!constOp) {

mlir/lib/IR/OperationSupport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,15 +657,15 @@ ValueRange::OwnerT ValueRange::offset_base(const OwnerT &owner,
657657
return {value + index};
658658
if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(owner))
659659
return {operand + index};
660-
return owner.get<detail::OpResultImpl *>()->getNextResultAtOffset(index);
660+
return cast<detail::OpResultImpl *>(owner)->getNextResultAtOffset(index);
661661
}
662662
/// See `llvm::detail::indexed_accessor_range_base` for details.
663663
Value ValueRange::dereference_iterator(const OwnerT &owner, ptrdiff_t index) {
664664
if (const auto *value = llvm::dyn_cast_if_present<const Value *>(owner))
665665
return value[index];
666666
if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(owner))
667667
return operand[index].get();
668-
return owner.get<detail::OpResultImpl *>()->getNextResultAtOffset(index);
668+
return cast<detail::OpResultImpl *>(owner)->getNextResultAtOffset(index);
669669
}
670670

671671
//===----------------------------------------------------------------------===//

mlir/lib/IR/Region.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ RegionRange::OwnerT RegionRange::offset_base(const OwnerT &owner,
271271
return region + index;
272272
if (auto **region = llvm::dyn_cast_if_present<Region **>(owner))
273273
return region + index;
274-
return &owner.get<Region *>()[index];
274+
return &cast<Region *>(owner)[index];
275275
}
276276
/// See `llvm::detail::indexed_accessor_range_base` for details.
277277
Region *RegionRange::dereference_iterator(const OwnerT &owner,
@@ -280,5 +280,5 @@ Region *RegionRange::dereference_iterator(const OwnerT &owner,
280280
return region[index].get();
281281
if (auto **region = llvm::dyn_cast_if_present<Region **>(owner))
282282
return region[index];
283-
return &owner.get<Region *>()[index];
283+
return &cast<Region *>(owner)[index];
284284
}

mlir/lib/IR/SymbolTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ struct SymbolScope {
623623
std::optional<WalkResult> walk(CallbackT cback) {
624624
if (Region *region = llvm::dyn_cast_if_present<Region *>(limit))
625625
return walkSymbolUses(*region, cback);
626-
return walkSymbolUses(limit.get<Operation *>(), cback);
626+
return walkSymbolUses(cast<Operation *>(limit), cback);
627627
}
628628
/// This variant is used when the callback type matches a stripped down type:
629629
/// void(SymbolTable::SymbolUse use)
@@ -643,7 +643,7 @@ struct SymbolScope {
643643
std::optional<WalkResult> walkSymbolTable(CallbackT &&cback) {
644644
if (Region *region = llvm::dyn_cast_if_present<Region *>(limit))
645645
return ::walkSymbolTable(*region, cback);
646-
return ::walkSymbolTable(limit.get<Operation *>(), cback);
646+
return ::walkSymbolTable(cast<Operation *>(limit), cback);
647647
}
648648

649649
/// The representation of the symbol within this scope.

mlir/lib/IR/TypeRange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ TypeRange::TypeRange(ValueRange values) : TypeRange(OwnerT(), values.size()) {
3232
else if (auto *operand = llvm::dyn_cast_if_present<OpOperand *>(owner))
3333
this->base = operand;
3434
else
35-
this->base = owner.get<const Value *>();
35+
this->base = cast<const Value *>(owner);
3636
}
3737

3838
/// See `llvm::detail::indexed_accessor_range_base` for details.

mlir/lib/IR/Verifier.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ LogicalResult OperationVerifier::verifyOperation(Operation &op) {
274274
WorkItemEntry &top = worklist.back();
275275

276276
auto visit = [](auto &&visitor, WorkItem w) {
277-
if (w.is<Operation *>())
278-
return visitor(w.get<Operation *>());
279-
return visitor(w.get<Block *>());
277+
if (auto *o = dyn_cast<Operation *>(w))
278+
return visitor(o);
279+
return visitor(cast<Block *>(w));
280280
};
281281

282282
const bool isExit = top.getInt();
@@ -299,18 +299,17 @@ LogicalResult OperationVerifier::verifyOperation(Operation &op) {
299299
item)))
300300
return failure();
301301

302-
if (item.is<Block *>()) {
303-
Block &currentBlock = *item.get<Block *>();
302+
if (Block *currentBlock = dyn_cast<Block *>(item)) {
304303
// Skip "isolated from above operations".
305-
for (Operation &o : llvm::reverse(currentBlock)) {
304+
for (Operation &o : llvm::reverse(*currentBlock)) {
306305
if (o.getNumRegions() == 0 ||
307306
!o.hasTrait<OpTrait::IsIsolatedFromAbove>())
308307
worklist.emplace_back(&o);
309308
}
310309
continue;
311310
}
312311

313-
Operation &currentOp = *item.get<Operation *>();
312+
Operation &currentOp = *cast<Operation *>(item);
314313
if (verifyRecursively)
315314
for (Region &region : llvm::reverse(currentOp.getRegions()))
316315
for (Block &block : llvm::reverse(region))

0 commit comments

Comments
 (0)