Update iree-dialects to IREE 7d9e4909f5524e275726b2754d3ad050818d56ae

pull/298/head
Sean Silva 2021-08-30 19:09:50 +00:00
parent 3b0e5910a8
commit 9cc4fdcaa8
6 changed files with 134 additions and 45 deletions

View File

@ -2,6 +2,7 @@ load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")
package( package(
default_visibility = ["//visibility:public"], default_visibility = ["//visibility:public"],
features = ["layering_check"],
licenses = ["notice"], licenses = ["notice"],
) )
@ -65,7 +66,9 @@ cc_library(
includes = ["include"], includes = ["include"],
deps = [ deps = [
":IREEOpsIncGen", ":IREEOpsIncGen",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:IR", "@llvm-project//mlir:IR",
"@llvm-project//mlir:Support",
], ],
) )

View File

View File

@ -92,8 +92,8 @@ def IREE_Dims : Variadic<IREE_Dim>;
def IREE_Shape : Variadic<IREE_Dim>; def IREE_Shape : Variadic<IREE_Dim>;
def IREE_ShapeDynamicDims : Variadic<IREE_Dim>; def IREE_ShapeDynamicDims : Variadic<IREE_Dim>;
def IREE_VariableRefAttr : IREE_AliasedSymbolRefAttr; def IREE_GlobalRefAttr : IREE_AliasedSymbolRefAttr;
def IREE_VariablePtr : IREE_AnyPtrOf<[IREE_Tensor, IREE_PrimitiveType]>; def IREE_AnyGlobalPtr : IREE_AnyPtrOf<[IREE_Tensor, IREE_PrimitiveType]>;
class IREE_IndexAttrBase<string descr> : class IREE_IndexAttrBase<string descr> :
TypedAttrBase< TypedAttrBase<

View File

@ -95,7 +95,7 @@ def IREE_PtrType : IREE_Type<"Ptr"> {
let parameters = (ins IREE_PtrTargetTypeParameter:$targetType); let parameters = (ins IREE_PtrTargetTypeParameter:$targetType);
let printer = [{ let printer = [{
$_printer << "list<" << getTargetType() << ">"; $_printer << "ptr<" << getTargetType() << ">";
}]; }];
let parser = [{ let parser = [{

View File

@ -30,7 +30,7 @@ def IREE_NullOp : IREE_PureOp<"null"> {
// Casts // 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 summary = "Casts a tensor to a BufferView, capturing dynamic dims";
let arguments = (ins let arguments = (ins
IREE_Tensor:$source, 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 summary = "Casts a BufferView to a tensor, providing dynamic dims";
let arguments = (ins let arguments = (ins
IREE_BufferViewType:$source, IREE_BufferViewType:$source,
@ -62,108 +62,120 @@ def IREE_BufferViewToTensor : IREE_PureOp<"cast.buffer_view_to_tensor"> {
// Global variables // Global variables
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def IREE_VariableOp : IREE_Op<"variable", [ def IREE_GlobalOp : IREE_Op<"global", [
Symbol, Symbol,
]> { ]> {
let summary = [{stateful variable declaration}]; let summary = [{stateful global variable declaration}];
let description = [{ 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 let arguments = (ins
StrAttr:$sym_name, OptionalAttr<StrAttr>:$sym_visibility,
SymbolNameAttr:$sym_name,
TypeAttr:$type, TypeAttr:$type,
UnitAttr:$is_mutable, UnitAttr:$is_mutable,
OptionalAttr<FlatSymbolRefAttr>:$initializer, OptionalAttr<FlatSymbolRefAttr>:$initializer,
OptionalAttr<AnyAttr>:$initial_value OptionalAttr<AnyAttr>:$initial_value
); );
let skipDefaultBuilders = 1; let assemblyFormat = [{
let builders = [ custom<SymbolVisibility>($sym_visibility)
OpBuilder<(ins "StringRef":$name, "bool":$isMutable, (`mutable` $is_mutable^)?
"FuncOp":$initializer, CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>, $sym_name
OpBuilder<(ins "StringRef":$name, "bool":$isMutable, "Type":$type, attr-dict
"Attribute":$initialValue, CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>, (`initializer` `(` $initializer^ `)`):(``)?
OpBuilder<(ins "StringRef":$name, "bool":$isMutable, "Type":$type, custom<TypeOrAttr>($type, $initial_value)
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>, }];
];
} }
def IREE_VariableAddressOp : IREE_PureOp<"variable.address"> { def IREE_GlobalAddressOp : IREE_PureOp<"global.address"> {
let summary = [{returns an address reference to a variable}]; let summary = [{returns an address reference to a global}];
let description = [{ let description = [{
Returns the address of a variable as a typed reference. Can be used with the Returns the address of a global as a typed reference. Can be used with the
variable load and store indirect ops. global load and store indirect ops.
}]; }];
let arguments = (ins let arguments = (ins
IREE_VariableRefAttr:$variable IREE_GlobalRefAttr:$global
); );
let results = (outs 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 summary = [{loads a value from a global variable}];
let description = [{ let description = [{
Returns a copy of the variable value. Returns a copy of the global value.
}]; }];
let arguments = (ins let arguments = (ins
IREE_VariableRefAttr:$variable IREE_GlobalRefAttr:$global
); );
let results = (outs let results = (outs
AnyType:$result 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 summary = [{loads a value from a global variable}];
let description = [{ let description = [{
Returns a copy of the variable value. Returns a copy of the global value.
}]; }];
let arguments = (ins let arguments = (ins
IREE_VariablePtr:$variable IREE_AnyGlobalPtr:$global
); );
let results = (outs let results = (outs
AnyType:$result 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 summary = [{stores a value into a global variable}];
let description = [{ let description = [{
Stores a copy of the value into a variable. Stores a copy of the value into a global.
}]; }];
let arguments = (ins let arguments = (ins
AnyType:$value, 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 summary = [{stores a value into a global variable}];
let description = [{ let description = [{
Stores a copy of the value into a variable. Stores a copy of the value into a global.
}]; }];
let arguments = (ins let arguments = (ins
AnyType:$value, 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, IREE_ShapeDynamicDims:$target_dims,
Variadic<IREE_Dim>:$start_indices, Variadic<IREE_Dim>:$start_indices,
IREE_Tensor:$update, IREE_Tensor:$update,
IREE_ShapeDynamicDims:$update_dims, IREE_ShapeDynamicDims:$update_dims
OptionalAttr<IREE_TiedOpStorageAttr>:$tied_operands
); );
let results = (outs let results = (outs
IREE_Tensor:$result IREE_Tensor:$result
@ -482,7 +493,7 @@ def IREE_TensorUpdateOp : IREE_PureOp<"tensor.update", [
let assemblyFormat = [{ let assemblyFormat = [{
$update `,` $target `[` $start_indices `]` `:` $update `,` $target `[` $start_indices `]` `:`
type($update) (`{` $update_dims^ `}`)? `->` type($update) (`{` $update_dims^ `}`)? `->`
`(` type($result) `,` $target_dims `,` $tied_operands `)` type($result) (`{` $target_dims^ `}`)?
attr-dict-with-keyword attr-dict-with-keyword
}]; }];
@ -508,7 +519,7 @@ def IREE_TensorTraceOp : IREE_Op<"tensor.trace", []> {
Variadic<IREE_Tensor>:$operands Variadic<IREE_Tensor>:$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 #endif // IREE_LLVM_EXTERNAL_PROJECTS_IREE_DIALECTS_DIALECT_IREE_IREE_OPS_TD

View File

@ -15,5 +15,80 @@
using namespace mlir; using namespace mlir;
using namespace mlir::iree; using namespace mlir::iree;
//===----------------------------------------------------------------------===//
// custom<SymbolVisibility>($sym_visibility)
//===----------------------------------------------------------------------===//
// some.op custom<SymbolVisibility>($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<TypeOrAttr>($type, $attr)
//===----------------------------------------------------------------------===//
// some.op custom<TypeOrAttr>($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 #define GET_OP_CLASSES
#include "iree-dialects/Dialect/IREE/IREEOps.cpp.inc" #include "iree-dialects/Dialect/IREE/IREEOps.cpp.inc"