1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
|
//===- VectorToSPIRV.cpp - Vector to SPIR-V Patterns ----------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file implements patterns to convert Vector dialect to SPIRV dialect.
//
//===----------------------------------------------------------------------===//
#include "mlir/Conversion/VectorToSPIRV/VectorToSPIRV.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/FormatVariadic.h"
#include <numeric>
using namespace mlir;
/// Gets the first integer value from `attr`, assuming it is an integer array
/// attribute.
static uint64_t getFirstIntValue(ArrayAttr attr) {
return (*attr.getAsValueRange<IntegerAttr>().begin()).getZExtValue();
}
/// Returns the number of bits for the given scalar/vector type.
static int getNumBits(Type type) {
// TODO: This does not take into account any memory layout or widening
// constraints. E.g., a vector<3xi57> may report to occupy 3x57=171 bit, even
// though in practice it will likely be stored as in a 4xi64 vector register.
if (auto vectorType = dyn_cast<VectorType>(type))
return vectorType.getNumElements() * vectorType.getElementTypeBitWidth();
return type.getIntOrFloatBitWidth();
}
namespace {
struct VectorShapeCast final : public OpConversionPattern<vector::ShapeCastOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::ShapeCastOp shapeCastOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type dstType = getTypeConverter()->convertType(shapeCastOp.getType());
if (!dstType)
return failure();
// If dstType is same as the source type or the vector size is 1, it can be
// directly replaced by the source.
if (dstType == adaptor.getSource().getType() ||
shapeCastOp.getResultVectorType().getNumElements() == 1) {
rewriter.replaceOp(shapeCastOp, adaptor.getSource());
return success();
}
// Lowering for size-n vectors when n > 1 hasn't been implemented.
return failure();
}
};
struct VectorBitcastConvert final
: public OpConversionPattern<vector::BitCastOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::BitCastOp bitcastOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type dstType = getTypeConverter()->convertType(bitcastOp.getType());
if (!dstType)
return failure();
if (dstType == adaptor.getSource().getType()) {
rewriter.replaceOp(bitcastOp, adaptor.getSource());
return success();
}
// Check that the source and destination type have the same bitwidth.
// Depending on the target environment, we may need to emulate certain
// types, which can cause issue with bitcast.
Type srcType = adaptor.getSource().getType();
if (getNumBits(dstType) != getNumBits(srcType)) {
return rewriter.notifyMatchFailure(
bitcastOp,
llvm::formatv("different source ({0}) and target ({1}) bitwidth",
srcType, dstType));
}
rewriter.replaceOpWithNewOp<spirv::BitcastOp>(bitcastOp, dstType,
adaptor.getSource());
return success();
}
};
struct VectorBroadcastConvert final
: public OpConversionPattern<vector::BroadcastOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::BroadcastOp castOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type resultType =
getTypeConverter()->convertType(castOp.getResultVectorType());
if (!resultType)
return failure();
if (isa<spirv::ScalarType>(resultType)) {
rewriter.replaceOp(castOp, adaptor.getSource());
return success();
}
SmallVector<Value, 4> source(castOp.getResultVectorType().getNumElements(),
adaptor.getSource());
rewriter.replaceOpWithNewOp<spirv::CompositeConstructOp>(
castOp, castOp.getResultVectorType(), source);
return success();
}
};
struct VectorExtractOpConvert final
: public OpConversionPattern<vector::ExtractOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::ExtractOp extractOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
// Only support extracting a scalar value now.
VectorType resultVectorType = dyn_cast<VectorType>(extractOp.getType());
if (resultVectorType && resultVectorType.getNumElements() > 1)
return failure();
Type dstType = getTypeConverter()->convertType(extractOp.getType());
if (!dstType)
return failure();
if (isa<spirv::ScalarType>(adaptor.getVector().getType())) {
rewriter.replaceOp(extractOp, adaptor.getVector());
return success();
}
int32_t id = getFirstIntValue(extractOp.getPosition());
rewriter.replaceOpWithNewOp<spirv::CompositeExtractOp>(
extractOp, adaptor.getVector(), id);
return success();
}
};
struct VectorExtractStridedSliceOpConvert final
: public OpConversionPattern<vector::ExtractStridedSliceOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::ExtractStridedSliceOp extractOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type dstType = getTypeConverter()->convertType(extractOp.getType());
if (!dstType)
return failure();
uint64_t offset = getFirstIntValue(extractOp.getOffsets());
uint64_t size = getFirstIntValue(extractOp.getSizes());
uint64_t stride = getFirstIntValue(extractOp.getStrides());
if (stride != 1)
return failure();
Value srcVector = adaptor.getOperands().front();
// Extract vector<1xT> case.
if (isa<spirv::ScalarType>(dstType)) {
rewriter.replaceOpWithNewOp<spirv::CompositeExtractOp>(extractOp,
srcVector, offset);
return success();
}
SmallVector<int32_t, 2> indices(size);
std::iota(indices.begin(), indices.end(), offset);
rewriter.replaceOpWithNewOp<spirv::VectorShuffleOp>(
extractOp, dstType, srcVector, srcVector,
rewriter.getI32ArrayAttr(indices));
return success();
}
};
template <class SPIRVFMAOp>
struct VectorFmaOpConvert final : public OpConversionPattern<vector::FMAOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::FMAOp fmaOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type dstType = getTypeConverter()->convertType(fmaOp.getType());
if (!dstType)
return failure();
rewriter.replaceOpWithNewOp<SPIRVFMAOp>(fmaOp, dstType, adaptor.getLhs(),
adaptor.getRhs(), adaptor.getAcc());
return success();
}
};
struct VectorInsertOpConvert final
: public OpConversionPattern<vector::InsertOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::InsertOp insertOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
if (isa<VectorType>(insertOp.getSourceType()))
return rewriter.notifyMatchFailure(insertOp, "unsupported vector source");
if (!getTypeConverter()->convertType(insertOp.getDestVectorType()))
return rewriter.notifyMatchFailure(insertOp,
"unsupported dest vector type");
// Special case for inserting scalar values into size-1 vectors.
if (insertOp.getSourceType().isIntOrFloat() &&
insertOp.getDestVectorType().getNumElements() == 1) {
rewriter.replaceOp(insertOp, adaptor.getSource());
return success();
}
int32_t id = getFirstIntValue(insertOp.getPosition());
rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(
insertOp, adaptor.getSource(), adaptor.getDest(), id);
return success();
}
};
struct VectorExtractElementOpConvert final
: public OpConversionPattern<vector::ExtractElementOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::ExtractElementOp extractOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type resultType = getTypeConverter()->convertType(extractOp.getType());
if (!resultType)
return failure();
if (isa<spirv::ScalarType>(adaptor.getVector().getType())) {
rewriter.replaceOp(extractOp, adaptor.getVector());
return success();
}
APInt cstPos;
if (matchPattern(adaptor.getPosition(), m_ConstantInt(&cstPos)))
rewriter.replaceOpWithNewOp<spirv::CompositeExtractOp>(
extractOp, resultType, adaptor.getVector(),
rewriter.getI32ArrayAttr({static_cast<int>(cstPos.getSExtValue())}));
else
rewriter.replaceOpWithNewOp<spirv::VectorExtractDynamicOp>(
extractOp, resultType, adaptor.getVector(), adaptor.getPosition());
return success();
}
};
struct VectorInsertElementOpConvert final
: public OpConversionPattern<vector::InsertElementOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::InsertElementOp insertOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type vectorType = getTypeConverter()->convertType(insertOp.getType());
if (!vectorType)
return failure();
if (isa<spirv::ScalarType>(vectorType)) {
rewriter.replaceOp(insertOp, adaptor.getSource());
return success();
}
APInt cstPos;
if (matchPattern(adaptor.getPosition(), m_ConstantInt(&cstPos)))
rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(
insertOp, adaptor.getSource(), adaptor.getDest(),
cstPos.getSExtValue());
else
rewriter.replaceOpWithNewOp<spirv::VectorInsertDynamicOp>(
insertOp, vectorType, insertOp.getDest(), adaptor.getSource(),
adaptor.getPosition());
return success();
}
};
struct VectorInsertStridedSliceOpConvert final
: public OpConversionPattern<vector::InsertStridedSliceOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::InsertStridedSliceOp insertOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Value srcVector = adaptor.getOperands().front();
Value dstVector = adaptor.getOperands().back();
uint64_t stride = getFirstIntValue(insertOp.getStrides());
if (stride != 1)
return failure();
uint64_t offset = getFirstIntValue(insertOp.getOffsets());
if (isa<spirv::ScalarType>(srcVector.getType())) {
assert(!isa<spirv::ScalarType>(dstVector.getType()));
rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(
insertOp, dstVector.getType(), srcVector, dstVector,
rewriter.getI32ArrayAttr(offset));
return success();
}
uint64_t totalSize = cast<VectorType>(dstVector.getType()).getNumElements();
uint64_t insertSize =
cast<VectorType>(srcVector.getType()).getNumElements();
SmallVector<int32_t, 2> indices(totalSize);
std::iota(indices.begin(), indices.end(), 0);
std::iota(indices.begin() + offset, indices.begin() + offset + insertSize,
totalSize);
rewriter.replaceOpWithNewOp<spirv::VectorShuffleOp>(
insertOp, dstVector.getType(), dstVector, srcVector,
rewriter.getI32ArrayAttr(indices));
return success();
}
};
template <class SPIRVFMaxOp, class SPIRVFMinOp, class SPIRVUMaxOp,
class SPIRVUMinOp, class SPIRVSMaxOp, class SPIRVSMinOp>
struct VectorReductionPattern final
: public OpConversionPattern<vector::ReductionOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::ReductionOp reduceOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type resultType = typeConverter->convertType(reduceOp.getType());
if (!resultType)
return failure();
auto srcVectorType = dyn_cast<VectorType>(adaptor.getVector().getType());
if (!srcVectorType || srcVectorType.getRank() != 1)
return rewriter.notifyMatchFailure(reduceOp, "not 1-D vector source");
// Extract all elements.
int numElements = srcVectorType.getDimSize(0);
SmallVector<Value, 4> values;
values.reserve(numElements + (adaptor.getAcc() != nullptr));
Location loc = reduceOp.getLoc();
for (int i = 0; i < numElements; ++i) {
values.push_back(rewriter.create<spirv::CompositeExtractOp>(
loc, srcVectorType.getElementType(), adaptor.getVector(),
rewriter.getI32ArrayAttr({i})));
}
if (Value acc = adaptor.getAcc())
values.push_back(acc);
// Reduce them.
Value result = values.front();
for (Value next : llvm::ArrayRef(values).drop_front()) {
switch (reduceOp.getKind()) {
#define INT_AND_FLOAT_CASE(kind, iop, fop) \
case vector::CombiningKind::kind: \
if (llvm::isa<IntegerType>(resultType)) { \
result = rewriter.create<spirv::iop>(loc, resultType, result, next); \
} else { \
assert(llvm::isa<FloatType>(resultType)); \
result = rewriter.create<spirv::fop>(loc, resultType, result, next); \
} \
break
#define INT_OR_FLOAT_CASE(kind, fop) \
case vector::CombiningKind::kind: \
result = rewriter.create<fop>(loc, resultType, result, next); \
break
INT_AND_FLOAT_CASE(ADD, IAddOp, FAddOp);
INT_AND_FLOAT_CASE(MUL, IMulOp, FMulOp);
INT_OR_FLOAT_CASE(MAXF, SPIRVFMaxOp);
INT_OR_FLOAT_CASE(MINF, SPIRVFMinOp);
INT_OR_FLOAT_CASE(MINUI, SPIRVUMinOp);
INT_OR_FLOAT_CASE(MINSI, SPIRVSMinOp);
INT_OR_FLOAT_CASE(MAXUI, SPIRVUMaxOp);
INT_OR_FLOAT_CASE(MAXSI, SPIRVSMaxOp);
case vector::CombiningKind::AND:
case vector::CombiningKind::OR:
case vector::CombiningKind::XOR:
return rewriter.notifyMatchFailure(reduceOp, "unimplemented");
}
}
rewriter.replaceOp(reduceOp, result);
return success();
}
};
class VectorSplatPattern final : public OpConversionPattern<vector::SplatOp> {
public:
using OpConversionPattern<vector::SplatOp>::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::SplatOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type dstType = getTypeConverter()->convertType(op.getType());
if (!dstType)
return failure();
if (isa<spirv::ScalarType>(dstType)) {
rewriter.replaceOp(op, adaptor.getInput());
} else {
auto dstVecType = cast<VectorType>(dstType);
SmallVector<Value, 4> source(dstVecType.getNumElements(),
adaptor.getInput());
rewriter.replaceOpWithNewOp<spirv::CompositeConstructOp>(op, dstType,
source);
}
return success();
}
};
struct VectorShuffleOpConvert final
: public OpConversionPattern<vector::ShuffleOp> {
using OpConversionPattern::OpConversionPattern;
LogicalResult
matchAndRewrite(vector::ShuffleOp shuffleOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
auto oldResultType = shuffleOp.getResultVectorType();
Type newResultType = getTypeConverter()->convertType(oldResultType);
if (!newResultType)
return rewriter.notifyMatchFailure(shuffleOp,
"unsupported result vector type");
auto oldSourceType = shuffleOp.getV1VectorType();
if (oldSourceType.getNumElements() > 1) {
SmallVector<int32_t, 4> components = llvm::to_vector<4>(
llvm::map_range(shuffleOp.getMask(), [](Attribute attr) -> int32_t {
return cast<IntegerAttr>(attr).getValue().getZExtValue();
}));
rewriter.replaceOpWithNewOp<spirv::VectorShuffleOp>(
shuffleOp, newResultType, adaptor.getV1(), adaptor.getV2(),
rewriter.getI32ArrayAttr(components));
return success();
}
SmallVector<Value, 2> oldOperands = {adaptor.getV1(), adaptor.getV2()};
SmallVector<Value, 4> newOperands;
newOperands.reserve(oldResultType.getNumElements());
for (const APInt &i : shuffleOp.getMask().getAsValueRange<IntegerAttr>()) {
newOperands.push_back(oldOperands[i.getZExtValue()]);
}
rewriter.replaceOpWithNewOp<spirv::CompositeConstructOp>(
shuffleOp, newResultType, newOperands);
return success();
}
};
struct VectorReductionToDotProd final : OpRewritePattern<vector::ReductionOp> {
using OpRewritePattern::OpRewritePattern;
LogicalResult matchAndRewrite(vector::ReductionOp op,
PatternRewriter &rewriter) const override {
if (op.getKind() != vector::CombiningKind::ADD)
return rewriter.notifyMatchFailure(op, "combining kind is not 'add'");
auto resultType = dyn_cast<IntegerType>(op.getType());
if (!resultType)
return rewriter.notifyMatchFailure(op, "result is not an integer");
int64_t resultBitwidth = resultType.getIntOrFloatBitWidth();
if (!llvm::is_contained({32, 64}, resultBitwidth))
return rewriter.notifyMatchFailure(op, "unsupported integer bitwidth");
VectorType inVecTy = op.getSourceVectorType();
if (!llvm::is_contained({4, 3}, inVecTy.getNumElements()) ||
inVecTy.getShape().size() != 1 || inVecTy.isScalable())
return rewriter.notifyMatchFailure(op, "unsupported vector shape");
auto mul = op.getVector().getDefiningOp<arith::MulIOp>();
if (!mul)
return rewriter.notifyMatchFailure(
op, "reduction operand is not 'arith.muli'");
if (succeeded(handleCase<arith::ExtSIOp, arith::ExtSIOp, spirv::SDotOp,
spirv::SDotAccSatOp, false>(op, mul, rewriter)))
return success();
if (succeeded(handleCase<arith::ExtUIOp, arith::ExtUIOp, spirv::UDotOp,
spirv::UDotAccSatOp, false>(op, mul, rewriter)))
return success();
if (succeeded(handleCase<arith::ExtSIOp, arith::ExtUIOp, spirv::SUDotOp,
spirv::SUDotAccSatOp, false>(op, mul, rewriter)))
return success();
if (succeeded(handleCase<arith::ExtUIOp, arith::ExtSIOp, spirv::SUDotOp,
spirv::SUDotAccSatOp, true>(op, mul, rewriter)))
return success();
return failure();
}
private:
template <typename LhsExtensionOp, typename RhsExtensionOp, typename DotOp,
typename DotAccOp, bool SwapOperands>
static LogicalResult handleCase(vector::ReductionOp op, arith::MulIOp mul,
PatternRewriter &rewriter) {
auto lhs = mul.getLhs().getDefiningOp<LhsExtensionOp>();
if (!lhs)
return failure();
Value lhsIn = lhs.getIn();
auto lhsInType = cast<VectorType>(lhsIn.getType());
if (!lhsInType.getElementType().isInteger(8))
return failure();
auto rhs = mul.getRhs().getDefiningOp<RhsExtensionOp>();
if (!rhs)
return failure();
Value rhsIn = rhs.getIn();
auto rhsInType = cast<VectorType>(rhsIn.getType());
if (!rhsInType.getElementType().isInteger(8))
return failure();
if (op.getSourceVectorType().getNumElements() == 3) {
IntegerType i8Type = rewriter.getI8Type();
auto v4i8Type = VectorType::get({4}, i8Type);
Location loc = op.getLoc();
Value zero = spirv::ConstantOp::getZero(i8Type, loc, rewriter);
lhsIn = rewriter.create<spirv::CompositeConstructOp>(
loc, v4i8Type, ValueRange{lhsIn, zero});
rhsIn = rewriter.create<spirv::CompositeConstructOp>(
loc, v4i8Type, ValueRange{rhsIn, zero});
}
// There's no variant of dot prod ops for unsigned LHS and signed RHS, so
// we have to swap operands instead in that case.
if (SwapOperands)
std::swap(lhsIn, rhsIn);
if (Value acc = op.getAcc()) {
rewriter.replaceOpWithNewOp<DotAccOp>(op, op.getType(), lhsIn, rhsIn, acc,
nullptr);
} else {
rewriter.replaceOpWithNewOp<DotOp>(op, op.getType(), lhsIn, rhsIn,
nullptr);
}
return success();
}
};
} // namespace
#define CL_MAX_MIN_OPS \
spirv::CLFMaxOp, spirv::CLFMinOp, spirv::CLUMaxOp, spirv::CLUMinOp, \
spirv::CLSMaxOp, spirv::CLSMinOp
#define GL_MAX_MIN_OPS \
spirv::GLFMaxOp, spirv::GLFMinOp, spirv::GLUMaxOp, spirv::GLUMinOp, \
spirv::GLSMaxOp, spirv::GLSMinOp
void mlir::populateVectorToSPIRVPatterns(SPIRVTypeConverter &typeConverter,
RewritePatternSet &patterns) {
patterns.add<VectorBitcastConvert, VectorBroadcastConvert,
VectorExtractElementOpConvert, VectorExtractOpConvert,
VectorExtractStridedSliceOpConvert,
VectorFmaOpConvert<spirv::GLFmaOp>,
VectorFmaOpConvert<spirv::CLFmaOp>, VectorInsertElementOpConvert,
VectorInsertOpConvert, VectorReductionPattern<GL_MAX_MIN_OPS>,
VectorReductionPattern<CL_MAX_MIN_OPS>, VectorShapeCast,
VectorInsertStridedSliceOpConvert, VectorShuffleOpConvert,
VectorSplatPattern>(typeConverter, patterns.getContext());
}
void mlir::populateVectorReductionToSPIRVDotProductPatterns(
RewritePatternSet &patterns) {
patterns.add<VectorReductionToDotProd>(patterns.getContext());
}
|