1193323Sed//===-- LiveStackAnalysis.h - Live Stack Slot Analysis ----------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file implements the live stack slot analysis pass. It is analogous to 11193323Sed// live interval analysis except it's analyzing liveness of stack slots rather 12193323Sed// than registers. 13193323Sed// 14193323Sed//===----------------------------------------------------------------------===// 15193323Sed 16249423Sdim#ifndef LLVM_CODEGEN_LIVESTACKANALYSIS_H 17249423Sdim#define LLVM_CODEGEN_LIVESTACKANALYSIS_H 18193323Sed 19249423Sdim#include "llvm/CodeGen/LiveInterval.h" 20193323Sed#include "llvm/CodeGen/MachineFunctionPass.h" 21249423Sdim#include "llvm/Support/Allocator.h" 22193323Sed#include "llvm/Target/TargetRegisterInfo.h" 23193323Sed#include <map> 24193323Sed 25193323Sednamespace llvm { 26193323Sed 27193323Sed class LiveStacks : public MachineFunctionPass { 28226633Sdim const TargetRegisterInfo *TRI; 29226633Sdim 30193323Sed /// Special pool allocator for VNInfo's (LiveInterval val#). 31193323Sed /// 32206083Srdivacky VNInfo::Allocator VNInfoAllocator; 33193323Sed 34193323Sed /// S2IMap - Stack slot indices to live interval mapping. 35193323Sed /// 36193323Sed typedef std::map<int, LiveInterval> SS2IntervalMap; 37193323Sed SS2IntervalMap S2IMap; 38193323Sed 39193323Sed /// S2RCMap - Stack slot indices to register class mapping. 40193323Sed std::map<int, const TargetRegisterClass*> S2RCMap; 41193323Sed 42193323Sed public: 43193323Sed static char ID; // Pass identification, replacement for typeid 44218893Sdim LiveStacks() : MachineFunctionPass(ID) { 45218893Sdim initializeLiveStacksPass(*PassRegistry::getPassRegistry()); 46218893Sdim } 47193323Sed 48193323Sed typedef SS2IntervalMap::iterator iterator; 49193323Sed typedef SS2IntervalMap::const_iterator const_iterator; 50193323Sed const_iterator begin() const { return S2IMap.begin(); } 51193323Sed const_iterator end() const { return S2IMap.end(); } 52193323Sed iterator begin() { return S2IMap.begin(); } 53193323Sed iterator end() { return S2IMap.end(); } 54193323Sed 55193323Sed unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); } 56193323Sed 57218893Sdim LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC); 58193323Sed 59193323Sed LiveInterval &getInterval(int Slot) { 60193323Sed assert(Slot >= 0 && "Spill slot indice must be >= 0"); 61193323Sed SS2IntervalMap::iterator I = S2IMap.find(Slot); 62193323Sed assert(I != S2IMap.end() && "Interval does not exist for stack slot"); 63193323Sed return I->second; 64193323Sed } 65193323Sed 66193323Sed const LiveInterval &getInterval(int Slot) const { 67193323Sed assert(Slot >= 0 && "Spill slot indice must be >= 0"); 68193323Sed SS2IntervalMap::const_iterator I = S2IMap.find(Slot); 69193323Sed assert(I != S2IMap.end() && "Interval does not exist for stack slot"); 70193323Sed return I->second; 71193323Sed } 72193323Sed 73193323Sed bool hasInterval(int Slot) const { 74193323Sed return S2IMap.count(Slot); 75193323Sed } 76193323Sed 77193323Sed const TargetRegisterClass *getIntervalRegClass(int Slot) const { 78193323Sed assert(Slot >= 0 && "Spill slot indice must be >= 0"); 79193323Sed std::map<int, const TargetRegisterClass*>::const_iterator 80193323Sed I = S2RCMap.find(Slot); 81193323Sed assert(I != S2RCMap.end() && 82193323Sed "Register class info does not exist for stack slot"); 83193323Sed return I->second; 84193323Sed } 85193323Sed 86206083Srdivacky VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; } 87193323Sed 88193323Sed virtual void getAnalysisUsage(AnalysisUsage &AU) const; 89193323Sed virtual void releaseMemory(); 90193323Sed 91193323Sed /// runOnMachineFunction - pass entry point 92193323Sed virtual bool runOnMachineFunction(MachineFunction&); 93193323Sed 94193323Sed /// print - Implement the dump method. 95198090Srdivacky virtual void print(raw_ostream &O, const Module* = 0) const; 96193323Sed }; 97193323Sed} 98193323Sed 99193323Sed#endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */ 100