FunctionPass deprecated in favor of OperationPass<FuncOp>

Hi all,

FunctionPass has been marked deprecated, please switch to OperationPass<FuncOp>(in C++) and Pass<"...", "::mlir::FuncOp"> (in Tablegen) instead. The main change in behavior is that FunctionPass implicitly skips external functions whereas OperationPass<FuncOp> does not, so please pay attention when switching your passes if you need to add new explicitly skipping of external functions or not.

Some Rationale: FunctionPass is from a time before functions were operations (and well, before operations were even a thing). It was created when MLIR had a structure similar to LLVM, but its existence is not very justifiable in modern MLIR where FuncOp is just another operation (and not really one that deserves/needs to be priviledged).

I’ve left the definition of FunctionPass as-is for now, but it will be removed in 1.5-2 weeks.

Thanks
– River

3 Likes

Currently, the above solution for tablegen produces an error saying

/build/tools/mlir/include/mlir/Conversion/Passes.h.inc:3783:73: error: no member named 'FuncOp' in namespace 'mlir'
class MyPass : public ::mlir::OperationPass<::mlir::FuncOp> {
                                                                ~~~~~~~~^

I take it that it has now changed to Pass<"...", "::mlir::func::FuncOp">?

If so, when I try to add a new conversion pass with the above signature in tablegen, building mlir-opt fails saying

/build/tools/mlir/include/mlir/Conversion/Passes.h.inc:3783:73: error: no member named 'func' in namespace 'mlir'
class MyPass : public ::mlir::OperationPass<::mlir::func::FuncOp> {
                                                                ~~~~~~~~^

How do I resolve this? Thanks!

Hi @hsnbrg !

Yup exactly, ::mlir::func::FuncOp is correct.

For your second error, I think you need to include the header file wherever you’re including Passes.h.inc:

#include "mlir/Dialect/Func/IR/FuncOps.h"

Also it might be better to create a new post if you have additional questions. Hope this helps!

1 Like

Hi @ataheridezfouli!

Really appreciate your prompt response and help! That worked! Thanks a lot!