CIRCT 20.0.0git
Loading...
Searching...
No Matches
SSPAttributes.cpp
Go to the documentation of this file.
1//===- SSPAttributes.cpp - SSP attribute implementation -------------------===//
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 implements the SSP (static scheduling problem) dialect attributes.
10//
11//===----------------------------------------------------------------------===//
12
15
16#include "mlir/IR/Builders.h"
17#include "mlir/IR/DialectImplementation.h"
18
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/TypeSwitch.h"
21
22using namespace circt;
23using namespace ssp;
24
25#define GET_ATTRDEF_CLASSES
26#include "circt/Dialect/SSP/SSPAttributes.cpp.inc"
27
28void SSPDialect::registerAttributes() {
29 addAttributes<
30#define GET_ATTRDEF_LIST
31#include "circt/Dialect/SSP/SSPAttributes.cpp.inc"
32 >();
33}
34
35mlir::OptionalParseResult
36ssp::parseOptionalPropertyArray(ArrayAttr &attr, AsmParser &parser,
37 ArrayRef<Attribute> alreadyParsed) {
38 auto &builder = parser.getBuilder();
39
40 if (parser.parseOptionalLSquare()) {
41 if (!alreadyParsed.empty()) {
42 attr = builder.getArrayAttr(alreadyParsed);
43 return success();
44 }
45 return {};
46 }
47
48 SmallVector<Attribute> elements;
49 elements.append(alreadyParsed.begin(), alreadyParsed.end());
50
51 auto parseListResult = parser.parseCommaSeparatedList([&]() -> ParseResult {
52 Attribute elem;
53
54 // Try to parse a generic attribute.
55 auto parseGenericAttrResult = parser.parseOptionalAttribute(elem);
56 if (parseGenericAttrResult.has_value()) {
57 if (failed(*parseGenericAttrResult))
58 return failure();
59
60 elements.push_back(elem);
61 return success();
62 }
63
64 // Try to parse one of the built-in SSP property attributes.
65 StringRef mnemonic;
66 auto parseShortformAttrResult =
67 generatedAttributeParser(parser, &mnemonic, Type(), elem);
68
69 if (!parseShortformAttrResult.has_value()) {
70 return parser.emitError(parser.getCurrentLocation(),
71 "carries unknown shortform property: ")
72 << mnemonic;
73 }
74
75 if (failed(*parseShortformAttrResult))
76 return failure();
77
78 elements.push_back(elem);
79 return success();
80 });
81
82 if (parseListResult || parser.parseRSquare())
83 return failure();
84
85 attr = builder.getArrayAttr(elements);
86 return success();
87}
88
89void ssp::printPropertyArray(ArrayAttr attr, AsmPrinter &p,
90 ArrayRef<Attribute> alreadyPrinted) {
91 auto elementsToPrint =
92 llvm::make_filter_range(attr.getAsRange<Attribute>(), [&](Attribute a) {
93 return !llvm::is_contained(alreadyPrinted, a);
94 });
95 if (elementsToPrint.empty())
96 return;
97
98 p << '[';
99 llvm::interleaveComma(elementsToPrint, p, [&](Attribute elem) {
100 // Try to emit the shortform for the built-in SSP property attributes, and
101 // if that fails, fall back to the generic form.
102 if (failed(generatedAttributePrinter(elem, p)))
103 p.printAttribute(attr);
104 });
105 p << ']';
106}
void printPropertyArray(ArrayAttr attr, AsmPrinter &p, ArrayRef< Attribute > alreadyPrinted={})
Print an array attribute, suppressing the #ssp.
mlir::OptionalParseResult parseOptionalPropertyArray(ArrayAttr &attr, AsmParser &parser, ArrayRef< Attribute > alreadyParsed={})
Parse an array of attributes while recognizing the properties of the SSP dialect even without a #ssp.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.