How to figure out why the `runOnOperation` not work properly

Hi, I’m new in MLIR and LLVM. I am learning about creating a transform pass.
My goal is to add a PragmaOp from my own dialect to the front of the AffineForOp. But the transform pass didn’t run properly.

This is what have done so far to try to figure out what happened:

  1. I had used -print-ir-after-all to confirm the pass is not work and the opt program is finished successfully.
  2. I had changed OperationPass<mlir::AffineForOp> to OperationPass<mlir::ModuleOp> and the pass is work fine.

How can I solve this? Is there any debug tools to trace why hook function not been evoked? Thanks a lot. :grinning:

This is some of my code, my dialect named miniEmitC:

  • Pass declaration:
    def InsertminiEmitCPragmaScop : Pass<"insert-pragma-scop", "mlir::AffineForOp"> {
      let summary = "Insert a PET scop pragma for affine.for.";
      let constructor = "createInsertminiEmitCPragmaScopPass()";
      let dependentDialects = ["miniEmitCDialect"];
  • Pass implementation:
    namespace miniemitc {
    namespace {
    struct InsertminiEmitCPragmaScopPass
        : public InsertminiEmitCPragmaScopBase<InsertminiEmitCPragmaScopPass> {
      void runOnOperation() override {
        auto op = getOperation();
        // TODO: Add insert func
    } // namespace
    createInsertminiEmitCPragmaScopPass() {
      return std::make_unique<InsertminiEmitCPragmaScopPass>();
    } // namespace miniemitc

You can’t have a pass running an operation that isn’t “IsolatedFromAbove”.
I’m actually surprised we don’t have a runtime failure for that…

Thanks for you reply. I’m going to take more time to read the manual to reach my goal. Very appreciate. :grinning: