forked from OSchip/llvm-project
[mlir] Introduce DefaultValuedOptionalAttr
Currently DefaultValuedAttr is confusingly actually default valued & optional but that was an artifact of development and longstanding TODO to address. Add new attribute that matches this behavior for cases where that is actually the desired behavior before addressing TODO (e.g., this is an incremental step to fixing DefaultValuedAttr). Differential Revision: https://reviews.llvm.org/D130679
This commit is contained in:
parent
5c38056431
commit
af3ed4a2a7
|
@ -967,6 +967,24 @@ class DefaultValuedAttr<Attr attr, string val> :
|
|||
let baseAttr = attr;
|
||||
}
|
||||
|
||||
// Decorates an optional attribute to have an (unvalidated) default value
|
||||
// return by ODS generated accessors if not present.
|
||||
class DefaultValuedOptionalAttr<Attr attr, string val> :
|
||||
Attr<attr.predicate, attr.summary> {
|
||||
// Construct this attribute with the input attribute and change only
|
||||
// the default value.
|
||||
// Note: this has to be kept up to date with Attr above.
|
||||
let storageType = attr.storageType;
|
||||
let returnType = attr.returnType;
|
||||
let convertFromStorage = attr.convertFromStorage;
|
||||
let constBuilderCall = attr.constBuilderCall;
|
||||
let defaultValue = val;
|
||||
let valueType = attr.valueType;
|
||||
let isOptional = 1;
|
||||
|
||||
let baseAttr = attr;
|
||||
}
|
||||
|
||||
// Decorates an attribute as optional. The return type of the generated
|
||||
// attribute accessor method will be Optional<>.
|
||||
class OptionalAttr<Attr attr> : Attr<attr.predicate, attr.summary> {
|
||||
|
|
|
@ -158,7 +158,7 @@ def Test2_Dialect : Dialect {
|
|||
def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
|
||||
let arguments = (ins
|
||||
SomeAttr:$aAttr,
|
||||
DefaultValuedAttr<SomeAttr, "4.2">:$bAttr,
|
||||
DefaultValuedOptionalAttr<SomeAttr, "4.2">:$bAttr,
|
||||
OptionalAttr<SomeAttr>:$cAttr
|
||||
);
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
|
|||
// DEF-NEXT: odsState.addAttribute(getCAttrAttrName(odsState.name), cAttr);
|
||||
|
||||
// DEF: void AgetOp::build(
|
||||
// DEF: some-return-type aAttr, some-return-type bAttr, /*optional*/some-attr-kind cAttr
|
||||
// DEF: some-return-type aAttr, /*optional*/some-return-type bAttr, /*optional*/some-attr-kind cAttr
|
||||
// DEF: odsState.addAttribute(getAAttrAttrName(odsState.name), some-const-builder-call(odsBuilder, aAttr));
|
||||
|
||||
// DEF: void AgetOp::build(
|
||||
|
|
Loading…
Reference in New Issue