Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.4 KiB

  1. //===- MachineLoopRanges.h - Ranges of machine loops -----------*- c++ -*--===//
  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 provides the interface to the MachineLoopRanges analysis.
  11. //
  12. // Provide on-demand information about the ranges of machine instructions
  13. // covered by a loop.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_CODEGEN_MACHINELOOPRANGES_H
  17. #define LLVM_CODEGEN_MACHINELOOPRANGES_H
  18. #include "llvm/ADT/IntervalMap.h"
  19. #include "llvm/CodeGen/SlotIndexes.h"
  20. namespace llvm {
  21. class MachineLoop;
  22. class MachineLoopInfo;
  23. class raw_ostream;
  24. /// MachineLoopRange - Range information for a single loop.
  25. class MachineLoopRange {
  26. friend class MachineLoopRanges;
  27. public:
  28. typedef IntervalMap<SlotIndex, unsigned, 4> Map;
  29. typedef Map::Allocator Allocator;
  30. private:
  31. /// The mapped loop.
  32. const MachineLoop *const Loop;
  33. /// Map intervals to a bit mask.
  34. /// Bit 0 = inside loop block.
  35. Map Intervals;
  36. /// Loop area as measured by SlotIndex::distance.
  37. unsigned Area;
  38. /// Create a MachineLoopRange, only accessible to MachineLoopRanges.
  39. MachineLoopRange(const MachineLoop*, Allocator&, SlotIndexes&);
  40. public:
  41. /// getLoop - Return the mapped machine loop.
  42. const MachineLoop *getLoop() const { return Loop; }
  43. /// overlaps - Return true if this loop overlaps the given range of machine
  44. /// inteructions.
  45. bool overlaps(SlotIndex Start, SlotIndex Stop);
  46. /// getNumber - Return the loop number. This is the same as the number of the
  47. /// header block.
  48. unsigned getNumber() const;
  49. /// getArea - Return the loop area. This number is approximately proportional
  50. /// to the number of instructions in the loop.
  51. unsigned getArea() const { return Area; }
  52. /// getMap - Allow public read-only access for IntervalMapOverlaps.
  53. const Map &getMap() { return Intervals; }
  54. /// print - Print loop ranges on OS.
  55. void print(raw_ostream&) const;
  56. /// byNumber - Comparator for array_pod_sort that sorts a list of
  57. /// MachineLoopRange pointers by number.
  58. static int byNumber(const void*, const void*);
  59. /// byAreaDesc - Comparator for array_pod_sort that sorts a list of
  60. /// MachineLoopRange pointers by descending area, then by number.
  61. static int byAreaDesc(const void*, const void*);
  62. };
  63. raw_ostream &operator<<(raw_ostream&, const MachineLoopRange&);
  64. /// MachineLoopRanges - Analysis pass that provides on-demand per-loop range
  65. /// information.
  66. class MachineLoopRanges : public MachineFunctionPass {
  67. typedef DenseMap<const MachineLoop*, MachineLoopRange*> CacheMap;
  68. typedef MachineLoopRange::Allocator MapAllocator;
  69. MapAllocator Allocator;
  70. SlotIndexes *Indexes;
  71. CacheMap Cache;
  72. public:
  73. static char ID; // Pass identification, replacement for typeid
  74. MachineLoopRanges() : MachineFunctionPass(ID), Indexes(0) {}
  75. ~MachineLoopRanges() { releaseMemory(); }
  76. /// getLoopRange - Return the range of loop.
  77. MachineLoopRange *getLoopRange(const MachineLoop *Loop);
  78. private:
  79. virtual bool runOnMachineFunction(MachineFunction&);
  80. virtual void releaseMemory();
  81. virtual void getAnalysisUsage(AnalysisUsage&) const;
  82. };
  83. } // end namespace llvm
  84. #endif // LLVM_CODEGEN_MACHINELOOPRANGES_H