@@ -1619,6 +1619,38 @@ int testOperands() {
1619
1619
return 0 ;
1620
1620
}
1621
1621
1622
+ /// Tests clone APIs.
1623
+ int testClone () {
1624
+ fprintf (stderr , "@testClone\n" );
1625
+ // CHECK-LABEL: @testClone
1626
+
1627
+ MlirContext ctx = mlirContextCreate ();
1628
+ MlirLocation loc = mlirLocationUnknownGet (ctx );
1629
+ MlirType indexType = mlirIndexTypeGet (ctx );
1630
+ MlirStringRef valueStringRef = mlirStringRefCreateFromCString ("value" );
1631
+
1632
+ MlirAttribute indexZeroLiteral =
1633
+ mlirAttributeParseGet (ctx , mlirStringRefCreateFromCString ("0 : index" ));
1634
+ MlirNamedAttribute indexZeroValueAttr = mlirNamedAttributeGet (mlirIdentifierGet (ctx , valueStringRef ), indexZeroLiteral );
1635
+ MlirOperationState constZeroState = mlirOperationStateGet (
1636
+ mlirStringRefCreateFromCString ("std.constant" ), loc );
1637
+ mlirOperationStateAddResults (& constZeroState , 1 , & indexType );
1638
+ mlirOperationStateAddAttributes (& constZeroState , 1 , & indexZeroValueAttr );
1639
+ MlirOperation constZero = mlirOperationCreate (& constZeroState );
1640
+
1641
+ MlirAttribute indexOneLiteral =
1642
+ mlirAttributeParseGet (ctx , mlirStringRefCreateFromCString ("1 : index" ));
1643
+ MlirOperation constOne = mlirOperationClone (constZero );
1644
+ mlirOperationSetAttributeByName (constOne , valueStringRef , indexOneLiteral );
1645
+
1646
+ mlirOperationPrint (constZero , printToStderr , NULL );
1647
+ mlirOperationPrint (constOne , printToStderr , NULL );
1648
+ // CHECK: %0 = "std.constant"() {value = 0 : index} : () -> index
1649
+ // CHECK: %0 = "std.constant"() {value = 1 : index} : () -> index
1650
+
1651
+ return 0 ;
1652
+ }
1653
+
1622
1654
// Wraps a diagnostic into additional text we can match against.
1623
1655
MlirLogicalResult errorHandler (MlirDiagnostic diagnostic , void * userData ) {
1624
1656
fprintf (stderr , "processing diagnostic (userData: %ld) <<\n" , (long )userData );
@@ -1698,6 +1730,8 @@ int main() {
1698
1730
return 10 ;
1699
1731
if (testOperands ())
1700
1732
return 11 ;
1733
+ if (testClone ())
1734
+ return 12 ;
1701
1735
1702
1736
mlirContextDestroy (ctx );
1703
1737
0 commit comments