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
20#include "llvm/IR/PassManager.h"
22#include "llvm/PassRegistry.h"
23#include <cassert>
24#include <map>
25#include <unordered_map>
26
27namespace llvm {
28
29class AnalysisUsage;
30class MachineFunction;
31class Module;
32class raw_ostream;
33class TargetRegisterClass;
34class TargetRegisterInfo;
35
37 const TargetRegisterInfo *TRI = nullptr;
38
39 /// Special pool allocator for VNInfo's (LiveInterval val#).
40 ///
41 VNInfo::Allocator VNInfoAllocator;
42
43 /// S2IMap - Stack slot indices to live interval mapping.
44 using SS2IntervalMap = std::unordered_map<int, LiveInterval>;
45 SS2IntervalMap S2IMap;
46
47 /// S2RCMap - Stack slot indices to register class mapping.
48 std::map<int, const TargetRegisterClass *> S2RCMap;
49
50public:
51 using iterator = SS2IntervalMap::iterator;
52 using const_iterator = SS2IntervalMap::const_iterator;
53
54 const_iterator begin() const { return S2IMap.begin(); }
55 const_iterator end() const { return S2IMap.end(); }
56 iterator begin() { return S2IMap.begin(); }
57 iterator end() { return S2IMap.end(); }
58
59 unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
60
62
64 assert(Slot >= 0 && "Spill slot indice must be >= 0");
65 SS2IntervalMap::iterator I = S2IMap.find(Slot);
66 assert(I != S2IMap.end() && "Interval does not exist for stack slot");
67 return I->second;
68 }
69
70 const LiveInterval &getInterval(int Slot) const {
71 assert(Slot >= 0 && "Spill slot indice must be >= 0");
72 SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
73 assert(I != S2IMap.end() && "Interval does not exist for stack slot");
74 return I->second;
75 }
76
77 bool hasInterval(int Slot) const { return S2IMap.count(Slot); }
78
80 assert(Slot >= 0 && "Spill slot indice must be >= 0");
81 std::map<int, const TargetRegisterClass *>::const_iterator I =
82 S2RCMap.find(Slot);
83 assert(I != S2RCMap.end() &&
84 "Register class info does not exist for stack slot");
85 return I->second;
86 }
87
88 VNInfo::Allocator &getVNInfoAllocator() { return VNInfoAllocator; }
89
90 void releaseMemory();
91 /// init - analysis entry point
92 void init(MachineFunction &MF);
93 void print(raw_ostream &O, const Module *M = nullptr) const;
94};
95
97 LiveStacks Impl;
98
99public:
100 static char ID; // Pass identification, replacement for typeid
101
104 }
105
106 LiveStacks &getLS() { return Impl; }
107 const LiveStacks &getLS() const { return Impl; }
108
109 void getAnalysisUsage(AnalysisUsage &AU) const override;
110 void releaseMemory() override;
111
112 /// runOnMachineFunction - pass entry point
113 bool runOnMachineFunction(MachineFunction &) override;
114
115 /// print - Implement the dump method.
116 void print(raw_ostream &O, const Module * = nullptr) const override;
117};
118
119class LiveStacksAnalysis : public AnalysisInfoMixin<LiveStacksAnalysis> {
120 static AnalysisKey Key;
122
123public:
125
127};
128
129class LiveStacksPrinterPass : public PassInfoMixin<LiveStacksPrinterPass> {
130 raw_ostream &OS;
131
132public:
136};
137} // end namespace llvm
138
139#endif
This header defines various interfaces for pass management in LLVM.
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
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
LiveStacks run(MachineFunction &MF, MachineFunctionAnalysisManager &)
Definition: LiveStacks.cpp:73
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &AM)
Definition: LiveStacks.cpp:80
LiveStacksPrinterPass(raw_ostream &OS)
Definition: LiveStacks.h:133
void print(raw_ostream &O, const Module *=nullptr) const override
print - Implement the dump method.
Definition: LiveStacks.cpp:94
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
bool runOnMachineFunction(MachineFunction &) override
runOnMachineFunction - pass entry point
Definition: LiveStacks.cpp:86
const LiveStacks & getLS() const
Definition: LiveStacks.h:107
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:92
SS2IntervalMap::const_iterator const_iterator
Definition: LiveStacks.h:52
LiveInterval & getInterval(int Slot)
Definition: LiveStacks.h:63
iterator begin()
Definition: LiveStacks.h:56
bool hasInterval(int Slot) const
Definition: LiveStacks.h:77
unsigned getNumIntervals() const
Definition: LiveStacks.h:59
VNInfo::Allocator & getVNInfoAllocator()
Definition: LiveStacks.h:88
SS2IntervalMap::iterator iterator
Definition: LiveStacks.h:51
LiveInterval & getOrCreateInterval(int Slot, const TargetRegisterClass *RC)
Definition: LiveStacks.cpp:53
void print(raw_ostream &O, const Module *M=nullptr) const
print - Implement the dump method.
Definition: LiveStacks.cpp:99
const TargetRegisterClass * getIntervalRegClass(int Slot) const
Definition: LiveStacks.h:79
const_iterator end() const
Definition: LiveStacks.h:55
const LiveInterval & getInterval(int Slot) const
Definition: LiveStacks.h:70
const_iterator begin() const
Definition: LiveStacks.h:54
iterator end()
Definition: LiveStacks.h:57
void init(MachineFunction &MF)
init - analysis entry point
Definition: LiveStacks.cpp:46
void releaseMemory()
Definition: LiveStacks.cpp:39
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...
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
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 initializeLiveStacksWrapperLegacyPass(PassRegistry &)
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69