[PATCH] D50680: [SDAG] Remove the reliance on MI's allocation strategy for `MachineMemOperand` pointers attached to `MachineSDNodes` and instead have the `SelectionDAG` fully manage the memory for this array.

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 13 17:43:44 PDT 2018


chandlerc marked an inline comment as done.
chandlerc added inline comments.


================
Comment at: llvm/include/llvm/CodeGen/SelectionDAGNodes.h:2256
 
-  /// Memory reference descriptions for this instruction.
-  mmo_iterator MemRefs = nullptr;
-  mmo_iterator MemRefsEnd = nullptr;
+  PointerUnion<MachineMemOperand *, MachineMemOperand **> MemRefs = {};
+
----------------
hfinkel wrote:
> Should we use TinyPtrVector here instead of making this PointerUnion and keeping NumMemRefs below?
We can't. I tried so hard to do this. It was terrible.

In a word, `MorphNodeTo`.

We don't actually run constructors or destructors reliably for any SDNode subclasses. We allocate enough memory and with enough alignment for any of the subclasses, and then we just "switch" the subclass by writing to `NodeType`. Yay.

We have manual code in `MorphNodeTo` to "clean up" and "initialize" the members as needed.

I tried fixing this, and it is terrible. Nothing works.

We essentially *have* to allocate any extra storage off the DAG's allocator so it gets freed for us, and we have to use POD-ish data types here that we can update with a simple store regardless of what uninitialized garbage memory is left there due to `MorphNodeTo`.

Sorry I couldn't find anything less awful than this.


Repository:
  rL LLVM

https://reviews.llvm.org/D50680





More information about the llvm-commits mailing list