@@ -1300,7 +1300,8 @@ class SSANameState {
1300
1300
1301
1301
// / Set the original identifier names if available. Used in debugging with
1302
1302
// / `--retain-identifier-names`/`shouldRetainIdentifierNames` in ParserConfig
1303
- void setRetainedIdentifierNames (Operation &op);
1303
+ void setRetainedIdentifierNames (Operation &op,
1304
+ SmallVector<int , 2 > &resultGroups);
1304
1305
1305
1306
// / This is the value ID for each SSA value. If this returns NameSentinel,
1306
1307
// / then the valueID has an entry in valueNames.
@@ -1573,7 +1574,7 @@ void SSANameState::numberValuesInOp(Operation &op) {
1573
1574
1574
1575
// Set the original identifier names if available. Used in debugging with
1575
1576
// `--retain-identifier-names`/`shouldRetainIdentifierNames` in ParserConfig
1576
- setRetainedIdentifierNames (op);
1577
+ setRetainedIdentifierNames (op, resultGroups );
1577
1578
1578
1579
unsigned numResults = op.getNumResults ();
1579
1580
if (numResults == 0 ) {
@@ -1597,25 +1598,33 @@ void SSANameState::numberValuesInOp(Operation &op) {
1597
1598
}
1598
1599
}
1599
1600
1600
- void SSANameState::setRetainedIdentifierNames (Operation &op) {
1601
- // Get the original SSA for the result(s) if available
1602
- unsigned numResults = op.getNumResults ();
1603
- if (numResults > 1 )
1604
- llvm::outs ()
1605
- << " have not yet implemented support for multiple return values\n " ;
1606
- else if (numResults == 1 ) {
1607
- Value resultBegin = op.getResult (0 );
1608
- if (StringAttr ssaNameAttr = op.getAttrOfType <StringAttr>(" mlir.ssaName" )) {
1609
- setValueName (resultBegin, ssaNameAttr.strref ());
1610
- op.removeDiscardableAttr (" mlir.ssaName" );
1601
+ void SSANameState::setRetainedIdentifierNames (
1602
+ Operation &op, SmallVector<int , 2 > &resultGroups) {
1603
+ // Get the original names for the results if available
1604
+ if (ArrayAttr resultNamesAttr =
1605
+ op.getAttrOfType <ArrayAttr>(" mlir.resultNames" )) {
1606
+ auto resultNames = resultNamesAttr.getValue ();
1607
+ auto results = op.getResults ();
1608
+ // Conservative in the case that the #results has changed
1609
+ for (size_t i = 0 ; i < results.size () && i < resultNames.size (); ++i) {
1610
+ auto resultName = resultNames[i].cast <StringAttr>().strref ();
1611
+ if (!resultName.empty ()) {
1612
+ if (!usedNames.count (resultName))
1613
+ setValueName (results[i], resultName);
1614
+ // If a result has a name, it is the start of a result group.
1615
+ if (i > 0 )
1616
+ resultGroups.push_back (i);
1617
+ }
1611
1618
}
1619
+ op.removeDiscardableAttr (" mlir.resultNames" );
1612
1620
}
1613
1621
1614
1622
// Get the original name for the op args if available
1615
1623
if (ArrayAttr opArgNamesAttr =
1616
1624
op.getAttrOfType <ArrayAttr>(" mlir.opArgNames" )) {
1617
1625
auto opArgNames = opArgNamesAttr.getValue ();
1618
1626
auto opArgs = op.getOperands ();
1627
+ // Conservative in the case that the #operands has changed
1619
1628
for (size_t i = 0 ; i < opArgs.size () && i < opArgNames.size (); ++i) {
1620
1629
auto opArgName = opArgNames[i].cast <StringAttr>().strref ();
1621
1630
if (!usedNames.count (opArgName))
@@ -1636,6 +1645,7 @@ void SSANameState::setRetainedIdentifierNames(Operation &op) {
1636
1645
op.getAttrOfType <ArrayAttr>(" mlir.blockArgNames" )) {
1637
1646
auto blockArgNames = blockArgNamesAttr.getValue ();
1638
1647
auto blockArgs = op.getBlock ()->getArguments ();
1648
+ // Conservative in the case that the #args has changed
1639
1649
for (size_t i = 0 ; i < blockArgs.size () && i < blockArgNames.size (); ++i) {
1640
1650
auto blockArgName = blockArgNames[i].cast <StringAttr>().strref ();
1641
1651
if (!usedNames.count (blockArgName))
0 commit comments