@@ -1536,10 +1536,13 @@ StringRef maybeGetValueNameFromLoc(Value value, StringRef name) {
15361536} // namespace
15371537
15381538void SSANameState::numberValuesInRegion (Region ®ion) {
1539+ // indicate whether OpAsmOpInterface set a name.
1540+ bool opAsmOpInterfaceUsed = false ;
15391541 auto setBlockArgNameFn = [&](Value arg, StringRef name) {
15401542 assert (!valueIDs.count (arg) && " arg numbered multiple times" );
15411543 assert (llvm::cast<BlockArgument>(arg).getOwner ()->getParent () == ®ion &&
15421544 " arg not defined in current region" );
1545+ opAsmOpInterfaceUsed = true ;
15431546 if (LLVM_UNLIKELY (printerFlags.shouldUseNameLocAsPrefix ()))
15441547 name = maybeGetValueNameFromLoc (arg, name);
15451548 setValueName (arg, name);
@@ -1549,6 +1552,18 @@ void SSANameState::numberValuesInRegion(Region ®ion) {
15491552 if (Operation *op = region.getParentOp ()) {
15501553 if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op))
15511554 asmInterface.getAsmBlockArgumentNames (region, setBlockArgNameFn);
1555+ if (!opAsmOpInterfaceUsed) {
1556+ // If the OpAsmOpInterface didn't set a name, get name from the type.
1557+ for (auto arg : region.getArguments ()) {
1558+ if (auto typeInterface =
1559+ mlir::dyn_cast<OpAsmTypeInterface>(arg.getType ())) {
1560+ auto setNameFn = [&](StringRef name) {
1561+ setBlockArgNameFn (arg, name);
1562+ };
1563+ typeInterface.getAsmName (setNameFn);
1564+ }
1565+ }
1566+ }
15521567 }
15531568 }
15541569
@@ -1598,9 +1613,12 @@ void SSANameState::numberValuesInBlock(Block &block) {
15981613void SSANameState::numberValuesInOp (Operation &op) {
15991614 // Function used to set the special result names for the operation.
16001615 SmallVector<int , 2 > resultGroups (/* Size=*/ 1 , /* Value=*/ 0 );
1616+ // indicating whether OpAsmOpInterface set a name.
1617+ bool opAsmOpInterfaceUsed = false ;
16011618 auto setResultNameFn = [&](Value result, StringRef name) {
16021619 assert (!valueIDs.count (result) && " result numbered multiple times" );
16031620 assert (result.getDefiningOp () == &op && " result not defined by 'op'" );
1621+ opAsmOpInterfaceUsed = true ;
16041622 if (LLVM_UNLIKELY (printerFlags.shouldUseNameLocAsPrefix ()))
16051623 name = maybeGetValueNameFromLoc (result, name);
16061624 setValueName (result, name);
@@ -1630,6 +1648,23 @@ void SSANameState::numberValuesInOp(Operation &op) {
16301648 asmInterface.getAsmBlockNames (setBlockNameFn);
16311649 asmInterface.getAsmResultNames (setResultNameFn);
16321650 }
1651+ if (!opAsmOpInterfaceUsed) {
1652+ // If the OpAsmOpInterface didn't set a name, and
1653+ // all results have OpAsmTypeInterface, get names from types.
1654+ bool allHaveOpAsmTypeInterface =
1655+ llvm::all_of (op.getResultTypes (), [&](Type type) {
1656+ return mlir::isa<OpAsmTypeInterface>(type);
1657+ });
1658+ if (allHaveOpAsmTypeInterface) {
1659+ for (auto result : op.getResults ()) {
1660+ auto typeInterface = mlir::cast<OpAsmTypeInterface>(result.getType ());
1661+ auto setNameFn = [&](StringRef name) {
1662+ setResultNameFn (result, name);
1663+ };
1664+ typeInterface.getAsmName (setNameFn);
1665+ }
1666+ }
1667+ }
16331668 }
16341669
16351670 unsigned numResults = op.getNumResults ();
0 commit comments