gokashi commited on
Commit
498b714
·
verified ·
1 Parent(s): 5e99411

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. deps/exla/cache/xla_extension/include/mlir/AsmParser/AsmParser.h +78 -0
  2. deps/exla/cache/xla_extension/include/mlir/AsmParser/AsmParserState.h +239 -0
  3. deps/exla/cache/xla_extension/include/mlir/AsmParser/CodeComplete.h +78 -0
  4. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPU.cpp.inc +0 -0
  5. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPU.h.inc +0 -0
  6. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUAttributes.cpp.inc +395 -0
  7. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUAttributes.h.inc +120 -0
  8. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUDialect.cpp.inc +27 -0
  9. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h +35 -0
  10. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h.inc +38 -0
  11. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUEnums.cpp.inc +223 -0
  12. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUEnums.h.inc +469 -0
  13. deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/Utils/Chipset.h +59 -0
  14. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMX.cpp.inc +1447 -0
  15. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMX.h.inc +1105 -0
  16. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXDialect.cpp.inc +25 -0
  17. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXDialect.h +34 -0
  18. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXDialect.h.inc +46 -0
  19. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXInterfaces.cpp.inc +22 -0
  20. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXInterfaces.h.inc +84 -0
  21. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXTypes.cpp.inc +131 -0
  22. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXTypes.h.inc +61 -0
  23. deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/Transforms.h +30 -0
  24. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h +199 -0
  25. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/AffineStructures.h +272 -0
  26. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/LoopAnalysis.h +133 -0
  27. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/NestedMatcher.h +198 -0
  28. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/Utils.h +633 -0
  29. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.cpp.inc +63 -0
  30. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.h +22 -0
  31. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.h.inc +435 -0
  32. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOps.cpp.inc +0 -0
  33. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOps.h +557 -0
  34. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOps.h.inc +0 -0
  35. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOpsDialect.cpp.inc +26 -0
  36. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOpsDialect.h.inc +34 -0
  37. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineValueMap.h +108 -0
  38. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.h +37 -0
  39. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/LoopFusionUtils.h +167 -0
  40. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/LoopUtils.h +312 -0
  41. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Passes.h +141 -0
  42. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Passes.h.inc +0 -0
  43. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Transforms/Transforms.h +119 -0
  44. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Utils.h +410 -0
  45. deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/ViewLikeInterfaceUtils.h +107 -0
  46. deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/Arith.h +160 -0
  47. deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/ArithCanonicalization.inc +0 -0
  48. deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/ArithOps.cpp.inc +0 -0
  49. deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/ArithOps.h.inc +0 -0
  50. deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc +240 -0
deps/exla/cache/xla_extension/include/mlir/AsmParser/AsmParser.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AsmParser.h - MLIR AsmParser Library Interface -----------*- 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 file is contains the interface to the MLIR assembly parser library.
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #ifndef MLIR_ASMPARSER_ASMPARSER_H
14
+ #define MLIR_ASMPARSER_ASMPARSER_H
15
+
16
+ #include "mlir/IR/AsmState.h"
17
+ #include <cstddef>
18
+
19
+ namespace llvm {
20
+ class SourceMgr;
21
+ class StringRef;
22
+ } // namespace llvm
23
+
24
+ namespace mlir {
25
+ class AsmParserState;
26
+ class AsmParserCodeCompleteContext;
27
+
28
+ /// This parses the file specified by the indicated SourceMgr and appends parsed
29
+ /// operations to the given block. If the block is non-empty, the operations are
30
+ /// placed before the current terminator. If parsing is successful, success is
31
+ /// returned. Otherwise, an error message is emitted through the error handler
32
+ /// registered in the context, and failure is returned. If `sourceFileLoc` is
33
+ /// non-null, it is populated with a file location representing the start of the
34
+ /// source file that is being parsed. If `asmState` is non-null, it is populated
35
+ /// with detailed information about the parsed IR (including exact locations for
36
+ /// SSA uses and definitions). `asmState` should only be provided if this
37
+ /// detailed information is desired. If `codeCompleteContext` is non-null, it is
38
+ /// used to signal tracking of a code completion event (generally only ever
39
+ /// useful for LSP or other high level language tooling).
40
+ LogicalResult
41
+ parseAsmSourceFile(const llvm::SourceMgr &sourceMgr, Block *block,
42
+ const ParserConfig &config,
43
+ AsmParserState *asmState = nullptr,
44
+ AsmParserCodeCompleteContext *codeCompleteContext = nullptr);
45
+
46
+ /// This parses a single MLIR attribute to an MLIR context if it was valid. If
47
+ /// not, an error diagnostic is emitted to the context and a null value is
48
+ /// returned.
49
+ /// If `numRead` is provided, it is set to the number of consumed characters on
50
+ /// successful parse. Otherwise, parsing fails if the entire string is not
51
+ /// consumed.
52
+ /// Some internal copying can be skipped if the source string is known to be
53
+ /// null terminated.
54
+ Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context,
55
+ Type type = {}, size_t *numRead = nullptr,
56
+ bool isKnownNullTerminated = false);
57
+
58
+ /// This parses a single MLIR type to an MLIR context if it was valid. If not,
59
+ /// an error diagnostic is emitted to the context.
60
+ /// If `numRead` is provided, it is set to the number of consumed characters on
61
+ /// successful parse. Otherwise, parsing fails if the entire string is not
62
+ /// consumed.
63
+ /// Some internal copying can be skipped if the source string is known to be
64
+ /// null terminated.
65
+ Type parseType(llvm::StringRef typeStr, MLIRContext *context,
66
+ size_t *numRead = nullptr, bool isKnownNullTerminated = false);
67
+
68
+ /// This parses a single IntegerSet/AffineMap to an MLIR context if it was
69
+ /// valid. If not, an error message is emitted through a new
70
+ /// SourceMgrDiagnosticHandler constructed from a new SourceMgr with a single
71
+ /// MemoryBuffer wrapping `str`. If the passed `str` has additional tokens that
72
+ /// were not part of the IntegerSet/AffineMap, a failure is returned.
73
+ AffineMap parseAffineMap(llvm::StringRef str, MLIRContext *context);
74
+ IntegerSet parseIntegerSet(llvm::StringRef str, MLIRContext *context);
75
+
76
+ } // namespace mlir
77
+
78
+ #endif // MLIR_ASMPARSER_ASMPARSER_H
deps/exla/cache/xla_extension/include/mlir/AsmParser/AsmParserState.h ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AsmParserState.h -----------------------------------------*- 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_ASMPARSER_ASMPARSERSTATE_H
10
+ #define MLIR_ASMPARSER_ASMPARSERSTATE_H
11
+
12
+ #include "mlir/IR/Attributes.h"
13
+ #include "mlir/IR/Types.h"
14
+ #include "llvm/Support/SMLoc.h"
15
+ #include <cstddef>
16
+
17
+ namespace mlir {
18
+ class Block;
19
+ class BlockArgument;
20
+ class FileLineColLoc;
21
+ class Operation;
22
+ class OperationName;
23
+ class SymbolRefAttr;
24
+ class Value;
25
+
26
+ /// This class represents state from a parsed MLIR textual format string. It is
27
+ /// useful for building additional analysis and language utilities on top of
28
+ /// textual MLIR. This should generally not be used for traditional compilation.
29
+ class AsmParserState {
30
+ public:
31
+ /// This class represents a definition within the source manager, containing
32
+ /// it's defining location and locations of any uses. SMDefinitions are only
33
+ /// provided for entities that have uses within an input file, e.g. SSA
34
+ /// values, Blocks, and Symbols.
35
+ struct SMDefinition {
36
+ SMDefinition() = default;
37
+ SMDefinition(SMRange loc) : loc(loc) {}
38
+
39
+ /// The source location of the definition.
40
+ SMRange loc;
41
+ /// The source location of all uses of the definition.
42
+ SmallVector<SMRange> uses;
43
+ };
44
+
45
+ /// This class represents the information for an operation definition within
46
+ /// an input file.
47
+ struct OperationDefinition {
48
+ struct ResultGroupDefinition {
49
+ ResultGroupDefinition(unsigned index, SMRange loc)
50
+ : startIndex(index), definition(loc) {}
51
+
52
+ /// The result number that starts this group.
53
+ unsigned startIndex;
54
+ /// The source definition of the result group.
55
+ SMDefinition definition;
56
+ };
57
+
58
+ OperationDefinition(Operation *op, SMRange loc, SMLoc endLoc)
59
+ : op(op), loc(loc), scopeLoc(loc.Start, endLoc) {}
60
+
61
+ /// The operation representing this definition.
62
+ Operation *op;
63
+
64
+ /// The source location for the operation, i.e. the location of its name.
65
+ SMRange loc;
66
+
67
+ /// The full source range of the operation definition, i.e. a range
68
+ /// encompassing the start and end of the full operation definition.
69
+ SMRange scopeLoc;
70
+
71
+ /// Source definitions for any result groups of this operation.
72
+ SmallVector<ResultGroupDefinition> resultGroups;
73
+
74
+ /// If this operation is a symbol operation, this vector contains symbol
75
+ /// uses of this operation.
76
+ SmallVector<SMRange> symbolUses;
77
+ };
78
+
79
+ /// This class represents the information for a block definition within the
80
+ /// input file.
81
+ struct BlockDefinition {
82
+ BlockDefinition(Block *block, SMRange loc = {})
83
+ : block(block), definition(loc) {}
84
+
85
+ /// The block representing this definition.
86
+ Block *block;
87
+
88
+ /// The source location for the block, i.e. the location of its name, and
89
+ /// any uses it has.
90
+ SMDefinition definition;
91
+
92
+ /// Source definitions for any arguments of this block.
93
+ SmallVector<SMDefinition> arguments;
94
+ };
95
+
96
+ /// This class represents the information for an attribute alias definition
97
+ /// within the input file.
98
+ struct AttributeAliasDefinition {
99
+ AttributeAliasDefinition(StringRef name, SMRange loc = {},
100
+ Attribute value = {})
101
+ : name(name), definition(loc), value(value) {}
102
+
103
+ /// The name of the attribute alias.
104
+ StringRef name;
105
+
106
+ /// The source location for the alias.
107
+ SMDefinition definition;
108
+
109
+ /// The value of the alias.
110
+ Attribute value;
111
+ };
112
+
113
+ /// This class represents the information for type definition within the input
114
+ /// file.
115
+ struct TypeAliasDefinition {
116
+ TypeAliasDefinition(StringRef name, SMRange loc, Type value)
117
+ : name(name), definition(loc), value(value) {}
118
+
119
+ /// The name of the attribute alias.
120
+ StringRef name;
121
+
122
+ /// The source location for the alias.
123
+ SMDefinition definition;
124
+
125
+ /// The value of the alias.
126
+ Type value;
127
+ };
128
+
129
+ AsmParserState();
130
+ ~AsmParserState();
131
+ AsmParserState &operator=(AsmParserState &&other);
132
+
133
+ //===--------------------------------------------------------------------===//
134
+ // Access State
135
+ //===--------------------------------------------------------------------===//
136
+
137
+ using BlockDefIterator = llvm::pointee_iterator<
138
+ ArrayRef<std::unique_ptr<BlockDefinition>>::iterator>;
139
+ using OperationDefIterator = llvm::pointee_iterator<
140
+ ArrayRef<std::unique_ptr<OperationDefinition>>::iterator>;
141
+ using AttributeDefIterator = llvm::pointee_iterator<
142
+ ArrayRef<std::unique_ptr<AttributeAliasDefinition>>::iterator>;
143
+ using TypeDefIterator = llvm::pointee_iterator<
144
+ ArrayRef<std::unique_ptr<TypeAliasDefinition>>::iterator>;
145
+
146
+ /// Return a range of the BlockDefinitions held by the current parser state.
147
+ iterator_range<BlockDefIterator> getBlockDefs() const;
148
+
149
+ /// Return the definition for the given block, or nullptr if the given
150
+ /// block does not have a definition.
151
+ const BlockDefinition *getBlockDef(Block *block) const;
152
+
153
+ /// Return a range of the OperationDefinitions held by the current parser
154
+ /// state.
155
+ iterator_range<OperationDefIterator> getOpDefs() const;
156
+
157
+ /// Return the definition for the given operation, or nullptr if the given
158
+ /// operation does not have a definition.
159
+ const OperationDefinition *getOpDef(Operation *op) const;
160
+
161
+ /// Return a range of the AttributeAliasDefinitions held by the current parser
162
+ /// state.
163
+ iterator_range<AttributeDefIterator> getAttributeAliasDefs() const;
164
+
165
+ /// Return the definition for the given attribute alias, or nullptr if the
166
+ /// given alias does not have a definition.
167
+ const AttributeAliasDefinition *getAttributeAliasDef(StringRef name) const;
168
+
169
+ /// Return a range of the TypeAliasDefinitions held by the current parser
170
+ /// state.
171
+ iterator_range<TypeDefIterator> getTypeAliasDefs() const;
172
+
173
+ /// Return the definition for the given type alias, or nullptr if the given
174
+ /// alias does not have a definition.
175
+ const TypeAliasDefinition *getTypeAliasDef(StringRef name) const;
176
+
177
+ /// Returns (heuristically) the range of an identifier given a SMLoc
178
+ /// corresponding to the start of an identifier location.
179
+ static SMRange convertIdLocToRange(SMLoc loc);
180
+
181
+ //===--------------------------------------------------------------------===//
182
+ // Populate State
183
+ //===--------------------------------------------------------------------===//
184
+
185
+ /// Initialize the state in preparation for populating more parser state under
186
+ /// the given top-level operation.
187
+ void initialize(Operation *topLevelOp);
188
+
189
+ /// Finalize any in-progress parser state under the given top-level operation.
190
+ void finalize(Operation *topLevelOp);
191
+
192
+ /// Start a definition for an operation with the given name.
193
+ void startOperationDefinition(const OperationName &opName);
194
+
195
+ /// Finalize the most recently started operation definition.
196
+ void finalizeOperationDefinition(
197
+ Operation *op, SMRange nameLoc, SMLoc endLoc,
198
+ ArrayRef<std::pair<unsigned, SMLoc>> resultGroups = std::nullopt);
199
+
200
+ /// Start a definition for a region nested under the current operation.
201
+ void startRegionDefinition();
202
+
203
+ /// Finalize the most recently started region definition.
204
+ void finalizeRegionDefinition();
205
+
206
+ /// Add a definition of the given entity.
207
+ void addDefinition(Block *block, SMLoc location);
208
+ void addDefinition(BlockArgument blockArg, SMLoc location);
209
+ void addAttrAliasDefinition(StringRef name, SMRange location,
210
+ Attribute value);
211
+ void addTypeAliasDefinition(StringRef name, SMRange location, Type value);
212
+
213
+ /// Add a source uses of the given value.
214
+ void addUses(Value value, ArrayRef<SMLoc> locations);
215
+ void addUses(Block *block, ArrayRef<SMLoc> locations);
216
+ void addAttrAliasUses(StringRef name, SMRange locations);
217
+ void addTypeAliasUses(StringRef name, SMRange locations);
218
+
219
+ /// Add source uses for all the references nested under `refAttr`. The
220
+ /// provided `locations` should match 1-1 with the number of references in
221
+ /// `refAttr`, i.e.:
222
+ /// nestedReferences.size() + /*leafReference=*/1 == refLocations.size()
223
+ void addUses(SymbolRefAttr refAttr, ArrayRef<SMRange> refLocations);
224
+
225
+ /// Refine the `oldValue` to the `newValue`. This is used to indicate that
226
+ /// `oldValue` was a placeholder, and the uses of it should really refer to
227
+ /// `newValue`.
228
+ void refineDefinition(Value oldValue, Value newValue);
229
+
230
+ private:
231
+ struct Impl;
232
+
233
+ /// A pointer to the internal implementation of this class.
234
+ std::unique_ptr<Impl> impl;
235
+ };
236
+
237
+ } // namespace mlir
238
+
239
+ #endif // MLIR_ASMPARSER_ASMPARSERSTATE_H
deps/exla/cache/xla_extension/include/mlir/AsmParser/CodeComplete.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- CodeComplete.h - MLIR Asm CodeComplete Context -----------*- 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_ASMPARSER_CODECOMPLETE_H
10
+ #define MLIR_ASMPARSER_CODECOMPLETE_H
11
+
12
+ #include "mlir/Support/LLVM.h"
13
+ #include "llvm/ADT/StringMap.h"
14
+ #include "llvm/Support/SourceMgr.h"
15
+
16
+ namespace mlir {
17
+ class Attribute;
18
+ class Type;
19
+
20
+ /// This class provides an abstract interface into the parser for hooking in
21
+ /// code completion events. This class is only really useful for providing
22
+ /// language tooling for MLIR, general clients should not need to use this
23
+ /// class.
24
+ class AsmParserCodeCompleteContext {
25
+ public:
26
+ virtual ~AsmParserCodeCompleteContext();
27
+
28
+ /// Return the source location used to provide code completion.
29
+ SMLoc getCodeCompleteLoc() const { return codeCompleteLoc; }
30
+
31
+ //===--------------------------------------------------------------------===//
32
+ // Completion Hooks
33
+ //===--------------------------------------------------------------------===//
34
+
35
+ /// Signal code completion for a dialect name, with an optional prefix.
36
+ virtual void completeDialectName(StringRef prefix) = 0;
37
+ void completeDialectName() { completeDialectName(""); }
38
+
39
+ /// Signal code completion for an operation name within the given dialect.
40
+ virtual void completeOperationName(StringRef dialectName) = 0;
41
+
42
+ /// Append the given SSA value as a code completion result for SSA value
43
+ /// completions.
44
+ virtual void appendSSAValueCompletion(StringRef name,
45
+ std::string typeData) = 0;
46
+
47
+ /// Append the given block as a code completion result for block name
48
+ /// completions.
49
+ virtual void appendBlockCompletion(StringRef name) = 0;
50
+
51
+ /// Signal a completion for the given expected tokens, which are optional if
52
+ /// `optional` is set.
53
+ virtual void completeExpectedTokens(ArrayRef<StringRef> tokens,
54
+ bool optional) = 0;
55
+
56
+ /// Signal a completion for an attribute.
57
+ virtual void completeAttribute(const llvm::StringMap<Attribute> &aliases) = 0;
58
+ virtual void completeDialectAttributeOrAlias(
59
+ const llvm::StringMap<Attribute> &aliases) = 0;
60
+
61
+ /// Signal a completion for a type.
62
+ virtual void completeType(const llvm::StringMap<Type> &aliases) = 0;
63
+ virtual void
64
+ completeDialectTypeOrAlias(const llvm::StringMap<Type> &aliases) = 0;
65
+
66
+ protected:
67
+ /// Create a new code completion context with the given code complete
68
+ /// location.
69
+ explicit AsmParserCodeCompleteContext(SMLoc codeCompleteLoc)
70
+ : codeCompleteLoc(codeCompleteLoc) {}
71
+
72
+ private:
73
+ /// The location used to code complete.
74
+ SMLoc codeCompleteLoc;
75
+ };
76
+ } // namespace mlir
77
+
78
+ #endif // MLIR_ASMPARSER_CODECOMPLETE_H
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPU.cpp.inc ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPU.h.inc ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUAttributes.cpp.inc ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* AttrDef Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+ #ifdef GET_ATTRDEF_LIST
10
+ #undef GET_ATTRDEF_LIST
11
+
12
+ ::mlir::amdgpu::AddressSpaceAttr,
13
+ ::mlir::amdgpu::DPPPermAttr,
14
+ ::mlir::amdgpu::sched_barrier_opt_enumAttr,
15
+ ::mlir::amdgpu::MFMAPermBAttr
16
+
17
+ #endif // GET_ATTRDEF_LIST
18
+
19
+ #ifdef GET_ATTRDEF_CLASSES
20
+ #undef GET_ATTRDEF_CLASSES
21
+
22
+ static ::mlir::OptionalParseResult generatedAttributeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type type, ::mlir::Attribute &value) {
23
+ return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
24
+ .Case(::mlir::amdgpu::AddressSpaceAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
25
+ value = ::mlir::amdgpu::AddressSpaceAttr::parse(parser, type);
26
+ return ::mlir::success(!!value);
27
+ })
28
+ .Case(::mlir::amdgpu::DPPPermAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
29
+ value = ::mlir::amdgpu::DPPPermAttr::parse(parser, type);
30
+ return ::mlir::success(!!value);
31
+ })
32
+ .Case(::mlir::amdgpu::sched_barrier_opt_enumAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
33
+ value = ::mlir::amdgpu::sched_barrier_opt_enumAttr::parse(parser, type);
34
+ return ::mlir::success(!!value);
35
+ })
36
+ .Case(::mlir::amdgpu::MFMAPermBAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
37
+ value = ::mlir::amdgpu::MFMAPermBAttr::parse(parser, type);
38
+ return ::mlir::success(!!value);
39
+ })
40
+ .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
41
+ *mnemonic = keyword;
42
+ return std::nullopt;
43
+ });
44
+ }
45
+
46
+ static ::llvm::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
47
+ return ::llvm::TypeSwitch<::mlir::Attribute, ::llvm::LogicalResult>(def) .Case<::mlir::amdgpu::AddressSpaceAttr>([&](auto t) {
48
+ printer << ::mlir::amdgpu::AddressSpaceAttr::getMnemonic();
49
+ t.print(printer);
50
+ return ::mlir::success();
51
+ })
52
+ .Case<::mlir::amdgpu::DPPPermAttr>([&](auto t) {
53
+ printer << ::mlir::amdgpu::DPPPermAttr::getMnemonic();
54
+ t.print(printer);
55
+ return ::mlir::success();
56
+ })
57
+ .Case<::mlir::amdgpu::sched_barrier_opt_enumAttr>([&](auto t) {
58
+ printer << ::mlir::amdgpu::sched_barrier_opt_enumAttr::getMnemonic();
59
+ t.print(printer);
60
+ return ::mlir::success();
61
+ })
62
+ .Case<::mlir::amdgpu::MFMAPermBAttr>([&](auto t) {
63
+ printer << ::mlir::amdgpu::MFMAPermBAttr::getMnemonic();
64
+ t.print(printer);
65
+ return ::mlir::success();
66
+ })
67
+ .Default([](auto) { return ::mlir::failure(); });
68
+ }
69
+
70
+ namespace mlir {
71
+ namespace amdgpu {
72
+ namespace detail {
73
+ struct AddressSpaceAttrStorage : public ::mlir::AttributeStorage {
74
+ using KeyTy = std::tuple<::mlir::amdgpu::AddressSpace>;
75
+ AddressSpaceAttrStorage(::mlir::amdgpu::AddressSpace value) : value(std::move(value)) {}
76
+
77
+ KeyTy getAsKey() const {
78
+ return KeyTy(value);
79
+ }
80
+
81
+ bool operator==(const KeyTy &tblgenKey) const {
82
+ return (value == std::get<0>(tblgenKey));
83
+ }
84
+
85
+ static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
86
+ return ::llvm::hash_combine(std::get<0>(tblgenKey));
87
+ }
88
+
89
+ static AddressSpaceAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
90
+ auto value = std::move(std::get<0>(tblgenKey));
91
+ return new (allocator.allocate<AddressSpaceAttrStorage>()) AddressSpaceAttrStorage(std::move(value));
92
+ }
93
+
94
+ ::mlir::amdgpu::AddressSpace value;
95
+ };
96
+ } // namespace detail
97
+ AddressSpaceAttr AddressSpaceAttr::get(::mlir::MLIRContext *context, ::mlir::amdgpu::AddressSpace value) {
98
+ return Base::get(context, std::move(value));
99
+ }
100
+
101
+ ::mlir::Attribute AddressSpaceAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
102
+ ::mlir::Builder odsBuilder(odsParser.getContext());
103
+ ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
104
+ (void) odsLoc;
105
+ ::mlir::FailureOr<::mlir::amdgpu::AddressSpace> _result_value;
106
+ // Parse literal '<'
107
+ if (odsParser.parseLess()) return {};
108
+
109
+ // Parse variable 'value'
110
+ _result_value = [&]() -> ::mlir::FailureOr<::mlir::amdgpu::AddressSpace> {
111
+ auto loc = odsParser.getCurrentLocation();
112
+ ::llvm::StringRef enumKeyword;
113
+ if (::mlir::failed(odsParser.parseKeyword(&enumKeyword)))
114
+ return ::mlir::failure();
115
+ auto maybeEnum = ::mlir::amdgpu::symbolizeAddressSpace(enumKeyword);
116
+ if (maybeEnum)
117
+ return *maybeEnum;
118
+ return {(::llvm::LogicalResult)(odsParser.emitError(loc) << "expected " << "::mlir::amdgpu::AddressSpace" << " to be one of: " << "fat_raw_buffer" << ", " << "buffer_rsrc" << ", " << "fat_structured_buffer")};
119
+ }();
120
+ if (::mlir::failed(_result_value)) {
121
+ odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse AMDGPU_AddressSpaceAttr parameter 'value' which is to be a `::mlir::amdgpu::AddressSpace`");
122
+ return {};
123
+ }
124
+ // Parse literal '>'
125
+ if (odsParser.parseGreater()) return {};
126
+ assert(::mlir::succeeded(_result_value));
127
+ return AddressSpaceAttr::get(odsParser.getContext(),
128
+ ::mlir::amdgpu::AddressSpace((*_result_value)));
129
+ }
130
+
131
+ void AddressSpaceAttr::print(::mlir::AsmPrinter &odsPrinter) const {
132
+ ::mlir::Builder odsBuilder(getContext());
133
+ odsPrinter << "<";
134
+ odsPrinter << stringifyAddressSpace(getValue());
135
+ odsPrinter << ">";
136
+ }
137
+
138
+ ::mlir::amdgpu::AddressSpace AddressSpaceAttr::getValue() const {
139
+ return getImpl()->value;
140
+ }
141
+
142
+ } // namespace amdgpu
143
+ } // namespace mlir
144
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amdgpu::AddressSpaceAttr)
145
+ namespace mlir {
146
+ namespace amdgpu {
147
+ namespace detail {
148
+ struct DPPPermAttrStorage : public ::mlir::AttributeStorage {
149
+ using KeyTy = std::tuple<::mlir::amdgpu::DPPPerm>;
150
+ DPPPermAttrStorage(::mlir::amdgpu::DPPPerm value) : value(std::move(value)) {}
151
+
152
+ KeyTy getAsKey() const {
153
+ return KeyTy(value);
154
+ }
155
+
156
+ bool operator==(const KeyTy &tblgenKey) const {
157
+ return (value == std::get<0>(tblgenKey));
158
+ }
159
+
160
+ static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
161
+ return ::llvm::hash_combine(std::get<0>(tblgenKey));
162
+ }
163
+
164
+ static DPPPermAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
165
+ auto value = std::move(std::get<0>(tblgenKey));
166
+ return new (allocator.allocate<DPPPermAttrStorage>()) DPPPermAttrStorage(std::move(value));
167
+ }
168
+
169
+ ::mlir::amdgpu::DPPPerm value;
170
+ };
171
+ } // namespace detail
172
+ DPPPermAttr DPPPermAttr::get(::mlir::MLIRContext *context, ::mlir::amdgpu::DPPPerm value) {
173
+ return Base::get(context, std::move(value));
174
+ }
175
+
176
+ ::mlir::Attribute DPPPermAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
177
+ ::mlir::Builder odsBuilder(odsParser.getContext());
178
+ ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
179
+ (void) odsLoc;
180
+ ::mlir::FailureOr<::mlir::amdgpu::DPPPerm> _result_value;
181
+
182
+ // Parse variable 'value'
183
+ _result_value = [&]() -> ::mlir::FailureOr<::mlir::amdgpu::DPPPerm> {
184
+ auto loc = odsParser.getCurrentLocation();
185
+ ::llvm::StringRef enumKeyword;
186
+ if (::mlir::failed(odsParser.parseKeyword(&enumKeyword)))
187
+ return ::mlir::failure();
188
+ auto maybeEnum = ::mlir::amdgpu::symbolizeDPPPerm(enumKeyword);
189
+ if (maybeEnum)
190
+ return *maybeEnum;
191
+ return {(::llvm::LogicalResult)(odsParser.emitError(loc) << "expected " << "::mlir::amdgpu::DPPPerm" << " to be one of: " << "quad_perm" << ", " << "row_shl" << ", " << "row_shr" << ", " << "row_ror" << ", " << "wave_shl" << ", " << "wave_shr" << ", " << "wave_ror" << ", " << "wave_rol" << ", " << "row_mirror" << ", " << "row_half_mirror" << ", " << "row_bcast_15" << ", " << "row_bcast_31")};
192
+ }();
193
+ if (::mlir::failed(_result_value)) {
194
+ odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse AMDGPU_DPPPermAttr parameter 'value' which is to be a `::mlir::amdgpu::DPPPerm`");
195
+ return {};
196
+ }
197
+ assert(::mlir::succeeded(_result_value));
198
+ return DPPPermAttr::get(odsParser.getContext(),
199
+ ::mlir::amdgpu::DPPPerm((*_result_value)));
200
+ }
201
+
202
+ void DPPPermAttr::print(::mlir::AsmPrinter &odsPrinter) const {
203
+ ::mlir::Builder odsBuilder(getContext());
204
+ odsPrinter << ' ';
205
+ odsPrinter << stringifyDPPPerm(getValue());
206
+ }
207
+
208
+ ::mlir::amdgpu::DPPPerm DPPPermAttr::getValue() const {
209
+ return getImpl()->value;
210
+ }
211
+
212
+ } // namespace amdgpu
213
+ } // namespace mlir
214
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amdgpu::DPPPermAttr)
215
+ namespace mlir {
216
+ namespace amdgpu {
217
+ namespace detail {
218
+ struct sched_barrier_opt_enumAttrStorage : public ::mlir::AttributeStorage {
219
+ using KeyTy = std::tuple<::mlir::amdgpu::sched_barrier_opt_enum>;
220
+ sched_barrier_opt_enumAttrStorage(::mlir::amdgpu::sched_barrier_opt_enum value) : value(std::move(value)) {}
221
+
222
+ KeyTy getAsKey() const {
223
+ return KeyTy(value);
224
+ }
225
+
226
+ bool operator==(const KeyTy &tblgenKey) const {
227
+ return (value == std::get<0>(tblgenKey));
228
+ }
229
+
230
+ static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
231
+ return ::llvm::hash_combine(std::get<0>(tblgenKey));
232
+ }
233
+
234
+ static sched_barrier_opt_enumAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
235
+ auto value = std::move(std::get<0>(tblgenKey));
236
+ return new (allocator.allocate<sched_barrier_opt_enumAttrStorage>()) sched_barrier_opt_enumAttrStorage(std::move(value));
237
+ }
238
+
239
+ ::mlir::amdgpu::sched_barrier_opt_enum value;
240
+ };
241
+ } // namespace detail
242
+ sched_barrier_opt_enumAttr sched_barrier_opt_enumAttr::get(::mlir::MLIRContext *context, ::mlir::amdgpu::sched_barrier_opt_enum value) {
243
+ return Base::get(context, std::move(value));
244
+ }
245
+
246
+ ::mlir::Attribute sched_barrier_opt_enumAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
247
+ ::mlir::Builder odsBuilder(odsParser.getContext());
248
+ ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
249
+ (void) odsLoc;
250
+ ::mlir::FailureOr<::mlir::amdgpu::sched_barrier_opt_enum> _result_value;
251
+ // Parse literal '<'
252
+ if (odsParser.parseLess()) return {};
253
+
254
+ // Parse variable 'value'
255
+ _result_value = [&]() -> ::mlir::FailureOr<::mlir::amdgpu::sched_barrier_opt_enum> {
256
+ ::mlir::amdgpu::sched_barrier_opt_enum flags = {};
257
+ auto loc = odsParser.getCurrentLocation();
258
+ ::llvm::StringRef enumKeyword;
259
+ do {
260
+ if (::mlir::failed(odsParser.parseKeyword(&enumKeyword)))
261
+ return ::mlir::failure();
262
+ auto maybeEnum = ::mlir::amdgpu::symbolizesched_barrier_opt_enum(enumKeyword);
263
+ if (!maybeEnum) {
264
+ return {(::llvm::LogicalResult)(odsParser.emitError(loc) << "expected " << "::mlir::amdgpu::sched_barrier_opt_enum" << " to be one of: " << "none" << ", " << "non_mem_non_sideffect" << ", " << "valu" << ", " << "salu" << ", " << "mfma_wmma" << ", " << "all_vmem" << ", " << "vmem_read" << ", " << "vmem_write" << ", " << "all_ds" << ", " << "ds_read" << ", " << "ds_write" << ", " << "transcendental")};
265
+ }
266
+ flags = flags | *maybeEnum;
267
+ } while(::mlir::succeeded(odsParser.parseOptionalVerticalBar()));
268
+ return flags;
269
+ }();
270
+ if (::mlir::failed(_result_value)) {
271
+ odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse AMDGPU_SchedBarrierOpOptAttr parameter 'value' which is to be a `::mlir::amdgpu::sched_barrier_opt_enum`");
272
+ return {};
273
+ }
274
+ // Parse literal '>'
275
+ if (odsParser.parseGreater()) return {};
276
+ assert(::mlir::succeeded(_result_value));
277
+ return sched_barrier_opt_enumAttr::get(odsParser.getContext(),
278
+ ::mlir::amdgpu::sched_barrier_opt_enum((*_result_value)));
279
+ }
280
+
281
+ void sched_barrier_opt_enumAttr::print(::mlir::AsmPrinter &odsPrinter) const {
282
+ ::mlir::Builder odsBuilder(getContext());
283
+ odsPrinter << "<";
284
+ odsPrinter << stringifysched_barrier_opt_enum(getValue());
285
+ odsPrinter << ">";
286
+ }
287
+
288
+ ::mlir::amdgpu::sched_barrier_opt_enum sched_barrier_opt_enumAttr::getValue() const {
289
+ return getImpl()->value;
290
+ }
291
+
292
+ } // namespace amdgpu
293
+ } // namespace mlir
294
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amdgpu::sched_barrier_opt_enumAttr)
295
+ namespace mlir {
296
+ namespace amdgpu {
297
+ namespace detail {
298
+ struct MFMAPermBAttrStorage : public ::mlir::AttributeStorage {
299
+ using KeyTy = std::tuple<::mlir::amdgpu::MFMAPermB>;
300
+ MFMAPermBAttrStorage(::mlir::amdgpu::MFMAPermB value) : value(std::move(value)) {}
301
+
302
+ KeyTy getAsKey() const {
303
+ return KeyTy(value);
304
+ }
305
+
306
+ bool operator==(const KeyTy &tblgenKey) const {
307
+ return (value == std::get<0>(tblgenKey));
308
+ }
309
+
310
+ static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
311
+ return ::llvm::hash_combine(std::get<0>(tblgenKey));
312
+ }
313
+
314
+ static MFMAPermBAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
315
+ auto value = std::move(std::get<0>(tblgenKey));
316
+ return new (allocator.allocate<MFMAPermBAttrStorage>()) MFMAPermBAttrStorage(std::move(value));
317
+ }
318
+
319
+ ::mlir::amdgpu::MFMAPermB value;
320
+ };
321
+ } // namespace detail
322
+ MFMAPermBAttr MFMAPermBAttr::get(::mlir::MLIRContext *context, ::mlir::amdgpu::MFMAPermB value) {
323
+ return Base::get(context, std::move(value));
324
+ }
325
+
326
+ ::mlir::Attribute MFMAPermBAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
327
+ ::mlir::Builder odsBuilder(odsParser.getContext());
328
+ ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
329
+ (void) odsLoc;
330
+ ::mlir::FailureOr<::mlir::amdgpu::MFMAPermB> _result_value;
331
+
332
+ // Parse variable 'value'
333
+ _result_value = [&]() -> ::mlir::FailureOr<::mlir::amdgpu::MFMAPermB> {
334
+ auto loc = odsParser.getCurrentLocation();
335
+ ::llvm::StringRef enumKeyword;
336
+ if (::mlir::failed(odsParser.parseKeyword(&enumKeyword)))
337
+ return ::mlir::failure();
338
+ auto maybeEnum = ::mlir::amdgpu::symbolizeMFMAPermB(enumKeyword);
339
+ if (maybeEnum)
340
+ return *maybeEnum;
341
+ return {(::llvm::LogicalResult)(odsParser.emitError(loc) << "expected " << "::mlir::amdgpu::MFMAPermB" << " to be one of: " << "none" << ", " << "bcast_first_32" << ", " << "bcast_second_32" << ", " << "rotate_16_right" << ", " << "bcast_first_16" << ", " << "bcast_second_16" << ", " << "bcast_third_16" << ", " << "bcast_fourth_16")};
342
+ }();
343
+ if (::mlir::failed(_result_value)) {
344
+ odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse AMDGPU_MFMAPermBAttr parameter 'value' which is to be a `::mlir::amdgpu::MFMAPermB`");
345
+ return {};
346
+ }
347
+ assert(::mlir::succeeded(_result_value));
348
+ return MFMAPermBAttr::get(odsParser.getContext(),
349
+ ::mlir::amdgpu::MFMAPermB((*_result_value)));
350
+ }
351
+
352
+ void MFMAPermBAttr::print(::mlir::AsmPrinter &odsPrinter) const {
353
+ ::mlir::Builder odsBuilder(getContext());
354
+ odsPrinter << ' ';
355
+ odsPrinter << stringifyMFMAPermB(getValue());
356
+ }
357
+
358
+ ::mlir::amdgpu::MFMAPermB MFMAPermBAttr::getValue() const {
359
+ return getImpl()->value;
360
+ }
361
+
362
+ } // namespace amdgpu
363
+ } // namespace mlir
364
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amdgpu::MFMAPermBAttr)
365
+ namespace mlir {
366
+ namespace amdgpu {
367
+
368
+ /// Parse an attribute registered to this dialect.
369
+ ::mlir::Attribute AMDGPUDialect::parseAttribute(::mlir::DialectAsmParser &parser,
370
+ ::mlir::Type type) const {
371
+ ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
372
+ ::llvm::StringRef attrTag;
373
+ {
374
+ ::mlir::Attribute attr;
375
+ auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
376
+ if (parseResult.has_value())
377
+ return attr;
378
+ }
379
+
380
+ parser.emitError(typeLoc) << "unknown attribute `"
381
+ << attrTag << "` in dialect `" << getNamespace() << "`";
382
+ return {};
383
+ }
384
+ /// Print an attribute registered to this dialect.
385
+ void AMDGPUDialect::printAttribute(::mlir::Attribute attr,
386
+ ::mlir::DialectAsmPrinter &printer) const {
387
+ if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
388
+ return;
389
+
390
+ }
391
+ } // namespace amdgpu
392
+ } // namespace mlir
393
+
394
+ #endif // GET_ATTRDEF_CLASSES
395
+
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUAttributes.h.inc ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* AttrDef Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+ #ifdef GET_ATTRDEF_CLASSES
10
+ #undef GET_ATTRDEF_CLASSES
11
+
12
+
13
+ namespace mlir {
14
+ class AsmParser;
15
+ class AsmPrinter;
16
+ } // namespace mlir
17
+ namespace mlir {
18
+ namespace amdgpu {
19
+ /// AMDGPU-specific address spaces
20
+ /// AMDGPU-specific memory spaces that may not have exact analogues on other
21
+ /// GPU targets or backends.
22
+ ///
23
+ /// - `fat_raw_buffer` is the memory space used when a memref is stored as
24
+ /// as a "buffer fat pointer" - that is, a buffer resource (that is set up to
25
+ /// use raw byte-level indexing) along with its offset. The AMDGPU backend
26
+ /// implements `ptr addrspace(7)` to represent these fat pointers so that
27
+ /// buffer resources (which allow advanced features like bounds checking or
28
+ /// cache swizzling) can be used like ordinary LLVM pointers or memrefs.
29
+ /// See also the `fat_raw_buffer_cast` operation
30
+ /// - `buffer_rsrc` is the memory space for `ptr addrspace(8)`, representing a
31
+ /// buffer resource. It should not be used for memrefs, since it does not support
32
+ /// indexing
33
+ /// - `fat_structured_buffer` represents `ptr addrspace(9)`, a buffer resource
34
+ /// that carries both an index and offset field, which are used for complex
35
+ /// structured indexing that is primarily seen in graphics applications. This
36
+ /// is also incompatible with the simple indexing model supported by memref.
37
+ class AddressSpaceAttr;
38
+ /// The possible permutations for a DPP operation
39
+ class DPPPermAttr;
40
+ /// The possible options for scheduling barriers
41
+ class sched_barrier_opt_enumAttr;
42
+ /// The possible permutations of the lanes storing B available in an MFMA
43
+ class MFMAPermBAttr;
44
+ namespace detail {
45
+ struct AddressSpaceAttrStorage;
46
+ } // namespace detail
47
+ class AddressSpaceAttr : public ::mlir::Attribute::AttrBase<AddressSpaceAttr, ::mlir::Attribute, detail::AddressSpaceAttrStorage> {
48
+ public:
49
+ using Base::Base;
50
+ static constexpr ::llvm::StringLiteral name = "amdgpu.address_space";
51
+ static constexpr ::llvm::StringLiteral dialectName = "amdgpu";
52
+ static AddressSpaceAttr get(::mlir::MLIRContext *context, ::mlir::amdgpu::AddressSpace value);
53
+ static constexpr ::llvm::StringLiteral getMnemonic() {
54
+ return {"address_space"};
55
+ }
56
+
57
+ static ::mlir::Attribute parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType);
58
+ void print(::mlir::AsmPrinter &odsPrinter) const;
59
+ ::mlir::amdgpu::AddressSpace getValue() const;
60
+ };
61
+ namespace detail {
62
+ struct DPPPermAttrStorage;
63
+ } // namespace detail
64
+ class DPPPermAttr : public ::mlir::Attribute::AttrBase<DPPPermAttr, ::mlir::Attribute, detail::DPPPermAttrStorage> {
65
+ public:
66
+ using Base::Base;
67
+ static constexpr ::llvm::StringLiteral name = "amdgpu.dpp_perm";
68
+ static constexpr ::llvm::StringLiteral dialectName = "amdgpu";
69
+ static DPPPermAttr get(::mlir::MLIRContext *context, ::mlir::amdgpu::DPPPerm value);
70
+ static constexpr ::llvm::StringLiteral getMnemonic() {
71
+ return {"dpp_perm"};
72
+ }
73
+
74
+ static ::mlir::Attribute parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType);
75
+ void print(::mlir::AsmPrinter &odsPrinter) const;
76
+ ::mlir::amdgpu::DPPPerm getValue() const;
77
+ };
78
+ namespace detail {
79
+ struct sched_barrier_opt_enumAttrStorage;
80
+ } // namespace detail
81
+ class sched_barrier_opt_enumAttr : public ::mlir::Attribute::AttrBase<sched_barrier_opt_enumAttr, ::mlir::Attribute, detail::sched_barrier_opt_enumAttrStorage> {
82
+ public:
83
+ using Base::Base;
84
+ static constexpr ::llvm::StringLiteral name = "amdgpu.sched_barrier_opt";
85
+ static constexpr ::llvm::StringLiteral dialectName = "amdgpu";
86
+ static sched_barrier_opt_enumAttr get(::mlir::MLIRContext *context, ::mlir::amdgpu::sched_barrier_opt_enum value);
87
+ static constexpr ::llvm::StringLiteral getMnemonic() {
88
+ return {"sched_barrier_opt"};
89
+ }
90
+
91
+ static ::mlir::Attribute parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType);
92
+ void print(::mlir::AsmPrinter &odsPrinter) const;
93
+ ::mlir::amdgpu::sched_barrier_opt_enum getValue() const;
94
+ };
95
+ namespace detail {
96
+ struct MFMAPermBAttrStorage;
97
+ } // namespace detail
98
+ class MFMAPermBAttr : public ::mlir::Attribute::AttrBase<MFMAPermBAttr, ::mlir::Attribute, detail::MFMAPermBAttrStorage> {
99
+ public:
100
+ using Base::Base;
101
+ static constexpr ::llvm::StringLiteral name = "amdgpu.mfma_perm_b";
102
+ static constexpr ::llvm::StringLiteral dialectName = "amdgpu";
103
+ static MFMAPermBAttr get(::mlir::MLIRContext *context, ::mlir::amdgpu::MFMAPermB value);
104
+ static constexpr ::llvm::StringLiteral getMnemonic() {
105
+ return {"mfma_perm_b"};
106
+ }
107
+
108
+ static ::mlir::Attribute parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType);
109
+ void print(::mlir::AsmPrinter &odsPrinter) const;
110
+ ::mlir::amdgpu::MFMAPermB getValue() const;
111
+ };
112
+ } // namespace amdgpu
113
+ } // namespace mlir
114
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amdgpu::AddressSpaceAttr)
115
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amdgpu::DPPPermAttr)
116
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amdgpu::sched_barrier_opt_enumAttr)
117
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amdgpu::MFMAPermBAttr)
118
+
119
+ #endif // GET_ATTRDEF_CLASSES
120
+
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUDialect.cpp.inc ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Dialect Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AMDGPU.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amdgpu::AMDGPUDialect)
11
+ namespace mlir {
12
+ namespace amdgpu {
13
+
14
+ AMDGPUDialect::AMDGPUDialect(::mlir::MLIRContext *context)
15
+ : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get<AMDGPUDialect>())
16
+
17
+ {
18
+ getContext()->loadDialect<ROCDL::ROCDLDialect>();
19
+ getContext()->loadDialect<arith::ArithDialect>();
20
+ getContext()->loadDialect<gpu::GPUDialect>();
21
+ initialize();
22
+ }
23
+
24
+ AMDGPUDialect::~AMDGPUDialect() = default;
25
+
26
+ } // namespace amdgpu
27
+ } // namespace mlir
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AMDGPUDialect.h - MLIR Dialect for AMDGPU ---------*- 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 file declares a dialect for MLIR wrappers around AMDGPU-specific
10
+ // intrinssics and for other AMD GPU-specific functionality.
11
+ //
12
+ //===----------------------------------------------------------------------===//
13
+
14
+ #ifndef MLIR_DIALECT_AMDGPU_IR_AMDGPUDIALECT_H_
15
+ #define MLIR_DIALECT_AMDGPU_IR_AMDGPUDIALECT_H_
16
+
17
+ #include "mlir/Bytecode/BytecodeOpInterface.h"
18
+ #include "mlir/IR/BuiltinTypes.h"
19
+ #include "mlir/IR/Dialect.h"
20
+ #include "mlir/IR/OpDefinition.h"
21
+ #include "mlir/Interfaces/InferTypeOpInterface.h"
22
+ #include "mlir/Interfaces/SideEffectInterfaces.h"
23
+ #include "mlir/Interfaces/ViewLikeInterface.h"
24
+
25
+ #include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h.inc"
26
+
27
+ #include "mlir/Dialect/AMDGPU/IR/AMDGPUEnums.h.inc"
28
+
29
+ #define GET_ATTRDEF_CLASSES
30
+ #include "mlir/Dialect/AMDGPU/IR/AMDGPUAttributes.h.inc"
31
+
32
+ #define GET_OP_CLASSES
33
+ #include "mlir/Dialect/AMDGPU/IR/AMDGPU.h.inc"
34
+
35
+ #endif // MLIR_DIALECT_AMDGPU_IR_AMDGPUDIALECT_H_
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h.inc ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Dialect Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AMDGPU.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ namespace mlir {
11
+ namespace amdgpu {
12
+
13
+ /// The `AMDGPU` dialect provides wrappers around AMD-specific functionality
14
+ /// and LLVM intrinsics. These wrappers should be used in conjunction with
15
+ /// more generic dialects, such as `gpu` and `vector`, when generating LLVM IR
16
+ /// that will eventually be executed on AMD hardware.
17
+ class AMDGPUDialect : public ::mlir::Dialect {
18
+ explicit AMDGPUDialect(::mlir::MLIRContext *context);
19
+
20
+ void initialize();
21
+ friend class ::mlir::MLIRContext;
22
+ public:
23
+ ~AMDGPUDialect() override;
24
+ static constexpr ::llvm::StringLiteral getDialectNamespace() {
25
+ return ::llvm::StringLiteral("amdgpu");
26
+ }
27
+
28
+ /// Parse an attribute registered to this dialect.
29
+ ::mlir::Attribute parseAttribute(::mlir::DialectAsmParser &parser,
30
+ ::mlir::Type type) const override;
31
+
32
+ /// Print an attribute registered to this dialect.
33
+ void printAttribute(::mlir::Attribute attr,
34
+ ::mlir::DialectAsmPrinter &os) const override;
35
+ };
36
+ } // namespace amdgpu
37
+ } // namespace mlir
38
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amdgpu::AMDGPUDialect)
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUEnums.cpp.inc ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Enum Utility Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AMDGPU.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ namespace mlir {
11
+ namespace amdgpu {
12
+ ::llvm::StringRef stringifyAddressSpace(AddressSpace val) {
13
+ switch (val) {
14
+ case AddressSpace::FatRawBuffer: return "fat_raw_buffer";
15
+ case AddressSpace::BufferRsrc: return "buffer_rsrc";
16
+ case AddressSpace::FatStructuredBuffer: return "fat_structured_buffer";
17
+ }
18
+ return "";
19
+ }
20
+
21
+ ::std::optional<AddressSpace> symbolizeAddressSpace(::llvm::StringRef str) {
22
+ return ::llvm::StringSwitch<::std::optional<AddressSpace>>(str)
23
+ .Case("fat_raw_buffer", AddressSpace::FatRawBuffer)
24
+ .Case("buffer_rsrc", AddressSpace::BufferRsrc)
25
+ .Case("fat_structured_buffer", AddressSpace::FatStructuredBuffer)
26
+ .Default(::std::nullopt);
27
+ }
28
+ ::std::optional<AddressSpace> symbolizeAddressSpace(uint32_t value) {
29
+ switch (value) {
30
+ case 0: return AddressSpace::FatRawBuffer;
31
+ case 1: return AddressSpace::BufferRsrc;
32
+ case 2: return AddressSpace::FatStructuredBuffer;
33
+ default: return ::std::nullopt;
34
+ }
35
+ }
36
+
37
+ } // namespace amdgpu
38
+ } // namespace mlir
39
+
40
+ namespace mlir {
41
+ namespace amdgpu {
42
+ ::llvm::StringRef stringifyDPPPerm(DPPPerm val) {
43
+ switch (val) {
44
+ case DPPPerm::quad_perm: return "quad_perm";
45
+ case DPPPerm::row_shl: return "row_shl";
46
+ case DPPPerm::row_shr: return "row_shr";
47
+ case DPPPerm::row_ror: return "row_ror";
48
+ case DPPPerm::wave_shl: return "wave_shl";
49
+ case DPPPerm::wave_shr: return "wave_shr";
50
+ case DPPPerm::wave_ror: return "wave_ror";
51
+ case DPPPerm::wave_rol: return "wave_rol";
52
+ case DPPPerm::row_mirror: return "row_mirror";
53
+ case DPPPerm::row_half_mirror: return "row_half_mirror";
54
+ case DPPPerm::row_bcast_15: return "row_bcast_15";
55
+ case DPPPerm::row_bcast_31: return "row_bcast_31";
56
+ }
57
+ return "";
58
+ }
59
+
60
+ ::std::optional<DPPPerm> symbolizeDPPPerm(::llvm::StringRef str) {
61
+ return ::llvm::StringSwitch<::std::optional<DPPPerm>>(str)
62
+ .Case("quad_perm", DPPPerm::quad_perm)
63
+ .Case("row_shl", DPPPerm::row_shl)
64
+ .Case("row_shr", DPPPerm::row_shr)
65
+ .Case("row_ror", DPPPerm::row_ror)
66
+ .Case("wave_shl", DPPPerm::wave_shl)
67
+ .Case("wave_shr", DPPPerm::wave_shr)
68
+ .Case("wave_ror", DPPPerm::wave_ror)
69
+ .Case("wave_rol", DPPPerm::wave_rol)
70
+ .Case("row_mirror", DPPPerm::row_mirror)
71
+ .Case("row_half_mirror", DPPPerm::row_half_mirror)
72
+ .Case("row_bcast_15", DPPPerm::row_bcast_15)
73
+ .Case("row_bcast_31", DPPPerm::row_bcast_31)
74
+ .Default(::std::nullopt);
75
+ }
76
+ ::std::optional<DPPPerm> symbolizeDPPPerm(uint32_t value) {
77
+ switch (value) {
78
+ case 0: return DPPPerm::quad_perm;
79
+ case 1: return DPPPerm::row_shl;
80
+ case 2: return DPPPerm::row_shr;
81
+ case 3: return DPPPerm::row_ror;
82
+ case 4: return DPPPerm::wave_shl;
83
+ case 5: return DPPPerm::wave_shr;
84
+ case 6: return DPPPerm::wave_ror;
85
+ case 7: return DPPPerm::wave_rol;
86
+ case 8: return DPPPerm::row_mirror;
87
+ case 9: return DPPPerm::row_half_mirror;
88
+ case 10: return DPPPerm::row_bcast_15;
89
+ case 11: return DPPPerm::row_bcast_31;
90
+ default: return ::std::nullopt;
91
+ }
92
+ }
93
+
94
+ } // namespace amdgpu
95
+ } // namespace mlir
96
+
97
+ namespace mlir {
98
+ namespace amdgpu {
99
+ ::llvm::StringRef stringifyMFMAPermB(MFMAPermB val) {
100
+ switch (val) {
101
+ case MFMAPermB::none: return "none";
102
+ case MFMAPermB::bcast_first_32: return "bcast_first_32";
103
+ case MFMAPermB::bcast_second_32: return "bcast_second_32";
104
+ case MFMAPermB::rotate_16_right: return "rotate_16_right";
105
+ case MFMAPermB::bcast_first_16: return "bcast_first_16";
106
+ case MFMAPermB::bcast_second_16: return "bcast_second_16";
107
+ case MFMAPermB::bcast_third_16: return "bcast_third_16";
108
+ case MFMAPermB::bcast_fourth_16: return "bcast_fourth_16";
109
+ }
110
+ return "";
111
+ }
112
+
113
+ ::std::optional<MFMAPermB> symbolizeMFMAPermB(::llvm::StringRef str) {
114
+ return ::llvm::StringSwitch<::std::optional<MFMAPermB>>(str)
115
+ .Case("none", MFMAPermB::none)
116
+ .Case("bcast_first_32", MFMAPermB::bcast_first_32)
117
+ .Case("bcast_second_32", MFMAPermB::bcast_second_32)
118
+ .Case("rotate_16_right", MFMAPermB::rotate_16_right)
119
+ .Case("bcast_first_16", MFMAPermB::bcast_first_16)
120
+ .Case("bcast_second_16", MFMAPermB::bcast_second_16)
121
+ .Case("bcast_third_16", MFMAPermB::bcast_third_16)
122
+ .Case("bcast_fourth_16", MFMAPermB::bcast_fourth_16)
123
+ .Default(::std::nullopt);
124
+ }
125
+ ::std::optional<MFMAPermB> symbolizeMFMAPermB(uint32_t value) {
126
+ switch (value) {
127
+ case 0: return MFMAPermB::none;
128
+ case 1: return MFMAPermB::bcast_first_32;
129
+ case 2: return MFMAPermB::bcast_second_32;
130
+ case 3: return MFMAPermB::rotate_16_right;
131
+ case 4: return MFMAPermB::bcast_first_16;
132
+ case 5: return MFMAPermB::bcast_second_16;
133
+ case 6: return MFMAPermB::bcast_third_16;
134
+ case 7: return MFMAPermB::bcast_fourth_16;
135
+ default: return ::std::nullopt;
136
+ }
137
+ }
138
+
139
+ } // namespace amdgpu
140
+ } // namespace mlir
141
+
142
+ namespace mlir {
143
+ namespace amdgpu {
144
+ std::string stringifysched_barrier_opt_enum(sched_barrier_opt_enum symbol) {
145
+ auto val = static_cast<uint32_t>(symbol);
146
+ assert(2047u == (2047u | val) && "invalid bits set in bit enum");
147
+ // Special case for all bits unset.
148
+ if (val == 0) return "none";
149
+
150
+ ::llvm::SmallVector<::llvm::StringRef, 2> strs;
151
+
152
+ if (1u == (1u & val))
153
+ strs.push_back("non_mem_non_sideffect");
154
+
155
+ if (2u == (2u & val))
156
+ strs.push_back("valu");
157
+
158
+ if (4u == (4u & val))
159
+ strs.push_back("salu");
160
+
161
+ if (8u == (8u & val))
162
+ strs.push_back("mfma_wmma");
163
+
164
+ if (16u == (16u & val))
165
+ strs.push_back("all_vmem");
166
+
167
+ if (32u == (32u & val))
168
+ strs.push_back("vmem_read");
169
+
170
+ if (64u == (64u & val))
171
+ strs.push_back("vmem_write");
172
+
173
+ if (128u == (128u & val))
174
+ strs.push_back("all_ds");
175
+
176
+ if (256u == (256u & val))
177
+ strs.push_back("ds_read");
178
+
179
+ if (512u == (512u & val))
180
+ strs.push_back("ds_write");
181
+
182
+ if (1024u == (1024u & val))
183
+ strs.push_back("transcendental");
184
+ return ::llvm::join(strs, "|");
185
+ }
186
+
187
+ ::std::optional<sched_barrier_opt_enum> symbolizesched_barrier_opt_enum(::llvm::StringRef str) {
188
+ // Special case for all bits unset.
189
+ if (str == "none") return sched_barrier_opt_enum::none;
190
+
191
+ ::llvm::SmallVector<::llvm::StringRef, 2> symbols;
192
+ str.split(symbols, "|");
193
+
194
+ uint32_t val = 0;
195
+ for (auto symbol : symbols) {
196
+ auto bit = llvm::StringSwitch<::std::optional<uint32_t>>(symbol.trim())
197
+ .Case("non_mem_non_sideffect", 1)
198
+ .Case("valu", 2)
199
+ .Case("salu", 4)
200
+ .Case("mfma_wmma", 8)
201
+ .Case("all_vmem", 16)
202
+ .Case("vmem_read", 32)
203
+ .Case("vmem_write", 64)
204
+ .Case("all_ds", 128)
205
+ .Case("ds_read", 256)
206
+ .Case("ds_write", 512)
207
+ .Case("transcendental", 1024)
208
+ .Default(::std::nullopt);
209
+ if (bit) { val |= *bit; } else { return ::std::nullopt; }
210
+ }
211
+ return static_cast<sched_barrier_opt_enum>(val);
212
+ }
213
+
214
+ ::std::optional<sched_barrier_opt_enum> symbolizesched_barrier_opt_enum(uint32_t value) {
215
+ // Special case for all bits unset.
216
+ if (value == 0) return sched_barrier_opt_enum::none;
217
+
218
+ if (value & ~static_cast<uint32_t>(2047u)) return std::nullopt;
219
+ return static_cast<sched_barrier_opt_enum>(value);
220
+ }
221
+ } // namespace amdgpu
222
+ } // namespace mlir
223
+
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/IR/AMDGPUEnums.h.inc ADDED
@@ -0,0 +1,469 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Enum Utility Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AMDGPU.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ namespace mlir {
11
+ namespace amdgpu {
12
+ // AMDGPU-specific address spaces
13
+ enum class AddressSpace : uint32_t {
14
+ FatRawBuffer = 0,
15
+ BufferRsrc = 1,
16
+ FatStructuredBuffer = 2,
17
+ };
18
+
19
+ ::std::optional<AddressSpace> symbolizeAddressSpace(uint32_t);
20
+ ::llvm::StringRef stringifyAddressSpace(AddressSpace);
21
+ ::std::optional<AddressSpace> symbolizeAddressSpace(::llvm::StringRef);
22
+ inline constexpr unsigned getMaxEnumValForAddressSpace() {
23
+ return 2;
24
+ }
25
+
26
+
27
+ inline ::llvm::StringRef stringifyEnum(AddressSpace enumValue) {
28
+ return stringifyAddressSpace(enumValue);
29
+ }
30
+
31
+ template <typename EnumType>
32
+ ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef);
33
+
34
+ template <>
35
+ inline ::std::optional<AddressSpace> symbolizeEnum<AddressSpace>(::llvm::StringRef str) {
36
+ return symbolizeAddressSpace(str);
37
+ }
38
+ } // namespace amdgpu
39
+ } // namespace mlir
40
+
41
+ namespace mlir {
42
+ template <typename T, typename>
43
+ struct FieldParser;
44
+
45
+ template<>
46
+ struct FieldParser<::mlir::amdgpu::AddressSpace, ::mlir::amdgpu::AddressSpace> {
47
+ template <typename ParserT>
48
+ static FailureOr<::mlir::amdgpu::AddressSpace> parse(ParserT &parser) {
49
+ // Parse the keyword/string containing the enum.
50
+ std::string enumKeyword;
51
+ auto loc = parser.getCurrentLocation();
52
+ if (failed(parser.parseOptionalKeywordOrString(&enumKeyword)))
53
+ return parser.emitError(loc, "expected keyword for AMDGPU-specific address spaces");
54
+
55
+ // Symbolize the keyword.
56
+ if (::std::optional<::mlir::amdgpu::AddressSpace> attr = ::mlir::amdgpu::symbolizeEnum<::mlir::amdgpu::AddressSpace>(enumKeyword))
57
+ return *attr;
58
+ return parser.emitError(loc, "expected one of [fat_raw_buffer, buffer_rsrc, fat_structured_buffer] for AMDGPU-specific address spaces, got: ") << enumKeyword;
59
+ }
60
+ };
61
+
62
+ /// Support for std::optional, useful in attribute/type definition where the enum is
63
+ /// used as:
64
+ ///
65
+ /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value);
66
+ template<>
67
+ struct FieldParser<std::optional<::mlir::amdgpu::AddressSpace>, std::optional<::mlir::amdgpu::AddressSpace>> {
68
+ template <typename ParserT>
69
+ static FailureOr<std::optional<::mlir::amdgpu::AddressSpace>> parse(ParserT &parser) {
70
+ // Parse the keyword/string containing the enum.
71
+ std::string enumKeyword;
72
+ auto loc = parser.getCurrentLocation();
73
+ if (failed(parser.parseOptionalKeywordOrString(&enumKeyword)))
74
+ return std::optional<::mlir::amdgpu::AddressSpace>{};
75
+
76
+ // Symbolize the keyword.
77
+ if (::std::optional<::mlir::amdgpu::AddressSpace> attr = ::mlir::amdgpu::symbolizeEnum<::mlir::amdgpu::AddressSpace>(enumKeyword))
78
+ return attr;
79
+ return parser.emitError(loc, "expected one of [fat_raw_buffer, buffer_rsrc, fat_structured_buffer] for AMDGPU-specific address spaces, got: ") << enumKeyword;
80
+ }
81
+ };
82
+ } // namespace mlir
83
+
84
+ namespace llvm {
85
+ inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, ::mlir::amdgpu::AddressSpace value) {
86
+ auto valueStr = stringifyEnum(value);
87
+ return p << valueStr;
88
+ }
89
+ } // namespace llvm
90
+
91
+ namespace llvm {
92
+ template<> struct DenseMapInfo<::mlir::amdgpu::AddressSpace> {
93
+ using StorageInfo = ::llvm::DenseMapInfo<uint32_t>;
94
+
95
+ static inline ::mlir::amdgpu::AddressSpace getEmptyKey() {
96
+ return static_cast<::mlir::amdgpu::AddressSpace>(StorageInfo::getEmptyKey());
97
+ }
98
+
99
+ static inline ::mlir::amdgpu::AddressSpace getTombstoneKey() {
100
+ return static_cast<::mlir::amdgpu::AddressSpace>(StorageInfo::getTombstoneKey());
101
+ }
102
+
103
+ static unsigned getHashValue(const ::mlir::amdgpu::AddressSpace &val) {
104
+ return StorageInfo::getHashValue(static_cast<uint32_t>(val));
105
+ }
106
+
107
+ static bool isEqual(const ::mlir::amdgpu::AddressSpace &lhs, const ::mlir::amdgpu::AddressSpace &rhs) {
108
+ return lhs == rhs;
109
+ }
110
+ };
111
+ }
112
+
113
+ namespace mlir {
114
+ namespace amdgpu {
115
+ // The possible permutations for a DPP operation
116
+ enum class DPPPerm : uint32_t {
117
+ quad_perm = 0,
118
+ row_shl = 1,
119
+ row_shr = 2,
120
+ row_ror = 3,
121
+ wave_shl = 4,
122
+ wave_shr = 5,
123
+ wave_ror = 6,
124
+ wave_rol = 7,
125
+ row_mirror = 8,
126
+ row_half_mirror = 9,
127
+ row_bcast_15 = 10,
128
+ row_bcast_31 = 11,
129
+ };
130
+
131
+ ::std::optional<DPPPerm> symbolizeDPPPerm(uint32_t);
132
+ ::llvm::StringRef stringifyDPPPerm(DPPPerm);
133
+ ::std::optional<DPPPerm> symbolizeDPPPerm(::llvm::StringRef);
134
+ inline constexpr unsigned getMaxEnumValForDPPPerm() {
135
+ return 11;
136
+ }
137
+
138
+
139
+ inline ::llvm::StringRef stringifyEnum(DPPPerm enumValue) {
140
+ return stringifyDPPPerm(enumValue);
141
+ }
142
+
143
+ template <typename EnumType>
144
+ ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef);
145
+
146
+ template <>
147
+ inline ::std::optional<DPPPerm> symbolizeEnum<DPPPerm>(::llvm::StringRef str) {
148
+ return symbolizeDPPPerm(str);
149
+ }
150
+ } // namespace amdgpu
151
+ } // namespace mlir
152
+
153
+ namespace mlir {
154
+ template <typename T, typename>
155
+ struct FieldParser;
156
+
157
+ template<>
158
+ struct FieldParser<::mlir::amdgpu::DPPPerm, ::mlir::amdgpu::DPPPerm> {
159
+ template <typename ParserT>
160
+ static FailureOr<::mlir::amdgpu::DPPPerm> parse(ParserT &parser) {
161
+ // Parse the keyword/string containing the enum.
162
+ std::string enumKeyword;
163
+ auto loc = parser.getCurrentLocation();
164
+ if (failed(parser.parseOptionalKeywordOrString(&enumKeyword)))
165
+ return parser.emitError(loc, "expected keyword for The possible permutations for a DPP operation");
166
+
167
+ // Symbolize the keyword.
168
+ if (::std::optional<::mlir::amdgpu::DPPPerm> attr = ::mlir::amdgpu::symbolizeEnum<::mlir::amdgpu::DPPPerm>(enumKeyword))
169
+ return *attr;
170
+ return parser.emitError(loc, "expected one of [quad_perm, row_shl, row_shr, row_ror, wave_shl, wave_shr, wave_ror, wave_rol, row_mirror, row_half_mirror, row_bcast_15, row_bcast_31] for The possible permutations for a DPP operation, got: ") << enumKeyword;
171
+ }
172
+ };
173
+
174
+ /// Support for std::optional, useful in attribute/type definition where the enum is
175
+ /// used as:
176
+ ///
177
+ /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value);
178
+ template<>
179
+ struct FieldParser<std::optional<::mlir::amdgpu::DPPPerm>, std::optional<::mlir::amdgpu::DPPPerm>> {
180
+ template <typename ParserT>
181
+ static FailureOr<std::optional<::mlir::amdgpu::DPPPerm>> parse(ParserT &parser) {
182
+ // Parse the keyword/string containing the enum.
183
+ std::string enumKeyword;
184
+ auto loc = parser.getCurrentLocation();
185
+ if (failed(parser.parseOptionalKeywordOrString(&enumKeyword)))
186
+ return std::optional<::mlir::amdgpu::DPPPerm>{};
187
+
188
+ // Symbolize the keyword.
189
+ if (::std::optional<::mlir::amdgpu::DPPPerm> attr = ::mlir::amdgpu::symbolizeEnum<::mlir::amdgpu::DPPPerm>(enumKeyword))
190
+ return attr;
191
+ return parser.emitError(loc, "expected one of [quad_perm, row_shl, row_shr, row_ror, wave_shl, wave_shr, wave_ror, wave_rol, row_mirror, row_half_mirror, row_bcast_15, row_bcast_31] for The possible permutations for a DPP operation, got: ") << enumKeyword;
192
+ }
193
+ };
194
+ } // namespace mlir
195
+
196
+ namespace llvm {
197
+ inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, ::mlir::amdgpu::DPPPerm value) {
198
+ auto valueStr = stringifyEnum(value);
199
+ return p << valueStr;
200
+ }
201
+ } // namespace llvm
202
+
203
+ namespace llvm {
204
+ template<> struct DenseMapInfo<::mlir::amdgpu::DPPPerm> {
205
+ using StorageInfo = ::llvm::DenseMapInfo<uint32_t>;
206
+
207
+ static inline ::mlir::amdgpu::DPPPerm getEmptyKey() {
208
+ return static_cast<::mlir::amdgpu::DPPPerm>(StorageInfo::getEmptyKey());
209
+ }
210
+
211
+ static inline ::mlir::amdgpu::DPPPerm getTombstoneKey() {
212
+ return static_cast<::mlir::amdgpu::DPPPerm>(StorageInfo::getTombstoneKey());
213
+ }
214
+
215
+ static unsigned getHashValue(const ::mlir::amdgpu::DPPPerm &val) {
216
+ return StorageInfo::getHashValue(static_cast<uint32_t>(val));
217
+ }
218
+
219
+ static bool isEqual(const ::mlir::amdgpu::DPPPerm &lhs, const ::mlir::amdgpu::DPPPerm &rhs) {
220
+ return lhs == rhs;
221
+ }
222
+ };
223
+ }
224
+
225
+ namespace mlir {
226
+ namespace amdgpu {
227
+ // The possible permutations of the lanes storing B available in an MFMA
228
+ enum class MFMAPermB : uint32_t {
229
+ none = 0,
230
+ bcast_first_32 = 1,
231
+ bcast_second_32 = 2,
232
+ rotate_16_right = 3,
233
+ bcast_first_16 = 4,
234
+ bcast_second_16 = 5,
235
+ bcast_third_16 = 6,
236
+ bcast_fourth_16 = 7,
237
+ };
238
+
239
+ ::std::optional<MFMAPermB> symbolizeMFMAPermB(uint32_t);
240
+ ::llvm::StringRef stringifyMFMAPermB(MFMAPermB);
241
+ ::std::optional<MFMAPermB> symbolizeMFMAPermB(::llvm::StringRef);
242
+ inline constexpr unsigned getMaxEnumValForMFMAPermB() {
243
+ return 7;
244
+ }
245
+
246
+
247
+ inline ::llvm::StringRef stringifyEnum(MFMAPermB enumValue) {
248
+ return stringifyMFMAPermB(enumValue);
249
+ }
250
+
251
+ template <typename EnumType>
252
+ ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef);
253
+
254
+ template <>
255
+ inline ::std::optional<MFMAPermB> symbolizeEnum<MFMAPermB>(::llvm::StringRef str) {
256
+ return symbolizeMFMAPermB(str);
257
+ }
258
+ } // namespace amdgpu
259
+ } // namespace mlir
260
+
261
+ namespace mlir {
262
+ template <typename T, typename>
263
+ struct FieldParser;
264
+
265
+ template<>
266
+ struct FieldParser<::mlir::amdgpu::MFMAPermB, ::mlir::amdgpu::MFMAPermB> {
267
+ template <typename ParserT>
268
+ static FailureOr<::mlir::amdgpu::MFMAPermB> parse(ParserT &parser) {
269
+ // Parse the keyword/string containing the enum.
270
+ std::string enumKeyword;
271
+ auto loc = parser.getCurrentLocation();
272
+ if (failed(parser.parseOptionalKeywordOrString(&enumKeyword)))
273
+ return parser.emitError(loc, "expected keyword for The possible permutations of the lanes storing B available in an MFMA");
274
+
275
+ // Symbolize the keyword.
276
+ if (::std::optional<::mlir::amdgpu::MFMAPermB> attr = ::mlir::amdgpu::symbolizeEnum<::mlir::amdgpu::MFMAPermB>(enumKeyword))
277
+ return *attr;
278
+ return parser.emitError(loc, "expected one of [none, bcast_first_32, bcast_second_32, rotate_16_right, bcast_first_16, bcast_second_16, bcast_third_16, bcast_fourth_16] for The possible permutations of the lanes storing B available in an MFMA, got: ") << enumKeyword;
279
+ }
280
+ };
281
+
282
+ /// Support for std::optional, useful in attribute/type definition where the enum is
283
+ /// used as:
284
+ ///
285
+ /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value);
286
+ template<>
287
+ struct FieldParser<std::optional<::mlir::amdgpu::MFMAPermB>, std::optional<::mlir::amdgpu::MFMAPermB>> {
288
+ template <typename ParserT>
289
+ static FailureOr<std::optional<::mlir::amdgpu::MFMAPermB>> parse(ParserT &parser) {
290
+ // Parse the keyword/string containing the enum.
291
+ std::string enumKeyword;
292
+ auto loc = parser.getCurrentLocation();
293
+ if (failed(parser.parseOptionalKeywordOrString(&enumKeyword)))
294
+ return std::optional<::mlir::amdgpu::MFMAPermB>{};
295
+
296
+ // Symbolize the keyword.
297
+ if (::std::optional<::mlir::amdgpu::MFMAPermB> attr = ::mlir::amdgpu::symbolizeEnum<::mlir::amdgpu::MFMAPermB>(enumKeyword))
298
+ return attr;
299
+ return parser.emitError(loc, "expected one of [none, bcast_first_32, bcast_second_32, rotate_16_right, bcast_first_16, bcast_second_16, bcast_third_16, bcast_fourth_16] for The possible permutations of the lanes storing B available in an MFMA, got: ") << enumKeyword;
300
+ }
301
+ };
302
+ } // namespace mlir
303
+
304
+ namespace llvm {
305
+ inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, ::mlir::amdgpu::MFMAPermB value) {
306
+ auto valueStr = stringifyEnum(value);
307
+ return p << valueStr;
308
+ }
309
+ } // namespace llvm
310
+
311
+ namespace llvm {
312
+ template<> struct DenseMapInfo<::mlir::amdgpu::MFMAPermB> {
313
+ using StorageInfo = ::llvm::DenseMapInfo<uint32_t>;
314
+
315
+ static inline ::mlir::amdgpu::MFMAPermB getEmptyKey() {
316
+ return static_cast<::mlir::amdgpu::MFMAPermB>(StorageInfo::getEmptyKey());
317
+ }
318
+
319
+ static inline ::mlir::amdgpu::MFMAPermB getTombstoneKey() {
320
+ return static_cast<::mlir::amdgpu::MFMAPermB>(StorageInfo::getTombstoneKey());
321
+ }
322
+
323
+ static unsigned getHashValue(const ::mlir::amdgpu::MFMAPermB &val) {
324
+ return StorageInfo::getHashValue(static_cast<uint32_t>(val));
325
+ }
326
+
327
+ static bool isEqual(const ::mlir::amdgpu::MFMAPermB &lhs, const ::mlir::amdgpu::MFMAPermB &rhs) {
328
+ return lhs == rhs;
329
+ }
330
+ };
331
+ }
332
+
333
+ namespace mlir {
334
+ namespace amdgpu {
335
+ // The possible options for scheduling barriers
336
+ enum class sched_barrier_opt_enum : uint32_t {
337
+ none = 0,
338
+ non_mem_non_sideffect = 1,
339
+ valu = 2,
340
+ salu = 4,
341
+ mfma_wmma = 8,
342
+ all_vmem = 16,
343
+ vmem_read = 32,
344
+ vmem_write = 64,
345
+ all_ds = 128,
346
+ ds_read = 256,
347
+ ds_write = 512,
348
+ transcendental = 1024,
349
+ };
350
+
351
+ ::std::optional<sched_barrier_opt_enum> symbolizesched_barrier_opt_enum(uint32_t);
352
+ std::string stringifysched_barrier_opt_enum(sched_barrier_opt_enum);
353
+ ::std::optional<sched_barrier_opt_enum> symbolizesched_barrier_opt_enum(::llvm::StringRef);
354
+
355
+ inline constexpr sched_barrier_opt_enum operator|(sched_barrier_opt_enum a, sched_barrier_opt_enum b) {
356
+ return static_cast<sched_barrier_opt_enum>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
357
+ }
358
+ inline constexpr sched_barrier_opt_enum operator&(sched_barrier_opt_enum a, sched_barrier_opt_enum b) {
359
+ return static_cast<sched_barrier_opt_enum>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
360
+ }
361
+ inline constexpr sched_barrier_opt_enum operator^(sched_barrier_opt_enum a, sched_barrier_opt_enum b) {
362
+ return static_cast<sched_barrier_opt_enum>(static_cast<uint32_t>(a) ^ static_cast<uint32_t>(b));
363
+ }
364
+ inline constexpr sched_barrier_opt_enum operator~(sched_barrier_opt_enum bits) {
365
+ // Ensure only bits that can be present in the enum are set
366
+ return static_cast<sched_barrier_opt_enum>(~static_cast<uint32_t>(bits) & static_cast<uint32_t>(2047u));
367
+ }
368
+ inline constexpr bool bitEnumContainsAll(sched_barrier_opt_enum bits, sched_barrier_opt_enum bit) {
369
+ return (bits & bit) == bit;
370
+ }
371
+ inline constexpr bool bitEnumContainsAny(sched_barrier_opt_enum bits, sched_barrier_opt_enum bit) {
372
+ return (static_cast<uint32_t>(bits) & static_cast<uint32_t>(bit)) != 0;
373
+ }
374
+ inline constexpr sched_barrier_opt_enum bitEnumClear(sched_barrier_opt_enum bits, sched_barrier_opt_enum bit) {
375
+ return bits & ~bit;
376
+ }
377
+ inline constexpr sched_barrier_opt_enum bitEnumSet(sched_barrier_opt_enum bits, sched_barrier_opt_enum bit, /*optional*/bool value=true) {
378
+ return value ? (bits | bit) : bitEnumClear(bits, bit);
379
+ }
380
+
381
+ inline std::string stringifyEnum(sched_barrier_opt_enum enumValue) {
382
+ return stringifysched_barrier_opt_enum(enumValue);
383
+ }
384
+
385
+ template <typename EnumType>
386
+ ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef);
387
+
388
+ template <>
389
+ inline ::std::optional<sched_barrier_opt_enum> symbolizeEnum<sched_barrier_opt_enum>(::llvm::StringRef str) {
390
+ return symbolizesched_barrier_opt_enum(str);
391
+ }
392
+ } // namespace amdgpu
393
+ } // namespace mlir
394
+
395
+ namespace mlir {
396
+ template <typename T, typename>
397
+ struct FieldParser;
398
+
399
+ template<>
400
+ struct FieldParser<::mlir::amdgpu::sched_barrier_opt_enum, ::mlir::amdgpu::sched_barrier_opt_enum> {
401
+ template <typename ParserT>
402
+ static FailureOr<::mlir::amdgpu::sched_barrier_opt_enum> parse(ParserT &parser) {
403
+ // Parse the keyword/string containing the enum.
404
+ std::string enumKeyword;
405
+ auto loc = parser.getCurrentLocation();
406
+ if (failed(parser.parseOptionalKeywordOrString(&enumKeyword)))
407
+ return parser.emitError(loc, "expected keyword for The possible options for scheduling barriers");
408
+
409
+ // Symbolize the keyword.
410
+ if (::std::optional<::mlir::amdgpu::sched_barrier_opt_enum> attr = ::mlir::amdgpu::symbolizeEnum<::mlir::amdgpu::sched_barrier_opt_enum>(enumKeyword))
411
+ return *attr;
412
+ return parser.emitError(loc, "expected one of [none, non_mem_non_sideffect, valu, salu, mfma_wmma, all_vmem, vmem_read, vmem_write, all_ds, ds_read, ds_write, transcendental] for The possible options for scheduling barriers, got: ") << enumKeyword;
413
+ }
414
+ };
415
+
416
+ /// Support for std::optional, useful in attribute/type definition where the enum is
417
+ /// used as:
418
+ ///
419
+ /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value);
420
+ template<>
421
+ struct FieldParser<std::optional<::mlir::amdgpu::sched_barrier_opt_enum>, std::optional<::mlir::amdgpu::sched_barrier_opt_enum>> {
422
+ template <typename ParserT>
423
+ static FailureOr<std::optional<::mlir::amdgpu::sched_barrier_opt_enum>> parse(ParserT &parser) {
424
+ // Parse the keyword/string containing the enum.
425
+ std::string enumKeyword;
426
+ auto loc = parser.getCurrentLocation();
427
+ if (failed(parser.parseOptionalKeywordOrString(&enumKeyword)))
428
+ return std::optional<::mlir::amdgpu::sched_barrier_opt_enum>{};
429
+
430
+ // Symbolize the keyword.
431
+ if (::std::optional<::mlir::amdgpu::sched_barrier_opt_enum> attr = ::mlir::amdgpu::symbolizeEnum<::mlir::amdgpu::sched_barrier_opt_enum>(enumKeyword))
432
+ return attr;
433
+ return parser.emitError(loc, "expected one of [none, non_mem_non_sideffect, valu, salu, mfma_wmma, all_vmem, vmem_read, vmem_write, all_ds, ds_read, ds_write, transcendental] for The possible options for scheduling barriers, got: ") << enumKeyword;
434
+ }
435
+ };
436
+ } // namespace mlir
437
+
438
+ namespace llvm {
439
+ inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, ::mlir::amdgpu::sched_barrier_opt_enum value) {
440
+ auto valueStr = stringifyEnum(value);
441
+ auto underlyingValue = static_cast<std::make_unsigned_t<::mlir::amdgpu::sched_barrier_opt_enum>>(value);
442
+ if (underlyingValue && !llvm::has_single_bit(underlyingValue))
443
+ return p << '"' << valueStr << '"';
444
+ return p << valueStr;
445
+ }
446
+ } // namespace llvm
447
+
448
+ namespace llvm {
449
+ template<> struct DenseMapInfo<::mlir::amdgpu::sched_barrier_opt_enum> {
450
+ using StorageInfo = ::llvm::DenseMapInfo<uint32_t>;
451
+
452
+ static inline ::mlir::amdgpu::sched_barrier_opt_enum getEmptyKey() {
453
+ return static_cast<::mlir::amdgpu::sched_barrier_opt_enum>(StorageInfo::getEmptyKey());
454
+ }
455
+
456
+ static inline ::mlir::amdgpu::sched_barrier_opt_enum getTombstoneKey() {
457
+ return static_cast<::mlir::amdgpu::sched_barrier_opt_enum>(StorageInfo::getTombstoneKey());
458
+ }
459
+
460
+ static unsigned getHashValue(const ::mlir::amdgpu::sched_barrier_opt_enum &val) {
461
+ return StorageInfo::getHashValue(static_cast<uint32_t>(val));
462
+ }
463
+
464
+ static bool isEqual(const ::mlir::amdgpu::sched_barrier_opt_enum &lhs, const ::mlir::amdgpu::sched_barrier_opt_enum &rhs) {
465
+ return lhs == rhs;
466
+ }
467
+ };
468
+ }
469
+
deps/exla/cache/xla_extension/include/mlir/Dialect/AMDGPU/Utils/Chipset.h ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- Chipset.h - AMDGPU Chipset version struct ----------*- 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
+ #ifndef MLIR_DIALECT_AMDGPU_UTILS_CHIPSET_H_
9
+ #define MLIR_DIALECT_AMDGPU_UTILS_CHIPSET_H_
10
+
11
+ #include "mlir/Support/LLVM.h"
12
+ #include <tuple>
13
+
14
+ namespace mlir::amdgpu {
15
+
16
+ /// Represents the amdgpu gfx chipset version, e.g., gfx90a, gfx942, gfx1103.
17
+ /// Note that the leading digits form a decimal number, while the last two
18
+ /// digits for a hexadecimal number. For example:
19
+ /// gfx942 --> major = 9, minor = 0x4, stepping = 0x2
20
+ /// gfx90a --> major = 9, minor = 0x0, stepping = 0xa
21
+ /// gfx1103 --> major = 10, minor = 0x0, stepping = 0x3
22
+ struct Chipset {
23
+ unsigned majorVersion = 0; // The major version (decimal).
24
+ unsigned minorVersion = 0; // The minor version (hexadecimal).
25
+ unsigned steppingVersion = 0; // The stepping version (hexadecimal).
26
+
27
+ constexpr Chipset() = default;
28
+ constexpr Chipset(unsigned major, unsigned minor, unsigned stepping)
29
+ : majorVersion(major), minorVersion(minor), steppingVersion(stepping) {};
30
+
31
+ /// Parses the chipset version string and returns the chipset on success, and
32
+ /// failure otherwise.
33
+ static FailureOr<Chipset> parse(StringRef name);
34
+
35
+ std::tuple<unsigned, unsigned, unsigned> asTuple() const {
36
+ return {majorVersion, minorVersion, steppingVersion};
37
+ }
38
+
39
+ #define DEFINE_COMP_OPERATOR(OPERATOR) \
40
+ friend bool operator OPERATOR(const Chipset &lhs, const Chipset &rhs) { \
41
+ return lhs.asTuple() OPERATOR rhs.asTuple(); \
42
+ }
43
+ DEFINE_COMP_OPERATOR(==)
44
+ DEFINE_COMP_OPERATOR(!=)
45
+ DEFINE_COMP_OPERATOR(<)
46
+ DEFINE_COMP_OPERATOR(<=)
47
+ DEFINE_COMP_OPERATOR(>)
48
+ DEFINE_COMP_OPERATOR(>=)
49
+ #undef DEFINE_COMP_OPERATOR
50
+ };
51
+
52
+ inline bool hasOcpFp8(const Chipset &chipset) {
53
+ return (chipset.majorVersion == 9 && chipset.minorVersion >= 5) ||
54
+ chipset.majorVersion >= 12;
55
+ }
56
+
57
+ } // namespace mlir::amdgpu
58
+
59
+ #endif
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMX.cpp.inc ADDED
@@ -0,0 +1,1447 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Op Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AMX.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ #ifdef GET_OP_LIST
11
+ #undef GET_OP_LIST
12
+
13
+ ::mlir::amx::TileLoadOp,
14
+ ::mlir::amx::TileMulFOp,
15
+ ::mlir::amx::TileMulIOp,
16
+ ::mlir::amx::TileStoreOp,
17
+ ::mlir::amx::TileZeroOp
18
+ #endif // GET_OP_LIST
19
+
20
+ #ifdef GET_OP_CLASSES
21
+ #undef GET_OP_CLASSES
22
+
23
+
24
+ //===----------------------------------------------------------------------===//
25
+ // Local Utility Method Definitions
26
+ //===----------------------------------------------------------------------===//
27
+
28
+ namespace mlir {
29
+ namespace amx {
30
+
31
+ static ::llvm::LogicalResult __mlir_ods_local_type_constraint_AMX1(
32
+ ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
33
+ unsigned valueIndex) {
34
+ if (!(((::llvm::isa<::mlir::MemRefType>(type))) && ([](::mlir::Type elementType) { return (true); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) {
35
+ return op->emitOpError(valueKind) << " #" << valueIndex
36
+ << " must be memref of any type values, but got " << type;
37
+ }
38
+ return ::mlir::success();
39
+ }
40
+
41
+ static ::llvm::LogicalResult __mlir_ods_local_type_constraint_AMX2(
42
+ ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
43
+ unsigned valueIndex) {
44
+ if (!((::llvm::isa<::mlir::IndexType>(type)))) {
45
+ return op->emitOpError(valueKind) << " #" << valueIndex
46
+ << " must be variadic of index, but got " << type;
47
+ }
48
+ return ::mlir::success();
49
+ }
50
+
51
+ static ::llvm::LogicalResult __mlir_ods_local_type_constraint_AMX3(
52
+ ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
53
+ unsigned valueIndex) {
54
+ if (!((((::llvm::isa<::mlir::amx::TileType>(type))) && ((::llvm::cast<::mlir::amx::TileType>(type).getRank() == 2))) && ([](::mlir::Type elementType) { return ((elementType.isF32())) || ((elementType.isF16())) || ((::llvm::isa<::mlir::BFloat16Type>(elementType))) || ((elementType.isSignlessInteger(32))) || ((elementType.isSignlessInteger(8))); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) {
55
+ return op->emitOpError(valueKind) << " #" << valueIndex
56
+ << " must be tile of 32-bit float or 16-bit float or bfloat16 type or 32-bit signless integer or 8-bit signless integer values, but got " << type;
57
+ }
58
+ return ::mlir::success();
59
+ }
60
+
61
+ static ::llvm::LogicalResult __mlir_ods_local_type_constraint_AMX4(
62
+ ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
63
+ unsigned valueIndex) {
64
+ if (!((((::llvm::isa<::mlir::amx::TileType>(type))) && ((::llvm::cast<::mlir::amx::TileType>(type).getRank() == 2))) && ([](::mlir::Type elementType) { return ((elementType.isF16())) || ((::llvm::isa<::mlir::BFloat16Type>(elementType))); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) {
65
+ return op->emitOpError(valueKind) << " #" << valueIndex
66
+ << " must be tile of 16-bit float or bfloat16 type values, but got " << type;
67
+ }
68
+ return ::mlir::success();
69
+ }
70
+
71
+ static ::llvm::LogicalResult __mlir_ods_local_type_constraint_AMX5(
72
+ ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
73
+ unsigned valueIndex) {
74
+ if (!((((::llvm::isa<::mlir::amx::TileType>(type))) && ((::llvm::cast<::mlir::amx::TileType>(type).getRank() == 2))) && ([](::mlir::Type elementType) { return (elementType.isF32()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) {
75
+ return op->emitOpError(valueKind) << " #" << valueIndex
76
+ << " must be tile of 32-bit float values, but got " << type;
77
+ }
78
+ return ::mlir::success();
79
+ }
80
+
81
+ static ::llvm::LogicalResult __mlir_ods_local_type_constraint_AMX6(
82
+ ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
83
+ unsigned valueIndex) {
84
+ if (!((((::llvm::isa<::mlir::amx::TileType>(type))) && ((::llvm::cast<::mlir::amx::TileType>(type).getRank() == 2))) && ([](::mlir::Type elementType) { return (elementType.isSignlessInteger(8)); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) {
85
+ return op->emitOpError(valueKind) << " #" << valueIndex
86
+ << " must be tile of 8-bit signless integer values, but got " << type;
87
+ }
88
+ return ::mlir::success();
89
+ }
90
+
91
+ static ::llvm::LogicalResult __mlir_ods_local_type_constraint_AMX7(
92
+ ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind,
93
+ unsigned valueIndex) {
94
+ if (!((((::llvm::isa<::mlir::amx::TileType>(type))) && ((::llvm::cast<::mlir::amx::TileType>(type).getRank() == 2))) && ([](::mlir::Type elementType) { return (elementType.isSignlessInteger(32)); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) {
95
+ return op->emitOpError(valueKind) << " #" << valueIndex
96
+ << " must be tile of 32-bit signless integer values, but got " << type;
97
+ }
98
+ return ::mlir::success();
99
+ }
100
+
101
+ static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_AMX1(
102
+ ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
103
+ if (attr && !((::llvm::isa<::mlir::UnitAttr>(attr))))
104
+ return emitError() << "attribute '" << attrName
105
+ << "' failed to satisfy constraint: unit attribute";
106
+ return ::mlir::success();
107
+ }
108
+ static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_AMX1(
109
+ ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) {
110
+ return __mlir_ods_local_attr_constraint_AMX1(attr, attrName, [op]() {
111
+ return op->emitOpError();
112
+ });
113
+ }
114
+ } // namespace amx
115
+ } // namespace mlir
116
+ namespace mlir {
117
+ namespace amx {
118
+
119
+ //===----------------------------------------------------------------------===//
120
+ // ::mlir::amx::TileLoadOp definitions
121
+ //===----------------------------------------------------------------------===//
122
+
123
+ namespace detail {
124
+ TileLoadOpGenericAdaptorBase::TileLoadOpGenericAdaptorBase(TileLoadOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {}
125
+
126
+ std::pair<unsigned, unsigned> TileLoadOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) {
127
+ bool isVariadic[] = {false, true};
128
+ int prevVariadicCount = 0;
129
+ for (unsigned i = 0; i < index; ++i)
130
+ if (isVariadic[i]) ++prevVariadicCount;
131
+
132
+ // Calculate how many dynamic values a static variadic operand corresponds to.
133
+ // This assumes all static variadic operands have the same dynamic value count.
134
+ int variadicSize = (odsOperandsSize - 1) / 1;
135
+ // `index` passed in as the parameter is the static index which counts each
136
+ // operand (variadic or not) as size 1. So here for each previous static variadic
137
+ // operand, we need to offset by (variadicSize - 1) to get where the dynamic
138
+ // value pack for this static operand starts.
139
+ int start = index + (variadicSize - 1) * prevVariadicCount;
140
+ int size = isVariadic[index] ? variadicSize : 1;
141
+ return {start, size};
142
+ }
143
+
144
+ } // namespace detail
145
+ TileLoadOpAdaptor::TileLoadOpAdaptor(TileLoadOp op) : TileLoadOpGenericAdaptor(op->getOperands(), op) {}
146
+
147
+ ::llvm::LogicalResult TileLoadOpAdaptor::verify(::mlir::Location loc) {
148
+ return ::mlir::success();
149
+ }
150
+
151
+ std::pair<unsigned, unsigned> TileLoadOp::getODSOperandIndexAndLength(unsigned index) {
152
+ bool isVariadic[] = {false, true};
153
+ int prevVariadicCount = 0;
154
+ for (unsigned i = 0; i < index; ++i)
155
+ if (isVariadic[i]) ++prevVariadicCount;
156
+
157
+ // Calculate how many dynamic values a static variadic operand corresponds to.
158
+ // This assumes all static variadic operands have the same dynamic value count.
159
+ int variadicSize = (getOperation()->getNumOperands() - 1) / 1;
160
+ // `index` passed in as the parameter is the static index which counts each
161
+ // operand (variadic or not) as size 1. So here for each previous static variadic
162
+ // operand, we need to offset by (variadicSize - 1) to get where the dynamic
163
+ // value pack for this static operand starts.
164
+ int start = index + (variadicSize - 1) * prevVariadicCount;
165
+ int size = isVariadic[index] ? variadicSize : 1;
166
+ return {start, size};
167
+ }
168
+
169
+ ::mlir::MutableOperandRange TileLoadOp::getIndicesMutable() {
170
+ auto range = getODSOperandIndexAndLength(1);
171
+ auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second);
172
+ return mutableRange;
173
+ }
174
+
175
+ ::llvm::LogicalResult TileLoadOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
176
+ ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr);
177
+ if (!dict) {
178
+ emitError() << "expected DictionaryAttr to set properties";
179
+ return ::mlir::failure();
180
+ }
181
+ return ::mlir::success();
182
+ }
183
+
184
+ ::mlir::Attribute TileLoadOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) {
185
+ ::mlir::SmallVector<::mlir::NamedAttribute> attrs;
186
+ ::mlir::Builder odsBuilder{ctx};
187
+
188
+ if (!attrs.empty())
189
+ return odsBuilder.getDictionaryAttr(attrs);
190
+ return {};
191
+ }
192
+
193
+ llvm::hash_code TileLoadOp::computePropertiesHash(const Properties &prop) {
194
+ using llvm::hash_value;
195
+ return llvm::hash_combine();
196
+ }
197
+
198
+ std::optional<mlir::Attribute> TileLoadOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) {
199
+ return std::nullopt;
200
+ }
201
+
202
+ void TileLoadOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) {
203
+ }
204
+
205
+ void TileLoadOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) {
206
+ }
207
+
208
+ ::llvm::LogicalResult TileLoadOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
209
+ return ::mlir::success();
210
+ }
211
+
212
+ void TileLoadOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res, ::mlir::Value base, ::mlir::ValueRange indices) {
213
+ odsState.addOperands(base);
214
+ odsState.addOperands(indices);
215
+ odsState.addTypes(res);
216
+ }
217
+
218
+ void TileLoadOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value base, ::mlir::ValueRange indices) {
219
+ odsState.addOperands(base);
220
+ odsState.addOperands(indices);
221
+ assert(resultTypes.size() == 1u && "mismatched number of results");
222
+ odsState.addTypes(resultTypes);
223
+ }
224
+
225
+ void TileLoadOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
226
+ assert(operands.size() >= 1u && "mismatched number of parameters");
227
+ odsState.addOperands(operands);
228
+ odsState.addAttributes(attributes);
229
+ assert(resultTypes.size() == 1u && "mismatched number of return types");
230
+ odsState.addTypes(resultTypes);
231
+ }
232
+
233
+ void TileLoadOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) {
234
+ assert(operands.size() >= 1u && "mismatched number of parameters");
235
+ odsState.addOperands(operands);
236
+ odsState.useProperties(const_cast<Properties&>(properties));
237
+ odsState.addAttributes(discardableAttributes);
238
+ assert(resultTypes.size() == 1u && "mismatched number of return types");
239
+ odsState.addTypes(resultTypes);
240
+ }
241
+
242
+ ::llvm::LogicalResult TileLoadOp::verifyInvariantsImpl() {
243
+ {
244
+ unsigned index = 0; (void)index;
245
+ auto valueGroup0 = getODSOperands(0);
246
+
247
+ for (auto v : valueGroup0) {
248
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX1(*this, v.getType(), "operand", index++)))
249
+ return ::mlir::failure();
250
+ }
251
+ auto valueGroup1 = getODSOperands(1);
252
+
253
+ for (auto v : valueGroup1) {
254
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX2(*this, v.getType(), "operand", index++)))
255
+ return ::mlir::failure();
256
+ }
257
+ }
258
+ {
259
+ unsigned index = 0; (void)index;
260
+ auto valueGroup0 = getODSResults(0);
261
+
262
+ for (auto v : valueGroup0) {
263
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX3(*this, v.getType(), "result", index++)))
264
+ return ::mlir::failure();
265
+ }
266
+ }
267
+ return ::mlir::success();
268
+ }
269
+
270
+ ::llvm::LogicalResult TileLoadOp::verifyInvariants() {
271
+ if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify()))
272
+ return ::mlir::success();
273
+ return ::mlir::failure();
274
+ }
275
+
276
+ ::mlir::ParseResult TileLoadOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) {
277
+ ::mlir::OpAsmParser::UnresolvedOperand baseRawOperand{};
278
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> baseOperands(&baseRawOperand, 1); ::llvm::SMLoc baseOperandsLoc;
279
+ (void)baseOperandsLoc;
280
+ ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> indicesOperands;
281
+ ::llvm::SMLoc indicesOperandsLoc;
282
+ (void)indicesOperandsLoc;
283
+ ::mlir::Type baseRawType{};
284
+ ::llvm::ArrayRef<::mlir::Type> baseTypes(&baseRawType, 1);
285
+ ::mlir::Type resRawType{};
286
+ ::llvm::ArrayRef<::mlir::Type> resTypes(&resRawType, 1);
287
+
288
+ baseOperandsLoc = parser.getCurrentLocation();
289
+ if (parser.parseOperand(baseRawOperand))
290
+ return ::mlir::failure();
291
+ if (parser.parseLSquare())
292
+ return ::mlir::failure();
293
+
294
+ indicesOperandsLoc = parser.getCurrentLocation();
295
+ if (parser.parseOperandList(indicesOperands))
296
+ return ::mlir::failure();
297
+ if (parser.parseRSquare())
298
+ return ::mlir::failure();
299
+ {
300
+ auto loc = parser.getCurrentLocation();(void)loc;
301
+ if (parser.parseOptionalAttrDict(result.attributes))
302
+ return ::mlir::failure();
303
+ if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
304
+ return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op ";
305
+ })))
306
+ return ::mlir::failure();
307
+ }
308
+ if (parser.parseColon())
309
+ return ::mlir::failure();
310
+
311
+ {
312
+ ::mlir::MemRefType type;
313
+ if (parser.parseCustomTypeWithFallback(type))
314
+ return ::mlir::failure();
315
+ baseRawType = type;
316
+ }
317
+ if (parser.parseKeyword("into"))
318
+ return ::mlir::failure();
319
+
320
+ if (parser.parseType(resRawType))
321
+ return ::mlir::failure();
322
+ ::mlir::Type odsBuildableType0 = parser.getBuilder().getIndexType();
323
+ result.addTypes(resTypes);
324
+ if (parser.resolveOperands(baseOperands, baseTypes, baseOperandsLoc, result.operands))
325
+ return ::mlir::failure();
326
+ if (parser.resolveOperands(indicesOperands, odsBuildableType0, indicesOperandsLoc, result.operands))
327
+ return ::mlir::failure();
328
+ return ::mlir::success();
329
+ }
330
+
331
+ void TileLoadOp::print(::mlir::OpAsmPrinter &_odsPrinter) {
332
+ _odsPrinter << ' ';
333
+ _odsPrinter << getBase();
334
+ _odsPrinter << "[";
335
+ _odsPrinter << getIndices();
336
+ _odsPrinter << "]";
337
+ ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;
338
+ _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs);
339
+ _odsPrinter << ' ' << ":";
340
+ _odsPrinter << ' ';
341
+ {
342
+ auto type = getBase().getType();
343
+ if (auto validType = ::llvm::dyn_cast<::mlir::MemRefType>(type))
344
+ _odsPrinter.printStrippedAttrOrType(validType);
345
+ else
346
+ _odsPrinter << type;
347
+ }
348
+ _odsPrinter << ' ' << "into";
349
+ _odsPrinter << ' ';
350
+ _odsPrinter << getRes().getType();
351
+ }
352
+
353
+ void TileLoadOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) {
354
+ {
355
+ auto valueRange = getODSOperandIndexAndLength(0);
356
+ for (unsigned idx = valueRange.first; idx < valueRange.first + valueRange.second; idx++) {
357
+ effects.emplace_back(::mlir::MemoryEffects::Read::get(), &getOperation()->getOpOperand(idx), 0, false, ::mlir::SideEffects::DefaultResource::get());
358
+ }
359
+ }
360
+ }
361
+
362
+ } // namespace amx
363
+ } // namespace mlir
364
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amx::TileLoadOp)
365
+
366
+ namespace mlir {
367
+ namespace amx {
368
+
369
+ //===----------------------------------------------------------------------===//
370
+ // ::mlir::amx::TileMulFOp definitions
371
+ //===----------------------------------------------------------------------===//
372
+
373
+ namespace detail {
374
+ TileMulFOpGenericAdaptorBase::TileMulFOpGenericAdaptorBase(TileMulFOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {}
375
+
376
+ } // namespace detail
377
+ TileMulFOpAdaptor::TileMulFOpAdaptor(TileMulFOp op) : TileMulFOpGenericAdaptor(op->getOperands(), op) {}
378
+
379
+ ::llvm::LogicalResult TileMulFOpAdaptor::verify(::mlir::Location loc) {
380
+ return ::mlir::success();
381
+ }
382
+
383
+ ::llvm::LogicalResult TileMulFOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
384
+ ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr);
385
+ if (!dict) {
386
+ emitError() << "expected DictionaryAttr to set properties";
387
+ return ::mlir::failure();
388
+ }
389
+ return ::mlir::success();
390
+ }
391
+
392
+ ::mlir::Attribute TileMulFOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) {
393
+ ::mlir::SmallVector<::mlir::NamedAttribute> attrs;
394
+ ::mlir::Builder odsBuilder{ctx};
395
+
396
+ if (!attrs.empty())
397
+ return odsBuilder.getDictionaryAttr(attrs);
398
+ return {};
399
+ }
400
+
401
+ llvm::hash_code TileMulFOp::computePropertiesHash(const Properties &prop) {
402
+ using llvm::hash_value;
403
+ return llvm::hash_combine();
404
+ }
405
+
406
+ std::optional<mlir::Attribute> TileMulFOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) {
407
+ return std::nullopt;
408
+ }
409
+
410
+ void TileMulFOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) {
411
+ }
412
+
413
+ void TileMulFOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) {
414
+ }
415
+
416
+ ::llvm::LogicalResult TileMulFOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
417
+ return ::mlir::success();
418
+ }
419
+
420
+ void TileMulFOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc) {
421
+ odsState.addOperands(lhs);
422
+ odsState.addOperands(rhs);
423
+ odsState.addOperands(acc);
424
+ odsState.addTypes(res);
425
+ }
426
+
427
+ void TileMulFOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc) {
428
+ odsState.addOperands(lhs);
429
+ odsState.addOperands(rhs);
430
+ odsState.addOperands(acc);
431
+ assert(resultTypes.size() == 1u && "mismatched number of results");
432
+ odsState.addTypes(resultTypes);
433
+ }
434
+
435
+ void TileMulFOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
436
+ assert(operands.size() == 3u && "mismatched number of parameters");
437
+ odsState.addOperands(operands);
438
+ odsState.addAttributes(attributes);
439
+ assert(resultTypes.size() == 1u && "mismatched number of return types");
440
+ odsState.addTypes(resultTypes);
441
+ }
442
+
443
+ void TileMulFOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) {
444
+ assert(operands.size() == 3u && "mismatched number of parameters");
445
+ odsState.addOperands(operands);
446
+ odsState.useProperties(const_cast<Properties&>(properties));
447
+ odsState.addAttributes(discardableAttributes);
448
+ assert(resultTypes.size() == 1u && "mismatched number of return types");
449
+ odsState.addTypes(resultTypes);
450
+ }
451
+
452
+ ::llvm::LogicalResult TileMulFOp::verifyInvariantsImpl() {
453
+ {
454
+ unsigned index = 0; (void)index;
455
+ auto valueGroup0 = getODSOperands(0);
456
+
457
+ for (auto v : valueGroup0) {
458
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX4(*this, v.getType(), "operand", index++)))
459
+ return ::mlir::failure();
460
+ }
461
+ auto valueGroup1 = getODSOperands(1);
462
+
463
+ for (auto v : valueGroup1) {
464
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX4(*this, v.getType(), "operand", index++)))
465
+ return ::mlir::failure();
466
+ }
467
+ auto valueGroup2 = getODSOperands(2);
468
+
469
+ for (auto v : valueGroup2) {
470
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX5(*this, v.getType(), "operand", index++)))
471
+ return ::mlir::failure();
472
+ }
473
+ }
474
+ {
475
+ unsigned index = 0; (void)index;
476
+ auto valueGroup0 = getODSResults(0);
477
+
478
+ for (auto v : valueGroup0) {
479
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX5(*this, v.getType(), "result", index++)))
480
+ return ::mlir::failure();
481
+ }
482
+ }
483
+ if (!((((*this->getODSOperands(2).begin()).getType()) == ((*this->getODSResults(0).begin()).getType()) && ((*this->getODSResults(0).begin()).getType()) == ((*this->getODSOperands(2).begin()).getType()))))
484
+ return emitOpError("failed to verify that all of {acc, res} have same type");
485
+ return ::mlir::success();
486
+ }
487
+
488
+ ::llvm::LogicalResult TileMulFOp::verifyInvariants() {
489
+ if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify()))
490
+ return ::mlir::success();
491
+ return ::mlir::failure();
492
+ }
493
+
494
+ ::mlir::ParseResult TileMulFOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) {
495
+ ::mlir::OpAsmParser::UnresolvedOperand lhsRawOperand{};
496
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> lhsOperands(&lhsRawOperand, 1); ::llvm::SMLoc lhsOperandsLoc;
497
+ (void)lhsOperandsLoc;
498
+ ::mlir::OpAsmParser::UnresolvedOperand rhsRawOperand{};
499
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> rhsOperands(&rhsRawOperand, 1); ::llvm::SMLoc rhsOperandsLoc;
500
+ (void)rhsOperandsLoc;
501
+ ::mlir::OpAsmParser::UnresolvedOperand accRawOperand{};
502
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> accOperands(&accRawOperand, 1); ::llvm::SMLoc accOperandsLoc;
503
+ (void)accOperandsLoc;
504
+ ::mlir::Type lhsRawType{};
505
+ ::llvm::ArrayRef<::mlir::Type> lhsTypes(&lhsRawType, 1);
506
+ ::mlir::Type rhsRawType{};
507
+ ::llvm::ArrayRef<::mlir::Type> rhsTypes(&rhsRawType, 1);
508
+ ::mlir::Type accRawType{};
509
+ ::llvm::ArrayRef<::mlir::Type> accTypes(&accRawType, 1);
510
+
511
+ lhsOperandsLoc = parser.getCurrentLocation();
512
+ if (parser.parseOperand(lhsRawOperand))
513
+ return ::mlir::failure();
514
+ if (parser.parseComma())
515
+ return ::mlir::failure();
516
+
517
+ rhsOperandsLoc = parser.getCurrentLocation();
518
+ if (parser.parseOperand(rhsRawOperand))
519
+ return ::mlir::failure();
520
+ if (parser.parseComma())
521
+ return ::mlir::failure();
522
+
523
+ accOperandsLoc = parser.getCurrentLocation();
524
+ if (parser.parseOperand(accRawOperand))
525
+ return ::mlir::failure();
526
+ {
527
+ auto loc = parser.getCurrentLocation();(void)loc;
528
+ if (parser.parseOptionalAttrDict(result.attributes))
529
+ return ::mlir::failure();
530
+ if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
531
+ return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op ";
532
+ })))
533
+ return ::mlir::failure();
534
+ }
535
+ if (parser.parseColon())
536
+ return ::mlir::failure();
537
+
538
+ if (parser.parseType(lhsRawType))
539
+ return ::mlir::failure();
540
+ if (parser.parseComma())
541
+ return ::mlir::failure();
542
+
543
+ if (parser.parseType(rhsRawType))
544
+ return ::mlir::failure();
545
+ if (parser.parseComma())
546
+ return ::mlir::failure();
547
+
548
+ if (parser.parseType(accRawType))
549
+ return ::mlir::failure();
550
+ result.addTypes(accTypes[0]);
551
+ if (parser.resolveOperands(lhsOperands, lhsTypes, lhsOperandsLoc, result.operands))
552
+ return ::mlir::failure();
553
+ if (parser.resolveOperands(rhsOperands, rhsTypes, rhsOperandsLoc, result.operands))
554
+ return ::mlir::failure();
555
+ if (parser.resolveOperands(accOperands, accTypes, accOperandsLoc, result.operands))
556
+ return ::mlir::failure();
557
+ return ::mlir::success();
558
+ }
559
+
560
+ void TileMulFOp::print(::mlir::OpAsmPrinter &_odsPrinter) {
561
+ _odsPrinter << ' ';
562
+ _odsPrinter << getLhs();
563
+ _odsPrinter << ",";
564
+ _odsPrinter << ' ';
565
+ _odsPrinter << getRhs();
566
+ _odsPrinter << ",";
567
+ _odsPrinter << ' ';
568
+ _odsPrinter << getAcc();
569
+ ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;
570
+ _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs);
571
+ _odsPrinter << ' ' << ":";
572
+ _odsPrinter << ' ';
573
+ _odsPrinter << getLhs().getType();
574
+ _odsPrinter << ",";
575
+ _odsPrinter << ' ';
576
+ _odsPrinter << getRhs().getType();
577
+ _odsPrinter << ",";
578
+ _odsPrinter << ' ';
579
+ _odsPrinter << getAcc().getType();
580
+ }
581
+
582
+ void TileMulFOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) {
583
+ }
584
+
585
+ } // namespace amx
586
+ } // namespace mlir
587
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amx::TileMulFOp)
588
+
589
+ namespace mlir {
590
+ namespace amx {
591
+
592
+ //===----------------------------------------------------------------------===//
593
+ // ::mlir::amx::TileMulIOp definitions
594
+ //===----------------------------------------------------------------------===//
595
+
596
+ namespace detail {
597
+ TileMulIOpGenericAdaptorBase::TileMulIOpGenericAdaptorBase(TileMulIOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {}
598
+
599
+ ::mlir::UnitAttr TileMulIOpGenericAdaptorBase::getIsZextLhsAttr() {
600
+ auto attr = ::llvm::dyn_cast_or_null<::mlir::UnitAttr>(getProperties().isZextLhs);
601
+ if (!attr)
602
+ attr = ((false) ? ::mlir::Builder(odsAttrs.getContext()).getUnitAttr() : nullptr);
603
+ return attr;
604
+ }
605
+
606
+ bool TileMulIOpGenericAdaptorBase::getIsZextLhs() {
607
+ auto attr = getIsZextLhsAttr();
608
+ if (!attr)
609
+ return ((false) ? ::mlir::Builder(odsAttrs.getContext()).getUnitAttr() : nullptr) != nullptr;
610
+ return attr != nullptr;
611
+ }
612
+
613
+ ::mlir::UnitAttr TileMulIOpGenericAdaptorBase::getIsZextRhsAttr() {
614
+ auto attr = ::llvm::dyn_cast_or_null<::mlir::UnitAttr>(getProperties().isZextRhs);
615
+ if (!attr)
616
+ attr = ((false) ? ::mlir::Builder(odsAttrs.getContext()).getUnitAttr() : nullptr);
617
+ return attr;
618
+ }
619
+
620
+ bool TileMulIOpGenericAdaptorBase::getIsZextRhs() {
621
+ auto attr = getIsZextRhsAttr();
622
+ if (!attr)
623
+ return ((false) ? ::mlir::Builder(odsAttrs.getContext()).getUnitAttr() : nullptr) != nullptr;
624
+ return attr != nullptr;
625
+ }
626
+
627
+ } // namespace detail
628
+ TileMulIOpAdaptor::TileMulIOpAdaptor(TileMulIOp op) : TileMulIOpGenericAdaptor(op->getOperands(), op) {}
629
+
630
+ ::llvm::LogicalResult TileMulIOpAdaptor::verify(::mlir::Location loc) {
631
+ auto tblgen_isZextLhs = getProperties().isZextLhs; (void)tblgen_isZextLhs;
632
+ auto tblgen_isZextRhs = getProperties().isZextRhs; (void)tblgen_isZextRhs;
633
+
634
+ if (tblgen_isZextLhs && !((::llvm::isa<::mlir::UnitAttr>(tblgen_isZextLhs))))
635
+ return emitError(loc, "'amx.tile_muli' op ""attribute 'isZextLhs' failed to satisfy constraint: unit attribute");
636
+
637
+ if (tblgen_isZextRhs && !((::llvm::isa<::mlir::UnitAttr>(tblgen_isZextRhs))))
638
+ return emitError(loc, "'amx.tile_muli' op ""attribute 'isZextRhs' failed to satisfy constraint: unit attribute");
639
+ return ::mlir::success();
640
+ }
641
+
642
+ ::llvm::LogicalResult TileMulIOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
643
+ ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr);
644
+ if (!dict) {
645
+ emitError() << "expected DictionaryAttr to set properties";
646
+ return ::mlir::failure();
647
+ }
648
+
649
+ {
650
+ auto &propStorage = prop.isZextLhs;
651
+ auto attr = dict.get("isZextLhs");
652
+ if (attr) {
653
+ auto convertedAttr = ::llvm::dyn_cast<std::remove_reference_t<decltype(propStorage)>>(attr);
654
+ if (convertedAttr) {
655
+ propStorage = convertedAttr;
656
+ } else {
657
+ emitError() << "Invalid attribute `isZextLhs` in property conversion: " << attr;
658
+ return ::mlir::failure();
659
+ }
660
+ }
661
+ }
662
+
663
+ {
664
+ auto &propStorage = prop.isZextRhs;
665
+ auto attr = dict.get("isZextRhs");
666
+ if (attr) {
667
+ auto convertedAttr = ::llvm::dyn_cast<std::remove_reference_t<decltype(propStorage)>>(attr);
668
+ if (convertedAttr) {
669
+ propStorage = convertedAttr;
670
+ } else {
671
+ emitError() << "Invalid attribute `isZextRhs` in property conversion: " << attr;
672
+ return ::mlir::failure();
673
+ }
674
+ }
675
+ }
676
+ return ::mlir::success();
677
+ }
678
+
679
+ ::mlir::Attribute TileMulIOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) {
680
+ ::mlir::SmallVector<::mlir::NamedAttribute> attrs;
681
+ ::mlir::Builder odsBuilder{ctx};
682
+
683
+ {
684
+ const auto &propStorage = prop.isZextLhs;
685
+ if (propStorage)
686
+ attrs.push_back(odsBuilder.getNamedAttr("isZextLhs",
687
+ propStorage));
688
+ }
689
+
690
+ {
691
+ const auto &propStorage = prop.isZextRhs;
692
+ if (propStorage)
693
+ attrs.push_back(odsBuilder.getNamedAttr("isZextRhs",
694
+ propStorage));
695
+ }
696
+
697
+ if (!attrs.empty())
698
+ return odsBuilder.getDictionaryAttr(attrs);
699
+ return {};
700
+ }
701
+
702
+ llvm::hash_code TileMulIOp::computePropertiesHash(const Properties &prop) {
703
+ using llvm::hash_value;
704
+ return llvm::hash_combine(
705
+ llvm::hash_value(prop.isZextLhs.getAsOpaquePointer()),
706
+ llvm::hash_value(prop.isZextRhs.getAsOpaquePointer()));
707
+ }
708
+
709
+ std::optional<mlir::Attribute> TileMulIOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) {
710
+ if (name == "isZextLhs")
711
+ return prop.isZextLhs;
712
+
713
+ if (name == "isZextRhs")
714
+ return prop.isZextRhs;
715
+ return std::nullopt;
716
+ }
717
+
718
+ void TileMulIOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) {
719
+ if (name == "isZextLhs") {
720
+ prop.isZextLhs = ::llvm::dyn_cast_or_null<std::remove_reference_t<decltype(prop.isZextLhs)>>(value);
721
+ return;
722
+ }
723
+
724
+ if (name == "isZextRhs") {
725
+ prop.isZextRhs = ::llvm::dyn_cast_or_null<std::remove_reference_t<decltype(prop.isZextRhs)>>(value);
726
+ return;
727
+ }
728
+ }
729
+
730
+ void TileMulIOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) {
731
+ if (prop.isZextLhs) attrs.append("isZextLhs", prop.isZextLhs);
732
+
733
+ if (prop.isZextRhs) attrs.append("isZextRhs", prop.isZextRhs);
734
+ }
735
+
736
+ ::llvm::LogicalResult TileMulIOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
737
+ {
738
+ ::mlir::Attribute attr = attrs.get(getIsZextLhsAttrName(opName));
739
+ if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_AMX1(attr, "isZextLhs", emitError)))
740
+ return ::mlir::failure();
741
+ }
742
+
743
+ {
744
+ ::mlir::Attribute attr = attrs.get(getIsZextRhsAttrName(opName));
745
+ if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_AMX1(attr, "isZextRhs", emitError)))
746
+ return ::mlir::failure();
747
+ }
748
+ return ::mlir::success();
749
+ }
750
+
751
+ ::llvm::LogicalResult TileMulIOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) {
752
+ auto &prop = state.getOrAddProperties<Properties>(); (void)prop;
753
+ if (::mlir::failed(reader.readOptionalAttribute(prop.isZextLhs)))
754
+ return ::mlir::failure();
755
+
756
+ if (::mlir::failed(reader.readOptionalAttribute(prop.isZextRhs)))
757
+ return ::mlir::failure();
758
+ return ::mlir::success();
759
+ }
760
+
761
+ void TileMulIOp::writeProperties(::mlir::DialectBytecodeWriter &writer) {
762
+ auto &prop = getProperties(); (void)prop;
763
+
764
+ writer.writeOptionalAttribute(prop.isZextLhs);
765
+
766
+ writer.writeOptionalAttribute(prop.isZextRhs);
767
+ }
768
+
769
+ bool TileMulIOp::getIsZextLhs() {
770
+ auto attr = getIsZextLhsAttr();
771
+ if (!attr)
772
+ return ((false) ? ::mlir::Builder((*this)->getContext()).getUnitAttr() : nullptr) != nullptr;
773
+ return attr != nullptr;
774
+ }
775
+
776
+ bool TileMulIOp::getIsZextRhs() {
777
+ auto attr = getIsZextRhsAttr();
778
+ if (!attr)
779
+ return ((false) ? ::mlir::Builder((*this)->getContext()).getUnitAttr() : nullptr) != nullptr;
780
+ return attr != nullptr;
781
+ }
782
+
783
+ void TileMulIOp::setIsZextLhs(bool attrValue) {
784
+ auto &odsProp = getProperties().isZextLhs;
785
+ if (attrValue)
786
+ odsProp = ((attrValue) ? ::mlir::Builder((*this)->getContext()).getUnitAttr() : nullptr);
787
+ else
788
+ odsProp = nullptr;
789
+ }
790
+
791
+ void TileMulIOp::setIsZextRhs(bool attrValue) {
792
+ auto &odsProp = getProperties().isZextRhs;
793
+ if (attrValue)
794
+ odsProp = ((attrValue) ? ::mlir::Builder((*this)->getContext()).getUnitAttr() : nullptr);
795
+ else
796
+ odsProp = nullptr;
797
+ }
798
+
799
+ void TileMulIOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc, /*optional*/::mlir::UnitAttr isZextLhs, /*optional*/::mlir::UnitAttr isZextRhs) {
800
+ odsState.addOperands(lhs);
801
+ odsState.addOperands(rhs);
802
+ odsState.addOperands(acc);
803
+ if (isZextLhs) {
804
+ odsState.getOrAddProperties<Properties>().isZextLhs = isZextLhs;
805
+ }
806
+ if (isZextRhs) {
807
+ odsState.getOrAddProperties<Properties>().isZextRhs = isZextRhs;
808
+ }
809
+ odsState.addTypes(res);
810
+ }
811
+
812
+ void TileMulIOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc, /*optional*/::mlir::UnitAttr isZextLhs, /*optional*/::mlir::UnitAttr isZextRhs) {
813
+ odsState.addOperands(lhs);
814
+ odsState.addOperands(rhs);
815
+ odsState.addOperands(acc);
816
+ if (isZextLhs) {
817
+ odsState.getOrAddProperties<Properties>().isZextLhs = isZextLhs;
818
+ }
819
+ if (isZextRhs) {
820
+ odsState.getOrAddProperties<Properties>().isZextRhs = isZextRhs;
821
+ }
822
+ assert(resultTypes.size() == 1u && "mismatched number of results");
823
+ odsState.addTypes(resultTypes);
824
+ }
825
+
826
+ void TileMulIOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc, /*optional*/bool isZextLhs, /*optional*/bool isZextRhs) {
827
+ odsState.addOperands(lhs);
828
+ odsState.addOperands(rhs);
829
+ odsState.addOperands(acc);
830
+ if (isZextLhs) {
831
+ odsState.getOrAddProperties<Properties>().isZextLhs = ((isZextLhs) ? odsBuilder.getUnitAttr() : nullptr);
832
+ }
833
+ if (isZextRhs) {
834
+ odsState.getOrAddProperties<Properties>().isZextRhs = ((isZextRhs) ? odsBuilder.getUnitAttr() : nullptr);
835
+ }
836
+ odsState.addTypes(res);
837
+ }
838
+
839
+ void TileMulIOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc, /*optional*/bool isZextLhs, /*optional*/bool isZextRhs) {
840
+ odsState.addOperands(lhs);
841
+ odsState.addOperands(rhs);
842
+ odsState.addOperands(acc);
843
+ if (isZextLhs) {
844
+ odsState.getOrAddProperties<Properties>().isZextLhs = ((isZextLhs) ? odsBuilder.getUnitAttr() : nullptr);
845
+ }
846
+ if (isZextRhs) {
847
+ odsState.getOrAddProperties<Properties>().isZextRhs = ((isZextRhs) ? odsBuilder.getUnitAttr() : nullptr);
848
+ }
849
+ assert(resultTypes.size() == 1u && "mismatched number of results");
850
+ odsState.addTypes(resultTypes);
851
+ }
852
+
853
+ void TileMulIOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
854
+ assert(operands.size() == 3u && "mismatched number of parameters");
855
+ odsState.addOperands(operands);
856
+ odsState.addAttributes(attributes);
857
+ assert(resultTypes.size() == 1u && "mismatched number of return types");
858
+ odsState.addTypes(resultTypes);
859
+
860
+ if (!attributes.empty()) {
861
+ ::mlir::OpaqueProperties properties =
862
+ &odsState.getOrAddProperties<TileMulIOp::Properties>();
863
+ std::optional<::mlir::RegisteredOperationName> info =
864
+ odsState.name.getRegisteredInfo();
865
+ if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties,
866
+ odsState.attributes.getDictionary(odsState.getContext()), nullptr)))
867
+ ::llvm::report_fatal_error("Property conversion failed.");
868
+ }
869
+ }
870
+
871
+ void TileMulIOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) {
872
+ assert(operands.size() == 3u && "mismatched number of parameters");
873
+ odsState.addOperands(operands);
874
+ odsState.useProperties(const_cast<Properties&>(properties));
875
+ odsState.addAttributes(discardableAttributes);
876
+ assert(resultTypes.size() == 1u && "mismatched number of return types");
877
+ odsState.addTypes(resultTypes);
878
+ }
879
+
880
+ ::llvm::LogicalResult TileMulIOp::verifyInvariantsImpl() {
881
+ auto tblgen_isZextLhs = getProperties().isZextLhs; (void)tblgen_isZextLhs;
882
+ auto tblgen_isZextRhs = getProperties().isZextRhs; (void)tblgen_isZextRhs;
883
+
884
+ if (::mlir::failed(__mlir_ods_local_attr_constraint_AMX1(*this, tblgen_isZextLhs, "isZextLhs")))
885
+ return ::mlir::failure();
886
+
887
+ if (::mlir::failed(__mlir_ods_local_attr_constraint_AMX1(*this, tblgen_isZextRhs, "isZextRhs")))
888
+ return ::mlir::failure();
889
+ {
890
+ unsigned index = 0; (void)index;
891
+ auto valueGroup0 = getODSOperands(0);
892
+
893
+ for (auto v : valueGroup0) {
894
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX6(*this, v.getType(), "operand", index++)))
895
+ return ::mlir::failure();
896
+ }
897
+ auto valueGroup1 = getODSOperands(1);
898
+
899
+ for (auto v : valueGroup1) {
900
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX6(*this, v.getType(), "operand", index++)))
901
+ return ::mlir::failure();
902
+ }
903
+ auto valueGroup2 = getODSOperands(2);
904
+
905
+ for (auto v : valueGroup2) {
906
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX7(*this, v.getType(), "operand", index++)))
907
+ return ::mlir::failure();
908
+ }
909
+ }
910
+ {
911
+ unsigned index = 0; (void)index;
912
+ auto valueGroup0 = getODSResults(0);
913
+
914
+ for (auto v : valueGroup0) {
915
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX7(*this, v.getType(), "result", index++)))
916
+ return ::mlir::failure();
917
+ }
918
+ }
919
+ if (!((((*this->getODSOperands(2).begin()).getType()) == ((*this->getODSResults(0).begin()).getType()) && ((*this->getODSResults(0).begin()).getType()) == ((*this->getODSOperands(2).begin()).getType()))))
920
+ return emitOpError("failed to verify that all of {acc, res} have same type");
921
+ return ::mlir::success();
922
+ }
923
+
924
+ ::llvm::LogicalResult TileMulIOp::verifyInvariants() {
925
+ if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify()))
926
+ return ::mlir::success();
927
+ return ::mlir::failure();
928
+ }
929
+
930
+ ::mlir::ParseResult TileMulIOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) {
931
+ ::mlir::OpAsmParser::UnresolvedOperand lhsRawOperand{};
932
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> lhsOperands(&lhsRawOperand, 1); ::llvm::SMLoc lhsOperandsLoc;
933
+ (void)lhsOperandsLoc;
934
+ ::mlir::OpAsmParser::UnresolvedOperand rhsRawOperand{};
935
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> rhsOperands(&rhsRawOperand, 1); ::llvm::SMLoc rhsOperandsLoc;
936
+ (void)rhsOperandsLoc;
937
+ ::mlir::OpAsmParser::UnresolvedOperand accRawOperand{};
938
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> accOperands(&accRawOperand, 1); ::llvm::SMLoc accOperandsLoc;
939
+ (void)accOperandsLoc;
940
+ ::mlir::Type lhsRawType{};
941
+ ::llvm::ArrayRef<::mlir::Type> lhsTypes(&lhsRawType, 1);
942
+ ::mlir::Type rhsRawType{};
943
+ ::llvm::ArrayRef<::mlir::Type> rhsTypes(&rhsRawType, 1);
944
+ ::mlir::Type accRawType{};
945
+ ::llvm::ArrayRef<::mlir::Type> accTypes(&accRawType, 1);
946
+
947
+ lhsOperandsLoc = parser.getCurrentLocation();
948
+ if (parser.parseOperand(lhsRawOperand))
949
+ return ::mlir::failure();
950
+ if (::mlir::succeeded(parser.parseOptionalKeyword("zext"))) {
951
+ result.getOrAddProperties<TileMulIOp::Properties>().isZextLhs = parser.getBuilder().getUnitAttr(); }
952
+ if (parser.parseComma())
953
+ return ::mlir::failure();
954
+
955
+ rhsOperandsLoc = parser.getCurrentLocation();
956
+ if (parser.parseOperand(rhsRawOperand))
957
+ return ::mlir::failure();
958
+ if (::mlir::succeeded(parser.parseOptionalKeyword("zext"))) {
959
+ result.getOrAddProperties<TileMulIOp::Properties>().isZextRhs = parser.getBuilder().getUnitAttr(); }
960
+ if (parser.parseComma())
961
+ return ::mlir::failure();
962
+
963
+ accOperandsLoc = parser.getCurrentLocation();
964
+ if (parser.parseOperand(accRawOperand))
965
+ return ::mlir::failure();
966
+ {
967
+ auto loc = parser.getCurrentLocation();(void)loc;
968
+ if (parser.parseOptionalAttrDict(result.attributes))
969
+ return ::mlir::failure();
970
+ if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
971
+ return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op ";
972
+ })))
973
+ return ::mlir::failure();
974
+ }
975
+ if (parser.parseColon())
976
+ return ::mlir::failure();
977
+
978
+ if (parser.parseType(lhsRawType))
979
+ return ::mlir::failure();
980
+ if (parser.parseComma())
981
+ return ::mlir::failure();
982
+
983
+ if (parser.parseType(rhsRawType))
984
+ return ::mlir::failure();
985
+ if (parser.parseComma())
986
+ return ::mlir::failure();
987
+
988
+ if (parser.parseType(accRawType))
989
+ return ::mlir::failure();
990
+ result.addTypes(accTypes[0]);
991
+ if (parser.resolveOperands(lhsOperands, lhsTypes, lhsOperandsLoc, result.operands))
992
+ return ::mlir::failure();
993
+ if (parser.resolveOperands(rhsOperands, rhsTypes, rhsOperandsLoc, result.operands))
994
+ return ::mlir::failure();
995
+ if (parser.resolveOperands(accOperands, accTypes, accOperandsLoc, result.operands))
996
+ return ::mlir::failure();
997
+ return ::mlir::success();
998
+ }
999
+
1000
+ void TileMulIOp::print(::mlir::OpAsmPrinter &_odsPrinter) {
1001
+ _odsPrinter << ' ';
1002
+ _odsPrinter << getLhs();
1003
+ if ((getIsZextLhsAttr() && getIsZextLhsAttr() != ((false) ? ::mlir::OpBuilder((*this)->getContext()).getUnitAttr() : nullptr))) {
1004
+ _odsPrinter << ' ' << "zext";
1005
+ }
1006
+ _odsPrinter << ",";
1007
+ _odsPrinter << ' ';
1008
+ _odsPrinter << getRhs();
1009
+ if ((getIsZextRhsAttr() && getIsZextRhsAttr() != ((false) ? ::mlir::OpBuilder((*this)->getContext()).getUnitAttr() : nullptr))) {
1010
+ _odsPrinter << ' ' << "zext";
1011
+ }
1012
+ _odsPrinter << ",";
1013
+ _odsPrinter << ' ';
1014
+ _odsPrinter << getAcc();
1015
+ ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;
1016
+ elidedAttrs.push_back("isZextLhs");
1017
+ elidedAttrs.push_back("isZextRhs");
1018
+ {
1019
+ ::mlir::Builder odsBuilder(getContext());
1020
+ ::mlir::Attribute attr = getIsZextLhsAttr();
1021
+ if(attr && (attr == ((false) ? odsBuilder.getUnitAttr() : nullptr)))
1022
+ elidedAttrs.push_back("isZextLhs");
1023
+ }
1024
+ {
1025
+ ::mlir::Builder odsBuilder(getContext());
1026
+ ::mlir::Attribute attr = getIsZextRhsAttr();
1027
+ if(attr && (attr == ((false) ? odsBuilder.getUnitAttr() : nullptr)))
1028
+ elidedAttrs.push_back("isZextRhs");
1029
+ }
1030
+ _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs);
1031
+ _odsPrinter << ' ' << ":";
1032
+ _odsPrinter << ' ';
1033
+ _odsPrinter << getLhs().getType();
1034
+ _odsPrinter << ",";
1035
+ _odsPrinter << ' ';
1036
+ _odsPrinter << getRhs().getType();
1037
+ _odsPrinter << ",";
1038
+ _odsPrinter << ' ';
1039
+ _odsPrinter << getAcc().getType();
1040
+ }
1041
+
1042
+ void TileMulIOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) {
1043
+ }
1044
+
1045
+ } // namespace amx
1046
+ } // namespace mlir
1047
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amx::TileMulIOp)
1048
+
1049
+ namespace mlir {
1050
+ namespace amx {
1051
+
1052
+ //===----------------------------------------------------------------------===//
1053
+ // ::mlir::amx::TileStoreOp definitions
1054
+ //===----------------------------------------------------------------------===//
1055
+
1056
+ namespace detail {
1057
+ TileStoreOpGenericAdaptorBase::TileStoreOpGenericAdaptorBase(TileStoreOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {}
1058
+
1059
+ std::pair<unsigned, unsigned> TileStoreOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) {
1060
+ bool isVariadic[] = {false, true, false};
1061
+ int prevVariadicCount = 0;
1062
+ for (unsigned i = 0; i < index; ++i)
1063
+ if (isVariadic[i]) ++prevVariadicCount;
1064
+
1065
+ // Calculate how many dynamic values a static variadic operand corresponds to.
1066
+ // This assumes all static variadic operands have the same dynamic value count.
1067
+ int variadicSize = (odsOperandsSize - 2) / 1;
1068
+ // `index` passed in as the parameter is the static index which counts each
1069
+ // operand (variadic or not) as size 1. So here for each previous static variadic
1070
+ // operand, we need to offset by (variadicSize - 1) to get where the dynamic
1071
+ // value pack for this static operand starts.
1072
+ int start = index + (variadicSize - 1) * prevVariadicCount;
1073
+ int size = isVariadic[index] ? variadicSize : 1;
1074
+ return {start, size};
1075
+ }
1076
+
1077
+ } // namespace detail
1078
+ TileStoreOpAdaptor::TileStoreOpAdaptor(TileStoreOp op) : TileStoreOpGenericAdaptor(op->getOperands(), op) {}
1079
+
1080
+ ::llvm::LogicalResult TileStoreOpAdaptor::verify(::mlir::Location loc) {
1081
+ return ::mlir::success();
1082
+ }
1083
+
1084
+ std::pair<unsigned, unsigned> TileStoreOp::getODSOperandIndexAndLength(unsigned index) {
1085
+ bool isVariadic[] = {false, true, false};
1086
+ int prevVariadicCount = 0;
1087
+ for (unsigned i = 0; i < index; ++i)
1088
+ if (isVariadic[i]) ++prevVariadicCount;
1089
+
1090
+ // Calculate how many dynamic values a static variadic operand corresponds to.
1091
+ // This assumes all static variadic operands have the same dynamic value count.
1092
+ int variadicSize = (getOperation()->getNumOperands() - 2) / 1;
1093
+ // `index` passed in as the parameter is the static index which counts each
1094
+ // operand (variadic or not) as size 1. So here for each previous static variadic
1095
+ // operand, we need to offset by (variadicSize - 1) to get where the dynamic
1096
+ // value pack for this static operand starts.
1097
+ int start = index + (variadicSize - 1) * prevVariadicCount;
1098
+ int size = isVariadic[index] ? variadicSize : 1;
1099
+ return {start, size};
1100
+ }
1101
+
1102
+ ::mlir::MutableOperandRange TileStoreOp::getIndicesMutable() {
1103
+ auto range = getODSOperandIndexAndLength(1);
1104
+ auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second);
1105
+ return mutableRange;
1106
+ }
1107
+
1108
+ ::llvm::LogicalResult TileStoreOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
1109
+ ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr);
1110
+ if (!dict) {
1111
+ emitError() << "expected DictionaryAttr to set properties";
1112
+ return ::mlir::failure();
1113
+ }
1114
+ return ::mlir::success();
1115
+ }
1116
+
1117
+ ::mlir::Attribute TileStoreOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) {
1118
+ ::mlir::SmallVector<::mlir::NamedAttribute> attrs;
1119
+ ::mlir::Builder odsBuilder{ctx};
1120
+
1121
+ if (!attrs.empty())
1122
+ return odsBuilder.getDictionaryAttr(attrs);
1123
+ return {};
1124
+ }
1125
+
1126
+ llvm::hash_code TileStoreOp::computePropertiesHash(const Properties &prop) {
1127
+ using llvm::hash_value;
1128
+ return llvm::hash_combine();
1129
+ }
1130
+
1131
+ std::optional<mlir::Attribute> TileStoreOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) {
1132
+ return std::nullopt;
1133
+ }
1134
+
1135
+ void TileStoreOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) {
1136
+ }
1137
+
1138
+ void TileStoreOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) {
1139
+ }
1140
+
1141
+ ::llvm::LogicalResult TileStoreOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
1142
+ return ::mlir::success();
1143
+ }
1144
+
1145
+ void TileStoreOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value base, ::mlir::ValueRange indices, ::mlir::Value val) {
1146
+ odsState.addOperands(base);
1147
+ odsState.addOperands(indices);
1148
+ odsState.addOperands(val);
1149
+ }
1150
+
1151
+ void TileStoreOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value base, ::mlir::ValueRange indices, ::mlir::Value val) {
1152
+ odsState.addOperands(base);
1153
+ odsState.addOperands(indices);
1154
+ odsState.addOperands(val);
1155
+ assert(resultTypes.size() == 0u && "mismatched number of results");
1156
+ odsState.addTypes(resultTypes);
1157
+ }
1158
+
1159
+ void TileStoreOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
1160
+ assert(operands.size() >= 2u && "mismatched number of parameters");
1161
+ odsState.addOperands(operands);
1162
+ odsState.addAttributes(attributes);
1163
+ assert(resultTypes.size() == 0u && "mismatched number of return types");
1164
+ odsState.addTypes(resultTypes);
1165
+ }
1166
+
1167
+ void TileStoreOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) {
1168
+ assert(operands.size() >= 2u && "mismatched number of parameters");
1169
+ odsState.addOperands(operands);
1170
+ odsState.useProperties(const_cast<Properties&>(properties));
1171
+ odsState.addAttributes(discardableAttributes);
1172
+ assert(resultTypes.size() == 0u && "mismatched number of return types");
1173
+ odsState.addTypes(resultTypes);
1174
+ }
1175
+
1176
+ ::llvm::LogicalResult TileStoreOp::verifyInvariantsImpl() {
1177
+ {
1178
+ unsigned index = 0; (void)index;
1179
+ auto valueGroup0 = getODSOperands(0);
1180
+
1181
+ for (auto v : valueGroup0) {
1182
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX1(*this, v.getType(), "operand", index++)))
1183
+ return ::mlir::failure();
1184
+ }
1185
+ auto valueGroup1 = getODSOperands(1);
1186
+
1187
+ for (auto v : valueGroup1) {
1188
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX2(*this, v.getType(), "operand", index++)))
1189
+ return ::mlir::failure();
1190
+ }
1191
+ auto valueGroup2 = getODSOperands(2);
1192
+
1193
+ for (auto v : valueGroup2) {
1194
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX3(*this, v.getType(), "operand", index++)))
1195
+ return ::mlir::failure();
1196
+ }
1197
+ }
1198
+ return ::mlir::success();
1199
+ }
1200
+
1201
+ ::llvm::LogicalResult TileStoreOp::verifyInvariants() {
1202
+ if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify()))
1203
+ return ::mlir::success();
1204
+ return ::mlir::failure();
1205
+ }
1206
+
1207
+ ::mlir::ParseResult TileStoreOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) {
1208
+ ::mlir::OpAsmParser::UnresolvedOperand baseRawOperand{};
1209
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> baseOperands(&baseRawOperand, 1); ::llvm::SMLoc baseOperandsLoc;
1210
+ (void)baseOperandsLoc;
1211
+ ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> indicesOperands;
1212
+ ::llvm::SMLoc indicesOperandsLoc;
1213
+ (void)indicesOperandsLoc;
1214
+ ::mlir::OpAsmParser::UnresolvedOperand valRawOperand{};
1215
+ ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> valOperands(&valRawOperand, 1); ::llvm::SMLoc valOperandsLoc;
1216
+ (void)valOperandsLoc;
1217
+ ::mlir::Type baseRawType{};
1218
+ ::llvm::ArrayRef<::mlir::Type> baseTypes(&baseRawType, 1);
1219
+ ::mlir::Type valRawType{};
1220
+ ::llvm::ArrayRef<::mlir::Type> valTypes(&valRawType, 1);
1221
+
1222
+ baseOperandsLoc = parser.getCurrentLocation();
1223
+ if (parser.parseOperand(baseRawOperand))
1224
+ return ::mlir::failure();
1225
+ if (parser.parseLSquare())
1226
+ return ::mlir::failure();
1227
+
1228
+ indicesOperandsLoc = parser.getCurrentLocation();
1229
+ if (parser.parseOperandList(indicesOperands))
1230
+ return ::mlir::failure();
1231
+ if (parser.parseRSquare())
1232
+ return ::mlir::failure();
1233
+ if (parser.parseComma())
1234
+ return ::mlir::failure();
1235
+
1236
+ valOperandsLoc = parser.getCurrentLocation();
1237
+ if (parser.parseOperand(valRawOperand))
1238
+ return ::mlir::failure();
1239
+ {
1240
+ auto loc = parser.getCurrentLocation();(void)loc;
1241
+ if (parser.parseOptionalAttrDict(result.attributes))
1242
+ return ::mlir::failure();
1243
+ if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
1244
+ return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op ";
1245
+ })))
1246
+ return ::mlir::failure();
1247
+ }
1248
+ if (parser.parseColon())
1249
+ return ::mlir::failure();
1250
+
1251
+ {
1252
+ ::mlir::MemRefType type;
1253
+ if (parser.parseCustomTypeWithFallback(type))
1254
+ return ::mlir::failure();
1255
+ baseRawType = type;
1256
+ }
1257
+ if (parser.parseComma())
1258
+ return ::mlir::failure();
1259
+
1260
+ if (parser.parseType(valRawType))
1261
+ return ::mlir::failure();
1262
+ ::mlir::Type odsBuildableType0 = parser.getBuilder().getIndexType();
1263
+ if (parser.resolveOperands(baseOperands, baseTypes, baseOperandsLoc, result.operands))
1264
+ return ::mlir::failure();
1265
+ if (parser.resolveOperands(indicesOperands, odsBuildableType0, indicesOperandsLoc, result.operands))
1266
+ return ::mlir::failure();
1267
+ if (parser.resolveOperands(valOperands, valTypes, valOperandsLoc, result.operands))
1268
+ return ::mlir::failure();
1269
+ return ::mlir::success();
1270
+ }
1271
+
1272
+ void TileStoreOp::print(::mlir::OpAsmPrinter &_odsPrinter) {
1273
+ _odsPrinter << ' ';
1274
+ _odsPrinter << getBase();
1275
+ _odsPrinter << "[";
1276
+ _odsPrinter << getIndices();
1277
+ _odsPrinter << "]";
1278
+ _odsPrinter << ",";
1279
+ _odsPrinter << ' ';
1280
+ _odsPrinter << getVal();
1281
+ ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;
1282
+ _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs);
1283
+ _odsPrinter << ' ' << ":";
1284
+ _odsPrinter << ' ';
1285
+ {
1286
+ auto type = getBase().getType();
1287
+ if (auto validType = ::llvm::dyn_cast<::mlir::MemRefType>(type))
1288
+ _odsPrinter.printStrippedAttrOrType(validType);
1289
+ else
1290
+ _odsPrinter << type;
1291
+ }
1292
+ _odsPrinter << ",";
1293
+ _odsPrinter << ' ';
1294
+ _odsPrinter << getVal().getType();
1295
+ }
1296
+
1297
+ void TileStoreOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) {
1298
+ {
1299
+ auto valueRange = getODSOperandIndexAndLength(0);
1300
+ for (unsigned idx = valueRange.first; idx < valueRange.first + valueRange.second; idx++) {
1301
+ effects.emplace_back(::mlir::MemoryEffects::Write::get(), &getOperation()->getOpOperand(idx), 0, false, ::mlir::SideEffects::DefaultResource::get());
1302
+ }
1303
+ }
1304
+ }
1305
+
1306
+ } // namespace amx
1307
+ } // namespace mlir
1308
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amx::TileStoreOp)
1309
+
1310
+ namespace mlir {
1311
+ namespace amx {
1312
+
1313
+ //===----------------------------------------------------------------------===//
1314
+ // ::mlir::amx::TileZeroOp definitions
1315
+ //===----------------------------------------------------------------------===//
1316
+
1317
+ namespace detail {
1318
+ TileZeroOpGenericAdaptorBase::TileZeroOpGenericAdaptorBase(TileZeroOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {}
1319
+
1320
+ } // namespace detail
1321
+ TileZeroOpAdaptor::TileZeroOpAdaptor(TileZeroOp op) : TileZeroOpGenericAdaptor(op->getOperands(), op) {}
1322
+
1323
+ ::llvm::LogicalResult TileZeroOpAdaptor::verify(::mlir::Location loc) {
1324
+ return ::mlir::success();
1325
+ }
1326
+
1327
+ ::llvm::LogicalResult TileZeroOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
1328
+ ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr);
1329
+ if (!dict) {
1330
+ emitError() << "expected DictionaryAttr to set properties";
1331
+ return ::mlir::failure();
1332
+ }
1333
+ return ::mlir::success();
1334
+ }
1335
+
1336
+ ::mlir::Attribute TileZeroOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) {
1337
+ ::mlir::SmallVector<::mlir::NamedAttribute> attrs;
1338
+ ::mlir::Builder odsBuilder{ctx};
1339
+
1340
+ if (!attrs.empty())
1341
+ return odsBuilder.getDictionaryAttr(attrs);
1342
+ return {};
1343
+ }
1344
+
1345
+ llvm::hash_code TileZeroOp::computePropertiesHash(const Properties &prop) {
1346
+ using llvm::hash_value;
1347
+ return llvm::hash_combine();
1348
+ }
1349
+
1350
+ std::optional<mlir::Attribute> TileZeroOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) {
1351
+ return std::nullopt;
1352
+ }
1353
+
1354
+ void TileZeroOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) {
1355
+ }
1356
+
1357
+ void TileZeroOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) {
1358
+ }
1359
+
1360
+ ::llvm::LogicalResult TileZeroOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {
1361
+ return ::mlir::success();
1362
+ }
1363
+
1364
+ void TileZeroOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res) {
1365
+ odsState.addTypes(res);
1366
+ }
1367
+
1368
+ void TileZeroOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes) {
1369
+ assert(resultTypes.size() == 1u && "mismatched number of results");
1370
+ odsState.addTypes(resultTypes);
1371
+ }
1372
+
1373
+ void TileZeroOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
1374
+ assert(operands.size() == 0u && "mismatched number of parameters");
1375
+ odsState.addOperands(operands);
1376
+ odsState.addAttributes(attributes);
1377
+ assert(resultTypes.size() == 1u && "mismatched number of return types");
1378
+ odsState.addTypes(resultTypes);
1379
+ }
1380
+
1381
+ void TileZeroOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) {
1382
+ assert(operands.size() == 0u && "mismatched number of parameters");
1383
+ odsState.addOperands(operands);
1384
+ odsState.useProperties(const_cast<Properties&>(properties));
1385
+ odsState.addAttributes(discardableAttributes);
1386
+ assert(resultTypes.size() == 1u && "mismatched number of return types");
1387
+ odsState.addTypes(resultTypes);
1388
+ }
1389
+
1390
+ ::llvm::LogicalResult TileZeroOp::verifyInvariantsImpl() {
1391
+ {
1392
+ unsigned index = 0; (void)index;
1393
+ auto valueGroup0 = getODSResults(0);
1394
+
1395
+ for (auto v : valueGroup0) {
1396
+ if (::mlir::failed(__mlir_ods_local_type_constraint_AMX3(*this, v.getType(), "result", index++)))
1397
+ return ::mlir::failure();
1398
+ }
1399
+ }
1400
+ return ::mlir::success();
1401
+ }
1402
+
1403
+ ::llvm::LogicalResult TileZeroOp::verifyInvariants() {
1404
+ if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify()))
1405
+ return ::mlir::success();
1406
+ return ::mlir::failure();
1407
+ }
1408
+
1409
+ ::mlir::ParseResult TileZeroOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) {
1410
+ ::mlir::Type resRawType{};
1411
+ ::llvm::ArrayRef<::mlir::Type> resTypes(&resRawType, 1);
1412
+ {
1413
+ auto loc = parser.getCurrentLocation();(void)loc;
1414
+ if (parser.parseOptionalAttrDict(result.attributes))
1415
+ return ::mlir::failure();
1416
+ if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
1417
+ return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op ";
1418
+ })))
1419
+ return ::mlir::failure();
1420
+ }
1421
+ if (parser.parseColon())
1422
+ return ::mlir::failure();
1423
+
1424
+ if (parser.parseType(resRawType))
1425
+ return ::mlir::failure();
1426
+ result.addTypes(resTypes);
1427
+ return ::mlir::success();
1428
+ }
1429
+
1430
+ void TileZeroOp::print(::mlir::OpAsmPrinter &_odsPrinter) {
1431
+ ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;
1432
+ _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs);
1433
+ _odsPrinter << ' ' << ":";
1434
+ _odsPrinter << ' ';
1435
+ _odsPrinter << getRes().getType();
1436
+ }
1437
+
1438
+ void TileZeroOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) {
1439
+ }
1440
+
1441
+ } // namespace amx
1442
+ } // namespace mlir
1443
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amx::TileZeroOp)
1444
+
1445
+
1446
+ #endif // GET_OP_CLASSES
1447
+
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMX.h.inc ADDED
@@ -0,0 +1,1105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Op Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AMX.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ namespace mlir {
11
+ namespace amx {
12
+ /// tile load operation
13
+ /// Loads a tile from memory defined by a base and indices, with the
14
+ /// shape defined by the 2-dim vector type of the result. This is
15
+ /// eventually lowered into the "tileloadd" instruction with the
16
+ /// corresponding tile configuration.
17
+ ///
18
+ /// Example:
19
+ ///
20
+ /// ```mlir
21
+ /// %0 = amx.tile_load %arg0[%c0, %c0] : memref<?x?xi8> into !amx.tile<16x64xi8>
22
+ /// ```
23
+ class TileLoadOp;
24
+ } // namespace amx
25
+ } // namespace mlir
26
+ namespace mlir {
27
+ namespace amx {
28
+ /// tile multiplication operation (floating-point)
29
+ /// Multiplies a "m x k" tile with a "k x n" tile and accumulates the results
30
+ /// into a "m x n" destination tile. Supports "f32 <- bf16 x bf16" (with
31
+ /// pairs of "bf16"). The operation is eventually lowered into the
32
+ /// "tdpbf16ps" instruction with the corresponding tile configuration.
33
+ ///
34
+ /// Example:
35
+ ///
36
+ /// ```mlir
37
+ /// %0 = amx.tile_mulf %a, %b, %c
38
+ /// : !amx.tile<16x32xbf16>, !amx.tile<16x32xbf16>, !amx.tile<16x16xf32>
39
+ /// ```
40
+ class TileMulFOp;
41
+ } // namespace amx
42
+ } // namespace mlir
43
+ namespace mlir {
44
+ namespace amx {
45
+ /// tile multiplication operation (integer)
46
+ /// Multiplies a "m x k" tile with a "k x n" tile and accumulates the results
47
+ /// into a "m x n" destination tile. Supports all "si32 <- s/ui8 x s/ui8"
48
+ /// combinations (4 bytes packed into dwords in the columns of both the
49
+ /// source operand tiles; the zero or sign extension is specified with
50
+ /// the attributes and default to sign extended). The operation is eventually
51
+ /// lowered into one of the "tdpbssd", "tdpbsud", "tdpbusd", or "tdpbuud"
52
+ /// instructions with the corresponding tile configuration.
53
+ ///
54
+ /// Example:
55
+ ///
56
+ /// ```mlir
57
+ /// %0 = amx.tile_muli %a zext, %b zext, %c
58
+ /// : !amx.tile<16x64xi8>, !amx.tile<16x64xi8>, !amx.tile<16x16xi32>
59
+ /// ```
60
+ class TileMulIOp;
61
+ } // namespace amx
62
+ } // namespace mlir
63
+ namespace mlir {
64
+ namespace amx {
65
+ /// tile store operation
66
+ /// Stores a tile to memory defined by a base and indices, with the
67
+ /// shape defined by the 2-dim vector type of the value. This is
68
+ /// eventually lowered into the "tilestored" instruction with the
69
+ /// corresponding tile configuration.
70
+ ///
71
+ /// Example:
72
+ ///
73
+ /// ```mlir
74
+ /// amx.tile_store %arg1[%c0, %c0], %0 : memref<?x?xi8>, !amx.tile<16x64xi8>
75
+ /// ```
76
+ class TileStoreOp;
77
+ } // namespace amx
78
+ } // namespace mlir
79
+ namespace mlir {
80
+ namespace amx {
81
+ /// tile zero operation
82
+ /// Zeroes the destination tile, with the shape defined by the 2-dim
83
+ /// vector type of the result. This is eventually lowered into the
84
+ /// "tilezero" instruction with the corresponding tile configuration.
85
+ ///
86
+ /// Example:
87
+ ///
88
+ /// ```mlir
89
+ /// %0 = amx.tile_zero : !amx.tile<16x16xbf16>
90
+ /// ```
91
+ class TileZeroOp;
92
+ } // namespace amx
93
+ } // namespace mlir
94
+ #ifdef GET_OP_CLASSES
95
+ #undef GET_OP_CLASSES
96
+
97
+ namespace mlir {
98
+ namespace amx {
99
+
100
+ //===----------------------------------------------------------------------===//
101
+ // ::mlir::amx::TileLoadOp declarations
102
+ //===----------------------------------------------------------------------===//
103
+
104
+ namespace detail {
105
+ class TileLoadOpGenericAdaptorBase {
106
+ public:
107
+ using Properties = ::mlir::EmptyProperties;
108
+ protected:
109
+ ::mlir::DictionaryAttr odsAttrs;
110
+ ::std::optional<::mlir::OperationName> odsOpName;
111
+ Properties properties;
112
+ ::mlir::RegionRange odsRegions;
113
+ public:
114
+ TileLoadOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs)
115
+ odsOpName.emplace("amx.tile_load", odsAttrs.getContext());
116
+ }
117
+
118
+ TileLoadOpGenericAdaptorBase(TileLoadOp op);
119
+
120
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize);
121
+ const Properties &getProperties() {
122
+ return properties;
123
+ }
124
+
125
+ ::mlir::DictionaryAttr getAttributes() {
126
+ return odsAttrs;
127
+ }
128
+
129
+ };
130
+ } // namespace detail
131
+ template <typename RangeT>
132
+ class TileLoadOpGenericAdaptor : public detail::TileLoadOpGenericAdaptorBase {
133
+ using ValueT = ::llvm::detail::ValueOfRange<RangeT>;
134
+ using Base = detail::TileLoadOpGenericAdaptorBase;
135
+ public:
136
+ TileLoadOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {}
137
+
138
+ TileLoadOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TileLoadOpGenericAdaptor(values, attrs, (properties ? *properties.as<Properties *>() : Properties{}), regions) {}
139
+
140
+ TileLoadOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : TileLoadOpGenericAdaptor(values, attrs, Properties{}, {}) {}
141
+
142
+ TileLoadOpGenericAdaptor(RangeT values, const TileLoadOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {}
143
+
144
+ template <typename LateInst = TileLoadOp, typename = std::enable_if_t<std::is_same_v<LateInst, TileLoadOp>>>
145
+ TileLoadOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {}
146
+
147
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) {
148
+ return Base::getODSOperandIndexAndLength(index, odsOperands.size());
149
+ }
150
+
151
+ RangeT getODSOperands(unsigned index) {
152
+ auto valueRange = getODSOperandIndexAndLength(index);
153
+ return {std::next(odsOperands.begin(), valueRange.first),
154
+ std::next(odsOperands.begin(), valueRange.first + valueRange.second)};
155
+ }
156
+
157
+ ValueT getBase() {
158
+ return (*getODSOperands(0).begin());
159
+ }
160
+
161
+ RangeT getIndices() {
162
+ return getODSOperands(1);
163
+ }
164
+
165
+ RangeT getOperands() {
166
+ return odsOperands;
167
+ }
168
+
169
+ private:
170
+ RangeT odsOperands;
171
+ };
172
+ class TileLoadOpAdaptor : public TileLoadOpGenericAdaptor<::mlir::ValueRange> {
173
+ public:
174
+ using TileLoadOpGenericAdaptor::TileLoadOpGenericAdaptor;
175
+ TileLoadOpAdaptor(TileLoadOp op);
176
+
177
+ ::llvm::LogicalResult verify(::mlir::Location loc);
178
+ };
179
+ class TileLoadOp : public ::mlir::Op<TileLoadOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::OneResult, ::mlir::OpTrait::OneTypedResult<::mlir::amx::TileType>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::AtLeastNOperands<1>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::LLVM::OneToOneIntrinsicOpInterface::Trait, ::mlir::amx::AMXIntrinsicOp::Trait> {
180
+ public:
181
+ using Op::Op;
182
+ using Op::print;
183
+ using Adaptor = TileLoadOpAdaptor;
184
+ template <typename RangeT>
185
+ using GenericAdaptor = TileLoadOpGenericAdaptor<RangeT>;
186
+ using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>;
187
+ using Properties = FoldAdaptor::Properties;
188
+ static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() {
189
+ return {};
190
+ }
191
+
192
+ static constexpr ::llvm::StringLiteral getOperationName() {
193
+ return ::llvm::StringLiteral("amx.tile_load");
194
+ }
195
+
196
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index);
197
+ ::mlir::Operation::operand_range getODSOperands(unsigned index) {
198
+ auto valueRange = getODSOperandIndexAndLength(index);
199
+ return {std::next(getOperation()->operand_begin(), valueRange.first),
200
+ std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)};
201
+ }
202
+
203
+ ::mlir::TypedValue<::mlir::MemRefType> getBase() {
204
+ return ::llvm::cast<::mlir::TypedValue<::mlir::MemRefType>>(*getODSOperands(0).begin());
205
+ }
206
+
207
+ ::mlir::Operation::operand_range getIndices() {
208
+ return getODSOperands(1);
209
+ }
210
+
211
+ ::mlir::OpOperand &getBaseMutable() {
212
+ auto range = getODSOperandIndexAndLength(0);
213
+ return getOperation()->getOpOperand(range.first);
214
+ }
215
+
216
+ ::mlir::MutableOperandRange getIndicesMutable();
217
+ std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index) {
218
+ return {index, 1};
219
+ }
220
+
221
+ ::mlir::Operation::result_range getODSResults(unsigned index) {
222
+ auto valueRange = getODSResultIndexAndLength(index);
223
+ return {std::next(getOperation()->result_begin(), valueRange.first),
224
+ std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)};
225
+ }
226
+
227
+ ::mlir::TypedValue<::mlir::amx::TileType> getRes() {
228
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSResults(0).begin());
229
+ }
230
+
231
+ static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
232
+ static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop);
233
+ static llvm::hash_code computePropertiesHash(const Properties &prop);
234
+ static std::optional<mlir::Attribute> getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name);
235
+ static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value);
236
+ static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs);
237
+ static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
238
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res, ::mlir::Value base, ::mlir::ValueRange indices);
239
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value base, ::mlir::ValueRange indices);
240
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
241
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
242
+ ::llvm::LogicalResult verifyInvariantsImpl();
243
+ ::llvm::LogicalResult verifyInvariants();
244
+ ::llvm::LogicalResult verify();
245
+ static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result);
246
+ void print(::mlir::OpAsmPrinter &_odsPrinter);
247
+ void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects);
248
+ public:
249
+ MemRefType getMemRefType() {
250
+ return ::llvm::cast<MemRefType>(getBase().getType());
251
+ }
252
+ TileType getTileType() {
253
+ return ::llvm::cast<TileType>(getRes().getType());
254
+ }
255
+
256
+ std::string getIntrinsicName() {
257
+ return "llvm.x86.tileloadd64.internal";
258
+ }
259
+ SmallVector<Value> getIntrinsicOperands(
260
+ ::mlir::ArrayRef<Value> operands,
261
+ const ::mlir::LLVMTypeConverter &typeConverter,
262
+ ::mlir::RewriterBase &rewriter);
263
+ };
264
+ } // namespace amx
265
+ } // namespace mlir
266
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amx::TileLoadOp)
267
+
268
+ namespace mlir {
269
+ namespace amx {
270
+
271
+ //===----------------------------------------------------------------------===//
272
+ // ::mlir::amx::TileMulFOp declarations
273
+ //===----------------------------------------------------------------------===//
274
+
275
+ namespace detail {
276
+ class TileMulFOpGenericAdaptorBase {
277
+ public:
278
+ using Properties = ::mlir::EmptyProperties;
279
+ protected:
280
+ ::mlir::DictionaryAttr odsAttrs;
281
+ ::std::optional<::mlir::OperationName> odsOpName;
282
+ Properties properties;
283
+ ::mlir::RegionRange odsRegions;
284
+ public:
285
+ TileMulFOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs)
286
+ odsOpName.emplace("amx.tile_mulf", odsAttrs.getContext());
287
+ }
288
+
289
+ TileMulFOpGenericAdaptorBase(TileMulFOp op);
290
+
291
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) {
292
+ return {index, 1};
293
+ }
294
+
295
+ const Properties &getProperties() {
296
+ return properties;
297
+ }
298
+
299
+ ::mlir::DictionaryAttr getAttributes() {
300
+ return odsAttrs;
301
+ }
302
+
303
+ };
304
+ } // namespace detail
305
+ template <typename RangeT>
306
+ class TileMulFOpGenericAdaptor : public detail::TileMulFOpGenericAdaptorBase {
307
+ using ValueT = ::llvm::detail::ValueOfRange<RangeT>;
308
+ using Base = detail::TileMulFOpGenericAdaptorBase;
309
+ public:
310
+ TileMulFOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {}
311
+
312
+ TileMulFOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TileMulFOpGenericAdaptor(values, attrs, (properties ? *properties.as<Properties *>() : Properties{}), regions) {}
313
+
314
+ TileMulFOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : TileMulFOpGenericAdaptor(values, attrs, Properties{}, {}) {}
315
+
316
+ TileMulFOpGenericAdaptor(RangeT values, const TileMulFOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {}
317
+
318
+ template <typename LateInst = TileMulFOp, typename = std::enable_if_t<std::is_same_v<LateInst, TileMulFOp>>>
319
+ TileMulFOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {}
320
+
321
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) {
322
+ return Base::getODSOperandIndexAndLength(index, odsOperands.size());
323
+ }
324
+
325
+ RangeT getODSOperands(unsigned index) {
326
+ auto valueRange = getODSOperandIndexAndLength(index);
327
+ return {std::next(odsOperands.begin(), valueRange.first),
328
+ std::next(odsOperands.begin(), valueRange.first + valueRange.second)};
329
+ }
330
+
331
+ ValueT getLhs() {
332
+ return (*getODSOperands(0).begin());
333
+ }
334
+
335
+ ValueT getRhs() {
336
+ return (*getODSOperands(1).begin());
337
+ }
338
+
339
+ ValueT getAcc() {
340
+ return (*getODSOperands(2).begin());
341
+ }
342
+
343
+ RangeT getOperands() {
344
+ return odsOperands;
345
+ }
346
+
347
+ private:
348
+ RangeT odsOperands;
349
+ };
350
+ class TileMulFOpAdaptor : public TileMulFOpGenericAdaptor<::mlir::ValueRange> {
351
+ public:
352
+ using TileMulFOpGenericAdaptor::TileMulFOpGenericAdaptor;
353
+ TileMulFOpAdaptor(TileMulFOp op);
354
+
355
+ ::llvm::LogicalResult verify(::mlir::Location loc);
356
+ };
357
+ class TileMulFOp : public ::mlir::Op<TileMulFOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::OneResult, ::mlir::OpTrait::OneTypedResult<::mlir::amx::TileType>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<3>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::LLVM::OneToOneIntrinsicOpInterface::Trait, ::mlir::amx::AMXIntrinsicOp::Trait> {
358
+ public:
359
+ using Op::Op;
360
+ using Op::print;
361
+ using Adaptor = TileMulFOpAdaptor;
362
+ template <typename RangeT>
363
+ using GenericAdaptor = TileMulFOpGenericAdaptor<RangeT>;
364
+ using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>;
365
+ using Properties = FoldAdaptor::Properties;
366
+ static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() {
367
+ return {};
368
+ }
369
+
370
+ static constexpr ::llvm::StringLiteral getOperationName() {
371
+ return ::llvm::StringLiteral("amx.tile_mulf");
372
+ }
373
+
374
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) {
375
+ return {index, 1};
376
+ }
377
+
378
+ ::mlir::Operation::operand_range getODSOperands(unsigned index) {
379
+ auto valueRange = getODSOperandIndexAndLength(index);
380
+ return {std::next(getOperation()->operand_begin(), valueRange.first),
381
+ std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)};
382
+ }
383
+
384
+ ::mlir::TypedValue<::mlir::amx::TileType> getLhs() {
385
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSOperands(0).begin());
386
+ }
387
+
388
+ ::mlir::TypedValue<::mlir::amx::TileType> getRhs() {
389
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSOperands(1).begin());
390
+ }
391
+
392
+ ::mlir::TypedValue<::mlir::amx::TileType> getAcc() {
393
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSOperands(2).begin());
394
+ }
395
+
396
+ ::mlir::OpOperand &getLhsMutable() {
397
+ auto range = getODSOperandIndexAndLength(0);
398
+ return getOperation()->getOpOperand(range.first);
399
+ }
400
+
401
+ ::mlir::OpOperand &getRhsMutable() {
402
+ auto range = getODSOperandIndexAndLength(1);
403
+ return getOperation()->getOpOperand(range.first);
404
+ }
405
+
406
+ ::mlir::OpOperand &getAccMutable() {
407
+ auto range = getODSOperandIndexAndLength(2);
408
+ return getOperation()->getOpOperand(range.first);
409
+ }
410
+
411
+ std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index) {
412
+ return {index, 1};
413
+ }
414
+
415
+ ::mlir::Operation::result_range getODSResults(unsigned index) {
416
+ auto valueRange = getODSResultIndexAndLength(index);
417
+ return {std::next(getOperation()->result_begin(), valueRange.first),
418
+ std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)};
419
+ }
420
+
421
+ ::mlir::TypedValue<::mlir::amx::TileType> getRes() {
422
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSResults(0).begin());
423
+ }
424
+
425
+ static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
426
+ static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop);
427
+ static llvm::hash_code computePropertiesHash(const Properties &prop);
428
+ static std::optional<mlir::Attribute> getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name);
429
+ static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value);
430
+ static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs);
431
+ static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
432
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc);
433
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc);
434
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
435
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
436
+ ::llvm::LogicalResult verifyInvariantsImpl();
437
+ ::llvm::LogicalResult verifyInvariants();
438
+ ::llvm::LogicalResult verify();
439
+ static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result);
440
+ void print(::mlir::OpAsmPrinter &_odsPrinter);
441
+ void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects);
442
+ public:
443
+ TileType getLhsTileType() {
444
+ return ::llvm::cast<TileType>(getLhs().getType());
445
+ }
446
+ TileType getRhsTileType() {
447
+ return ::llvm::cast<TileType>(getRhs().getType());
448
+ }
449
+ TileType getTileType() {
450
+ return ::llvm::cast<TileType>(getRes().getType());
451
+ }
452
+
453
+ std::string getIntrinsicName() {
454
+ std::string intr = "llvm.x86.tdp";
455
+ auto elementType =
456
+ getLhsTileType().getElementType();
457
+ intr += elementType.isF16() ? "fp16" : "bf16";
458
+ intr += "ps.internal";
459
+ return intr;
460
+ }
461
+ SmallVector<Value> getIntrinsicOperands(
462
+ ::mlir::ArrayRef<Value> operands,
463
+ const ::mlir::LLVMTypeConverter &typeConverter,
464
+ ::mlir::RewriterBase &rewriter);
465
+ };
466
+ } // namespace amx
467
+ } // namespace mlir
468
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amx::TileMulFOp)
469
+
470
+ namespace mlir {
471
+ namespace amx {
472
+
473
+ //===----------------------------------------------------------------------===//
474
+ // ::mlir::amx::TileMulIOp declarations
475
+ //===----------------------------------------------------------------------===//
476
+
477
+ namespace detail {
478
+ class TileMulIOpGenericAdaptorBase {
479
+ public:
480
+ struct Properties {
481
+ using isZextLhsTy = ::mlir::UnitAttr;
482
+ isZextLhsTy isZextLhs;
483
+
484
+ auto getIsZextLhs() const {
485
+ auto &propStorage = this->isZextLhs;
486
+ return ::llvm::dyn_cast_or_null<::mlir::UnitAttr>(propStorage);
487
+ }
488
+ void setIsZextLhs(const ::mlir::UnitAttr &propValue) {
489
+ this->isZextLhs = propValue;
490
+ }
491
+ using isZextRhsTy = ::mlir::UnitAttr;
492
+ isZextRhsTy isZextRhs;
493
+
494
+ auto getIsZextRhs() const {
495
+ auto &propStorage = this->isZextRhs;
496
+ return ::llvm::dyn_cast_or_null<::mlir::UnitAttr>(propStorage);
497
+ }
498
+ void setIsZextRhs(const ::mlir::UnitAttr &propValue) {
499
+ this->isZextRhs = propValue;
500
+ }
501
+ bool operator==(const Properties &rhs) const {
502
+ return
503
+ rhs.isZextLhs == this->isZextLhs &&
504
+ rhs.isZextRhs == this->isZextRhs &&
505
+ true;
506
+ }
507
+ bool operator!=(const Properties &rhs) const {
508
+ return !(*this == rhs);
509
+ }
510
+ };
511
+ protected:
512
+ ::mlir::DictionaryAttr odsAttrs;
513
+ ::std::optional<::mlir::OperationName> odsOpName;
514
+ Properties properties;
515
+ ::mlir::RegionRange odsRegions;
516
+ public:
517
+ TileMulIOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs)
518
+ odsOpName.emplace("amx.tile_muli", odsAttrs.getContext());
519
+ }
520
+
521
+ TileMulIOpGenericAdaptorBase(TileMulIOp op);
522
+
523
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) {
524
+ return {index, 1};
525
+ }
526
+
527
+ const Properties &getProperties() {
528
+ return properties;
529
+ }
530
+
531
+ ::mlir::DictionaryAttr getAttributes() {
532
+ return odsAttrs;
533
+ }
534
+
535
+ ::mlir::UnitAttr getIsZextLhsAttr();
536
+ bool getIsZextLhs();
537
+ ::mlir::UnitAttr getIsZextRhsAttr();
538
+ bool getIsZextRhs();
539
+ };
540
+ } // namespace detail
541
+ template <typename RangeT>
542
+ class TileMulIOpGenericAdaptor : public detail::TileMulIOpGenericAdaptorBase {
543
+ using ValueT = ::llvm::detail::ValueOfRange<RangeT>;
544
+ using Base = detail::TileMulIOpGenericAdaptorBase;
545
+ public:
546
+ TileMulIOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {}
547
+
548
+ TileMulIOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TileMulIOpGenericAdaptor(values, attrs, (properties ? *properties.as<Properties *>() : Properties{}), regions) {}
549
+
550
+ TileMulIOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : TileMulIOpGenericAdaptor(values, attrs, Properties{}, {}) {}
551
+
552
+ TileMulIOpGenericAdaptor(RangeT values, const TileMulIOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {}
553
+
554
+ template <typename LateInst = TileMulIOp, typename = std::enable_if_t<std::is_same_v<LateInst, TileMulIOp>>>
555
+ TileMulIOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {}
556
+
557
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) {
558
+ return Base::getODSOperandIndexAndLength(index, odsOperands.size());
559
+ }
560
+
561
+ RangeT getODSOperands(unsigned index) {
562
+ auto valueRange = getODSOperandIndexAndLength(index);
563
+ return {std::next(odsOperands.begin(), valueRange.first),
564
+ std::next(odsOperands.begin(), valueRange.first + valueRange.second)};
565
+ }
566
+
567
+ ValueT getLhs() {
568
+ return (*getODSOperands(0).begin());
569
+ }
570
+
571
+ ValueT getRhs() {
572
+ return (*getODSOperands(1).begin());
573
+ }
574
+
575
+ ValueT getAcc() {
576
+ return (*getODSOperands(2).begin());
577
+ }
578
+
579
+ RangeT getOperands() {
580
+ return odsOperands;
581
+ }
582
+
583
+ private:
584
+ RangeT odsOperands;
585
+ };
586
+ class TileMulIOpAdaptor : public TileMulIOpGenericAdaptor<::mlir::ValueRange> {
587
+ public:
588
+ using TileMulIOpGenericAdaptor::TileMulIOpGenericAdaptor;
589
+ TileMulIOpAdaptor(TileMulIOp op);
590
+
591
+ ::llvm::LogicalResult verify(::mlir::Location loc);
592
+ };
593
+ class TileMulIOp : public ::mlir::Op<TileMulIOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::OneResult, ::mlir::OpTrait::OneTypedResult<::mlir::amx::TileType>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<3>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::LLVM::OneToOneIntrinsicOpInterface::Trait, ::mlir::amx::AMXIntrinsicOp::Trait> {
594
+ public:
595
+ using Op::Op;
596
+ using Op::print;
597
+ using Adaptor = TileMulIOpAdaptor;
598
+ template <typename RangeT>
599
+ using GenericAdaptor = TileMulIOpGenericAdaptor<RangeT>;
600
+ using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>;
601
+ using Properties = FoldAdaptor::Properties;
602
+ static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() {
603
+ static ::llvm::StringRef attrNames[] = {::llvm::StringRef("isZextLhs"), ::llvm::StringRef("isZextRhs")};
604
+ return ::llvm::ArrayRef(attrNames);
605
+ }
606
+
607
+ ::mlir::StringAttr getIsZextLhsAttrName() {
608
+ return getAttributeNameForIndex(0);
609
+ }
610
+
611
+ static ::mlir::StringAttr getIsZextLhsAttrName(::mlir::OperationName name) {
612
+ return getAttributeNameForIndex(name, 0);
613
+ }
614
+
615
+ ::mlir::StringAttr getIsZextRhsAttrName() {
616
+ return getAttributeNameForIndex(1);
617
+ }
618
+
619
+ static ::mlir::StringAttr getIsZextRhsAttrName(::mlir::OperationName name) {
620
+ return getAttributeNameForIndex(name, 1);
621
+ }
622
+
623
+ static constexpr ::llvm::StringLiteral getOperationName() {
624
+ return ::llvm::StringLiteral("amx.tile_muli");
625
+ }
626
+
627
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) {
628
+ return {index, 1};
629
+ }
630
+
631
+ ::mlir::Operation::operand_range getODSOperands(unsigned index) {
632
+ auto valueRange = getODSOperandIndexAndLength(index);
633
+ return {std::next(getOperation()->operand_begin(), valueRange.first),
634
+ std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)};
635
+ }
636
+
637
+ ::mlir::TypedValue<::mlir::amx::TileType> getLhs() {
638
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSOperands(0).begin());
639
+ }
640
+
641
+ ::mlir::TypedValue<::mlir::amx::TileType> getRhs() {
642
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSOperands(1).begin());
643
+ }
644
+
645
+ ::mlir::TypedValue<::mlir::amx::TileType> getAcc() {
646
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSOperands(2).begin());
647
+ }
648
+
649
+ ::mlir::OpOperand &getLhsMutable() {
650
+ auto range = getODSOperandIndexAndLength(0);
651
+ return getOperation()->getOpOperand(range.first);
652
+ }
653
+
654
+ ::mlir::OpOperand &getRhsMutable() {
655
+ auto range = getODSOperandIndexAndLength(1);
656
+ return getOperation()->getOpOperand(range.first);
657
+ }
658
+
659
+ ::mlir::OpOperand &getAccMutable() {
660
+ auto range = getODSOperandIndexAndLength(2);
661
+ return getOperation()->getOpOperand(range.first);
662
+ }
663
+
664
+ std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index) {
665
+ return {index, 1};
666
+ }
667
+
668
+ ::mlir::Operation::result_range getODSResults(unsigned index) {
669
+ auto valueRange = getODSResultIndexAndLength(index);
670
+ return {std::next(getOperation()->result_begin(), valueRange.first),
671
+ std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)};
672
+ }
673
+
674
+ ::mlir::TypedValue<::mlir::amx::TileType> getRes() {
675
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSResults(0).begin());
676
+ }
677
+
678
+ static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
679
+ static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop);
680
+ static llvm::hash_code computePropertiesHash(const Properties &prop);
681
+ static std::optional<mlir::Attribute> getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name);
682
+ static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value);
683
+ static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs);
684
+ static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
685
+ static ::llvm::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state);
686
+ void writeProperties(::mlir::DialectBytecodeWriter &writer);
687
+ ::mlir::UnitAttr getIsZextLhsAttr() {
688
+ return ::llvm::dyn_cast_or_null<::mlir::UnitAttr>(getProperties().isZextLhs);
689
+ }
690
+
691
+ bool getIsZextLhs();
692
+ ::mlir::UnitAttr getIsZextRhsAttr() {
693
+ return ::llvm::dyn_cast_or_null<::mlir::UnitAttr>(getProperties().isZextRhs);
694
+ }
695
+
696
+ bool getIsZextRhs();
697
+ void setIsZextLhsAttr(::mlir::UnitAttr attr) {
698
+ getProperties().isZextLhs = attr;
699
+ }
700
+
701
+ void setIsZextLhs(bool attrValue);
702
+ void setIsZextRhsAttr(::mlir::UnitAttr attr) {
703
+ getProperties().isZextRhs = attr;
704
+ }
705
+
706
+ void setIsZextRhs(bool attrValue);
707
+ ::mlir::Attribute removeIsZextLhsAttr() {
708
+ auto attr = getProperties().isZextLhs;
709
+ getProperties().isZextLhs = {};
710
+ return attr;
711
+ }
712
+
713
+ ::mlir::Attribute removeIsZextRhsAttr() {
714
+ auto attr = getProperties().isZextRhs;
715
+ getProperties().isZextRhs = {};
716
+ return attr;
717
+ }
718
+
719
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc, /*optional*/::mlir::UnitAttr isZextLhs, /*optional*/::mlir::UnitAttr isZextRhs = nullptr);
720
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc, /*optional*/::mlir::UnitAttr isZextLhs, /*optional*/::mlir::UnitAttr isZextRhs = nullptr);
721
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc, /*optional*/bool isZextLhs = false, /*optional*/bool isZextRhs = false);
722
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs, ::mlir::Value acc, /*optional*/bool isZextLhs = false, /*optional*/bool isZextRhs = false);
723
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
724
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
725
+ ::llvm::LogicalResult verifyInvariantsImpl();
726
+ ::llvm::LogicalResult verifyInvariants();
727
+ ::llvm::LogicalResult verify();
728
+ static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result);
729
+ void print(::mlir::OpAsmPrinter &_odsPrinter);
730
+ void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects);
731
+ private:
732
+ ::mlir::StringAttr getAttributeNameForIndex(unsigned index) {
733
+ return getAttributeNameForIndex((*this)->getName(), index);
734
+ }
735
+
736
+ static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) {
737
+ assert(index < 2 && "invalid attribute index");
738
+ assert(name.getStringRef() == getOperationName() && "invalid operation name");
739
+ assert(name.isRegistered() && "Operation isn't registered, missing a "
740
+ "dependent dialect loading?");
741
+ return name.getAttributeNames()[index];
742
+ }
743
+
744
+ public:
745
+ TileType getLhsTileType() {
746
+ return ::llvm::cast<TileType>(getLhs().getType());
747
+ }
748
+ TileType getRhsTileType() {
749
+ return ::llvm::cast<TileType>(getRhs().getType());
750
+ }
751
+ TileType getTileType() {
752
+ return ::llvm::cast<TileType>(getRes().getType());
753
+ }
754
+
755
+ std::string getIntrinsicName() {
756
+ std::string intr = "llvm.x86.tdpb";
757
+ intr += getIsZextLhs() ? "u" : "s";
758
+ intr += getIsZextRhs() ? "u" : "s";
759
+ intr += "d.internal";
760
+ return intr;
761
+ }
762
+ SmallVector<Value> getIntrinsicOperands(
763
+ ::mlir::ArrayRef<Value> operands,
764
+ const ::mlir::LLVMTypeConverter &typeConverter,
765
+ ::mlir::RewriterBase &rewriter);
766
+ };
767
+ } // namespace amx
768
+ } // namespace mlir
769
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amx::TileMulIOp)
770
+
771
+ namespace mlir {
772
+ namespace amx {
773
+
774
+ //===----------------------------------------------------------------------===//
775
+ // ::mlir::amx::TileStoreOp declarations
776
+ //===----------------------------------------------------------------------===//
777
+
778
+ namespace detail {
779
+ class TileStoreOpGenericAdaptorBase {
780
+ public:
781
+ using Properties = ::mlir::EmptyProperties;
782
+ protected:
783
+ ::mlir::DictionaryAttr odsAttrs;
784
+ ::std::optional<::mlir::OperationName> odsOpName;
785
+ Properties properties;
786
+ ::mlir::RegionRange odsRegions;
787
+ public:
788
+ TileStoreOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs)
789
+ odsOpName.emplace("amx.tile_store", odsAttrs.getContext());
790
+ }
791
+
792
+ TileStoreOpGenericAdaptorBase(TileStoreOp op);
793
+
794
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize);
795
+ const Properties &getProperties() {
796
+ return properties;
797
+ }
798
+
799
+ ::mlir::DictionaryAttr getAttributes() {
800
+ return odsAttrs;
801
+ }
802
+
803
+ };
804
+ } // namespace detail
805
+ template <typename RangeT>
806
+ class TileStoreOpGenericAdaptor : public detail::TileStoreOpGenericAdaptorBase {
807
+ using ValueT = ::llvm::detail::ValueOfRange<RangeT>;
808
+ using Base = detail::TileStoreOpGenericAdaptorBase;
809
+ public:
810
+ TileStoreOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {}
811
+
812
+ TileStoreOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TileStoreOpGenericAdaptor(values, attrs, (properties ? *properties.as<Properties *>() : Properties{}), regions) {}
813
+
814
+ TileStoreOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : TileStoreOpGenericAdaptor(values, attrs, Properties{}, {}) {}
815
+
816
+ TileStoreOpGenericAdaptor(RangeT values, const TileStoreOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {}
817
+
818
+ template <typename LateInst = TileStoreOp, typename = std::enable_if_t<std::is_same_v<LateInst, TileStoreOp>>>
819
+ TileStoreOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {}
820
+
821
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) {
822
+ return Base::getODSOperandIndexAndLength(index, odsOperands.size());
823
+ }
824
+
825
+ RangeT getODSOperands(unsigned index) {
826
+ auto valueRange = getODSOperandIndexAndLength(index);
827
+ return {std::next(odsOperands.begin(), valueRange.first),
828
+ std::next(odsOperands.begin(), valueRange.first + valueRange.second)};
829
+ }
830
+
831
+ ValueT getBase() {
832
+ return (*getODSOperands(0).begin());
833
+ }
834
+
835
+ RangeT getIndices() {
836
+ return getODSOperands(1);
837
+ }
838
+
839
+ ValueT getVal() {
840
+ return (*getODSOperands(2).begin());
841
+ }
842
+
843
+ RangeT getOperands() {
844
+ return odsOperands;
845
+ }
846
+
847
+ private:
848
+ RangeT odsOperands;
849
+ };
850
+ class TileStoreOpAdaptor : public TileStoreOpGenericAdaptor<::mlir::ValueRange> {
851
+ public:
852
+ using TileStoreOpGenericAdaptor::TileStoreOpGenericAdaptor;
853
+ TileStoreOpAdaptor(TileStoreOp op);
854
+
855
+ ::llvm::LogicalResult verify(::mlir::Location loc);
856
+ };
857
+ class TileStoreOp : public ::mlir::Op<TileStoreOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::ZeroResults, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::AtLeastNOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::LLVM::OneToOneIntrinsicOpInterface::Trait, ::mlir::amx::AMXIntrinsicOp::Trait, ::mlir::MemoryEffectOpInterface::Trait> {
858
+ public:
859
+ using Op::Op;
860
+ using Op::print;
861
+ using Adaptor = TileStoreOpAdaptor;
862
+ template <typename RangeT>
863
+ using GenericAdaptor = TileStoreOpGenericAdaptor<RangeT>;
864
+ using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>;
865
+ using Properties = FoldAdaptor::Properties;
866
+ static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() {
867
+ return {};
868
+ }
869
+
870
+ static constexpr ::llvm::StringLiteral getOperationName() {
871
+ return ::llvm::StringLiteral("amx.tile_store");
872
+ }
873
+
874
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index);
875
+ ::mlir::Operation::operand_range getODSOperands(unsigned index) {
876
+ auto valueRange = getODSOperandIndexAndLength(index);
877
+ return {std::next(getOperation()->operand_begin(), valueRange.first),
878
+ std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)};
879
+ }
880
+
881
+ ::mlir::TypedValue<::mlir::MemRefType> getBase() {
882
+ return ::llvm::cast<::mlir::TypedValue<::mlir::MemRefType>>(*getODSOperands(0).begin());
883
+ }
884
+
885
+ ::mlir::Operation::operand_range getIndices() {
886
+ return getODSOperands(1);
887
+ }
888
+
889
+ ::mlir::TypedValue<::mlir::amx::TileType> getVal() {
890
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSOperands(2).begin());
891
+ }
892
+
893
+ ::mlir::OpOperand &getBaseMutable() {
894
+ auto range = getODSOperandIndexAndLength(0);
895
+ return getOperation()->getOpOperand(range.first);
896
+ }
897
+
898
+ ::mlir::MutableOperandRange getIndicesMutable();
899
+ ::mlir::OpOperand &getValMutable() {
900
+ auto range = getODSOperandIndexAndLength(2);
901
+ return getOperation()->getOpOperand(range.first);
902
+ }
903
+
904
+ std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index) {
905
+ return {index, 1};
906
+ }
907
+
908
+ ::mlir::Operation::result_range getODSResults(unsigned index) {
909
+ auto valueRange = getODSResultIndexAndLength(index);
910
+ return {std::next(getOperation()->result_begin(), valueRange.first),
911
+ std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)};
912
+ }
913
+
914
+ static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
915
+ static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop);
916
+ static llvm::hash_code computePropertiesHash(const Properties &prop);
917
+ static std::optional<mlir::Attribute> getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name);
918
+ static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value);
919
+ static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs);
920
+ static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
921
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value base, ::mlir::ValueRange indices, ::mlir::Value val);
922
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value base, ::mlir::ValueRange indices, ::mlir::Value val);
923
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
924
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
925
+ ::llvm::LogicalResult verifyInvariantsImpl();
926
+ ::llvm::LogicalResult verifyInvariants();
927
+ ::llvm::LogicalResult verify();
928
+ static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result);
929
+ void print(::mlir::OpAsmPrinter &_odsPrinter);
930
+ void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects);
931
+ public:
932
+ MemRefType getMemRefType() {
933
+ return ::llvm::cast<MemRefType>(getBase().getType());
934
+ }
935
+ TileType getTileType() {
936
+ return ::llvm::cast<TileType>(getVal().getType());
937
+ }
938
+
939
+ std::string getIntrinsicName() {
940
+ return "llvm.x86.tilestored64.internal";
941
+ }
942
+ SmallVector<Value> getIntrinsicOperands(
943
+ ::mlir::ArrayRef<Value> operands,
944
+ const ::mlir::LLVMTypeConverter &typeConverter,
945
+ ::mlir::RewriterBase &rewriter);
946
+ };
947
+ } // namespace amx
948
+ } // namespace mlir
949
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amx::TileStoreOp)
950
+
951
+ namespace mlir {
952
+ namespace amx {
953
+
954
+ //===----------------------------------------------------------------------===//
955
+ // ::mlir::amx::TileZeroOp declarations
956
+ //===----------------------------------------------------------------------===//
957
+
958
+ namespace detail {
959
+ class TileZeroOpGenericAdaptorBase {
960
+ public:
961
+ using Properties = ::mlir::EmptyProperties;
962
+ protected:
963
+ ::mlir::DictionaryAttr odsAttrs;
964
+ ::std::optional<::mlir::OperationName> odsOpName;
965
+ Properties properties;
966
+ ::mlir::RegionRange odsRegions;
967
+ public:
968
+ TileZeroOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs)
969
+ odsOpName.emplace("amx.tile_zero", odsAttrs.getContext());
970
+ }
971
+
972
+ TileZeroOpGenericAdaptorBase(TileZeroOp op);
973
+
974
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) {
975
+ return {index, 1};
976
+ }
977
+
978
+ const Properties &getProperties() {
979
+ return properties;
980
+ }
981
+
982
+ ::mlir::DictionaryAttr getAttributes() {
983
+ return odsAttrs;
984
+ }
985
+
986
+ };
987
+ } // namespace detail
988
+ template <typename RangeT>
989
+ class TileZeroOpGenericAdaptor : public detail::TileZeroOpGenericAdaptorBase {
990
+ using ValueT = ::llvm::detail::ValueOfRange<RangeT>;
991
+ using Base = detail::TileZeroOpGenericAdaptorBase;
992
+ public:
993
+ TileZeroOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {}
994
+
995
+ TileZeroOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TileZeroOpGenericAdaptor(values, attrs, (properties ? *properties.as<Properties *>() : Properties{}), regions) {}
996
+
997
+ TileZeroOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : TileZeroOpGenericAdaptor(values, attrs, Properties{}, {}) {}
998
+
999
+ TileZeroOpGenericAdaptor(RangeT values, const TileZeroOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {}
1000
+
1001
+ template <typename LateInst = TileZeroOp, typename = std::enable_if_t<std::is_same_v<LateInst, TileZeroOp>>>
1002
+ TileZeroOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {}
1003
+
1004
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) {
1005
+ return Base::getODSOperandIndexAndLength(index, odsOperands.size());
1006
+ }
1007
+
1008
+ RangeT getODSOperands(unsigned index) {
1009
+ auto valueRange = getODSOperandIndexAndLength(index);
1010
+ return {std::next(odsOperands.begin(), valueRange.first),
1011
+ std::next(odsOperands.begin(), valueRange.first + valueRange.second)};
1012
+ }
1013
+
1014
+ RangeT getOperands() {
1015
+ return odsOperands;
1016
+ }
1017
+
1018
+ private:
1019
+ RangeT odsOperands;
1020
+ };
1021
+ class TileZeroOpAdaptor : public TileZeroOpGenericAdaptor<::mlir::ValueRange> {
1022
+ public:
1023
+ using TileZeroOpGenericAdaptor::TileZeroOpGenericAdaptor;
1024
+ TileZeroOpAdaptor(TileZeroOp op);
1025
+
1026
+ ::llvm::LogicalResult verify(::mlir::Location loc);
1027
+ };
1028
+ class TileZeroOp : public ::mlir::Op<TileZeroOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::OneResult, ::mlir::OpTrait::OneTypedResult<::mlir::amx::TileType>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::LLVM::OneToOneIntrinsicOpInterface::Trait, ::mlir::amx::AMXIntrinsicOp::Trait> {
1029
+ public:
1030
+ using Op::Op;
1031
+ using Op::print;
1032
+ using Adaptor = TileZeroOpAdaptor;
1033
+ template <typename RangeT>
1034
+ using GenericAdaptor = TileZeroOpGenericAdaptor<RangeT>;
1035
+ using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>;
1036
+ using Properties = FoldAdaptor::Properties;
1037
+ static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() {
1038
+ return {};
1039
+ }
1040
+
1041
+ static constexpr ::llvm::StringLiteral getOperationName() {
1042
+ return ::llvm::StringLiteral("amx.tile_zero");
1043
+ }
1044
+
1045
+ std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) {
1046
+ return {index, 1};
1047
+ }
1048
+
1049
+ ::mlir::Operation::operand_range getODSOperands(unsigned index) {
1050
+ auto valueRange = getODSOperandIndexAndLength(index);
1051
+ return {std::next(getOperation()->operand_begin(), valueRange.first),
1052
+ std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)};
1053
+ }
1054
+
1055
+ std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index) {
1056
+ return {index, 1};
1057
+ }
1058
+
1059
+ ::mlir::Operation::result_range getODSResults(unsigned index) {
1060
+ auto valueRange = getODSResultIndexAndLength(index);
1061
+ return {std::next(getOperation()->result_begin(), valueRange.first),
1062
+ std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)};
1063
+ }
1064
+
1065
+ ::mlir::TypedValue<::mlir::amx::TileType> getRes() {
1066
+ return ::llvm::cast<::mlir::TypedValue<::mlir::amx::TileType>>(*getODSResults(0).begin());
1067
+ }
1068
+
1069
+ static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
1070
+ static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop);
1071
+ static llvm::hash_code computePropertiesHash(const Properties &prop);
1072
+ static std::optional<mlir::Attribute> getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name);
1073
+ static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value);
1074
+ static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs);
1075
+ static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);
1076
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type res);
1077
+ static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes);
1078
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
1079
+ static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
1080
+ ::llvm::LogicalResult verifyInvariantsImpl();
1081
+ ::llvm::LogicalResult verifyInvariants();
1082
+ ::llvm::LogicalResult verify();
1083
+ static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result);
1084
+ void print(::mlir::OpAsmPrinter &_odsPrinter);
1085
+ void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects);
1086
+ public:
1087
+ TileType getTileType() {
1088
+ return ::llvm::cast<TileType>(getRes().getType());
1089
+ }
1090
+
1091
+ std::string getIntrinsicName() {
1092
+ return "llvm.x86.tilezero.internal";
1093
+ }
1094
+ SmallVector<Value> getIntrinsicOperands(
1095
+ ::mlir::ArrayRef<Value> operands,
1096
+ const ::mlir::LLVMTypeConverter &typeConverter,
1097
+ ::mlir::RewriterBase &rewriter);
1098
+ };
1099
+ } // namespace amx
1100
+ } // namespace mlir
1101
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amx::TileZeroOp)
1102
+
1103
+
1104
+ #endif // GET_OP_CLASSES
1105
+
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXDialect.cpp.inc ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Dialect Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AMX.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amx::AMXDialect)
11
+ namespace mlir {
12
+ namespace amx {
13
+
14
+ AMXDialect::AMXDialect(::mlir::MLIRContext *context)
15
+ : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get<AMXDialect>())
16
+
17
+ {
18
+
19
+ initialize();
20
+ }
21
+
22
+ AMXDialect::~AMXDialect() = default;
23
+
24
+ } // namespace amx
25
+ } // namespace mlir
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXDialect.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AMXDialect.h - MLIR Dialect for AMX ----------------------*- 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 file declares the Target dialect for AMX in MLIR.
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #ifndef MLIR_DIALECT_AMX_AMXDIALECT_H_
14
+ #define MLIR_DIALECT_AMX_AMXDIALECT_H_
15
+
16
+ #include "mlir/Bytecode/BytecodeOpInterface.h"
17
+ #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
18
+ #include "mlir/IR/BuiltinTypes.h"
19
+ #include "mlir/IR/Dialect.h"
20
+ #include "mlir/IR/OpDefinition.h"
21
+ #include "mlir/Interfaces/SideEffectInterfaces.h"
22
+
23
+ /// Include the generated interface declarations.
24
+ #include "mlir/Dialect/AMX/AMXInterfaces.h.inc"
25
+
26
+ #include "mlir/Dialect/AMX/AMXDialect.h.inc"
27
+
28
+ #define GET_TYPEDEF_CLASSES
29
+ #include "mlir/Dialect/AMX/AMXTypes.h.inc"
30
+
31
+ #define GET_OP_CLASSES
32
+ #include "mlir/Dialect/AMX/AMX.h.inc"
33
+
34
+ #endif // MLIR_DIALECT_AMX_AMXDIALECT_H_
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXDialect.h.inc ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Dialect Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AMX.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ namespace mlir {
11
+ namespace amx {
12
+
13
+ /// The Intel Advanced Matrix Extensions (AMX) provide a tile matrix
14
+ /// multiply unit (TMUL), a tile control register (TILECFG), and eight
15
+ /// tile registers TMM0 through TMM7 (TILEDATA).
16
+ ///
17
+ /// This `AMX` dialect provides a bridge between MLIR concepts such as
18
+ /// vectors and memrefs and the lower level LLVM IR support of AMX.
19
+ ///
20
+ /// Note that since configuration changes (implicit at dialect level) are
21
+ /// costly, it is highly recommended to use the AMX dialect on same-shaped
22
+ /// vectors, at least within a single method.
23
+ ///
24
+ /// For details, see the Intel documentation:
25
+ /// https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html
26
+ class AMXDialect : public ::mlir::Dialect {
27
+ explicit AMXDialect(::mlir::MLIRContext *context);
28
+
29
+ void initialize();
30
+ friend class ::mlir::MLIRContext;
31
+ public:
32
+ ~AMXDialect() override;
33
+ static constexpr ::llvm::StringLiteral getDialectNamespace() {
34
+ return ::llvm::StringLiteral("amx");
35
+ }
36
+
37
+ /// Parse a type registered to this dialect.
38
+ ::mlir::Type parseType(::mlir::DialectAsmParser &parser) const override;
39
+
40
+ /// Print a type registered to this dialect.
41
+ void printType(::mlir::Type type,
42
+ ::mlir::DialectAsmPrinter &os) const override;
43
+ };
44
+ } // namespace amx
45
+ } // namespace mlir
46
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amx::AMXDialect)
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXInterfaces.cpp.inc ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Interface Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+
10
+ /// Returns mangled LLVM intrinsic function name matching the operation
11
+ /// variant.
12
+ std::string mlir::amx::AMXIntrinsicOp::getIntrinsicName() {
13
+ return getImpl()->implOneToOneIntrinsicOpInterface->getIntrinsicName(getImpl()->implOneToOneIntrinsicOpInterface, getOperation());
14
+ }
15
+
16
+ /// Returns operands for a corresponding LLVM intrinsic.
17
+ ///
18
+ /// Additional operations may be created to facilitate mapping
19
+ /// between the source operands and the target intrinsic.
20
+ SmallVector<Value> mlir::amx::AMXIntrinsicOp::getIntrinsicOperands(::mlir::ArrayRef<Value> operands, const ::mlir::LLVMTypeConverter & typeConverter, ::mlir::RewriterBase & rewriter) {
21
+ return getImpl()->implOneToOneIntrinsicOpInterface->getIntrinsicOperands(getImpl()->implOneToOneIntrinsicOpInterface, getOperation(), operands, typeConverter, rewriter);
22
+ }
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXInterfaces.h.inc ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Interface Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+ namespace mlir {
10
+ namespace amx {
11
+ /// A wrapper interface for operations representing AMX LLVM intrinsics.
12
+ class AMXIntrinsicOp;
13
+ namespace detail {
14
+ struct AMXIntrinsicOpInterfaceTraits {
15
+ struct Concept {
16
+ /// The methods defined by the interface.
17
+ /// The base classes of this interface.
18
+ const ::mlir::LLVM::OneToOneIntrinsicOpInterface::Concept *implOneToOneIntrinsicOpInterface = nullptr;
19
+
20
+ void initializeInterfaceConcept(::mlir::detail::InterfaceMap &interfaceMap) {
21
+ implOneToOneIntrinsicOpInterface = interfaceMap.lookup<::mlir::LLVM::OneToOneIntrinsicOpInterface>();
22
+ assert(implOneToOneIntrinsicOpInterface && "`::mlir::amx::AMXIntrinsicOp` expected its base interface `::mlir::LLVM::OneToOneIntrinsicOpInterface` to be registered");
23
+ }
24
+ };
25
+ template<typename ConcreteOp>
26
+ class Model : public Concept {
27
+ public:
28
+ using Interface = ::mlir::amx::AMXIntrinsicOp;
29
+ Model() : Concept{} {}
30
+
31
+ };
32
+ template<typename ConcreteOp>
33
+ class FallbackModel : public Concept {
34
+ public:
35
+ using Interface = ::mlir::amx::AMXIntrinsicOp;
36
+ FallbackModel() : Concept{} {}
37
+
38
+ };
39
+ template<typename ConcreteModel, typename ConcreteOp>
40
+ class ExternalModel : public FallbackModel<ConcreteModel> {
41
+ public:
42
+ using ConcreteEntity = ConcreteOp;
43
+ };
44
+ };
45
+ template <typename ConcreteOp>
46
+ struct AMXIntrinsicOpTrait;
47
+
48
+ } // namespace detail
49
+ class AMXIntrinsicOp : public ::mlir::OpInterface<AMXIntrinsicOp, detail::AMXIntrinsicOpInterfaceTraits> {
50
+ public:
51
+ using ::mlir::OpInterface<AMXIntrinsicOp, detail::AMXIntrinsicOpInterfaceTraits>::OpInterface;
52
+ template <typename ConcreteOp>
53
+ struct Trait : public detail::AMXIntrinsicOpTrait<ConcreteOp> {};
54
+ //===----------------------------------------------------------------===//
55
+ // Inherited from ::mlir::LLVM::OneToOneIntrinsicOpInterface
56
+ //===----------------------------------------------------------------===//
57
+
58
+ operator ::mlir::LLVM::OneToOneIntrinsicOpInterface () const {
59
+ if (!*this) return nullptr;
60
+ return ::mlir::LLVM::OneToOneIntrinsicOpInterface(*this, getImpl()->implOneToOneIntrinsicOpInterface);
61
+ }
62
+
63
+
64
+ /// Returns mangled LLVM intrinsic function name matching the operation
65
+ /// variant.
66
+ std::string getIntrinsicName();
67
+
68
+ /// Returns operands for a corresponding LLVM intrinsic.
69
+ ///
70
+ /// Additional operations may be created to facilitate mapping
71
+ /// between the source operands and the target intrinsic.
72
+ SmallVector<Value> getIntrinsicOperands(::mlir::ArrayRef<Value> operands, const ::mlir::LLVMTypeConverter & typeConverter, ::mlir::RewriterBase & rewriter);
73
+ };
74
+ namespace detail {
75
+ template <typename ConcreteOp>
76
+ struct AMXIntrinsicOpTrait : public ::mlir::OpInterface<AMXIntrinsicOp, detail::AMXIntrinsicOpInterfaceTraits>::Trait<ConcreteOp> {
77
+ };
78
+ }// namespace detail
79
+ } // namespace amx
80
+ } // namespace mlir
81
+ namespace mlir {
82
+ namespace amx {
83
+ } // namespace amx
84
+ } // namespace mlir
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXTypes.cpp.inc ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* TypeDef Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+ #ifdef GET_TYPEDEF_LIST
10
+ #undef GET_TYPEDEF_LIST
11
+
12
+ ::mlir::amx::TileType
13
+
14
+ #endif // GET_TYPEDEF_LIST
15
+
16
+ #ifdef GET_TYPEDEF_CLASSES
17
+ #undef GET_TYPEDEF_CLASSES
18
+
19
+ static ::mlir::OptionalParseResult generatedTypeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type &value) {
20
+ return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
21
+ .Case(::mlir::amx::TileType::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
22
+ value = ::mlir::amx::TileType::parse(parser);
23
+ return ::mlir::success(!!value);
24
+ })
25
+ .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
26
+ *mnemonic = keyword;
27
+ return std::nullopt;
28
+ });
29
+ }
30
+
31
+ static ::llvm::LogicalResult generatedTypePrinter(::mlir::Type def, ::mlir::AsmPrinter &printer) {
32
+ return ::llvm::TypeSwitch<::mlir::Type, ::llvm::LogicalResult>(def) .Case<::mlir::amx::TileType>([&](auto t) {
33
+ printer << ::mlir::amx::TileType::getMnemonic();
34
+ t.print(printer);
35
+ return ::mlir::success();
36
+ })
37
+ .Default([](auto) { return ::mlir::failure(); });
38
+ }
39
+
40
+ namespace mlir {
41
+ namespace amx {
42
+ namespace detail {
43
+ struct TileTypeStorage : public ::mlir::TypeStorage {
44
+ using KeyTy = std::tuple<::llvm::ArrayRef<int64_t>, ::mlir::Type>;
45
+ TileTypeStorage(::llvm::ArrayRef<int64_t> shape, ::mlir::Type elementType) : shape(std::move(shape)), elementType(std::move(elementType)) {}
46
+
47
+ KeyTy getAsKey() const {
48
+ return KeyTy(shape, elementType);
49
+ }
50
+
51
+ bool operator==(const KeyTy &tblgenKey) const {
52
+ return (shape == std::get<0>(tblgenKey)) && (elementType == std::get<1>(tblgenKey));
53
+ }
54
+
55
+ static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
56
+ return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
57
+ }
58
+
59
+ static TileTypeStorage *construct(::mlir::TypeStorageAllocator &allocator, KeyTy &&tblgenKey) {
60
+ auto shape = std::move(std::get<0>(tblgenKey));
61
+ auto elementType = std::move(std::get<1>(tblgenKey));
62
+ shape = allocator.copyInto(shape);
63
+ return new (allocator.allocate<TileTypeStorage>()) TileTypeStorage(std::move(shape), std::move(elementType));
64
+ }
65
+
66
+ ::llvm::ArrayRef<int64_t> shape;
67
+ ::mlir::Type elementType;
68
+ };
69
+ } // namespace detail
70
+ TileType TileType::get(ArrayRef<int64_t> shape, Type elementType) {
71
+ return Base::get(elementType.getContext(), shape, elementType);
72
+ }
73
+
74
+ TileType TileType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ArrayRef<int64_t> shape, Type elementType) {
75
+ return Base::getChecked(emitError, elementType.getContext(), shape, elementType);
76
+ }
77
+
78
+ ::llvm::LogicalResult TileType::verifyInvariantsImpl(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::llvm::ArrayRef<int64_t> shape, ::mlir::Type elementType) {
79
+ if (!(((elementType.isF32())) || ((elementType.isF16())) || ((::llvm::isa<::mlir::BFloat16Type>(elementType))) || ((elementType.isSignlessInteger(32))) || ((elementType.isSignlessInteger(8))))) {
80
+ emitError() << "failed to verify 'elementType': 32-bit float or 16-bit float or bfloat16 type or 32-bit signless integer or 8-bit signless integer";
81
+ return ::mlir::failure();
82
+ }
83
+
84
+ return ::mlir::success();
85
+ }
86
+
87
+ ::llvm::LogicalResult TileType::verifyInvariants(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::llvm::ArrayRef<int64_t> shape, ::mlir::Type elementType) {
88
+ if (::mlir::failed(verifyInvariantsImpl(emitError, shape, elementType)))
89
+ return ::mlir::failure();
90
+ return ::mlir::success();
91
+ }
92
+
93
+ ::llvm::ArrayRef<int64_t> TileType::getShape() const {
94
+ return getImpl()->shape;
95
+ }
96
+
97
+ ::mlir::Type TileType::getElementType() const {
98
+ return getImpl()->elementType;
99
+ }
100
+
101
+ } // namespace amx
102
+ } // namespace mlir
103
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::amx::TileType)
104
+ namespace mlir {
105
+ namespace amx {
106
+
107
+ /// Parse a type registered to this dialect.
108
+ ::mlir::Type AMXDialect::parseType(::mlir::DialectAsmParser &parser) const {
109
+ ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
110
+ ::llvm::StringRef mnemonic;
111
+ ::mlir::Type genType;
112
+ auto parseResult = generatedTypeParser(parser, &mnemonic, genType);
113
+ if (parseResult.has_value())
114
+ return genType;
115
+
116
+ parser.emitError(typeLoc) << "unknown type `"
117
+ << mnemonic << "` in dialect `" << getNamespace() << "`";
118
+ return {};
119
+ }
120
+ /// Print a type registered to this dialect.
121
+ void AMXDialect::printType(::mlir::Type type,
122
+ ::mlir::DialectAsmPrinter &printer) const {
123
+ if (::mlir::succeeded(generatedTypePrinter(type, printer)))
124
+ return;
125
+
126
+ }
127
+ } // namespace amx
128
+ } // namespace mlir
129
+
130
+ #endif // GET_TYPEDEF_CLASSES
131
+
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/AMXTypes.h.inc ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* TypeDef Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+ #ifdef GET_TYPEDEF_CLASSES
10
+ #undef GET_TYPEDEF_CLASSES
11
+
12
+
13
+ namespace mlir {
14
+ class AsmParser;
15
+ class AsmPrinter;
16
+ } // namespace mlir
17
+ namespace mlir {
18
+ namespace amx {
19
+ /// AMX 2D tile to be used by AMX opertaions.
20
+ /// This type is used to represent values in AMX tile registers. All AMX operations
21
+ /// work on AMX tiles and these tiles cannot be used in other operations directly.
22
+ /// LLVM IR type for AMX tile is a primitive type, but in MLIR we provide shape and
23
+ /// element type for IR verification and lowering to LLVMIR dialect.
24
+ class TileType;
25
+ namespace detail {
26
+ struct TileTypeStorage;
27
+ } // namespace detail
28
+ class TileType : public ::mlir::Type::TypeBase<TileType, ::mlir::Type, detail::TileTypeStorage, ::mlir::ShapedType::Trait, ::mlir::ValueSemantics> {
29
+ public:
30
+ using Base::Base;
31
+ /// Returns if this type is ranked (always true).
32
+ bool hasRank() const { return true; }
33
+
34
+ /// Clone this tile type with the given shape and element type. If the
35
+ /// provided shape is `std::nullopt`, the current shape of the type is used.
36
+ TileType cloneWith(std::optional<ArrayRef<int64_t>> shape,
37
+ Type elementType) const {
38
+ return get(shape.value_or(getShape()), elementType);
39
+ }
40
+ static constexpr ::llvm::StringLiteral name = "amx.tile";
41
+ static constexpr ::llvm::StringLiteral dialectName = "amx";
42
+ using Base::getChecked;
43
+ static TileType get(ArrayRef<int64_t> shape, Type elementType);
44
+ static TileType getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ArrayRef<int64_t> shape, Type elementType);
45
+ static ::llvm::LogicalResult verifyInvariantsImpl(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::llvm::ArrayRef<int64_t> shape, ::mlir::Type elementType);
46
+ static ::llvm::LogicalResult verifyInvariants(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::llvm::ArrayRef<int64_t> shape, ::mlir::Type elementType);
47
+ static constexpr ::llvm::StringLiteral getMnemonic() {
48
+ return {"tile"};
49
+ }
50
+
51
+ static ::mlir::Type parse(::mlir::AsmParser &odsParser);
52
+ void print(::mlir::AsmPrinter &odsPrinter) const;
53
+ ::llvm::ArrayRef<int64_t> getShape() const;
54
+ ::mlir::Type getElementType() const;
55
+ };
56
+ } // namespace amx
57
+ } // namespace mlir
58
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::amx::TileType)
59
+
60
+ #endif // GET_TYPEDEF_CLASSES
61
+
deps/exla/cache/xla_extension/include/mlir/Dialect/AMX/Transforms.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- Transforms.h - AMX Dialect Transformation Entrypoints ----*- 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_AMX_TRANSFORMS_H
10
+ #define MLIR_DIALECT_AMX_TRANSFORMS_H
11
+
12
+ namespace mlir {
13
+
14
+ class LLVMConversionTarget;
15
+ class LLVMTypeConverter;
16
+ class RewritePatternSet;
17
+ class DialectRegistry;
18
+
19
+ /// Collect a set of patterns to lower AMX ops to ops that map to LLVM
20
+ /// intrinsics.
21
+ void populateAMXLegalizeForLLVMExportPatterns(LLVMTypeConverter &converter,
22
+ RewritePatternSet &patterns);
23
+
24
+ /// Configure the target to support lowering AMX ops to ops that map to LLVM
25
+ /// intrinsics.
26
+ void configureAMXLegalizeForExportTarget(LLVMConversionTarget &target);
27
+
28
+ } // namespace mlir
29
+
30
+ #endif // MLIR_DIALECT_AMX_TRANSFORMS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AffineAnalysis.h - analyses for affine structures --------*- 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 methods that perform analysis
10
+ // involving affine structures (AffineExprStorage, AffineMap, IntegerSet, etc.)
11
+ // and other IR structures that in turn use these.
12
+ //
13
+ //===----------------------------------------------------------------------===//
14
+
15
+ #ifndef MLIR_DIALECT_AFFINE_ANALYSIS_AFFINEANALYSIS_H
16
+ #define MLIR_DIALECT_AFFINE_ANALYSIS_AFFINEANALYSIS_H
17
+
18
+ #include "mlir/Analysis/Presburger/IntegerRelation.h"
19
+ #include "mlir/Dialect/Arith/IR/Arith.h"
20
+ #include "mlir/IR/Value.h"
21
+ #include "llvm/ADT/SmallVector.h"
22
+ #include <optional>
23
+
24
+ namespace mlir {
25
+ class Operation;
26
+
27
+ namespace affine {
28
+ class AffineApplyOp;
29
+ class AffineForOp;
30
+ class AffineValueMap;
31
+ class FlatAffineRelation;
32
+ class FlatAffineValueConstraints;
33
+
34
+ /// A description of a (parallelizable) reduction in an affine loop.
35
+ struct LoopReduction {
36
+ /// Reduction kind.
37
+ arith::AtomicRMWKind kind;
38
+
39
+ /// Position of the iteration argument that acts as accumulator.
40
+ unsigned iterArgPosition;
41
+
42
+ /// The value being reduced.
43
+ Value value;
44
+ };
45
+
46
+ /// Populate `supportedReductions` with descriptors of the supported reductions.
47
+ void getSupportedReductions(
48
+ AffineForOp forOp, SmallVectorImpl<LoopReduction> &supportedReductions);
49
+
50
+ /// Returns true if `forOp' is a parallel loop. If `parallelReductions` is
51
+ /// provided, populates it with descriptors of the parallelizable reductions and
52
+ /// treats them as not preventing parallelization.
53
+ bool isLoopParallel(
54
+ AffineForOp forOp,
55
+ SmallVectorImpl<LoopReduction> *parallelReductions = nullptr);
56
+
57
+ /// Returns true if `forOp' doesn't have memory dependences preventing
58
+ /// parallelization. Memrefs that are allocated inside `forOp` do not impact its
59
+ /// dependences and parallelism. This function does not check iter_args (for
60
+ /// values other than memref types) and should be used only as a building block
61
+ /// for complete parallelism-checking functions.
62
+ bool isLoopMemoryParallel(AffineForOp forOp);
63
+
64
+ /// Returns in `affineApplyOps`, the sequence of those AffineApplyOp
65
+ /// Operations that are reachable via a search starting from `operands` and
66
+ /// ending at those operands that are not the result of an AffineApplyOp.
67
+ void getReachableAffineApplyOps(ArrayRef<Value> operands,
68
+ SmallVectorImpl<Operation *> &affineApplyOps);
69
+
70
+ /// Builds a system of constraints with dimensional variables corresponding to
71
+ /// the loop IVs of the forOps and AffineIfOp's operands appearing in
72
+ /// that order. Bounds of the loop are used to add appropriate inequalities.
73
+ /// Constraints from the index sets of AffineIfOp are also added. Any symbols
74
+ /// founds in the bound operands are added as symbols in the system. Returns
75
+ /// failure for the yet unimplemented cases. `ops` accepts both AffineForOp and
76
+ /// AffineIfOp.
77
+ // TODO: handle non-unit strides.
78
+ LogicalResult getIndexSet(MutableArrayRef<Operation *> ops,
79
+ FlatAffineValueConstraints *domain);
80
+
81
+ /// Encapsulates a memref load or store access information.
82
+ struct MemRefAccess {
83
+ Value memref;
84
+ Operation *opInst;
85
+ SmallVector<Value, 4> indices;
86
+
87
+ /// Constructs a MemRefAccess from a load or store operation.
88
+ // TODO: add accessors to standard op's load, store, DMA op's to return
89
+ // MemRefAccess, i.e., loadOp->getAccess(), dmaOp->getRead/WriteAccess.
90
+ explicit MemRefAccess(Operation *opInst);
91
+
92
+ // Returns the rank of the memref associated with this access.
93
+ unsigned getRank() const;
94
+ // Returns true if this access is of a store op.
95
+ bool isStore() const;
96
+
97
+ /// Creates an access relation for the access. An access relation maps
98
+ /// elements of an iteration domain to the element(s) of an array domain
99
+ /// accessed by that iteration of the associated statement through some array
100
+ /// reference. For example, given the MLIR code:
101
+ ///
102
+ /// affine.for %i0 = 0 to 10 {
103
+ /// affine.for %i1 = 0 to 10 {
104
+ /// %a = affine.load %arr[%i0 + %i1, %i0 + 2 * %i1] : memref<100x100xf32>
105
+ /// }
106
+ /// }
107
+ ///
108
+ /// The access relation, assuming that the memory locations for %arr are
109
+ /// represented as %m0, %m1 would be:
110
+ ///
111
+ /// (%i0, %i1) -> (%m0, %m1)
112
+ /// %m0 = %i0 + %i1
113
+ /// %m1 = %i0 + 2 * %i1
114
+ /// 0 <= %i0 < 10
115
+ /// 0 <= %i1 < 10
116
+ ///
117
+ /// Returns failure for yet unimplemented/unsupported cases (see docs of
118
+ /// mlir::getIndexSet and mlir::getRelationFromMap for these cases).
119
+ LogicalResult getAccessRelation(presburger::IntegerRelation &accessRel) const;
120
+
121
+ /// Populates 'accessMap' with composition of AffineApplyOps reachable from
122
+ /// 'indices'.
123
+ void getAccessMap(AffineValueMap *accessMap) const;
124
+
125
+ /// Equal if both affine accesses can be proved to be equivalent at compile
126
+ /// time (considering the memrefs, their respective affine access maps and
127
+ /// operands). The equality of access functions + operands is checked by
128
+ /// subtracting fully composed value maps, and then simplifying the difference
129
+ /// using the expression flattener.
130
+ /// TODO: this does not account for aliasing of memrefs.
131
+ bool operator==(const MemRefAccess &rhs) const;
132
+ bool operator!=(const MemRefAccess &rhs) const { return !(*this == rhs); }
133
+ };
134
+
135
+ // DependenceComponent contains state about the direction of a dependence as an
136
+ // interval [lb, ub] for an AffineForOp.
137
+ // Distance vectors components are represented by the interval [lb, ub] with
138
+ // lb == ub.
139
+ // Direction vectors components are represented by the interval [lb, ub] with
140
+ // lb < ub. Note that ub/lb == None means unbounded.
141
+ struct DependenceComponent {
142
+ // The AffineForOp Operation associated with this dependence component.
143
+ Operation *op = nullptr;
144
+ // The lower bound of the dependence distance.
145
+ std::optional<int64_t> lb;
146
+ // The upper bound of the dependence distance (inclusive).
147
+ std::optional<int64_t> ub;
148
+ DependenceComponent() : lb(std::nullopt), ub(std::nullopt) {}
149
+ };
150
+
151
+ /// Checks whether two accesses to the same memref access the same element.
152
+ /// Each access is specified using the MemRefAccess structure, which contains
153
+ /// the operation, indices and memref associated with the access. Returns
154
+ /// 'NoDependence' if it can be determined conclusively that the accesses do not
155
+ /// access the same memref element. If 'allowRAR' is true, will consider
156
+ /// read-after-read dependences (typically used by applications trying to
157
+ /// optimize input reuse).
158
+ // TODO: Wrap 'dependenceConstraints' and 'dependenceComponents' into a single
159
+ // struct.
160
+ // TODO: Make 'dependenceConstraints' optional arg.
161
+ struct DependenceResult {
162
+ enum ResultEnum {
163
+ HasDependence, // A dependence exists between 'srcAccess' and 'dstAccess'.
164
+ NoDependence, // No dependence exists between 'srcAccess' and 'dstAccess'.
165
+ Failure, // Dependence check failed due to unsupported cases.
166
+ } value;
167
+ DependenceResult(ResultEnum v) : value(v) {}
168
+ };
169
+
170
+ DependenceResult checkMemrefAccessDependence(
171
+ const MemRefAccess &srcAccess, const MemRefAccess &dstAccess,
172
+ unsigned loopDepth,
173
+ FlatAffineValueConstraints *dependenceConstraints = nullptr,
174
+ SmallVector<DependenceComponent, 2> *dependenceComponents = nullptr,
175
+ bool allowRAR = false);
176
+
177
+ /// Utility function that returns true if the provided DependenceResult
178
+ /// corresponds to a dependence result.
179
+ inline bool hasDependence(DependenceResult result) {
180
+ return result.value == DependenceResult::HasDependence;
181
+ }
182
+
183
+ /// Returns true if the provided DependenceResult corresponds to the absence of
184
+ /// a dependence.
185
+ inline bool noDependence(DependenceResult result) {
186
+ return result.value == DependenceResult::NoDependence;
187
+ }
188
+
189
+ /// Returns in 'depCompsVec', dependence components for dependences between all
190
+ /// load and store ops in loop nest rooted at 'forOp', at loop depths in range
191
+ /// [1, maxLoopDepth].
192
+ void getDependenceComponents(
193
+ AffineForOp forOp, unsigned maxLoopDepth,
194
+ std::vector<SmallVector<DependenceComponent, 2>> *depCompsVec);
195
+
196
+ } // namespace affine
197
+ } // namespace mlir
198
+
199
+ #endif // MLIR_DIALECT_AFFINE_ANALYSIS_AFFINEANALYSIS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/AffineStructures.h ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AffineStructures.h - MLIR Affine Structures Class --------*- 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
+ // Structures for affine/polyhedral analysis of ML functions.
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #ifndef MLIR_DIALECT_AFFINE_ANALYSIS_AFFINESTRUCTURES_H
14
+ #define MLIR_DIALECT_AFFINE_ANALYSIS_AFFINESTRUCTURES_H
15
+
16
+ #include "mlir/Analysis/FlatLinearValueConstraints.h"
17
+ #include "mlir/Analysis/Presburger/IntegerRelation.h"
18
+ #include "mlir/Analysis/Presburger/Matrix.h"
19
+ #include "mlir/IR/AffineExpr.h"
20
+ #include "mlir/IR/OpDefinition.h"
21
+ #include <optional>
22
+
23
+ namespace mlir {
24
+ class AffineMap;
25
+ class IntegerSet;
26
+ class MemRefType;
27
+ class MLIRContext;
28
+ struct MutableAffineMap;
29
+ class Value;
30
+
31
+ namespace presburger {
32
+ class MultiAffineFunction;
33
+ } // namespace presburger
34
+
35
+ namespace affine {
36
+ class AffineCondition;
37
+ class AffineForOp;
38
+ class AffineIfOp;
39
+ class AffineParallelOp;
40
+ class AffineValueMap;
41
+
42
+ /// FlatAffineValueConstraints is an extension of FlatLinearValueConstraints
43
+ /// with helper functions for Affine dialect ops.
44
+ class FlatAffineValueConstraints : public FlatLinearValueConstraints {
45
+ public:
46
+ using FlatLinearValueConstraints::FlatLinearValueConstraints;
47
+
48
+ /// Return the kind of this object.
49
+ Kind getKind() const override { return Kind::FlatAffineValueConstraints; }
50
+
51
+ static bool classof(const IntegerRelation *cst) {
52
+ return cst->getKind() >= Kind::FlatAffineValueConstraints &&
53
+ cst->getKind() <= Kind::FlatAffineRelation;
54
+ }
55
+
56
+ /// Adds constraints (lower and upper bounds) for the specified 'affine.for'
57
+ /// operation's Value using IR information stored in its bound maps. The
58
+ /// right variable is first looked up using `forOp`'s Value. Asserts if the
59
+ /// Value corresponding to the 'affine.for' operation isn't found in the
60
+ /// constraint system. Returns failure for the yet unimplemented/unsupported
61
+ /// cases. Any new variables that are found in the bound operands of the
62
+ /// 'affine.for' operation are added as trailing variables (either
63
+ /// dimensional or symbolic depending on whether the operand is a valid
64
+ /// symbol).
65
+ LogicalResult addAffineForOpDomain(AffineForOp forOp);
66
+
67
+ /// Add constraints (lower and upper bounds) for the specified
68
+ /// 'affine.parallel' operation's Value using IR information stored in its
69
+ /// bound maps. Returns failure for the yet unimplemented/unsupported cases.
70
+ /// Asserts if the Value corresponding to the 'affine.parallel' operation
71
+ /// isn't found in the constraint system.
72
+ LogicalResult addAffineParallelOpDomain(AffineParallelOp parallelOp);
73
+
74
+ /// Adds constraints (lower and upper bounds) for each loop in the loop nest
75
+ /// described by the bound maps `lbMaps` and `ubMaps` of a computation slice.
76
+ /// Every pair (`lbMaps[i]`, `ubMaps[i]`) describes the bounds of a loop in
77
+ /// the nest, sorted outer-to-inner. `operands` contains the bound operands
78
+ /// for a single bound map. All the bound maps will use the same bound
79
+ /// operands. Note that some loops described by a computation slice might not
80
+ /// exist yet in the IR so the Value attached to those dimension variables
81
+ /// might be empty. For that reason, this method doesn't perform Value
82
+ /// look-ups to retrieve the dimension variable positions. Instead, it
83
+ /// assumes the position of the dim variables in the constraint system is
84
+ /// the same as the position of the loop in the loop nest.
85
+ LogicalResult addDomainFromSliceMaps(ArrayRef<AffineMap> lbMaps,
86
+ ArrayRef<AffineMap> ubMaps,
87
+ ArrayRef<Value> operands);
88
+
89
+ /// Adds constraints imposed by the `affine.if` operation. These constraints
90
+ /// are collected from the IntegerSet attached to the given `affine.if`
91
+ /// instance argument (`ifOp`). It is asserted that:
92
+ /// 1) The IntegerSet of the given `affine.if` instance should not contain
93
+ /// semi-affine expressions,
94
+ /// 2) The columns of the constraint system created from `ifOp` should match
95
+ /// the columns in the current one regarding numbers and values.
96
+ void addAffineIfOpDomain(AffineIfOp ifOp);
97
+
98
+ /// Adds a bound for the variable at the specified position with constraints
99
+ /// being drawn from the specified bound map and operands. In case of an
100
+ /// EQ bound, the bound map is expected to have exactly one result. In case
101
+ /// of a LB/UB, the bound map may have more than one result, for each of which
102
+ /// an inequality is added.
103
+ LogicalResult addBound(presburger::BoundType type, unsigned pos,
104
+ AffineMap boundMap, ValueRange operands);
105
+ using FlatLinearValueConstraints::addBound;
106
+
107
+ /// Add the specified values as a dim or symbol var depending on its nature,
108
+ /// if it already doesn't exist in the system. `val` has to be either a
109
+ /// terminal symbol or a loop IV, i.e., it cannot be the result of an
110
+ /// affine.apply of any symbols or loop IVs. Return failure if the addition
111
+ /// wasn't possible due to the above conditions not being met. This method can
112
+ /// also fail if the addition of the domain of an affine IV fails. The
113
+ /// variable is added to the end of the existing dims or symbols. Additional
114
+ /// information on the variable is extracted from the IR and added to the
115
+ /// constraint system.
116
+ LogicalResult addInductionVarOrTerminalSymbol(Value val);
117
+
118
+ /// Adds slice lower bounds represented by lower bounds in `lbMaps` and upper
119
+ /// bounds in `ubMaps` to each variable in the constraint system which has
120
+ /// a value in `values`. Note that both lower/upper bounds share the same
121
+ /// operand list `operands`.
122
+ /// This function assumes `values.size` == `lbMaps.size` == `ubMaps.size`.
123
+ /// Note that both lower/upper bounds use operands from `operands`.
124
+ LogicalResult addSliceBounds(ArrayRef<Value> values,
125
+ ArrayRef<AffineMap> lbMaps,
126
+ ArrayRef<AffineMap> ubMaps,
127
+ ArrayRef<Value> operands);
128
+
129
+ /// Changes all symbol variables which are loop IVs to dim variables.
130
+ void convertLoopIVSymbolsToDims();
131
+
132
+ /// Returns the bound for the variable at `pos` from the inequality at
133
+ /// `ineqPos` as a 1-d affine value map (affine map + operands). The returned
134
+ /// affine value map can either be a lower bound or an upper bound depending
135
+ /// on the sign of atIneq(ineqPos, pos). Asserts if the row at `ineqPos` does
136
+ /// not involve the `pos`th variable.
137
+ void getIneqAsAffineValueMap(unsigned pos, unsigned ineqPos,
138
+ AffineValueMap &vmap,
139
+ MLIRContext *context) const;
140
+
141
+ /// Composes the affine value map with this FlatAffineValueConstrains, adding
142
+ /// the results of the map as dimensions at the front
143
+ /// [0, vMap->getNumResults()) and with the dimensions set to the equalities
144
+ /// specified by the value map.
145
+ ///
146
+ /// Returns failure if the composition fails (when vMap is a semi-affine map).
147
+ /// The vMap's operand Value's are used to look up the right positions in
148
+ /// the FlatAffineValueConstraints with which to associate. Every operand of
149
+ /// vMap should have a matching dim/symbol column in this constraint system
150
+ /// (with the same associated Value).
151
+ LogicalResult composeMap(const AffineValueMap *vMap);
152
+ };
153
+
154
+ /// A FlatAffineRelation represents a set of ordered pairs (domain -> range)
155
+ /// where "domain" and "range" are tuples of variables. The relation is
156
+ /// represented as a FlatAffineValueConstraints with separation of dimension
157
+ /// variables into domain and range. The variables are stored as:
158
+ /// [domainVars, rangeVars, symbolVars, localVars, constant].
159
+ ///
160
+ /// Deprecated: use IntegerRelation and store SSA Values in the PresburgerSpace
161
+ /// of the relation using PresburgerSpace::identifiers. Note that
162
+ /// FlatAffineRelation::numDomainDims and FlatAffineRelation::numRangeDims are
163
+ /// independent of numDomain and numRange of the relation's space. In
164
+ /// particular, operations such as FlatAffineRelation::compose do not ensure
165
+ /// consistency between numDomainDims/numRangeDims and numDomain/numRange which
166
+ /// may lead to unexpected behaviour.
167
+ class FlatAffineRelation : public FlatAffineValueConstraints {
168
+ public:
169
+ FlatAffineRelation(unsigned numReservedInequalities,
170
+ unsigned numReservedEqualities, unsigned numReservedCols,
171
+ unsigned numDomainDims, unsigned numRangeDims,
172
+ unsigned numSymbols, unsigned numLocals,
173
+ ArrayRef<std::optional<Value>> valArgs = {})
174
+ : FlatAffineValueConstraints(
175
+ numReservedInequalities, numReservedEqualities, numReservedCols,
176
+ numDomainDims + numRangeDims, numSymbols, numLocals, valArgs),
177
+ numDomainDims(numDomainDims), numRangeDims(numRangeDims) {}
178
+
179
+ FlatAffineRelation(unsigned numDomainDims = 0, unsigned numRangeDims = 0,
180
+ unsigned numSymbols = 0, unsigned numLocals = 0)
181
+ : FlatAffineValueConstraints(numDomainDims + numRangeDims, numSymbols,
182
+ numLocals),
183
+ numDomainDims(numDomainDims), numRangeDims(numRangeDims) {}
184
+
185
+ FlatAffineRelation(unsigned numDomainDims, unsigned numRangeDims,
186
+ FlatAffineValueConstraints &fac)
187
+ : FlatAffineValueConstraints(fac), numDomainDims(numDomainDims),
188
+ numRangeDims(numRangeDims) {}
189
+
190
+ FlatAffineRelation(unsigned numDomainDims, unsigned numRangeDims,
191
+ IntegerPolyhedron &fac)
192
+ : FlatAffineValueConstraints(fac), numDomainDims(numDomainDims),
193
+ numRangeDims(numRangeDims) {}
194
+
195
+ /// Return the kind of this object.
196
+ Kind getKind() const override { return Kind::FlatAffineRelation; }
197
+
198
+ static bool classof(const IntegerRelation *cst) {
199
+ return cst->getKind() == Kind::FlatAffineRelation;
200
+ }
201
+
202
+ /// Returns a set corresponding to the domain/range of the affine relation.
203
+ FlatAffineValueConstraints getDomainSet() const;
204
+ FlatAffineValueConstraints getRangeSet() const;
205
+
206
+ /// Returns the number of variables corresponding to domain/range of
207
+ /// relation.
208
+ inline unsigned getNumDomainDims() const { return numDomainDims; }
209
+ inline unsigned getNumRangeDims() const { return numRangeDims; }
210
+
211
+ /// Given affine relation `other: (domainOther -> rangeOther)`, this operation
212
+ /// takes the composition of `other` on `this: (domainThis -> rangeThis)`.
213
+ /// The resulting relation represents tuples of the form: `domainOther ->
214
+ /// rangeThis`.
215
+ void compose(const FlatAffineRelation &other);
216
+
217
+ /// Swap domain and range of the relation.
218
+ /// `(domain -> range)` is converted to `(range -> domain)`.
219
+ void inverse();
220
+
221
+ /// Insert `num` variables of the specified kind after the `pos` variable
222
+ /// of that kind. The coefficient columns corresponding to the added
223
+ /// variables are initialized to zero.
224
+ void insertDomainVar(unsigned pos, unsigned num = 1);
225
+ void insertRangeVar(unsigned pos, unsigned num = 1);
226
+
227
+ /// Append `num` variables of the specified kind after the last variable
228
+ /// of that kind. The coefficient columns corresponding to the added
229
+ /// variables are initialized to zero.
230
+ void appendDomainVar(unsigned num = 1);
231
+ void appendRangeVar(unsigned num = 1);
232
+
233
+ /// Removes variables in the column range [varStart, varLimit), and copies any
234
+ /// remaining valid data into place, updates member variables, and resizes
235
+ /// arrays as needed.
236
+ void removeVarRange(VarKind kind, unsigned varStart,
237
+ unsigned varLimit) override;
238
+ using IntegerRelation::removeVarRange;
239
+
240
+ protected:
241
+ // Number of dimension variables corresponding to domain variables.
242
+ unsigned numDomainDims;
243
+
244
+ // Number of dimension variables corresponding to range variables.
245
+ unsigned numRangeDims;
246
+ };
247
+
248
+ /// Builds a relation from the given AffineMap/AffineValueMap `map`, containing
249
+ /// all pairs of the form `operands -> result` that satisfy `map`. `rel` is set
250
+ /// to the relation built. For example, give the AffineMap:
251
+ ///
252
+ /// (d0, d1)[s0] -> (d0 + s0, d0 - s0)
253
+ ///
254
+ /// the resulting relation formed is:
255
+ ///
256
+ /// (d0, d1) -> (r1, r2)
257
+ /// [d0 d1 r1 r2 s0 const]
258
+ /// 1 0 -1 0 1 0 = 0
259
+ /// 0 1 0 -1 -1 0 = 0
260
+ ///
261
+ /// For AffineValueMap, the domain and symbols have Value set corresponding to
262
+ /// the Value in `map`. Returns failure if the AffineMap could not be flattened
263
+ /// (i.e., semi-affine is not yet handled).
264
+ LogicalResult getRelationFromMap(AffineMap &map,
265
+ presburger::IntegerRelation &rel);
266
+ LogicalResult getRelationFromMap(const AffineValueMap &map,
267
+ presburger::IntegerRelation &rel);
268
+
269
+ } // namespace affine
270
+ } // namespace mlir
271
+
272
+ #endif // MLIR_DIALECT_AFFINE_ANALYSIS_AFFINESTRUCTURES_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/LoopAnalysis.h ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- LoopAnalysis.h - loop analysis methods -------------------*- 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 methods to analyze loops.
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #ifndef MLIR_DIALECT_AFFINE_ANALYSIS_LOOPANALYSIS_H
14
+ #define MLIR_DIALECT_AFFINE_ANALYSIS_LOOPANALYSIS_H
15
+
16
+ #include "mlir/Support/LLVM.h"
17
+ #include "llvm/ADT/ArrayRef.h"
18
+ #include <optional>
19
+
20
+ namespace mlir {
21
+ class AffineExpr;
22
+ class AffineMap;
23
+ class BlockArgument;
24
+ class MemRefType;
25
+ class Operation;
26
+ class Value;
27
+
28
+ namespace affine {
29
+ class AffineForOp;
30
+ class NestedPattern;
31
+
32
+ /// Returns the trip count of the loop as an affine map with its corresponding
33
+ /// operands if the latter is expressible as an affine expression, and nullptr
34
+ /// otherwise. This method always succeeds as long as the lower bound is not a
35
+ /// multi-result map. The trip count expression is simplified before returning.
36
+ /// This method only utilizes map composition to construct lower and upper
37
+ /// bounds before computing the trip count expressions
38
+ void getTripCountMapAndOperands(AffineForOp forOp, AffineMap *map,
39
+ SmallVectorImpl<Value> *operands);
40
+
41
+ /// Returns the trip count of the loop if it's a constant, std::nullopt
42
+ /// otherwise. This uses affine expression analysis and is able to determine
43
+ /// constant trip count in non-trivial cases.
44
+ std::optional<uint64_t> getConstantTripCount(AffineForOp forOp);
45
+
46
+ /// Returns the greatest known integral divisor of the trip count. Affine
47
+ /// expression analysis is used (indirectly through getTripCount), and
48
+ /// this method is thus able to determine non-trivial divisors.
49
+ uint64_t getLargestDivisorOfTripCount(AffineForOp forOp);
50
+
51
+ /// Checks if an affine read or write operation depends on `forOp`'s IV, i.e.,
52
+ /// if the memory access is invariant on `forOp`.
53
+ template <typename LoadOrStoreOp>
54
+ bool isInvariantAccess(LoadOrStoreOp memOp, AffineForOp forOp);
55
+
56
+ /// Given an induction variable `iv` of type AffineForOp and `indices` of type
57
+ /// IndexType, returns the set of `indices` that are independent of `iv`.
58
+ ///
59
+ /// Prerequisites (inherited from `isAccessInvariant` above):
60
+ /// 1. `iv` and `indices` of the proper type;
61
+ /// 2. at most one affine.apply is reachable from each index in `indices`;
62
+ ///
63
+ /// Emits a note if it encounters a chain of affine.apply and conservatively
64
+ /// those cases.
65
+ DenseSet<Value, DenseMapInfo<Value>>
66
+ getInvariantAccesses(Value iv, ArrayRef<Value> indices);
67
+
68
+ /// Given:
69
+ /// 1. an induction variable `iv` of type AffineForOp;
70
+ /// 2. a `memoryOp` of type const LoadOp& or const StoreOp&;
71
+ /// determines whether `memoryOp` has a contiguous access along `iv`. Contiguous
72
+ /// is defined as either invariant or varying only along a unique MemRef dim.
73
+ /// Upon success, the unique MemRef dim is written in `memRefDim` (or -1 to
74
+ /// convey the memRef access is invariant along `iv`).
75
+ ///
76
+ /// Prerequisites:
77
+ /// 1. `memRefDim` ~= nullptr;
78
+ /// 2. `iv` of the proper type;
79
+ /// 3. the MemRef accessed by `memoryOp` has no layout map or at most an
80
+ /// identity layout map.
81
+ ///
82
+ /// Currently only supports no layout map or identity layout map in the memref.
83
+ /// Returns false if the memref has a non-identity layoutMap. This behavior is
84
+ /// conservative.
85
+ template <typename LoadOrStoreOp>
86
+ bool isContiguousAccess(Value iv, LoadOrStoreOp memoryOp, int *memRefDim);
87
+
88
+ using VectorizableLoopFun = std::function<bool(AffineForOp)>;
89
+
90
+ /// Checks whether the loop is structurally vectorizable; i.e.:
91
+ /// 1. no conditionals are nested under the loop;
92
+ /// 2. all nested load/stores are to scalar MemRefs.
93
+ /// TODO: relax the no-conditionals restriction
94
+ bool isVectorizableLoopBody(AffineForOp loop,
95
+ NestedPattern &vectorTransferMatcher);
96
+
97
+ /// Checks whether the loop is structurally vectorizable and that all the LoadOp
98
+ /// and StoreOp matched have access indexing functions that are either:
99
+ /// 1. invariant along the loop induction variable created by 'loop';
100
+ /// 2. varying along at most one memory dimension. If such a unique dimension
101
+ /// is found, it is written into `memRefDim`.
102
+ bool isVectorizableLoopBody(AffineForOp loop, int *memRefDim,
103
+ NestedPattern &vectorTransferMatcher);
104
+
105
+ /// Checks where SSA dominance would be violated if a for op's body
106
+ /// operations are shifted by the specified shifts. This method checks if a
107
+ /// 'def' and all its uses have the same shift factor.
108
+ // TODO: extend this to check for memory-based dependence violation when we have
109
+ // the support.
110
+ bool isOpwiseShiftValid(AffineForOp forOp, ArrayRef<uint64_t> shifts);
111
+
112
+ /// Checks whether hyper-rectangular loop tiling of the nest represented by
113
+ /// `loops` is valid. The validity condition is from Irigoin and Triolet,
114
+ /// which states that two tiles cannot depend on each other. We simplify such
115
+ /// condition to just checking whether there is any negative dependence
116
+ /// direction, since we have the prior knowledge that the tiling results will be
117
+ /// hyper-rectangles, which are scheduled in the lexicographically increasing
118
+ /// order on the vector of loop indices. This function will return failure when
119
+ /// any dependence component is negative along any of `loops`.
120
+ bool isTilingValid(ArrayRef<AffineForOp> loops);
121
+
122
+ /// Returns true if the affine nest rooted at `root` has a cyclic dependence
123
+ /// among its affine memory accesses. The dependence could be through any
124
+ /// dependences carried by loops contained in `root` (inclusive of `root`) and
125
+ /// those carried by loop bodies (blocks) contained. Dependences carried by
126
+ /// loops outer to `root` aren't relevant. This method doesn't consider/account
127
+ /// for aliases.
128
+ bool hasCyclicDependence(AffineForOp root);
129
+
130
+ } // namespace affine
131
+ } // namespace mlir
132
+
133
+ #endif // MLIR_DIALECT_AFFINE_ANALYSIS_LOOPANALYSIS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/NestedMatcher.h ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- NestedMacher.h - Nested matcher for Function -------------*- 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_AFFINE_ANALYSIS_NESTEDMATCHER_H
10
+ #define MLIR_DIALECT_AFFINE_ANALYSIS_NESTEDMATCHER_H
11
+
12
+ #include "mlir/IR/BuiltinOps.h"
13
+ #include "mlir/IR/Operation.h"
14
+ #include "llvm/Support/Allocator.h"
15
+
16
+ namespace mlir {
17
+ class Operation;
18
+
19
+ namespace affine {
20
+ class NestedPattern;
21
+
22
+ /// An NestedPattern captures nested patterns in the IR.
23
+ /// It is used in conjunction with a scoped NestedPatternContext which is an
24
+ /// llvm::BumpPtrAllocator that handles memory allocations efficiently and
25
+ /// avoids ownership issues.
26
+ ///
27
+ /// In order to use NestedPatterns, first create a scoped context.
28
+ /// When the context goes out of scope, everything is freed.
29
+ /// This design simplifies the API by avoiding references to the context and
30
+ /// makes it clear that references to matchers must not escape.
31
+ ///
32
+ /// Example:
33
+ /// {
34
+ /// NestedPatternContext context;
35
+ /// auto gemmLike = Doall(Doall(Red(LoadStores())));
36
+ /// auto matches = gemmLike.match(f);
37
+ /// // do work on matches
38
+ /// } // everything is freed
39
+ ///
40
+ ///
41
+ /// Nested abstraction for matching results.
42
+ /// Provides access to the nested Operation* captured by a Matcher.
43
+ ///
44
+ /// A NestedMatch contains an Operation* and the children NestedMatch and is
45
+ /// thus cheap to copy. NestedMatch is stored in a scoped bumper allocator whose
46
+ /// lifetime is managed by an RAII NestedPatternContext.
47
+ class NestedMatch {
48
+ public:
49
+ static NestedMatch build(Operation *operation,
50
+ ArrayRef<NestedMatch> nestedMatches);
51
+ NestedMatch(const NestedMatch &) = default;
52
+ NestedMatch &operator=(const NestedMatch &) = default;
53
+
54
+ explicit operator bool() { return matchedOperation != nullptr; }
55
+
56
+ Operation *getMatchedOperation() const { return matchedOperation; }
57
+ ArrayRef<NestedMatch> getMatchedChildren() { return matchedChildren; }
58
+
59
+ private:
60
+ friend class NestedPattern;
61
+ friend class NestedPatternContext;
62
+
63
+ /// Underlying global bump allocator managed by a NestedPatternContext.
64
+ static llvm::BumpPtrAllocator *&allocator();
65
+
66
+ NestedMatch() = default;
67
+
68
+ /// Payload, holds a NestedMatch and all its children along this branch.
69
+ Operation *matchedOperation = nullptr;
70
+ ArrayRef<NestedMatch> matchedChildren;
71
+ };
72
+
73
+ /// A NestedPattern is a nested operation walker that:
74
+ /// 1. recursively matches a substructure in the tree;
75
+ /// 2. uses a filter function to refine matches with extra semantic
76
+ /// constraints (passed via a lambda of type FilterFunctionType);
77
+ /// 3. TODO: optionally applies actions (lambda).
78
+ ///
79
+ /// Nested patterns are meant to capture imperfectly nested loops while matching
80
+ /// properties over the whole loop nest. For instance, in vectorization we are
81
+ /// interested in capturing all the imperfectly nested loops of a certain type
82
+ /// and such that all the load and stores have certain access patterns along the
83
+ /// loops' induction variables). Such NestedMatches are first captured using the
84
+ /// `match` function and are later processed to analyze properties and apply
85
+ /// transformations in a non-greedy way.
86
+ ///
87
+ /// The NestedMatches captured in the IR can grow large, especially after
88
+ /// aggressive unrolling. As experience has shown, it is generally better to use
89
+ /// a plain walk over operations to match flat patterns but the current
90
+ /// implementation is competitive nonetheless.
91
+ using FilterFunctionType = std::function<bool(Operation &)>;
92
+ inline bool defaultFilterFunction(Operation &) { return true; }
93
+ class NestedPattern {
94
+ public:
95
+ NestedPattern(ArrayRef<NestedPattern> nested,
96
+ FilterFunctionType filter = defaultFilterFunction);
97
+ NestedPattern(const NestedPattern &other);
98
+ NestedPattern &operator=(const NestedPattern &other);
99
+
100
+ ~NestedPattern() {
101
+ // Call destructors manually, ArrayRef is non-owning so it wouldn't call
102
+ // them, but we should free the memory allocated by std::function outside of
103
+ // the arena allocator.
104
+ freeNested();
105
+ }
106
+
107
+ /// Returns all the top-level matches in `op`.
108
+ void match(Operation *op, SmallVectorImpl<NestedMatch> *matches) {
109
+ op->walk([&](Operation *child) { matchOne(child, matches); });
110
+ }
111
+
112
+ /// Returns the depth of the pattern.
113
+ unsigned getDepth() const;
114
+
115
+ private:
116
+ friend class NestedPatternContext;
117
+ friend class NestedMatch;
118
+ friend struct State;
119
+
120
+ /// Copies the list of nested patterns to the arena allocator associated with
121
+ /// this pattern.
122
+ void copyNestedToThis(ArrayRef<NestedPattern> nested);
123
+
124
+ /// Calls destructors on nested patterns.
125
+ void freeNested();
126
+
127
+ /// Underlying global bump allocator managed by a NestedPatternContext.
128
+ static llvm::BumpPtrAllocator *&allocator();
129
+
130
+ /// Matches this pattern against a single `op` and fills matches with the
131
+ /// result.
132
+ void matchOne(Operation *op, SmallVectorImpl<NestedMatch> *matches);
133
+
134
+ /// Nested patterns to be matched.
135
+ ArrayRef<NestedPattern> nestedPatterns;
136
+
137
+ /// Extra filter function to apply to prune patterns as the IR is walked.
138
+ FilterFunctionType filter;
139
+
140
+ /// skip is an implementation detail needed so that we can implement match
141
+ /// without switching on the type of the Operation. The idea is that a
142
+ /// NestedPattern first checks if it matches locally and then recursively
143
+ /// applies its nested matchers to its elem->nested. Since we want to rely on
144
+ /// the existing operation walking functionality rather than duplicate
145
+ /// it, we allow an off-by-one traversal to account for the fact that we
146
+ /// write:
147
+ ///
148
+ /// void match(Operation *elem) {
149
+ /// for (auto &c : getNestedPatterns()) {
150
+ /// NestedPattern childPattern(...);
151
+ /// ^~~~ Needs off-by-one skip.
152
+ ///
153
+ Operation *skip;
154
+ };
155
+
156
+ /// RAII structure to transparently manage the bump allocator for
157
+ /// NestedPattern and NestedMatch classes. This avoids passing a context to
158
+ /// all the API functions.
159
+ class NestedPatternContext {
160
+ public:
161
+ NestedPatternContext() {
162
+ assert(NestedMatch::allocator() == nullptr &&
163
+ "Only a single NestedPatternContext is supported");
164
+ assert(NestedPattern::allocator() == nullptr &&
165
+ "Only a single NestedPatternContext is supported");
166
+ NestedMatch::allocator() = &allocator;
167
+ NestedPattern::allocator() = &allocator;
168
+ }
169
+ ~NestedPatternContext() {
170
+ NestedMatch::allocator() = nullptr;
171
+ NestedPattern::allocator() = nullptr;
172
+ }
173
+ llvm::BumpPtrAllocator allocator;
174
+ };
175
+
176
+ namespace matcher {
177
+ // Syntactic sugar NestedPattern builder functions.
178
+ NestedPattern Op(FilterFunctionType filter = defaultFilterFunction);
179
+ NestedPattern If(const NestedPattern &child);
180
+ NestedPattern If(const FilterFunctionType &filter, const NestedPattern &child);
181
+ NestedPattern If(ArrayRef<NestedPattern> nested = {});
182
+ NestedPattern If(const FilterFunctionType &filter,
183
+ ArrayRef<NestedPattern> nested = {});
184
+ NestedPattern For(const NestedPattern &child);
185
+ NestedPattern For(const FilterFunctionType &filter, const NestedPattern &child);
186
+ NestedPattern For(ArrayRef<NestedPattern> nested = {});
187
+ NestedPattern For(const FilterFunctionType &filter,
188
+ ArrayRef<NestedPattern> nested = {});
189
+
190
+ bool isParallelLoop(Operation &op);
191
+ bool isReductionLoop(Operation &op);
192
+ bool isLoadOrStore(Operation &op);
193
+
194
+ } // namespace matcher
195
+ } // namespace affine
196
+ } // namespace mlir
197
+
198
+ #endif // MLIR_DIALECT_AFFINE_ANALYSIS_NESTEDMATCHER_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Analysis/Utils.h ADDED
@@ -0,0 +1,633 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- Utils.h - General analysis 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 transformation utilities for
10
+ // memref's and non-loop IR structures. These are not passes by themselves but
11
+ // are used either by passes, optimization sequences, or in turn by other
12
+ // transformation utilities.
13
+ //
14
+ //===----------------------------------------------------------------------===//
15
+
16
+ #ifndef MLIR_DIALECT_AFFINE_ANALYSIS_UTILS_H
17
+ #define MLIR_DIALECT_AFFINE_ANALYSIS_UTILS_H
18
+
19
+ #include "mlir/Dialect/Affine/Analysis/AffineStructures.h"
20
+ #include "mlir/Dialect/Affine/IR/AffineOps.h"
21
+ #include <memory>
22
+ #include <optional>
23
+
24
+ namespace mlir {
25
+ class Block;
26
+ class Location;
27
+ class Operation;
28
+ class Value;
29
+
30
+ namespace affine {
31
+ class AffineForOp;
32
+ class AffineValueMap;
33
+ struct MemRefAccess;
34
+
35
+ // LoopNestStateCollector walks loop nests and collects load and store
36
+ // operations, and whether or not a region holding op other than ForOp and IfOp
37
+ // was encountered in the loop nest.
38
+ struct LoopNestStateCollector {
39
+ SmallVector<AffineForOp, 4> forOps;
40
+ // Affine loads.
41
+ SmallVector<Operation *, 4> loadOpInsts;
42
+ // Affine stores.
43
+ SmallVector<Operation *, 4> storeOpInsts;
44
+ // Non-affine loads.
45
+ SmallVector<Operation *, 4> memrefLoads;
46
+ // Non-affine stores.
47
+ SmallVector<Operation *, 4> memrefStores;
48
+ // Free operations.
49
+ SmallVector<Operation *, 4> memrefFrees;
50
+
51
+ // Collects load and store operations, and whether or not a region holding op
52
+ // other than ForOp and IfOp was encountered in the loop nest.
53
+ void collect(Operation *opToWalk);
54
+ };
55
+
56
+ // MemRefDependenceGraph is a graph data structure where graph nodes are
57
+ // top-level operations in a `Block` and edges are memref dependences or SSA
58
+ // dependences (on memrefs) between the nodes. Nodes are created for all
59
+ // top-level operations except in certain cases (see `init` method). Edges are
60
+ // created between nodes with a dependence (see `Edge` documentation). Edges
61
+ // aren't created from/to nodes that have no memory effects.
62
+ struct MemRefDependenceGraph {
63
+ public:
64
+ // Node represents a node in the graph. A Node is either an entire loop nest
65
+ // rooted at the top level which contains loads/stores, or a top level
66
+ // load/store.
67
+ struct Node {
68
+ // The unique identifier of this node in the graph.
69
+ unsigned id;
70
+ // The top-level statement which is (or contains) a load/store.
71
+ Operation *op;
72
+ // List of affine loads.
73
+ SmallVector<Operation *, 4> loads;
74
+ // List of non-affine loads.
75
+ SmallVector<Operation *, 4> memrefLoads;
76
+ // List of affine store ops.
77
+ SmallVector<Operation *, 4> stores;
78
+ // List of non-affine stores.
79
+ SmallVector<Operation *, 4> memrefStores;
80
+ // List of free operations.
81
+ SmallVector<Operation *, 4> memrefFrees;
82
+ // Set of private memrefs used in this node.
83
+ DenseSet<Value> privateMemrefs;
84
+
85
+ Node(unsigned id, Operation *op) : id(id), op(op) {}
86
+
87
+ // Returns the load op count for 'memref'.
88
+ unsigned getLoadOpCount(Value memref) const;
89
+
90
+ // Returns the store op count for 'memref'.
91
+ unsigned getStoreOpCount(Value memref) const;
92
+
93
+ /// Returns true if there exists an operation with a write memory effect to
94
+ /// `memref` in this node.
95
+ unsigned hasStore(Value memref) const;
96
+
97
+ // Returns true if the node has a free op on `memref`.
98
+ unsigned hasFree(Value memref) const;
99
+
100
+ // Returns all store ops in 'storeOps' which access 'memref'.
101
+ void getStoreOpsForMemref(Value memref,
102
+ SmallVectorImpl<Operation *> *storeOps) const;
103
+
104
+ // Returns all load ops in 'loadOps' which access 'memref'.
105
+ void getLoadOpsForMemref(Value memref,
106
+ SmallVectorImpl<Operation *> *loadOps) const;
107
+
108
+ // Returns all memrefs in 'loadAndStoreMemrefSet' for which this node
109
+ // has at least one load and store operation.
110
+ void getLoadAndStoreMemrefSet(DenseSet<Value> *loadAndStoreMemrefSet) const;
111
+ };
112
+
113
+ // Edge represents a data dependence between nodes in the graph. It can either
114
+ // be a memory dependence or an SSA dependence. In the former case, it
115
+ // corresponds to a pair of memory accesses to the same memref or aliasing
116
+ // memrefs where at least one of them has a write or free memory effect. The
117
+ // memory accesses need not be affine load/store operations. Operations are
118
+ // checked for read/write effects and edges may be added conservatively. Edges
119
+ // are not created to/from nodes that have no memory effect. An exception to
120
+ // this are SSA dependences between operations that define memrefs (like
121
+ // alloc's, view-like ops) and their memory-effecting users that are enclosed
122
+ // in loops.
123
+ struct Edge {
124
+ // The id of the node at the other end of the edge.
125
+ // If this edge is stored in Edge = Node.inEdges[i], then
126
+ // 'Node.inEdges[i].id' is the identifier of the source node of the edge.
127
+ // If this edge is stored in Edge = Node.outEdges[i], then
128
+ // 'Node.outEdges[i].id' is the identifier of the dest node of the edge.
129
+ unsigned id;
130
+ // The SSA value on which this edge represents a dependence.
131
+ // If the value is a memref, then the dependence is between graph nodes
132
+ // which contain accesses to the same memref 'value'. If the value is a
133
+ // non-memref value, then the dependence is between a graph node which
134
+ // defines an SSA value and another graph node which uses the SSA value
135
+ // (e.g. a constant or load operation defining a value which is used inside
136
+ // a loop nest).
137
+ Value value;
138
+ };
139
+
140
+ // Map from node id to Node.
141
+ DenseMap<unsigned, Node> nodes;
142
+ // Map from node id to list of input edges. The absence of an entry for a key
143
+ // is also equivalent to the absence of any edges.
144
+ DenseMap<unsigned, SmallVector<Edge, 2>> inEdges;
145
+ // Map from node id to list of output edges. The absence of an entry for a
146
+ // node is also equivalent to the absence of any edges.
147
+ DenseMap<unsigned, SmallVector<Edge, 2>> outEdges;
148
+ // Map from memref to a count on the dependence edges associated with that
149
+ // memref.
150
+ DenseMap<Value, unsigned> memrefEdgeCount;
151
+ // The next unique identifier to use for newly created graph nodes.
152
+ unsigned nextNodeId = 0;
153
+
154
+ MemRefDependenceGraph(Block &block) : block(block) {}
155
+
156
+ // Initializes the dependence graph based on operations in `block'.
157
+ // Returns true on success, false otherwise.
158
+ bool init();
159
+
160
+ // Returns the graph node for 'id'.
161
+ const Node *getNode(unsigned id) const;
162
+ Node *getNode(unsigned id) {
163
+ return const_cast<Node *>(
164
+ static_cast<const MemRefDependenceGraph *>(this)->getNode(id));
165
+ }
166
+
167
+ // Returns true if the graph has node with ID `id`.
168
+ bool hasNode(unsigned id) const { return nodes.contains(id); }
169
+
170
+ // Returns the graph node for 'forOp'.
171
+ const Node *getForOpNode(AffineForOp forOp) const;
172
+ Node *getForOpNode(AffineForOp forOp) {
173
+ return const_cast<Node *>(
174
+ static_cast<const MemRefDependenceGraph *>(this)->getForOpNode(forOp));
175
+ }
176
+
177
+ // Adds a node with 'op' to the graph and returns its unique identifier.
178
+ unsigned addNode(Operation *op);
179
+
180
+ // Remove node 'id' (and its associated edges) from graph.
181
+ void removeNode(unsigned id);
182
+
183
+ // Returns true if node 'id' writes to any memref which escapes (or is an
184
+ // argument to) the block. Returns false otherwise.
185
+ bool writesToLiveInOrEscapingMemrefs(unsigned id) const;
186
+
187
+ // Returns true iff there is an edge from node 'srcId' to node 'dstId' which
188
+ // is for 'value' if non-null, or for any value otherwise. Returns false
189
+ // otherwise.
190
+ bool hasEdge(unsigned srcId, unsigned dstId, Value value = nullptr) const;
191
+
192
+ // Adds an edge from node 'srcId' to node 'dstId' for 'value'.
193
+ void addEdge(unsigned srcId, unsigned dstId, Value value);
194
+
195
+ // Removes an edge from node 'srcId' to node 'dstId' for 'value'.
196
+ void removeEdge(unsigned srcId, unsigned dstId, Value value);
197
+
198
+ // Returns true if there is a path in the dependence graph from node 'srcId'
199
+ // to node 'dstId'. Returns false otherwise. `srcId`, `dstId`, and the
200
+ // operations that the edges connected are expected to be from the same block.
201
+ bool hasDependencePath(unsigned srcId, unsigned dstId) const;
202
+
203
+ // Returns the input edge count for node 'id' and 'memref' from src nodes
204
+ // which access 'memref' with a store operation.
205
+ unsigned getIncomingMemRefAccesses(unsigned id, Value memref) const;
206
+
207
+ // Returns the output edge count for node 'id' and 'memref' (if non-null),
208
+ // otherwise returns the total output edge count from node 'id'.
209
+ unsigned getOutEdgeCount(unsigned id, Value memref = nullptr) const;
210
+
211
+ /// Return all nodes which define SSA values used in node 'id'.
212
+ void gatherDefiningNodes(unsigned id,
213
+ DenseSet<unsigned> &definingNodes) const;
214
+
215
+ // Computes and returns an insertion point operation, before which the
216
+ // the fused <srcId, dstId> loop nest can be inserted while preserving
217
+ // dependences. Returns nullptr if no such insertion point is found.
218
+ Operation *getFusedLoopNestInsertionPoint(unsigned srcId,
219
+ unsigned dstId) const;
220
+
221
+ // Updates edge mappings from node 'srcId' to node 'dstId' after fusing them,
222
+ // taking into account that:
223
+ // *) if 'removeSrcId' is true, 'srcId' will be removed after fusion,
224
+ // *) memrefs in 'privateMemRefs' has been replaced in node at 'dstId' by a
225
+ // private memref.
226
+ void updateEdges(unsigned srcId, unsigned dstId,
227
+ const DenseSet<Value> &privateMemRefs, bool removeSrcId);
228
+
229
+ // Update edge mappings for nodes 'sibId' and 'dstId' to reflect fusion
230
+ // of sibling node 'sibId' into node 'dstId'.
231
+ void updateEdges(unsigned sibId, unsigned dstId);
232
+
233
+ // Adds the specified ops to lists of node at 'id'.
234
+ void addToNode(unsigned id, ArrayRef<Operation *> loads,
235
+ ArrayRef<Operation *> stores,
236
+ ArrayRef<Operation *> memrefLoads,
237
+ ArrayRef<Operation *> memrefStores,
238
+ ArrayRef<Operation *> memrefFrees);
239
+
240
+ void clearNodeLoadAndStores(unsigned id);
241
+
242
+ // Calls 'callback' for each input edge incident to node 'id' which carries a
243
+ // memref dependence.
244
+ void forEachMemRefInputEdge(unsigned id,
245
+ const std::function<void(Edge)> &callback);
246
+
247
+ // Calls 'callback' for each output edge from node 'id' which carries a
248
+ // memref dependence.
249
+ void forEachMemRefOutputEdge(unsigned id,
250
+ const std::function<void(Edge)> &callback);
251
+
252
+ // Calls 'callback' for each edge in 'edges' which carries a memref
253
+ // dependence.
254
+ void forEachMemRefEdge(ArrayRef<Edge> edges,
255
+ const std::function<void(Edge)> &callback);
256
+
257
+ void print(raw_ostream &os) const;
258
+
259
+ void dump() const { print(llvm::errs()); }
260
+
261
+ /// The block for which this graph is created to perform fusion.
262
+ Block &block;
263
+ };
264
+
265
+ /// Populates 'loops' with IVs of the affine.for ops surrounding 'op' ordered
266
+ /// from the outermost 'affine.for' operation to the innermost one while not
267
+ /// traversing outside of the surrounding affine scope.
268
+ void getAffineForIVs(Operation &op, SmallVectorImpl<AffineForOp> *loops);
269
+
270
+ /// Populates 'ivs' with IVs of the surrounding affine.for and affine.parallel
271
+ /// ops ordered from the outermost one to the innermost while not traversing
272
+ /// outside of the surrounding affine scope.
273
+ void getAffineIVs(Operation &op, SmallVectorImpl<Value> &ivs);
274
+
275
+ /// Populates 'ops' with affine operations enclosing `op` ordered from outermost
276
+ /// to innermost while stopping at the boundary of the affine scope. affine.for,
277
+ /// affine.if, or affine.parallel ops comprise such surrounding affine ops.
278
+ /// `ops` is guaranteed by design to have a successive chain of affine parent
279
+ /// ops.
280
+ void getEnclosingAffineOps(Operation &op, SmallVectorImpl<Operation *> *ops);
281
+
282
+ /// Returns the nesting depth of this operation, i.e., the number of loops
283
+ /// surrounding this operation.
284
+ unsigned getNestingDepth(Operation *op);
285
+
286
+ /// Returns whether a loop is a parallel loop and contains a reduction loop.
287
+ bool isLoopParallelAndContainsReduction(AffineForOp forOp);
288
+
289
+ /// Returns in 'sequentialLoops' all sequential loops in loop nest rooted
290
+ /// at 'forOp'.
291
+ void getSequentialLoops(AffineForOp forOp,
292
+ llvm::SmallDenseSet<Value, 8> *sequentialLoops);
293
+
294
+ /// Enumerates different result statuses of slice computation by
295
+ /// `computeSliceUnion`
296
+ // TODO: Identify and add different kinds of failures during slice computation.
297
+ struct SliceComputationResult {
298
+ enum ResultEnum {
299
+ Success,
300
+ IncorrectSliceFailure, // Slice is computed, but it is incorrect.
301
+ GenericFailure, // Unable to compute src loop computation slice.
302
+ } value;
303
+ SliceComputationResult(ResultEnum v) : value(v) {}
304
+ };
305
+
306
+ /// ComputationSliceState aggregates loop IVs, loop bound AffineMaps and their
307
+ /// associated operands for a set of loops within a loop nest (typically the
308
+ /// set of loops surrounding a store operation). Loop bound AffineMaps which
309
+ /// are non-null represent slices of that loop's iteration space.
310
+ struct ComputationSliceState {
311
+ // List of sliced loop IVs (ordered from outermost to innermost).
312
+ // EX: 'ivs[i]' has lower bound 'lbs[i]' and upper bound 'ubs[i]'.
313
+ SmallVector<Value, 4> ivs;
314
+ // List of lower bound AffineMaps.
315
+ SmallVector<AffineMap, 4> lbs;
316
+ // List of upper bound AffineMaps.
317
+ SmallVector<AffineMap, 4> ubs;
318
+ // List of lower bound operands (lbOperands[i] are used by 'lbs[i]').
319
+ std::vector<SmallVector<Value, 4>> lbOperands;
320
+ // List of upper bound operands (ubOperands[i] are used by 'ubs[i]').
321
+ std::vector<SmallVector<Value, 4>> ubOperands;
322
+ // Slice loop nest insertion point in target loop nest.
323
+ Block::iterator insertPoint;
324
+ // Adds to 'cst' with constraints which represent the slice bounds on 'ivs'
325
+ // in 'this'. Specifically, the values in 'ivs' are added to 'cst' as dim
326
+ // variables and the values in 'lb/ubOperands' are added as symbols.
327
+ // Constraints are added for all loop IV bounds (dim or symbol), and
328
+ // constraints are added for slice bounds in 'lbs'/'ubs'.
329
+ // Returns failure if we cannot add loop bounds because of unsupported cases.
330
+ LogicalResult getAsConstraints(FlatAffineValueConstraints *cst) const;
331
+
332
+ /// Adds to 'cst' constraints which represent the original loop bounds on
333
+ /// 'ivs' in 'this'. This corresponds to the original domain of the loop nest
334
+ /// from which the slice is being computed. Returns failure if we cannot add
335
+ /// loop bounds because of unsupported cases.
336
+ LogicalResult getSourceAsConstraints(FlatAffineValueConstraints &cst) const;
337
+
338
+ // Clears all bounds and operands in slice state.
339
+ void clearBounds();
340
+
341
+ /// Returns true if the computation slice is empty.
342
+ bool isEmpty() const { return ivs.empty(); }
343
+
344
+ /// Returns true if the computation slice encloses all the iterations of the
345
+ /// sliced loop nest. Returns false if it does not. Returns std::nullopt if it
346
+ /// cannot determine if the slice is maximal or not.
347
+ // TODO: Cache 'isMaximal' so that we don't recompute it when the slice
348
+ // information hasn't changed.
349
+ std::optional<bool> isMaximal() const;
350
+
351
+ /// Checks the validity of the slice computed. This is done using the
352
+ /// following steps:
353
+ /// 1. Get the new domain of the slice that would be created if fusion
354
+ /// succeeds. This domain gets constructed with source loop IVS and
355
+ /// destination loop IVS as dimensions.
356
+ /// 2. Project out the dimensions of the destination loop from the domain
357
+ /// above calculated in step(1) to express it purely in terms of the source
358
+ /// loop IVs.
359
+ /// 3. Calculate a set difference between the iterations of the new domain and
360
+ /// the original domain of the source loop.
361
+ /// If this difference is empty, the slice is declared to be valid. Otherwise,
362
+ /// return false as it implies that the effective fusion results in at least
363
+ /// one iteration of the slice that was not originally in the source's domain.
364
+ /// If the validity cannot be determined, returns std::nullopt.
365
+ std::optional<bool> isSliceValid() const;
366
+
367
+ void dump() const;
368
+
369
+ private:
370
+ /// Fast check to determine if the computation slice is maximal. Returns true
371
+ /// if each slice dimension maps to an existing dst dimension and both the src
372
+ /// and the dst loops for those dimensions have the same bounds. Returns false
373
+ /// if both the src and the dst loops don't have the same bounds. Returns
374
+ /// std::nullopt if none of the above can be proven.
375
+ std::optional<bool> isSliceMaximalFastCheck() const;
376
+ };
377
+
378
+ /// Computes the computation slice loop bounds for one loop nest as affine maps
379
+ /// of the other loop nest's IVs and symbols, using 'dependenceConstraints'
380
+ /// computed between 'depSourceAccess' and 'depSinkAccess'.
381
+ /// If 'isBackwardSlice' is true, a backwards slice is computed in which the
382
+ /// slice bounds of loop nest surrounding 'depSourceAccess' are computed in
383
+ /// terms of loop IVs and symbols of the loop nest surrounding 'depSinkAccess'
384
+ /// at 'loopDepth'.
385
+ /// If 'isBackwardSlice' is false, a forward slice is computed in which the
386
+ /// slice bounds of loop nest surrounding 'depSinkAccess' are computed in terms
387
+ /// of loop IVs and symbols of the loop nest surrounding 'depSourceAccess' at
388
+ /// 'loopDepth'.
389
+ /// The slice loop bounds and associated operands are returned in 'sliceState'.
390
+ //
391
+ // Backward slice example:
392
+ //
393
+ // affine.for %i0 = 0 to 10 {
394
+ // affine.store %cst, %0[%i0] : memref<100xf32> // 'depSourceAccess'
395
+ // }
396
+ // affine.for %i1 = 0 to 10 {
397
+ // %v = affine.load %0[%i1] : memref<100xf32> // 'depSinkAccess'
398
+ // }
399
+ //
400
+ // // Backward computation slice of loop nest '%i0'.
401
+ // affine.for %i0 = (d0) -> (d0)(%i1) to (d0) -> (d0 + 1)(%i1) {
402
+ // affine.store %cst, %0[%i0] : memref<100xf32> // 'depSourceAccess'
403
+ // }
404
+ //
405
+ // Forward slice example:
406
+ //
407
+ // affine.for %i0 = 0 to 10 {
408
+ // affine.store %cst, %0[%i0] : memref<100xf32> // 'depSourceAccess'
409
+ // }
410
+ // affine.for %i1 = 0 to 10 {
411
+ // %v = affine.load %0[%i1] : memref<100xf32> // 'depSinkAccess'
412
+ // }
413
+ //
414
+ // // Forward computation slice of loop nest '%i1'.
415
+ // affine.for %i1 = (d0) -> (d0)(%i0) to (d0) -> (d0 + 1)(%i0) {
416
+ // %v = affine.load %0[%i1] : memref<100xf32> // 'depSinkAccess'
417
+ // }
418
+ //
419
+ void getComputationSliceState(
420
+ Operation *depSourceOp, Operation *depSinkOp,
421
+ const FlatAffineValueConstraints &dependenceConstraints, unsigned loopDepth,
422
+ bool isBackwardSlice, ComputationSliceState *sliceState);
423
+
424
+ /// Return the number of iterations for the `slicetripCountMap` provided.
425
+ uint64_t getSliceIterationCount(
426
+ const llvm::SmallDenseMap<Operation *, uint64_t, 8> &sliceTripCountMap);
427
+
428
+ /// Builds a map 'tripCountMap' from AffineForOp to constant trip count for
429
+ /// loop nest surrounding represented by slice loop bounds in 'slice'. Returns
430
+ /// true on success, false otherwise (if a non-constant trip count was
431
+ /// encountered).
432
+ bool buildSliceTripCountMap(
433
+ const ComputationSliceState &slice,
434
+ llvm::SmallDenseMap<Operation *, uint64_t, 8> *tripCountMap);
435
+
436
+ /// Computes in 'sliceUnion' the union of all slice bounds computed at
437
+ /// 'loopDepth' between all dependent pairs of ops in 'opsA' and 'opsB', and
438
+ /// then verifies if it is valid. The parameter 'numCommonLoops' is the number
439
+ /// of loops common to the operations in 'opsA' and 'opsB'. If 'isBackwardSlice'
440
+ /// is true, computes slice bounds for loop nest surrounding ops in 'opsA', as a
441
+ /// function of IVs and symbols of loop nest surrounding ops in 'opsB' at
442
+ /// 'loopDepth'. If 'isBackwardSlice' is false, computes slice bounds for loop
443
+ /// nest surrounding ops in 'opsB', as a function of IVs and symbols of loop
444
+ /// nest surrounding ops in 'opsA' at 'loopDepth'. Returns
445
+ /// 'SliceComputationResult::Success' if union was computed correctly, an
446
+ /// appropriate 'failure' otherwise.
447
+ SliceComputationResult
448
+ computeSliceUnion(ArrayRef<Operation *> opsA, ArrayRef<Operation *> opsB,
449
+ unsigned loopDepth, unsigned numCommonLoops,
450
+ bool isBackwardSlice, ComputationSliceState *sliceUnion);
451
+
452
+ /// Creates a clone of the computation contained in the loop nest surrounding
453
+ /// 'srcOpInst', slices the iteration space of src loop based on slice bounds
454
+ /// in 'sliceState', and inserts the computation slice at the beginning of the
455
+ /// operation block of the loop at 'dstLoopDepth' in the loop nest surrounding
456
+ /// 'dstOpInst'. Returns the top-level loop of the computation slice on
457
+ /// success, returns nullptr otherwise.
458
+ // Loop depth is a crucial optimization choice that determines where to
459
+ // materialize the results of the backward slice - presenting a trade-off b/w
460
+ // storage and redundant computation in several cases.
461
+ // TODO: Support computation slices with common surrounding loops.
462
+ AffineForOp insertBackwardComputationSlice(Operation *srcOpInst,
463
+ Operation *dstOpInst,
464
+ unsigned dstLoopDepth,
465
+ ComputationSliceState *sliceState);
466
+
467
+ /// A region of a memref's data space; this is typically constructed by
468
+ /// analyzing load/store op's on this memref and the index space of loops
469
+ /// surrounding such op's.
470
+ // For example, the memref region for a load operation at loop depth = 1:
471
+ //
472
+ // affine.for %i = 0 to 32 {
473
+ // affine.for %ii = %i to (d0) -> (d0 + 8) (%i) {
474
+ // affine.load %A[%ii]
475
+ // }
476
+ // }
477
+ //
478
+ // Region: {memref = %A, write = false, {%i <= m0 <= %i + 7} }
479
+ // The last field is a 2-d FlatAffineValueConstraints symbolic in %i.
480
+ //
481
+ struct MemRefRegion {
482
+ explicit MemRefRegion(Location loc) : loc(loc) {}
483
+
484
+ /// Computes the memory region accessed by this memref with the region
485
+ /// represented as constraints symbolic/parametric in 'loopDepth' loops
486
+ /// surrounding opInst. The computed region's 'cst' field has exactly as many
487
+ /// dimensional variables as the rank of the memref, and *potentially*
488
+ /// additional symbolic variables which could include any of the loop IVs
489
+ /// surrounding opInst up until 'loopDepth' and another additional Function
490
+ /// symbols involved with the access (for eg., those appear in affine.apply's,
491
+ /// loop bounds, etc.). If 'sliceState' is non-null, operands from
492
+ /// 'sliceState' are added as symbols, and the following constraints are added
493
+ /// to the system:
494
+ /// *) Inequality constraints which represent loop bounds for 'sliceState'
495
+ /// operands which are loop IVS (these represent the destination loop IVs
496
+ /// of the slice, and are added as symbols to MemRefRegion's constraint
497
+ /// system).
498
+ /// *) Inequality constraints for the slice bounds in 'sliceState', which
499
+ /// represent the bounds on the loop IVs in this constraint system w.r.t
500
+ /// to slice operands (which correspond to symbols).
501
+ /// If 'addMemRefDimBounds' is true, constant upper/lower bounds
502
+ /// [0, memref.getDimSize(i)) are added for each MemRef dimension 'i'.
503
+ /// If `dropLocalVars` is true, all local variables in `cst` are projected
504
+ /// out.
505
+ ///
506
+ /// For example, the memref region for this operation at loopDepth = 1 will
507
+ /// be:
508
+ ///
509
+ /// affine.for %i = 0 to 32 {
510
+ /// affine.for %ii = %i to (d0) -> (d0 + 8) (%i) {
511
+ /// load %A[%ii]
512
+ /// }
513
+ /// }
514
+ ///
515
+ /// {memref = %A, write = false, {%i <= m0 <= %i + 7} }
516
+ /// The last field is a 2-d FlatAffineValueConstraints symbolic in %i.
517
+ ///
518
+ /// If `dropOuterIVs` is true, project out any IVs other than those among
519
+ /// `loopDepth` surrounding IVs, which would be symbols. If `dropOuterIVs`
520
+ /// is false, the IVs would be turned into local variables instead of being
521
+ /// projected out.
522
+ LogicalResult compute(Operation *op, unsigned loopDepth,
523
+ const ComputationSliceState *sliceState = nullptr,
524
+ bool addMemRefDimBounds = true,
525
+ bool dropLocalVars = true, bool dropOuterIVs = true);
526
+
527
+ FlatAffineValueConstraints *getConstraints() { return &cst; }
528
+ const FlatAffineValueConstraints *getConstraints() const { return &cst; }
529
+ bool isWrite() const { return write; }
530
+ void setWrite(bool flag) { write = flag; }
531
+
532
+ /// Returns a constant upper bound on the number of elements in this region if
533
+ /// bounded by a known constant (always possible for static shapes),
534
+ /// std::nullopt otherwise. Note that the symbols of the region are treated
535
+ /// specially, i.e., the returned bounding constant holds for *any given*
536
+ /// value of the symbol variables. The 'shape' vector is set to the
537
+ /// corresponding dimension-wise bounds major to minor. The number of elements
538
+ /// and all the dimension-wise bounds are guaranteed to be non-negative. We
539
+ /// use int64_t instead of uint64_t since index types can be at most
540
+ /// int64_t. `lbs` are set to the lower bound maps for each of the rank
541
+ /// dimensions where each of these maps is purely symbolic in the constraints
542
+ /// set's symbols.
543
+ std::optional<int64_t> getConstantBoundingSizeAndShape(
544
+ SmallVectorImpl<int64_t> *shape = nullptr,
545
+ SmallVectorImpl<AffineMap> *lbs = nullptr) const;
546
+
547
+ /// Gets the lower and upper bound map for the dimensional variable at
548
+ /// `pos`.
549
+ void getLowerAndUpperBound(unsigned pos, AffineMap &lbMap,
550
+ AffineMap &ubMap) const;
551
+
552
+ /// Returns the size of this MemRefRegion in bytes.
553
+ std::optional<int64_t> getRegionSize();
554
+
555
+ // Wrapper around FlatAffineValueConstraints::unionBoundingBox.
556
+ LogicalResult unionBoundingBox(const MemRefRegion &other);
557
+
558
+ /// Returns the rank of the memref that this region corresponds to.
559
+ unsigned getRank() const;
560
+
561
+ /// Memref that this region corresponds to.
562
+ Value memref;
563
+
564
+ /// Read or write.
565
+ bool write = false;
566
+
567
+ /// If there is more than one load/store op associated with the region, the
568
+ /// location information would correspond to one of those op's.
569
+ Location loc;
570
+
571
+ /// Region (data space) of the memref accessed. This set will thus have at
572
+ /// least as many dimensional variables as the shape dimensionality of the
573
+ /// memref, and these are the leading dimensions of the set appearing in that
574
+ /// order (major to minor / outermost to innermost). There may be additional
575
+ /// variables since getMemRefRegion() is called with a specific loop depth,
576
+ /// and thus the region is symbolic in the outer surrounding loops at that
577
+ /// depth.
578
+ FlatAffineValueConstraints cst;
579
+ };
580
+
581
+ /// Returns the size of a memref with element type int or float in bytes if it's
582
+ /// statically shaped, std::nullopt otherwise.
583
+ std::optional<uint64_t> getIntOrFloatMemRefSizeInBytes(MemRefType memRefType);
584
+
585
+ /// Checks a load or store op for an out of bound access; returns failure if the
586
+ /// access is out of bounds along any of the dimensions, success otherwise.
587
+ /// Emits a diagnostic error (with location information) if emitError is true.
588
+ template <typename LoadOrStoreOpPointer>
589
+ LogicalResult boundCheckLoadOrStoreOp(LoadOrStoreOpPointer loadOrStoreOp,
590
+ bool emitError = true);
591
+
592
+ /// Returns the number of surrounding loops common to both A and B.
593
+ unsigned getNumCommonSurroundingLoops(Operation &a, Operation &b);
594
+
595
+ /// Gets the memory footprint of all data touched in the specified memory space
596
+ /// in bytes; if the memory space is unspecified, considers all memory spaces.
597
+ std::optional<int64_t> getMemoryFootprintBytes(AffineForOp forOp,
598
+ int memorySpace = -1);
599
+
600
+ /// Returns the memref's element type's size in bytes where the elemental type
601
+ /// is an int or float or a vector of such types.
602
+ std::optional<int64_t> getMemRefIntOrFloatEltSizeInBytes(MemRefType memRefType);
603
+
604
+ /// Simplify the integer set by simplifying the underlying affine expressions by
605
+ /// flattening and some simple inference. Also, drop any duplicate constraints.
606
+ /// Returns the simplified integer set. This method runs in time linear in the
607
+ /// number of constraints.
608
+ IntegerSet simplifyIntegerSet(IntegerSet set);
609
+
610
+ /// Returns the innermost common loop depth for the set of operations in 'ops'.
611
+ unsigned getInnermostCommonLoopDepth(
612
+ ArrayRef<Operation *> ops,
613
+ SmallVectorImpl<AffineForOp> *surroundingLoops = nullptr);
614
+
615
+ /// Try to simplify the given affine.min or affine.max op to an affine map with
616
+ /// a single result and operands, taking into account the specified constraint
617
+ /// set. Return failure if no simplified version could be found.
618
+ FailureOr<AffineValueMap>
619
+ simplifyConstrainedMinMaxOp(Operation *op,
620
+ FlatAffineValueConstraints constraints);
621
+
622
+ /// Find the innermost common `Block` of `a` and `b` in the affine scope
623
+ /// that `a` and `b` are part of. Return nullptr if they belong to different
624
+ /// affine scopes. Also, return nullptr if they do not have a common `Block`
625
+ /// ancestor (for eg., when they are part of the `then` and `else` regions
626
+ /// of an op that itself starts an affine scope.
627
+ mlir::Block *findInnermostCommonBlockInScope(mlir::Operation *a,
628
+ mlir::Operation *b);
629
+
630
+ } // namespace affine
631
+ } // namespace mlir
632
+
633
+ #endif // MLIR_DIALECT_AFFINE_ANALYSIS_UTILS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.cpp.inc ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Interface Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+
10
+ /// Returns the AffineMapAttr associated with 'memref'.
11
+ ::mlir::NamedAttribute mlir::affine::AffineMapAccessInterface::getAffineMapAttrForMemRef(::mlir::Value memref) {
12
+ return getImpl()->getAffineMapAttrForMemRef(getImpl(), getOperation(), memref);
13
+ }
14
+
15
+ /// Returns the memref operand to read from.
16
+ ::mlir::Value mlir::affine::AffineReadOpInterface::getMemRef() {
17
+ return getImpl()->getMemRef(getImpl(), getOperation());
18
+ }
19
+
20
+ /// Returns the type of the memref operand.
21
+ ::mlir::MemRefType mlir::affine::AffineReadOpInterface::getMemRefType() {
22
+ return getImpl()->getMemRefType(getImpl(), getOperation());
23
+ }
24
+
25
+ /// Returns affine map operands.
26
+ ::mlir::Operation::operand_range mlir::affine::AffineReadOpInterface::getMapOperands() {
27
+ return getImpl()->getMapOperands(getImpl(), getOperation());
28
+ }
29
+
30
+ /// Returns the affine map used to index the memref for this operation.
31
+ ::mlir::AffineMap mlir::affine::AffineReadOpInterface::getAffineMap() {
32
+ return getImpl()->getAffineMap(getImpl(), getOperation());
33
+ }
34
+
35
+ /// Returns the value read by this operation.
36
+ ::mlir::Value mlir::affine::AffineReadOpInterface::getValue() {
37
+ return getImpl()->getValue(getImpl(), getOperation());
38
+ }
39
+
40
+ /// Returns the memref operand to write to.
41
+ ::mlir::Value mlir::affine::AffineWriteOpInterface::getMemRef() {
42
+ return getImpl()->getMemRef(getImpl(), getOperation());
43
+ }
44
+
45
+ /// Returns the type of the memref operand.
46
+ ::mlir::MemRefType mlir::affine::AffineWriteOpInterface::getMemRefType() {
47
+ return getImpl()->getMemRefType(getImpl(), getOperation());
48
+ }
49
+
50
+ /// Returns affine map operands.
51
+ ::mlir::Operation::operand_range mlir::affine::AffineWriteOpInterface::getMapOperands() {
52
+ return getImpl()->getMapOperands(getImpl(), getOperation());
53
+ }
54
+
55
+ /// Returns the affine map used to index the memref for this operation.
56
+ ::mlir::AffineMap mlir::affine::AffineWriteOpInterface::getAffineMap() {
57
+ return getImpl()->getAffineMap(getImpl(), getOperation());
58
+ }
59
+
60
+ /// Returns the value to store.
61
+ ::mlir::Value mlir::affine::AffineWriteOpInterface::getValueToStore() {
62
+ return getImpl()->getValueToStore(getImpl(), getOperation());
63
+ }
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AffineMemoryOpInterfaces.h -------------------------------*- 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 file contains a set of interfaces for affine memory ops.
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #ifndef MLIR_DIALECT_AFFINE_IR_AFFINEMEMORYOPINTERFACES_H
14
+ #define MLIR_DIALECT_AFFINE_IR_AFFINEMEMORYOPINTERFACES_H
15
+
16
+ #include "mlir/IR/AffineMap.h"
17
+ #include "mlir/IR/BuiltinTypes.h"
18
+ #include "mlir/IR/OpDefinition.h"
19
+
20
+ #include "mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.h.inc"
21
+
22
+ #endif // MLIR_DIALECT_AFFINE_IR_AFFINEMEMORYOPINTERFACES_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.h.inc ADDED
@@ -0,0 +1,435 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Interface Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+ namespace mlir {
10
+ namespace affine {
11
+ /// Interface to query characteristics of read-like ops with affine
12
+ /// restrictions.
13
+ class AffineReadOpInterface;
14
+ namespace detail {
15
+ struct AffineReadOpInterfaceInterfaceTraits {
16
+ struct Concept {
17
+ /// The methods defined by the interface.
18
+ ::mlir::Value (*getMemRef)(const Concept *impl, ::mlir::Operation *);
19
+ ::mlir::MemRefType (*getMemRefType)(const Concept *impl, ::mlir::Operation *);
20
+ ::mlir::Operation::operand_range (*getMapOperands)(const Concept *impl, ::mlir::Operation *);
21
+ ::mlir::AffineMap (*getAffineMap)(const Concept *impl, ::mlir::Operation *);
22
+ ::mlir::Value (*getValue)(const Concept *impl, ::mlir::Operation *);
23
+ };
24
+ template<typename ConcreteOp>
25
+ class Model : public Concept {
26
+ public:
27
+ using Interface = ::mlir::affine::AffineReadOpInterface;
28
+ Model() : Concept{getMemRef, getMemRefType, getMapOperands, getAffineMap, getValue} {}
29
+
30
+ static inline ::mlir::Value getMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
31
+ static inline ::mlir::MemRefType getMemRefType(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
32
+ static inline ::mlir::Operation::operand_range getMapOperands(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
33
+ static inline ::mlir::AffineMap getAffineMap(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
34
+ static inline ::mlir::Value getValue(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
35
+ };
36
+ template<typename ConcreteOp>
37
+ class FallbackModel : public Concept {
38
+ public:
39
+ using Interface = ::mlir::affine::AffineReadOpInterface;
40
+ FallbackModel() : Concept{getMemRef, getMemRefType, getMapOperands, getAffineMap, getValue} {}
41
+
42
+ static inline ::mlir::Value getMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
43
+ static inline ::mlir::MemRefType getMemRefType(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
44
+ static inline ::mlir::Operation::operand_range getMapOperands(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
45
+ static inline ::mlir::AffineMap getAffineMap(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
46
+ static inline ::mlir::Value getValue(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
47
+ };
48
+ template<typename ConcreteModel, typename ConcreteOp>
49
+ class ExternalModel : public FallbackModel<ConcreteModel> {
50
+ public:
51
+ using ConcreteEntity = ConcreteOp;
52
+ ::mlir::Value getMemRef(::mlir::Operation *tablegen_opaque_val) const;
53
+ ::mlir::MemRefType getMemRefType(::mlir::Operation *tablegen_opaque_val) const;
54
+ ::mlir::Operation::operand_range getMapOperands(::mlir::Operation *tablegen_opaque_val) const;
55
+ ::mlir::AffineMap getAffineMap(::mlir::Operation *tablegen_opaque_val) const;
56
+ ::mlir::Value getValue(::mlir::Operation *tablegen_opaque_val) const;
57
+ };
58
+ };
59
+ template <typename ConcreteOp>
60
+ struct AffineReadOpInterfaceTrait;
61
+
62
+ } // namespace detail
63
+ class AffineReadOpInterface : public ::mlir::OpInterface<AffineReadOpInterface, detail::AffineReadOpInterfaceInterfaceTraits> {
64
+ public:
65
+ using ::mlir::OpInterface<AffineReadOpInterface, detail::AffineReadOpInterfaceInterfaceTraits>::OpInterface;
66
+ template <typename ConcreteOp>
67
+ struct Trait : public detail::AffineReadOpInterfaceTrait<ConcreteOp> {};
68
+
69
+ /// Returns the memref operand to read from.
70
+ ::mlir::Value getMemRef();
71
+
72
+ /// Returns the type of the memref operand.
73
+ ::mlir::MemRefType getMemRefType();
74
+
75
+ /// Returns affine map operands.
76
+ ::mlir::Operation::operand_range getMapOperands();
77
+
78
+ /// Returns the affine map used to index the memref for this operation.
79
+ ::mlir::AffineMap getAffineMap();
80
+
81
+ /// Returns the value read by this operation.
82
+ ::mlir::Value getValue();
83
+ };
84
+ namespace detail {
85
+ template <typename ConcreteOp>
86
+ struct AffineReadOpInterfaceTrait : public ::mlir::OpInterface<AffineReadOpInterface, detail::AffineReadOpInterfaceInterfaceTraits>::Trait<ConcreteOp> {
87
+
88
+ /// Returns the memref operand to read from.
89
+ ::mlir::Value getMemRef() {
90
+ return (*static_cast<ConcreteOp *>(this)).getOperand((*static_cast<ConcreteOp *>(this)).getMemRefOperandIndex());
91
+ }
92
+
93
+ /// Returns the type of the memref operand.
94
+ ::mlir::MemRefType getMemRefType() {
95
+ return ::llvm::cast<::mlir::MemRefType>((*static_cast<ConcreteOp *>(this)).getMemRef().getType());
96
+ }
97
+
98
+ /// Returns affine map operands.
99
+ ::mlir::Operation::operand_range getMapOperands() {
100
+ return llvm::drop_begin((*static_cast<ConcreteOp *>(this)).getOperands(), 1);
101
+ }
102
+
103
+ /// Returns the affine map used to index the memref for this operation.
104
+ ::mlir::AffineMap getAffineMap() {
105
+ return (*static_cast<ConcreteOp *>(this)).getAffineMapAttr().getValue();
106
+ }
107
+
108
+ /// Returns the value read by this operation.
109
+ ::mlir::Value getValue() {
110
+ return (*static_cast<ConcreteOp *>(this));
111
+ }
112
+ };
113
+ }// namespace detail
114
+ } // namespace affine
115
+ } // namespace mlir
116
+ namespace mlir {
117
+ namespace affine {
118
+ /// Interface to query characteristics of write-like ops with affine
119
+ /// restrictions.
120
+ class AffineWriteOpInterface;
121
+ namespace detail {
122
+ struct AffineWriteOpInterfaceInterfaceTraits {
123
+ struct Concept {
124
+ /// The methods defined by the interface.
125
+ ::mlir::Value (*getMemRef)(const Concept *impl, ::mlir::Operation *);
126
+ ::mlir::MemRefType (*getMemRefType)(const Concept *impl, ::mlir::Operation *);
127
+ ::mlir::Operation::operand_range (*getMapOperands)(const Concept *impl, ::mlir::Operation *);
128
+ ::mlir::AffineMap (*getAffineMap)(const Concept *impl, ::mlir::Operation *);
129
+ ::mlir::Value (*getValueToStore)(const Concept *impl, ::mlir::Operation *);
130
+ };
131
+ template<typename ConcreteOp>
132
+ class Model : public Concept {
133
+ public:
134
+ using Interface = ::mlir::affine::AffineWriteOpInterface;
135
+ Model() : Concept{getMemRef, getMemRefType, getMapOperands, getAffineMap, getValueToStore} {}
136
+
137
+ static inline ::mlir::Value getMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
138
+ static inline ::mlir::MemRefType getMemRefType(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
139
+ static inline ::mlir::Operation::operand_range getMapOperands(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
140
+ static inline ::mlir::AffineMap getAffineMap(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
141
+ static inline ::mlir::Value getValueToStore(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
142
+ };
143
+ template<typename ConcreteOp>
144
+ class FallbackModel : public Concept {
145
+ public:
146
+ using Interface = ::mlir::affine::AffineWriteOpInterface;
147
+ FallbackModel() : Concept{getMemRef, getMemRefType, getMapOperands, getAffineMap, getValueToStore} {}
148
+
149
+ static inline ::mlir::Value getMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
150
+ static inline ::mlir::MemRefType getMemRefType(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
151
+ static inline ::mlir::Operation::operand_range getMapOperands(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
152
+ static inline ::mlir::AffineMap getAffineMap(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
153
+ static inline ::mlir::Value getValueToStore(const Concept *impl, ::mlir::Operation *tablegen_opaque_val);
154
+ };
155
+ template<typename ConcreteModel, typename ConcreteOp>
156
+ class ExternalModel : public FallbackModel<ConcreteModel> {
157
+ public:
158
+ using ConcreteEntity = ConcreteOp;
159
+ ::mlir::Value getMemRef(::mlir::Operation *tablegen_opaque_val) const;
160
+ ::mlir::MemRefType getMemRefType(::mlir::Operation *tablegen_opaque_val) const;
161
+ ::mlir::Operation::operand_range getMapOperands(::mlir::Operation *tablegen_opaque_val) const;
162
+ ::mlir::AffineMap getAffineMap(::mlir::Operation *tablegen_opaque_val) const;
163
+ ::mlir::Value getValueToStore(::mlir::Operation *tablegen_opaque_val) const;
164
+ };
165
+ };
166
+ template <typename ConcreteOp>
167
+ struct AffineWriteOpInterfaceTrait;
168
+
169
+ } // namespace detail
170
+ class AffineWriteOpInterface : public ::mlir::OpInterface<AffineWriteOpInterface, detail::AffineWriteOpInterfaceInterfaceTraits> {
171
+ public:
172
+ using ::mlir::OpInterface<AffineWriteOpInterface, detail::AffineWriteOpInterfaceInterfaceTraits>::OpInterface;
173
+ template <typename ConcreteOp>
174
+ struct Trait : public detail::AffineWriteOpInterfaceTrait<ConcreteOp> {};
175
+
176
+ /// Returns the memref operand to write to.
177
+ ::mlir::Value getMemRef();
178
+
179
+ /// Returns the type of the memref operand.
180
+ ::mlir::MemRefType getMemRefType();
181
+
182
+ /// Returns affine map operands.
183
+ ::mlir::Operation::operand_range getMapOperands();
184
+
185
+ /// Returns the affine map used to index the memref for this operation.
186
+ ::mlir::AffineMap getAffineMap();
187
+
188
+ /// Returns the value to store.
189
+ ::mlir::Value getValueToStore();
190
+ };
191
+ namespace detail {
192
+ template <typename ConcreteOp>
193
+ struct AffineWriteOpInterfaceTrait : public ::mlir::OpInterface<AffineWriteOpInterface, detail::AffineWriteOpInterfaceInterfaceTraits>::Trait<ConcreteOp> {
194
+
195
+ /// Returns the memref operand to write to.
196
+ ::mlir::Value getMemRef() {
197
+ return (*static_cast<ConcreteOp *>(this)).getOperand((*static_cast<ConcreteOp *>(this)).getMemRefOperandIndex());
198
+ }
199
+
200
+ /// Returns the type of the memref operand.
201
+ ::mlir::MemRefType getMemRefType() {
202
+ return ::llvm::cast<::mlir::MemRefType>((*static_cast<ConcreteOp *>(this)).getMemRef().getType());
203
+ }
204
+
205
+ /// Returns affine map operands.
206
+ ::mlir::Operation::operand_range getMapOperands() {
207
+ return llvm::drop_begin((*static_cast<ConcreteOp *>(this)).getOperands(), 2);
208
+ }
209
+
210
+ /// Returns the affine map used to index the memref for this operation.
211
+ ::mlir::AffineMap getAffineMap() {
212
+ return (*static_cast<ConcreteOp *>(this)).getAffineMapAttr().getValue();
213
+ }
214
+
215
+ /// Returns the value to store.
216
+ ::mlir::Value getValueToStore() {
217
+ return (*static_cast<ConcreteOp *>(this)).getOperand((*static_cast<ConcreteOp *>(this)).getStoredValOperandIndex());
218
+ }
219
+ };
220
+ }// namespace detail
221
+ } // namespace affine
222
+ } // namespace mlir
223
+ namespace mlir {
224
+ namespace affine {
225
+ /// Interface to query the AffineMap used to dereference and access a given
226
+ /// memref. Implementers of this interface must operate on at least one
227
+ /// memref operand. The memref argument given to this interface much match
228
+ /// one of those memref operands.
229
+ class AffineMapAccessInterface;
230
+ namespace detail {
231
+ struct AffineMapAccessInterfaceInterfaceTraits {
232
+ struct Concept {
233
+ /// The methods defined by the interface.
234
+ ::mlir::NamedAttribute (*getAffineMapAttrForMemRef)(const Concept *impl, ::mlir::Operation *, ::mlir::Value);
235
+ };
236
+ template<typename ConcreteOp>
237
+ class Model : public Concept {
238
+ public:
239
+ using Interface = ::mlir::affine::AffineMapAccessInterface;
240
+ Model() : Concept{getAffineMapAttrForMemRef} {}
241
+
242
+ static inline ::mlir::NamedAttribute getAffineMapAttrForMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val, ::mlir::Value memref);
243
+ };
244
+ template<typename ConcreteOp>
245
+ class FallbackModel : public Concept {
246
+ public:
247
+ using Interface = ::mlir::affine::AffineMapAccessInterface;
248
+ FallbackModel() : Concept{getAffineMapAttrForMemRef} {}
249
+
250
+ static inline ::mlir::NamedAttribute getAffineMapAttrForMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val, ::mlir::Value memref);
251
+ };
252
+ template<typename ConcreteModel, typename ConcreteOp>
253
+ class ExternalModel : public FallbackModel<ConcreteModel> {
254
+ public:
255
+ using ConcreteEntity = ConcreteOp;
256
+ ::mlir::NamedAttribute getAffineMapAttrForMemRef(::mlir::Operation *tablegen_opaque_val, ::mlir::Value memref) const;
257
+ };
258
+ };
259
+ template <typename ConcreteOp>
260
+ struct AffineMapAccessInterfaceTrait;
261
+
262
+ } // namespace detail
263
+ class AffineMapAccessInterface : public ::mlir::OpInterface<AffineMapAccessInterface, detail::AffineMapAccessInterfaceInterfaceTraits> {
264
+ public:
265
+ using ::mlir::OpInterface<AffineMapAccessInterface, detail::AffineMapAccessInterfaceInterfaceTraits>::OpInterface;
266
+ template <typename ConcreteOp>
267
+ struct Trait : public detail::AffineMapAccessInterfaceTrait<ConcreteOp> {};
268
+
269
+ /// Returns the AffineMapAttr associated with 'memref'.
270
+ ::mlir::NamedAttribute getAffineMapAttrForMemRef(::mlir::Value memref);
271
+ };
272
+ namespace detail {
273
+ template <typename ConcreteOp>
274
+ struct AffineMapAccessInterfaceTrait : public ::mlir::OpInterface<AffineMapAccessInterface, detail::AffineMapAccessInterfaceInterfaceTraits>::Trait<ConcreteOp> {
275
+
276
+ /// Returns the AffineMapAttr associated with 'memref'.
277
+ ::mlir::NamedAttribute getAffineMapAttrForMemRef(::mlir::Value memref) {
278
+ assert(memref == (*static_cast<ConcreteOp *>(this)).getMemRef() &&
279
+ "Expected memref argument to match memref operand");
280
+ return {::mlir::StringAttr::get(
281
+ (*static_cast<ConcreteOp *>(this)).getContext(), (*static_cast<ConcreteOp *>(this)).getMapAttrStrName()),
282
+ (*static_cast<ConcreteOp *>(this)).getAffineMapAttr()};
283
+ }
284
+ };
285
+ }// namespace detail
286
+ } // namespace affine
287
+ } // namespace mlir
288
+ namespace mlir {
289
+ namespace affine {
290
+ template<typename ConcreteOp>
291
+ ::mlir::Value detail::AffineReadOpInterfaceInterfaceTraits::Model<ConcreteOp>::getMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
292
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRef();
293
+ }
294
+ template<typename ConcreteOp>
295
+ ::mlir::MemRefType detail::AffineReadOpInterfaceInterfaceTraits::Model<ConcreteOp>::getMemRefType(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
296
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRefType();
297
+ }
298
+ template<typename ConcreteOp>
299
+ ::mlir::Operation::operand_range detail::AffineReadOpInterfaceInterfaceTraits::Model<ConcreteOp>::getMapOperands(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
300
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMapOperands();
301
+ }
302
+ template<typename ConcreteOp>
303
+ ::mlir::AffineMap detail::AffineReadOpInterfaceInterfaceTraits::Model<ConcreteOp>::getAffineMap(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
304
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getAffineMap();
305
+ }
306
+ template<typename ConcreteOp>
307
+ ::mlir::Value detail::AffineReadOpInterfaceInterfaceTraits::Model<ConcreteOp>::getValue(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
308
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getValue();
309
+ }
310
+ template<typename ConcreteOp>
311
+ ::mlir::Value detail::AffineReadOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
312
+ return static_cast<const ConcreteOp *>(impl)->getMemRef(tablegen_opaque_val);
313
+ }
314
+ template<typename ConcreteOp>
315
+ ::mlir::MemRefType detail::AffineReadOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getMemRefType(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
316
+ return static_cast<const ConcreteOp *>(impl)->getMemRefType(tablegen_opaque_val);
317
+ }
318
+ template<typename ConcreteOp>
319
+ ::mlir::Operation::operand_range detail::AffineReadOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getMapOperands(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
320
+ return static_cast<const ConcreteOp *>(impl)->getMapOperands(tablegen_opaque_val);
321
+ }
322
+ template<typename ConcreteOp>
323
+ ::mlir::AffineMap detail::AffineReadOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getAffineMap(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
324
+ return static_cast<const ConcreteOp *>(impl)->getAffineMap(tablegen_opaque_val);
325
+ }
326
+ template<typename ConcreteOp>
327
+ ::mlir::Value detail::AffineReadOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getValue(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
328
+ return static_cast<const ConcreteOp *>(impl)->getValue(tablegen_opaque_val);
329
+ }
330
+ template<typename ConcreteModel, typename ConcreteOp>
331
+ ::mlir::Value detail::AffineReadOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getMemRef(::mlir::Operation *tablegen_opaque_val) const {
332
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getOperand((llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRefOperandIndex());
333
+ }
334
+ template<typename ConcreteModel, typename ConcreteOp>
335
+ ::mlir::MemRefType detail::AffineReadOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getMemRefType(::mlir::Operation *tablegen_opaque_val) const {
336
+ return ::llvm::cast<::mlir::MemRefType>((llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRef().getType());
337
+ }
338
+ template<typename ConcreteModel, typename ConcreteOp>
339
+ ::mlir::Operation::operand_range detail::AffineReadOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getMapOperands(::mlir::Operation *tablegen_opaque_val) const {
340
+ return llvm::drop_begin((llvm::cast<ConcreteOp>(tablegen_opaque_val)).getOperands(), 1);
341
+ }
342
+ template<typename ConcreteModel, typename ConcreteOp>
343
+ ::mlir::AffineMap detail::AffineReadOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getAffineMap(::mlir::Operation *tablegen_opaque_val) const {
344
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getAffineMapAttr().getValue();
345
+ }
346
+ template<typename ConcreteModel, typename ConcreteOp>
347
+ ::mlir::Value detail::AffineReadOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getValue(::mlir::Operation *tablegen_opaque_val) const {
348
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val));
349
+ }
350
+ } // namespace affine
351
+ } // namespace mlir
352
+ namespace mlir {
353
+ namespace affine {
354
+ template<typename ConcreteOp>
355
+ ::mlir::Value detail::AffineWriteOpInterfaceInterfaceTraits::Model<ConcreteOp>::getMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
356
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRef();
357
+ }
358
+ template<typename ConcreteOp>
359
+ ::mlir::MemRefType detail::AffineWriteOpInterfaceInterfaceTraits::Model<ConcreteOp>::getMemRefType(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
360
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRefType();
361
+ }
362
+ template<typename ConcreteOp>
363
+ ::mlir::Operation::operand_range detail::AffineWriteOpInterfaceInterfaceTraits::Model<ConcreteOp>::getMapOperands(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
364
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMapOperands();
365
+ }
366
+ template<typename ConcreteOp>
367
+ ::mlir::AffineMap detail::AffineWriteOpInterfaceInterfaceTraits::Model<ConcreteOp>::getAffineMap(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
368
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getAffineMap();
369
+ }
370
+ template<typename ConcreteOp>
371
+ ::mlir::Value detail::AffineWriteOpInterfaceInterfaceTraits::Model<ConcreteOp>::getValueToStore(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
372
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getValueToStore();
373
+ }
374
+ template<typename ConcreteOp>
375
+ ::mlir::Value detail::AffineWriteOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
376
+ return static_cast<const ConcreteOp *>(impl)->getMemRef(tablegen_opaque_val);
377
+ }
378
+ template<typename ConcreteOp>
379
+ ::mlir::MemRefType detail::AffineWriteOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getMemRefType(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
380
+ return static_cast<const ConcreteOp *>(impl)->getMemRefType(tablegen_opaque_val);
381
+ }
382
+ template<typename ConcreteOp>
383
+ ::mlir::Operation::operand_range detail::AffineWriteOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getMapOperands(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
384
+ return static_cast<const ConcreteOp *>(impl)->getMapOperands(tablegen_opaque_val);
385
+ }
386
+ template<typename ConcreteOp>
387
+ ::mlir::AffineMap detail::AffineWriteOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getAffineMap(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
388
+ return static_cast<const ConcreteOp *>(impl)->getAffineMap(tablegen_opaque_val);
389
+ }
390
+ template<typename ConcreteOp>
391
+ ::mlir::Value detail::AffineWriteOpInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getValueToStore(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) {
392
+ return static_cast<const ConcreteOp *>(impl)->getValueToStore(tablegen_opaque_val);
393
+ }
394
+ template<typename ConcreteModel, typename ConcreteOp>
395
+ ::mlir::Value detail::AffineWriteOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getMemRef(::mlir::Operation *tablegen_opaque_val) const {
396
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getOperand((llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRefOperandIndex());
397
+ }
398
+ template<typename ConcreteModel, typename ConcreteOp>
399
+ ::mlir::MemRefType detail::AffineWriteOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getMemRefType(::mlir::Operation *tablegen_opaque_val) const {
400
+ return ::llvm::cast<::mlir::MemRefType>((llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRef().getType());
401
+ }
402
+ template<typename ConcreteModel, typename ConcreteOp>
403
+ ::mlir::Operation::operand_range detail::AffineWriteOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getMapOperands(::mlir::Operation *tablegen_opaque_val) const {
404
+ return llvm::drop_begin((llvm::cast<ConcreteOp>(tablegen_opaque_val)).getOperands(), 2);
405
+ }
406
+ template<typename ConcreteModel, typename ConcreteOp>
407
+ ::mlir::AffineMap detail::AffineWriteOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getAffineMap(::mlir::Operation *tablegen_opaque_val) const {
408
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getAffineMapAttr().getValue();
409
+ }
410
+ template<typename ConcreteModel, typename ConcreteOp>
411
+ ::mlir::Value detail::AffineWriteOpInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getValueToStore(::mlir::Operation *tablegen_opaque_val) const {
412
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getOperand((llvm::cast<ConcreteOp>(tablegen_opaque_val)).getStoredValOperandIndex());
413
+ }
414
+ } // namespace affine
415
+ } // namespace mlir
416
+ namespace mlir {
417
+ namespace affine {
418
+ template<typename ConcreteOp>
419
+ ::mlir::NamedAttribute detail::AffineMapAccessInterfaceInterfaceTraits::Model<ConcreteOp>::getAffineMapAttrForMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val, ::mlir::Value memref) {
420
+ return (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getAffineMapAttrForMemRef(memref);
421
+ }
422
+ template<typename ConcreteOp>
423
+ ::mlir::NamedAttribute detail::AffineMapAccessInterfaceInterfaceTraits::FallbackModel<ConcreteOp>::getAffineMapAttrForMemRef(const Concept *impl, ::mlir::Operation *tablegen_opaque_val, ::mlir::Value memref) {
424
+ return static_cast<const ConcreteOp *>(impl)->getAffineMapAttrForMemRef(tablegen_opaque_val, memref);
425
+ }
426
+ template<typename ConcreteModel, typename ConcreteOp>
427
+ ::mlir::NamedAttribute detail::AffineMapAccessInterfaceInterfaceTraits::ExternalModel<ConcreteModel, ConcreteOp>::getAffineMapAttrForMemRef(::mlir::Operation *tablegen_opaque_val, ::mlir::Value memref) const {
428
+ assert(memref == (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMemRef() &&
429
+ "Expected memref argument to match memref operand");
430
+ return {::mlir::StringAttr::get(
431
+ (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getContext(), (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getMapAttrStrName()),
432
+ (llvm::cast<ConcreteOp>(tablegen_opaque_val)).getAffineMapAttr()};
433
+ }
434
+ } // namespace affine
435
+ } // namespace mlir
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOps.cpp.inc ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOps.h ADDED
@@ -0,0 +1,557 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AffineOps.h - MLIR Affine Operations -------------------------------===//
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 file defines convenience types for working with Affine operations
10
+ // in the MLIR operation set.
11
+ //
12
+ //===----------------------------------------------------------------------===//
13
+
14
+ #ifndef MLIR_DIALECT_AFFINE_IR_AFFINEOPS_H
15
+ #define MLIR_DIALECT_AFFINE_IR_AFFINEOPS_H
16
+
17
+ #include "mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.h"
18
+ #include "mlir/Dialect/Arith/IR/Arith.h"
19
+ #include "mlir/Dialect/Utils/StaticValueUtils.h"
20
+ #include "mlir/IR/AffineMap.h"
21
+ #include "mlir/IR/Builders.h"
22
+ #include "mlir/Interfaces/ControlFlowInterfaces.h"
23
+ #include "mlir/Interfaces/LoopLikeInterface.h"
24
+ namespace mlir {
25
+ namespace affine {
26
+
27
+ class AffineApplyOp;
28
+ class AffineBound;
29
+ class AffineMaxOp;
30
+ class AffineMinOp;
31
+ class AffineValueMap;
32
+
33
+ /// A utility function to check if a value is defined at the top level of an
34
+ /// op with trait `AffineScope` or is a region argument for such an op. A value
35
+ /// of index type defined at the top level is always a valid symbol for all its
36
+ /// uses.
37
+ bool isTopLevelValue(Value value);
38
+
39
+ /// A utility function to check if a value is defined at the top level of
40
+ /// `region` or is an argument of `region`. A value of index type defined at the
41
+ /// top level of a `AffineScope` region is always a valid symbol for all
42
+ /// uses in that region.
43
+ bool isTopLevelValue(Value value, Region *region);
44
+
45
+ /// Returns the closest region enclosing `op` that is held by an operation with
46
+ /// trait `AffineScope`; `nullptr` if there is no such region.
47
+ Region *getAffineScope(Operation *op);
48
+
49
+ /// Returns the closest region enclosing `op` that is held by a non-affine
50
+ /// operation; `nullptr` if there is no such region. This method is meant to
51
+ /// be used by affine analysis methods (e.g. dependence analysis) which are
52
+ /// only meaningful when performed among/between operations from the same
53
+ /// analysis scope.
54
+ Region *getAffineAnalysisScope(Operation *op);
55
+
56
+ /// Return the product of `terms`, creating an `affine.apply` if any of them are
57
+ /// non-constant values. If any of `terms` is `nullptr`, return `nullptr`.
58
+ OpFoldResult computeProduct(Location loc, OpBuilder &builder,
59
+ ArrayRef<OpFoldResult> terms);
60
+
61
+ /// AffineDmaStartOp starts a non-blocking DMA operation that transfers data
62
+ /// from a source memref to a destination memref. The source and destination
63
+ /// memref need not be of the same dimensionality, but need to have the same
64
+ /// elemental type. The operands include the source and destination memref's
65
+ /// each followed by its indices, size of the data transfer in terms of the
66
+ /// number of elements (of the elemental type of the memref), a tag memref with
67
+ /// its indices, and optionally at the end, a stride and a
68
+ /// number_of_elements_per_stride arguments. The tag location is used by an
69
+ /// AffineDmaWaitOp to check for completion. The indices of the source memref,
70
+ /// destination memref, and the tag memref have the same restrictions as any
71
+ /// affine.load/store. In particular, index for each memref dimension must be an
72
+ /// affine expression of loop induction variables and symbols.
73
+ /// The optional stride arguments should be of 'index' type, and specify a
74
+ /// stride for the slower memory space (memory space with a lower memory space
75
+ /// id), transferring chunks of number_of_elements_per_stride every stride until
76
+ /// %num_elements are transferred. Either both or no stride arguments should be
77
+ /// specified. The value of 'num_elements' must be a multiple of
78
+ /// 'number_of_elements_per_stride'. If the source and destination locations
79
+ /// overlap the behavior of this operation is not defined.
80
+ //
81
+ // For example, an AffineDmaStartOp operation that transfers 256 elements of a
82
+ // memref '%src' in memory space 0 at indices [%i + 3, %j] to memref '%dst' in
83
+ // memory space 1 at indices [%k + 7, %l], would be specified as follows:
84
+ //
85
+ // %num_elements = arith.constant 256
86
+ // %idx = arith.constant 0 : index
87
+ // %tag = memref.alloc() : memref<1xi32, 4>
88
+ // affine.dma_start %src[%i + 3, %j], %dst[%k + 7, %l], %tag[%idx],
89
+ // %num_elements :
90
+ // memref<40x128xf32, 0>, memref<2x1024xf32, 1>, memref<1xi32, 2>
91
+ //
92
+ // If %stride and %num_elt_per_stride are specified, the DMA is expected to
93
+ // transfer %num_elt_per_stride elements every %stride elements apart from
94
+ // memory space 0 until %num_elements are transferred.
95
+ //
96
+ // affine.dma_start %src[%i, %j], %dst[%k, %l], %tag[%idx], %num_elements,
97
+ // %stride, %num_elt_per_stride : ...
98
+ //
99
+ // TODO: add additional operands to allow source and destination striding, and
100
+ // multiple stride levels (possibly using AffineMaps to specify multiple levels
101
+ // of striding).
102
+ class AffineDmaStartOp
103
+ : public Op<AffineDmaStartOp, OpTrait::MemRefsNormalizable,
104
+ OpTrait::VariadicOperands, OpTrait::ZeroResults,
105
+ OpTrait::OpInvariants, AffineMapAccessInterface::Trait,
106
+ MemoryEffectOpInterface::Trait> {
107
+ public:
108
+ using Op::Op;
109
+ static ArrayRef<StringRef> getAttributeNames() { return {}; }
110
+
111
+ static void build(OpBuilder &builder, OperationState &result, Value srcMemRef,
112
+ AffineMap srcMap, ValueRange srcIndices, Value destMemRef,
113
+ AffineMap dstMap, ValueRange destIndices, Value tagMemRef,
114
+ AffineMap tagMap, ValueRange tagIndices, Value numElements,
115
+ Value stride = nullptr, Value elementsPerStride = nullptr);
116
+
117
+ /// Returns the operand index of the source memref.
118
+ unsigned getSrcMemRefOperandIndex() { return 0; }
119
+
120
+ /// Returns the source MemRefType for this DMA operation.
121
+ Value getSrcMemRef() { return getOperand(getSrcMemRefOperandIndex()); }
122
+ OpOperand &getSrcMemRefMutable() {
123
+ return getOperation()->getOpOperand(getSrcMemRefOperandIndex());
124
+ }
125
+ MemRefType getSrcMemRefType() {
126
+ return cast<MemRefType>(getSrcMemRef().getType());
127
+ }
128
+
129
+ /// Returns the rank (number of indices) of the source MemRefType.
130
+ unsigned getSrcMemRefRank() { return getSrcMemRefType().getRank(); }
131
+
132
+ /// Returns the affine map used to access the source memref.
133
+ AffineMap getSrcMap() { return getSrcMapAttr().getValue(); }
134
+ AffineMapAttr getSrcMapAttr() {
135
+ return cast<AffineMapAttr>(
136
+ *(*this)->getInherentAttr(getSrcMapAttrStrName()));
137
+ }
138
+
139
+ /// Returns the source memref affine map indices for this DMA operation.
140
+ operand_range getSrcIndices() {
141
+ return {operand_begin() + getSrcMemRefOperandIndex() + 1,
142
+ operand_begin() + getSrcMemRefOperandIndex() + 1 +
143
+ getSrcMap().getNumInputs()};
144
+ }
145
+
146
+ /// Returns the memory space of the source memref.
147
+ unsigned getSrcMemorySpace() {
148
+ return cast<MemRefType>(getSrcMemRef().getType()).getMemorySpaceAsInt();
149
+ }
150
+
151
+ /// Returns the operand index of the destination memref.
152
+ unsigned getDstMemRefOperandIndex() {
153
+ return getSrcMemRefOperandIndex() + 1 + getSrcMap().getNumInputs();
154
+ }
155
+
156
+ /// Returns the destination MemRefType for this DMA operation.
157
+ Value getDstMemRef() { return getOperand(getDstMemRefOperandIndex()); }
158
+ OpOperand &getDstMemRefMutable() {
159
+ return getOperation()->getOpOperand(getDstMemRefOperandIndex());
160
+ }
161
+ MemRefType getDstMemRefType() {
162
+ return cast<MemRefType>(getDstMemRef().getType());
163
+ }
164
+
165
+ /// Returns the rank (number of indices) of the destination MemRefType.
166
+ unsigned getDstMemRefRank() {
167
+ return cast<MemRefType>(getDstMemRef().getType()).getRank();
168
+ }
169
+
170
+ /// Returns the memory space of the source memref.
171
+ unsigned getDstMemorySpace() {
172
+ return cast<MemRefType>(getDstMemRef().getType()).getMemorySpaceAsInt();
173
+ }
174
+
175
+ /// Returns the affine map used to access the destination memref.
176
+ AffineMap getDstMap() { return getDstMapAttr().getValue(); }
177
+ AffineMapAttr getDstMapAttr() {
178
+ return cast<AffineMapAttr>(
179
+ *(*this)->getInherentAttr(getDstMapAttrStrName()));
180
+ }
181
+
182
+ /// Returns the destination memref indices for this DMA operation.
183
+ operand_range getDstIndices() {
184
+ return {operand_begin() + getDstMemRefOperandIndex() + 1,
185
+ operand_begin() + getDstMemRefOperandIndex() + 1 +
186
+ getDstMap().getNumInputs()};
187
+ }
188
+
189
+ /// Returns the operand index of the tag memref.
190
+ unsigned getTagMemRefOperandIndex() {
191
+ return getDstMemRefOperandIndex() + 1 + getDstMap().getNumInputs();
192
+ }
193
+
194
+ /// Returns the Tag MemRef for this DMA operation.
195
+ Value getTagMemRef() { return getOperand(getTagMemRefOperandIndex()); }
196
+ OpOperand &getTagMemRefMutable() {
197
+ return getOperation()->getOpOperand(getTagMemRefOperandIndex());
198
+ }
199
+ MemRefType getTagMemRefType() {
200
+ return cast<MemRefType>(getTagMemRef().getType());
201
+ }
202
+
203
+ /// Returns the rank (number of indices) of the tag MemRefType.
204
+ unsigned getTagMemRefRank() {
205
+ return cast<MemRefType>(getTagMemRef().getType()).getRank();
206
+ }
207
+
208
+ /// Returns the affine map used to access the tag memref.
209
+ AffineMap getTagMap() { return getTagMapAttr().getValue(); }
210
+ AffineMapAttr getTagMapAttr() {
211
+ return cast<AffineMapAttr>(
212
+ *(*this)->getInherentAttr(getTagMapAttrStrName()));
213
+ }
214
+
215
+ /// Returns the tag memref indices for this DMA operation.
216
+ operand_range getTagIndices() {
217
+ return {operand_begin() + getTagMemRefOperandIndex() + 1,
218
+ operand_begin() + getTagMemRefOperandIndex() + 1 +
219
+ getTagMap().getNumInputs()};
220
+ }
221
+
222
+ /// Returns the number of elements being transferred by this DMA operation.
223
+ Value getNumElements() {
224
+ return getOperand(getTagMemRefOperandIndex() + 1 +
225
+ getTagMap().getNumInputs());
226
+ }
227
+
228
+ /// Impelements the AffineMapAccessInterface.
229
+ /// Returns the AffineMapAttr associated with 'memref'.
230
+ NamedAttribute getAffineMapAttrForMemRef(Value memref) {
231
+ if (memref == getSrcMemRef())
232
+ return {StringAttr::get(getContext(), getSrcMapAttrStrName()),
233
+ getSrcMapAttr()};
234
+ if (memref == getDstMemRef())
235
+ return {StringAttr::get(getContext(), getDstMapAttrStrName()),
236
+ getDstMapAttr()};
237
+ assert(memref == getTagMemRef() &&
238
+ "DmaStartOp expected source, destination or tag memref");
239
+ return {StringAttr::get(getContext(), getTagMapAttrStrName()),
240
+ getTagMapAttr()};
241
+ }
242
+
243
+ /// Returns true if this is a DMA from a faster memory space to a slower one.
244
+ bool isDestMemorySpaceFaster() {
245
+ return (getSrcMemorySpace() < getDstMemorySpace());
246
+ }
247
+
248
+ /// Returns true if this is a DMA from a slower memory space to a faster one.
249
+ bool isSrcMemorySpaceFaster() {
250
+ // Assumes that a lower number is for a slower memory space.
251
+ return (getDstMemorySpace() < getSrcMemorySpace());
252
+ }
253
+
254
+ /// Given a DMA start operation, returns the operand position of either the
255
+ /// source or destination memref depending on the one that is at the higher
256
+ /// level of the memory hierarchy. Asserts failure if neither is true.
257
+ unsigned getFasterMemPos() {
258
+ assert(isSrcMemorySpaceFaster() || isDestMemorySpaceFaster());
259
+ return isSrcMemorySpaceFaster() ? 0 : getDstMemRefOperandIndex();
260
+ }
261
+
262
+ void
263
+ getEffects(SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
264
+ &effects);
265
+
266
+ static StringRef getSrcMapAttrStrName() { return "src_map"; }
267
+ static StringRef getDstMapAttrStrName() { return "dst_map"; }
268
+ static StringRef getTagMapAttrStrName() { return "tag_map"; }
269
+
270
+ static StringRef getOperationName() { return "affine.dma_start"; }
271
+ static ParseResult parse(OpAsmParser &parser, OperationState &result);
272
+ void print(OpAsmPrinter &p);
273
+ LogicalResult verifyInvariantsImpl();
274
+ LogicalResult verifyInvariants() { return verifyInvariantsImpl(); }
275
+ LogicalResult fold(ArrayRef<Attribute> cstOperands,
276
+ SmallVectorImpl<OpFoldResult> &results);
277
+
278
+ /// Returns true if this DMA operation is strided, returns false otherwise.
279
+ bool isStrided() {
280
+ return getNumOperands() !=
281
+ getTagMemRefOperandIndex() + 1 + getTagMap().getNumInputs() + 1;
282
+ }
283
+
284
+ /// Returns the stride value for this DMA operation.
285
+ Value getStride() {
286
+ if (!isStrided())
287
+ return nullptr;
288
+ return getOperand(getNumOperands() - 1 - 1);
289
+ }
290
+
291
+ /// Returns the number of elements to transfer per stride for this DMA op.
292
+ Value getNumElementsPerStride() {
293
+ if (!isStrided())
294
+ return nullptr;
295
+ return getOperand(getNumOperands() - 1);
296
+ }
297
+ };
298
+
299
+ /// AffineDmaWaitOp blocks until the completion of a DMA operation associated
300
+ /// with the tag element '%tag[%index]'. %tag is a memref, and %index has to be
301
+ /// an index with the same restrictions as any load/store index. In particular,
302
+ /// index for each memref dimension must be an affine expression of loop
303
+ /// induction variables and symbols. %num_elements is the number of elements
304
+ /// associated with the DMA operation. For example:
305
+ //
306
+ // affine.dma_start %src[%i, %j], %dst[%k, %l], %tag[%index], %num_elements :
307
+ // memref<2048xf32, 0>, memref<256xf32, 1>, memref<1xi32, 2>
308
+ // ...
309
+ // ...
310
+ // affine.dma_wait %tag[%index], %num_elements : memref<1xi32, 2>
311
+ //
312
+ class AffineDmaWaitOp
313
+ : public Op<AffineDmaWaitOp, OpTrait::MemRefsNormalizable,
314
+ OpTrait::VariadicOperands, OpTrait::ZeroResults,
315
+ OpTrait::OpInvariants, AffineMapAccessInterface::Trait> {
316
+ public:
317
+ using Op::Op;
318
+ static ArrayRef<StringRef> getAttributeNames() { return {}; }
319
+
320
+ static void build(OpBuilder &builder, OperationState &result, Value tagMemRef,
321
+ AffineMap tagMap, ValueRange tagIndices, Value numElements);
322
+
323
+ static StringRef getOperationName() { return "affine.dma_wait"; }
324
+
325
+ /// Returns the Tag MemRef associated with the DMA operation being waited on.
326
+ Value getTagMemRef() { return getOperand(0); }
327
+ OpOperand &getTagMemRefMutable() { return getOperation()->getOpOperand(0); }
328
+ MemRefType getTagMemRefType() {
329
+ return cast<MemRefType>(getTagMemRef().getType());
330
+ }
331
+
332
+ /// Returns the affine map used to access the tag memref.
333
+ AffineMap getTagMap() { return getTagMapAttr().getValue(); }
334
+ AffineMapAttr getTagMapAttr() {
335
+ return cast<AffineMapAttr>(
336
+ *(*this)->getInherentAttr(getTagMapAttrStrName()));
337
+ }
338
+
339
+ /// Returns the tag memref index for this DMA operation.
340
+ operand_range getTagIndices() {
341
+ return {operand_begin() + 1,
342
+ operand_begin() + 1 + getTagMap().getNumInputs()};
343
+ }
344
+
345
+ /// Returns the rank (number of indices) of the tag memref.
346
+ unsigned getTagMemRefRank() {
347
+ return cast<MemRefType>(getTagMemRef().getType()).getRank();
348
+ }
349
+
350
+ /// Impelements the AffineMapAccessInterface. Returns the AffineMapAttr
351
+ /// associated with 'memref'.
352
+ NamedAttribute getAffineMapAttrForMemRef(Value memref) {
353
+ assert(memref == getTagMemRef());
354
+ return {StringAttr::get(getContext(), getTagMapAttrStrName()),
355
+ getTagMapAttr()};
356
+ }
357
+
358
+ /// Returns the number of elements transferred by the associated DMA op.
359
+ Value getNumElements() { return getOperand(1 + getTagMap().getNumInputs()); }
360
+
361
+ static StringRef getTagMapAttrStrName() { return "tag_map"; }
362
+ static ParseResult parse(OpAsmParser &parser, OperationState &result);
363
+ void print(OpAsmPrinter &p);
364
+ LogicalResult verifyInvariantsImpl();
365
+ LogicalResult verifyInvariants() { return verifyInvariantsImpl(); }
366
+ LogicalResult fold(ArrayRef<Attribute> cstOperands,
367
+ SmallVectorImpl<OpFoldResult> &results);
368
+ void
369
+ getEffects(SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
370
+ &effects);
371
+ };
372
+
373
+ /// Returns true if the given Value can be used as a dimension id in the region
374
+ /// of the closest surrounding op that has the trait `AffineScope`.
375
+ bool isValidDim(Value value);
376
+
377
+ /// Returns true if the given Value can be used as a dimension id in `region`,
378
+ /// i.e., for all its uses in `region`.
379
+ bool isValidDim(Value value, Region *region);
380
+
381
+ /// Returns true if the given value can be used as a symbol in the region of the
382
+ /// closest surrounding op that has the trait `AffineScope`.
383
+ bool isValidSymbol(Value value);
384
+
385
+ /// Returns true if the given Value can be used as a symbol for `region`, i.e.,
386
+ /// for all its uses in `region`.
387
+ bool isValidSymbol(Value value, Region *region);
388
+
389
+ /// Parses dimension and symbol list. `numDims` is set to the number of
390
+ /// dimensions in the list parsed.
391
+ ParseResult parseDimAndSymbolList(OpAsmParser &parser,
392
+ SmallVectorImpl<Value> &operands,
393
+ unsigned &numDims);
394
+
395
+ /// Modifies both `map` and `operands` in-place so as to:
396
+ /// 1. drop duplicate operands
397
+ /// 2. drop unused dims and symbols from map
398
+ /// 3. promote valid symbols to symbolic operands in case they appeared as
399
+ /// dimensional operands
400
+ /// 4. propagate constant operands and drop them
401
+ void canonicalizeMapAndOperands(AffineMap *map,
402
+ SmallVectorImpl<Value> *operands);
403
+
404
+ /// Canonicalizes an integer set the same way canonicalizeMapAndOperands does
405
+ /// for affine maps.
406
+ void canonicalizeSetAndOperands(IntegerSet *set,
407
+ SmallVectorImpl<Value> *operands);
408
+
409
+ /// Returns a composed AffineApplyOp by composing `map` and `operands` with
410
+ /// other AffineApplyOps supplying those operands. The operands of the resulting
411
+ /// AffineApplyOp do not change the length of AffineApplyOp chains.
412
+ AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineMap map,
413
+ ArrayRef<OpFoldResult> operands);
414
+ AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineExpr e,
415
+ ArrayRef<OpFoldResult> operands);
416
+
417
+ /// Constructs an AffineApplyOp that applies `map` to `operands` after composing
418
+ /// the map with the maps of any other AffineApplyOp supplying the operands,
419
+ /// then immediately attempts to fold it. If folding results in a constant
420
+ /// value, no ops are actually created. The `map` must be a single-result affine
421
+ /// map.
422
+ OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc,
423
+ AffineMap map,
424
+ ArrayRef<OpFoldResult> operands);
425
+ /// Variant of `makeComposedFoldedAffineApply` that applies to an expression.
426
+ OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc,
427
+ AffineExpr expr,
428
+ ArrayRef<OpFoldResult> operands);
429
+ /// Variant of `makeComposedFoldedAffineApply` suitable for multi-result maps.
430
+ /// Note that this may create as many affine.apply operations as the map has
431
+ /// results given that affine.apply must be single-result.
432
+ SmallVector<OpFoldResult> makeComposedFoldedMultiResultAffineApply(
433
+ OpBuilder &b, Location loc, AffineMap map, ArrayRef<OpFoldResult> operands);
434
+
435
+ /// Returns an AffineMinOp obtained by composing `map` and `operands` with
436
+ /// AffineApplyOps supplying those operands.
437
+ AffineMinOp makeComposedAffineMin(OpBuilder &b, Location loc, AffineMap map,
438
+ ArrayRef<OpFoldResult> operands);
439
+
440
+ /// Constructs an AffineMinOp that computes a minimum across the results of
441
+ /// applying `map` to `operands`, then immediately attempts to fold it. If
442
+ /// folding results in a constant value, no ops are actually created.
443
+ OpFoldResult makeComposedFoldedAffineMin(OpBuilder &b, Location loc,
444
+ AffineMap map,
445
+ ArrayRef<OpFoldResult> operands);
446
+
447
+ /// Constructs an AffineMinOp that computes a maximum across the results of
448
+ /// applying `map` to `operands`, then immediately attempts to fold it. If
449
+ /// folding results in a constant value, no ops are actually created.
450
+ OpFoldResult makeComposedFoldedAffineMax(OpBuilder &b, Location loc,
451
+ AffineMap map,
452
+ ArrayRef<OpFoldResult> operands);
453
+
454
+ /// Given an affine map `map` and its input `operands`, this method composes
455
+ /// into `map`, maps of AffineApplyOps whose results are the values in
456
+ /// `operands`, iteratively until no more of `operands` are the result of an
457
+ /// AffineApplyOp. When this function returns, `map` becomes the composed affine
458
+ /// map, and each Value in `operands` is guaranteed to be either a loop IV or a
459
+ /// terminal symbol, i.e., a symbol defined at the top level or a block/function
460
+ /// argument.
461
+ void fullyComposeAffineMapAndOperands(AffineMap *map,
462
+ SmallVectorImpl<Value> *operands);
463
+
464
+ } // namespace affine
465
+ } // namespace mlir
466
+
467
+ #include "mlir/Dialect/Affine/IR/AffineOpsDialect.h.inc"
468
+
469
+ #define GET_OP_CLASSES
470
+ #include "mlir/Dialect/Affine/IR/AffineOps.h.inc"
471
+
472
+ namespace mlir {
473
+ namespace affine {
474
+
475
+ /// Returns true if the provided value is the induction variable of an
476
+ /// AffineForOp.
477
+ bool isAffineForInductionVar(Value val);
478
+
479
+ /// Returns true if `val` is the induction variable of an AffineParallelOp.
480
+ bool isAffineParallelInductionVar(Value val);
481
+
482
+ /// Returns true if the provided value is the induction variable of an
483
+ /// AffineForOp or AffineParallelOp.
484
+ bool isAffineInductionVar(Value val);
485
+
486
+ /// Returns the loop parent of an induction variable. If the provided value is
487
+ /// not an induction variable, then return nullptr.
488
+ AffineForOp getForInductionVarOwner(Value val);
489
+
490
+ /// Returns true if the provided value is among the induction variables of an
491
+ /// AffineParallelOp.
492
+ AffineParallelOp getAffineParallelInductionVarOwner(Value val);
493
+
494
+ /// Extracts the induction variables from a list of AffineForOps and places them
495
+ /// in the output argument `ivs`.
496
+ void extractForInductionVars(ArrayRef<AffineForOp> forInsts,
497
+ SmallVectorImpl<Value> *ivs);
498
+
499
+ /// Extracts the induction variables from a list of either AffineForOp or
500
+ /// AffineParallelOp and places them in the output argument `ivs`.
501
+ void extractInductionVars(ArrayRef<Operation *> affineOps,
502
+ SmallVectorImpl<Value> &ivs);
503
+
504
+ /// Builds a perfect nest of affine.for loops, i.e., each loop except the
505
+ /// innermost one contains only another loop and a terminator. The loops iterate
506
+ /// from "lbs" to "ubs" with "steps". The body of the innermost loop is
507
+ /// populated by calling "bodyBuilderFn" and providing it with an OpBuilder, a
508
+ /// Location and a list of loop induction variables.
509
+ void buildAffineLoopNest(OpBuilder &builder, Location loc,
510
+ ArrayRef<int64_t> lbs, ArrayRef<int64_t> ubs,
511
+ ArrayRef<int64_t> steps,
512
+ function_ref<void(OpBuilder &, Location, ValueRange)>
513
+ bodyBuilderFn = nullptr);
514
+ void buildAffineLoopNest(OpBuilder &builder, Location loc, ValueRange lbs,
515
+ ValueRange ubs, ArrayRef<int64_t> steps,
516
+ function_ref<void(OpBuilder &, Location, ValueRange)>
517
+ bodyBuilderFn = nullptr);
518
+
519
+ /// AffineBound represents a lower or upper bound in the for operation.
520
+ /// This class does not own the underlying operands. Instead, it refers
521
+ /// to the operands stored in the AffineForOp. Its life span should not exceed
522
+ /// that of the for operation it refers to.
523
+ class AffineBound {
524
+ public:
525
+ AffineForOp getAffineForOp() { return op; }
526
+ AffineMap getMap() { return map; }
527
+
528
+ unsigned getNumOperands() { return operands.size(); }
529
+ Value getOperand(unsigned idx) {
530
+ return op.getOperand(operands.getBeginOperandIndex() + idx);
531
+ }
532
+
533
+ using operand_iterator = AffineForOp::operand_iterator;
534
+ using operand_range = AffineForOp::operand_range;
535
+
536
+ operand_iterator operandBegin() { return operands.begin(); }
537
+ operand_iterator operandEnd() { return operands.end(); }
538
+ operand_range getOperands() { return {operandBegin(), operandEnd()}; }
539
+
540
+ private:
541
+ // 'affine.for' operation that contains this bound.
542
+ AffineForOp op;
543
+ // Operands of the affine map.
544
+ OperandRange operands;
545
+ // Affine map for this bound.
546
+ AffineMap map;
547
+
548
+ AffineBound(AffineForOp op, OperandRange operands, AffineMap map)
549
+ : op(op), operands(operands), map(map) {}
550
+
551
+ friend class AffineForOp;
552
+ };
553
+
554
+ } // namespace affine
555
+ } // namespace mlir
556
+
557
+ #endif
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOps.h.inc ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOpsDialect.cpp.inc ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Dialect Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AffineOps.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::affine::AffineDialect)
11
+ namespace mlir {
12
+ namespace affine {
13
+
14
+ AffineDialect::AffineDialect(::mlir::MLIRContext *context)
15
+ : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get<AffineDialect>())
16
+
17
+ {
18
+ getContext()->loadDialect<arith::ArithDialect>();
19
+ getContext()->loadDialect<ub::UBDialect>();
20
+ initialize();
21
+ }
22
+
23
+ AffineDialect::~AffineDialect() = default;
24
+
25
+ } // namespace affine
26
+ } // namespace mlir
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineOpsDialect.h.inc ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* Dialect Declarations *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* From: AffineOps.td *|
7
+ |* *|
8
+ \*===----------------------------------------------------------------------===*/
9
+
10
+ namespace mlir {
11
+ namespace affine {
12
+
13
+
14
+ class AffineDialect : public ::mlir::Dialect {
15
+ explicit AffineDialect(::mlir::MLIRContext *context);
16
+
17
+ void initialize();
18
+ friend class ::mlir::MLIRContext;
19
+ public:
20
+ ~AffineDialect() override;
21
+ static constexpr ::llvm::StringLiteral getDialectNamespace() {
22
+ return ::llvm::StringLiteral("affine");
23
+ }
24
+
25
+ /// Materialize a single constant operation from a given attribute value with
26
+ /// the desired resultant type.
27
+ ::mlir::Operation *materializeConstant(::mlir::OpBuilder &builder,
28
+ ::mlir::Attribute value,
29
+ ::mlir::Type type,
30
+ ::mlir::Location loc) override;
31
+ };
32
+ } // namespace affine
33
+ } // namespace mlir
34
+ MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::affine::AffineDialect)
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/AffineValueMap.h ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- AffineValueMap.h - MLIR Affine Value Map Class -----------*- 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
+ // An AffineValueMap is an affine map plus its ML value operands and results for
10
+ // analysis purposes.
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #ifndef MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
14
+ #define MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
15
+
16
+ #include "mlir/IR/AffineMap.h"
17
+ #include "mlir/IR/OperationSupport.h"
18
+ #include "mlir/IR/Value.h"
19
+
20
+ namespace mlir {
21
+ namespace affine {
22
+
23
+ /// An AffineValueMap is an affine map plus its ML value operands and
24
+ /// results for analysis purposes. The structure is still a tree form that is
25
+ /// same as that of an affine map or an AffineApplyOp. However, its operands,
26
+ /// results, and its map can themselves change as a result of
27
+ /// substitutions, simplifications, and other analysis.
28
+ // An affine value map can readily be constructed from an AffineApplyOp, or an
29
+ // AffineBound of a AffineForOp. It can be further transformed, substituted
30
+ // into, or simplified. Unlike AffineMap's, AffineValueMap's are created and
31
+ // destroyed during analysis. Only the AffineMap expressions that are pointed by
32
+ // them are unique'd. An affine value map, and the operations on it, maintain
33
+ // the invariant that operands are always positionally aligned with the
34
+ // AffineDimExpr and AffineSymbolExpr in the underlying AffineMap.
35
+ class AffineValueMap {
36
+ public:
37
+ // Creates an empty AffineValueMap (users should call 'reset' to reset map
38
+ // and operands).
39
+ AffineValueMap() = default;
40
+ AffineValueMap(AffineMap map, ValueRange operands, ValueRange results = {});
41
+
42
+ ~AffineValueMap();
43
+
44
+ // Resets this AffineValueMap with 'map', 'operands', and 'results'.
45
+ void reset(AffineMap map, ValueRange operands, ValueRange results = {});
46
+
47
+ /// Composes all incoming affine.apply ops and then simplifies and
48
+ /// canonicalizes the map and operands. This can change the number of
49
+ /// operands, but the result count remains the same.
50
+ void composeSimplifyAndCanonicalize();
51
+
52
+ /// Return the value map that is the difference of value maps 'a' and 'b',
53
+ /// represented as an affine map and its operands. The output map + operands
54
+ /// are canonicalized and simplified.
55
+ static void difference(const AffineValueMap &a, const AffineValueMap &b,
56
+ AffineValueMap *res);
57
+
58
+ /// Return true if the idx^th result can be proved to be a multiple of
59
+ /// 'factor', false otherwise.
60
+ inline bool isMultipleOf(unsigned idx, int64_t factor) const;
61
+
62
+ /// Return true if the idx^th result depends on 'value', false otherwise.
63
+ bool isFunctionOf(unsigned idx, Value value) const;
64
+
65
+ /// Return true if the result at 'idx' is a constant, false
66
+ /// otherwise.
67
+ bool isConstant(unsigned idx) const;
68
+
69
+ /// Return true if this is an identity map.
70
+ bool isIdentity() const;
71
+
72
+ void setResult(unsigned i, AffineExpr e) { map.setResult(i, e); }
73
+ AffineExpr getResult(unsigned i) { return map.getResult(i); }
74
+ inline unsigned getNumOperands() const { return operands.size(); }
75
+ inline unsigned getNumDims() const { return map.getNumDims(); }
76
+ inline unsigned getNumSymbols() const { return map.getNumSymbols(); }
77
+ inline unsigned getNumResults() const { return map.getNumResults(); }
78
+
79
+ Value getOperand(unsigned i) const;
80
+ ArrayRef<Value> getOperands() const;
81
+ AffineMap getAffineMap() const;
82
+
83
+ /// Attempts to canonicalize the map and operands. Return success if the map
84
+ /// and/or operands have been modified.
85
+ LogicalResult canonicalize();
86
+
87
+ /// Checks if the application of this map to its operands is semantically
88
+ /// equal to `other`'s.
89
+ bool operator==(const AffineValueMap &other) const;
90
+ bool operator!=(const AffineValueMap &other) const {
91
+ return !(*this == other);
92
+ }
93
+
94
+ private:
95
+ // A mutable affine map.
96
+ MutableAffineMap map;
97
+
98
+ // TODO: make these trailing objects?
99
+ /// The SSA operands binding to the dim's and symbols of 'map'.
100
+ SmallVector<Value, 4> operands;
101
+ /// The SSA results binding to the results of 'map'.
102
+ SmallVector<Value, 4> results;
103
+ };
104
+
105
+ } // namespace affine
106
+ } // namespace mlir
107
+
108
+ #endif // MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.h ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- ValueBoundsOpInterfaceImpl.h - Impl. of ValueBoundsOpInterface -----===//
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_AFFINE_IR_VALUEBOUNDSOPINTERFACEIMPL_H
10
+ #define MLIR_DIALECT_AFFINE_IR_VALUEBOUNDSOPINTERFACEIMPL_H
11
+
12
+ #include "mlir/Support/LLVM.h"
13
+ #include <cstdint>
14
+
15
+ namespace mlir {
16
+ class DialectRegistry;
17
+ class Value;
18
+
19
+ namespace affine {
20
+ void registerValueBoundsOpInterfaceExternalModels(DialectRegistry &registry);
21
+
22
+ /// Compute a constant delta of the given two values. Return "failure" if we
23
+ /// cannot determine a constant delta. `value1`/`value2` must be index-typed.
24
+ ///
25
+ /// This function is similar to
26
+ /// `ValueBoundsConstraintSet::computeConstantDistance`. To work around
27
+ /// limitations in `FlatLinearConstraints`, this function fully composes
28
+ /// `value1` and `value2` (if they are the result of affine.apply ops) before
29
+ /// populating the constraint set. The folding/composing logic can see
30
+ /// opportunities for simplifications that the constraint set implementation
31
+ /// cannot see.
32
+ FailureOr<int64_t> fullyComposeAndComputeConstantDelta(Value value1,
33
+ Value value2);
34
+ } // namespace affine
35
+ } // namespace mlir
36
+
37
+ #endif // MLIR_DIALECT_AFFINE_IR_VALUEBOUNDSOPINTERFACEIMPL_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/LoopFusionUtils.h ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- LoopFusionUtils.h - Loop fusion 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 loop fusion utility
10
+ // methods: 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_AFFINE_LOOPFUSIONUTILS_H
16
+ #define MLIR_DIALECT_AFFINE_LOOPFUSIONUTILS_H
17
+
18
+ #include "mlir/IR/Value.h"
19
+ #include "mlir/Support/LLVM.h"
20
+ #include "llvm/ADT/DenseMap.h"
21
+ #include "llvm/ADT/SmallVector.h"
22
+
23
+ namespace mlir {
24
+ class Operation;
25
+
26
+ namespace affine {
27
+ class AffineForOp;
28
+ struct ComputationSliceState;
29
+
30
+ struct FusionResult {
31
+ enum ResultEnum {
32
+ Success,
33
+ FailPrecondition, // Failed precondition for fusion. (e.g. same block).
34
+ FailBlockDependence, // Fusion would violate another dependence in block.
35
+ FailFusionDependence, // Fusion would reverse dependences between loops.
36
+ FailComputationSlice, // Unable to compute src loop computation slice.
37
+ FailIncorrectSlice, // Slice is computed, but it is incorrect.
38
+ } value;
39
+ FusionResult(ResultEnum v) : value(v) {}
40
+ };
41
+
42
+ /// Describes the fusion strategy to be used in the Affine loop fusion
43
+ /// utilities. Currently, it is used to specialized the loop fusion utilities
44
+ /// with the assumptions made in the AffineLoopFusion pass for producer-consumer
45
+ /// and sibling fusion, while sharing a single implementation. The latter
46
+ /// strategies are also limited to scenarios where a single memref is involved
47
+ /// in the producer-consume or sibling relationship between the candidate
48
+ /// loops. We use 'memref' to keep track of such a memref.
49
+ // TODO: Generalize utilities so that producer-consumer and sibling fusion
50
+ // strategies can be used without the assumptions made in the AffineLoopFusion
51
+ // pass.
52
+ class FusionStrategy {
53
+ public:
54
+ enum StrategyEnum {
55
+ // Generic loop fusion: Arbitrary loops are considered for fusion. No
56
+ // assumptions about a specific fusion strategy from AffineLoopFusion pass
57
+ // are made.
58
+ // TODO: Generic fusion is not fully implemented by fusion utilities yet.
59
+ // It should only be used for testing.
60
+ Generic,
61
+ // Producer-consumer fusion: Only loops with a producer-consumer
62
+ // memref dependence are considered for fusion. Currently, assumptions from
63
+ // the producer-consumer fusion implementation in AffineLoopFusion pass are
64
+ // made. See pass for specific details.
65
+ ProducerConsumer,
66
+ // Sibling fusion: Only sibling loops with no producer-consumer memref
67
+ // dependences are considered for fusion. Memref reuse is taken into account
68
+ // for profitability. Currently, assumptions from the sibling fusion
69
+ // implementation in AffineLoopFusion pass are made. See pass for specific
70
+ // details.
71
+ Sibling
72
+ };
73
+
74
+ /// Construct a generic or producer-consumer fusion strategy.
75
+ FusionStrategy(StrategyEnum strategy) : strategy(strategy) {
76
+ assert(strategy != Sibling &&
77
+ "Sibling fusion strategy requires a specific memref");
78
+ }
79
+
80
+ /// Construct a sibling fusion strategy targeting 'memref'. This construct
81
+ /// should only be used for sibling fusion.
82
+ FusionStrategy(Value memref) : strategy(Sibling), memref(memref) {}
83
+
84
+ /// Returns the fusion strategy.
85
+ StrategyEnum getStrategy() const { return strategy; };
86
+
87
+ /// Returns the memref attached to this sibling fusion strategy.
88
+ Value getSiblingFusionMemRef() const {
89
+ assert(strategy == Sibling && "Memref is only valid for sibling fusion");
90
+ return memref;
91
+ }
92
+
93
+ private:
94
+ /// Fusion strategy.
95
+ StrategyEnum strategy;
96
+
97
+ /// Target memref for this fusion transformation. Only used for sibling
98
+ /// fusion.
99
+ Value memref;
100
+ };
101
+
102
+ /// Checks the feasibility of fusing the loop nest rooted at 'srcForOp' into the
103
+ /// loop nest rooted at 'dstForOp' at 'dstLoopDepth'. Returns FusionResult
104
+ /// 'Success' if fusion of the src/dst loop nests is feasible (i.e. they are
105
+ /// in the same block and dependences would not be violated). Otherwise
106
+ /// returns a FusionResult explaining why fusion is not feasible.
107
+ /// NOTE: This function is not feature complete and should only be used in
108
+ /// testing.
109
+ FusionResult
110
+ canFuseLoops(AffineForOp srcForOp, AffineForOp dstForOp, unsigned dstLoopDepth,
111
+ ComputationSliceState *srcSlice,
112
+ FusionStrategy fusionStrategy = FusionStrategy::Generic);
113
+
114
+ /// Fuses 'srcForOp' into 'dstForOp' with destination loop block insertion
115
+ /// point and source slice loop bounds specified in 'srcSlice'.
116
+ /// `isInnermostSiblingInsertionFusion` enables cleanup of `srcForOp that is a
117
+ /// single-iteration reduction loop being sibling-fused into a 'dstForOp'.
118
+ void fuseLoops(AffineForOp srcForOp, AffineForOp dstForOp,
119
+ const ComputationSliceState &srcSlice,
120
+ bool isInnermostSiblingInsertionFusion = false);
121
+
122
+ /// LoopNestStats aggregates various per-loop statistics (eg. loop trip count
123
+ /// and operation count) for a loop nest up until (and including) the innermost
124
+ /// loop body.
125
+ struct LoopNestStats {
126
+ /// Map from AffineForOp to immediate child AffineForOps in its loop body.
127
+ DenseMap<Operation *, SmallVector<AffineForOp, 2>> loopMap;
128
+ /// Map from AffineForOp to count of operations in its loop body.
129
+ DenseMap<Operation *, uint64_t> opCountMap;
130
+ /// Map from AffineForOp to its constant trip count.
131
+ DenseMap<Operation *, uint64_t> tripCountMap;
132
+ };
133
+
134
+ /// Collect loop nest statistics (eg. loop trip count and operation count)
135
+ /// in 'stats' for loop nest rooted at 'forOp'. Returns true on success,
136
+ /// returns false otherwise.
137
+ // TODO: Consider moving this to LoopUtils.
138
+ bool getLoopNestStats(AffineForOp forOp, LoopNestStats *stats);
139
+
140
+ /// Computes the total cost of the loop nest rooted at 'forOp' using 'stats'.
141
+ /// Currently, the total cost is computed by counting the total operation
142
+ /// instance count (i.e. total number of operations in the loop body * loop
143
+ /// trip count) for the entire loop nest.
144
+ int64_t getComputeCost(AffineForOp forOp, LoopNestStats &stats);
145
+
146
+ /// Computes and returns in 'computeCost', the total compute cost of fusing the
147
+ /// 'slice' of the loop nest rooted at 'srcForOp' into 'dstForOp'. Currently,
148
+ /// the total cost is computed by counting the total operation instance count
149
+ /// (i.e. total number of operations in the loop body * loop trip count) for
150
+ /// the entire loop nest.
151
+ /// Returns true on success, failure otherwise (e.g. non-constant trip counts).
152
+ bool getFusionComputeCost(AffineForOp srcForOp, LoopNestStats &srcStats,
153
+ AffineForOp dstForOp, LoopNestStats &dstStats,
154
+ const ComputationSliceState &slice,
155
+ int64_t *computeCost);
156
+
157
+ /// Returns in 'producerConsumerMemrefs' the memrefs involved in a
158
+ /// producer-consumer dependence between write ops in 'srcOps' and read ops in
159
+ /// 'dstOps'.
160
+ void gatherProducerConsumerMemrefs(ArrayRef<Operation *> srcOps,
161
+ ArrayRef<Operation *> dstOps,
162
+ DenseSet<Value> &producerConsumerMemrefs);
163
+
164
+ } // namespace affine
165
+ } // namespace mlir
166
+
167
+ #endif // MLIR_DIALECT_AFFINE_LOOPFUSIONUTILS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/LoopUtils.h ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- LoopUtils.h - Loop 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 loop transformation utility
10
+ // methods: 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_AFFINE_LOOPUTILS_H
16
+ #define MLIR_DIALECT_AFFINE_LOOPUTILS_H
17
+
18
+ #include "mlir/IR/Block.h"
19
+ #include "mlir/Support/LLVM.h"
20
+ #include "mlir/Transforms/RegionUtils.h"
21
+ #include <optional>
22
+
23
+ namespace mlir {
24
+ class AffineMap;
25
+ class LoopLikeOpInterface;
26
+ class OpBuilder;
27
+ class Value;
28
+ class ValueRange;
29
+
30
+ namespace func {
31
+ class FuncOp;
32
+ } // namespace func
33
+
34
+ namespace scf {
35
+ class ForOp;
36
+ class ParallelOp;
37
+ } // namespace scf
38
+
39
+ namespace affine {
40
+ class AffineForOp;
41
+ struct MemRefRegion;
42
+
43
+ /// Unrolls this for operation completely if the trip count is known to be
44
+ /// constant. Returns failure otherwise.
45
+ LogicalResult loopUnrollFull(AffineForOp forOp);
46
+
47
+ /// Unrolls this for operation by the specified unroll factor. Returns failure
48
+ /// if the loop cannot be unrolled either due to restrictions or due to invalid
49
+ /// unroll factors. Requires positive loop bounds and step. If specified,
50
+ /// annotates the Ops in each unrolled iteration by applying `annotateFn`.
51
+ /// When `cleanUpUnroll` is true, we can ensure the cleanup loop is unrolled
52
+ /// regardless of the unroll factor.
53
+ LogicalResult loopUnrollByFactor(
54
+ AffineForOp forOp, uint64_t unrollFactor,
55
+ function_ref<void(unsigned, Operation *, OpBuilder)> annotateFn = nullptr,
56
+ bool cleanUpUnroll = false);
57
+
58
+ /// Unrolls this loop by the specified unroll factor or its trip count,
59
+ /// whichever is lower.
60
+ LogicalResult loopUnrollUpToFactor(AffineForOp forOp, uint64_t unrollFactor);
61
+
62
+ /// Returns true if `loops` is a perfectly nested loop nest, where loops appear
63
+ /// in it from outermost to innermost.
64
+ bool LLVM_ATTRIBUTE_UNUSED isPerfectlyNested(ArrayRef<AffineForOp> loops);
65
+
66
+ /// Get perfectly nested sequence of loops starting at root of loop nest
67
+ /// (the first op being another AffineFor, and the second op - a terminator).
68
+ /// A loop is perfectly nested iff: the first op in the loop's body is another
69
+ /// AffineForOp, and the second op is a terminator).
70
+ void getPerfectlyNestedLoops(SmallVectorImpl<AffineForOp> &nestedLoops,
71
+ AffineForOp root);
72
+
73
+ /// Unrolls and jams this loop by the specified factor. `forOp` can be a loop
74
+ /// with iteration arguments performing supported reductions and its inner loops
75
+ /// can have iteration arguments. Returns success if the loop is successfully
76
+ /// unroll-jammed.
77
+ LogicalResult loopUnrollJamByFactor(AffineForOp forOp,
78
+ uint64_t unrollJamFactor);
79
+
80
+ /// Unrolls and jams this loop by the specified factor or by the trip count (if
81
+ /// constant), whichever is lower.
82
+ LogicalResult loopUnrollJamUpToFactor(AffineForOp forOp,
83
+ uint64_t unrollJamFactor);
84
+
85
+ /// Promotes the loop body of a AffineForOp to its containing block if the loop
86
+ /// was known to have a single iteration.
87
+ LogicalResult promoteIfSingleIteration(AffineForOp forOp);
88
+
89
+ /// Promotes all single iteration AffineForOp's in the Function, i.e., moves
90
+ /// their body into the containing Block.
91
+ void promoteSingleIterationLoops(func::FuncOp f);
92
+
93
+ /// Skew the operations in an affine.for's body with the specified
94
+ /// operation-wise shifts. The shifts are with respect to the original execution
95
+ /// order, and are multiplied by the loop 'step' before being applied. If
96
+ /// `unrollPrologueEpilogue` is set, fully unroll the prologue and epilogue
97
+ /// loops when possible.
98
+ LogicalResult affineForOpBodySkew(AffineForOp forOp, ArrayRef<uint64_t> shifts,
99
+ bool unrollPrologueEpilogue = false);
100
+
101
+ /// Identify valid and profitable bands of loops to tile. This is currently just
102
+ /// a temporary placeholder to test the mechanics of tiled code generation.
103
+ /// Returns all maximal outermost perfect loop nests to tile.
104
+ void getTileableBands(func::FuncOp f,
105
+ std::vector<SmallVector<AffineForOp, 6>> *bands);
106
+
107
+ /// Tiles the specified band of perfectly nested loops creating tile-space loops
108
+ /// and intra-tile loops. A band is a contiguous set of loops. This utility
109
+ /// doesn't check for the validity of tiling itself, but just performs it.
110
+ LogicalResult
111
+ tilePerfectlyNested(MutableArrayRef<AffineForOp> input,
112
+ ArrayRef<unsigned> tileSizes,
113
+ SmallVectorImpl<AffineForOp> *tiledNest = nullptr);
114
+
115
+ /// Tiles the specified band of perfectly nested loops creating tile-space
116
+ /// loops and intra-tile loops, using SSA values as tiling parameters. A band
117
+ /// is a contiguous set of loops.
118
+ LogicalResult tilePerfectlyNestedParametric(
119
+ MutableArrayRef<AffineForOp> input, ArrayRef<Value> tileSizes,
120
+ SmallVectorImpl<AffineForOp> *tiledNest = nullptr);
121
+
122
+ /// Performs loop interchange on 'forOpA' and 'forOpB'. Requires that 'forOpA'
123
+ /// and 'forOpB' are part of a perfectly nested sequence of loops.
124
+ void interchangeLoops(AffineForOp forOpA, AffineForOp forOpB);
125
+
126
+ /// Checks if the loop interchange permutation 'loopPermMap', of the perfectly
127
+ /// nested sequence of loops in 'loops', would violate dependences (loop 'i' in
128
+ /// 'loops' is mapped to location 'j = 'loopPermMap[i]' in the interchange).
129
+ bool isValidLoopInterchangePermutation(ArrayRef<AffineForOp> loops,
130
+ ArrayRef<unsigned> loopPermMap);
131
+
132
+ /// Performs a loop permutation on a perfectly nested loop nest `inputNest`
133
+ /// (where the contained loops appear from outer to inner) as specified by the
134
+ /// permutation `permMap`: loop 'i' in `inputNest` is mapped to location
135
+ /// 'loopPermMap[i]', where positions 0, 1, ... are from the outermost position
136
+ /// to inner. Returns the position in `inputNest` of the AffineForOp that
137
+ /// becomes the new outermost loop of this nest. This method always succeeds,
138
+ /// asserts out on invalid input / specifications.
139
+ unsigned permuteLoops(ArrayRef<AffineForOp> inputNest,
140
+ ArrayRef<unsigned> permMap);
141
+
142
+ // Sinks all sequential loops to the innermost levels (while preserving
143
+ // relative order among them) and moves all parallel loops to the
144
+ // outermost (while again preserving relative order among them).
145
+ // Returns AffineForOp of the root of the new loop nest after loop interchanges.
146
+ AffineForOp sinkSequentialLoops(AffineForOp forOp);
147
+
148
+ /// Performs tiling fo imperfectly nested loops (with interchange) by
149
+ /// strip-mining the `forOps` by `sizes` and sinking them, in their order of
150
+ /// occurrence in `forOps`, under each of the `targets`.
151
+ /// Returns the new AffineForOps, one per each of (`forOps`, `targets`) pair,
152
+ /// nested immediately under each of `targets`.
153
+ SmallVector<SmallVector<AffineForOp, 8>, 8> tile(ArrayRef<AffineForOp> forOps,
154
+ ArrayRef<uint64_t> sizes,
155
+ ArrayRef<AffineForOp> targets);
156
+
157
+ /// Performs tiling (with interchange) by strip-mining the `forOps` by `sizes`
158
+ /// and sinking them, in their order of occurrence in `forOps`, under `target`.
159
+ /// Returns the new AffineForOps, one per `forOps`, nested immediately under
160
+ /// `target`.
161
+ SmallVector<AffineForOp, 8> tile(ArrayRef<AffineForOp> forOps,
162
+ ArrayRef<uint64_t> sizes, AffineForOp target);
163
+
164
+ /// Explicit copy / DMA generation options for mlir::affineDataCopyGenerate.
165
+ struct AffineCopyOptions {
166
+ // True if DMAs should be generated instead of point-wise copies.
167
+ bool generateDma;
168
+ // The slower memory space from which data is to be moved.
169
+ unsigned slowMemorySpace;
170
+ // Memory space of the faster one (typically a scratchpad).
171
+ unsigned fastMemorySpace;
172
+ // Memory space to place tags in: only meaningful for DMAs.
173
+ unsigned tagMemorySpace;
174
+ // Capacity of the fast memory space in bytes.
175
+ uint64_t fastMemCapacityBytes;
176
+ };
177
+
178
+ /// Performs explicit copying for the contiguous sequence of operations in the
179
+ /// block iterator range [`begin', `end'), where `end' can't be past the
180
+ /// terminator of the block (since additional operations are potentially
181
+ /// inserted right before `end`. `copyOptions` provides various parameters, and
182
+ /// the output argument `copyNests` is the set of all copy nests inserted, each
183
+ /// represented by its root affine.for. Since we generate alloc's and dealloc's
184
+ /// for all fast buffers (before and after the range of operations resp. or at a
185
+ /// hoisted position), all of the fast memory capacity is assumed to be
186
+ /// available for processing this block range. When 'filterMemRef' is specified,
187
+ /// copies are only generated for the provided MemRef. Returns success if the
188
+ /// explicit copying succeeded for all memrefs on which affine load/stores were
189
+ /// encountered. For memrefs for whose element types a size in bytes can't be
190
+ /// computed (`index` type), their capacity is not accounted for and the
191
+ /// `fastMemCapacityBytes` copy option would be non-functional in such cases.
192
+ LogicalResult affineDataCopyGenerate(Block::iterator begin, Block::iterator end,
193
+ const AffineCopyOptions &copyOptions,
194
+ std::optional<Value> filterMemRef,
195
+ DenseSet<Operation *> &copyNests);
196
+
197
+ /// A convenience version of affineDataCopyGenerate for all ops in the body of
198
+ /// an AffineForOp.
199
+ LogicalResult affineDataCopyGenerate(AffineForOp forOp,
200
+ const AffineCopyOptions &copyOptions,
201
+ std::optional<Value> filterMemRef,
202
+ DenseSet<Operation *> &copyNests);
203
+
204
+ /// Result for calling generateCopyForMemRegion.
205
+ struct CopyGenerateResult {
206
+ // Number of bytes used by alloc.
207
+ uint64_t sizeInBytes;
208
+
209
+ // The newly created buffer allocation.
210
+ Operation *alloc;
211
+
212
+ // Generated loop nest for copying data between the allocated buffer and the
213
+ // original memref.
214
+ Operation *copyNest;
215
+ };
216
+
217
+ /// generateCopyForMemRegion is similar to affineDataCopyGenerate, but works
218
+ /// with a single memref region. `memrefRegion` is supposed to contain analysis
219
+ /// information within analyzedOp. The generated prologue and epilogue always
220
+ /// surround `analyzedOp`.
221
+ ///
222
+ /// Note that `analyzedOp` is a single op for API convenience, and the
223
+ /// [begin, end) version can be added as needed.
224
+ ///
225
+ /// Also note that certain options in `copyOptions` aren't looked at anymore,
226
+ /// like slowMemorySpace.
227
+ LogicalResult generateCopyForMemRegion(const MemRefRegion &memrefRegion,
228
+ Operation *analyzedOp,
229
+ const AffineCopyOptions &copyOptions,
230
+ CopyGenerateResult &result);
231
+
232
+ /// Replace a perfect nest of "for" loops with a single linearized loop. Assumes
233
+ /// `loops` contains a list of perfectly nested loops outermost to innermost
234
+ /// that are normalized (step one and lower bound of zero) and with bounds and
235
+ /// steps independent of any loop induction variable involved in the nest.
236
+ /// Coalescing affine.for loops is not always possible, i.e., the result may not
237
+ /// be representable using affine.for.
238
+ LogicalResult coalesceLoops(MutableArrayRef<AffineForOp> loops);
239
+
240
+ /// Maps `forOp` for execution on a parallel grid of virtual `processorIds` of
241
+ /// size given by `numProcessors`. This is achieved by embedding the SSA values
242
+ /// corresponding to `processorIds` and `numProcessors` into the bounds and step
243
+ /// of the `forOp`. No check is performed on the legality of the rewrite, it is
244
+ /// the caller's responsibility to ensure legality.
245
+ ///
246
+ /// Requires that `processorIds` and `numProcessors` have the same size and that
247
+ /// for each idx, `processorIds`[idx] takes, at runtime, all values between 0
248
+ /// and `numProcessors`[idx] - 1. This corresponds to traditional use cases for:
249
+ /// 1. GPU (threadIdx, get_local_id(), ...)
250
+ /// 2. MPI (MPI_Comm_rank)
251
+ /// 3. OpenMP (omp_get_thread_num)
252
+ ///
253
+ /// Example:
254
+ /// Assuming a 2-d grid with processorIds = [blockIdx.x, threadIdx.x] and
255
+ /// numProcessors = [gridDim.x, blockDim.x], the loop:
256
+ ///
257
+ /// ```
258
+ /// scf.for %i = %lb to %ub step %step {
259
+ /// ...
260
+ /// }
261
+ /// ```
262
+ ///
263
+ /// is rewritten into a version resembling the following pseudo-IR:
264
+ ///
265
+ /// ```
266
+ /// scf.for %i = %lb + %step * (threadIdx.x + blockIdx.x * blockDim.x)
267
+ /// to %ub step %gridDim.x * blockDim.x * %step {
268
+ /// ...
269
+ /// }
270
+ /// ```
271
+ void mapLoopToProcessorIds(scf::ForOp forOp, ArrayRef<Value> processorId,
272
+ ArrayRef<Value> numProcessors);
273
+
274
+ /// Gathers all AffineForOps in 'func.func' grouped by loop depth.
275
+ void gatherLoops(func::FuncOp func,
276
+ std::vector<SmallVector<AffineForOp, 2>> &depthToLoops);
277
+
278
+ /// Creates an AffineForOp while ensuring that the lower and upper bounds are
279
+ /// canonicalized, i.e., unused and duplicate operands are removed, any constant
280
+ /// operands propagated/folded in, and duplicate bound maps dropped.
281
+ AffineForOp createCanonicalizedAffineForOp(OpBuilder b, Location loc,
282
+ ValueRange lbOperands,
283
+ AffineMap lbMap,
284
+ ValueRange ubOperands,
285
+ AffineMap ubMap, int64_t step = 1);
286
+
287
+ /// Separates full tiles from partial tiles for a perfect nest `nest` by
288
+ /// generating a conditional guard that selects between the full tile version
289
+ /// and the partial tile version using an AffineIfOp. The original loop nest
290
+ /// is replaced by this guarded two version form.
291
+ ///
292
+ /// affine.if (cond)
293
+ /// // full_tile
294
+ /// else
295
+ /// // partial tile
296
+ ///
297
+ LogicalResult
298
+ separateFullTiles(MutableArrayRef<AffineForOp> nest,
299
+ SmallVectorImpl<AffineForOp> *fullTileNest = nullptr);
300
+
301
+ /// Walk an affine.for to find a band to coalesce.
302
+ LogicalResult coalescePerfectlyNestedAffineLoops(AffineForOp op);
303
+
304
+ /// Count the number of loops surrounding `operand` such that operand could be
305
+ /// hoisted above.
306
+ /// Stop counting at the first loop over which the operand cannot be hoisted.
307
+ /// This counts any LoopLikeOpInterface, not just affine.for.
308
+ int64_t numEnclosingInvariantLoops(OpOperand &operand);
309
+ } // namespace affine
310
+ } // namespace mlir
311
+
312
+ #endif // MLIR_DIALECT_AFFINE_LOOPUTILS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Passes.h ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- Passes.h - Pass Entrypoints ------------------------------*- 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 a set of transforms specific for the AffineOps
10
+ // dialect.
11
+ //
12
+ //===----------------------------------------------------------------------===//
13
+
14
+ #ifndef MLIR_DIALECT_AFFINE_PASSES_H
15
+ #define MLIR_DIALECT_AFFINE_PASSES_H
16
+
17
+ #include "mlir/Interfaces/FunctionInterfaces.h"
18
+ #include "mlir/Pass/Pass.h"
19
+ #include <limits>
20
+
21
+ namespace mlir {
22
+
23
+ namespace func {
24
+ class FuncOp;
25
+ } // namespace func
26
+ namespace memref {
27
+ class MemRefDialect;
28
+ } // namespace memref
29
+
30
+ namespace affine {
31
+ class AffineForOp;
32
+
33
+ /// Fusion mode to attempt. The default mode `Greedy` does both
34
+ /// producer-consumer and sibling fusion.
35
+ enum FusionMode { Greedy, ProducerConsumer, Sibling };
36
+
37
+ #define GEN_PASS_DECL
38
+ #include "mlir/Dialect/Affine/Passes.h.inc"
39
+
40
+ /// Creates a simplification pass for affine structures (maps and sets). In
41
+ /// addition, this pass also normalizes memrefs to have the trivial (identity)
42
+ /// layout map.
43
+ std::unique_ptr<OperationPass<func::FuncOp>>
44
+ createSimplifyAffineStructuresPass();
45
+
46
+ /// Creates a loop invariant code motion pass that hoists loop invariant
47
+ /// operations out of affine loops.
48
+ std::unique_ptr<OperationPass<func::FuncOp>>
49
+ createAffineLoopInvariantCodeMotionPass();
50
+
51
+ /// Creates a pass to convert all parallel affine.for's into 1-d affine.parallel
52
+ /// ops.
53
+ std::unique_ptr<OperationPass<func::FuncOp>> createAffineParallelizePass();
54
+
55
+ /// Creates a pass that converts some memref operators to affine operators.
56
+ std::unique_ptr<OperationPass<func::FuncOp>> createRaiseMemrefToAffine();
57
+
58
+ /// Apply normalization transformations to affine loop-like ops. If
59
+ /// `promoteSingleIter` is true, single iteration loops are promoted (i.e., the
60
+ /// loop is replaced by its loop body).
61
+ std::unique_ptr<OperationPass<func::FuncOp>>
62
+ createAffineLoopNormalizePass(bool promoteSingleIter = false);
63
+
64
+ /// Performs packing (or explicit copying) of accessed memref regions into
65
+ /// buffers in the specified faster memory space through either pointwise copies
66
+ /// or DMA operations.
67
+ std::unique_ptr<OperationPass<func::FuncOp>> createAffineDataCopyGenerationPass(
68
+ unsigned slowMemorySpace, unsigned fastMemorySpace,
69
+ unsigned tagMemorySpace = 0, int minDmaTransferSize = 1024,
70
+ uint64_t fastMemCapacityBytes = std::numeric_limits<uint64_t>::max());
71
+ /// Overload relying on pass options for initialization.
72
+ std::unique_ptr<OperationPass<func::FuncOp>>
73
+ createAffineDataCopyGenerationPass();
74
+
75
+ /// Creates a pass to replace affine memref accesses by scalars using store to
76
+ /// load forwarding and redundant load elimination; consequently also eliminate
77
+ /// dead allocs.
78
+ std::unique_ptr<OperationPass<func::FuncOp>>
79
+ createAffineScalarReplacementPass();
80
+
81
+ /// Creates a pass that transforms perfectly nested loops with independent
82
+ /// bounds into a single loop.
83
+ std::unique_ptr<OperationPass<func::FuncOp>> createLoopCoalescingPass();
84
+
85
+ /// Creates a loop fusion pass which fuses affine loop nests at the top-level of
86
+ /// the operation the pass is created on according to the type of fusion
87
+ /// specified in `fusionMode`. Buffers of size less than or equal to
88
+ /// `localBufSizeThreshold` are promoted to memory space `fastMemorySpace`.
89
+ std::unique_ptr<Pass>
90
+ createLoopFusionPass(unsigned fastMemorySpace = 0,
91
+ uint64_t localBufSizeThreshold = 0,
92
+ bool maximalFusion = false,
93
+ enum FusionMode fusionMode = FusionMode::Greedy);
94
+
95
+ /// Creates a pass to perform tiling on loop nests.
96
+ std::unique_ptr<OperationPass<func::FuncOp>>
97
+ createLoopTilingPass(uint64_t cacheSizeBytes);
98
+ /// Overload relying on pass options for initialization.
99
+ std::unique_ptr<OperationPass<func::FuncOp>> createLoopTilingPass();
100
+
101
+ /// Creates a loop unrolling pass with the provided parameters.
102
+ /// 'getUnrollFactor' is a function callback for clients to supply a function
103
+ /// that computes an unroll factor - the callback takes precedence over unroll
104
+ /// factors supplied through other means. If -1 is passed as the unrollFactor
105
+ /// and no callback is provided, anything passed from the command-line (if at
106
+ /// all) or the default unroll factor is used (LoopUnroll:kDefaultUnrollFactor).
107
+ std::unique_ptr<InterfacePass<FunctionOpInterface>> createLoopUnrollPass(
108
+ int unrollFactor = -1, bool unrollUpToFactor = false,
109
+ bool unrollFull = false,
110
+ const std::function<unsigned(AffineForOp)> &getUnrollFactor = nullptr);
111
+
112
+ /// Creates a loop unroll jam pass to unroll jam by the specified factor. A
113
+ /// factor of -1 lets the pass use the default factor or the one on the command
114
+ /// line if provided.
115
+ std::unique_ptr<InterfacePass<FunctionOpInterface>>
116
+ createLoopUnrollAndJamPass(int unrollJamFactor = -1);
117
+
118
+ /// Creates a pass to pipeline explicit movement of data across levels of the
119
+ /// memory hierarchy.
120
+ std::unique_ptr<OperationPass<func::FuncOp>> createPipelineDataTransferPass();
121
+
122
+ /// Creates a pass to expand affine index operations into more fundamental
123
+ /// operations (not necessarily restricted to Affine dialect).
124
+ std::unique_ptr<Pass> createAffineExpandIndexOpsPass();
125
+
126
+ /// Creates a pass to expand affine index operations into affine.apply
127
+ /// operations.
128
+ std::unique_ptr<Pass> createAffineExpandIndexOpsAsAffinePass();
129
+
130
+ //===----------------------------------------------------------------------===//
131
+ // Registration
132
+ //===----------------------------------------------------------------------===//
133
+
134
+ /// Generate the code for registering passes.
135
+ #define GEN_PASS_REGISTRATION
136
+ #include "mlir/Dialect/Affine/Passes.h.inc"
137
+
138
+ } // namespace affine
139
+ } // namespace mlir
140
+
141
+ #endif // MLIR_DIALECT_AFFINE_PASSES_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Passes.h.inc ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Transforms/Transforms.h ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- Transforms.h - Transforms Entrypoints --------------------*- 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 a set of transforms specific for the AffineOps
10
+ // dialect.
11
+ //
12
+ //===----------------------------------------------------------------------===//
13
+
14
+ #ifndef MLIR_DIALECT_AFFINE_TRANSFORMS_TRANSFORMS_H
15
+ #define MLIR_DIALECT_AFFINE_TRANSFORMS_TRANSFORMS_H
16
+
17
+ #include "mlir/Interfaces/ValueBoundsOpInterface.h"
18
+ #include "mlir/Support/LLVM.h"
19
+
20
+ namespace mlir {
21
+ class AffineMap;
22
+ class Location;
23
+ class OpBuilder;
24
+ class OpFoldResult;
25
+ class RewritePatternSet;
26
+ class RewriterBase;
27
+ class Value;
28
+
29
+ namespace presburger {
30
+ enum class BoundType;
31
+ } // namespace presburger
32
+
33
+ namespace affine {
34
+ class AffineApplyOp;
35
+
36
+ /// Populate patterns that expand affine index operations into more fundamental
37
+ /// operations (not necessarily restricted to Affine dialect).
38
+ void populateAffineExpandIndexOpsPatterns(RewritePatternSet &patterns);
39
+
40
+ /// Populate patterns that expand affine index operations into their equivalent
41
+ /// `affine.apply` representations.
42
+ void populateAffineExpandIndexOpsAsAffinePatterns(RewritePatternSet &patterns);
43
+
44
+ /// Helper function to rewrite `op`'s affine map and reorder its operands such
45
+ /// that they are in increasing order of hoistability (i.e. the least hoistable)
46
+ /// operands come first in the operand list.
47
+ void reorderOperandsByHoistability(RewriterBase &rewriter, AffineApplyOp op);
48
+
49
+ /// Split an "affine.apply" operation into smaller ops.
50
+ /// This reassociates a large AffineApplyOp into an ordered list of smaller
51
+ /// AffineApplyOps. This can be used right before lowering affine ops to arith
52
+ /// to exhibit more opportunities for CSE and LICM.
53
+ /// Return the sink AffineApplyOp on success or failure if `op` does not
54
+ /// decompose into smaller AffineApplyOps.
55
+ /// Note that this can be undone by canonicalization which tries to
56
+ /// maximally compose chains of AffineApplyOps.
57
+ FailureOr<AffineApplyOp> decompose(RewriterBase &rewriter, AffineApplyOp op);
58
+
59
+ /// Reify a bound for the given variable in terms of SSA values for which
60
+ /// `stopCondition` is met.
61
+ ///
62
+ /// By default, lower/equal bounds are closed and upper bounds are open. If
63
+ /// `closedUB` is set to "true", upper bounds are also closed.
64
+ FailureOr<OpFoldResult>
65
+ reifyValueBound(OpBuilder &b, Location loc, presburger::BoundType type,
66
+ const ValueBoundsConstraintSet::Variable &var,
67
+ ValueBoundsConstraintSet::StopConditionFn stopCondition,
68
+ bool closedUB = false);
69
+
70
+ /// Reify a bound for the given index-typed value in terms of SSA values for
71
+ /// which `stopCondition` is met. If no stop condition is specified, reify in
72
+ /// terms of the operands of the owner op.
73
+ ///
74
+ /// By default, lower/equal bounds are closed and upper bounds are open. If
75
+ /// `closedUB` is set to "true", upper bounds are also closed.
76
+ ///
77
+ /// Example:
78
+ /// %0 = arith.addi %a, %b : index
79
+ /// %1 = arith.addi %0, %c : index
80
+ ///
81
+ /// * If `stopCondition` evaluates to "true" for %0 and %c, "%0 + %c" is an EQ
82
+ /// bound for %1.
83
+ /// * If `stopCondition` evaluates to "true" for %a, %b and %c, "%a + %b + %c"
84
+ /// is an EQ bound for %1.
85
+ /// * Otherwise, if the owners of %a, %b or %c do not implement the
86
+ /// ValueBoundsOpInterface, no bound can be computed.
87
+ FailureOr<OpFoldResult> reifyIndexValueBound(
88
+ OpBuilder &b, Location loc, presburger::BoundType type, Value value,
89
+ ValueBoundsConstraintSet::StopConditionFn stopCondition = nullptr,
90
+ bool closedUB = false);
91
+
92
+ /// Reify a bound for the specified dimension of the given shaped value in terms
93
+ /// of SSA values for which `stopCondition` is met. If no stop condition is
94
+ /// specified, reify in terms of the operands of the owner op.
95
+ ///
96
+ /// By default, lower/equal bounds are closed and upper bounds are open. If
97
+ /// `closedUB` is set to "true", upper bounds are also closed.
98
+ FailureOr<OpFoldResult> reifyShapedValueDimBound(
99
+ OpBuilder &b, Location loc, presburger::BoundType type, Value value,
100
+ int64_t dim,
101
+ ValueBoundsConstraintSet::StopConditionFn stopCondition = nullptr,
102
+ bool closedUB = false);
103
+
104
+ /// Materialize an already computed bound with Affine dialect ops.
105
+ ///
106
+ /// * `ValueBoundsOpInterface::computeBound` computes bounds but does not
107
+ /// create IR. It is dialect independent.
108
+ /// * `materializeComputedBound` materializes computed bounds with Affine
109
+ /// dialect ops.
110
+ /// * `reifyIndexValueBound`/`reifyShapedValueDimBound` are a combination of
111
+ /// the two functions mentioned above.
112
+ OpFoldResult materializeComputedBound(
113
+ OpBuilder &b, Location loc, AffineMap boundMap,
114
+ ArrayRef<std::pair<Value, std::optional<int64_t>>> mapOperands);
115
+
116
+ } // namespace affine
117
+ } // namespace mlir
118
+
119
+ #endif // MLIR_DIALECT_AFFINE_TRANSFORMS_TRANSFORMS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/Utils.h ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- Utils.h - Affine dialect 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 declares a set of utilities for the affine dialect ops.
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #ifndef MLIR_DIALECT_AFFINE_UTILS_H
14
+ #define MLIR_DIALECT_AFFINE_UTILS_H
15
+
16
+ #include "mlir/Analysis/AliasAnalysis.h"
17
+ #include "mlir/Dialect/Affine/Analysis/AffineAnalysis.h"
18
+ #include "mlir/Dialect/Affine/IR/AffineOps.h"
19
+ #include "mlir/IR/OpDefinition.h"
20
+ #include <optional>
21
+
22
+ namespace mlir {
23
+ class DominanceInfo;
24
+ class Operation;
25
+ class PostDominanceInfo;
26
+ class ImplicitLocOpBuilder;
27
+
28
+ namespace func {
29
+ class FuncOp;
30
+ } // namespace func
31
+
32
+ namespace memref {
33
+ class AllocOp;
34
+ class AllocaOp;
35
+ class ReinterpretCastOp;
36
+ } // namespace memref
37
+
38
+ namespace affine {
39
+ class AffineForOp;
40
+ class AffineIfOp;
41
+ class AffineParallelOp;
42
+
43
+ using ReductionLoopMap = DenseMap<Operation *, SmallVector<LoopReduction, 2>>;
44
+
45
+ /// Replaces a parallel affine.for op with a 1-d affine.parallel op. `forOp`'s
46
+ /// body is taken by the affine.parallel op and the former is erased.
47
+ /// (mlir::isLoopParallel can be used to detect a parallel affine.for op.) The
48
+ /// reductions specified in `parallelReductions` are also parallelized.
49
+ /// Parallelization will fail in the presence of loop iteration arguments that
50
+ /// are not listed in `parallelReductions`. `resOp` if non-null is set to the
51
+ /// newly created affine.parallel op.
52
+ LogicalResult affineParallelize(AffineForOp forOp,
53
+ ArrayRef<LoopReduction> parallelReductions = {},
54
+ AffineParallelOp *resOp = nullptr);
55
+
56
+ /// Hoists out affine.if/else to as high as possible, i.e., past all invariant
57
+ /// affine.fors/parallel's. Returns success if any hoisting happened; folded` is
58
+ /// set to true if the op was folded or erased. This hoisting could lead to
59
+ /// significant code expansion in some cases.
60
+ LogicalResult hoistAffineIfOp(AffineIfOp ifOp, bool *folded = nullptr);
61
+
62
+ /// Holds parameters to perform n-D vectorization on a single loop nest.
63
+ /// For example, for the following loop nest:
64
+ ///
65
+ /// func @vec2d(%in: memref<64x128x512xf32>, %out: memref<64x128x512xf32>) {
66
+ /// affine.for %i0 = 0 to 64 {
67
+ /// affine.for %i1 = 0 to 128 {
68
+ /// affine.for %i2 = 0 to 512 {
69
+ /// %ld = affine.load %in[%i0, %i1, %i2] : memref<64x128x512xf32>
70
+ /// affine.store %ld, %out[%i0, %i1, %i2] : memref<64x128x512xf32>
71
+ /// }
72
+ /// }
73
+ /// }
74
+ /// return
75
+ /// }
76
+ ///
77
+ /// and VectorizationStrategy = 'vectorSizes = {8, 4}', 'loopToVectorDim =
78
+ /// {{i1->0}, {i2->1}}', SuperVectorizer will generate:
79
+ ///
80
+ /// func @vec2d(%arg0: memref<64x128x512xf32>, %arg1: memref<64x128x512xf32>) {
81
+ /// affine.for %arg2 = 0 to 64 {
82
+ /// affine.for %arg3 = 0 to 128 step 8 {
83
+ /// affine.for %arg4 = 0 to 512 step 4 {
84
+ /// %cst = arith.constant 0.000000e+00 : f32
85
+ /// %0 = vector.transfer_read %arg0[%arg2, %arg3, %arg4], %cst : ...
86
+ /// vector.transfer_write %0, %arg1[%arg2, %arg3, %arg4] : ...
87
+ /// }
88
+ /// }
89
+ /// }
90
+ /// return
91
+ /// }
92
+ // TODO: Hoist to a VectorizationStrategy.cpp when appropriate.
93
+ struct VectorizationStrategy {
94
+ // Vectorization factors to apply to each target vector dimension.
95
+ // Each factor will be applied to a different loop.
96
+ SmallVector<int64_t, 8> vectorSizes;
97
+ // Maps each AffineForOp vectorization candidate with its vector dimension.
98
+ // The candidate will be vectorized using the vectorization factor in
99
+ // 'vectorSizes' for that dimension.
100
+ DenseMap<Operation *, unsigned> loopToVectorDim;
101
+ // Maps loops that implement vectorizable reductions to the corresponding
102
+ // reduction descriptors.
103
+ ReductionLoopMap reductionLoops;
104
+ };
105
+
106
+ /// Replace affine store and load accesses by scalars by forwarding stores to
107
+ /// loads and eliminate invariant affine loads; consequently, eliminate dead
108
+ /// allocs.
109
+ void affineScalarReplace(func::FuncOp f, DominanceInfo &domInfo,
110
+ PostDominanceInfo &postDomInfo,
111
+ AliasAnalysis &analysis);
112
+
113
+ /// Vectorizes affine loops in 'loops' using the n-D vectorization factors in
114
+ /// 'vectorSizes'. By default, each vectorization factor is applied
115
+ /// inner-to-outer to the loops of each loop nest. 'fastestVaryingPattern' can
116
+ /// be optionally used to provide a different loop vectorization order.
117
+ /// If `reductionLoops` is not empty, the given reduction loops may be
118
+ /// vectorized along the reduction dimension.
119
+ /// TODO: Vectorizing reductions is supported only for 1-D vectorization.
120
+ void vectorizeAffineLoops(
121
+ Operation *parentOp,
122
+ llvm::DenseSet<Operation *, DenseMapInfo<Operation *>> &loops,
123
+ ArrayRef<int64_t> vectorSizes, ArrayRef<int64_t> fastestVaryingPattern,
124
+ const ReductionLoopMap &reductionLoops = ReductionLoopMap());
125
+
126
+ /// External utility to vectorize affine loops from a single loop nest using an
127
+ /// n-D vectorization strategy (see doc in VectorizationStrategy definition).
128
+ /// Loops are provided in a 2D vector container. The first dimension represents
129
+ /// the nesting level relative to the loops to be vectorized. The second
130
+ /// dimension contains the loops. This means that:
131
+ /// a) every loop in 'loops[i]' must have a parent loop in 'loops[i-1]',
132
+ /// b) a loop in 'loops[i]' may or may not have a child loop in 'loops[i+1]'.
133
+ ///
134
+ /// For example, for the following loop nest:
135
+ ///
136
+ /// func @vec2d(%in0: memref<64x128x512xf32>, %in1: memref<64x128x128xf32>,
137
+ /// %out0: memref<64x128x512xf32>,
138
+ /// %out1: memref<64x128x128xf32>) {
139
+ /// affine.for %i0 = 0 to 64 {
140
+ /// affine.for %i1 = 0 to 128 {
141
+ /// affine.for %i2 = 0 to 512 {
142
+ /// %ld = affine.load %in0[%i0, %i1, %i2] : memref<64x128x512xf32>
143
+ /// affine.store %ld, %out0[%i0, %i1, %i2] : memref<64x128x512xf32>
144
+ /// }
145
+ /// affine.for %i3 = 0 to 128 {
146
+ /// %ld = affine.load %in1[%i0, %i1, %i3] : memref<64x128x128xf32>
147
+ /// affine.store %ld, %out1[%i0, %i1, %i3] : memref<64x128x128xf32>
148
+ /// }
149
+ /// }
150
+ /// }
151
+ /// return
152
+ /// }
153
+ ///
154
+ /// loops = {{%i0}, {%i2, %i3}}, to vectorize the outermost and the two
155
+ /// innermost loops;
156
+ /// loops = {{%i1}, {%i2, %i3}}, to vectorize the middle and the two innermost
157
+ /// loops;
158
+ /// loops = {{%i2}}, to vectorize only the first innermost loop;
159
+ /// loops = {{%i3}}, to vectorize only the second innermost loop;
160
+ /// loops = {{%i1}}, to vectorize only the middle loop.
161
+ LogicalResult
162
+ vectorizeAffineLoopNest(std::vector<SmallVector<AffineForOp, 2>> &loops,
163
+ const VectorizationStrategy &strategy);
164
+
165
+ /// Normalize a affine.parallel op so that lower bounds are 0 and steps are 1.
166
+ /// As currently implemented, this transformation cannot fail and will return
167
+ /// early if the op is already in a normalized form.
168
+ void normalizeAffineParallel(AffineParallelOp op);
169
+
170
+ /// Normalize an affine.for op. An affine.for op is normalized by converting the
171
+ /// lower bound to zero and loop step to one. The upper bound is set to the trip
172
+ /// count of the loop. Original loops must have a lower bound with only a single
173
+ /// result. There is no such restriction on upper bounds. Returns success if the
174
+ /// loop has been normalized (or is already in the normal form). If
175
+ /// `promoteSingleIter` is true, the loop is simply promoted if it has a single
176
+ /// iteration.
177
+ LogicalResult normalizeAffineFor(AffineForOp op,
178
+ bool promoteSingleIter = false);
179
+
180
+ /// Traverse `e` and return an AffineExpr where all occurrences of `dim` have
181
+ /// been replaced by either:
182
+ /// - `min` if `positivePath` is true when we reach an occurrence of `dim`
183
+ /// - `max` if `positivePath` is true when we reach an occurrence of `dim`
184
+ /// `positivePath` is negated each time we hit a multiplicative or divisive
185
+ /// binary op with a constant negative coefficient.
186
+ AffineExpr substWithMin(AffineExpr e, AffineExpr dim, AffineExpr min,
187
+ AffineExpr max, bool positivePath = true);
188
+
189
+ /// Replaces all "dereferencing" uses of `oldMemRef` with `newMemRef` while
190
+ /// optionally remapping the old memref's indices using the supplied affine map,
191
+ /// `indexRemap`. The new memref could be of a different shape or rank.
192
+ /// `extraIndices` provides any additional access indices to be added to the
193
+ /// start.
194
+ ///
195
+ /// `indexRemap` remaps indices of the old memref access to a new set of indices
196
+ /// that are used to index the memref. Additional input operands to indexRemap
197
+ /// can be optionally provided in `extraOperands`, and they occupy the start
198
+ /// of its input list. `indexRemap`'s dimensional inputs are expected to
199
+ /// correspond to memref's indices, and its symbolic inputs if any should be
200
+ /// provided in `symbolOperands`.
201
+ ///
202
+ /// `domOpFilter`, if non-null, restricts the replacement to only those
203
+ /// operations that are dominated by the former; similarly, `postDomOpFilter`
204
+ /// restricts replacement to only those operations that are postdominated by it.
205
+ ///
206
+ /// 'allowNonDereferencingOps', if set, allows replacement of non-dereferencing
207
+ /// uses of a memref without any requirement for access index rewrites as long
208
+ /// as the user operation has the MemRefsNormalizable trait. The default value
209
+ /// of this flag is false.
210
+ ///
211
+ /// 'replaceInDeallocOp', if set, lets DeallocOp, a non-dereferencing user, to
212
+ /// also be a candidate for replacement. The default value of this flag is
213
+ /// false.
214
+ ///
215
+ /// Returns true on success and false if the replacement is not possible,
216
+ /// whenever a memref is used as an operand in a non-dereferencing context and
217
+ /// 'allowNonDereferencingOps' is false, except for dealloc's on the memref
218
+ /// which are left untouched. See comments at function definition for an
219
+ /// example.
220
+ //
221
+ // Ex: to replace load %A[%i, %j] with load %Abuf[%t mod 2, %ii - %i, %j]:
222
+ // The SSA value corresponding to '%t mod 2' should be in 'extraIndices', and
223
+ // index remap will perform (%i, %j) -> (%ii - %i, %j), i.e., indexRemap = (d0,
224
+ // d1, d2) -> (d0 - d1, d2), and %ii will be the extra operand. Without any
225
+ // extra operands, note that 'indexRemap' would just be applied to existing
226
+ // indices (%i, %j).
227
+ // TODO: allow extraIndices to be added at any position.
228
+ LogicalResult replaceAllMemRefUsesWith(
229
+ Value oldMemRef, Value newMemRef, ArrayRef<Value> extraIndices = {},
230
+ AffineMap indexRemap = AffineMap(), ArrayRef<Value> extraOperands = {},
231
+ ArrayRef<Value> symbolOperands = {}, Operation *domOpFilter = nullptr,
232
+ Operation *postDomOpFilter = nullptr, bool allowNonDereferencingOps = false,
233
+ bool replaceInDeallocOp = false);
234
+
235
+ /// Performs the same replacement as the other version above but only for the
236
+ /// dereferencing uses of `oldMemRef` in `op`, except in cases where
237
+ /// 'allowNonDereferencingOps' is set to true where we replace the
238
+ /// non-dereferencing uses as well.
239
+ LogicalResult replaceAllMemRefUsesWith(Value oldMemRef, Value newMemRef,
240
+ Operation *op,
241
+ ArrayRef<Value> extraIndices = {},
242
+ AffineMap indexRemap = AffineMap(),
243
+ ArrayRef<Value> extraOperands = {},
244
+ ArrayRef<Value> symbolOperands = {},
245
+ bool allowNonDereferencingOps = false);
246
+
247
+ /// Rewrites the memref defined by alloc or reinterpret_cast op to have an
248
+ /// identity layout map and updates all its indexing uses. Returns failure if
249
+ /// any of its uses escape (while leaving the IR in a valid state).
250
+ template <typename AllocLikeOp>
251
+ LogicalResult normalizeMemRef(AllocLikeOp op);
252
+ extern template LogicalResult
253
+ normalizeMemRef<memref::AllocaOp>(memref::AllocaOp op);
254
+ extern template LogicalResult
255
+ normalizeMemRef<memref::AllocOp>(memref::AllocOp op);
256
+ LogicalResult normalizeMemRef(memref::ReinterpretCastOp op);
257
+
258
+ /// Normalizes `memrefType` so that the affine layout map of the memref is
259
+ /// transformed to an identity map with a new shape being computed for the
260
+ /// normalized memref type and returns it. The old memref type is simplify
261
+ /// returned if the normalization failed.
262
+ MemRefType normalizeMemRefType(MemRefType memrefType);
263
+
264
+ /// Given an operation, inserts one or more single result affine apply
265
+ /// operations, results of which are exclusively used by this operation.
266
+ /// The operands of these newly created affine apply ops are
267
+ /// guaranteed to be loop iterators or terminal symbols of a function.
268
+ ///
269
+ /// Before
270
+ ///
271
+ /// affine.for %i = 0 to #map(%N)
272
+ /// %idx = affine.apply (d0) -> (d0 mod 2) (%i)
273
+ /// send %A[%idx], ...
274
+ /// %v = "compute"(%idx, ...)
275
+ ///
276
+ /// After
277
+ ///
278
+ /// affine.for %i = 0 to #map(%N)
279
+ /// %idx = affine.apply (d0) -> (d0 mod 2) (%i)
280
+ /// send %A[%idx], ...
281
+ /// %idx_ = affine.apply (d0) -> (d0 mod 2) (%i)
282
+ /// %v = "compute"(%idx_, ...)
283
+
284
+ /// This allows the application of different transformations on send and
285
+ /// compute (for eg. different shifts/delays)
286
+ ///
287
+ /// Fills `sliceOps` with the list of affine.apply operations.
288
+ /// In the following cases, `sliceOps` remains empty:
289
+ /// 1. If none of opInst's operands were the result of an affine.apply
290
+ /// (i.e., there was no affine computation slice to create).
291
+ /// 2. If all the affine.apply op's supplying operands to this opInst did not
292
+ /// have any uses other than those in this opInst.
293
+ void createAffineComputationSlice(Operation *opInst,
294
+ SmallVectorImpl<AffineApplyOp> *sliceOps);
295
+
296
+ /// Emit code that computes the given affine expression using standard
297
+ /// arithmetic operations applied to the provided dimension and symbol values.
298
+ Value expandAffineExpr(OpBuilder &builder, Location loc, AffineExpr expr,
299
+ ValueRange dimValues, ValueRange symbolValues);
300
+
301
+ /// Create a sequence of operations that implement the `affineMap` applied to
302
+ /// the given `operands` (as it it were an AffineApplyOp).
303
+ std::optional<SmallVector<Value, 8>> expandAffineMap(OpBuilder &builder,
304
+ Location loc,
305
+ AffineMap affineMap,
306
+ ValueRange operands);
307
+
308
+ /// Holds the result of (div a, b) and (mod a, b).
309
+ struct DivModValue {
310
+ Value quotient;
311
+ Value remainder;
312
+ };
313
+
314
+ /// Create IR to calculate (div lhs, rhs) and (mod lhs, rhs).
315
+ DivModValue getDivMod(OpBuilder &b, Location loc, Value lhs, Value rhs);
316
+
317
+ /// Generate the IR to delinearize `linearIndex` given the `basis` and return
318
+ /// the multi-index. `hasOuterBound` indicates whether `basis` has an entry
319
+ /// given the size of the first multi-index result - if it is true, the function
320
+ /// will return `basis.size()` values, otherwise, it will return `basis.size() +
321
+ /// 1`.
322
+ FailureOr<SmallVector<Value>> delinearizeIndex(OpBuilder &b, Location loc,
323
+ Value linearIndex,
324
+ ArrayRef<Value> basis,
325
+ bool hasOuterBound = true);
326
+
327
+ FailureOr<SmallVector<Value>> delinearizeIndex(OpBuilder &b, Location loc,
328
+ Value linearIndex,
329
+ ArrayRef<OpFoldResult> basis,
330
+ bool hasOuterBound = true);
331
+
332
+ // Generate IR that extracts the linear index from a multi-index according to
333
+ // a basis/shape. The basis may contain either `multiIndex.size()` or
334
+ // `multiIndex.size() - 1` elements.
335
+ OpFoldResult linearizeIndex(ArrayRef<OpFoldResult> multiIndex,
336
+ ArrayRef<OpFoldResult> basis,
337
+ ImplicitLocOpBuilder &builder);
338
+
339
+ OpFoldResult linearizeIndex(OpBuilder &builder, Location loc,
340
+ ArrayRef<OpFoldResult> multiIndex,
341
+ ArrayRef<OpFoldResult> basis);
342
+
343
+ /// Ensure that all operations that could be executed after `start`
344
+ /// (noninclusive) and prior to `memOp` (e.g. on a control flow/op path
345
+ /// between the operations) do not have the potential memory effect
346
+ /// `EffectType` on `memOp`. `memOp` is an operation that reads or writes to
347
+ /// a memref. For example, if `EffectType` is MemoryEffects::Write, this method
348
+ /// will check if there is no write to the memory between `start` and `memOp`
349
+ /// that would change the read within `memOp`.
350
+ template <typename EffectType, typename T>
351
+ bool hasNoInterveningEffect(Operation *start, T memOp,
352
+ llvm::function_ref<bool(Value, Value)> mayAlias);
353
+
354
+ struct AffineValueExpr {
355
+ explicit AffineValueExpr(AffineExpr e) : e(e) {}
356
+ AffineValueExpr bind(Value v) {
357
+ this->v = v;
358
+ return *this;
359
+ }
360
+ AffineValueExpr bind(OpFoldResult v) {
361
+ this->v = v;
362
+ return *this;
363
+ }
364
+ operator AffineExpr() const { return e; }
365
+ operator OpFoldResult() const { return v; }
366
+ AffineExpr e;
367
+ OpFoldResult v;
368
+ };
369
+
370
+ /// Helper struct to build simple AffineValueExprs with minimal type inference
371
+ /// support.
372
+ struct AffineBuilder {
373
+ AffineBuilder(OpBuilder &b, Location loc) : b(b), loc(loc) {}
374
+ OpFoldResult add(AffineValueExpr lhs, AffineValueExpr rhs) {
375
+ return makeComposedFoldedAffineApply(b, loc, {lhs.e + rhs.e}, {lhs, rhs});
376
+ }
377
+ OpFoldResult sub(AffineValueExpr lhs, AffineValueExpr rhs) {
378
+ return makeComposedFoldedAffineApply(b, loc, {lhs.e - rhs.e}, {lhs, rhs});
379
+ }
380
+ OpFoldResult mul(AffineValueExpr lhs, AffineValueExpr rhs) {
381
+ return makeComposedFoldedAffineApply(b, loc, {lhs.e * rhs.e}, {lhs, rhs});
382
+ }
383
+ OpFoldResult floor(AffineValueExpr lhs, AffineValueExpr rhs) {
384
+ return makeComposedFoldedAffineApply(b, loc, {lhs.e.floorDiv(rhs.e)},
385
+ {lhs, rhs});
386
+ }
387
+ OpFoldResult ceil(AffineValueExpr lhs, AffineValueExpr rhs) {
388
+ return makeComposedFoldedAffineApply(b, loc, {lhs.e.ceilDiv(rhs.e)},
389
+ {lhs, rhs});
390
+ }
391
+ OpFoldResult min(ArrayRef<OpFoldResult> vals) {
392
+ return makeComposedFoldedAffineMin(
393
+ b, loc, AffineMap::getMultiDimIdentityMap(vals.size(), b.getContext()),
394
+ vals);
395
+ }
396
+ OpFoldResult max(ArrayRef<OpFoldResult> vals) {
397
+ return makeComposedFoldedAffineMax(
398
+ b, loc, AffineMap::getMultiDimIdentityMap(vals.size(), b.getContext()),
399
+ vals);
400
+ }
401
+
402
+ private:
403
+ OpBuilder &b;
404
+ Location loc;
405
+ };
406
+
407
+ } // namespace affine
408
+ } // namespace mlir
409
+
410
+ #endif // MLIR_DIALECT_AFFINE_UTILS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Affine/ViewLikeInterfaceUtils.h ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- ViewLikeInterfaceUtils.h ---------------------------------*- 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_AFFINE_VIEWLIKEINTERFACEUTILS_H
10
+ #define MLIR_DIALECT_AFFINE_VIEWLIKEINTERFACEUTILS_H
11
+
12
+ #include "mlir/Dialect/Utils/StaticValueUtils.h"
13
+ #include "mlir/IR/OpDefinition.h"
14
+ #include "mlir/Interfaces/ViewLikeInterface.h"
15
+
16
+ namespace mlir {
17
+ class RewriterBase;
18
+
19
+ namespace affine {
20
+
21
+ /// Fills the `combinedOffsets`, `combinedSizes` and `combinedStrides` to use
22
+ /// when combining a producer slice **into** a consumer slice.
23
+ ///
24
+ /// This function performs the following computation:
25
+ /// - Combined offsets = producer_offsets * consumer_strides + consumer_offsets
26
+ /// - Combined sizes = consumer_sizes
27
+ /// - Combined strides = producer_strides * consumer_strides
28
+ // TODO: unify this API with resolveIndicesIntoOpWithOffsetsAndStrides or
29
+ // deprecate.
30
+ LogicalResult
31
+ mergeOffsetsSizesAndStrides(OpBuilder &builder, Location loc,
32
+ ArrayRef<OpFoldResult> producerOffsets,
33
+ ArrayRef<OpFoldResult> producerSizes,
34
+ ArrayRef<OpFoldResult> producerStrides,
35
+ const llvm::SmallBitVector &droppedProducerDims,
36
+ ArrayRef<OpFoldResult> consumerOffsets,
37
+ ArrayRef<OpFoldResult> consumerSizes,
38
+ ArrayRef<OpFoldResult> consumerStrides,
39
+ SmallVector<OpFoldResult> &combinedOffsets,
40
+ SmallVector<OpFoldResult> &combinedSizes,
41
+ SmallVector<OpFoldResult> &combinedStrides);
42
+
43
+ /// Fills the `combinedOffsets`, `combinedSizes` and `combinedStrides` to use
44
+ /// when combining a `producer` slice op **into** a `consumer` slice op.
45
+ // TODO: unify this API with resolveIndicesIntoOpWithOffsetsAndStrides or
46
+ // deprecate.
47
+ LogicalResult
48
+ mergeOffsetsSizesAndStrides(OpBuilder &builder, Location loc,
49
+ OffsetSizeAndStrideOpInterface producer,
50
+ OffsetSizeAndStrideOpInterface consumer,
51
+ const llvm::SmallBitVector &droppedProducerDims,
52
+ SmallVector<OpFoldResult> &combinedOffsets,
53
+ SmallVector<OpFoldResult> &combinedSizes,
54
+ SmallVector<OpFoldResult> &combinedStrides);
55
+
56
+ /// Given the 'consumerIndices' of a load/store operation operating on an op
57
+ /// with offsets and strides, return the combined indices.
58
+ ///
59
+ /// For example, using `memref.load` and `memref.subview` as an illustration:
60
+ ///
61
+ /// ```
62
+ /// %0 = ... : memref<12x42xf32>
63
+ /// %1 = memref.subview %0[%arg0, %arg1][...][%stride1, %stride2] :
64
+ /// memref<12x42xf32> to memref<4x4xf32, offset=?, strides=[?, ?]>
65
+ /// %2 = load %1[%i1, %i2] : memref<4x4xf32, offset=?, strides=[?, ?]>
66
+ /// ```
67
+ ///
68
+ /// could be folded into:
69
+ ///
70
+ /// ```
71
+ /// %2 = load %0[%arg0 + %i1 * %stride1][%arg1 + %i2 * %stride2] :
72
+ /// memref<12x42xf32>å
73
+ /// ```
74
+ void resolveIndicesIntoOpWithOffsetsAndStrides(
75
+ RewriterBase &rewriter, Location loc,
76
+ ArrayRef<OpFoldResult> mixedSourceOffsets,
77
+ ArrayRef<OpFoldResult> mixedSourceStrides,
78
+ const llvm::SmallBitVector &rankReducedDims,
79
+ ArrayRef<OpFoldResult> consumerIndices,
80
+ SmallVectorImpl<Value> &resolvedIndices);
81
+
82
+ inline void resolveIndicesIntoOpWithOffsetsAndStrides(
83
+ RewriterBase &rewriter, Location loc,
84
+ ArrayRef<OpFoldResult> mixedSourceOffsets,
85
+ ArrayRef<OpFoldResult> mixedSourceStrides,
86
+ const llvm::SmallBitVector &rankReducedDims, ValueRange consumerIndices,
87
+ SmallVectorImpl<Value> &resolvedIndices) {
88
+ return resolveIndicesIntoOpWithOffsetsAndStrides(
89
+ rewriter, loc, mixedSourceOffsets, mixedSourceStrides, rankReducedDims,
90
+ getAsOpFoldResult(consumerIndices), resolvedIndices);
91
+ }
92
+
93
+ /// Given `sourceSizes`, `destSizes` and information about which dimensions are
94
+ /// dropped by the source: `rankReducedSourceDims`, compute the resolved sizes
95
+ /// that correspond to dest_op(source_op).
96
+ /// In practice, this amounts to filtering by `rankReducedSourceDims` and taking
97
+ /// from `sourceSizes` if a dimension is dropped, otherwise taking from
98
+ /// `destSizes`.
99
+ void resolveSizesIntoOpWithSizes(
100
+ ArrayRef<OpFoldResult> sourceSizes, ArrayRef<OpFoldResult> destSizes,
101
+ const llvm::SmallBitVector &rankReducedSourceDims,
102
+ SmallVectorImpl<OpFoldResult> &resolvedSizes);
103
+
104
+ } // namespace affine
105
+ } // namespace mlir
106
+
107
+ #endif // MLIR_DIALECT_AFFINE_VIEWLIKEINTERFACEUTILS_H
deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/Arith.h ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===- Arith.h - Arith dialect ------------------------------------*- 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_ARITH_IR_ARITH_H_
10
+ #define MLIR_DIALECT_ARITH_IR_ARITH_H_
11
+
12
+ #include "mlir/Bytecode/BytecodeOpInterface.h"
13
+ #include "mlir/IR/Dialect.h"
14
+ #include "mlir/IR/OpDefinition.h"
15
+ #include "mlir/IR/OpImplementation.h"
16
+ #include "mlir/Interfaces/CastInterfaces.h"
17
+ #include "mlir/Interfaces/ControlFlowInterfaces.h"
18
+ #include "mlir/Interfaces/InferIntRangeInterface.h"
19
+ #include "mlir/Interfaces/InferTypeOpInterface.h"
20
+ #include "mlir/Interfaces/SideEffectInterfaces.h"
21
+ #include "mlir/Interfaces/VectorInterfaces.h"
22
+ #include "llvm/ADT/StringExtras.h"
23
+
24
+ //===----------------------------------------------------------------------===//
25
+ // ArithDialect
26
+ //===----------------------------------------------------------------------===//
27
+
28
+ #include "mlir/Dialect/Arith/IR/ArithOpsDialect.h.inc"
29
+
30
+ //===----------------------------------------------------------------------===//
31
+ // Arith Dialect Enum Attributes
32
+ //===----------------------------------------------------------------------===//
33
+
34
+ #include "mlir/Dialect/Arith/IR/ArithOpsEnums.h.inc"
35
+ #define GET_ATTRDEF_CLASSES
36
+ #include "mlir/Dialect/Arith/IR/ArithOpsAttributes.h.inc"
37
+
38
+ //===----------------------------------------------------------------------===//
39
+ // Arith Interfaces
40
+ //===----------------------------------------------------------------------===//
41
+ #include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.h.inc"
42
+
43
+ //===----------------------------------------------------------------------===//
44
+ // Arith Dialect Operations
45
+ //===----------------------------------------------------------------------===//
46
+
47
+ #define GET_OP_CLASSES
48
+ #include "mlir/Dialect/Arith/IR/ArithOps.h.inc"
49
+
50
+ namespace mlir {
51
+ namespace arith {
52
+
53
+ /// Specialization of `arith.constant` op that returns an integer value.
54
+ class ConstantIntOp : public arith::ConstantOp {
55
+ public:
56
+ using arith::ConstantOp::ConstantOp;
57
+ static ::mlir::TypeID resolveTypeID() { return TypeID::get<ConstantOp>(); }
58
+
59
+ /// Build a constant int op that produces an integer of the specified width.
60
+ static void build(OpBuilder &builder, OperationState &result, int64_t value,
61
+ unsigned width);
62
+
63
+ /// Build a constant int op that produces an integer of the specified type,
64
+ /// which must be an integer type.
65
+ static void build(OpBuilder &builder, OperationState &result, int64_t value,
66
+ Type type);
67
+
68
+ inline int64_t value() {
69
+ return cast<IntegerAttr>(arith::ConstantOp::getValue()).getInt();
70
+ }
71
+
72
+ static bool classof(Operation *op);
73
+ };
74
+
75
+ /// Specialization of `arith.constant` op that returns a floating point value.
76
+ class ConstantFloatOp : public arith::ConstantOp {
77
+ public:
78
+ using arith::ConstantOp::ConstantOp;
79
+ static ::mlir::TypeID resolveTypeID() { return TypeID::get<ConstantOp>(); }
80
+
81
+ /// Build a constant float op that produces a float of the specified type.
82
+ static void build(OpBuilder &builder, OperationState &result,
83
+ const APFloat &value, FloatType type);
84
+
85
+ inline APFloat value() {
86
+ return cast<FloatAttr>(arith::ConstantOp::getValue()).getValue();
87
+ }
88
+
89
+ static bool classof(Operation *op);
90
+ };
91
+
92
+ /// Specialization of `arith.constant` op that returns an integer of index type.
93
+ class ConstantIndexOp : public arith::ConstantOp {
94
+ public:
95
+ using arith::ConstantOp::ConstantOp;
96
+ static ::mlir::TypeID resolveTypeID() { return TypeID::get<ConstantOp>(); }
97
+ /// Build a constant int op that produces an index.
98
+ static void build(OpBuilder &builder, OperationState &result, int64_t value);
99
+
100
+ inline int64_t value() {
101
+ return cast<IntegerAttr>(arith::ConstantOp::getValue()).getInt();
102
+ }
103
+
104
+ static bool classof(Operation *op);
105
+ };
106
+
107
+ } // namespace arith
108
+ } // namespace mlir
109
+
110
+ //===----------------------------------------------------------------------===//
111
+ // Utility Functions
112
+ //===----------------------------------------------------------------------===//
113
+
114
+ namespace mlir {
115
+ namespace arith {
116
+
117
+ /// Compute `lhs` `pred` `rhs`, where `pred` is one of the known integer
118
+ /// comparison predicates.
119
+ bool applyCmpPredicate(arith::CmpIPredicate predicate, const APInt &lhs,
120
+ const APInt &rhs);
121
+
122
+ /// Compute `lhs` `pred` `rhs`, where `pred` is one of the known floating point
123
+ /// comparison predicates.
124
+ bool applyCmpPredicate(arith::CmpFPredicate predicate, const APFloat &lhs,
125
+ const APFloat &rhs);
126
+
127
+ /// Returns the identity value attribute associated with an AtomicRMWKind op.
128
+ /// `useOnlyFiniteValue` defines whether the identity value should steer away
129
+ /// from infinity representations or anything that is not a proper finite
130
+ /// number.
131
+ /// E.g., The identity value for maxf is in theory `-Inf`, but if we want to
132
+ /// stay in the finite range, it would be `BiggestRepresentableNegativeFloat`.
133
+ /// The purpose of this boolean is to offer constants that will play nice
134
+ /// with fast math related optimizations.
135
+ TypedAttr getIdentityValueAttr(AtomicRMWKind kind, Type resultType,
136
+ OpBuilder &builder, Location loc,
137
+ bool useOnlyFiniteValue = false);
138
+
139
+ /// Return the identity numeric value associated to the give op. Return
140
+ /// std::nullopt if there is no known neutral element.
141
+ /// If `op` has `FastMathFlags::ninf`, only finite values will be used
142
+ /// as neutral element.
143
+ std::optional<TypedAttr> getNeutralElement(Operation *op);
144
+
145
+ /// Returns the identity value associated with an AtomicRMWKind op.
146
+ /// \see getIdentityValueAttr for a description of what `useOnlyFiniteValue`
147
+ /// does.
148
+ Value getIdentityValue(AtomicRMWKind op, Type resultType, OpBuilder &builder,
149
+ Location loc, bool useOnlyFiniteValue = false);
150
+
151
+ /// Returns the value obtained by applying the reduction operation kind
152
+ /// associated with a binary AtomicRMWKind op to `lhs` and `rhs`.
153
+ Value getReductionOp(AtomicRMWKind op, OpBuilder &builder, Location loc,
154
+ Value lhs, Value rhs);
155
+
156
+ arith::CmpIPredicate invertPredicate(arith::CmpIPredicate pred);
157
+ } // namespace arith
158
+ } // namespace mlir
159
+
160
+ #endif // MLIR_DIALECT_ARITH_IR_ARITH_H_
deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/ArithCanonicalization.inc ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/ArithOps.cpp.inc ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/ArithOps.h.inc ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
+ |* *|
3
+ |* AttrDef Definitions *|
4
+ |* *|
5
+ |* Automatically generated file, do not edit! *|
6
+ |* *|
7
+ \*===----------------------------------------------------------------------===*/
8
+
9
+ #ifdef GET_ATTRDEF_LIST
10
+ #undef GET_ATTRDEF_LIST
11
+
12
+ ::mlir::arith::FastMathFlagsAttr,
13
+ ::mlir::arith::IntegerOverflowFlagsAttr
14
+
15
+ #endif // GET_ATTRDEF_LIST
16
+
17
+ #ifdef GET_ATTRDEF_CLASSES
18
+ #undef GET_ATTRDEF_CLASSES
19
+
20
+ static ::mlir::OptionalParseResult generatedAttributeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type type, ::mlir::Attribute &value) {
21
+ return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
22
+ .Case(::mlir::arith::FastMathFlagsAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
23
+ value = ::mlir::arith::FastMathFlagsAttr::parse(parser, type);
24
+ return ::mlir::success(!!value);
25
+ })
26
+ .Case(::mlir::arith::IntegerOverflowFlagsAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
27
+ value = ::mlir::arith::IntegerOverflowFlagsAttr::parse(parser, type);
28
+ return ::mlir::success(!!value);
29
+ })
30
+ .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
31
+ *mnemonic = keyword;
32
+ return std::nullopt;
33
+ });
34
+ }
35
+
36
+ static ::llvm::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
37
+ return ::llvm::TypeSwitch<::mlir::Attribute, ::llvm::LogicalResult>(def) .Case<::mlir::arith::FastMathFlagsAttr>([&](auto t) {
38
+ printer << ::mlir::arith::FastMathFlagsAttr::getMnemonic();
39
+ t.print(printer);
40
+ return ::mlir::success();
41
+ })
42
+ .Case<::mlir::arith::IntegerOverflowFlagsAttr>([&](auto t) {
43
+ printer << ::mlir::arith::IntegerOverflowFlagsAttr::getMnemonic();
44
+ t.print(printer);
45
+ return ::mlir::success();
46
+ })
47
+ .Default([](auto) { return ::mlir::failure(); });
48
+ }
49
+
50
+ namespace mlir {
51
+ namespace arith {
52
+ namespace detail {
53
+ struct FastMathFlagsAttrStorage : public ::mlir::AttributeStorage {
54
+ using KeyTy = std::tuple<::mlir::arith::FastMathFlags>;
55
+ FastMathFlagsAttrStorage(::mlir::arith::FastMathFlags value) : value(std::move(value)) {}
56
+
57
+ KeyTy getAsKey() const {
58
+ return KeyTy(value);
59
+ }
60
+
61
+ bool operator==(const KeyTy &tblgenKey) const {
62
+ return (value == std::get<0>(tblgenKey));
63
+ }
64
+
65
+ static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
66
+ return ::llvm::hash_combine(std::get<0>(tblgenKey));
67
+ }
68
+
69
+ static FastMathFlagsAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
70
+ auto value = std::move(std::get<0>(tblgenKey));
71
+ return new (allocator.allocate<FastMathFlagsAttrStorage>()) FastMathFlagsAttrStorage(std::move(value));
72
+ }
73
+
74
+ ::mlir::arith::FastMathFlags value;
75
+ };
76
+ } // namespace detail
77
+ FastMathFlagsAttr FastMathFlagsAttr::get(::mlir::MLIRContext *context, ::mlir::arith::FastMathFlags value) {
78
+ return Base::get(context, std::move(value));
79
+ }
80
+
81
+ ::mlir::Attribute FastMathFlagsAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
82
+ ::mlir::Builder odsBuilder(odsParser.getContext());
83
+ ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
84
+ (void) odsLoc;
85
+ ::mlir::FailureOr<::mlir::arith::FastMathFlags> _result_value;
86
+ // Parse literal '<'
87
+ if (odsParser.parseLess()) return {};
88
+
89
+ // Parse variable 'value'
90
+ _result_value = [&]() -> ::mlir::FailureOr<::mlir::arith::FastMathFlags> {
91
+ ::mlir::arith::FastMathFlags flags = {};
92
+ auto loc = odsParser.getCurrentLocation();
93
+ ::llvm::StringRef enumKeyword;
94
+ do {
95
+ if (::mlir::failed(odsParser.parseKeyword(&enumKeyword)))
96
+ return ::mlir::failure();
97
+ auto maybeEnum = ::mlir::arith::symbolizeFastMathFlags(enumKeyword);
98
+ if (!maybeEnum) {
99
+ return {(::llvm::LogicalResult)(odsParser.emitError(loc) << "expected " << "::mlir::arith::FastMathFlags" << " to be one of: " << "none" << ", " << "reassoc" << ", " << "nnan" << ", " << "ninf" << ", " << "nsz" << ", " << "arcp" << ", " << "contract" << ", " << "afn" << ", " << "fast")};
100
+ }
101
+ flags = flags | *maybeEnum;
102
+ } while(::mlir::succeeded(odsParser.parseOptionalComma()));
103
+ return flags;
104
+ }();
105
+ if (::mlir::failed(_result_value)) {
106
+ odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Arith_FastMathAttr parameter 'value' which is to be a `::mlir::arith::FastMathFlags`");
107
+ return {};
108
+ }
109
+ // Parse literal '>'
110
+ if (odsParser.parseGreater()) return {};
111
+ assert(::mlir::succeeded(_result_value));
112
+ return FastMathFlagsAttr::get(odsParser.getContext(),
113
+ ::mlir::arith::FastMathFlags((*_result_value)));
114
+ }
115
+
116
+ void FastMathFlagsAttr::print(::mlir::AsmPrinter &odsPrinter) const {
117
+ ::mlir::Builder odsBuilder(getContext());
118
+ odsPrinter << "<";
119
+ odsPrinter << stringifyFastMathFlags(getValue());
120
+ odsPrinter << ">";
121
+ }
122
+
123
+ ::mlir::arith::FastMathFlags FastMathFlagsAttr::getValue() const {
124
+ return getImpl()->value;
125
+ }
126
+
127
+ } // namespace arith
128
+ } // namespace mlir
129
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::arith::FastMathFlagsAttr)
130
+ namespace mlir {
131
+ namespace arith {
132
+ namespace detail {
133
+ struct IntegerOverflowFlagsAttrStorage : public ::mlir::AttributeStorage {
134
+ using KeyTy = std::tuple<::mlir::arith::IntegerOverflowFlags>;
135
+ IntegerOverflowFlagsAttrStorage(::mlir::arith::IntegerOverflowFlags value) : value(std::move(value)) {}
136
+
137
+ KeyTy getAsKey() const {
138
+ return KeyTy(value);
139
+ }
140
+
141
+ bool operator==(const KeyTy &tblgenKey) const {
142
+ return (value == std::get<0>(tblgenKey));
143
+ }
144
+
145
+ static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
146
+ return ::llvm::hash_combine(std::get<0>(tblgenKey));
147
+ }
148
+
149
+ static IntegerOverflowFlagsAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
150
+ auto value = std::move(std::get<0>(tblgenKey));
151
+ return new (allocator.allocate<IntegerOverflowFlagsAttrStorage>()) IntegerOverflowFlagsAttrStorage(std::move(value));
152
+ }
153
+
154
+ ::mlir::arith::IntegerOverflowFlags value;
155
+ };
156
+ } // namespace detail
157
+ IntegerOverflowFlagsAttr IntegerOverflowFlagsAttr::get(::mlir::MLIRContext *context, ::mlir::arith::IntegerOverflowFlags value) {
158
+ return Base::get(context, std::move(value));
159
+ }
160
+
161
+ ::mlir::Attribute IntegerOverflowFlagsAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
162
+ ::mlir::Builder odsBuilder(odsParser.getContext());
163
+ ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
164
+ (void) odsLoc;
165
+ ::mlir::FailureOr<::mlir::arith::IntegerOverflowFlags> _result_value;
166
+ // Parse literal '<'
167
+ if (odsParser.parseLess()) return {};
168
+
169
+ // Parse variable 'value'
170
+ _result_value = [&]() -> ::mlir::FailureOr<::mlir::arith::IntegerOverflowFlags> {
171
+ ::mlir::arith::IntegerOverflowFlags flags = {};
172
+ auto loc = odsParser.getCurrentLocation();
173
+ ::llvm::StringRef enumKeyword;
174
+ do {
175
+ if (::mlir::failed(odsParser.parseKeyword(&enumKeyword)))
176
+ return ::mlir::failure();
177
+ auto maybeEnum = ::mlir::arith::symbolizeIntegerOverflowFlags(enumKeyword);
178
+ if (!maybeEnum) {
179
+ return {(::llvm::LogicalResult)(odsParser.emitError(loc) << "expected " << "::mlir::arith::IntegerOverflowFlags" << " to be one of: " << "none" << ", " << "nsw" << ", " << "nuw")};
180
+ }
181
+ flags = flags | *maybeEnum;
182
+ } while(::mlir::succeeded(odsParser.parseOptionalComma()));
183
+ return flags;
184
+ }();
185
+ if (::mlir::failed(_result_value)) {
186
+ odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Arith_IntegerOverflowAttr parameter 'value' which is to be a `::mlir::arith::IntegerOverflowFlags`");
187
+ return {};
188
+ }
189
+ // Parse literal '>'
190
+ if (odsParser.parseGreater()) return {};
191
+ assert(::mlir::succeeded(_result_value));
192
+ return IntegerOverflowFlagsAttr::get(odsParser.getContext(),
193
+ ::mlir::arith::IntegerOverflowFlags((*_result_value)));
194
+ }
195
+
196
+ void IntegerOverflowFlagsAttr::print(::mlir::AsmPrinter &odsPrinter) const {
197
+ ::mlir::Builder odsBuilder(getContext());
198
+ odsPrinter << "<";
199
+ odsPrinter << stringifyIntegerOverflowFlags(getValue());
200
+ odsPrinter << ">";
201
+ }
202
+
203
+ ::mlir::arith::IntegerOverflowFlags IntegerOverflowFlagsAttr::getValue() const {
204
+ return getImpl()->value;
205
+ }
206
+
207
+ } // namespace arith
208
+ } // namespace mlir
209
+ MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::arith::IntegerOverflowFlagsAttr)
210
+ namespace mlir {
211
+ namespace arith {
212
+
213
+ /// Parse an attribute registered to this dialect.
214
+ ::mlir::Attribute ArithDialect::parseAttribute(::mlir::DialectAsmParser &parser,
215
+ ::mlir::Type type) const {
216
+ ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
217
+ ::llvm::StringRef attrTag;
218
+ {
219
+ ::mlir::Attribute attr;
220
+ auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
221
+ if (parseResult.has_value())
222
+ return attr;
223
+ }
224
+
225
+ parser.emitError(typeLoc) << "unknown attribute `"
226
+ << attrTag << "` in dialect `" << getNamespace() << "`";
227
+ return {};
228
+ }
229
+ /// Print an attribute registered to this dialect.
230
+ void ArithDialect::printAttribute(::mlir::Attribute attr,
231
+ ::mlir::DialectAsmPrinter &printer) const {
232
+ if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
233
+ return;
234
+
235
+ }
236
+ } // namespace arith
237
+ } // namespace mlir
238
+
239
+ #endif // GET_ATTRDEF_CLASSES
240
+