Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
Show All 12 Lines | |||||
#ifndef SHAPE_OPS | #ifndef SHAPE_OPS | ||||
#define SHAPE_OPS | #define SHAPE_OPS | ||||
include "mlir/Dialect/Shape/IR/ShapeBase.td" | include "mlir/Dialect/Shape/IR/ShapeBase.td" | ||||
include "mlir/Interfaces/ControlFlowInterfaces.td" | include "mlir/Interfaces/ControlFlowInterfaces.td" | ||||
include "mlir/Interfaces/InferTypeOpInterface.td" | include "mlir/Interfaces/InferTypeOpInterface.td" | ||||
include "mlir/Interfaces/SideEffectInterfaces.td" | include "mlir/Interfaces/SideEffectInterfaces.td" | ||||
include "mlir/IR/OpAsmInterface.td" | include "mlir/IR/OpAsmInterface.td" | ||||
include "mlir/IR/SymbolInterfaces.td" | |||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// Shape op definitions | // Shape op definitions | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// Base class for the operation in this dialect | // Base class for the operation in this dialect | ||||
class Shape_Op<string mnemonic, list<OpTrait> traits = []> : | class Shape_Op<string mnemonic, list<OpTrait> traits = []> : | ||||
Op<ShapeDialect, mnemonic, traits>; | Op<ShapeDialect, mnemonic, traits>; | ||||
▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | def Shape_WithOp : Shape_Op<"with_shape", [NoSideEffect]> { | ||||
let arguments = (ins AnyTypeOf<[AnyShaped, Shape_ValueShapeType]>:$operand, | let arguments = (ins AnyTypeOf<[AnyShaped, Shape_ValueShapeType]>:$operand, | ||||
Shape_ShapeType:$shape); | Shape_ShapeType:$shape); | ||||
let results = (outs Shape_ValueShapeType:$result); | let results = (outs Shape_ValueShapeType:$result); | ||||
let assemblyFormat = "operands attr-dict `:` type($operand) `,` type($shape)"; | let assemblyFormat = "operands attr-dict `:` type($operand) `,` type($shape)"; | ||||
} | } | ||||
def Shape_YieldOp : Shape_Op<"yield", | def Shape_YieldOp : Shape_Op<"yield", | ||||
[HasParent<"ReduceOp">, | [HasParent<"ReduceOp, FunctionLibraryOp">, | ||||
NoSideEffect, | NoSideEffect, | ||||
ReturnLike, | ReturnLike, | ||||
Terminator]> { | Terminator]> { | ||||
let summary = "Returns the value to parent op"; | let summary = "Returns the value to parent op"; | ||||
let arguments = (ins Variadic<AnyType>:$operands); | let arguments = (ins Variadic<AnyType>:$operands); | ||||
let builders = [OpBuilderDAG<(ins), | let builders = [OpBuilderDAG<(ins), | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | def Shape_CstrRequireOp : Shape_Op<"cstr_require", []> { | ||||
let arguments = (ins I1:$pred, StrAttr:$msg); | let arguments = (ins I1:$pred, StrAttr:$msg); | ||||
let results = (outs Shape_WitnessType:$result); | let results = (outs Shape_WitnessType:$result); | ||||
let assemblyFormat = "$pred `,` $msg attr-dict"; | let assemblyFormat = "$pred `,` $msg attr-dict"; | ||||
let hasFolder = 1; | let hasFolder = 1; | ||||
} | } | ||||
//===----------------------------------------------------------------------===// | |||||
// Shape collection ops. | |||||
//===----------------------------------------------------------------------===// | |||||
def Shape_FunctionLibraryOp : Shape_Op<"function_library", | |||||
[AffineScope, IsolatedFromAbove, NoRegionArguments, SymbolTable, Symbol, | |||||
SingleBlockImplicitTerminator<"ShapeFunctionLibraryTerminatorOp">]> { | |||||
let summary = "Represents shape functions and corresponding ops"; | |||||
let description = [{ | |||||
Represents a list of shape functions and the ops whose shape transfer | |||||
functions they represent. | |||||
Example: | |||||
```mlir | |||||
shape.function_library { | |||||
func @same_result_shape(%arg: !shape.value_shape) -> !shape.shape { | |||||
%0 = shape.shape_of %arg : !shape.value_shape -> !shape.shape | |||||
return %0 : !shape.shape | |||||
} | |||||
} mapping { | |||||
std.atan = @same_result_shape | |||||
} | |||||
``` | |||||
}]; | |||||
let arguments = (ins SymbolNameAttr:$sym_name, | |||||
OptionalAttr<StrAttr>:$sym_visibility); | |||||
let arguments = (ins DictionaryAttr:$mapping); | |||||
let regions = (region AnyRegion:$body); | |||||
tpopp: Maybe use the OneRegion trait instead to catch any code expecting that trait instead. | |||||
You should never be adding that yourself, it's automatic. rriddle: You should never be adding that yourself, it's automatic. | |||||
SizedRegion<1> is to express that the region has a single block, not that there is a single region. mehdi_amini: SizedRegion<1> is to express that the region has a single block, not that there is a single… | |||||
let extraClassDeclaration = [{ | |||||
/// Returns an associated shape function for an operation if defined. | |||||
FuncOp getShapeFunction(Operation *op); | |||||
}]; | |||||
let builders = [OpBuilderDAG<(ins "StringRef":$name)>]; | |||||
Operation& -> Operation & Also I'd probably use Operation * here instead given that this is the overwhelming common way of passing an operation, and the one that has the most nice implicit conversions. rriddle: `Operation&` -> `Operation &`
Also I'd probably use `Operation *` here instead given that this… | |||||
let skipDefaultBuilders = 1; | |||||
let printer = [{ ::print(p, *this); }]; | |||||
let parser = [{ return ::parse$cppClass(parser, result); }]; | |||||
} | |||||
//===----------------------------------------------------------------------===// | |||||
// ShapeFunctionLibraryTerminatorOp | |||||
I think this should be without shape in the op name as that's redundant (shape.shape_fn_lib_terminator) tpopp: I think this should be without shape in the op name as that's redundant (shape. | |||||
//===----------------------------------------------------------------------===// | |||||
def ShapeFunctionLibraryTerminatorOp : Shape_Op<"fn_lib_terminator", | |||||
[Terminator, HasParent<"FunctionLibraryOp">]> { | |||||
let summary = "A pseudo op that marks the end of a shape function library"; | |||||
let description = [{ | |||||
`shape_fn_lib_terminator` is a special pseudo terminator operation for the | |||||
shape function library. It has no semantic meaning beyond keeping the body | |||||
well-formed. | |||||
}]; | |||||
let assemblyFormat = "attr-dict"; | |||||
} | |||||
#endif // SHAPE_OPS | #endif // SHAPE_OPS |
Maybe use the OneRegion trait instead to catch any code expecting that trait instead.