You can see in my branch retain-names-dev
, I’ve implemented this behaviour in around a dozen lines (without a flag implemented, this is just default behaviour in this branch).
I do my name replacement in AsmPrinter.cpp’s SSANameState::printValueID
. I believe this is the most generic place where this replacement can occur.
I am keeping track of the original names with llvm::DenseMap<Operation *, llvm::StringRef>
in MLIRContext. Values are inserted at parse time, and I’m using value->getDefiningOp()
as the key.
Since the original name information needs to be accessible from the printer, as I said above, I think this should either be a property of the Value class, or in a map in the MLIRContext.
As @jpienaar mentioned, the location info is already in the Value object, so perhaps this kind of debug information is acceptable to include there. I suppose I could parse the original name from the location information at print time, but for now I’m storing it when we parse it the first time. The tradeoff is either adding a new set of data to keep track off, or increasing the code complexity to parse at print time from the location. I’d be interesting in hearing opinions from more experienced folk.
As you can see, to actually support the functionality of retained variable names only requires a small amount of code. The question is where that logic should reside, and if having this as a feature at all in e.g., mlir-opt
would be useful.