CIRCT 24.0.0git
Loading...
Searching...
No Matches
CustomDirectiveImpl.h
Go to the documentation of this file.
1//===- CustomDirectiveImpl.h - Custom TableGen directives -------*- 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// This file provides common custom directives for table-gen assembly formats.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_SUPPORT_CUSTOMDIRECTIVEIMPL_H
14#define CIRCT_SUPPORT_CUSTOMDIRECTIVEIMPL_H
15
16#include "circt/Support/LLVM.h"
17#include "mlir/IR/Builders.h"
18#include "mlir/IR/BuiltinAttributes.h"
19#include "mlir/IR/OpImplementation.h"
20#include "mlir/IR/OperationSupport.h"
21#include "mlir/IR/TypeRange.h"
22#include "mlir/IR/Types.h"
23
24namespace circt {
25
26//===----------------------------------------------------------------------===//
27// ImplicitSSAName Custom Directive
28//===----------------------------------------------------------------------===//
29
30/// Parse an implicit SSA name string attribute. If the name is not provided in
31/// the input text, its value is inferred from the SSA name of the operation's
32/// first result.
33///
34/// implicit-name ::= (`name` str-attr)?
35ParseResult parseImplicitSSAName(OpAsmParser &parser, StringAttr &attr);
36
37/// Parse an array of implicit SSA name string attributes. Each name is inferred
38/// from the corresponding SSA name of the operation's results.
39ParseResult parseImplicitSSANames(OpAsmParser &parser, ArrayAttr &attr);
40
41/// Parse an attribute dictionary and ensure that it contains a `name` field by
42/// inferring its value from the SSA name of the operation's first result if
43/// necessary.
44ParseResult parseImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs);
45
46/// Ensure that `attrs` contains a `name` attribute by inferring its value from
47/// the SSA name of the operation's first result if necessary. Returns true if a
48/// name was inferred, false if `attrs` already contained a `name`.
49bool inferImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs);
50
51/// Print an implicit SSA name string attribute. If the given string attribute
52/// does not match the SSA name of the operation's first result, the name is
53/// explicitly printed. Prints a leading space in front of `name` if any name is
54/// present.
55///
56/// implicit-name ::= (`name` str-attr)?
57void printImplicitSSAName(OpAsmPrinter &p, Operation *op, StringAttr attr);
58
59/// Print an array of implicit SSA name string attributes. The names are
60/// represented by the SSA result names and therefore require no additional
61/// output.
62void printImplicitSSANames(OpAsmPrinter &p, Operation *op, ArrayAttr attr);
63
64/// Print an attribute dictionary and elide the `name` field if its value
65/// matches the SSA name of the operation's first result.
66void printImplicitSSAName(OpAsmPrinter &p, Operation *op, DictionaryAttr attrs,
67 ArrayRef<StringRef> extraElides = {});
68
69/// Check if the `name` attribute in `attrs` matches the SSA name of the
70/// operation's first result. If it does, add `name` to `elides`. This is
71/// helpful during printing of attribute dictionaries in order to determine if
72/// the inclusion of the `name` field would be redundant.
73void elideImplicitSSAName(OpAsmPrinter &printer, Operation *op,
74 DictionaryAttr attrs,
75 SmallVectorImpl<StringRef> &elides);
76
77/// Print/parse binary operands type only when types are different.
78/// optional-bin-op-types := type($lhs) (, type($rhs))?
79void printOptionalBinaryOpTypes(OpAsmPrinter &p, Operation *op, Type lhs,
80 Type rhs);
81ParseResult parseOptionalBinaryOpTypes(OpAsmParser &parser, Type &lhs,
82 Type &rhs);
83
84//===----------------------------------------------------------------------===//
85// KeywordBool Custom Directive
86//===----------------------------------------------------------------------===//
87
88/// Parse a boolean as one of two keywords. The `trueKeyword` will result in a
89/// true boolean; the `falseKeyword` will result in a false boolean.
90///
91/// labeled-bool ::= (true-label | false-label)
92ParseResult parseKeywordBool(OpAsmParser &parser, BoolAttr &attr,
93 StringRef trueKeyword, StringRef falseKeyword);
94
95/// Print a boolean as one of two keywords. If the boolean is true, the
96/// `trueKeyword` is used; if it is false, the `falseKeyword` is used.
97///
98/// labeled-bool ::= (true-label | false-label)
99void printKeywordBool(OpAsmPrinter &printer, Operation *op, BoolAttr attr,
100 StringRef trueKeyword, StringRef falseKeyword);
101
102//===----------------------------------------------------------------------===//
103// Variadic Invertible Custom Directive
104//===----------------------------------------------------------------------===//
105
106/// Parse a variadic list of operands that may be prefixed with an optional
107/// `not` keyword. If the `not` keyword is present, the corresponding element
108/// in the `inverted` attribute is set to true; otherwise, it is set to false.
110 OpAsmParser &parser,
111 SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operands, Type &resultType,
112 mlir::DenseBoolArrayAttr &inverted, NamedAttrList &attrDict);
113
114/// Print a variadic list of operands that may be prefixed with an optional
115/// `not` keyword. If the corresponding element in `isInverted` is true, the
116/// `not` keyword is printed before the operand; otherwise, it is omitted.
117void printVariadicInvertibleOperands(OpAsmPrinter &printer, Operation *op,
118 OperandRange operands, Type resultType,
119 mlir::DenseBoolArrayAttr inverted,
120 DictionaryAttr attrDict);
121
122} // namespace circt
123
124#endif // CIRCT_SUPPORT_CUSTOMDIRECTIVEIMPL_H
NamedAttrList attrs
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
ParseResult parseVariadicInvertibleOperands(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &operands, Type &resultType, mlir::DenseBoolArrayAttr &inverted, NamedAttrList &attrDict)
Parse a variadic list of operands that may be prefixed with an optional not keyword.
ParseResult parseKeywordBool(OpAsmParser &parser, BoolAttr &attr, StringRef trueKeyword, StringRef falseKeyword)
Parse a boolean as one of two keywords.
void printOptionalBinaryOpTypes(OpAsmPrinter &p, Operation *op, Type lhs, Type rhs)
Print/parse binary operands type only when types are different.
ParseResult parseImplicitSSANames(OpAsmParser &parser, ArrayAttr &attr)
Parse an array of implicit SSA name string attributes.
void elideImplicitSSAName(OpAsmPrinter &printer, Operation *op, DictionaryAttr attrs, SmallVectorImpl< StringRef > &elides)
Check if the name attribute in attrs matches the SSA name of the operation's first result.
void printVariadicInvertibleOperands(OpAsmPrinter &printer, Operation *op, OperandRange operands, Type resultType, mlir::DenseBoolArrayAttr inverted, DictionaryAttr attrDict)
Print a variadic list of operands that may be prefixed with an optional not keyword.
ParseResult parseImplicitSSAName(OpAsmParser &parser, StringAttr &attr)
Parse an implicit SSA name string attribute.
void printKeywordBool(OpAsmPrinter &printer, Operation *op, BoolAttr attr, StringRef trueKeyword, StringRef falseKeyword)
Print a boolean as one of two keywords.
bool inferImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs)
Ensure that attrs contains a name attribute by inferring its value from the SSA name of the operation...
void printImplicitSSANames(OpAsmPrinter &p, Operation *op, ArrayAttr attr)
Print an array of implicit SSA name string attributes.
void printImplicitSSAName(OpAsmPrinter &p, Operation *op, StringAttr attr)
Print an implicit SSA name string attribute.
ParseResult parseOptionalBinaryOpTypes(OpAsmParser &parser, Type &lhs, Type &rhs)