MLIR 23.0.0git
X86VectorUtils.h
Go to the documentation of this file.
1//===- X86VectorUtils.h - X86Vector Utilities -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef MLIR_DIALECT_X86VECTOR_UTILS_X86VECTORUTILS_H_
10#define MLIR_DIALECT_X86VECTOR_UTILS_X86VECTORUTILS_H_
11
14#include "mlir/IR/Value.h"
16#include "llvm/ADT/ArrayRef.h"
17#include <cstdint>
18#include <optional>
19#include <string>
20
21namespace mlir {
22class AffineMap;
23class Operation;
24
25namespace x86vector {
26
27// Return true if the operation is in VNNI layout.
28// Optionally, the check can be constrained to a specific VNNI blocking factor.
29bool isInVnniLayout(Operation *op, llvm::ArrayRef<AffineMap> indexingMaps,
30 std::optional<unsigned> blockingFactor = std::nullopt);
31
32// Returns true if two contraction ops form a valid pair for VNNI packing.
33// It verifies that both contractions share the appropriate operand, read from
34// the same source buffer, and use constant indices that differ by 8 or 16.
35bool validatePairVectorContract(vector::ContractionOp contractOp,
36 vector::ContractionOp pairContOp,
37 bool rhsHasMultipleNonUnitDims,
38 int64_t nonUnitDimValue);
39
40// Walks backward from a value to find its originating vector read-like op
41// (vector.transfer_read or vector.load), following scf.for iter-args but
42// stopping at layout-transforming ops; returns the read op or nullptr.
43Operation *traceToVectorReadLikeParentOperation(Value v);
44
45// Recursively traces a value to find a downstream vector write-like op
46// (vector.transfer_write or vector.store), crossing scf.for/yield but
47// stopping at layout-altering ops. Returns nullptr if no vector writer/store
48// ops or there are multiple users.
49Operation *traceToVectorWriteLikeUserOperation(Value v);
50
51// Packs the accumulators of two flat BF16 vector.contraction ops into a
52// VNNI-packed layout and replaces the original accumulators to enable post-read
53// packing transformations.
54LogicalResult shuffleAfterReadLikeOp(PatternRewriter &rewriter, Operation *opA,
55 Operation *opB,
56 vector::ContractionOp contractA,
57 vector::ContractionOp contractB,
58 int64_t nonUnitDimAcc, VectorType accTy);
59
60// Shuffles vectors produced by vector.contraction ops into a flat layout
61// before they are written to memory.
62LogicalResult shuffleBeforeWriteLikeOp(PatternRewriter &rewriter,
63 Operation *opA, Operation *opB,
64 int64_t nonUnitDimAcc, VectorType accTy);
65
66} // namespace x86vector
67} // namespace mlir
68
69#endif // MLIR_DIALECT_X86VECTOR_UTILS_X86VECTORUTILS_H_
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition AffineMap.h:46
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
Operation * traceToVectorReadLikeParentOperation(Value v)
Operation * traceToVectorWriteLikeUserOperation(Value v)
bool validatePairVectorContract(vector::ContractionOp contractOp, vector::ContractionOp pairContOp, bool rhsHasMultipleNonUnitDims, int64_t nonUnitDimValue)
LogicalResult shuffleBeforeWriteLikeOp(PatternRewriter &rewriter, Operation *opA, Operation *opB, int64_t nonUnitDimAcc, VectorType accTy)
LogicalResult shuffleAfterReadLikeOp(PatternRewriter &rewriter, Operation *opA, Operation *opB, vector::ContractionOp contractA, vector::ContractionOp contractB, int64_t nonUnitDimAcc, VectorType accTy)
bool isInVnniLayout(Operation *op, llvm::ArrayRef< AffineMap > indexingMaps, std::optional< unsigned > blockingFactor=std::nullopt)
Include the generated interface declarations.