[mlir][OpFormatGen] Add initial support for regions in the custom op assembly format

This adds some initial support for regions and does not support formatting the specific arguments of a region. For now this can be achieved by using a custom directive that formats the arguments and then parses the region.

Differential Revision: https://reviews.llvm.org/D86760
This commit is contained in:
River Riddle
2020-08-31 12:33:55 -07:00
parent 24b88920fe
commit eaeadce9bd
12 changed files with 631 additions and 129 deletions

View File

@@ -1045,7 +1045,6 @@ public:
}
/// Parse an optional attribute.
/// Template utilities to simplify specifying multiple derived overloads.
template <typename AttrT>
OptionalParseResult
parseOptionalAttributeAndAddToList(AttrT &result, Type type,
@@ -1056,25 +1055,15 @@ public:
attrs.push_back(parser.builder.getNamedAttr(attrName, result));
return parseResult;
}
template <typename AttrT>
OptionalParseResult parseOptionalAttributeAndAddToList(AttrT &result,
StringRef attrName,
NamedAttrList &attrs) {
OptionalParseResult parseResult = parser.parseOptionalAttribute(result);
if (parseResult.hasValue() && succeeded(*parseResult))
attrs.push_back(parser.builder.getNamedAttr(attrName, result));
return parseResult;
}
OptionalParseResult parseOptionalAttribute(Attribute &result, Type type,
StringRef attrName,
NamedAttrList &attrs) override {
return parseOptionalAttributeAndAddToList(result, type, attrName, attrs);
}
OptionalParseResult parseOptionalAttribute(ArrayAttr &result,
OptionalParseResult parseOptionalAttribute(ArrayAttr &result, Type type,
StringRef attrName,
NamedAttrList &attrs) override {
return parseOptionalAttributeAndAddToList(result, attrName, attrs);
return parseOptionalAttributeAndAddToList(result, type, attrName, attrs);
}
/// Parse a named dictionary into 'result' if it is present.
@@ -1355,6 +1344,23 @@ public:
return parseRegion(region, arguments, argTypes, enableNameShadowing);
}
/// Parses a region if present. If the region is present, a new region is
/// allocated and placed in `region`. If no region is present, `region`
/// remains untouched.
OptionalParseResult
parseOptionalRegion(std::unique_ptr<Region> &region,
ArrayRef<OperandType> arguments, ArrayRef<Type> argTypes,
bool enableNameShadowing = false) override {
if (parser.getToken().isNot(Token::l_brace))
return llvm::None;
std::unique_ptr<Region> newRegion = std::make_unique<Region>();
if (parseRegion(*newRegion, arguments, argTypes, enableNameShadowing))
return failure();
region = std::move(newRegion);
return success();
}
/// Parse a region argument. The type of the argument will be resolved later
/// by a call to `parseRegion`.
ParseResult parseRegionArgument(OperandType &argument) override {