diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td --- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td +++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td @@ -17,6 +17,7 @@ include "mlir/Interfaces/ShapedOpInterfaces.td" include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/Interfaces/ViewLikeInterface.td" +include "mlir/IR/OpAsmInterface.td" include "mlir/IR/SymbolInterfaces.td" /// A TypeAttr for memref types. @@ -135,7 +136,8 @@ // AllocOp //===----------------------------------------------------------------------===// -def MemRef_AllocOp : AllocLikeOp<"alloc", DefaultResource, []> { +def MemRef_AllocOp : AllocLikeOp<"alloc", DefaultResource, [ + DeclareOpInterfaceMethods]> { let summary = "memory allocation operation"; let description = [{ The `alloc` operation allocates a region of memory, as specified by its @@ -276,7 +278,8 @@ // AllocaOp //===----------------------------------------------------------------------===// -def MemRef_AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource> { +def MemRef_AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource,[ + DeclareOpInterfaceMethods]> { let summary = "stack memory allocation operation"; let description = [{ The `alloca` operation allocates memory on the stack, to be automatically @@ -398,10 +401,12 @@ //===----------------------------------------------------------------------===// def MemRef_CastOp : MemRef_Op<"cast", [ - NoSideEffect, SameOperandsAndResultShape, DeclareOpInterfaceMethods, - ViewLikeOpInterface, - MemRefsNormalizable + DeclareOpInterfaceMethods, + MemRefsNormalizable, + NoSideEffect, + SameOperandsAndResultShape, + ViewLikeOpInterface ]> { let summary = "memref cast operation"; let description = [{ @@ -477,8 +482,8 @@ // CopyOp //===----------------------------------------------------------------------===// -def CopyOp : MemRef_Op<"copy", - [CopyOpInterface, SameOperandsElementType, SameOperandsShape]> { +def CopyOp : MemRef_Op<"copy", [CopyOpInterface, SameOperandsElementType, + SameOperandsShape]> { let description = [{ Copies the data from the source to the destination memref. @@ -536,8 +541,11 @@ // DimOp //===----------------------------------------------------------------------===// -def MemRef_DimOp : MemRef_Op<"dim", [NoSideEffect, MemRefsNormalizable, - ShapedDimOpInterface]> { +def MemRef_DimOp : MemRef_Op<"dim", [ + DeclareOpInterfaceMethods, + MemRefsNormalizable, + NoSideEffect, + ShapedDimOpInterface]> { let summary = "dimension index operation"; let description = [{ The `dim` operation takes a memref and a dimension operand of type `index`. @@ -798,8 +806,11 @@ // ExtractAlignedPointerAsIndexOp //===----------------------------------------------------------------------===// -def MemRef_ExtractAlignedPointerAsIndexOp : MemRef_Op<"extract_aligned_pointer_as_index", - [NoSideEffect, SameVariadicResultSize]> { +def MemRef_ExtractAlignedPointerAsIndexOp : + MemRef_Op<"extract_aligned_pointer_as_index", [ + DeclareOpInterfaceMethods, + NoSideEffect, + SameVariadicResultSize]> { let summary = "Extracts a memref's underlying aligned pointer as an index"; let description = [{ Extracts the underlying aligned pointer as an index. @@ -836,8 +847,10 @@ // ExtractStridedMetadataOp //===----------------------------------------------------------------------===// -def MemRef_ExtractStridedMetadataOp : MemRef_Op<"extract_strided_metadata", - [NoSideEffect, SameVariadicResultSize]> { +def MemRef_ExtractStridedMetadataOp : MemRef_Op<"extract_strided_metadata", [ + DeclareOpInterfaceMethods, + NoSideEffect, + SameVariadicResultSize]> { let summary = "Extracts a buffer base with offset and strides"; let description = [{ Extracts a base buffer, offset and strides. This op allows additional layers @@ -1193,8 +1206,12 @@ def MemRef_ReinterpretCastOp : MemRef_OpWithOffsetSizesAndStrides<"reinterpret_cast", [ - NoSideEffect, AttrSizedOperandSegments, ViewLikeOpInterface, - OffsetSizeAndStrideOpInterface, MemRefsNormalizable + DeclareOpInterfaceMethods, + AttrSizedOperandSegments, + MemRefsNormalizable, + NoSideEffect, + OffsetSizeAndStrideOpInterface, + ViewLikeOpInterface ]> { let summary = "memref reinterpret cast operation"; let description = [{ @@ -1313,7 +1330,9 @@ //===----------------------------------------------------------------------===// def MemRef_ReshapeOp: MemRef_Op<"reshape", [ - ViewLikeOpInterface, NoSideEffect]> { + DeclareOpInterfaceMethods, + NoSideEffect, + ViewLikeOpInterface]> { let summary = "memref reshape operation"; let description = [{ The `reshape` operation converts a memref from one type to an @@ -1412,7 +1431,8 @@ let hasVerifier = 1; } -def MemRef_ExpandShapeOp : MemRef_ReassociativeReshapeOp<"expand_shape"> { +def MemRef_ExpandShapeOp : MemRef_ReassociativeReshapeOp<"expand_shape", [ + DeclareOpInterfaceMethods]> { let summary = "operation to produce a memref with a higher rank."; let description = [{ The `memref.expand_shape` op produces a new view with a higher rank whose @@ -1491,7 +1511,8 @@ let hasVerifier = 1; } -def MemRef_CollapseShapeOp : MemRef_ReassociativeReshapeOp<"collapse_shape"> { +def MemRef_CollapseShapeOp : MemRef_ReassociativeReshapeOp<"collapse_shape", [ + DeclareOpInterfaceMethods]> { let summary = "operation to produce a memref with a smaller rank."; let description = [{ The `memref.collapse_shape` op produces a new view with a smaller rank @@ -1656,8 +1677,11 @@ //===----------------------------------------------------------------------===// def SubViewOp : MemRef_OpWithOffsetSizesAndStrides<"subview", [ - DeclareOpInterfaceMethods, NoSideEffect, - AttrSizedOperandSegments, OffsetSizeAndStrideOpInterface + DeclareOpInterfaceMethods, + DeclareOpInterfaceMethods, + AttrSizedOperandSegments, + OffsetSizeAndStrideOpInterface, + NoSideEffect ]> { let summary = "memref subview operation"; let description = [{ @@ -1940,7 +1964,9 @@ // TransposeOp //===----------------------------------------------------------------------===// -def MemRef_TransposeOp : MemRef_Op<"transpose", [NoSideEffect]>, +def MemRef_TransposeOp : MemRef_Op<"transpose", [ + DeclareOpInterfaceMethods, + NoSideEffect]>, Arguments<(ins AnyStridedMemRef:$in, AffineMapAttr:$permutation)>, Results<(outs AnyStridedMemRef)> { let summary = "`transpose` produces a new strided memref (metadata-only)"; @@ -1975,7 +2001,9 @@ //===----------------------------------------------------------------------===// def MemRef_ViewOp : MemRef_Op<"view", [ - DeclareOpInterfaceMethods, NoSideEffect]> { + DeclareOpInterfaceMethods, + DeclareOpInterfaceMethods, + NoSideEffect]> { let summary = "memref view operation"; let description = [{ The "view" operation extracts an N-D contiguous memref with empty layout map diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -113,6 +113,16 @@ // AllocOp / AllocaOp //===----------------------------------------------------------------------===// +void AllocOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "alloc"); +} + +void AllocaOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "alloca"); +} + template static LogicalResult verifyAllocLikeOp(AllocLikeOp op) { static_assert(llvm::is_one_of::value, @@ -522,6 +532,10 @@ // CastOp //===----------------------------------------------------------------------===// +void CastOp::getAsmResultNames(function_ref setNameFn) { + setNameFn(getResult(), "cast"); +} + /// Determines whether MemRef_CastOp casts to a more dynamic version of the /// source memref. This is useful to to fold a memref.cast into a consuming op /// and implement canonicalization patterns for ops in different dialects that @@ -782,6 +796,10 @@ // DimOp //===----------------------------------------------------------------------===// +void DimOp::getAsmResultNames(function_ref setNameFn) { + setNameFn(getResult(), "dim"); +} + void DimOp::build(OpBuilder &builder, OperationState &result, Value source, int64_t index) { auto loc = result.location; @@ -1209,6 +1227,31 @@ return success(); } +//===----------------------------------------------------------------------===// +// ExtractAlignedPointerAsIndexOp +//===----------------------------------------------------------------------===// + +void ExtractAlignedPointerAsIndexOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "intptr"); +} + +//===----------------------------------------------------------------------===// +// ExtractStridedMetadataOp +//===----------------------------------------------------------------------===// + +void ExtractStridedMetadataOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getBaseBuffer(), "base_buffer"); + setNameFn(getOffset(), "offset"); + // For multi-result to work properly with pretty names and packed syntax `x:3` + // we can only give a pretty name to the first value in the pack. + if (!getSizes().empty()) { + setNameFn(getSizes().front(), "sizes"); + setNameFn(getStrides().front(), "strides"); + } +} + //===----------------------------------------------------------------------===// // GenericAtomicRMWOp //===----------------------------------------------------------------------===// @@ -1508,6 +1551,11 @@ // ReinterpretCastOp //===----------------------------------------------------------------------===// +void ReinterpretCastOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "reinterpret_cast"); +} + /// Build a ReinterpretCastOp with all dynamic entries: `staticOffsets`, /// `staticSizes` and `staticStrides` are automatically filled with /// source-memref-rank sentinel values that encode dynamic entries. @@ -1709,6 +1757,16 @@ // Reassociative reshape ops //===----------------------------------------------------------------------===// +void CollapseShapeOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "collapse_shape"); +} + +void ExpandShapeOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "expand_shape"); +} + /// Helper function for verifying the shape of ExpandShapeOp and ResultShapeOp /// result and operand. Layout maps are verified separately. /// @@ -2120,6 +2178,11 @@ // ReshapeOp //===----------------------------------------------------------------------===// +void ReshapeOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "reshape"); +} + LogicalResult ReshapeOp::verify() { Type operandType = getSource().getType(); Type resultType = getResult().getType(); @@ -2170,6 +2233,11 @@ // SubViewOp //===----------------------------------------------------------------------===// +void SubViewOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "subview"); +} + /// A subview result type can be fully inferred from the source type and the /// static representation of offsets, sizes and strides. Special sentinels /// encode the dynamic case. @@ -2735,6 +2803,11 @@ // TransposeOp //===----------------------------------------------------------------------===// +void TransposeOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), "transpose"); +} + /// Build a strided memref type by applying `permutationMap` tp `memRefType`. static MemRefType inferTransposeResultType(MemRefType memRefType, AffineMap permutationMap) { @@ -2826,6 +2899,10 @@ // ViewOp //===----------------------------------------------------------------------===// +void ViewOp::getAsmResultNames(function_ref setNameFn) { + setNameFn(getResult(), "view"); +} + LogicalResult ViewOp::verify() { auto baseType = getOperand(0).getType().cast(); auto viewType = getType();