MLIR  19.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 
20 #include "mlir/IR/BuiltinTypes.h"
21 #include <optional>
22 
23 namespace mlir {
24 class Location;
25 class PatternRewriter;
26 class Value;
27 } // namespace mlir
28 
29 namespace mlir::arm_sme {
30 
31 constexpr unsigned MinStreamingVectorLengthInBits = 128;
32 
33 /// Return minimum number of elements for the given element `type` in
34 /// a vector of SVL bits.
35 unsigned getSMETileSliceMinNumElts(Type type);
36 
37 /// Returns true if `type` is a valid element type for an SME tile or false
38 /// otherwise.
40 
41 /// Returns true if `vType` is a valid vector type for an SME tile or false
42 /// otherwise.
43 bool isValidSMETileVectorType(VectorType vType);
44 
45 /// Returns the type of SME tile this vector type corresponds to, or none if the
46 /// vector type does not fit within an SME tile.
47 std::optional<ArmSMETileType> getSMETileType(VectorType);
48 
49 /// Verifies the tile ID (if set) on this tile operation is valid.
51 
52 /// Generates a for loop over ZA tile slices where the induction variable is
53 /// the tile slice index and each iteration yields a new tile. Loop body is
54 /// built via `makeLoopBody`, which returns the next tile value.
55 scf::ForOp createLoopOverTileSlices(
56  PatternRewriter &rewriter, Location loc, Value initTile,
57  std::function<Value(OpBuilder &, Location, Value, Value)> makeLoopBody);
58 
59 /// Returns true if `vType` is a multiple of an SME tile size. Returns false if
60 /// the `vType` exactly matches the size of an SME tile.
61 bool isMultipleOfSMETileVectorType(VectorType vType);
62 
63 /// Creates a vector type for the SME tile of `elementType`.
64 VectorType getSMETileTypeForElement(Type elementType);
65 
66 } // namespace mlir::arm_sme
67 
68 #endif // MLIR_DIALECT_ARMSME_UTILS_UTILS_H_
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
This class helps build Operations.
Definition: Builders.h:209
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...
Definition: PatternMatch.h:785
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:44
VectorType getSMETileTypeForElement(Type elementType)
Creates a vector type for the SME tile of elementType.
Definition: Utils.cpp:114
unsigned getSMETileSliceMinNumElts(Type type)
Return minimum number of elements for the given element type in a vector of SVL bits.
Definition: Utils.cpp:18
bool isValidSMETileElementType(Type type)
Returns true if type is a valid element type for an SME tile or false otherwise.
Definition: Utils.cpp:23
bool isMultipleOfSMETileVectorType(VectorType vType)
Returns true if vType is a multiple of an SME tile size.
Definition: Utils.cpp:97
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:75
bool isValidSMETileVectorType(VectorType vType)
Returns true if vType is a valid vector type for an SME tile or false otherwise.
Definition: Utils.cpp:29
LogicalResult verifyOperationHasValidTileId(Operation *)
Verifies the tile ID (if set) on this tile operation is valid.
Definition: Utils.cpp:63
constexpr unsigned MinStreamingVectorLengthInBits
Definition: Utils.h:31
Include the generated interface declarations.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26