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_LIVESTACKANALYSIS_H
17 #define LLVM_CODEGEN_LIVESTACKANALYSIS_H
19 #include "llvm/CodeGen/LiveInterval.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21 #include "llvm/Support/Allocator.h"
22 #include "llvm/Target/TargetRegisterInfo.h"
24 #include <unordered_map>
28 class LiveStacks : public MachineFunctionPass {
29 const TargetRegisterInfo *TRI;
31 /// Special pool allocator for VNInfo's (LiveInterval val#).
33 VNInfo::Allocator VNInfoAllocator;
35 /// S2IMap - Stack slot indices to live interval mapping.
37 typedef std::unordered_map<int, LiveInterval> SS2IntervalMap;
38 SS2IntervalMap S2IMap;
40 /// S2RCMap - Stack slot indices to register class mapping.
41 std::map<int, const TargetRegisterClass*> S2RCMap;
44 static char ID; // Pass identification, replacement for typeid
45 LiveStacks() : MachineFunctionPass(ID) {
46 initializeLiveStacksPass(*PassRegistry::getPassRegistry());
49 typedef SS2IntervalMap::iterator iterator;
50 typedef SS2IntervalMap::const_iterator const_iterator;
51 const_iterator begin() const { return S2IMap.begin(); }
52 const_iterator end() const { return S2IMap.end(); }
53 iterator begin() { return S2IMap.begin(); }
54 iterator end() { return S2IMap.end(); }
56 unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
58 LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC);
60 LiveInterval &getInterval(int Slot) {
61 assert(Slot >= 0 && "Spill slot indice must be >= 0");
62 SS2IntervalMap::iterator I = S2IMap.find(Slot);
63 assert(I != S2IMap.end() && "Interval does not exist for stack slot");
67 const LiveInterval &getInterval(int Slot) const {
68 assert(Slot >= 0 && "Spill slot indice must be >= 0");
69 SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
70 assert(I != S2IMap.end() && "Interval does not exist for stack slot");
74 bool hasInterval(int Slot) const {
75 return S2IMap.count(Slot);
78 const TargetRegisterClass *getIntervalRegClass(int Slot) const {
79 assert(Slot >= 0 && "Spill slot indice must be >= 0");
80 std::map<int, const TargetRegisterClass*>::const_iterator
81 I = S2RCMap.find(Slot);
82 assert(I != S2RCMap.end() &&
83 "Register class info does not exist for stack slot");
87 VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; }
89 void getAnalysisUsage(AnalysisUsage &AU) const override;
90 void releaseMemory() override;
92 /// runOnMachineFunction - pass entry point
93 bool runOnMachineFunction(MachineFunction&) override;
95 /// print - Implement the dump method.
96 void print(raw_ostream &O, const Module* = nullptr) const override;
100 #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */