Skip to content

Commit

Permalink
Use isa and cast as is and get are deprecated
Browse files Browse the repository at this point in the history
Signed-off-by: Nirvedh Meshram <nirvedh@gmail.com>
  • Loading branch information
nirvedhmeshram committed Jan 20, 2025
1 parent 88c7a06 commit d07a2ec
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static Value getAsIndexValue(OpFoldResult attrOrValue, OpBuilder &builder,
return val;
matchPattern(val, m_Constant(&attr));
} else {
attr = llvm::cast<IntegerAttr>(attrOrValue.get<Attribute>());
attr = llvm::cast<IntegerAttr>(cast<Attribute>(attrOrValue));
}
return builder.createOrFold<arith::ConstantIndexOp>(
loc, attr.getValue().getSExtValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static LogicalResult commonRunOnOperation(

// Do nothing if any of inner tile sizes is dynamic.
if (llvm::any_of(packOp.getMixedTiles(), [](OpFoldResult tile) {
return tile.is<Value>();
return isa<Value>(tile);
})) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static Value getAsIndexValue(OpFoldResult attrOrValue, OpBuilder &builder,
return val;
matchPattern(val, m_Constant(&attr));
} else {
attr = llvm::cast<IntegerAttr>(attrOrValue.get<Attribute>());
attr = cast<IntegerAttr>(cast<Attribute>(attrOrValue));
}
return builder.createOrFold<arith::ConstantIndexOp>(loc, attr.getInt());
}
Expand Down Expand Up @@ -101,12 +101,12 @@ struct VectorizePadWithConditions final

/// Return true if the given `attrOrValue` is a constant zero.
auto isConstantZero = [](OpFoldResult attrOrValue) {
if (attrOrValue.is<Attribute>()) {
auto attr = llvm::dyn_cast<IntegerAttr>(attrOrValue.get<Attribute>());
if (isa<Attribute>(attrOrValue)) {
auto attr = dyn_cast<IntegerAttr>(cast<Attribute>(attrOrValue));
return attr && attr.getValue().getZExtValue() == 0;
}
IntegerAttr attr;
return matchPattern(attrOrValue.get<Value>(), m_Constant(&attr)) &&
return matchPattern(cast<Value>(attrOrValue), m_Constant(&attr)) &&
attr.getValue().getZExtValue() == 0;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void DistributionLayout::print(raw_ostream &os) const {
void DistributionLayout::onUpdate(DataFlowSolver *solver) const {
AnalysisState::onUpdate(solver);

Value value = anchor.get<Value>();
Value value = cast<Value>(anchor);

if (propagation) {
// Make propagation run again on all users of this value.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/iree/compiler/Codegen/LLVMCPU/DispatchABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,12 @@ MemRefDescriptor HALDispatchABI::loadBinding(Operation *forOp, int64_t ordinal,
currentStrideVal = builder.create<LLVM::ConstantOp>(
loc, llvmIndexType, currentStrideInt.value());
} else {
currentStrideVal = currentStride.get<Value>();
currentStrideVal = cast<Value>(currentStride);
}
currentStride =
builder.create<LLVM::MulOp>(loc, currentStrideVal, dim)
.getResult();
desc.setStride(builder, loc, i - 1, currentStride.get<Value>());
desc.setStride(builder, loc, i - 1, cast<Value>(currentStride));
} else {
currentStride = builder.getIndexAttr(strides[i - 1]);
desc.setConstantStride(builder, loc, i - 1, strides[i - 1]);
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/iree/compiler/Codegen/LLVMCPU/KernelDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ static LogicalResult setRootConfig(mlir::FunctionOpInterface entryPointFn,
DictionaryAttr pipelineConfig;
auto target = IREE::HAL::ExecutableTargetAttr::lookup(entryPointFn);
bool hasDynamicInnerTile = llvm::any_of(
op.getMixedTiles(), [](OpFoldResult ofr) { return ofr.is<Value>(); });
op.getMixedTiles(), [](OpFoldResult ofr) { return isa<Value>(ofr); });
if (!hasDynamicInnerTile && !isX86(target) && !isRISCV(target)) {
pipelineConfig = getPipelineConfWithDecompositionAttr(op.getContext());
}
Expand Down Expand Up @@ -1829,7 +1829,7 @@ static LogicalResult setRootConfig(mlir::FunctionOpInterface entryPointFn,
DictionaryAttr pipelineConfig;
auto target = IREE::HAL::ExecutableTargetAttr::lookup(entryPointFn);
bool hasDynamicInnerTile = llvm::any_of(
op.getMixedTiles(), [](OpFoldResult ofr) { return ofr.is<Value>(); });
op.getMixedTiles(), [](OpFoldResult ofr) { return isa<Value>(ofr); });
if (!hasDynamicInnerTile && !isX86(target) && !isRISCV(target)) {
pipelineConfig = getPipelineConfWithDecompositionAttr(op.getContext());
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/iree/compiler/Codegen/LLVMGPU/ConvertToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@ class ConvertIREEBindingSubspanOp : public ConvertToLLVMPattern {
currentStrideVal = rewriter.create<LLVM::ConstantOp>(
loc, llvmIndexType, currentStrideInt.value());
} else {
currentStrideVal = currentStride.get<Value>();
currentStrideVal = cast<Value>(currentStride);
}
currentStride =
rewriter.create<LLVM::MulOp>(loc, currentStrideVal, dim)
.getResult();
desc.setStride(rewriter, loc, i - 1, currentStride.get<Value>());
desc.setStride(rewriter, loc, i - 1, cast<Value>(currentStride));
} else {
currentStride = rewriter.getIndexAttr(strides[i - 1]);
desc.setConstantStride(rewriter, loc, i - 1, strides[i - 1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ getPaddedShapeFromTensorLoad(IREE::Flow::DispatchTensorLoadOp tensorLoad,
FailureOr<int64_t> upperBound =
ValueBoundsConstraintSet::computeConstantBound(
presburger::BoundType::UB,
{size.get<Value>(), /*dim=*/std::nullopt},
{cast<Value>(size), /*dim=*/std::nullopt},
/*stopCondition=*/nullptr, /*closedUB=*/true);
if (failed(upperBound))
return failure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,11 @@ struct ReifyExtractOfCreateMask final
for (auto [idx, size] :
llvm::zip_equal(extractOp.getMixedPosition(), maskOp.getOperands())) {
Value idxVal;
if (idx.is<Attribute>()) {
if (isa<Attribute>(idx)) {
idxVal = rewriter.create<arith::ConstantIndexOp>(
loc, cast<IntegerAttr>(idx.get<Attribute>()).getInt());
loc, cast<IntegerAttr>(cast<Attribute>(idx)).getInt());
} else {
idxVal = idx.get<Value>();
idxVal = cast<Value>(idx);
}
Value cmpIdx = rewriter.create<arith::CmpIOp>(
loc, arith::CmpIPredicate::slt, idxVal, size);
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/iree/compiler/Codegen/Transforms/Transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ static SliceAndDynamicDims cloneOffsetsSizesAndStridesImpl(
SmallVector<OpFoldResult> clonedOfrs;
clonedOfrs.reserve(ofrs.size());
for (auto ofr : ofrs) {
if (ofr.is<Attribute>()) {
if (isa<Attribute>(ofr)) {
clonedOfrs.push_back(ofr);
} else {
clonedOfrs.push_back(bvm.lookupOrDefault(ofr.get<Value>()));
clonedOfrs.push_back(bvm.lookupOrDefault(cast<Value>(ofr)));
}
}
return clonedOfrs;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/iree/compiler/Dialect/Flow/IR/FlowOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def FLOW_CallOp : FLOW_Op<"call", [

/// Set the callee for this operation.
void setCalleeFromCallable(CallInterfaceCallable callee) {
(*this)->setAttr("callee", callee.get<SymbolRefAttr>());
(*this)->setAttr("callee", cast<SymbolRefAttr>(callee));
}

ValueRange getOperandDynamicDims(unsigned idx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ reifyDynamicResultDimsImpl(OpBuilder &b, Value value,
return failure();
for (int64_t i = 0; i < shapedType.getRank(); ++i)
if (shapedType.isDynamicDim(i))
dynamicDims.push_back(dims[opResult.getResultNumber()][i].get<Value>());
dynamicDims.push_back(cast<Value>(dims[opResult.getResultNumber()][i]));
return success();
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/iree/compiler/Dialect/Stream/IR/StreamOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ def Stream_AsyncCallOp : Stream_Op<"async.call", [

/// Set the callee for this operation.
void setCalleeFromCallable(CallInterfaceCallable callee) {
(*this)->setAttr("callee", callee.get<SymbolRefAttr>());
(*this)->setAttr("callee", cast<SymbolRefAttr>(callee));
}

Value getOperandSize(unsigned idx) {
Expand Down Expand Up @@ -3322,7 +3322,7 @@ def Stream_CmdCallOp : Stream_Op<"cmd.call", [

/// Set the callee for this operation.
void setCalleeFromCallable(CallInterfaceCallable callee) {
(*this)->setAttr("callee", callee.get<SymbolRefAttr>());
(*this)->setAttr("callee", cast<SymbolRefAttr>(callee));
}

Value getOperandSize(unsigned idx) {
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/iree/compiler/Dialect/Util/Analysis/Explorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void Explorer::initializeGlobalInfos() {
void Explorer::initializeInverseCallGraph() {
forEachFunctionLikeOp([&](FunctionOpInterface parentOp) {
parentOp->walk([&](CallOpInterface callOp) {
if (callOp.getCallableForCallee().is<Value>()) {
if (isa<Value>(callOp.getCallableForCallee())) {
// Indirect calls can't be tracked in the call graph, so ensure we mark
// the incomplete flag so that any call graph queries return
// TraversalResult::INCOMPLETE.
Expand Down Expand Up @@ -777,7 +777,7 @@ TraversalResult Explorer::walkDefiningOps(Value value, ResultWalkFn fn,
// Indirect calls would require us to perform an analysis to first see if we
// can make them direct or annotate the call sites with the possible
// targets.
if (callOp.getCallableForCallee().is<Value>()) {
if (isa<Value>(callOp.getCallableForCallee())) {
LLVM_DEBUG({
llvm::dbgs()
<< " !! traversal incomplete due to unanalyzable indirect call: ";
Expand All @@ -786,7 +786,7 @@ TraversalResult Explorer::walkDefiningOps(Value value, ResultWalkFn fn,
});
return TraversalResult::INCOMPLETE;
}
auto targetSymbol = callOp.getCallableForCallee().get<SymbolRefAttr>();
auto targetSymbol = cast<SymbolRefAttr>(callOp.getCallableForCallee());
auto targetOp = symbolTables.lookupNearestSymbolFrom<CallableOpInterface>(
callOp, targetSymbol);
assert(targetOp && "call target not found");
Expand Down Expand Up @@ -1031,7 +1031,7 @@ TraversalResult Explorer::walkTransitiveUses(Value value, UseWalkFn fn,
// Move across a call to the callee entry block.
auto traverseCallOp = [&](CallOpInterface callOp, unsigned operandIdx) {
auto callable = callOp.getCallableForCallee();
if (callable.is<Value>()) {
if (isa<Value>(callable)) {
LLVM_DEBUG({
llvm::dbgs()
<< " !! traversal incomplete due to unanalyzable indirect call: ";
Expand All @@ -1040,7 +1040,7 @@ TraversalResult Explorer::walkTransitiveUses(Value value, UseWalkFn fn,
});
return TraversalResult::INCOMPLETE;
}
auto targetSymbol = callable.get<SymbolRefAttr>();
auto targetSymbol = cast<SymbolRefAttr>(callable);
auto targetOp = symbolTables.lookupNearestSymbolFrom<CallableOpInterface>(
callOp, targetSymbol);
assert(targetOp && "call target not found");
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/iree/compiler/Dialect/Util/IR/UtilOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ def Util_CallOp : Util_Op<"call", [
return (*this)->getAttrOfType<SymbolRefAttr>("callee");
}
void setCalleeFromCallable(CallInterfaceCallable callee) {
(*this)->setAttr("callee", callee.get<SymbolRefAttr>());
(*this)->setAttr("callee", cast<SymbolRefAttr>(callee));
}

// Clones the call and potentially expands each operand and result.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/iree/compiler/Dialect/VM/IR/VMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -4223,7 +4223,7 @@ class VM_CallBaseOp<string mnemonic, list<Trait> traits = []> :

/// Set the callee for this operation.
void setCalleeFromCallable(CallInterfaceCallable callee) {
(*this)->setAttr("callee", callee.get<SymbolRefAttr>());
(*this)->setAttr("callee", cast<SymbolRefAttr>(callee));
}

/// Get the argument operands to the called function as a mutable range, this is
Expand Down

0 comments on commit d07a2ec

Please sign in to comment.