Hello debug-info folks!
Some may have been wondering, "What happened to that variable-location rewrite that Jeremy was trying to sell?". It was a bit delayed, and my thought process went like this:
- Hey cool, this new LiveDebugValues is SSA construction at the end of compilation!
- I didn't know you could do SSA construction just with lattices!
- Ah... you actually can't, so I've missed something in my understanding,
- Curses.
As it happens, I was keeping an extra piece of information for each block that meant the analysis didn't qualify as a normal dataflow algorithm. I've refreshed my understanding and written more docs on what's happening, plus three worked examples. The short summary is:
- It's SSA construction, where the hard part is identifying PHIs,
- We have to eliminate all dead PHIs to get accurate variable locations,
- We use value propagation the eliminate most dead PHIs,
- And an RPO-traversal algorithm to eliminate dead PHIs at loop heads.
Reassuringly, mem2reg does the same thing, but in a different way, to eliminate dead PHIs.
Now that this is sorted out, I'll be much happier landing patches on this topic.
The diagrams are written in tikz, I've been using the "tikzit" environment. I'm not sure what LLVM needs in terms of the "original source" for diagrams like this.
Might be nice to add the command line that produced the png as a comment here.
Maybe more LLVM readers are familiar with Graphviz dote files, since LLVM produces them, but I don't have a strong opinion.