Add parser support for internal named attributes. These are attributes with names starting with ':'.
PiperOrigin-RevId: 235774810
This commit is contained in:
parent
bac3eece66
commit
2d4b0e2c00
|
@ -867,7 +867,7 @@ Syntax:
|
|||
``` {.ebnf}
|
||||
attribute-dict ::= `{` `}`
|
||||
| `{` attribute-entry (`,` attribute-entry)* `}`
|
||||
attribute-entry ::= bare-id `:` attribute-value
|
||||
attribute-entry ::= `:`? bare-id `:` attribute-value
|
||||
```
|
||||
|
||||
Attributes are the mechanism for specifying constant data in MLIR in places
|
||||
|
|
|
@ -1022,8 +1022,8 @@ void ModulePrinter::printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
|
|||
SmallVector<NamedAttribute, 8> filteredAttrs;
|
||||
for (auto attr : attrs) {
|
||||
auto attrName = attr.first.strref();
|
||||
// Never print attributes that start with a colon. These are internal
|
||||
// attributes that represent location or other internal metadata.
|
||||
// By default, never print attributes that start with a colon. These are
|
||||
// attributes represent location or other internal metadata.
|
||||
if (!printInternalAttributes && attrName.startswith(":"))
|
||||
return;
|
||||
|
||||
|
|
|
@ -1433,7 +1433,7 @@ ParseResult Parser::parseLocationInstance(llvm::Optional<Location> *loc) {
|
|||
///
|
||||
/// attribute-dict ::= `{` `}`
|
||||
/// | `{` attribute-entry (`,` attribute-entry)* `}`
|
||||
/// attribute-entry ::= bare-id `:` attribute-value
|
||||
/// attribute-entry ::= `:`? bare-id `:` attribute-value
|
||||
///
|
||||
ParseResult
|
||||
Parser::parseAttributeDict(SmallVectorImpl<NamedAttribute> &attributes) {
|
||||
|
@ -1441,11 +1441,17 @@ Parser::parseAttributeDict(SmallVectorImpl<NamedAttribute> &attributes) {
|
|||
return ParseFailure;
|
||||
|
||||
auto parseElt = [&]() -> ParseResult {
|
||||
// Check for an internal attribute.
|
||||
bool isInternalAttr = consumeIf(Token::colon);
|
||||
|
||||
// We allow keywords as attribute names.
|
||||
if (getToken().isNot(Token::bare_identifier, Token::inttype) &&
|
||||
!getToken().isKeyword())
|
||||
return emitError("expected attribute name");
|
||||
auto nameId = builder.getIdentifier(getTokenSpelling());
|
||||
Identifier nameId =
|
||||
isInternalAttr
|
||||
? builder.getIdentifier(Twine(":" + getTokenSpelling()).str())
|
||||
: builder.getIdentifier(getTokenSpelling());
|
||||
consumeToken();
|
||||
|
||||
if (parseToken(Token::colon, "expected ':' in attribute list"))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: mlir-opt %s | FileCheck %s
|
||||
// RUN: mlir-opt -mlir-print-internal-attributes %s | FileCheck %s
|
||||
|
||||
// CHECK-DAG: #map{{[0-9]+}} = (d0, d1, d2, d3, d4)[s0] -> (d0, d1, d2, d4, d3)
|
||||
#map0 = (d0, d1, d2, d3, d4)[s0] -> (d0, d1, d2, d4, d3)
|
||||
|
@ -802,3 +802,10 @@ func @unregistered_term(%arg0 : i1) -> i1 {
|
|||
^bb1(%arg1 : i1):
|
||||
return %arg1 : i1
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func @internal_attrs
|
||||
func @internal_attrs()
|
||||
// CHECK-NEXT: attributes {:internal.attr: 10
|
||||
attributes {:internal.attr: 10} {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue