MLIR  20.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 
21 #include "mlir/IR/BuiltinTypes.h"
23 #include <optional>
24 
25 namespace mlir {
26 class Location;
27 class PatternRewriter;
28 class Value;
29 } // namespace mlir
30 
31 namespace mlir::arm_sme {
32 
33 constexpr unsigned MinStreamingVectorLengthInBits = 128;
34 
35 /// Return minimum number of elements for the given element `type` in
36 /// a vector of SVL bits.
37 unsigned getSMETileSliceMinNumElts(Type type);
38 
39 /// Returns true if `type` is a valid element type for an SME tile or false
40 /// otherwise.
42 
43 /// Returns true if `vType` is a valid vector type for an SME tile or false
44 /// otherwise.
45 bool isValidSMETileVectorType(VectorType vType);
46 
47 inline bool isValidSMETileVectorType(Type type) {
48  auto vType = dyn_cast<VectorType>(type);
49  return vType && isValidSMETileVectorType(vType);
50 }
51 
52 /// Returns the type of SME tile this vector type corresponds to, or none if the
53 /// vector type does not fit within an SME tile.
54 std::optional<ArmSMETileType> getSMETileType(VectorType);
55 
56 /// Verifies the tile ID (if set) on this tile operation is valid.
58 
59 /// Generates a for loop over ZA tile slices where the induction variable is
60 /// the tile slice index and each iteration yields a new tile. Loop body is
61 /// built via `makeLoopBody`, which returns the next tile value.
62 scf::ForOp createLoopOverTileSlices(
63  PatternRewriter &rewriter, Location loc, Value initTile,
64  std::function<Value(OpBuilder &, Location, Value, Value)> makeLoopBody);
65 
66 /// Returns true if `vType` is a multiple of an SME tile size. Returns false if
67 /// the `vType` exactly matches the size of an SME tile.
68 bool isMultipleOfSMETileVectorType(VectorType vType);
69 
70 /// Creates a vector type for the SME tile of `elementType`.
71 VectorType getSMETileTypeForElement(Type elementType);
72 
73 /// Erase trivially dead tile ops from a function.
75  FunctionOpInterface function);
76 
77 /// Returns true if `tileOp` is trivially cloneable. A tile operation is
78 /// trivially cloneable if:
79 ///
80 /// 1. It has no operands (and only a single tile result)
81 /// 2. It is 'Pure'
82 ///
83 /// This ensures that the cloned operation will not share any dependencies with
84 /// the original operation (which could also need to be considered), and that
85 /// inserting the cloned operation at a different point in the program won't
86 /// change the semantics of the program (as it has no side effects).
87 bool isTriviallyCloneableTileOp(arm_sme::ArmSMETileOpInterface tileOp);
88 
89 /// Returns true if `tileOp` produces a tile result.
90 bool hasTileResult(arm_sme::ArmSMETileOpInterface tileOp);
91 
92 /// Returns the tile `OpOperand` for this `tileOp` (or null).
93 OpOperand *getTileOpOperand(arm_sme::ArmSMETileOpInterface tileOp);
94 
95 /// Returns true `typeA` is >= (in terms of bytes) than `typeB`.
96 bool isTileTypeGreaterOrEqual(ArmSMETileType typeA, ArmSMETileType typeB);
97 
98 } // namespace mlir::arm_sme
99 
100 #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 ...
Definition: PatternMatch.h:772
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:66
This class helps build Operations.
Definition: Builders.h:215
This class represents an operand of an operation.
Definition: Value.h:267
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:791
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
void eraseTriviallyDeadTileOps(IRRewriter &rewriter, FunctionOpInterface function)
Erase trivially dead tile ops from a function.
Definition: Utils.cpp:119
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
bool isTriviallyCloneableTileOp(arm_sme::ArmSMETileOpInterface tileOp)
Returns true if tileOp is trivially cloneable.
Definition: Utils.cpp:139
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 isTileTypeGreaterOrEqual(ArmSMETileType typeA, ArmSMETileType typeB)
Returns true typeA is >= (in terms of bytes) than typeB.
Definition: Utils.cpp:167
bool isValidSMETileVectorType(VectorType vType)
Returns true if vType is a valid vector type for an SME tile or false otherwise.
Definition: Utils.cpp:29
OpOperand * getTileOpOperand(arm_sme::ArmSMETileOpInterface tileOp)
Returns the tile OpOperand for this tileOp (or null).
Definition: Utils.cpp:152
LogicalResult verifyOperationHasValidTileId(Operation *)
Verifies the tile ID (if set) on this tile operation is valid.
Definition: Utils.cpp:63
bool hasTileResult(arm_sme::ArmSMETileOpInterface tileOp)
Returns true if tileOp produces a tile result.
Definition: Utils.cpp:144
constexpr unsigned MinStreamingVectorLengthInBits
Definition: Utils.h:33
Include the generated interface declarations.