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, 164 llvm::SmallVector<int64_t> &value); 165 166 void printUsingPropertyInCustom(mlir::OpAsmPrinter &printer, 167 mlir::Operation *op, 168 llvm::ArrayRef<int64_t> value); 169 170 //===----------------------------------------------------------------------===// 171 // CustomDirectiveIntProperty 172 //===----------------------------------------------------------------------===// 173 174 bool parseIntProperty(mlir::OpAsmParser &parser, int64_t &value); 175 176 void printIntProperty(mlir::OpAsmPrinter &printer, mlir::Operation *op, 177 int64_t value); 178 179 //===----------------------------------------------------------------------===// 180 // CustomDirectiveSumProperty 181 //===----------------------------------------------------------------------===// 182 183 bool parseSumProperty(mlir::OpAsmParser &parser, int64_t &second, 184 int64_t first); 185 186 void printSumProperty(mlir::OpAsmPrinter &printer, mlir::Operation *op, 187 int64_t second, int64_t first); 188 189 //===----------------------------------------------------------------------===// 190 // CustomDirectiveOptionalCustomParser 191 //===----------------------------------------------------------------------===// 192 193 mlir::OptionalParseResult parseOptionalCustomParser(mlir::AsmParser &p, 194 mlir::IntegerAttr &result); 195 196 void printOptionalCustomParser(mlir::AsmPrinter &p, mlir::Operation *, 197 mlir::IntegerAttr result); 198 199 //===----------------------------------------------------------------------===// 200 // CustomDirectiveAttrElideType 201 //===----------------------------------------------------------------------===// 202 203 mlir::ParseResult parseAttrElideType(mlir::AsmParser &parser, 204 mlir::TypeAttr type, 205 mlir::Attribute &attr); 206 207 void printAttrElideType(mlir::AsmPrinter &printer, mlir::Operation *op, 208 mlir::TypeAttr type, mlir::Attribute attr); 209 210 } // end namespace test 211 212 #endif // MLIR_TESTFORMATUTILS_H 213