@@ -1536,10 +1536,13 @@ StringRef maybeGetValueNameFromLoc(Value value, StringRef name) {
1536
1536
} // namespace
1537
1537
1538
1538
void SSANameState::numberValuesInRegion (Region ®ion) {
1539
+ // Indicates 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,15 @@ 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 the OpAsmOpInterface didn't set a name, get name from the type.
1556
+ if (!opAsmOpInterfaceUsed) {
1557
+ for (BlockArgument arg : region.getArguments ()) {
1558
+ if (auto interface = dyn_cast<OpAsmTypeInterface>(arg.getType ())) {
1559
+ interface.getAsmName (
1560
+ [&](StringRef name) { setBlockArgNameFn (arg, name); });
1561
+ }
1562
+ }
1563
+ }
1552
1564
}
1553
1565
}
1554
1566
@@ -1598,9 +1610,12 @@ void SSANameState::numberValuesInBlock(Block &block) {
1598
1610
void SSANameState::numberValuesInOp (Operation &op) {
1599
1611
// Function used to set the special result names for the operation.
1600
1612
SmallVector<int , 2 > resultGroups (/* Size=*/ 1 , /* Value=*/ 0 );
1613
+ // Indicates whether OpAsmOpInterface set a name.
1614
+ bool opAsmOpInterfaceUsed = false ;
1601
1615
auto setResultNameFn = [&](Value result, StringRef name) {
1602
1616
assert (!valueIDs.count (result) && " result numbered multiple times" );
1603
1617
assert (result.getDefiningOp () == &op && " result not defined by 'op'" );
1618
+ opAsmOpInterfaceUsed = true ;
1604
1619
if (LLVM_UNLIKELY (printerFlags.shouldUseNameLocAsPrefix ()))
1605
1620
name = maybeGetValueNameFromLoc (result, name);
1606
1621
setValueName (result, name);
@@ -1630,6 +1645,21 @@ void SSANameState::numberValuesInOp(Operation &op) {
1630
1645
asmInterface.getAsmBlockNames (setBlockNameFn);
1631
1646
asmInterface.getAsmResultNames (setResultNameFn);
1632
1647
}
1648
+ if (!opAsmOpInterfaceUsed) {
1649
+ // If the OpAsmOpInterface didn't set a name, and all results have
1650
+ // OpAsmTypeInterface, get names from types.
1651
+ bool allHaveOpAsmTypeInterface =
1652
+ llvm::all_of (op.getResultTypes (), [&](Type type) {
1653
+ return isa<OpAsmTypeInterface>(type);
1654
+ });
1655
+ if (allHaveOpAsmTypeInterface) {
1656
+ for (OpResult result : op.getResults ()) {
1657
+ auto interface = cast<OpAsmTypeInterface>(result.getType ());
1658
+ interface.getAsmName (
1659
+ [&](StringRef name) { setResultNameFn (result, name); });
1660
+ }
1661
+ }
1662
+ }
1633
1663
}
1634
1664
1635
1665
unsigned numResults = op.getNumResults ();
0 commit comments