Home | History | Annotate | Download | only in CodeGen
      1 //===-- LiveStackAnalysis.h - Live Stack Slot Analysis ----------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     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
     12 // than registers.
     13 //
     14 //===----------------------------------------------------------------------===//
     15 
     16 #ifndef LLVM_CODEGEN_LIVESTACK_ANALYSIS_H
     17 #define LLVM_CODEGEN_LIVESTACK_ANALYSIS_H
     18 
     19 #include "llvm/CodeGen/MachineFunctionPass.h"
     20 #include "llvm/CodeGen/LiveInterval.h"
     21 #include "llvm/Target/TargetRegisterInfo.h"
     22 #include "llvm/Support/Allocator.h"
     23 #include <map>
     24 
     25 namespace llvm {
     26 
     27   class LiveStacks : public MachineFunctionPass {
     28     /// Special pool allocator for VNInfo's (LiveInterval val#).
     29     ///
     30     VNInfo::Allocator VNInfoAllocator;
     31 
     32     /// S2IMap - Stack slot indices to live interval mapping.
     33     ///
     34     typedef std::map<int, LiveInterval> SS2IntervalMap;
     35     SS2IntervalMap S2IMap;
     36 
     37     /// S2RCMap - Stack slot indices to register class mapping.
     38     std::map<int, const TargetRegisterClass*> S2RCMap;
     39 
     40   public:
     41     static char ID; // Pass identification, replacement for typeid
     42     LiveStacks() : MachineFunctionPass(ID) {
     43       initializeLiveStacksPass(*PassRegistry::getPassRegistry());
     44     }
     45 
     46     typedef SS2IntervalMap::iterator iterator;
     47     typedef SS2IntervalMap::const_iterator const_iterator;
     48     const_iterator begin() const { return S2IMap.begin(); }
     49     const_iterator end() const { return S2IMap.end(); }
     50     iterator begin() { return S2IMap.begin(); }
     51     iterator end() { return S2IMap.end(); }
     52 
     53     unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
     54 
     55     LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC);
     56 
     57     LiveInterval &getInterval(int Slot) {
     58       assert(Slot >= 0 && "Spill slot indice must be >= 0");
     59       SS2IntervalMap::iterator I = S2IMap.find(Slot);
     60       assert(I != S2IMap.end() && "Interval does not exist for stack slot");
     61       return I->second;
     62     }
     63 
     64     const LiveInterval &getInterval(int Slot) const {
     65       assert(Slot >= 0 && "Spill slot indice must be >= 0");
     66       SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
     67       assert(I != S2IMap.end() && "Interval does not exist for stack slot");
     68       return I->second;
     69     }
     70 
     71     bool hasInterval(int Slot) const {
     72       return S2IMap.count(Slot);
     73     }
     74 
     75     const TargetRegisterClass *getIntervalRegClass(int Slot) const {
     76       assert(Slot >= 0 && "Spill slot indice must be >= 0");
     77       std::map<int, const TargetRegisterClass*>::const_iterator
     78         I = S2RCMap.find(Slot);
     79       assert(I != S2RCMap.end() &&
     80              "Register class info does not exist for stack slot");
     81       return I->second;
     82     }
     83 
     84     VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; }
     85 
     86     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
     87     virtual void releaseMemory();
     88 
     89     /// runOnMachineFunction - pass entry point
     90     virtual bool runOnMachineFunction(MachineFunction&);
     91 
     92     /// print - Implement the dump method.
     93     virtual void print(raw_ostream &O, const Module* = 0) const;
     94   };
     95 }
     96 
     97 #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */
     98