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#include "llvm/ADT/STLExtras.h"
17
18namespace mlir {
19class OpAsmPrinter;
20
21namespace transform {
22class TransformState;
23
24/// Printer hook for custom directive in assemblyFormat.
25///
26/// custom<PackedOrDynamicIndexList>($packed, type($packed), $values,
27/// type($values), $integers)
28///
29/// where `values` are variadic Index values, `integers` is an `I64ArrayAttr`
30/// and `packed` is a single transform dialect handle who's mapped payload ops
31/// have a single Index result and represent the index list. Either `packed`
32/// or the other two parameters may be specified.
33///
34/// This allows idiomatic printing of mixed value and integer attributes in a
35/// list or with a single handle. E.g., `[%arg0 : !transform.any_op, 7, 42,
36/// %arg42 : !transform.param<i64>]` or just `%h : !transform.any_op`.
37void printPackedOrDynamicIndexList(OpAsmPrinter &printer, Operation *op,
38 Value packed, Type packedType,
39 OperandRange values, TypeRange valueTypes,
40 DenseBoolArrayAttr scalableFlags,
41 DenseI64ArrayAttr integers);
43 Value packed, Type packedType,
44 OperandRange values,
45 TypeRange valueTypes,
46 DenseI64ArrayAttr integers) {
47 printPackedOrDynamicIndexList(printer, op, packed, packedType, values,
48 valueTypes, DenseBoolArrayAttr(), integers);
49}
51 Value packed, OperandRange values,
52 DenseBoolArrayAttr scalableFlags,
53 DenseI64ArrayAttr integers) {
54 printPackedOrDynamicIndexList(printer, op, packed, Type(), values,
55 TypeRange{}, scalableFlags, integers);
56}
58 Value packed, OperandRange values,
59 DenseI64ArrayAttr integers,
60 DenseBoolArrayAttr scalableFlags) {
61 printPackedOrDynamicIndexList(printer, op, packed, values, scalableFlags,
62 integers);
63}
65 Value packed, OperandRange values,
66 DenseI64ArrayAttr integers) {
67 printPackedOrDynamicIndexList(printer, op, packed, Type(), values,
68 TypeRange{}, DenseBoolArrayAttr(), integers);
69}
70
71/// Parser hook for custom directive in assemblyFormat.
72///
73/// custom<PackedOrDynamicIndexList>($packed, type($packed), $values,
74/// type($values), $integers)
75///
76/// See `printPackedOrDynamicIndexList` for details. Overloads that do not
77/// return scalable flags reject scalable indices.
79 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
81 DenseBoolArrayAttr &scalableFlags, SmallVectorImpl<Type> *valueTypes,
82 DenseI64ArrayAttr &integers);
84 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
86 SmallVectorImpl<Type> *valueTypes, DenseI64ArrayAttr &integers) {
87 DenseBoolArrayAttr scalableFlags;
88 if (failed(parsePackedOrDynamicIndexList(parser, packed, packedType, values,
89 scalableFlags, valueTypes,
90 integers)))
91 return failure();
92 if (llvm::is_contained(scalableFlags.asArrayRef(), true))
93 return parser.emitError(parser.getNameLoc())
94 << "scalable indices are not supported";
95 return success();
96}
98 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
100 DenseBoolArrayAttr &scalableFlags, DenseI64ArrayAttr &integers) {
101 Type packedType;
102 return parsePackedOrDynamicIndexList(parser, packed, packedType, values,
103 scalableFlags, nullptr, integers);
104}
106 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
108 DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableFlags) {
109 return parsePackedOrDynamicIndexList(parser, packed, values, scalableFlags,
110 integers);
111}
113 OpAsmParser &parser, std::optional<OpAsmParser::UnresolvedOperand> &packed,
115 DenseI64ArrayAttr &integers) {
116 Type packedType;
117 return parsePackedOrDynamicIndexList(parser, packed, packedType, values,
118 /*valueTypes=*/nullptr, integers);
119}
120} // namespace transform
121} // namespace mlir
122
123#endif // MLIR_DIALECT_TRANSFORMS_UTILS_UTILS_H
return success()
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
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