Skip to content

Commit b0746c6

Browse files
[mlir-tblgen] Migrate away from PointerUnion::{is,get} (NFC) (llvm#119994)
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 49a5ad8 commit b0746c6

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,7 @@ void OpEmitter::buildParamList(SmallVectorImpl<MethodParameter> &paramList,
31623162
isOptional);
31633163
continue;
31643164
}
3165-
const NamedAttribute &namedAttr = *arg.get<NamedAttribute *>();
3165+
const NamedAttribute &namedAttr = *cast<NamedAttribute *>(arg);
31663166
const Attribute &attr = namedAttr.attr;
31673167

31683168
// Inferred attributes don't need to be added to the param list.
@@ -3499,14 +3499,14 @@ void OpEmitter::genSideEffectInterfaceMethods() {
34993499
/// Attributes and Operands.
35003500
for (unsigned i = 0, operandIt = 0, e = op.getNumArgs(); i != e; ++i) {
35013501
Argument arg = op.getArg(i);
3502-
if (arg.is<NamedTypeConstraint *>()) {
3502+
if (isa<NamedTypeConstraint *>(arg)) {
35033503
resolveDecorators(op.getArgDecorators(i), operandIt, EffectKind::Operand);
35043504
++operandIt;
35053505
continue;
35063506
}
3507-
if (arg.is<NamedProperty *>())
3507+
if (isa<NamedProperty *>(arg))
35083508
continue;
3509-
const NamedAttribute *attr = arg.get<NamedAttribute *>();
3509+
const NamedAttribute *attr = cast<NamedAttribute *>(arg);
35103510
if (attr->attr.getBaseAttr().isSymbolRefAttr())
35113511
resolveDecorators(op.getArgDecorators(i), i, EffectKind::Symbol);
35123512
}
@@ -3547,7 +3547,7 @@ void OpEmitter::genSideEffectInterfaceMethods() {
35473547
.str();
35483548
} else if (location.kind == EffectKind::Symbol) {
35493549
// A symbol reference requires adding the proper attribute.
3550-
const auto *attr = op.getArg(location.index).get<NamedAttribute *>();
3550+
const auto *attr = cast<NamedAttribute *>(op.getArg(location.index));
35513551
std::string argName = op.getGetterName(attr->name);
35523552
if (attr->attr.isOptional()) {
35533553
body << " if (auto symbolRef = " << argName << "Attr())\n "
@@ -3648,7 +3648,7 @@ void OpEmitter::genTypeInterfaceMethods() {
36483648
// If this is an attribute, index into the attribute dictionary.
36493649
} else {
36503650
auto *attr =
3651-
op.getArg(arg.operandOrAttributeIndex()).get<NamedAttribute *>();
3651+
cast<NamedAttribute *>(op.getArg(arg.operandOrAttributeIndex()));
36523652
body << " ::mlir::TypedAttr odsInferredTypeAttr" << inferredTypeIdx
36533653
<< " = ";
36543654
if (op.getDialect().usePropertiesForAttributes()) {

mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ static void populateBuilderArgs(const Operator &op,
628628
name = formatv("_gen_arg_{0}", i);
629629
name = sanitizeName(name);
630630
builderArgs.push_back(name);
631-
if (!op.getArg(i).is<NamedAttribute *>())
631+
if (!isa<NamedAttribute *>(op.getArg(i)))
632632
operandNames.push_back(name);
633633
}
634634
}

mlir/tools/mlir-tblgen/RewriterGen.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,15 @@ void PatternEmitter::emitOpMatch(DagNode tree, StringRef opName, int depth) {
655655
}
656656

657657
// Next handle DAG leaf: operand or attribute
658-
if (opArg.is<NamedTypeConstraint *>()) {
658+
if (isa<NamedTypeConstraint *>(opArg)) {
659659
auto operandName =
660660
formatv("{0}.getODSOperands({1})", castedName, nextOperand);
661661
emitOperandMatch(tree, castedName, operandName.str(), opArgIdx,
662662
/*operandMatcher=*/tree.getArgAsLeaf(i),
663663
/*argName=*/tree.getArgName(i), opArgIdx,
664664
/*variadicSubIndex=*/std::nullopt);
665665
++nextOperand;
666-
} else if (opArg.is<NamedAttribute *>()) {
666+
} else if (isa<NamedAttribute *>(opArg)) {
667667
emitAttributeMatch(tree, opName, opArgIdx, depth);
668668
} else {
669669
PrintFatalError(loc, "unhandled case when matching op");
@@ -680,7 +680,7 @@ void PatternEmitter::emitOperandMatch(DagNode tree, StringRef opName,
680680
int argIndex,
681681
std::optional<int> variadicSubIndex) {
682682
Operator &op = tree.getDialectOp(opMap);
683-
auto *operand = op.getArg(operandIndex).get<NamedTypeConstraint *>();
683+
auto *operand = cast<NamedTypeConstraint *>(op.getArg(operandIndex));
684684

685685
// If a constraint is specified, we need to generate C++ statements to
686686
// check the constraint.
@@ -770,7 +770,7 @@ void PatternEmitter::emitEitherOperandMatch(DagNode tree, DagNode eitherArgTree,
770770
// need to queue the operation only if the matching success. Thus we emit
771771
// the code at the end.
772772
tblgenOps << formatv("tblgen_ops.push_back({0});\n", argName);
773-
} else if (op.getArg(argIndex).is<NamedTypeConstraint *>()) {
773+
} else if (isa<NamedTypeConstraint *>(op.getArg(argIndex))) {
774774
emitOperandMatch(tree, opName, /*operandName=*/formatv("v{0}", i).str(),
775775
operandIndex,
776776
/*operandMatcher=*/eitherArgTree.getArgAsLeaf(i),
@@ -851,7 +851,7 @@ void PatternEmitter::emitVariadicOperandMatch(DagNode tree,
851851
os << formatv("tblgen_ops.push_back({0});\n", argName);
852852

853853
os.unindent() << "}\n";
854-
} else if (op.getArg(argIndex).is<NamedTypeConstraint *>()) {
854+
} else if (isa<NamedTypeConstraint *>(op.getArg(argIndex))) {
855855
auto operandName = formatv("variadic_operand_range.slice({0}, 1)", i);
856856
emitOperandMatch(tree, opName, operandName.str(), operandIndex,
857857
/*operandMatcher=*/variadicArgTree.getArgAsLeaf(i),
@@ -867,7 +867,7 @@ void PatternEmitter::emitVariadicOperandMatch(DagNode tree,
867867
void PatternEmitter::emitAttributeMatch(DagNode tree, StringRef opName,
868868
int argIndex, int depth) {
869869
Operator &op = tree.getDialectOp(opMap);
870-
auto *namedAttr = op.getArg(argIndex).get<NamedAttribute *>();
870+
auto *namedAttr = cast<NamedAttribute *>(op.getArg(argIndex));
871871
const auto &attr = namedAttr->attr;
872872

873873
os << "{\n";
@@ -1775,7 +1775,7 @@ void PatternEmitter::supplyValuesForOpArgs(
17751775
auto patArgName = node.getArgName(argIndex);
17761776
if (leaf.isConstantAttr() || leaf.isEnumAttrCase()) {
17771777
// TODO: Refactor out into map to avoid recomputing these.
1778-
if (!opArg.is<NamedAttribute *>())
1778+
if (!isa<NamedAttribute *>(opArg))
17791779
PrintFatalError(loc, Twine("expected attribute ") + Twine(argIndex));
17801780
if (!patArgName.empty())
17811781
os << "/*" << patArgName << "=*/";
@@ -1805,7 +1805,7 @@ void PatternEmitter::createAggregateLocalVarsForOpArgs(
18051805
bool hasOperandSegmentSizes = false;
18061806
std::vector<std::string> sizes;
18071807
for (int argIndex = 0, e = resultOp.getNumArgs(); argIndex < e; ++argIndex) {
1808-
if (resultOp.getArg(argIndex).is<NamedAttribute *>()) {
1808+
if (isa<NamedAttribute *>(resultOp.getArg(argIndex))) {
18091809
// The argument in the op definition.
18101810
auto opArgName = resultOp.getArgName(argIndex);
18111811
hasOperandSegmentSizes =
@@ -1826,7 +1826,7 @@ void PatternEmitter::createAggregateLocalVarsForOpArgs(
18261826
}
18271827

18281828
const auto *operand =
1829-
resultOp.getArg(argIndex).get<NamedTypeConstraint *>();
1829+
cast<NamedTypeConstraint *>(resultOp.getArg(argIndex));
18301830
std::string varName;
18311831
if (operand->isVariadic()) {
18321832
++numVariadic;

mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
#include <optional>
3434

3535
using llvm::ArrayRef;
36+
using llvm::cast;
3637
using llvm::formatv;
38+
using llvm::isa;
3739
using llvm::raw_ostream;
3840
using llvm::raw_string_ostream;
3941
using llvm::Record;
@@ -607,11 +609,11 @@ static void emitArgumentSerialization(const Operator &op, ArrayRef<SMLoc> loc,
607609
bool areOperandsAheadOfAttrs = true;
608610
// Find the first attribute.
609611
const Argument *it = llvm::find_if(op.getArgs(), [](const Argument &arg) {
610-
return arg.is<NamedAttribute *>();
612+
return isa<NamedAttribute *>(arg);
611613
});
612614
// Check whether all following arguments are attributes.
613615
for (const Argument *ie = op.arg_end(); it != ie; ++it) {
614-
if (!it->is<NamedAttribute *>()) {
616+
if (!isa<NamedAttribute *>(*it)) {
615617
areOperandsAheadOfAttrs = false;
616618
break;
617619
}
@@ -642,7 +644,7 @@ static void emitArgumentSerialization(const Operator &op, ArrayRef<SMLoc> loc,
642644
for (unsigned i = 0, e = op.getNumArgs(); i < e; ++i) {
643645
auto argument = op.getArg(i);
644646
os << tabs << "{\n";
645-
if (argument.is<NamedTypeConstraint *>()) {
647+
if (isa<NamedTypeConstraint *>(argument)) {
646648
os << tabs
647649
<< formatv(" for (auto arg : {0}.getODSOperands({1})) {{\n", opVar,
648650
operandNum);
@@ -657,7 +659,7 @@ static void emitArgumentSerialization(const Operator &op, ArrayRef<SMLoc> loc,
657659
os << " }\n";
658660
operandNum++;
659661
} else {
660-
NamedAttribute *attr = argument.get<NamedAttribute *>();
662+
NamedAttribute *attr = cast<NamedAttribute *>(argument);
661663
auto newtabs = tabs.str() + " ";
662664
emitAttributeSerialization(
663665
(attr->attr.isOptional() ? attr->attr.getBaseAttr() : attr->attr),
@@ -962,7 +964,7 @@ static void emitOperandDeserialization(const Operator &op, ArrayRef<SMLoc> loc,
962964
os << tabs << "}\n";
963965
} else {
964966
os << tabs << formatv("if ({0} < {1}.size()) {{\n", wordIndex, words);
965-
auto *attr = argument.get<NamedAttribute *>();
967+
auto *attr = cast<NamedAttribute *>(argument);
966968
auto newtabs = tabs.str() + " ";
967969
emitAttributeDeserialization(
968970
(attr->attr.isOptional() ? attr->attr.getBaseAttr() : attr->attr),

0 commit comments

Comments
 (0)