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