@@ -197,9 +197,9 @@ struct AsmPrinterOptions {
197
197
llvm::cl::desc (" Print unique SSA ID numbers for values, block arguments "
198
198
" and naming conflicts across all regions" )};
199
199
200
- llvm::cl::opt<bool > useNameLocAsPrefix{" mlir-use-nameloc-as-prefix " ,
201
- llvm::cl::init (false ),
202
- llvm::cl::desc (" TODO " )};
200
+ llvm::cl::opt<bool > useNameLocAsPrefix{
201
+ " mlir-use-nameloc-as-prefix " , llvm::cl::init (false ),
202
+ llvm::cl::desc (" Print SSA IDs using NameLocs as prefixes " )};
203
203
};
204
204
} // namespace
205
205
@@ -369,7 +369,7 @@ bool OpPrintingFlags::shouldPrintUniqueSSAIDs() const {
369
369
return printUniqueSSAIDsFlag || shouldPrintGenericOpForm ();
370
370
}
371
371
372
- // / TODO
372
+ // / Return if the printer should use NameLocs as prefixes when printing SSA IDs
373
373
bool OpPrintingFlags::shouldUseNameLocAsPrefix () const {
374
374
return useNameLocAsPrefix;
375
375
}
@@ -1523,25 +1523,18 @@ void SSANameState::numberValuesInRegion(Region ®ion) {
1523
1523
assert (!valueIDs.count (arg) && " arg numbered multiple times" );
1524
1524
assert (llvm::cast<BlockArgument>(arg).getOwner ()->getParent () == ®ion &&
1525
1525
" arg not defined in current region" );
1526
- setValueName (arg, name);
1526
+ if (printerFlags.shouldUseNameLocAsPrefix () && isa<NameLoc>(arg.getLoc ())) {
1527
+ auto nameLoc = cast<NameLoc>(arg.getLoc ());
1528
+ setValueName (arg, nameLoc.getName ());
1529
+ } else {
1530
+ setValueName (arg, name);
1531
+ }
1527
1532
};
1528
1533
1529
- bool alreadySetNames = false ;
1530
1534
if (!printerFlags.shouldPrintGenericOpForm ()) {
1531
1535
if (Operation *op = region.getParentOp ()) {
1532
- if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op)) {
1536
+ if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op))
1533
1537
asmInterface.getAsmBlockArgumentNames (region, setBlockArgNameFn);
1534
- alreadySetNames = true ;
1535
- }
1536
- }
1537
- }
1538
-
1539
- if (printerFlags.shouldUseNameLocAsPrefix () && !alreadySetNames) {
1540
- for (BlockArgument arg : region.getArguments ()) {
1541
- if (isa<NameLoc>(arg.getLoc ())) {
1542
- auto nameLoc = cast<NameLoc>(arg.getLoc ());
1543
- setBlockArgNameFn (arg, nameLoc.getName ());
1544
- }
1545
1538
}
1546
1539
}
1547
1540
@@ -1596,7 +1589,13 @@ void SSANameState::numberValuesInOp(Operation &op) {
1596
1589
auto setResultNameFn = [&](Value result, StringRef name) {
1597
1590
assert (!valueIDs.count (result) && " result numbered multiple times" );
1598
1591
assert (result.getDefiningOp () == &op && " result not defined by 'op'" );
1599
- setValueName (result, name);
1592
+ if (printerFlags.shouldUseNameLocAsPrefix () &&
1593
+ isa<NameLoc>(result.getLoc ())) {
1594
+ auto nameLoc = cast<NameLoc>(result.getLoc ());
1595
+ setValueName (result, nameLoc.getName ());
1596
+ } else {
1597
+ setValueName (result, name);
1598
+ }
1600
1599
1601
1600
// Record the result number for groups not anchored at 0.
1602
1601
if (int resultNo = llvm::cast<OpResult>(result).getResultNumber ())
@@ -1618,25 +1617,14 @@ void SSANameState::numberValuesInOp(Operation &op) {
1618
1617
blockNames[block] = {-1 , name};
1619
1618
};
1620
1619
1621
- bool alreadySetNames = false ;
1622
1620
if (!printerFlags.shouldPrintGenericOpForm ()) {
1623
1621
if (OpAsmOpInterface asmInterface = dyn_cast<OpAsmOpInterface>(&op)) {
1624
1622
asmInterface.getAsmBlockNames (setBlockNameFn);
1625
1623
asmInterface.getAsmResultNames (setResultNameFn);
1626
- alreadySetNames = true ;
1627
1624
}
1628
1625
}
1629
1626
1630
1627
unsigned numResults = op.getNumResults ();
1631
- if (printerFlags.shouldUseNameLocAsPrefix () && !alreadySetNames &&
1632
- numResults > 0 ) {
1633
- Value resultBegin = op.getResult (0 );
1634
- if (isa<NameLoc>(resultBegin.getLoc ())) {
1635
- auto nameLoc = cast<NameLoc>(resultBegin.getLoc ());
1636
- setResultNameFn (resultBegin, nameLoc.getName ());
1637
- }
1638
- }
1639
-
1640
1628
if (numResults == 0 ) {
1641
1629
// If value users should be printed, operations with no result need an id.
1642
1630
if (printerFlags.shouldPrintValueUsers ()) {
@@ -1647,6 +1635,13 @@ void SSANameState::numberValuesInOp(Operation &op) {
1647
1635
}
1648
1636
Value resultBegin = op.getResult (0 );
1649
1637
1638
+ if (printerFlags.shouldUseNameLocAsPrefix () && !valueIDs.count (resultBegin)) {
1639
+ if (isa<NameLoc>(resultBegin.getLoc ())) {
1640
+ auto nameLoc = cast<NameLoc>(resultBegin.getLoc ());
1641
+ setResultNameFn (resultBegin, nameLoc.getName ());
1642
+ }
1643
+ }
1644
+
1650
1645
// If the first result wasn't numbered, give it a default number.
1651
1646
if (valueIDs.try_emplace (resultBegin, nextValueID).second )
1652
1647
++nextValueID;
0 commit comments