@@ -195,6 +195,10 @@ struct AsmPrinterOptions {
195
195
" mlir-print-unique-ssa-ids" , llvm::cl::init (false ),
196
196
llvm::cl::desc (" Print unique SSA ID numbers for values, block arguments "
197
197
" and naming conflicts across all regions" )};
198
+
199
+ llvm::cl::opt<bool > useNameLocAsPrefix{
200
+ " mlir-use-nameloc-as-prefix" , llvm::cl::init (false ),
201
+ llvm::cl::desc (" TODO" )};
198
202
};
199
203
} // namespace
200
204
@@ -212,7 +216,8 @@ OpPrintingFlags::OpPrintingFlags()
212
216
: printDebugInfoFlag(false ), printDebugInfoPrettyFormFlag(false ),
213
217
printGenericOpFormFlag(false ), skipRegionsFlag(false ),
214
218
assumeVerifiedFlag(false ), printLocalScope(false ),
215
- printValueUsersFlag(false ), printUniqueSSAIDsFlag(false ) {
219
+ printValueUsersFlag(false ), printUniqueSSAIDsFlag(false ),
220
+ useNameLocAsPrefix(false ) {
216
221
// Initialize based upon command line options, if they are available.
217
222
if (!clOptions.isConstructed ())
218
223
return ;
@@ -231,6 +236,7 @@ OpPrintingFlags::OpPrintingFlags()
231
236
skipRegionsFlag = clOptions->skipRegionsOpt ;
232
237
printValueUsersFlag = clOptions->printValueUsers ;
233
238
printUniqueSSAIDsFlag = clOptions->printUniqueSSAIDs ;
239
+ useNameLocAsPrefix = clOptions->useNameLocAsPrefix ;
234
240
}
235
241
236
242
// / Enable the elision of large elements attributes, by printing a '...'
@@ -362,6 +368,11 @@ bool OpPrintingFlags::shouldPrintUniqueSSAIDs() const {
362
368
return printUniqueSSAIDsFlag || shouldPrintGenericOpForm ();
363
369
}
364
370
371
+ // / TODO
372
+ bool OpPrintingFlags::shouldUseNameLocAsPrefix () const {
373
+ return useNameLocAsPrefix;
374
+ }
375
+
365
376
// ===----------------------------------------------------------------------===//
366
377
// NewLineCounter
367
378
// ===----------------------------------------------------------------------===//
@@ -1514,10 +1525,22 @@ void SSANameState::numberValuesInRegion(Region ®ion) {
1514
1525
setValueName (arg, name);
1515
1526
};
1516
1527
1528
+ bool alreadySetNames = false ;
1517
1529
if (!printerFlags.shouldPrintGenericOpForm ()) {
1518
1530
if (Operation *op = region.getParentOp ()) {
1519
- if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op))
1531
+ if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op)) {
1520
1532
asmInterface.getAsmBlockArgumentNames (region, setBlockArgNameFn);
1533
+ alreadySetNames = true ;
1534
+ }
1535
+ }
1536
+ }
1537
+
1538
+ if (printerFlags.shouldUseNameLocAsPrefix () && !alreadySetNames) {
1539
+ for (BlockArgument arg : region.getArguments ()) {
1540
+ if (isa<NameLoc>(arg.getLoc ())) {
1541
+ auto nameLoc = cast<NameLoc>(arg.getLoc ());
1542
+ setBlockArgNameFn (arg, nameLoc.getName ());
1543
+ }
1521
1544
}
1522
1545
}
1523
1546
@@ -1553,7 +1576,12 @@ void SSANameState::numberValuesInBlock(Block &block) {
1553
1576
specialNameBuffer.resize (strlen (" arg" ));
1554
1577
specialName << nextArgumentID++;
1555
1578
}
1556
- setValueName (arg, specialName.str ());
1579
+ if (printerFlags.shouldUseNameLocAsPrefix () && isa<NameLoc>(arg.getLoc ())) {
1580
+ auto nameLoc = cast<NameLoc>(arg.getLoc ());
1581
+ setValueName (arg, nameLoc.getName ());
1582
+ } else {
1583
+ setValueName (arg, specialName.str ());
1584
+ }
1557
1585
}
1558
1586
1559
1587
// Number the operations in this block.
@@ -1589,10 +1617,21 @@ void SSANameState::numberValuesInOp(Operation &op) {
1589
1617
blockNames[block] = {-1 , name};
1590
1618
};
1591
1619
1620
+ bool alreadySetNames = false ;
1592
1621
if (!printerFlags.shouldPrintGenericOpForm ()) {
1593
1622
if (OpAsmOpInterface asmInterface = dyn_cast<OpAsmOpInterface>(&op)) {
1594
1623
asmInterface.getAsmBlockNames (setBlockNameFn);
1595
1624
asmInterface.getAsmResultNames (setResultNameFn);
1625
+ alreadySetNames = true ;
1626
+ }
1627
+ }
1628
+
1629
+ if (printerFlags.shouldUseNameLocAsPrefix () && !alreadySetNames) {
1630
+ for (Value opResult : op.getResults ()) {
1631
+ if (isa<NameLoc>(opResult.getLoc ())) {
1632
+ auto nameLoc = cast<NameLoc>(opResult.getLoc ());
1633
+ setResultNameFn (opResult, nameLoc.getName ());
1634
+ }
1596
1635
}
1597
1636
}
1598
1637
0 commit comments