@@ -1536,10 +1536,13 @@ StringRef maybeGetValueNameFromLoc(Value value, StringRef name) {
1536
1536
} // namespace
1537
1537
1538
1538
void SSANameState::numberValuesInRegion (Region ®ion) {
1539
+ // indicate whether OpAsmOpInterface set a name
1540
+ bool opAsmOpInterfaceUsed = false ;
1539
1541
auto setBlockArgNameFn = [&](Value arg, StringRef name) {
1540
1542
assert (!valueIDs.count (arg) && " arg numbered multiple times" );
1541
1543
assert (llvm::cast<BlockArgument>(arg).getOwner ()->getParent () == ®ion &&
1542
1544
" arg not defined in current region" );
1545
+ opAsmOpInterfaceUsed = true ;
1543
1546
if (LLVM_UNLIKELY (printerFlags.shouldUseNameLocAsPrefix ()))
1544
1547
name = maybeGetValueNameFromLoc (arg, name);
1545
1548
setValueName (arg, name);
@@ -1549,6 +1552,23 @@ void SSANameState::numberValuesInRegion(Region ®ion) {
1549
1552
if (Operation *op = region.getParentOp ()) {
1550
1553
if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op))
1551
1554
asmInterface.getAsmBlockArgumentNames (region, setBlockArgNameFn);
1555
+ if (!opAsmOpInterfaceUsed) {
1556
+ // If the OpAsmOpInterface didn't set a name, and when
1557
+ // all arguments have OpAsmTypeInterface, get names from the type
1558
+ bool allHaveOpAsmTypeInterface =
1559
+ llvm::all_of (region.getArguments (), [&](Value arg) {
1560
+ return mlir::isa<OpAsmTypeInterface>(arg.getType ());
1561
+ });
1562
+ if (allHaveOpAsmTypeInterface) {
1563
+ for (auto arg : region.getArguments ()) {
1564
+ auto typeInterface = mlir::cast<OpAsmTypeInterface>(arg.getType ());
1565
+ auto setNameFn = [&](StringRef name) {
1566
+ setBlockArgNameFn (arg, name);
1567
+ };
1568
+ typeInterface.getAsmName (setNameFn);
1569
+ }
1570
+ }
1571
+ }
1552
1572
}
1553
1573
}
1554
1574
@@ -1598,9 +1618,12 @@ void SSANameState::numberValuesInBlock(Block &block) {
1598
1618
void SSANameState::numberValuesInOp (Operation &op) {
1599
1619
// Function used to set the special result names for the operation.
1600
1620
SmallVector<int , 2 > resultGroups (/* Size=*/ 1 , /* Value=*/ 0 );
1621
+ // indicating whether OpAsmOpInterface set a name
1622
+ bool opAsmOpInterfaceUsed = false ;
1601
1623
auto setResultNameFn = [&](Value result, StringRef name) {
1602
1624
assert (!valueIDs.count (result) && " result numbered multiple times" );
1603
1625
assert (result.getDefiningOp () == &op && " result not defined by 'op'" );
1626
+ opAsmOpInterfaceUsed = true ;
1604
1627
if (LLVM_UNLIKELY (printerFlags.shouldUseNameLocAsPrefix ()))
1605
1628
name = maybeGetValueNameFromLoc (result, name);
1606
1629
setValueName (result, name);
@@ -1630,6 +1653,23 @@ void SSANameState::numberValuesInOp(Operation &op) {
1630
1653
asmInterface.getAsmBlockNames (setBlockNameFn);
1631
1654
asmInterface.getAsmResultNames (setResultNameFn);
1632
1655
}
1656
+ if (!opAsmOpInterfaceUsed) {
1657
+ // If the OpAsmOpInterface didn't set a name, and when
1658
+ // all results have OpAsmTypeInterface, get names from the type
1659
+ bool allHaveOpAsmTypeInterface =
1660
+ llvm::all_of (op.getResults (), [&](Value result) {
1661
+ return mlir::isa<OpAsmTypeInterface>(result.getType ());
1662
+ });
1663
+ if (allHaveOpAsmTypeInterface) {
1664
+ for (auto result : op.getResults ()) {
1665
+ auto typeInterface = mlir::cast<OpAsmTypeInterface>(result.getType ());
1666
+ auto setNameFn = [&](StringRef name) {
1667
+ setResultNameFn (result, name);
1668
+ };
1669
+ typeInterface.getAsmName (setNameFn);
1670
+ }
1671
+ }
1672
+ }
1633
1673
}
1634
1674
1635
1675
unsigned numResults = op.getNumResults ();
0 commit comments