[llvm] r247978 - [WinEH] Moved funclet pads should be in relative order
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 18 01:18:08 PDT 2015
Author: majnemer
Date: Fri Sep 18 03:18:07 2015
New Revision: 247978
URL: http://llvm.org/viewvc/llvm-project?rev=247978&view=rev
Log:
[WinEH] Moved funclet pads should be in relative order
We shifted the MachineBasicBlocks to the end of the MachineFunction in
DFS order. This will not ensure that MachineBasicBlocks which fell
through to one another will remain contiguous. Instead, implement
a stable sort algorithm for iplist.
This partially reverts commit r214150.
Modified:
llvm/trunk/include/llvm/ADT/ilist.h
llvm/trunk/include/llvm/CodeGen/MachineFunction.h
llvm/trunk/lib/CodeGen/FuncletLayout.cpp
Modified: llvm/trunk/include/llvm/ADT/ilist.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ilist.h?rev=247978&r1=247977&r2=247978&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ilist.h (original)
+++ llvm/trunk/include/llvm/ADT/ilist.h Fri Sep 18 03:18:07 2015
@@ -579,6 +579,53 @@ public:
void splice(iterator where, iplist &L2, iterator first, iterator last) {
if (first != last) transfer(where, L2, first, last);
}
+
+ template <class Compare>
+ void merge(iplist &Right, Compare comp) {
+ if (this == &Right)
+ return;
+ iterator First1 = begin(), Last1 = end();
+ iterator First2 = Right.begin(), Last2 = Right.end();
+ while (First1 != Last1 && First2 != Last2) {
+ if (comp(*First2, *First1)) {
+ iterator Next = First2;
+ transfer(First1, Right, First2, ++Next);
+ First2 = Next;
+ } else {
+ ++First1;
+ }
+ }
+ if (First2 != Last2)
+ transfer(Last1, Right, First2, Last2);
+ }
+ void merge(iplist &Right) { return merge(Right, op_less); }
+
+ template <class Compare>
+ void sort(Compare comp) {
+ // The list is empty, vacuously sorted.
+ if (empty())
+ return;
+ // The list has a single element, vacuously sorted.
+ if (std::next(begin()) == end())
+ return;
+ // Find the split point for the list.
+ iterator Center = begin(), End = begin();
+ while (End != end() && std::next(End) != end()) {
+ Center = std::next(Center);
+ End = std::next(std::next(End));
+ }
+ // Split the list into two.
+ iplist RightHalf;
+ RightHalf.splice(RightHalf.begin(), *this, Center, end());
+
+ // Sort the two sublists.
+ sort(comp);
+ RightHalf.sort(comp);
+
+ // Merge the two sublists back together.
+ merge(RightHalf, comp);
+ }
+ void sort() { sort(op_less); }
};
Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=247978&r1=247977&r2=247978&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Fri Sep 18 03:18:07 2015
@@ -375,6 +375,11 @@ public:
BasicBlocks.erase(MBBI);
}
+ template <typename Comp>
+ void sort(Comp comp) {
+ BasicBlocks.sort(comp);
+ }
+
//===--------------------------------------------------------------------===//
// Internal functions used to automatically number MachineBasicBlocks
//
Modified: llvm/trunk/lib/CodeGen/FuncletLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/FuncletLayout.cpp?rev=247978&r1=247977&r2=247978&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/FuncletLayout.cpp (original)
+++ llvm/trunk/lib/CodeGen/FuncletLayout.cpp Fri Sep 18 03:18:07 2015
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/Passes.h"
-#include "llvm/ADT/MapVector.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -34,7 +33,7 @@ public:
}
static void
-collectFuncletMembers(MapVector<MachineBasicBlock *, int> &FuncletMembership,
+collectFuncletMembers(DenseMap<MachineBasicBlock *, int> &FuncletMembership,
int Funclet, MachineBasicBlock *MBB) {
// Don't revisit blocks.
if (FuncletMembership.count(MBB) > 0)
@@ -81,16 +80,13 @@ bool FuncletLayout::runOnMachineFunction
if (FuncletBlocks.empty())
return false;
- MapVector<MachineBasicBlock *, int> FuncletMembership;
+ DenseMap<MachineBasicBlock *, int> FuncletMembership;
for (MachineBasicBlock *MBB : FuncletBlocks)
collectFuncletMembers(FuncletMembership, MBB->getNumber(), MBB);
- for (std::pair<llvm::MachineBasicBlock *, int> &FuncletMember :
- FuncletMembership) {
- // Move this block to the end of the function.
- MachineBasicBlock *MBB = FuncletMember.first;
- MBB->moveAfter(--F.end());
- }
+ F.sort([&](MachineBasicBlock &x, MachineBasicBlock &y) {
+ return FuncletMembership[&x] < FuncletMembership[&y];
+ });
// Conservatively assume we changed something.
return true;
More information about the llvm-commits
mailing list