[llvm] [LLVM] Add option to store Parent-pointer in ilist_node_base (PR #94224)
Stephen Tozer via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 4 04:50:44 PDT 2024
SLTozer wrote:
Alright, I've made some modifications - using some mixin classes to 1) reduce a bit of duplication in `ilist_node_base`, and 2) make the parent access a bit "smarter": `ilist_node_impl` will now have public get/set parent methods iff the list uses `ilist_parent`, and similarly the `ilist_iterator` only provides `getNodeParent()` if the node type uses `ilist_parent`. This reduces the potential for misuse (unknowingly trying to `getNodeParent()` from an iterator that doesn't actually support it), and means that `Instruction` doesn't need to declare get/set parent at all.
I think this is getting close to "too much template logic"; I also experimented making changes to `SymbolTableList` that would set the parent on the sentinel node automatically (as it does for other nodes), but it ended up at 30 lines of garbled template nonsense in order to avoid one call to `end().getNodePtr()->setParent(this)` in the `BasicBlock` constructor, so I decided not to add that to the patch.
https://github.com/llvm/llvm-project/pull/94224
More information about the llvm-commits
mailing list