CIRCT 22.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 attribute dictionary and ensure that it contains a `name` field by
38/// inferring its value from the SSA name of the operation's first result if
39/// necessary.
40ParseResult parseImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs);
41
42/// Ensure that `attrs` contains a `name` attribute by inferring its value from
43/// the SSA name of the operation's first result if necessary. Returns true if a
44/// name was inferred, false if `attrs` already contained a `name`.
45bool inferImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs);
46
47/// Print an implicit SSA name string attribute. If the given string attribute
48/// does not match the SSA name of the operation's first result, the name is
49/// explicitly printed. Prints a leading space in front of `name` if any name is
50/// present.
51///
52/// implicit-name ::= (`name` str-attr)?
53void printImplicitSSAName(OpAsmPrinter &p, Operation *op, StringAttr attr);
54
55/// Print an attribute dictionary and elide the `name` field if its value
56/// matches the SSA name of the operation's first result.
57void printImplicitSSAName(OpAsmPrinter &p, Operation *op, DictionaryAttr attrs,
58 ArrayRef<StringRef> extraElides = {});
59
60/// Check if the `name` attribute in `attrs` matches the SSA name of the
61/// operation's first result. If it does, add `name` to `elides`. This is
62/// helpful during printing of attribute dictionaries in order to determine if
63/// the inclusion of the `name` field would be redundant.
64void elideImplicitSSAName(OpAsmPrinter &printer, Operation *op,
65 DictionaryAttr attrs,
66 SmallVectorImpl<StringRef> &elides);
67
68/// Print/parse binary operands type only when types are different.
69/// optional-bin-op-types := type($lhs) (, type($rhs))?
70void printOptionalBinaryOpTypes(OpAsmPrinter &p, Operation *op, Type lhs,
71 Type rhs);
72ParseResult parseOptionalBinaryOpTypes(OpAsmParser &parser, Type &lhs,
73 Type &rhs);
74
75//===----------------------------------------------------------------------===//
76// KeywordBool Custom Directive
77//===----------------------------------------------------------------------===//
78
79/// Parse a boolean as one of two keywords. The `trueKeyword` will result in a
80/// true boolean; the `falseKeyword` will result in a false boolean.
81///
82/// labeled-bool ::= (true-label | false-label)
83ParseResult parseKeywordBool(OpAsmParser &parser, BoolAttr &attr,
84 StringRef trueKeyword, StringRef falseKeyword);
85
86/// Print a boolean as one of two keywords. If the boolean is true, the
87/// `trueKeyword` is used; if it is false, the `falseKeyword` is used.
88///
89/// labeled-bool ::= (true-label | false-label)
90void printKeywordBool(OpAsmPrinter &printer, Operation *op, BoolAttr attr,
91 StringRef trueKeyword, StringRef falseKeyword);
92
93//===----------------------------------------------------------------------===//
94// Variadic Invertible Custom Directive
95//===----------------------------------------------------------------------===//
96
97/// Parse a variadic list of operands that may be prefixed with an optional
98/// `not` keyword. If the `not` keyword is present, the corresponding element
99/// in the `inverted` attribute is set to true; otherwise, it is set to false.
101 OpAsmParser &parser,
102 SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operands, Type &resultType,
103 mlir::DenseBoolArrayAttr &inverted, NamedAttrList &attrDict);
104
105/// Print a variadic list of operands that may be prefixed with an optional
106/// `not` keyword. If the corresponding element in `isInverted` is true, the
107/// `not` keyword is printed before the operand; otherwise, it is omitted.
108void printVariadicInvertibleOperands(OpAsmPrinter &printer, Operation *op,
109 OperandRange operands, Type resultType,
110 mlir::DenseBoolArrayAttr inverted,
111 DictionaryAttr attrDict);
112
113} // namespace circt
114
115#endif // CIRCT_SUPPORT_CUSTOMDIRECTIVEIMPL_H
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.
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 printImplicitSSAName(OpAsmPrinter &p, Operation *op, StringAttr attr)
Print an implicit SSA name string attribute.
ParseResult parseOptionalBinaryOpTypes(OpAsmParser &parser, Type &lhs, Type &rhs)