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/Target/TargetRegisterInfo.h"
22 #include "llvm/Support/Allocator.h"
27 class LiveStacks : public MachineFunctionPass {
28 /// Special pool allocator for VNInfo's (LiveInterval val#).
30 BumpPtrAllocator VNInfoAllocator;
32 /// S2IMap - Stack slot indices to live interval mapping.
34 typedef std::map<int, LiveInterval> SS2IntervalMap;
35 SS2IntervalMap S2IMap;
37 /// S2RCMap - Stack slot indices to register class mapping.
38 std::map<int, const TargetRegisterClass*> S2RCMap;
41 static char ID; // Pass identification, replacement for typeid
42 LiveStacks() : MachineFunctionPass(&ID) {}
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(); }
51 void scaleNumbering(int factor);
53 unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
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));
62 // Use the largest common subclass register class.
63 const TargetRegisterClass *OldRC = S2RCMap[Slot];
64 S2RCMap[Slot] = getCommonSubClass(OldRC, RC);
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");
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");
83 bool hasInterval(int Slot) const {
84 return S2IMap.count(Slot);
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");
96 BumpPtrAllocator& getVNInfoAllocator() { return VNInfoAllocator; }
98 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
99 virtual void releaseMemory();
101 /// runOnMachineFunction - pass entry point
102 virtual bool runOnMachineFunction(MachineFunction&);
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 {
112 #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */