[PATCH] D25188: Fix nondeterministic output in local stack slot alloc pass
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 3 07:31:23 PDT 2016
arsenm created this revision.
arsenm added a subscriber: llvm-commits.
Herald added a subscriber: wdng.
This finds all of the references to a frame index in a function, and
sorts by the offset. If multiple instructions use the same offset,
nothing was breaking the tie for sorting.
This avoids the test failures the reverted r282999 introduced.
https://reviews.llvm.org/D25188
Files:
lib/CodeGen/LocalStackSlotAllocation.cpp
Index: lib/CodeGen/LocalStackSlotAllocation.cpp
===================================================================
--- lib/CodeGen/LocalStackSlotAllocation.cpp
+++ lib/CodeGen/LocalStackSlotAllocation.cpp
@@ -51,11 +51,19 @@
MachineBasicBlock::iterator MI; // Instr referencing the frame
int64_t LocalOffset; // Local offset of the frame idx referenced
int FrameIdx; // The frame index
+
+ // Order reference instruction appears in program. Used to ensure
+ // deterministic order when multiple instructions may reference the same
+ // location.
+ unsigned Order;
+
public:
- FrameRef(MachineBasicBlock::iterator I, int64_t Offset, int Idx) :
- MI(I), LocalOffset(Offset), FrameIdx(Idx) {}
+ FrameRef(MachineInstr *I, int64_t Offset, int Idx, unsigned Ord) :
+ MI(I), LocalOffset(Offset), FrameIdx(Idx), Order(Ord) {}
bool operator<(const FrameRef &RHS) const {
- return LocalOffset < RHS.LocalOffset;
+ if (LocalOffset < RHS.LocalOffset)
+ return true;
+ return Order < RHS.Order;
}
MachineBasicBlock::iterator getMachineInstr() const { return MI; }
int64_t getLocalOffset() const { return LocalOffset; }
@@ -285,6 +293,8 @@
// choose the first one).
SmallVector<FrameRef, 64> FrameReferenceInsns;
+ unsigned Order = 0;
+
for (MachineBasicBlock &BB : Fn) {
for (MachineInstr &MI : BB) {
// Debug value, stackmap and patchpoint instructions can't be out of
@@ -311,7 +321,7 @@
int64_t LocalOffset = LocalOffsets[Idx];
if (!TRI->needsFrameBaseReg(&MI, LocalOffset))
break;
- FrameReferenceInsns.push_back(FrameRef(&MI, LocalOffset, Idx));
+ FrameReferenceInsns.push_back(FrameRef(&MI, LocalOffset, Idx, Order++));
break;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25188.73279.patch
Type: text/x-patch
Size: 1846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161003/b35a4c31/attachment.bin>
More information about the llvm-commits
mailing list