LLVM API Documentation
00001 //===-- LiveStackAnalysis.h - Live Stack Slot Analysis ----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the live stack slot analysis pass. It is analogous to 00011 // live interval analysis except it's analyzing liveness of stack slots rather 00012 // than registers. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_CODEGEN_LIVESTACK_ANALYSIS_H 00017 #define LLVM_CODEGEN_LIVESTACK_ANALYSIS_H 00018 00019 #include "llvm/CodeGen/MachineFunctionPass.h" 00020 #include "llvm/CodeGen/LiveInterval.h" 00021 #include "llvm/Target/TargetRegisterInfo.h" 00022 #include "llvm/Support/Allocator.h" 00023 #include <map> 00024 00025 namespace llvm { 00026 00027 class LiveStacks : public MachineFunctionPass { 00028 /// Special pool allocator for VNInfo's (LiveInterval val#). 00029 /// 00030 BumpPtrAllocator VNInfoAllocator; 00031 00032 /// S2IMap - Stack slot indices to live interval mapping. 00033 /// 00034 typedef std::map<int, LiveInterval> SS2IntervalMap; 00035 SS2IntervalMap S2IMap; 00036 00037 /// S2RCMap - Stack slot indices to register class mapping. 00038 std::map<int, const TargetRegisterClass*> S2RCMap; 00039 00040 public: 00041 static char ID; // Pass identification, replacement for typeid 00042 LiveStacks() : MachineFunctionPass(&ID) {} 00043 00044 typedef SS2IntervalMap::iterator iterator; 00045 typedef SS2IntervalMap::const_iterator const_iterator; 00046 const_iterator begin() const { return S2IMap.begin(); } 00047 const_iterator end() const { return S2IMap.end(); } 00048 iterator begin() { return S2IMap.begin(); } 00049 iterator end() { return S2IMap.end(); } 00050 00051 void scaleNumbering(int factor); 00052 00053 unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); } 00054 00055 LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC) { 00056 assert(Slot >= 0 && "Spill slot indice must be >= 0"); 00057 SS2IntervalMap::iterator I = S2IMap.find(Slot); 00058 if (I == S2IMap.end()) { 00059 I = S2IMap.insert(I,std::make_pair(Slot, LiveInterval(Slot,0.0F,true))); 00060 S2RCMap.insert(std::make_pair(Slot, RC)); 00061 } else { 00062 // Use the largest common subclass register class. 00063 const TargetRegisterClass *OldRC = S2RCMap[Slot]; 00064 S2RCMap[Slot] = getCommonSubClass(OldRC, RC); 00065 } 00066 return I->second; 00067 } 00068 00069 LiveInterval &getInterval(int Slot) { 00070 assert(Slot >= 0 && "Spill slot indice must be >= 0"); 00071 SS2IntervalMap::iterator I = S2IMap.find(Slot); 00072 assert(I != S2IMap.end() && "Interval does not exist for stack slot"); 00073 return I->second; 00074 } 00075 00076 const LiveInterval &getInterval(int Slot) const { 00077 assert(Slot >= 0 && "Spill slot indice must be >= 0"); 00078 SS2IntervalMap::const_iterator I = S2IMap.find(Slot); 00079 assert(I != S2IMap.end() && "Interval does not exist for stack slot"); 00080 return I->second; 00081 } 00082 00083 bool hasInterval(int Slot) const { 00084 return S2IMap.count(Slot); 00085 } 00086 00087 const TargetRegisterClass *getIntervalRegClass(int Slot) const { 00088 assert(Slot >= 0 && "Spill slot indice must be >= 0"); 00089 std::map<int, const TargetRegisterClass*>::const_iterator 00090 I = S2RCMap.find(Slot); 00091 assert(I != S2RCMap.end() && 00092 "Register class info does not exist for stack slot"); 00093 return I->second; 00094 } 00095 00096 BumpPtrAllocator& getVNInfoAllocator() { return VNInfoAllocator; } 00097 00098 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 00099 virtual void releaseMemory(); 00100 00101 /// runOnMachineFunction - pass entry point 00102 virtual bool runOnMachineFunction(MachineFunction&); 00103 00104 /// print - Implement the dump method. 00105 virtual void print(std::ostream &O, const Module* = 0) const; 00106 void print(std::ostream *O, const Module* M = 0) const { 00107 if (O) print(*O, M); 00108 } 00109 }; 00110 } 00111 00112 #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */