1 //===- TestFormatUtils.h - MLIR Test Dialect Assembly Format Utilities ----===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef MLIR_TESTFORMATUTILS_H
10 #define MLIR_TESTFORMATUTILS_H
12 #include "mlir/IR/OpImplementation.h"
16 //===----------------------------------------------------------------------===//
17 // CustomDirectiveOperands
18 //===----------------------------------------------------------------------===//
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
);
25 void printCustomDirectiveOperands(mlir::OpAsmPrinter
&printer
,
26 mlir::Operation
*, mlir::Value operand
,
27 mlir::Value optOperand
,
28 mlir::OperandRange varOperands
);
30 //===----------------------------------------------------------------------===//
31 // CustomDirectiveResults
32 //===----------------------------------------------------------------------===//
35 parseCustomDirectiveResults(mlir::OpAsmParser
&parser
, mlir::Type
&operandType
,
36 mlir::Type
&optOperandType
,
37 llvm::SmallVectorImpl
<mlir::Type
> &varOperandTypes
);
39 void printCustomDirectiveResults(mlir::OpAsmPrinter
&printer
, mlir::Operation
*,
40 mlir::Type operandType
,
41 mlir::Type optOperandType
,
42 mlir::TypeRange varOperandTypes
);
44 //===----------------------------------------------------------------------===//
45 // CustomDirectiveWithTypeRefs
46 //===----------------------------------------------------------------------===//
48 mlir::ParseResult
parseCustomDirectiveWithTypeRefs(
49 mlir::OpAsmParser
&parser
, mlir::Type operandType
,
50 mlir::Type optOperandType
,
51 const llvm::SmallVectorImpl
<mlir::Type
> &varOperandTypes
);
53 void printCustomDirectiveWithTypeRefs(mlir::OpAsmPrinter
&printer
,
55 mlir::Type operandType
,
56 mlir::Type optOperandType
,
57 mlir::TypeRange varOperandTypes
);
59 //===----------------------------------------------------------------------===//
60 // CustomDirectiveOperandsAndTypes
61 //===----------------------------------------------------------------------===//
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
);
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
);
76 //===----------------------------------------------------------------------===//
77 // CustomDirectiveRegions
78 //===----------------------------------------------------------------------===//
80 mlir::ParseResult
parseCustomDirectiveRegions(
81 mlir::OpAsmParser
&parser
, mlir::Region
®ion
,
82 llvm::SmallVectorImpl
<std::unique_ptr
<mlir::Region
>> &varRegions
);
84 void printCustomDirectiveRegions(
85 mlir::OpAsmPrinter
&printer
, mlir::Operation
*, mlir::Region
®ion
,
86 llvm::MutableArrayRef
<mlir::Region
> varRegions
);
88 //===----------------------------------------------------------------------===//
89 // CustomDirectiveSuccessors
90 //===----------------------------------------------------------------------===//
92 mlir::ParseResult
parseCustomDirectiveSuccessors(
93 mlir::OpAsmParser
&parser
, mlir::Block
*&successor
,
94 llvm::SmallVectorImpl
<mlir::Block
*> &varSuccessors
);
96 void printCustomDirectiveSuccessors(mlir::OpAsmPrinter
&printer
,
97 mlir::Operation
*, mlir::Block
*successor
,
98 mlir::SuccessorRange varSuccessors
);
100 //===----------------------------------------------------------------------===//
101 // CustomDirectiveAttributes
102 //===----------------------------------------------------------------------===//
104 mlir::ParseResult
parseCustomDirectiveAttributes(mlir::OpAsmParser
&parser
,
105 mlir::IntegerAttr
&attr
,
106 mlir::IntegerAttr
&optAttr
);
108 void printCustomDirectiveAttributes(mlir::OpAsmPrinter
&printer
,
110 mlir::Attribute attribute
,
111 mlir::Attribute optAttribute
);
113 //===----------------------------------------------------------------------===//
114 // CustomDirectiveAttrDict
115 //===----------------------------------------------------------------------===//
117 mlir::ParseResult
parseCustomDirectiveAttrDict(mlir::OpAsmParser
&parser
,
118 mlir::NamedAttrList
&attrs
);
120 void printCustomDirectiveAttrDict(mlir::OpAsmPrinter
&printer
,
122 mlir::DictionaryAttr attrs
);
124 //===----------------------------------------------------------------------===//
125 // CustomDirectiveOptionalOperandRef
126 //===----------------------------------------------------------------------===//
128 mlir::ParseResult
parseCustomDirectiveOptionalOperandRef(
129 mlir::OpAsmParser
&parser
,
130 std::optional
<mlir::OpAsmParser::UnresolvedOperand
> &optOperand
);
132 void printCustomDirectiveOptionalOperandRef(mlir::OpAsmPrinter
&printer
,
134 mlir::Value optOperand
);
136 //===----------------------------------------------------------------------===//
137 // CustomDirectiveOptionalOperand
138 //===----------------------------------------------------------------------===//
140 mlir::ParseResult
parseCustomOptionalOperand(
141 mlir::OpAsmParser
&parser
,
142 std::optional
<mlir::OpAsmParser::UnresolvedOperand
> &optOperand
);
144 void printCustomOptionalOperand(mlir::OpAsmPrinter
&printer
, mlir::Operation
*,
145 mlir::Value optOperand
);
147 //===----------------------------------------------------------------------===//
148 // CustomDirectiveSwitchCases
149 //===----------------------------------------------------------------------===//
151 mlir::ParseResult
parseSwitchCases(
152 mlir::OpAsmParser
&p
, mlir::DenseI64ArrayAttr
&cases
,
153 llvm::SmallVectorImpl
<std::unique_ptr
<mlir::Region
>> &caseRegions
);
155 void printSwitchCases(mlir::OpAsmPrinter
&p
, mlir::Operation
*op
,
156 mlir::DenseI64ArrayAttr cases
,
157 mlir::RegionRange caseRegions
);
159 //===----------------------------------------------------------------------===//
160 // CustomUsingPropertyInCustom
161 //===----------------------------------------------------------------------===//
163 bool parseUsingPropertyInCustom(mlir::OpAsmParser
&parser
,
164 llvm::SmallVector
<int64_t> &value
);
166 void printUsingPropertyInCustom(mlir::OpAsmPrinter
&printer
,
168 llvm::ArrayRef
<int64_t> value
);
170 //===----------------------------------------------------------------------===//
171 // CustomDirectiveIntProperty
172 //===----------------------------------------------------------------------===//
174 bool parseIntProperty(mlir::OpAsmParser
&parser
, int64_t &value
);
176 void printIntProperty(mlir::OpAsmPrinter
&printer
, mlir::Operation
*op
,
179 //===----------------------------------------------------------------------===//
180 // CustomDirectiveSumProperty
181 //===----------------------------------------------------------------------===//
183 bool parseSumProperty(mlir::OpAsmParser
&parser
, int64_t &second
,
186 void printSumProperty(mlir::OpAsmPrinter
&printer
, mlir::Operation
*op
,
187 int64_t second
, int64_t first
);
189 //===----------------------------------------------------------------------===//
190 // CustomDirectiveOptionalCustomParser
191 //===----------------------------------------------------------------------===//
193 mlir::OptionalParseResult
parseOptionalCustomParser(mlir::AsmParser
&p
,
194 mlir::IntegerAttr
&result
);
196 void printOptionalCustomParser(mlir::AsmPrinter
&p
, mlir::Operation
*,
197 mlir::IntegerAttr result
);
199 //===----------------------------------------------------------------------===//
200 // CustomDirectiveAttrElideType
201 //===----------------------------------------------------------------------===//
203 mlir::ParseResult
parseAttrElideType(mlir::AsmParser
&parser
,
205 mlir::Attribute
&attr
);
207 void printAttrElideType(mlir::AsmPrinter
&printer
, mlir::Operation
*op
,
208 mlir::TypeAttr type
, mlir::Attribute attr
);
210 } // end namespace test
212 #endif // MLIR_TESTFORMATUTILS_H