llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.25k stars 12.07k forks source link

[mlir][bug] func::ReturnOp::getSuccessorRegions always asserts #112146

Open fabianmcg opened 1 month ago

fabianmcg commented 1 month ago

Currently ReturnLike attaches RegionBranchTerminatorOpInterface as a sub trait (see https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Interfaces/ControlFlowInterfaces.td#L384). Consequently, func::ReturnOp implements RegionBranchTerminatorOpInterface. However, func::FuncOp doesn't implement RegionBranchOpInterface (see https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/Func/IR/FuncOps.td#L226-L229), resulting on an assert produced by the default implementation of RegionBranchTerminatorOpInterface:

      "void", "getSuccessorRegions",
      (ins "::llvm::ArrayRef<::mlir::Attribute>":$operands,
           "::llvm::SmallVectorImpl<::mlir::RegionSuccessor> &":$regions), [{}],
      /*defaultImplementation=*/[{
        ::mlir::Operation *op = $_op;
        ::llvm::cast<::mlir::RegionBranchOpInterface>(op->getParentOp())
          .getSuccessorRegions(op->getParentRegion(), regions);
      }]
llvmbot commented 1 month ago

@llvm/issue-subscribers-mlir

Author: Fabian Mora (fabianmcg)

Currently `ReturnLike` attaches `RegionBranchTerminatorOpInterface` as a sub trait (see https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Interfaces/ControlFlowInterfaces.td#L384). Consequently, `func::ReturnOp` implements `RegionBranchTerminatorOpInterface`. However, `func::FuncOp` doesn't implement `RegionBranchOpInterface` (see https://github.com/fabianmcg/llvm-project/blob/main/mlir/include/mlir/Dialect/Func/IR/FuncOps.td#L226-L229), resulting on an assert produced by the default implementation of `RegionBranchTerminatorOpInterface`: ``` "void", "getSuccessorRegions", (ins "::llvm::ArrayRef<::mlir::Attribute>":$operands, "::llvm::SmallVectorImpl<::mlir::RegionSuccessor> &":$regions), [{}], /*defaultImplementation=*/[{ ::mlir::Operation *op = $_op; ::llvm::cast<::mlir::RegionBranchOpInterface>(op->getParentOp()) .getSuccessorRegions(op->getParentRegion(), regions); }] ```