David Majnemer | 9789023 | 2015-09-17 20:45:18 +0000 | [diff] [blame] | 1 | //===-- FuncletLayout.cpp - Contiguously lay out funclets -----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements basic block placement transformations which result in |
| 11 | // funclets being contiguous. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #include "llvm/CodeGen/Passes.h" |
David Majnemer | 1619355 | 2015-10-04 02:22:52 +0000 | [diff] [blame^] | 15 | #include "llvm/CodeGen/Analysis.h" |
David Majnemer | 9789023 | 2015-09-17 20:45:18 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFunction.h" |
| 17 | #include "llvm/CodeGen/MachineFunctionPass.h" |
David Majnemer | 9789023 | 2015-09-17 20:45:18 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
| 20 | #define DEBUG_TYPE "funclet-layout" |
| 21 | |
| 22 | namespace { |
| 23 | class FuncletLayout : public MachineFunctionPass { |
| 24 | public: |
| 25 | static char ID; // Pass identification, replacement for typeid |
| 26 | FuncletLayout() : MachineFunctionPass(ID) { |
| 27 | initializeFuncletLayoutPass(*PassRegistry::getPassRegistry()); |
| 28 | } |
| 29 | |
| 30 | bool runOnMachineFunction(MachineFunction &F) override; |
| 31 | }; |
| 32 | } |
| 33 | |
David Majnemer | 9789023 | 2015-09-17 20:45:18 +0000 | [diff] [blame] | 34 | char FuncletLayout::ID = 0; |
| 35 | char &llvm::FuncletLayoutID = FuncletLayout::ID; |
| 36 | INITIALIZE_PASS(FuncletLayout, "funclet-layout", |
| 37 | "Contiguously Lay Out Funclets", false, false) |
| 38 | |
| 39 | bool FuncletLayout::runOnMachineFunction(MachineFunction &F) { |
David Majnemer | 1619355 | 2015-10-04 02:22:52 +0000 | [diff] [blame^] | 40 | DenseMap<const MachineBasicBlock *, int> FuncletMembership = |
| 41 | getFuncletMembership(F); |
| 42 | if (FuncletMembership.empty()) |
David Majnemer | 9789023 | 2015-09-17 20:45:18 +0000 | [diff] [blame] | 43 | return false; |
| 44 | |
David Majnemer | 9966fe8 | 2015-09-18 08:18:07 +0000 | [diff] [blame] | 45 | F.sort([&](MachineBasicBlock &x, MachineBasicBlock &y) { |
| 46 | return FuncletMembership[&x] < FuncletMembership[&y]; |
| 47 | }); |
David Majnemer | 9789023 | 2015-09-17 20:45:18 +0000 | [diff] [blame] | 48 | |
| 49 | // Conservatively assume we changed something. |
| 50 | return true; |
| 51 | } |