MLIR 24.0.0git
X86Utils.h
Go to the documentation of this file.
1//===- X86Utils.h - X86 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_X86_UTILS_X86UTILS_H_
10#define MLIR_DIALECT_X86_UTILS_X86UTILS_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 x86 {
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// Recursively follows single-use values through scf.yield operations
33// and returns the first non-yield user result in the contraction chain.
34Value contractionUsersAfterYield(Value v);
35
36// Returns true if two contraction ops form a valid pair for VNNI packing.
37// It verifies that both contractions share the appropriate operand, read from
38// the same source buffer, and use constant indices that differ by 8 or 16.
39bool validatePairVectorContract(vector::ContractionOp contractOp,
40 vector::ContractionOp pairContOp,
41 bool rhsHasMultipleNonUnitDims,
42 int64_t nonUnitDimValue);
43
44// Walks backward from a value to find its originating vector read-like op
45// (vector.transfer_read or vector.load), following scf.for iter-args but
46// stopping at layout-transforming ops; returns the read op or nullptr.
47Operation *traceToVectorReadLikeParentOperation(Value v);
48
49// Recursively traces a value to find a downstream vector write-like op
50// (vector.transfer_write or vector.store), crossing scf.for/yield but
51// stopping at layout-altering ops. Returns nullptr if no vector writer/store
52// ops or there are multiple users.
53Operation *traceToVectorWriteLikeUserOperation(Value v);
54
55// Packs the accumulators of two flat BF16 vector.contraction ops into a
56// VNNI-packed layout and replaces the original accumulators to enable post-read
57// packing transformations.
58LogicalResult shuffleAfterReadLikeOp(PatternRewriter &rewriter, Operation *opA,
59 Operation *opB,
60 vector::ContractionOp contractA,
61 vector::ContractionOp contractB,
62 int64_t nonUnitDimAcc, VectorType accTy);
63
64// Shuffles vectors produced by vector.contraction ops into a flat layout
65// before they are written to memory.
66LogicalResult shuffleBeforeWriteLikeOp(PatternRewriter &rewriter,
67 Value contractARes, Value contractBRes,
68 int64_t nonUnitDimAcc, VectorType accTy);
69
70} // namespace x86
71} // namespace mlir
72
73#endif // MLIR_DIALECT_X86_UTILS_X86UTILS_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:87
LogicalResult shuffleBeforeWriteLikeOp(PatternRewriter &rewriter, Value contractARes, Value contractBRes, int64_t nonUnitDimAcc, VectorType accTy)
Definition X86Utils.cpp:331
Operation * traceToVectorWriteLikeUserOperation(Value v)
Definition X86Utils.cpp:233
bool isInVnniLayout(Operation *op, llvm::ArrayRef< AffineMap > indexingMaps, std::optional< unsigned > blockingFactor=std::nullopt)
Definition X86Utils.cpp:42
Value contractionUsersAfterYield(Value v)
Definition X86Utils.cpp:149
Operation * traceToVectorReadLikeParentOperation(Value v)
Definition X86Utils.cpp:173
LogicalResult shuffleAfterReadLikeOp(PatternRewriter &rewriter, Operation *opA, Operation *opB, vector::ContractionOp contractA, vector::ContractionOp contractB, int64_t nonUnitDimAcc, VectorType accTy)
Definition X86Utils.cpp:281
bool validatePairVectorContract(vector::ContractionOp contractOp, vector::ContractionOp pairContOp, bool rhsHasMultipleNonUnitDims, int64_t nonUnitDimValue)
Definition X86Utils.cpp:386
Include the generated interface declarations.