Restricting a pass execution for a particular function

Hi All,

I have 2 different passes that supposed to be run on two different functions. Can I restrict that a pass should run on a particular function only, ignoring the other functions in a module?

Regards
Meena

What distinguishes the function you want to run on from the one(s) you don’t? A function pass could look for such a defining characteristic and only alter the function if it has it. A module pass could look for only the function it should modify, if it’s something dependent on features at the module level. That isn’t something that you can configure in the pass manager though AFAIK

It is possible to implement a wrapper pass doing some filtering and using the dynamic pipeline feature.

void MyPass::runOnOperation() {
  Operation *operation = getOperation();
  if (hasSomeSpecificProperty(operation)) {
    OpPassManager dynamicPM(operation->getName());
    ...; // Build the dynamic pipeline.
    if (failed(runPipeline(dynamicPM, operation)))
      return signalPassFailure();
  } else if (hasSomeOtherSpecificProperty(operation)) {
    // Other pipeline?
    ...
  }
}

Hi,

Thank you for your inputs.

My requirement is to run the entire pass on the particular functions of a module. For example, if I am having three functions “Func1”, “Func2” and “Func3” in a module, then the PassA should run on the operations inside “Func1” and “Func2”. And, another PassB should run only on the operations inside “Func3”.

I am planning to achieve it by adding a custom attribute to the Function definition and while lowering any operation, will check if it resides inside a specific function attribute type.

Is this the right approach or some better solution is available.

Thanks and Regards
Meena

I would likely implement roughly a scheme like the one I proposed above.

If really you want to do just A or B, I would even maybe implement a PassAorB which in runOnOperation() just dispatch to the right utility to achieve the same thing as either pass A or pass B depending on the attribute.

I want to run both the passes, PassA and PassB, passes execution is not conditional. But PassA supposed to lower operations inside FuncA and PassB supposed to lower operations inside FuncB. Both the functions have same operations e.g. Gemm operations. The only difference is that the Gemm operations inside FuncA should be lowered differently than the Gemm operations inside FuncB. But as per my understanding, if there is a function to lower a particular operation (GemmOpLowering), it will be iteratively applied on all the Gemm operations inside all the functions of a module. So, how I can restrict it only to a particular function.