Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mlir/examples/transform-opt/mlir-transform-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,17 @@ class DiagnosticHandlerWrapper {
/// Verifies the captured "expected-*" diagnostics if required.
llvm::LogicalResult verify() const {
if (auto *ptr =
handler.dyn_cast<mlir::SourceMgrDiagnosticVerifierHandler *>()) {
dyn_cast_if_present<mlir::SourceMgrDiagnosticVerifierHandler *>(
handler)) {
return ptr->verify();
}
return mlir::success();
}

/// Destructs the object of the same type as allocated.
~DiagnosticHandlerWrapper() {
if (auto *ptr = handler.dyn_cast<mlir::SourceMgrDiagnosticHandler *>()) {
if (auto *ptr =
dyn_cast_if_present<mlir::SourceMgrDiagnosticHandler *>(handler)) {
delete ptr;
} else {
delete cast<mlir::SourceMgrDiagnosticVerifierHandler *>(handler);
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static Value getIndexedPtrs(ConversionPatternRewriter &rewriter, Location loc,
/// an LLVM constant op.
static Value getAsLLVMValue(OpBuilder &builder, Location loc,
OpFoldResult foldResult) {
if (auto attr = foldResult.dyn_cast<Attribute>()) {
if (auto attr = dyn_cast_if_present<Attribute>(foldResult)) {
auto intAttr = cast<IntegerAttr>(attr);
return builder.create<LLVM::ConstantOp>(loc, intAttr).getResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ LogicalResult transform::applyTransformNamedSequence(
<< "expected one payload to be bound to the first argument, got "
<< bindings.at(0).size();
}
auto *payloadRoot = bindings.at(0).front().dyn_cast<Operation *>();
auto *payloadRoot = dyn_cast_if_present<Operation *>(bindings.at(0).front());
if (!payloadRoot) {
return transformRoot->emitError() << "expected the object bound to the "
"first argument to be an operation";
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/Vector/IR/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ SmallVector<Value> vector::getAsValues(OpBuilder &builder, Location loc,
SmallVector<Value> values;
llvm::transform(foldResults, std::back_inserter(values),
[&](OpFoldResult foldResult) {
if (auto attr = foldResult.dyn_cast<Attribute>())
if (auto attr = dyn_cast_if_present<Attribute>(foldResult))
return builder
.create<arith::ConstantIndexOp>(
loc, cast<IntegerAttr>(attr).getInt())
Expand Down Expand Up @@ -2880,7 +2880,7 @@ LogicalResult InsertOp::verify() {
return emitOpError(
"expected position attribute rank to match the dest vector rank");
for (auto [idx, pos] : llvm::enumerate(position)) {
if (auto attr = pos.dyn_cast<Attribute>()) {
if (auto attr = dyn_cast_if_present<Attribute>(pos)) {
int64_t constIdx = cast<IntegerAttr>(attr).getInt();
if (constIdx < 0 || constIdx >= destVectorType.getDimSize(idx)) {
return emitOpError("expected position attribute #")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ static Value dynamicallyExtractSubVector(OpBuilder &rewriter, Location loc,
int64_t numElementsToExtract) {
for (int i = 0; i < numElementsToExtract; ++i) {
Value extractLoc =
(i == 0) ? offset.dyn_cast<Value>()
(i == 0) ? dyn_cast_if_present<Value>(offset)
: rewriter.create<arith::AddIOp>(
loc, rewriter.getIndexType(), offset.dyn_cast<Value>(),
loc, rewriter.getIndexType(),
dyn_cast_if_present<Value>(offset),
rewriter.create<arith::ConstantIndexOp>(loc, i));
auto extractOp =
rewriter.create<vector::ExtractOp>(loc, source, extractLoc);
Expand Down
5 changes: 3 additions & 2 deletions mlir/lib/IR/AffineMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ AffineMap mlir::foldAttributesIntoMap(Builder &b, AffineMap map,
SmallVector<AffineExpr> dimReplacements, symReplacements;
int64_t numDims = 0;
for (int64_t i = 0; i < map.getNumDims(); ++i) {
if (auto attr = operands[i].dyn_cast<Attribute>()) {
if (auto attr = dyn_cast_if_present<Attribute>(operands[i])) {
dimReplacements.push_back(
b.getAffineConstantExpr(cast<IntegerAttr>(attr).getInt()));
} else {
Expand All @@ -758,7 +758,8 @@ AffineMap mlir::foldAttributesIntoMap(Builder &b, AffineMap map,
}
int64_t numSymbols = 0;
for (int64_t i = 0; i < map.getNumSymbols(); ++i) {
if (auto attr = operands[i + map.getNumDims()].dyn_cast<Attribute>()) {
if (auto attr =
dyn_cast_if_present<Attribute>(operands[i + map.getNumDims()])) {
symReplacements.push_back(
b.getAffineConstantExpr(cast<IntegerAttr>(attr).getInt()));
} else {
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ bool GreedyPatternRewriteDriver::processWorklist() {
bool materializationSucceeded = true;
for (auto [ofr, resultType] :
llvm::zip_equal(foldResults, op->getResultTypes())) {
if (auto value = ofr.dyn_cast<Value>()) {
if (auto value = dyn_cast_if_present<Value>(ofr)) {
assert(value.getType() == resultType &&
"folder produced value of incorrect type");
replacements.push_back(value);
Expand Down
5 changes: 3 additions & 2 deletions mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ void OpEmitter::genPropertiesSupportForBytecode(
writePropertiesMethod << tgfmt(writeBytecodeSegmentSizeLegacy, &fmtCtxt);
}
if (const auto *namedProperty =
attrOrProp.dyn_cast<const NamedProperty *>()) {
dyn_cast_if_present<const NamedProperty *>(attrOrProp)) {
StringRef name = namedProperty->name;
readPropertiesMethod << formatv(
R"(
Expand All @@ -1807,7 +1807,8 @@ void OpEmitter::genPropertiesSupportForBytecode(
name, tgfmt(namedProperty->prop.getWriteToMlirBytecodeCall(), &fctx));
continue;
}
const auto *namedAttr = attrOrProp.dyn_cast<const AttributeMetadata *>();
const auto *namedAttr =
dyn_cast_if_present<const AttributeMetadata *>(attrOrProp);
StringRef name = namedAttr->attrName;
if (namedAttr->isRequired) {
readPropertiesMethod << formatv(R"(
Expand Down
6 changes: 3 additions & 3 deletions mlir/unittests/IR/SymbolTableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class ReplaceAllSymbolUsesTest : public ::testing::Test {
// Check that it got renamed.
bool calleeFound = false;
fooOp->walk([&](CallOpInterface callOp) {
StringAttr callee = callOp.getCallableForCallee()
.dyn_cast<SymbolRefAttr>()
.getLeafReference();
StringAttr callee =
dyn_cast_if_present<SymbolRefAttr>(callOp.getCallableForCallee())
.getLeafReference();
EXPECT_EQ(callee, "baz");
calleeFound = true;
});
Expand Down
Loading