EdgeBundles.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-------- EdgeBundles.h - Bundles of CFG edges --------------*- c++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // The EdgeBundles analysis forms equivalence classes of CFG edges such that all
  15. // edges leaving a machine basic block are in the same bundle, and all edges
  16. // entering a machine basic block are in the same bundle.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CODEGEN_EDGEBUNDLES_H
  20. #define LLVM_CODEGEN_EDGEBUNDLES_H
  21. #include "llvm/ADT/ArrayRef.h"
  22. #include "llvm/ADT/IntEqClasses.h"
  23. #include "llvm/CodeGen/MachineFunctionPass.h"
  24. namespace llvm {
  25. class EdgeBundles : public MachineFunctionPass {
  26. const MachineFunction *MF;
  27. /// EC - Each edge bundle is an equivalence class. The keys are:
  28. /// 2*BB->getNumber() -> Ingoing bundle.
  29. /// 2*BB->getNumber()+1 -> Outgoing bundle.
  30. IntEqClasses EC;
  31. /// Blocks - Map each bundle to a list of basic block numbers.
  32. SmallVector<SmallVector<unsigned, 8>, 4> Blocks;
  33. public:
  34. static char ID;
  35. EdgeBundles() : MachineFunctionPass(ID) {}
  36. /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
  37. /// bundle number for basic block #N
  38. unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
  39. /// getNumBundles - Return the total number of bundles in the CFG.
  40. unsigned getNumBundles() const { return EC.getNumClasses(); }
  41. /// getBlocks - Return an array of blocks that are connected to Bundle.
  42. ArrayRef<unsigned> getBlocks(unsigned Bundle) const { return Blocks[Bundle]; }
  43. /// getMachineFunction - Return the last machine function computed.
  44. const MachineFunction *getMachineFunction() const { return MF; }
  45. /// view - Visualize the annotated bipartite CFG with Graphviz.
  46. void view() const;
  47. private:
  48. bool runOnMachineFunction(MachineFunction&) override;
  49. void getAnalysisUsage(AnalysisUsage&) const override;
  50. };
  51. } // end namespace llvm
  52. #endif
  53. #ifdef __GNUC__
  54. #pragma GCC diagnostic pop
  55. #endif