From 9cc4fdcaa8f5fe3d65f991ce27e17b22d098063c Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Mon, 30 Aug 2021 19:09:50 +0000 Subject: [PATCH] Update iree-dialects to IREE 7d9e4909f5524e275726b2754d3ad050818d56ae --- external/iree-dialects/BUILD | 3 + .../build_tools/build_standalone.sh | 0 .../iree-dialects/Dialect/IREE/IREEBase.td | 4 +- .../iree-dialects/Dialect/IREE/IREEDialect.td | 2 +- .../iree-dialects/Dialect/IREE/IREEOps.td | 95 +++++++++++-------- .../lib/Dialect/IREE/IREEOps.cpp | 75 +++++++++++++++ 6 files changed, 134 insertions(+), 45 deletions(-) mode change 100644 => 100755 external/iree-dialects/build_tools/build_standalone.sh diff --git a/external/iree-dialects/BUILD b/external/iree-dialects/BUILD index dc824479c..429aab784 100644 --- a/external/iree-dialects/BUILD +++ b/external/iree-dialects/BUILD @@ -2,6 +2,7 @@ load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library") package( default_visibility = ["//visibility:public"], + features = ["layering_check"], licenses = ["notice"], ) @@ -65,7 +66,9 @@ cc_library( includes = ["include"], deps = [ ":IREEOpsIncGen", + "@llvm-project//llvm:Support", "@llvm-project//mlir:IR", + "@llvm-project//mlir:Support", ], ) diff --git a/external/iree-dialects/build_tools/build_standalone.sh b/external/iree-dialects/build_tools/build_standalone.sh old mode 100644 new mode 100755 diff --git a/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEBase.td b/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEBase.td index 09e655ea4..3194b5147 100644 --- a/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEBase.td +++ b/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEBase.td @@ -92,8 +92,8 @@ def IREE_Dims : Variadic; def IREE_Shape : Variadic; def IREE_ShapeDynamicDims : Variadic; -def IREE_VariableRefAttr : IREE_AliasedSymbolRefAttr; -def IREE_VariablePtr : IREE_AnyPtrOf<[IREE_Tensor, IREE_PrimitiveType]>; +def IREE_GlobalRefAttr : IREE_AliasedSymbolRefAttr; +def IREE_AnyGlobalPtr : IREE_AnyPtrOf<[IREE_Tensor, IREE_PrimitiveType]>; class IREE_IndexAttrBase : TypedAttrBase< diff --git a/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEDialect.td b/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEDialect.td index d9740ae0f..691359aaf 100644 --- a/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEDialect.td +++ b/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEDialect.td @@ -95,7 +95,7 @@ def IREE_PtrType : IREE_Type<"Ptr"> { let parameters = (ins IREE_PtrTargetTypeParameter:$targetType); let printer = [{ - $_printer << "list<" << getTargetType() << ">"; + $_printer << "ptr<" << getTargetType() << ">"; }]; let parser = [{ diff --git a/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEOps.td b/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEOps.td index 608353bca..f937ef7d6 100644 --- a/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEOps.td +++ b/external/iree-dialects/include/iree-dialects/Dialect/IREE/IREEOps.td @@ -30,7 +30,7 @@ def IREE_NullOp : IREE_PureOp<"null"> { // Casts //===----------------------------------------------------------------------===// -def IREE_TensorToBufferView : IREE_PureOp<"cast.tensor_to_buffer_view"> { +def IREE_TensorToBufferViewOp : IREE_PureOp<"cast.tensor_to_buffer_view"> { let summary = "Casts a tensor to a BufferView, capturing dynamic dims"; let arguments = (ins IREE_Tensor:$source, @@ -44,7 +44,7 @@ def IREE_TensorToBufferView : IREE_PureOp<"cast.tensor_to_buffer_view"> { }]; } -def IREE_BufferViewToTensor : IREE_PureOp<"cast.buffer_view_to_tensor"> { +def IREE_BufferViewToTensorOp : IREE_PureOp<"cast.buffer_view_to_tensor"> { let summary = "Casts a BufferView to a tensor, providing dynamic dims"; let arguments = (ins IREE_BufferViewType:$source, @@ -62,108 +62,120 @@ def IREE_BufferViewToTensor : IREE_PureOp<"cast.buffer_view_to_tensor"> { // Global variables //===----------------------------------------------------------------------===// -def IREE_VariableOp : IREE_Op<"variable", [ +def IREE_GlobalOp : IREE_Op<"global", [ Symbol, ]> { - let summary = [{stateful variable declaration}]; + let summary = [{stateful global variable declaration}]; let description = [{ - Declares a persistent variable that maintains its value. + Declares a global variable that maintains its value across invocations. + The value is tied to the execution context of the module and different + contexts will have different global storage. }]; let arguments = (ins - StrAttr:$sym_name, + OptionalAttr:$sym_visibility, + SymbolNameAttr:$sym_name, TypeAttr:$type, UnitAttr:$is_mutable, OptionalAttr:$initializer, OptionalAttr:$initial_value ); - let skipDefaultBuilders = 1; - let builders = [ - OpBuilder<(ins "StringRef":$name, "bool":$isMutable, - "FuncOp":$initializer, CArg<"ArrayRef", "{}">:$attrs)>, - OpBuilder<(ins "StringRef":$name, "bool":$isMutable, "Type":$type, - "Attribute":$initialValue, CArg<"ArrayRef", "{}">:$attrs)>, - OpBuilder<(ins "StringRef":$name, "bool":$isMutable, "Type":$type, - CArg<"ArrayRef", "{}">:$attrs)>, - ]; + let assemblyFormat = [{ + custom($sym_visibility) + (`mutable` $is_mutable^)? + $sym_name + attr-dict + (`initializer` `(` $initializer^ `)`):(``)? + custom($type, $initial_value) + }]; } -def IREE_VariableAddressOp : IREE_PureOp<"variable.address"> { - let summary = [{returns an address reference to a variable}]; +def IREE_GlobalAddressOp : IREE_PureOp<"global.address"> { + let summary = [{returns an address reference to a global}]; let description = [{ - Returns the address of a variable as a typed reference. Can be used with the - variable load and store indirect ops. + Returns the address of a global as a typed reference. Can be used with the + global load and store indirect ops. }]; let arguments = (ins - IREE_VariableRefAttr:$variable + IREE_GlobalRefAttr:$global ); let results = (outs - IREE_VariablePtr:$result + IREE_AnyGlobalPtr:$result ); - let assemblyFormat = "$variable attr-dict `:` type($result)"; + let assemblyFormat = [{ + $global attr-dict `:` type($result) + }]; } -def IREE_VariableLoadOp : IREE_Op<"variable.load"> { +def IREE_GlobalLoadOp : IREE_Op<"global.load"> { let summary = [{loads a value from a global variable}]; let description = [{ - Returns a copy of the variable value. + Returns a copy of the global value. }]; let arguments = (ins - IREE_VariableRefAttr:$variable + IREE_GlobalRefAttr:$global ); let results = (outs AnyType:$result ); - let assemblyFormat = "$variable attr-dict `:` type($result)"; + let assemblyFormat = [{ + $global attr-dict `:` type($result) + }]; } -def IREE_VariableLoadIndirectOp : IREE_Op<"variable.load.indirect"> { +def IREE_GlobalLoadIndirectOp : IREE_Op<"global.load.indirect"> { let summary = [{loads a value from a global variable}]; let description = [{ - Returns a copy of the variable value. + Returns a copy of the global value. }]; let arguments = (ins - IREE_VariablePtr:$variable + IREE_AnyGlobalPtr:$global ); let results = (outs AnyType:$result ); - let assemblyFormat = "$variable attr-dict `:` type($variable) `->` type($result)"; + let assemblyFormat = [{ + $global attr-dict `:` type($global) `->` type($result) + }]; } -def IREE_VariableStoreOp : IREE_Op<"variable.store"> { +def IREE_GlobalStoreOp : IREE_Op<"global.store"> { let summary = [{stores a value into a global variable}]; let description = [{ - Stores a copy of the value into a variable. + Stores a copy of the value into a global. }]; let arguments = (ins AnyType:$value, - IREE_VariableRefAttr:$variable + IREE_GlobalRefAttr:$global ); - let assemblyFormat = "$value `,` $variable attr-dict `:` type($value)"; + let assemblyFormat = [{ + $value `,` $global attr-dict `:` type($value) + }]; } -def IREE_VariableStoreIndirectOp : IREE_Op<"variable.store.indirect"> { +def IREE_GlobalStoreIndirectOp : IREE_Op<"global.store.indirect"> { let summary = [{stores a value into a global variable}]; let description = [{ - Stores a copy of the value into a variable. + Stores a copy of the value into a global. }]; let arguments = (ins AnyType:$value, - IREE_VariablePtr:$variable + IREE_AnyGlobalPtr:$global ); - let assemblyFormat = "$value `,` $variable attr-dict `:` type($value) `->` type($variable)"; + let assemblyFormat = [{ + $value `,` $global attr-dict `:` type($value) `->` type($global) + }]; } //===----------------------------------------------------------------------===// @@ -472,8 +484,7 @@ def IREE_TensorUpdateOp : IREE_PureOp<"tensor.update", [ IREE_ShapeDynamicDims:$target_dims, Variadic:$start_indices, IREE_Tensor:$update, - IREE_ShapeDynamicDims:$update_dims, - OptionalAttr:$tied_operands + IREE_ShapeDynamicDims:$update_dims ); let results = (outs IREE_Tensor:$result @@ -482,7 +493,7 @@ def IREE_TensorUpdateOp : IREE_PureOp<"tensor.update", [ let assemblyFormat = [{ $update `,` $target `[` $start_indices `]` `:` type($update) (`{` $update_dims^ `}`)? `->` - `(` type($result) `,` $target_dims `,` $tied_operands `)` + type($result) (`{` $target_dims^ `}`)? attr-dict-with-keyword }]; @@ -508,7 +519,7 @@ def IREE_TensorTraceOp : IREE_Op<"tensor.trace", []> { Variadic:$operands ); - let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?"; + let assemblyFormat = "$key attr-dict ($operands^ `:` type($operands))?"; } #endif // IREE_LLVM_EXTERNAL_PROJECTS_IREE_DIALECTS_DIALECT_IREE_IREE_OPS_TD diff --git a/external/iree-dialects/lib/Dialect/IREE/IREEOps.cpp b/external/iree-dialects/lib/Dialect/IREE/IREEOps.cpp index 2a127515c..a723b58db 100644 --- a/external/iree-dialects/lib/Dialect/IREE/IREEOps.cpp +++ b/external/iree-dialects/lib/Dialect/IREE/IREEOps.cpp @@ -15,5 +15,80 @@ using namespace mlir; using namespace mlir::iree; +//===----------------------------------------------------------------------===// +// custom($sym_visibility) +//===----------------------------------------------------------------------===// +// some.op custom($sym_visibility) $sym_name +// -> +// some.op @foo +// some.op private @foo + +static ParseResult parseSymbolVisibility(OpAsmParser &parser, + StringAttr &symVisibilityAttr) { + StringRef symVisibility; + parser.parseOptionalKeyword(&symVisibility, {"public", "private", "nested"}); + if (!symVisibility.empty()) { + symVisibilityAttr = parser.getBuilder().getStringAttr(symVisibility); + } + return success(); +} + +static void printSymbolVisibility(OpAsmPrinter &p, Operation *op, + StringAttr symVisibilityAttr) { + if (!symVisibilityAttr) { + p << "public"; + } else { + p << symVisibilityAttr.getValue(); + } +} + +//===----------------------------------------------------------------------===// +// custom($type, $attr) +//===----------------------------------------------------------------------===// +// some.op custom($type, $attr) +// -> +// some.op : i32 +// some.op = 42 : i32 +// some.op : i32 = 42 : index + +static ParseResult parseTypeOrAttr(OpAsmParser &parser, TypeAttr &typeAttr, + Attribute &attr) { + if (succeeded(parser.parseOptionalEqual())) { + if (failed(parser.parseAttribute(attr))) { + return parser.emitError(parser.getCurrentLocation()) + << "expected attribute"; + } + typeAttr = TypeAttr::get(attr.getType()); + return success(); + } + + Type type; + if (failed(parser.parseColonType(type))) { + return parser.emitError(parser.getCurrentLocation()) << "expected type"; + } + typeAttr = TypeAttr::get(type); + + if (succeeded(parser.parseOptionalEqual())) { + if (failed(parser.parseAttribute(attr))) { + return parser.emitError(parser.getCurrentLocation()) + << "expected attribute"; + } + } + + return success(); +} + +static void printTypeOrAttr(OpAsmPrinter &p, Operation *op, TypeAttr type, + Attribute attr) { + if (!attr || attr.getType() != type.getValue()) { + p << " : "; + p.printAttribute(type); + } + if (attr) { + p << " = "; + p.printAttribute(attr); + } +} + #define GET_OP_CLASSES #include "iree-dialects/Dialect/IREE/IREEOps.cpp.inc"