FuncletLayout.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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"
  15. #include "llvm/CodeGen/Analysis.h"
  16. #include "llvm/CodeGen/MachineFunction.h"
  17. #include "llvm/CodeGen/MachineFunctionPass.h"
  18. using namespace llvm;
  19. #define DEBUG_TYPE "funclet-layout"
  20. namespace {
  21. class FuncletLayout : public MachineFunctionPass {
  22. public:
  23. static char ID; // Pass identification, replacement for typeid
  24. FuncletLayout() : MachineFunctionPass(ID) {
  25. initializeFuncletLayoutPass(*PassRegistry::getPassRegistry());
  26. }
  27. bool runOnMachineFunction(MachineFunction &F) override;
  28. };
  29. }
  30. char FuncletLayout::ID = 0;
  31. char &llvm::FuncletLayoutID = FuncletLayout::ID;
  32. INITIALIZE_PASS(FuncletLayout, "funclet-layout",
  33. "Contiguously Lay Out Funclets", false, false)
  34. bool FuncletLayout::runOnMachineFunction(MachineFunction &F) {
  35. DenseMap<const MachineBasicBlock *, int> FuncletMembership =
  36. getFuncletMembership(F);
  37. if (FuncletMembership.empty())
  38. return false;
  39. F.sort([&](MachineBasicBlock &x, MachineBasicBlock &y) {
  40. return FuncletMembership[&x] < FuncletMembership[&y];
  41. });
  42. // Conservatively assume we changed something.
  43. return true;
  44. }