[cleanup] Add materializer for basicpy.singleton

This allows the canonicalizer to coalesce it like other constants.
pull/214/head
Sean Silva 2021-04-30 14:56:35 -07:00
parent 3d08c83580
commit 133bdf4b31
2 changed files with 14 additions and 1 deletions

View File

@ -86,6 +86,9 @@ Operation *BasicpyDialect::materializeConstant(OpBuilder &builder,
return builder.create<StrConstantOp>(loc, type, strValue);
}
if (auto typeAttr = value.dyn_cast<TypeAttr>())
return builder.create<SingletonOp>(loc, typeAttr.getValue());
return nullptr;
}

View File

@ -1,4 +1,4 @@
// RUN: npcomp-opt -split-input-file %s | npcomp-opt -canonicalize | FileCheck --dump-input=fail %s
// RUN: npcomp-opt -split-input-file -canonicalize %s | FileCheck %s
// CHECK-LABEL: func @unknown_cast_elide
func @unknown_cast_elide(%arg0 : i32) -> i32 {
@ -80,3 +80,13 @@ func @bool_cast() -> i1 {
// CHECK: return %[[CTRUE]] : i1
return %1 : i1
}
// -----
// CHECK-LABEL: func @singleton_coalesce
func @singleton_coalesce() -> (!basicpy.NoneType, !basicpy.NoneType) {
%0 = basicpy.singleton : !basicpy.NoneType
%1 = basicpy.singleton : !basicpy.NoneType
// CHECK-NEXT: %[[RET:.*]] = basicpy.singleton
// CHECK-NEXT: return %[[RET]], %[[RET]]
return %0, %1 : !basicpy.NoneType, !basicpy.NoneType
}