1 //===-- LiveStackAnalysis.h - Live Stack Slot Analysis ----------*- 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 implements the live stack slot analysis pass. It is analogous to
11 // live interval analysis except it's analyzing liveness of stack slots rather
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_LIVESTACK_ANALYSIS_H
17 #define LLVM_CODEGEN_LIVESTACK_ANALYSIS_H
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/CodeGen/LiveInterval.h"
21 #include "llvm/Support/Allocator.h"
26 class LiveStacks : public MachineFunctionPass {
27 /// Special pool allocator for VNInfo's (LiveInterval val#).
29 BumpPtrAllocator VNInfoAllocator;
31 /// s2iMap - Stack slot indices to live interval mapping.
33 typedef std::map<int, LiveInterval> SS2IntervalMap;
34 SS2IntervalMap s2iMap;
37 static char ID; // Pass identification, replacement for typeid
38 LiveStacks() : MachineFunctionPass(&ID) {}
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(); }
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)));
55 LiveInterval &getInterval(int Slot) {
56 SS2IntervalMap::iterator I = s2iMap.find(Slot);
57 assert(I != s2iMap.end() && "Interval does not exist for stack slot");
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");
67 bool hasInterval(unsigned reg) const {
68 return s2iMap.count(reg);
71 BumpPtrAllocator& getVNInfoAllocator() { return VNInfoAllocator; }
73 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
74 virtual void releaseMemory();
76 /// runOnMachineFunction - pass entry point
77 virtual bool runOnMachineFunction(MachineFunction&);
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 {
87 #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */