diff options
| author | Chandler Carruth <chandlerc@gmail.com> | 2018-08-14 23:30:32 +0000 |
|---|---|---|
| committer | Chandler Carruth <chandlerc@gmail.com> | 2018-08-14 23:30:32 +0000 |
| commit | 66654b72c9e6b2aea51d20f9949a010df864d0f9 (patch) | |
| tree | 729a349a925aa9a8d7e1a4a970c811df18d04418 /llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | |
| parent | 44fdf2dad6ac2434630cb122418cfc8bf418cc83 (diff) | |
| download | bcm5719-llvm-66654b72c9e6b2aea51d20f9949a010df864d0f9.tar.gz bcm5719-llvm-66654b72c9e6b2aea51d20f9949a010df864d0f9.zip | |
[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.
Prior to this change, the memory management was deeply confusing here --
The way the MI was built relied on the `SelectionDAG` allocating memory
for these arrays of pointers using the `MachineFunction`'s allocator so
that the raw pointer to the array could be blindly copied into an
eventual `MachineInstr`. This creates a hard coupling between how
`MachineInstr`s allocate their array of `MachineMemOperand` pointers and
how the `MachineSDNode` does.
This change is motivated in large part by a change I am making to how
`MachineFunction` allocates these pointers, but it seems like a layering
improvement as well.
This would run the risk of increasing allocations overall, but I've
implemented an optimization that should avoid that by storing a single
`MachineMemOperand` pointer directly instead of allocating anything.
This is expected to be a net win because the vast majority of uses of
these only need a single pointer.
As a side-effect, this makes the API for updating a `MachineSDNode` and
a `MachineInstr` reasonably different which seems nice to avoid
unexpected coupling of these two layers. We can map between them, but we
shouldn't be *surprised* at where that occurs. =]
Differential Revision: https://reviews.llvm.org/D50680
llvm-svn: 339740
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index f7bd8847bee..8df30fb0349 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -3598,38 +3598,22 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch, bool mayLoad = MCID.mayLoad(); bool mayStore = MCID.mayStore(); - unsigned NumMemRefs = 0; - for (SmallVectorImpl<MachineMemOperand *>::const_iterator I = - MatchedMemRefs.begin(), E = MatchedMemRefs.end(); I != E; ++I) { - if ((*I)->isLoad()) { + // We expect to have relatively few of these so just filter them into a + // temporary buffer so that we can easily add them to the instruction. + SmallVector<MachineMemOperand *, 4> FilteredMemRefs; + for (MachineMemOperand *MMO : MatchedMemRefs) { + if (MMO->isLoad()) { if (mayLoad) - ++NumMemRefs; - } else if ((*I)->isStore()) { + FilteredMemRefs.push_back(MMO); + } else if (MMO->isStore()) { if (mayStore) - ++NumMemRefs; + FilteredMemRefs.push_back(MMO); } else { - ++NumMemRefs; + FilteredMemRefs.push_back(MMO); } } - MachineSDNode::mmo_iterator MemRefs = - MF->allocateMemRefsArray(NumMemRefs); - - MachineSDNode::mmo_iterator MemRefsPos = MemRefs; - for (SmallVectorImpl<MachineMemOperand *>::const_iterator I = - MatchedMemRefs.begin(), E = MatchedMemRefs.end(); I != E; ++I) { - if ((*I)->isLoad()) { - if (mayLoad) - *MemRefsPos++ = *I; - } else if ((*I)->isStore()) { - if (mayStore) - *MemRefsPos++ = *I; - } else { - *MemRefsPos++ = *I; - } - } - - Res->setMemRefs(MemRefs, MemRefs + NumMemRefs); + CurDAG->setNodeMemRefs(Res, FilteredMemRefs); } LLVM_DEBUG(if (!MatchedMemRefs.empty() && Res->memoperands_empty()) dbgs() |

