LLVM API Documentation

LiveStackAnalysis.h

Go to the documentation of this file.
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/Support/Allocator.h"
00022 #include <map>
00023 
00024 namespace llvm {
00025 
00026   class LiveStacks : public MachineFunctionPass {
00027     /// Special pool allocator for VNInfo's (LiveInterval val#).
00028     ///
00029     BumpPtrAllocator VNInfoAllocator;
00030 
00031     /// s2iMap - Stack slot indices to live interval mapping.
00032     ///
00033     typedef std::map<int, LiveInterval> SS2IntervalMap;
00034     SS2IntervalMap s2iMap;
00035 
00036   public:
00037     static char ID; // Pass identification, replacement for typeid
00038     LiveStacks() : MachineFunctionPass(&ID) {}
00039 
00040     typedef SS2IntervalMap::iterator iterator;
00041     typedef SS2IntervalMap::const_iterator const_iterator;
00042     const_iterator begin() const { return s2iMap.begin(); }
00043     const_iterator end() const { return s2iMap.end(); }
00044     iterator begin() { return s2iMap.begin(); }
00045     iterator end() { return s2iMap.end(); }
00046     unsigned getNumIntervals() const { return (unsigned)s2iMap.size(); }
00047 
00048     LiveInterval &getOrCreateInterval(int Slot) {
00049       SS2IntervalMap::iterator I = s2iMap.find(Slot);
00050       if (I == s2iMap.end())
00051         I = s2iMap.insert(I,std::make_pair(Slot,LiveInterval(Slot,0.0F,true)));
00052       return I->second;
00053     }
00054 
00055     LiveInterval &getInterval(int Slot) {
00056       SS2IntervalMap::iterator I = s2iMap.find(Slot);
00057       assert(I != s2iMap.end() && "Interval does not exist for stack slot");
00058       return I->second;
00059     }
00060 
00061     const LiveInterval &getInterval(int Slot) const {
00062       SS2IntervalMap::const_iterator I = s2iMap.find(Slot);
00063       assert(I != s2iMap.end() && "Interval does not exist for stack slot");
00064       return I->second;
00065     }
00066 
00067     bool hasInterval(unsigned Slot) const {
00068       return s2iMap.count(Slot);
00069     }
00070 
00071     BumpPtrAllocator& getVNInfoAllocator() { return VNInfoAllocator; }
00072 
00073     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
00074     virtual void releaseMemory();
00075 
00076     /// runOnMachineFunction - pass entry point
00077     virtual bool runOnMachineFunction(MachineFunction&);
00078 
00079     /// print - Implement the dump method.
00080     virtual void print(std::ostream &O, const Module* = 0) const;
00081     void print(std::ostream *O, const Module* M = 0) const {
00082       if (O) print(*O, M);
00083     }
00084   };
00085 }
00086 
00087 #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */