1 //===- MachineLoopRanges.h - Ranges of machine loops -----------*- c++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides the interface to the MachineLoopRanges analysis.
12 // Provide on-demand information about the ranges of machine instructions
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CODEGEN_MACHINELOOPRANGES_H
18 #define LLVM_CODEGEN_MACHINELOOPRANGES_H
20 #include "llvm/ADT/IntervalMap.h"
21 #include "llvm/CodeGen/SlotIndexes.h"
26 class MachineLoopInfo;
29 /// MachineLoopRange - Range information for a single loop.
30 class MachineLoopRange {
31 friend class MachineLoopRanges;
34 typedef IntervalMap<SlotIndex, unsigned, 4> Map;
35 typedef Map::Allocator Allocator;
39 const MachineLoop *const Loop;
41 /// Map intervals to a bit mask.
42 /// Bit 0 = inside loop block.
45 /// Loop area as measured by SlotIndex::distance.
48 /// Create a MachineLoopRange, only accessible to MachineLoopRanges.
49 MachineLoopRange(const MachineLoop*, Allocator&, SlotIndexes&);
52 /// getLoop - Return the mapped machine loop.
53 const MachineLoop *getLoop() const { return Loop; }
55 /// overlaps - Return true if this loop overlaps the given range of machine
57 bool overlaps(SlotIndex Start, SlotIndex Stop);
59 /// getNumber - Return the loop number. This is the same as the number of the
61 unsigned getNumber() const;
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; }
67 /// getMap - Allow public read-only access for IntervalMapOverlaps.
68 const Map &getMap() { return Intervals; }
70 /// print - Print loop ranges on OS.
71 void print(raw_ostream&) const;
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*);
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*);
82 raw_ostream &operator<<(raw_ostream&, const MachineLoopRange&);
84 /// MachineLoopRanges - Analysis pass that provides on-demand per-loop range
86 class MachineLoopRanges : public MachineFunctionPass {
87 typedef DenseMap<const MachineLoop*, MachineLoopRange*> CacheMap;
88 typedef MachineLoopRange::Allocator MapAllocator;
90 MapAllocator Allocator;
95 static char ID; // Pass identification, replacement for typeid
97 MachineLoopRanges() : MachineFunctionPass(ID), Indexes(0) {}
98 ~MachineLoopRanges() { releaseMemory(); }
100 /// getLoopRange - Return the range of loop.
101 MachineLoopRange *getLoopRange(const MachineLoop *Loop);
104 virtual bool runOnMachineFunction(MachineFunction&);
105 virtual void releaseMemory();
106 virtual void getAnalysisUsage(AnalysisUsage&) const;
110 } // end namespace llvm
112 #endif // LLVM_CODEGEN_MACHINELOOPRANGES_H