1 //===- LiveStacks.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_LIVESTACKS_H
17 #define LLVM_CODEGEN_LIVESTACKS_H
19 #include "llvm/CodeGen/LiveInterval.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21 #include "llvm/Pass.h"
24 #include <unordered_map>
28 class TargetRegisterClass;
29 class TargetRegisterInfo;
31 class LiveStacks : public MachineFunctionPass {
32 const TargetRegisterInfo *TRI;
34 /// Special pool allocator for VNInfo's (LiveInterval val#).
36 VNInfo::Allocator VNInfoAllocator;
38 /// S2IMap - Stack slot indices to live interval mapping.
39 using SS2IntervalMap = std::unordered_map<int, LiveInterval>;
40 SS2IntervalMap S2IMap;
42 /// S2RCMap - Stack slot indices to register class mapping.
43 std::map<int, const TargetRegisterClass *> S2RCMap;
46 static char ID; // Pass identification, replacement for typeid
48 LiveStacks() : MachineFunctionPass(ID) {
49 initializeLiveStacksPass(*PassRegistry::getPassRegistry());
52 using iterator = SS2IntervalMap::iterator;
53 using const_iterator = SS2IntervalMap::const_iterator;
55 const_iterator begin() const { return S2IMap.begin(); }
56 const_iterator end() const { return S2IMap.end(); }
57 iterator begin() { return S2IMap.begin(); }
58 iterator end() { return S2IMap.end(); }
60 unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
62 LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC);
64 LiveInterval &getInterval(int Slot) {
65 assert(Slot >= 0 && "Spill slot indice must be >= 0");
66 SS2IntervalMap::iterator I = S2IMap.find(Slot);
67 assert(I != S2IMap.end() && "Interval does not exist for stack slot");
71 const LiveInterval &getInterval(int Slot) const {
72 assert(Slot >= 0 && "Spill slot indice must be >= 0");
73 SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
74 assert(I != S2IMap.end() && "Interval does not exist for stack slot");
78 bool hasInterval(int Slot) const { return S2IMap.count(Slot); }
80 const TargetRegisterClass *getIntervalRegClass(int Slot) const {
81 assert(Slot >= 0 && "Spill slot indice must be >= 0");
82 std::map<int, const TargetRegisterClass *>::const_iterator I =
84 assert(I != S2RCMap.end() &&
85 "Register class info does not exist for stack slot");
89 VNInfo::Allocator &getVNInfoAllocator() { return VNInfoAllocator; }
91 void getAnalysisUsage(AnalysisUsage &AU) const override;
92 void releaseMemory() override;
94 /// runOnMachineFunction - pass entry point
95 bool runOnMachineFunction(MachineFunction &) override;
97 /// print - Implement the dump method.
98 void print(raw_ostream &O, const Module * = nullptr) const override;
101 } // end namespace llvm