[Mlir-commits] [mlir] [MLIR][NFC] Stop depending on func.func in affine LoopUtils (PR #82079)

Alexey Z. llvmlistbot at llvm.org
Fri Feb 16 18:26:55 PST 2024


last5bits wrote:

> But `getFunctionBody()` can be replaced by `getRegion(0)` for example.
> 
> Basically I'm wondering why we can't replace this with "Operation" without more restriction,and `walk()` the IR regardless the operation that is the anchor for the pass.

I see your point, you're thinking to use an even more general "interface". After a cursory look at the code in `Affine/LoopUtils.cpp`, there are places where it's assumed that `func` has a single overarching region, for example when creating a constant expression.

```
    // Builder to create constants at the top level.                                                      
    auto func =                                                                                           
        copyPlacementBlock->getParent()->getParentOfType<FunctionOpInterface>();                          
    OpBuilder top(func.getFunctionBody());

  AffineExpr offset = top.getAffineConstantExpr(0);
```

If it was more general, imagine passing a `affine.if` as the what's now called `func`. An `affine.if` has two regions, so the above wouldn't make sense.

https://github.com/llvm/llvm-project/pull/82079


More information about the Mlir-commits mailing list