[Mlir-commits] [mlir] [mlir][linalg] Add a new helper hook - `isVectorizable` (PR #110708)

Andrzej WarzyƄski llvmlistbot at llvm.org
Wed Oct 2 00:17:35 PDT 2024


banach-space wrote:

> I don't mind the little snippet. @ftynse ?

Sure, but then we have to repeat the same snippet twice. Also, `isVectorizable` is really a property of the vectorizer that should be captured/documented somewhere. That's missing today.

In case it wasn't clear from the diff, this is what's happening today (pseudo-code to capture the high-level idea):

```cpp
// CURRENT logic for transform.structured.vectorize
LogicalResult process_vectorize_td(Operation *target) {
  if (!isa<linalg::LinalgOp, tensor::PadOp, tensor::PackOp, tensor::UnPackOp>(target))
    return rewriter.notifyMatchFailure(op, "Unsupported Op, cannot vectorize");

  return vectorize(target);
}

// CURRENT logic for transform.structured.vectorize_children_and_apply_patterns
LogicalResult process_vectorize_children_and_apply_patterns_td(Operation *target) {
  // NOTE - this condition is unnecessarily restrictive and is being relaxed in this PR
  if (!isa<linalg::LinalgOp>(target))
    return rewriter.notifyMatchFailure(op, "expected Linalg Op");

  return vectorize(target);
}
```

After this change, we will have this:
```cpp
bool isVectorizable(Operation *op) {
  return isa<linalg::LinalgOp, tensor::PadOp, tensor::PackOp, tensor::UnPackOp>(
      op);
}

// NEW logic for transform.structured.vectorize
LogicalResult process_vectorize_td(Operation *target) {
  if (!isVectorizable(target))
    return mlir::emitSilenceableFailure(target->getLoc())
           << "Unsupported Op, cannot vectorize";

  return vectorize(target);
}

// NEW logic for transform.structured.vectorize_children_and_apply_patterns
LogicalResult
process_vectorize_children_and_apply_patterns_td(Operation *target) {
  if (!isVectorizable(target))
    return mlir::emitSilenceableFailure(target->getLoc())
           << "Unsupported Op, cannot vectorize";

  return vectorize(target);
}
```

Put differently, this PR aims to achieve two things:
* healthier code re-use,
* relax the artificially imposed restrictions on `ransform.structured.vectorize_children_and_apply_patterns`.

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


More information about the Mlir-commits mailing list