[mlir][EmitC] Remove the type from the OpaqueAttr
This removes the type from EmitC's opaque attribute. The value provided as a StringRefParameter can always be emitted as is. In consquence the constant and variable ops explicitly need to opaque attributes which are no longer typed attributes. Co-authored-by: Simon Camphausen <simon.camphausen@iml.fraunhofer.de> Reviewed By: Mogball, jpienaar Differential Revision: https://reviews.llvm.org/D131666
This commit is contained in:
parent
13c1e7a8aa
commit
90736babca
|
@ -139,7 +139,7 @@ def EmitC_ConstantOp : EmitC_Op<"constant", [ConstantLike]> {
|
|||
```
|
||||
}];
|
||||
|
||||
let arguments = (ins TypedAttrInterface:$value);
|
||||
let arguments = (ins EmitC_OpaqueOrTypedAttr:$value);
|
||||
let results = (outs AnyType);
|
||||
|
||||
let hasFolder = 1;
|
||||
|
@ -212,7 +212,7 @@ def EmitC_VariableOp : EmitC_Op<"variable", []> {
|
|||
```
|
||||
}];
|
||||
|
||||
let arguments = (ins TypedAttrInterface:$value);
|
||||
let arguments = (ins EmitC_OpaqueOrTypedAttr:$value);
|
||||
let results = (outs AnyType);
|
||||
|
||||
let hasVerifier = 1;
|
||||
|
|
|
@ -26,7 +26,7 @@ class EmitC_Attr<string name, string attrMnemonic, list<Trait> traits = []>
|
|||
let mnemonic = attrMnemonic;
|
||||
}
|
||||
|
||||
def EmitC_OpaqueAttr : EmitC_Attr<"Opaque", "opaque", [TypedAttrInterface]> {
|
||||
def EmitC_OpaqueAttr : EmitC_Attr<"Opaque", "opaque"> {
|
||||
let summary = "An opaque attribute";
|
||||
|
||||
let description = [{
|
||||
|
@ -41,10 +41,11 @@ def EmitC_OpaqueAttr : EmitC_Attr<"Opaque", "opaque", [TypedAttrInterface]> {
|
|||
```
|
||||
}];
|
||||
|
||||
let parameters = (ins "Type":$type,
|
||||
StringRefParameter<"the opaque value">:$value);
|
||||
let parameters = (ins StringRefParameter<"the opaque value">:$value);
|
||||
|
||||
let hasCustomAssemblyFormat = 1;
|
||||
}
|
||||
|
||||
def EmitC_OpaqueOrTypedAttr : AnyAttrOf<[EmitC_OpaqueAttr, TypedAttrInterface]>;
|
||||
|
||||
#endif // MLIR_DIALECT_EMITC_IR_EMITCATTRIBUTES
|
||||
|
|
|
@ -118,6 +118,9 @@ LogicalResult emitc::CallOp::verify() {
|
|||
|
||||
/// The constant op requires that the attribute's type matches the return type.
|
||||
LogicalResult emitc::ConstantOp::verify() {
|
||||
if (getValueAttr().isa<emitc::OpaqueAttr>())
|
||||
return success();
|
||||
|
||||
TypedAttr value = getValueAttr();
|
||||
Type type = getType();
|
||||
if (!value.getType().isa<NoneType>() && type != value.getType())
|
||||
|
@ -172,6 +175,9 @@ ParseResult IncludeOp::parse(OpAsmParser &parser, OperationState &result) {
|
|||
|
||||
/// The variable op requires that the attribute's type matches the return type.
|
||||
LogicalResult emitc::VariableOp::verify() {
|
||||
if (getValueAttr().isa<emitc::OpaqueAttr>())
|
||||
return success();
|
||||
|
||||
TypedAttr value = getValueAttr();
|
||||
Type type = getType();
|
||||
if (!value.getType().isa<NoneType>() && type != value.getType())
|
||||
|
@ -206,8 +212,7 @@ Attribute emitc::OpaqueAttr::parse(AsmParser &parser, Type type) {
|
|||
if (parser.parseGreater())
|
||||
return Attribute();
|
||||
|
||||
return get(parser.getContext(),
|
||||
type ? type : NoneType::get(parser.getContext()), value);
|
||||
return get(parser.getContext(), value);
|
||||
}
|
||||
|
||||
void emitc::OpaqueAttr::print(AsmPrinter &printer) const {
|
||||
|
|
|
@ -7,7 +7,7 @@ func.func @emitc_constant() {
|
|||
%c2 = "emitc.constant"(){value = -1 : i32} : () -> i32
|
||||
%c3 = "emitc.constant"(){value = -1 : si8} : () -> si8
|
||||
%c4 = "emitc.constant"(){value = 255 : ui8} : () -> ui8
|
||||
%c5 = "emitc.constant"(){value = #emitc.opaque<"CHAR_MIN"> : !emitc.opaque<"char">} : () -> !emitc.opaque<"char">
|
||||
%c5 = "emitc.constant"(){value = #emitc.opaque<"CHAR_MIN">} : () -> !emitc.opaque<"char">
|
||||
return
|
||||
}
|
||||
// CPP-DEFAULT: void emitc_constant() {
|
||||
|
|
|
@ -7,8 +7,8 @@ func.func @emitc_variable() {
|
|||
%c2 = "emitc.variable"(){value = -1 : i32} : () -> i32
|
||||
%c3 = "emitc.variable"(){value = -1 : si8} : () -> si8
|
||||
%c4 = "emitc.variable"(){value = 255 : ui8} : () -> ui8
|
||||
%c5 = "emitc.variable"(){value = #emitc.opaque<""> : !emitc.ptr<i32>} : () -> !emitc.ptr<i32>
|
||||
%c6 = "emitc.variable"(){value = #emitc.opaque<"NULL"> : !emitc.ptr<i32>} : () -> !emitc.ptr<i32>
|
||||
%c5 = "emitc.variable"(){value = #emitc.opaque<"">} : () -> !emitc.ptr<i32>
|
||||
%c6 = "emitc.variable"(){value = #emitc.opaque<"NULL">} : () -> !emitc.ptr<i32>
|
||||
return
|
||||
}
|
||||
// CPP-DEFAULT: void emitc_variable() {
|
||||
|
|
Loading…
Reference in New Issue