MLIR 24.0.0git
Utils.h
Go to the documentation of this file.
1//===- Utils.h - Transform 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#ifndef MLIR_DIALECT_TRANSFORMS_UTILS_UTILS_H
10#define MLIR_DIALECT_TRANSFORMS_UTILS_UTILS_H
11
13#include "mlir/IR/Value.h"
14#include "mlir/IR/ValueRange.h"
15#include "mlir/Support/LLVM.h"
16
17namespace mlir {
18class OpAsmPrinter;
19
20namespace transform {
21class TransformState;
22
23/// Printer hook for custom directive in assemblyFormat.
24///
25/// custom<PackedOrDynamicIndexList>($packed, type($packed), $values,
26/// type($values), $integers)
27///
28/// where `values` are variadic Index values, `integers` is an `I64ArrayAttr`
29/// and `packed` is a single transform dialect handle who's mapped payload ops
30/// have a single Index result and represent the index list. Either `packed`
31/// or the other two parameters may be specified.
32///
33/// This allows idiomatic printing of mixed value and integer attributes in a
34/// list or with a single handle. E.g., `[%arg0 : !transform.any_op, 7, 42,
35/// %arg42 : !transform.param<i64>]` or just `%h : !transform.any_op`.
36void printPackedOrDynamicIndexList(OpAsmPrinter &printer, Operation *op,
37 Value packed, Type packedType,
38 OperandRange values, TypeRange valueTypes,
39 DenseBoolArrayAttr scalableFlags,
40 DenseI64ArrayAttr integers);
42 Value packed, Type packedType,
43 OperandRange values,
44 TypeRange valueTypes,
45 DenseI64ArrayAttr integers) {
46 printPackedOrDynamicIndexList(printer, op, packed, packedType, values,
47 valueTypes, DenseBoolArrayAttr(), integers);
48}
50 Value packed, OperandRange values,
51 DenseBoolArrayAttr scalableFlags,
52 DenseI64ArrayAttr integers) {
53 printPackedOrDynamicIndexList(printer, op, packed, Type(), values,
54 TypeRange{}, scalableFlags, integers);
55}
57 Value packed, OperandRange values,
58 DenseI64ArrayAttr integers,
59 DenseBoolArrayAttr scalableFlags) {
60 printPackedOrDynamicIndexList(printer, op, packed, values, scalableFlags,
61 integers);
62}
64 Value packed, OperandRange values,
65 DenseI64ArrayAttr integers) {
66 printPackedOrDynamicIndexList(printer, op, packed, Type(), values,
67 TypeRange{}, DenseBoolArrayAttr(), integers);
68}
69
70/// Parser hook for custom directive in assemblyFormat.
71///
72/// custom<PackedOrDynamicIndexList>($packed, type($packed), $values,
73/// type($values), $integers)
74///
75/// See `printPackedOrDynamicIndexList` for details.
77 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
79 DenseBoolArrayAttr &scalableFlags, SmallVectorImpl<Type> *valueTypes,
80 DenseI64ArrayAttr &integers);
82 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
84 SmallVectorImpl<Type> *valueTypes, DenseI64ArrayAttr &integers) {
85 DenseBoolArrayAttr scalableFlags;
86 return parsePackedOrDynamicIndexList(parser, packed, packedType, values,
87 scalableFlags, valueTypes, integers);
88}
90 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
92 DenseBoolArrayAttr &scalableFlags, DenseI64ArrayAttr &integers) {
93 Type packedType;
94 return parsePackedOrDynamicIndexList(parser, packed, packedType, values,
95 scalableFlags, nullptr, integers);
96}
98 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
100 DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableFlags) {
101 return parsePackedOrDynamicIndexList(parser, packed, values, scalableFlags,
102 integers);
103}
105 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
107 DenseI64ArrayAttr &integers) {
108 DenseBoolArrayAttr scalableFlags;
109 return parsePackedOrDynamicIndexList(parser, packed, values, scalableFlags,
110 integers);
111}
112} // namespace transform
113} // namespace mlir
114
115#endif // MLIR_DIALECT_TRANSFORMS_UTILS_UTILS_H
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class implements the operand iterators for the Operation class.
Definition ValueRange.h:44
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
This class provides an abstraction over the various different ranges of value types.
Definition TypeRange.h:40
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
The state maintained across applications of various ops implementing the TransformOpInterface.
ParseResult parsePackedOrDynamicIndexList(OpAsmParser &parser, std::optional< OpAsmParser::UnresolvedOperand > &packed, Type &packedType, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, DenseBoolArrayAttr &scalableFlags, SmallVectorImpl< Type > *valueTypes, DenseI64ArrayAttr &integers)
Parser hook for custom directive in assemblyFormat.
Definition Utils.cpp:38
void printPackedOrDynamicIndexList(OpAsmPrinter &printer, Operation *op, Value packed, Type packedType, OperandRange values, TypeRange valueTypes, DenseBoolArrayAttr scalableFlags, DenseI64ArrayAttr integers)
Printer hook for custom directive in assemblyFormat.
Definition Utils.cpp:17
Include the generated interface declarations.
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
detail::DenseArrayAttrImpl< bool > DenseBoolArrayAttr