Fix the name of an argument.
[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/Support/Allocator.h"
22 #include <map>
23
24 namespace llvm {
25
26   class LiveStacks : public MachineFunctionPass {
27     /// Special pool allocator for VNInfo's (LiveInterval val#).
28     ///
29     BumpPtrAllocator VNInfoAllocator;
30
31     /// s2iMap - Stack slot indices to live interval mapping.
32     ///
33     typedef std::map<int, LiveInterval> SS2IntervalMap;
34     SS2IntervalMap s2iMap;
35
36   public:
37     static char ID; // Pass identification, replacement for typeid
38     LiveStacks() : MachineFunctionPass(&ID) {}
39
40     typedef SS2IntervalMap::iterator iterator;
41     typedef SS2IntervalMap::const_iterator const_iterator;
42     const_iterator begin() const { return s2iMap.begin(); }
43     const_iterator end() const { return s2iMap.end(); }
44     iterator begin() { return s2iMap.begin(); }
45     iterator end() { return s2iMap.end(); }
46     unsigned getNumIntervals() const { return (unsigned)s2iMap.size(); }
47
48     LiveInterval &getOrCreateInterval(int Slot) {
49       SS2IntervalMap::iterator I = s2iMap.find(Slot);
50       if (I == s2iMap.end())
51         I = s2iMap.insert(I,std::make_pair(Slot,LiveInterval(Slot,0.0F,true)));
52       return I->second;
53     }
54
55     LiveInterval &getInterval(int Slot) {
56       SS2IntervalMap::iterator I = s2iMap.find(Slot);
57       assert(I != s2iMap.end() && "Interval does not exist for stack slot");
58       return I->second;
59     }
60
61     const LiveInterval &getInterval(int Slot) const {
62       SS2IntervalMap::const_iterator I = s2iMap.find(Slot);
63       assert(I != s2iMap.end() && "Interval does not exist for stack slot");
64       return I->second;
65     }
66
67     bool hasInterval(unsigned Slot) const {
68       return s2iMap.count(Slot);
69     }
70
71     BumpPtrAllocator& getVNInfoAllocator() { return VNInfoAllocator; }
72
73     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
74     virtual void releaseMemory();
75
76     /// runOnMachineFunction - pass entry point
77     virtual bool runOnMachineFunction(MachineFunction&);
78
79     /// print - Implement the dump method.
80     virtual void print(std::ostream &O, const Module* = 0) const;
81     void print(std::ostream *O, const Module* M = 0) const {
82       if (O) print(*O, M);
83     }
84   };
85 }
86
87 #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */