Pass skip by lamdba function


Is there a declerative way to define a lamdba function on a pass to filter function/module operations? For example, I would like my pass not to be called for FuncOp which is Decalertaion (without skipping inside runOnOperation function of the pass).


Hi @aviadc, I don’t think there is a declarative way to specify a lambda function on a pass, but you could use a walker(MLIR: mlir::Operation Class Reference)

funcOp->walk([](dialect::myOp myOp) {
 // do something with myOp.

@chelini thanks for replaying.
I am more interested in declaring pass on a function (not a module) and skip before runOnOperation is called.

There is no builtin way.

I considered at some point a generic “filter-symbol” adaptor/wrapper for this purpose, but it’s hard to have a general solution, it always seems ad-hoc and I didn’t find a goood API (do you take a regex?).

That said what you want is fairly easy to implement, it is a pass that has an option which is a pass-pipeline. It initializes the pipeline in its initialize() method, do the filtering in the runOnOperation() before calling runPipeline with the provided pipeline.