Skip to content

Commit 4f4e2ab

Browse files
[mlir] Migrate away from PointerUnion::{is,get} (NFC) (llvm#122591)
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 a56eb7c commit 4f4e2ab

File tree

13 files changed

+21
-20
lines changed

13 files changed

+21
-20
lines changed

mlir/examples/transform-opt/mlir-transform-opt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class DiagnosticHandlerWrapper {
131131
if (auto *ptr = handler.dyn_cast<mlir::SourceMgrDiagnosticHandler *>()) {
132132
delete ptr;
133133
} else {
134-
delete handler.get<mlir::SourceMgrDiagnosticVerifierHandler *>();
134+
delete cast<mlir::SourceMgrDiagnosticVerifierHandler *>(handler);
135135
}
136136
}
137137

mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AbstractSparseLattice : public AnalysisState {
3737
AbstractSparseLattice(Value value) : AnalysisState(value) {}
3838

3939
/// Return the value this lattice is located at.
40-
Value getAnchor() const { return AnalysisState::getAnchor().get<Value>(); }
40+
Value getAnchor() const { return cast<Value>(AnalysisState::getAnchor()); }
4141

4242
/// Join the information contained in 'rhs' into this lattice. Returns
4343
/// if the value of the lattice changed.

mlir/include/mlir/IR/Matchers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct constant_op_binder {
9292
(void)result;
9393
assert(succeeded(result) && "expected ConstantLike op to be foldable");
9494

95-
if (auto attr = llvm::dyn_cast<AttrT>(foldedOp.front().get<Attribute>())) {
95+
if (auto attr = llvm::dyn_cast<AttrT>(cast<Attribute>(foldedOp.front()))) {
9696
if (bind_value)
9797
*bind_value = attr;
9898
return true;

mlir/include/mlir/IR/OpDefinition.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ class OpFoldResult : public PointerUnion<Attribute, Value> {
272272
void dump() const { llvm::errs() << *this << "\n"; }
273273

274274
MLIRContext *getContext() const {
275-
return is<Attribute>() ? get<Attribute>().getContext()
276-
: get<Value>().getContext();
275+
PointerUnion pu = *this;
276+
return isa<Attribute>(pu) ? cast<Attribute>(pu).getContext()
277+
: cast<Value>(pu).getContext();
277278
}
278279
};
279280

mlir/include/mlir/Interfaces/DataLayoutInterfaces.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def DataLayoutEntryInterface : AttrInterface<"DataLayoutEntryInterface"> {
8686
let extraClassDeclaration = [{
8787
/// Returns `true` if the key of this entry is a type.
8888
bool isTypeEntry() {
89-
return getKey().is<::mlir::Type>();
89+
return llvm::isa<::mlir::Type>(getKey());
9090
}
9191
}];
9292
}

mlir/include/mlir/Pass/AnalysisManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ struct NestedAnalysisMap {
262262
PassInstrumentor *getPassInstrumentor() const {
263263
if (auto *parent = getParent())
264264
return parent->getPassInstrumentor();
265-
return parentOrInstrumentor.get<PassInstrumentor *>();
265+
return cast<PassInstrumentor *>(parentOrInstrumentor);
266266
}
267267

268268
/// The cached analyses for nested operations.

mlir/lib/Analysis/DataFlowFramework.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void LatticeAnchor::print(raw_ostream &os) const {
8484
return value.print(os, OpPrintingFlags().skipRegions());
8585
}
8686

87-
return get<ProgramPoint *>()->print(os);
87+
return llvm::cast<ProgramPoint *>(*this)->print(os);
8888
}
8989

9090
Location LatticeAnchor::getLoc() const {
@@ -93,7 +93,7 @@ Location LatticeAnchor::getLoc() const {
9393
if (auto value = llvm::dyn_cast<Value>(*this))
9494
return value.getLoc();
9595

96-
ProgramPoint *pp = get<ProgramPoint *>();
96+
ProgramPoint *pp = llvm::cast<ProgramPoint *>(*this);
9797
if (!pp->isBlockStart())
9898
return pp->getPrevOp()->getLoc();
9999
return pp->getBlock()->getParent()->getLoc();

mlir/lib/AsmParser/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,7 @@ OperationParser::parseTrailingLocationSpecifier(OpOrArgument opOrArgument) {
21622162
if (auto *op = llvm::dyn_cast_if_present<Operation *>(opOrArgument))
21632163
op->setLoc(directLoc);
21642164
else
2165-
opOrArgument.get<BlockArgument>().setLoc(directLoc);
2165+
cast<BlockArgument>(opOrArgument).setLoc(directLoc);
21662166
return success();
21672167
}
21682168

mlir/lib/Bytecode/Writer/IRNumbering.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ struct AttrTypeNumbering {
5050
};
5151
struct AttributeNumbering : public AttrTypeNumbering {
5252
AttributeNumbering(Attribute value) : AttrTypeNumbering(value) {}
53-
Attribute getValue() const { return value.get<Attribute>(); }
53+
Attribute getValue() const { return cast<Attribute>(value); }
5454
};
5555
struct TypeNumbering : public AttrTypeNumbering {
5656
TypeNumbering(Type value) : AttrTypeNumbering(value) {}
57-
Type getValue() const { return value.get<Type>(); }
57+
Type getValue() const { return cast<Type>(value); }
5858
};
5959

6060
//===----------------------------------------------------------------------===//

mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct PDLIndexSymbol {
142142
const ast::Name *declName = decl->getName();
143143
return declName ? declName->getLoc() : decl->getLoc();
144144
}
145-
return definition.get<const ods::Operation *>()->getLoc();
145+
return cast<const ods::Operation *>(definition)->getLoc();
146146
}
147147

148148
/// The main definition of the symbol.
@@ -470,7 +470,7 @@ PDLDocument::findHover(const lsp::URIForFile &uri,
470470
if (const auto *op =
471471
llvm::dyn_cast_if_present<const ods::Operation *>(symbol->definition))
472472
return buildHoverForOpName(op, hoverRange);
473-
const auto *decl = symbol->definition.get<const ast::Decl *>();
473+
const auto *decl = cast<const ast::Decl *>(symbol->definition);
474474
return findHover(decl, hoverRange);
475475
}
476476

mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ struct TableGenRecordSymbol : public TableGenIndexSymbol {
165165
~TableGenRecordSymbol() override = default;
166166

167167
static bool classof(const TableGenIndexSymbol *symbol) {
168-
return symbol->definition.is<const Record *>();
168+
return isa<const Record *>(symbol->definition);
169169
}
170170

171171
/// Return the value of this symbol.
172-
const Record *getValue() const { return definition.get<const Record *>(); }
172+
const Record *getValue() const { return cast<const Record *>(definition); }
173173
};
174174
/// This class represents a single record value symbol.
175175
struct TableGenRecordValSymbol : public TableGenIndexSymbol {
@@ -178,12 +178,12 @@ struct TableGenRecordValSymbol : public TableGenIndexSymbol {
178178
~TableGenRecordValSymbol() override = default;
179179

180180
static bool classof(const TableGenIndexSymbol *symbol) {
181-
return symbol->definition.is<const RecordVal *>();
181+
return isa<const RecordVal *>(symbol->definition);
182182
}
183183

184184
/// Return the value of this symbol.
185185
const RecordVal *getValue() const {
186-
return definition.get<const RecordVal *>();
186+
return cast<const RecordVal *>(definition);
187187
}
188188

189189
/// The parent record of this symbol.

mlir/lib/Transforms/Utils/FoldUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ OperationFolder::processFoldResults(Operation *op,
260260

261261
// Check to see if there is a canonicalized version of this constant.
262262
auto res = op->getResult(i);
263-
Attribute attrRepl = foldResults[i].get<Attribute>();
263+
Attribute attrRepl = cast<Attribute>(foldResults[i]);
264264
if (auto *constOp =
265265
tryGetOrCreateConstant(uniquedConstants, dialect, attrRepl,
266266
res.getType(), erasedFoldedLocation)) {

mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ bool GreedyPatternRewriteDriver::processWorklist() {
523523
}
524524
// Materialize Attributes as SSA values.
525525
Operation *constOp = op->getDialect()->materializeConstant(
526-
rewriter, ofr.get<Attribute>(), resultType, op->getLoc());
526+
rewriter, cast<Attribute>(ofr), resultType, op->getLoc());
527527

528528
if (!constOp) {
529529
// If materialization fails, cleanup any operations generated for

0 commit comments

Comments
 (0)