Skip to content

Commit 77f903f

Browse files
authored
Using explicit operation types in passes. (#21971)
@kuhar noted that using `auto op = getOperation();` can mask errors if the Passes.td changes and I've personally had that happen before - updating all our usage to use the explicit types so that we'll get compile errors if types don't match (or aren't downcast-compatible).
1 parent bb77caf commit 77f903f

File tree

166 files changed

+241
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+241
-240
lines changed

compiler/plugins/input/StableHLO/Conversion/Preprocessing/FlattenTuplesInCFG.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,15 @@ LogicalResult convertFunction(func::FuncOp oldFunction,
316316
struct FlattenTuplesInCFG final
317317
: impl::FlattenTuplesInCFGBase<FlattenTuplesInCFG> {
318318
void runOnOperation() override {
319-
ModuleOp module = getOperation();
320-
MLIRContext *ctx = module.getContext();
319+
mlir::ModuleOp moduleOp = getOperation();
320+
MLIRContext *ctx = moduleOp.getContext();
321321
Builder builder(ctx);
322322

323323
// Build a list of (oldFunction, newFunction) for all functions we need to
324324
// replace. This will ensure that when we go to convert function bodies we
325325
// have only new functions defined.
326326
SmallVector<std::pair<func::FuncOp, func::FuncOp>> convertedFunctions;
327-
for (auto oldFunction : module.getOps<func::FuncOp>()) {
327+
for (auto oldFunction : moduleOp.getOps<func::FuncOp>()) {
328328
FunctionType oldFunctionType = oldFunction.getFunctionType();
329329

330330
llvm::SmallVector<Type> newInputTypes;
@@ -349,7 +349,7 @@ struct FlattenTuplesInCFG final
349349
// Replace functions in the module.
350350
for (auto [oldFunction, newFunction] : convertedFunctions) {
351351
oldFunction.erase();
352-
module.push_back(newFunction);
352+
moduleOp.push_back(newFunction);
353353
}
354354

355355
// Run canonicalization patterns to cancel out remaining tuple ops. We need

compiler/plugins/input/StableHLO/Conversion/Preprocessing/FlattenTuplesInSCF.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ struct FlattenTuplesInSCF final
243243
}
244244

245245
void runOnOperation() override {
246-
ModuleOp module = getOperation();
247-
MLIRContext *ctx = module.getContext();
246+
MLIRContext *ctx = &getContext();
248247
Builder b(ctx);
249248

250249
// Run canonicalization patterns to cancel out remaining tuple ops. We need

compiler/plugins/input/TOSA/InputConversion/Converti48Toi64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ void Converti48Toi64Pass::runOnOperation() {
166166
});
167167

168168
auto *ctx = &getContext();
169-
auto func = getOperation();
169+
mlir::FunctionOpInterface funcOp = getOperation();
170170

171171
RewritePatternSet patterns(&getContext());
172172
patterns.add<GenericTypeConvert>(ctx, converter);
173173
populateFunctionOpInterfaceTypeConversionPattern<func::FuncOp>(patterns,
174174
converter);
175175

176-
if (failed(applyFullConversion(func, target, std::move(patterns)))) {
176+
if (failed(applyFullConversion(funcOp, target, std::move(patterns)))) {
177177
signalPassFailure();
178178
}
179179
}

compiler/plugins/input/TOSA/InputConversion/TosaToLinalgExt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ class TosaToLinalgExtPass final
157157
target.addIllegalOp<tosa::ScatterOp>();
158158
target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
159159

160-
FunctionOpInterface func = getOperation();
160+
mlir::FunctionOpInterface funcOp = getOperation();
161161
mlir::iree_compiler::populateTosaToLinalgExtPatterns(&patterns);
162-
if (failed(applyFullConversion(func, target, std::move(patterns))))
162+
if (failed(applyFullConversion(funcOp, target, std::move(patterns))))
163163
signalPassFailure();
164164
}
165165
};

compiler/src/iree/compiler/Codegen/Common/BufferizeCopyOnlyDispatchesPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct BufferizeCopyOnlyDispatchesPass final
5151
} // namespace
5252

5353
void BufferizeCopyOnlyDispatchesPass::runOnOperation() {
54-
auto funcOp = getOperation();
54+
mlir::FunctionOpInterface funcOp = getOperation();
5555

5656
/// Check if the dispatch has all sources for
5757
/// `iree_tensor_ext.dispatch.tensor.store` operations coming from

compiler/src/iree/compiler/Codegen/Common/CPU/CPUPrepareUkernels.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ struct CPUPrepareUkernelsPass
411411
void CPUPrepareUkernelsPass::runOnOperation() {
412412
MLIRContext *ctx = &getContext();
413413
RewritePatternSet patterns(ctx);
414-
auto funcOp = getOperation();
414+
mlir::FunctionOpInterface funcOp = getOperation();
415415
IRRewriter rewriter(ctx);
416416
auto targetAttr = IREE::HAL::ExecutableTargetAttr::lookup(funcOp);
417417

compiler/src/iree/compiler/Codegen/Common/ConcretizePadResultShape.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ConcretizePadResultShapePass final
134134
public:
135135
void runOnOperation() override {
136136
MLIRContext *context = &getContext();
137-
auto funcOp = getOperation();
137+
mlir::FunctionOpInterface funcOp = getOperation();
138138

139139
ConfigTrackingListener listener;
140140
GreedyRewriteConfig config;

compiler/src/iree/compiler/Codegen/Common/ConvertToDestinationPassingStylePass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ struct SwitchStoreOfIfResultValue
599599
} // namespace
600600

601601
void ConvertToDestinationPassingStylePass::runOnOperation() {
602-
auto funcOp = getOperation();
602+
mlir::FunctionOpInterface funcOp = getOperation();
603603
MLIRContext *context = &getContext();
604604

605605
// Dont do anything for functions that have multiple blocks for now.

compiler/src/iree/compiler/Codegen/Common/DropVectorUnitDims.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DropVectorUnitDimsPass
3131

3232
void DropVectorUnitDimsPass::runOnOperation() {
3333
MLIRContext *ctx = &getContext();
34-
auto funcOp = getOperation();
34+
mlir::FunctionOpInterface funcOp = getOperation();
3535

3636
// Apply transfer ops write to read forwarding and dead transfer write
3737
// optimizations.

compiler/src/iree/compiler/Codegen/Common/EraseDeadAllocAndStores.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class EraseDeadAllocAndStoresPass final
3131
};
3232

3333
void EraseDeadAllocAndStoresPass::runOnOperation() {
34-
auto funcOp = getOperation();
34+
mlir::FunctionOpInterface funcOp = getOperation();
3535
IRRewriter rewriter(&getContext());
3636
memref::eraseDeadAllocAndStores(rewriter, funcOp);
3737
}

0 commit comments

Comments
 (0)