MLIR 22.0.0git
Utils.h
Go to the documentation of this file.
1//===- Utils.h - General ArmSME transformation 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// This header file defines prototypes for various utilities for the ArmSME
10// dialect. These are not passes by themselves but are used either by passes,
11// optimization sequences, or in turn by other transformation utilities.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_DIALECT_ARMSME_UTILS_UTILS_H_
16#define MLIR_DIALECT_ARMSME_UTILS_UTILS_H_
17
23#include <optional>
24
25namespace mlir {
26class Location;
27class PatternRewriter;
28class Value;
29} // namespace mlir
30
31namespace mlir::arm_sme {
32
33constexpr unsigned MinStreamingVectorLengthInBits = 128;
34
35/// Return the size represented by arm_sme::TypeSize in bytes.
36unsigned getSizeInBytes(TypeSize type);
37
38/// Return minimum number of elements for the given element `type` in
39/// a vector of SVL bits.
40unsigned getSMETileSliceMinNumElts(Type type);
41
42/// Returns true if `type` is a valid element type for an SME tile or false
43/// otherwise.
45
46/// Returns true if `vType` is a valid vector type for an SME tile or false
47/// otherwise.
48bool isValidSMETileVectorType(VectorType vType);
49
50inline bool isValidSMETileVectorType(Type type) {
51 auto vType = dyn_cast<VectorType>(type);
52 return vType && isValidSMETileVectorType(vType);
53}
54
55/// Returns the type of SME tile this vector type corresponds to, or none if the
56/// vector type does not fit within an SME tile.
57std::optional<ArmSMETileType> getSMETileType(VectorType);
58
59/// Verifies the tile ID (if set) on this tile operation is valid.
61
62/// Generates a for loop over ZA tile slices where the induction variable is
63/// the tile slice index and each iteration yields a new tile. Loop body is
64/// built via `makeLoopBody`, which returns the next tile value.
66 PatternRewriter &rewriter, Location loc, Value initTile,
67 std::function<Value(OpBuilder &, Location, Value, Value)> makeLoopBody);
68
69/// Returns true if `vType` is a multiple of an SME tile size. Returns false if
70/// the `vType` exactly matches the size of an SME tile.
71bool isMultipleOfSMETileVectorType(VectorType vType);
72
73/// Creates a vector type for the SME tile of `elementType`.
74VectorType getSMETileTypeForElement(Type elementType);
75
76/// Erase trivially dead tile ops from a function.
78 FunctionOpInterface function);
79
80/// Returns true if `tileOp` is trivially cloneable. A tile operation is
81/// trivially cloneable if:
82///
83/// 1. It has no operands (and only a single tile result)
84/// 2. It is 'Pure'
85///
86/// This ensures that the cloned operation will not share any dependencies with
87/// the original operation (which could also need to be considered), and that
88/// inserting the cloned operation at a different point in the program won't
89/// change the semantics of the program (as it has no side effects).
91
92/// Returns true if `tileOp` produces a tile result.
94
95/// Returns the tile `OpOperand` for this `tileOp` (or null).
97
98/// Returns true `typeA` is >= (in terms of bytes) than `typeB`.
99bool isTileTypeGreaterOrEqual(ArmSMETileType typeA, ArmSMETileType typeB);
100
101} // namespace mlir::arm_sme
102
103#endif // MLIR_DIALECT_ARMSME_UTILS_UTILS_H_
This class coordinates rewriting a piece of IR outside of a pattern rewrite, providing a way to keep ...
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:207
This class represents an operand of an operation.
Definition Value.h:257
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
std::optional< ArmSMETileType > getSMETileType(VectorType)
Returns the type of SME tile this vector type corresponds to, or none if the vector type does not fit...
Definition Utils.cpp:58
void eraseTriviallyDeadTileOps(IRRewriter &rewriter, FunctionOpInterface function)
Erase trivially dead tile ops from a function.
Definition Utils.cpp:133
VectorType getSMETileTypeForElement(Type elementType)
Creates a vector type for the SME tile of elementType.
Definition Utils.cpp:128
unsigned getSMETileSliceMinNumElts(Type type)
Return minimum number of elements for the given element type in a vector of SVL bits.
Definition Utils.cpp:32
bool isValidSMETileElementType(Type type)
Returns true if type is a valid element type for an SME tile or false otherwise.
Definition Utils.cpp:37
bool isMultipleOfSMETileVectorType(VectorType vType)
Returns true if vType is a multiple of an SME tile size.
Definition Utils.cpp:111
bool isTriviallyCloneableTileOp(arm_sme::ArmSMETileOpInterface tileOp)
Returns true if tileOp is trivially cloneable.
Definition Utils.cpp:153
scf::ForOp createLoopOverTileSlices(PatternRewriter &rewriter, Location loc, Value initTile, std::function< Value(OpBuilder &, Location, Value, Value)> makeLoopBody)
Generates a for loop over ZA tile slices where the induction variable is the tile slice index and eac...
Definition Utils.cpp:89
unsigned getSizeInBytes(TypeSize type)
Return the size represented by arm_sme::TypeSize in bytes.
Definition Utils.cpp:17
bool isTileTypeGreaterOrEqual(ArmSMETileType typeA, ArmSMETileType typeB)
Returns true typeA is >= (in terms of bytes) than typeB.
Definition Utils.cpp:181
bool isValidSMETileVectorType(VectorType vType)
Returns true if vType is a valid vector type for an SME tile or false otherwise.
Definition Utils.cpp:43
OpOperand * getTileOpOperand(arm_sme::ArmSMETileOpInterface tileOp)
Returns the tile OpOperand for this tileOp (or null).
Definition Utils.cpp:166
LogicalResult verifyOperationHasValidTileId(Operation *)
Verifies the tile ID (if set) on this tile operation is valid.
Definition Utils.cpp:77
bool hasTileResult(arm_sme::ArmSMETileOpInterface tileOp)
Returns true if tileOp produces a tile result.
Definition Utils.cpp:158
constexpr unsigned MinStreamingVectorLengthInBits
Definition Utils.h:33
Include the generated interface declarations.