LLVM 20.0.0git
LiveStacks.h
Go to the documentation of this file.
1//===- LiveStacks.h - Live Stack Slot Analysis ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the live stack slot analysis pass. It is analogous to
10// live interval analysis except it's analyzing liveness of stack slots rather
11// than registers.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_LIVESTACKS_H
16#define LLVM_CODEGEN_LIVESTACKS_H
17
21#include "llvm/PassRegistry.h"
22#include <cassert>
23#include <map>
24#include <unordered_map>
25
26namespace llvm {
27
28class AnalysisUsage;
29class MachineFunction;
30class Module;
31class raw_ostream;
32class TargetRegisterClass;
33class TargetRegisterInfo;
34
36 const TargetRegisterInfo *TRI = nullptr;
37
38 /// Special pool allocator for VNInfo's (LiveInterval val#).
39 ///
40 VNInfo::Allocator VNInfoAllocator;
41
42 /// S2IMap - Stack slot indices to live interval mapping.
43 using SS2IntervalMap = std::unordered_map<int, LiveInterval>;
44 SS2IntervalMap S2IMap;
45
46 /// S2RCMap - Stack slot indices to register class mapping.
47 std::map<int, const TargetRegisterClass *> S2RCMap;
48
49public:
50 static char ID; // Pass identification, replacement for typeid
51
54 }
55
56 using iterator = SS2IntervalMap::iterator;
57 using const_iterator = SS2IntervalMap::const_iterator;
58
59 const_iterator begin() const { return S2IMap.begin(); }
60 const_iterator end() const { return S2IMap.end(); }
61 iterator begin() { return S2IMap.begin(); }
62 iterator end() { return S2IMap.end(); }
63
64 unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
65
67
69 assert(Slot >= 0 && "Spill slot indice must be >= 0");
70 SS2IntervalMap::iterator I = S2IMap.find(Slot);
71 assert(I != S2IMap.end() && "Interval does not exist for stack slot");
72 return I->second;
73 }
74
75 const LiveInterval &getInterval(int Slot) const {
76 assert(Slot >= 0 && "Spill slot indice must be >= 0");
77 SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
78 assert(I != S2IMap.end() && "Interval does not exist for stack slot");
79 return I->second;
80 }
81
82 bool hasInterval(int Slot) const { return S2IMap.count(Slot); }
83
85 assert(Slot >= 0 && "Spill slot indice must be >= 0");
86 std::map<int, const TargetRegisterClass *>::const_iterator I =
87 S2RCMap.find(Slot);
88 assert(I != S2RCMap.end() &&
89 "Register class info does not exist for stack slot");
90 return I->second;
91 }
92
93 VNInfo::Allocator &getVNInfoAllocator() { return VNInfoAllocator; }
94
95 void getAnalysisUsage(AnalysisUsage &AU) const override;
96 void releaseMemory() override;
97
98 /// runOnMachineFunction - pass entry point
100
101 /// print - Implement the dump method.
102 void print(raw_ostream &O, const Module * = nullptr) const override;
103};
104
105} // end namespace llvm
106
107#endif
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represent the analysis usage information of a pass.
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:687
SS2IntervalMap::const_iterator const_iterator
Definition: LiveStacks.h:57
LiveInterval & getInterval(int Slot)
Definition: LiveStacks.h:68
iterator begin()
Definition: LiveStacks.h:61
bool hasInterval(int Slot) const
Definition: LiveStacks.h:82
unsigned getNumIntervals() const
Definition: LiveStacks.h:64
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LiveStacks.cpp:32
VNInfo::Allocator & getVNInfoAllocator()
Definition: LiveStacks.h:93
SS2IntervalMap::iterator iterator
Definition: LiveStacks.h:56
LiveInterval & getOrCreateInterval(int Slot, const TargetRegisterClass *RC)
Definition: LiveStacks.cpp:54
const TargetRegisterClass * getIntervalRegClass(int Slot) const
Definition: LiveStacks.h:84
const_iterator end() const
Definition: LiveStacks.h:60
bool runOnMachineFunction(MachineFunction &) override
runOnMachineFunction - pass entry point
Definition: LiveStacks.cpp:46
const LiveInterval & getInterval(int Slot) const
Definition: LiveStacks.h:75
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: LiveStacks.cpp:39
const_iterator begin() const
Definition: LiveStacks.h:59
iterator end()
Definition: LiveStacks.h:62
void print(raw_ostream &O, const Module *=nullptr) const override
print - Implement the dump method.
Definition: LiveStacks.cpp:73
static char ID
Definition: LiveStacks.h:50
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeLiveStacksPass(PassRegistry &)