diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-02-19 17:15:17 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-02-19 17:15:17 +0000 |
commit | 7b2e91fb59b4608ccade3c364b5445257d41c37c (patch) | |
tree | c11a0b7d065b3f9bbc032c26dcb13090a665e61f /llvm/lib/CodeGen/SelectionDAG | |
parent | 622ab96c85adc7660cc4e39b5610b0a0e092b8fb (diff) | |
download | bcm5719-llvm-7b2e91fb59b4608ccade3c364b5445257d41c37c.tar.gz bcm5719-llvm-7b2e91fb59b4608ccade3c364b5445257d41c37c.zip |
[StatepointLowering] Clean up allocateStackSlot
This removes the unusual loop structure in allocateStackSlot in favor of
something more straightforward. I've also removed the cautionary
comment in the function, which I suspect is historical cruft now, and
confuses more than it enlightens.
llvm-svn: 261335
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp index 5b9c614476d..fdc02ee3bee 100644 --- a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp @@ -72,49 +72,36 @@ void StatepointLoweringState::clear() { SDValue StatepointLoweringState::allocateStackSlot(EVT ValueType, SelectionDAGBuilder &Builder) { - NumSlotsAllocatedForStatepoints++; - // The basic scheme here is to first look for a previously created stack slot - // which is not in use (accounting for the fact arbitrary slots may already - // be reserved), or to create a new stack slot and use it. - - // If this doesn't succeed in 40000 iterations, something is seriously wrong - for (int i = 0; i < 40000; i++) { - assert(Builder.FuncInfo.StatepointStackSlots.size() == - AllocatedStackSlots.size() && - "broken invariant"); - const size_t NumSlots = AllocatedStackSlots.size(); - assert(NextSlotToAllocate <= NumSlots && "broken invariant"); - - if (NextSlotToAllocate >= NumSlots) { - assert(NextSlotToAllocate == NumSlots); - // record stats - if (NumSlots + 1 > StatepointMaxSlotsRequired) { - StatepointMaxSlotsRequired = NumSlots + 1; - } - - SDValue SpillSlot = Builder.DAG.CreateStackTemporary(ValueType); - const unsigned FI = cast<FrameIndexSDNode>(SpillSlot)->getIndex(); - auto *MFI = Builder.DAG.getMachineFunction().getFrameInfo(); - MFI->markAsStatepointSpillSlotObjectIndex(FI); - - Builder.FuncInfo.StatepointStackSlots.push_back(FI); - AllocatedStackSlots.push_back(true); - return SpillSlot; - } + // First look for a previously created stack slot which is not in + // use (accounting for the fact arbitrary slots may already be + // reserved), or to create a new stack slot and use it. + + const size_t NumSlots = AllocatedStackSlots.size(); + assert(NextSlotToAllocate <= NumSlots && "Broken invariant"); + + for (; NextSlotToAllocate < NumSlots; NextSlotToAllocate++) { if (!AllocatedStackSlots[NextSlotToAllocate]) { const int FI = Builder.FuncInfo.StatepointStackSlots[NextSlotToAllocate]; AllocatedStackSlots[NextSlotToAllocate] = true; return Builder.DAG.getFrameIndex(FI, ValueType); } - // Note: We deliberately choose to advance this only on the failing path. - // Doing so on the succeeding path involves a bit of complexity that caused - // a minor bug previously. Unless performance shows this matters, please - // keep this code as simple as possible. - NextSlotToAllocate++; } - llvm_unreachable("infinite loop?"); + + // Couldn't find a free slot, so create a new one: + + StatepointMaxSlotsRequired = + std::max<unsigned long>(StatepointMaxSlotsRequired, NumSlots + 1); + + SDValue SpillSlot = Builder.DAG.CreateStackTemporary(ValueType); + const unsigned FI = cast<FrameIndexSDNode>(SpillSlot)->getIndex(); + auto *MFI = Builder.DAG.getMachineFunction().getFrameInfo(); + MFI->markAsStatepointSpillSlotObjectIndex(FI); + + Builder.FuncInfo.StatepointStackSlots.push_back(FI); + AllocatedStackSlots.push_back(true); + return SpillSlot; } /// Utility function for reservePreviousStackSlotForValue. Tries to find |