diff --git a/mlir/include/mlir/Dialect/Index/IR/IndexOps.h b/mlir/include/mlir/Dialect/Index/IR/IndexOps.h --- a/mlir/include/mlir/Dialect/Index/IR/IndexOps.h +++ b/mlir/include/mlir/Dialect/Index/IR/IndexOps.h @@ -11,6 +11,7 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/OpDefinition.h" +#include "mlir/IR/OpImplementation.h" #include "mlir/Interfaces/CastInterfaces.h" #include "mlir/Interfaces/InferTypeOpInterface.h" #include "mlir/Interfaces/SideEffectInterfaces.h" diff --git a/mlir/include/mlir/Dialect/Index/IR/IndexOps.td b/mlir/include/mlir/Dialect/Index/IR/IndexOps.td --- a/mlir/include/mlir/Dialect/Index/IR/IndexOps.td +++ b/mlir/include/mlir/Dialect/Index/IR/IndexOps.td @@ -14,6 +14,7 @@ include "mlir/Interfaces/CastInterfaces.td" include "mlir/Interfaces/InferTypeOpInterface.td" include "mlir/Interfaces/SideEffectInterfaces.td" +include "mlir/IR/OpAsmInterface.td" include "mlir/IR/OpBase.td" //===----------------------------------------------------------------------===// @@ -528,7 +529,10 @@ // ConstantOp //===----------------------------------------------------------------------===// -def Index_ConstantOp : IndexOp<"constant", [ConstantLike]> { +def Index_ConstantOp : IndexOp<"constant", [ + ConstantLike, + DeclareOpInterfaceMethods + ]> { let summary = "index constant"; let description = [{ The `index.constant` operation produces an index-typed SSA value equal to @@ -553,7 +557,10 @@ // BoolConstantOp //===----------------------------------------------------------------------===// -def Index_BoolConstantOp : IndexOp<"bool.constant", [ConstantLike]> { +def Index_BoolConstantOp : IndexOp<"bool.constant", [ + ConstantLike, + DeclareOpInterfaceMethods + ]> { let summary = "boolean constant"; let description = [{ The `index.bool.constant` operation produces an bool-typed SSA value equal diff --git a/mlir/lib/Dialect/Index/IR/IndexOps.cpp b/mlir/lib/Dialect/Index/IR/IndexOps.cpp --- a/mlir/lib/Dialect/Index/IR/IndexOps.cpp +++ b/mlir/lib/Dialect/Index/IR/IndexOps.cpp @@ -11,6 +11,7 @@ #include "mlir/Dialect/Index/IR/IndexDialect.h" #include "mlir/IR/Builders.h" #include "mlir/IR/OpImplementation.h" +#include "llvm/ADT/SmallString.h" using namespace mlir; using namespace mlir::index; @@ -424,6 +425,14 @@ // ConstantOp //===----------------------------------------------------------------------===// +void ConstantOp::getAsmResultNames( + function_ref setNameFn) { + SmallString<32> specialNameBuffer; + llvm::raw_svector_ostream specialName(specialNameBuffer); + specialName << "idx" << getValueAttr().getValue(); + setNameFn(getResult(), specialName.str()); +} + OpFoldResult ConstantOp::fold(ArrayRef operands) { return getValueAttr(); } @@ -440,6 +449,11 @@ return getValueAttr(); } +void BoolConstantOp::getAsmResultNames( + function_ref setNameFn) { + setNameFn(getResult(), getValue() ? "true" : "false"); +} + //===----------------------------------------------------------------------===// // ODS-Generated Definitions //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/Index/index-ops.mlir b/mlir/test/Dialect/Index/index-ops.mlir --- a/mlir/test/Dialect/Index/index-ops.mlir +++ b/mlir/test/Dialect/Index/index-ops.mlir @@ -77,20 +77,20 @@ // CHECK-LABEL: @constant_op func.func @constant_op() { - // CHECK-NEXT: index.constant 0 + // CHECK-NEXT: %idx0 = index.constant 0 %0 = index.constant 0 - // CHECK-NEXT: index.constant 1 + // CHECK-NEXT: %idx1 = index.constant 1 %1 = index.constant 1 - // CHECK-NEXT: index.constant 42 + // CHECK-NEXT: %idx42 = index.constant 42 %2 = index.constant 42 return } // CHECK-LABEL: @bool_constant_op func.func @bool_constant_op() { - // CHECK-NEXT: index.bool.constant true + // CHECK-NEXT: %true = index.bool.constant true %0 = index.bool.constant true - // CHECK-NEXT: index.bool.constant false + // CHECK-NEXT: %false = index.bool.constant false %1 = index.bool.constant false return }