Existing Linalg passes are still anchoring on FuncOp.
Relax this unnecessary limitation.
Differential Revision: https://reviews.llvm.org/D154497
std::unique_ptr<Pass> createLinalgNamedOpConversionPass();
-std::unique_ptr<OperationPass<func::FuncOp>>
-createLinalgInlineScalarOperandsPass();
+std::unique_ptr<Pass> createLinalgInlineScalarOperandsPass();
/// Create a pass to convert Linalg operations to scf.for loops and
/// memref.load/memref.store accesses.
-std::unique_ptr<OperationPass<func::FuncOp>> createConvertLinalgToLoopsPass();
+std::unique_ptr<Pass> createConvertLinalgToLoopsPass();
/// Create a pass to convert Linalg operations to scf.parallel loops and
/// memref.load/memref.store accesses.
-std::unique_ptr<OperationPass<func::FuncOp>>
-createConvertLinalgToParallelLoopsPass();
+std::unique_ptr<Pass> createConvertLinalgToParallelLoopsPass();
/// Create a pass to convert Linalg operations to affine.for loops and
/// affine_load/affine_store accesses.
/// Placeholder for now, this is NYI.
-std::unique_ptr<OperationPass<func::FuncOp>>
-createConvertLinalgToAffineLoopsPass();
+std::unique_ptr<Pass> createConvertLinalgToAffineLoopsPass();
/// Create a pass to convert Linalg operations which work on tensors to use
/// buffers instead.
-std::unique_ptr<OperationPass<func::FuncOp>> createLinalgBufferizePass();
+std::unique_ptr<Pass> createLinalgBufferizePass();
/// Create a pass to convert named Linalg operations to Linalg generic
/// operations.
-std::unique_ptr<OperationPass<func::FuncOp>> createLinalgGeneralizationPass();
+std::unique_ptr<Pass> createLinalgGeneralizationPass();
/// Create a pass to convert Linalg operations to equivalent operations that
/// work on primitive types, if possible.
let dependentDialects = ["linalg::LinalgDialect", "tensor::TensorDialect"];
}
-def LinalgInlineScalarOperands : Pass<"linalg-inline-scalar-operands", "func::FuncOp"> {
+def LinalgInlineScalarOperands : Pass<"linalg-inline-scalar-operands"> {
let summary = "Inline scalar operands into linalg generic ops";
let constructor = "mlir::createLinalgInlineScalarOperandsPass()";
let dependentDialects = [
];
}
-def LinalgLowerToAffineLoops : Pass<"convert-linalg-to-affine-loops", "func::FuncOp"> {
+def LinalgLowerToAffineLoops : Pass<"convert-linalg-to-affine-loops"> {
let summary = "Lower the operations from the linalg dialect into affine "
"loops";
let constructor = "mlir::createConvertLinalgToAffineLoopsPass()";
"affine::AffineDialect", "linalg::LinalgDialect", "memref::MemRefDialect"];
}
-def LinalgLowerToLoops : Pass<"convert-linalg-to-loops", "func::FuncOp"> {
+def LinalgLowerToLoops : Pass<"convert-linalg-to-loops"> {
let summary = "Lower the operations from the linalg dialect into loops";
let constructor = "mlir::createConvertLinalgToLoopsPass()";
let dependentDialects = [
}
def LinalgLowerToParallelLoops
- : Pass<"convert-linalg-to-parallel-loops", "func::FuncOp"> {
+ : Pass<"convert-linalg-to-parallel-loops"> {
let summary = "Lower the operations from the linalg dialect into parallel "
"loops";
let constructor = "mlir::createConvertLinalgToParallelLoopsPass()";
];
}
-def LinalgBufferize : Pass<"linalg-bufferize", "func::FuncOp"> {
+def LinalgBufferize : Pass<"linalg-bufferize"> {
let summary = "Bufferize the linalg dialect";
let constructor = "mlir::createLinalgBufferizePass()";
let dependentDialects = [
];
}
-def LinalgGeneralization : Pass<"linalg-generalize-named-ops", "func::FuncOp"> {
+def LinalgGeneralization : Pass<"linalg-generalize-named-ops"> {
let summary = "Convert named ops into generic ops";
let constructor = "mlir::createLinalgGeneralizationPass()";
let dependentDialects = ["linalg::LinalgDialect"];
};
} // namespace
-std::unique_ptr<OperationPass<func::FuncOp>> mlir::createLinalgBufferizePass() {
+std::unique_ptr<Pass> mlir::createLinalgBufferizePass() {
return std::make_unique<LinalgBufferizePass>();
}
} // namespace
void LinalgGeneralizationPass::runOnOperation() {
- func::FuncOp func = getOperation();
RewritePatternSet patterns(&getContext());
populateLinalgNamedOpsGeneralizationPatterns(patterns);
- (void)applyPatternsAndFoldGreedily(func.getBody(), std::move(patterns));
+ (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns));
}
void mlir::linalg::populateLinalgNamedOpsGeneralizationPatterns(
patterns.add<LinalgGeneralizationPattern>(patterns.getContext());
}
-std::unique_ptr<OperationPass<func::FuncOp>>
-mlir::createLinalgGeneralizationPass() {
+std::unique_ptr<Pass> mlir::createLinalgGeneralizationPass() {
return std::make_unique<LinalgGeneralizationPass>();
}
: public impl::LinalgInlineScalarOperandsBase<
LinalgInlineScalarOperandsPass> {
void runOnOperation() override {
- func::FuncOp funcOp = getOperation();
- MLIRContext *context = funcOp.getContext();
- RewritePatternSet patterns(context);
-
+ Operation *op = getOperation();
+ MLIRContext &ctx = getContext();
+ RewritePatternSet patterns(&ctx);
populateInlineConstantOperandsPatterns(patterns);
- (void)applyPatternsAndFoldGreedily(funcOp.getBody(), std::move(patterns));
+ (void)applyPatternsAndFoldGreedily(op, std::move(patterns));
}
};
} // namespace
-std::unique_ptr<OperationPass<func::FuncOp>>
-mlir::createLinalgInlineScalarOperandsPass() {
+std::unique_ptr<Pass> mlir::createLinalgInlineScalarOperandsPass() {
return std::make_unique<LinalgInlineScalarOperandsPass>();
}
};
template <typename LoopType>
-static void lowerLinalgToLoopsImpl(func::FuncOp funcOp) {
- MLIRContext *context = funcOp.getContext();
+static void lowerLinalgToLoopsImpl(Operation *enclosingOp) {
+ MLIRContext *context = enclosingOp->getContext();
RewritePatternSet patterns(context);
patterns.add<LinalgRewritePattern<LoopType>>(context);
memref::DimOp::getCanonicalizationPatterns(patterns, context);
affine::AffineApplyOp::getCanonicalizationPatterns(patterns, context);
patterns.add<FoldAffineOp>(context);
// Just apply the patterns greedily.
- (void)applyPatternsAndFoldGreedily(funcOp, std::move(patterns));
+ (void)applyPatternsAndFoldGreedily(enclosingOp, std::move(patterns));
}
struct LowerToAffineLoops
} // namespace
-std::unique_ptr<OperationPass<func::FuncOp>>
-mlir::createConvertLinalgToLoopsPass() {
+std::unique_ptr<Pass> mlir::createConvertLinalgToLoopsPass() {
return std::make_unique<LowerToLoops>();
}
-std::unique_ptr<OperationPass<func::FuncOp>>
-mlir::createConvertLinalgToParallelLoopsPass() {
+std::unique_ptr<Pass> mlir::createConvertLinalgToParallelLoopsPass() {
return std::make_unique<LowerToParallelLoops>();
}
-std::unique_ptr<OperationPass<func::FuncOp>>
-mlir::createConvertLinalgToAffineLoopsPass() {
+std::unique_ptr<Pass> mlir::createConvertLinalgToAffineLoopsPass() {
return std::make_unique<LowerToAffineLoops>();
}