Update to in-place spilling framework. Includes live interval scaling and trivial...
[oota-llvm.git] / include / llvm / CodeGen / LiveStackAnalysis.h
1 //===-- LiveStackAnalysis.h - Live Stack Slot Analysis ----------*- 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 implements the live stack slot analysis pass. It is analogous to
11 // live interval analysis except it's analyzing liveness of stack slots rather
12 // than registers.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_LIVESTACK_ANALYSIS_H
17 #define LLVM_CODEGEN_LIVESTACK_ANALYSIS_H
18
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/CodeGen/LiveInterval.h"
21 #include "llvm/Target/TargetRegisterInfo.h"
22 #include "llvm/Support/Allocator.h"
23 #include <map>
24
25 namespace llvm {
26
27   class LiveStacks : public MachineFunctionPass {
28     /// Special pool allocator for VNInfo's (LiveInterval val#).
29     ///
30     BumpPtrAllocator VNInfoAllocator;
31
32     /// S2IMap - Stack slot indices to live interval mapping.
33     ///
34     typedef std::map<int, LiveInterval> SS2IntervalMap;
35     SS2IntervalMap S2IMap;
36
37     /// S2RCMap - Stack slot indices to register class mapping.
38     std::map<int, const TargetRegisterClass*> S2RCMap;
39     
40   public:
41     static char ID; // Pass identification, replacement for typeid
42     LiveStacks() : MachineFunctionPass(&ID) {}
43
44     typedef SS2IntervalMap::iterator iterator;
45     typedef SS2IntervalMap::const_iterator const_iterator;
46     const_iterator begin() const { return S2IMap.begin(); }
47     const_iterator end() const { return S2IMap.end(); }
48     iterator begin() { return S2IMap.begin(); }
49     iterator end() { return S2IMap.end(); }
50
51     void scaleNumbering(int factor);
52
53     unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
54
55     LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC) {
56       assert(Slot >= 0 && "Spill slot indice must be >= 0");
57       SS2IntervalMap::iterator I = S2IMap.find(Slot);
58       if (I == S2IMap.end()) {
59         I = S2IMap.insert(I,std::make_pair(Slot, LiveInterval(Slot,0.0F,true)));
60         S2RCMap.insert(std::make_pair(Slot, RC));
61       } else {
62         // Use the largest common subclass register class.
63         const TargetRegisterClass *OldRC = S2RCMap[Slot];
64         S2RCMap[Slot] = getCommonSubClass(OldRC, RC);
65       }
66       return I->second;
67     }
68
69     LiveInterval &getInterval(int Slot) {
70       assert(Slot >= 0 && "Spill slot indice must be >= 0");
71       SS2IntervalMap::iterator I = S2IMap.find(Slot);
72       assert(I != S2IMap.end() && "Interval does not exist for stack slot");
73       return I->second;
74     }
75
76     const LiveInterval &getInterval(int Slot) const {
77       assert(Slot >= 0 && "Spill slot indice must be >= 0");
78       SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
79       assert(I != S2IMap.end() && "Interval does not exist for stack slot");
80       return I->second;
81     }
82
83     bool hasInterval(int Slot) const {
84       return S2IMap.count(Slot);
85     }
86
87     const TargetRegisterClass *getIntervalRegClass(int Slot) const {
88       assert(Slot >= 0 && "Spill slot indice must be >= 0");
89       std::map<int, const TargetRegisterClass*>::const_iterator
90         I = S2RCMap.find(Slot);
91       assert(I != S2RCMap.end() &&
92              "Register class info does not exist for stack slot");
93       return I->second;
94     }
95
96     BumpPtrAllocator& getVNInfoAllocator() { return VNInfoAllocator; }
97
98     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
99     virtual void releaseMemory();
100
101     /// runOnMachineFunction - pass entry point
102     virtual bool runOnMachineFunction(MachineFunction&);
103
104     /// print - Implement the dump method.
105     virtual void print(std::ostream &O, const Module* = 0) const;
106     void print(std::ostream *O, const Module* M = 0) const {
107       if (O) print(*O, M);
108     }
109   };
110 }
111
112 #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */