Files
llvm/mlir/lib/Dialect/Transform/Utils/Utils.cpp
Andrzej Warzynski ad7ef1923f [mlir][transform] Allow arbitrary indices to be scalable
This change lifts the limitation that only the trailing dimensions/sizes
in dynamic index lists can be scalable. It allows us to extend
`MaskedVectorizeOp` and `TileOp` from the Transform dialect so that the
following is allowed:

  %1, %loops:3 = transform.structured.tile %0 [4, [4], [4]]

This is also a follow up for https://reviews.llvm.org/D153372
that will enable the following (middle vector dimension is scalable):

  transform.structured.masked_vectorize %0 vector_sizes [2, [4], 8]

To facilate this change, the hooks for parsing and printing dynamic
index lists are updated accordingly (`printDynamicIndexList` and
`parseDynamicIndexList`, respectively). `MaskedVectorizeOp` and `TileOp`
are updated to include an array of attribute of bools that captures
whether the corresponding vector dimension/tile size, respectively, are
scalable or not.

NOTE 1: I am re-landing this after the initial version was reverted. To
fix the regression and in addition to the original patch, this revision
updates the Python bindings for the transform dialect

NOTE 2: This change is a part of a larger effort to enable scalable
vectorisation in Linalg. See this RFC for more context:
  * https://discourse.llvm.org/t/rfc-scalable-vectorisation-in-linalg/

This relands 048764f23a with fixes.

Differential Revision: https://reviews.llvm.org/D154336
2023-07-05 09:53:26 +01:00

47 lines
1.8 KiB
C++

//===- Utils.cpp - Transform dialect utilities ----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Transform/Utils/Utils.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/Interfaces/ViewLikeInterface.h"
using namespace mlir;
using namespace mlir::transform;
void mlir::transform::printPackedOrDynamicIndexList(
OpAsmPrinter &printer, Operation *op, Value packed, Type packedType,
OperandRange values, TypeRange valueTypes, ArrayRef<int64_t> integers) {
if (packed) {
assert(values.empty() && integers.empty() && "expected no values/integers");
printer << "*(" << packed << " : " << packedType << ")";
return;
}
printDynamicIndexList(printer, op, values, integers, valueTypes);
}
ParseResult mlir::transform::parsePackedOrDynamicIndexList(
OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
Type &packedType, SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
SmallVectorImpl<Type> &valueTypes, DenseI64ArrayAttr &integers) {
OpAsmParser::UnresolvedOperand packedOperand;
if (parser.parseOptionalStar().succeeded()) {
if (parser.parseLParen().failed() ||
parser.parseOperand(packedOperand).failed() ||
parser.parseColonType(packedType).failed() ||
parser.parseRParen().failed()) {
return failure();
}
packed.emplace(packedOperand);
integers = parser.getBuilder().getDenseI64ArrayAttr({});
return success();
}
return parseDynamicIndexList(parser, values, integers, &valueTypes);
}