1 | //===- TestFormatUtils.h - MLIR Test Dialect Assembly Format Utilities ----===// |
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_TESTFORMATUTILS_H |
10 | #define MLIR_TESTFORMATUTILS_H |
11 | |
12 | #include "mlir/IR/OpImplementation.h" |
13 | |
14 | namespace test { |
15 | |
16 | //===----------------------------------------------------------------------===// |
17 | // CustomDirectiveOperands |
18 | //===----------------------------------------------------------------------===// |
19 | |
20 | mlir::ParseResult parseCustomDirectiveOperands( |
21 | mlir::OpAsmParser &parser, mlir::OpAsmParser::UnresolvedOperand &operand, |
22 | std::optional<mlir::OpAsmParser::UnresolvedOperand> &optOperand, |
23 | llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &varOperands); |
24 | |
25 | void printCustomDirectiveOperands(mlir::OpAsmPrinter &printer, |
26 | mlir::Operation *, mlir::Value operand, |
27 | mlir::Value optOperand, |
28 | mlir::OperandRange varOperands); |
29 | |
30 | //===----------------------------------------------------------------------===// |
31 | // CustomDirectiveResults |
32 | //===----------------------------------------------------------------------===// |
33 | |
34 | mlir::ParseResult |
35 | parseCustomDirectiveResults(mlir::OpAsmParser &parser, mlir::Type &operandType, |
36 | mlir::Type &optOperandType, |
37 | llvm::SmallVectorImpl<mlir::Type> &varOperandTypes); |
38 | |
39 | void printCustomDirectiveResults(mlir::OpAsmPrinter &printer, mlir::Operation *, |
40 | mlir::Type operandType, |
41 | mlir::Type optOperandType, |
42 | mlir::TypeRange varOperandTypes); |
43 | |
44 | //===----------------------------------------------------------------------===// |
45 | // CustomDirectiveWithTypeRefs |
46 | //===----------------------------------------------------------------------===// |
47 | |
48 | mlir::ParseResult parseCustomDirectiveWithTypeRefs( |
49 | mlir::OpAsmParser &parser, mlir::Type operandType, |
50 | mlir::Type optOperandType, |
51 | const llvm::SmallVectorImpl<mlir::Type> &varOperandTypes); |
52 | |
53 | void printCustomDirectiveWithTypeRefs(mlir::OpAsmPrinter &printer, |
54 | mlir::Operation *op, |
55 | mlir::Type operandType, |
56 | mlir::Type optOperandType, |
57 | mlir::TypeRange varOperandTypes); |
58 | |
59 | //===----------------------------------------------------------------------===// |
60 | // CustomDirectiveOperandsAndTypes |
61 | //===----------------------------------------------------------------------===// |
62 | |
63 | mlir::ParseResult parseCustomDirectiveOperandsAndTypes( |
64 | mlir::OpAsmParser &parser, mlir::OpAsmParser::UnresolvedOperand &operand, |
65 | std::optional<mlir::OpAsmParser::UnresolvedOperand> &optOperand, |
66 | llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &varOperands, |
67 | mlir::Type &operandType, mlir::Type &optOperandType, |
68 | llvm::SmallVectorImpl<mlir::Type> &varOperandTypes); |
69 | |
70 | void printCustomDirectiveOperandsAndTypes( |
71 | mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::Value operand, |
72 | mlir::Value optOperand, mlir::OperandRange varOperands, |
73 | mlir::Type operandType, mlir::Type optOperandType, |
74 | mlir::TypeRange varOperandTypes); |
75 | |
76 | //===----------------------------------------------------------------------===// |
77 | // CustomDirectiveRegions |
78 | //===----------------------------------------------------------------------===// |
79 | |
80 | mlir::ParseResult parseCustomDirectiveRegions( |
81 | mlir::OpAsmParser &parser, mlir::Region ®ion, |
82 | llvm::SmallVectorImpl<std::unique_ptr<mlir::Region>> &varRegions); |
83 | |
84 | void printCustomDirectiveRegions( |
85 | mlir::OpAsmPrinter &printer, mlir::Operation *, mlir::Region ®ion, |
86 | llvm::MutableArrayRef<mlir::Region> varRegions); |
87 | |
88 | //===----------------------------------------------------------------------===// |
89 | // CustomDirectiveSuccessors |
90 | //===----------------------------------------------------------------------===// |
91 | |
92 | mlir::ParseResult parseCustomDirectiveSuccessors( |
93 | mlir::OpAsmParser &parser, mlir::Block *&successor, |
94 | llvm::SmallVectorImpl<mlir::Block *> &varSuccessors); |
95 | |
96 | void printCustomDirectiveSuccessors(mlir::OpAsmPrinter &printer, |
97 | mlir::Operation *, mlir::Block *successor, |
98 | mlir::SuccessorRange varSuccessors); |
99 | |
100 | //===----------------------------------------------------------------------===// |
101 | // CustomDirectiveAttributes |
102 | //===----------------------------------------------------------------------===// |
103 | |
104 | mlir::ParseResult parseCustomDirectiveAttributes(mlir::OpAsmParser &parser, |
105 | mlir::IntegerAttr &attr, |
106 | mlir::IntegerAttr &optAttr); |
107 | |
108 | void printCustomDirectiveAttributes(mlir::OpAsmPrinter &printer, |
109 | mlir::Operation *, |
110 | mlir::Attribute attribute, |
111 | mlir::Attribute optAttribute); |
112 | |
113 | //===----------------------------------------------------------------------===// |
114 | // CustomDirectiveAttrDict |
115 | //===----------------------------------------------------------------------===// |
116 | |
117 | mlir::ParseResult parseCustomDirectiveAttrDict(mlir::OpAsmParser &parser, |
118 | mlir::NamedAttrList &attrs); |
119 | |
120 | void printCustomDirectiveAttrDict(mlir::OpAsmPrinter &printer, |
121 | mlir::Operation *op, |
122 | mlir::DictionaryAttr attrs); |
123 | |
124 | //===----------------------------------------------------------------------===// |
125 | // CustomDirectiveOptionalOperandRef |
126 | //===----------------------------------------------------------------------===// |
127 | |
128 | mlir::ParseResult parseCustomDirectiveOptionalOperandRef( |
129 | mlir::OpAsmParser &parser, |
130 | std::optional<mlir::OpAsmParser::UnresolvedOperand> &optOperand); |
131 | |
132 | void printCustomDirectiveOptionalOperandRef(mlir::OpAsmPrinter &printer, |
133 | mlir::Operation *op, |
134 | mlir::Value optOperand); |
135 | |
136 | //===----------------------------------------------------------------------===// |
137 | // CustomDirectiveOptionalOperand |
138 | //===----------------------------------------------------------------------===// |
139 | |
140 | mlir::ParseResult parseCustomOptionalOperand( |
141 | mlir::OpAsmParser &parser, |
142 | std::optional<mlir::OpAsmParser::UnresolvedOperand> &optOperand); |
143 | |
144 | void printCustomOptionalOperand(mlir::OpAsmPrinter &printer, mlir::Operation *, |
145 | mlir::Value optOperand); |
146 | |
147 | //===----------------------------------------------------------------------===// |
148 | // CustomDirectiveSwitchCases |
149 | //===----------------------------------------------------------------------===// |
150 | |
151 | mlir::ParseResult parseSwitchCases( |
152 | mlir::OpAsmParser &p, mlir::DenseI64ArrayAttr &cases, |
153 | llvm::SmallVectorImpl<std::unique_ptr<mlir::Region>> &caseRegions); |
154 | |
155 | void printSwitchCases(mlir::OpAsmPrinter &p, mlir::Operation *op, |
156 | mlir::DenseI64ArrayAttr cases, |
157 | mlir::RegionRange caseRegions); |
158 | |
159 | //===----------------------------------------------------------------------===// |
160 | // CustomUsingPropertyInCustom |
161 | //===----------------------------------------------------------------------===// |
162 | |
163 | bool parseUsingPropertyInCustom(mlir::OpAsmParser &parser, int64_t value[3]); |
164 | |
165 | void printUsingPropertyInCustom(mlir::OpAsmPrinter &printer, |
166 | mlir::Operation *op, |
167 | llvm::ArrayRef<int64_t> value); |
168 | |
169 | //===----------------------------------------------------------------------===// |
170 | // CustomDirectiveIntProperty |
171 | //===----------------------------------------------------------------------===// |
172 | |
173 | bool parseIntProperty(mlir::OpAsmParser &parser, int64_t &value); |
174 | |
175 | void printIntProperty(mlir::OpAsmPrinter &printer, mlir::Operation *op, |
176 | int64_t value); |
177 | |
178 | //===----------------------------------------------------------------------===// |
179 | // CustomDirectiveSumProperty |
180 | //===----------------------------------------------------------------------===// |
181 | |
182 | bool parseSumProperty(mlir::OpAsmParser &parser, int64_t &second, |
183 | int64_t first); |
184 | |
185 | void printSumProperty(mlir::OpAsmPrinter &printer, mlir::Operation *op, |
186 | int64_t second, int64_t first); |
187 | |
188 | //===----------------------------------------------------------------------===// |
189 | // CustomDirectiveOptionalCustomParser |
190 | //===----------------------------------------------------------------------===// |
191 | |
192 | mlir::OptionalParseResult parseOptionalCustomParser(mlir::AsmParser &p, |
193 | mlir::IntegerAttr &result); |
194 | |
195 | void printOptionalCustomParser(mlir::AsmPrinter &p, mlir::Operation *, |
196 | mlir::IntegerAttr result); |
197 | |
198 | //===----------------------------------------------------------------------===// |
199 | // CustomDirectiveAttrElideType |
200 | //===----------------------------------------------------------------------===// |
201 | |
202 | mlir::ParseResult parseAttrElideType(mlir::AsmParser &parser, |
203 | mlir::TypeAttr type, |
204 | mlir::Attribute &attr); |
205 | |
206 | void printAttrElideType(mlir::AsmPrinter &printer, mlir::Operation *op, |
207 | mlir::TypeAttr type, mlir::Attribute attr); |
208 | |
209 | } // end namespace test |
210 | |
211 | #endif // MLIR_TESTFORMATUTILS_H |
212 | |