LLVM 23.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;
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 const TargetRegisterClass *RC);
63
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");
68 return I->second;
69 }
70
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");
75 return I->second;
76 }
77
78 bool hasInterval(int Slot) const { return S2IMap.count(Slot); }
79
81 assert(Slot >= 0 && "Spill slot indice must be >= 0");
82 std::map<int, const TargetRegisterClass *>::const_iterator I =
83 S2RCMap.find(Slot);
84 assert(I != S2RCMap.end() &&
85 "Register class info does not exist for stack slot");
86 return I->second;
87 }
88
89 VNInfo::Allocator &getVNInfoAllocator() { return VNInfoAllocator; }
90
92 /// init - analysis entry point
94 LLVM_ABI void print(raw_ostream &O, const Module *M = nullptr) const;
95};
96
98 LiveStacks Impl;
99
100public:
101 static char ID; // Pass identification, replacement for typeid
102
104
105 LiveStacks &getLS() { return Impl; }
106 const LiveStacks &getLS() const { return Impl; }
107
108 void getAnalysisUsage(AnalysisUsage &AU) const override;
109 void releaseMemory() override;
110
111 /// runOnMachineFunction - pass entry point
112 bool runOnMachineFunction(MachineFunction &) override;
113
114 /// print - Implement the dump method.
115 void print(raw_ostream &O, const Module * = nullptr) const override;
116};
117
118class LiveStacksAnalysis : public AnalysisInfoMixin<LiveStacksAnalysis> {
119 static AnalysisKey Key;
121
122public:
124
127};
128
130 : public RequiredPassInfoMixin<LiveStacksPrinterPass> {
131 raw_ostream &OS;
132
133public:
137};
138} // end namespace llvm
139
140#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define LLVM_ABI
Definition Compiler.h:213
This header defines various interfaces for pass management in LLVM.
#define I(x, y, z)
Definition MD5.cpp:57
Represent the analysis usage information of a pass.
LiveInterval - This class represents the liveness of a register, or stack slot.
LLVM_ABI LiveStacks run(MachineFunction &MF, MachineFunctionAnalysisManager &)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &AM)
LiveStacksPrinterPass(raw_ostream &OS)
Definition LiveStacks.h:134
const LiveStacks & getLS() const
Definition LiveStacks.h:106
SS2IntervalMap::const_iterator const_iterator
Definition LiveStacks.h:52
LiveInterval & getInterval(int Slot)
Definition LiveStacks.h:64
iterator begin()
Definition LiveStacks.h:56
bool hasInterval(int Slot) const
Definition LiveStacks.h:78
unsigned getNumIntervals() const
Definition LiveStacks.h:59
VNInfo::Allocator & getVNInfoAllocator()
Definition LiveStacks.h:89
SS2IntervalMap::iterator iterator
Definition LiveStacks.h:51
LLVM_ABI LiveInterval & getOrCreateInterval(int Slot, const TargetRegisterClass *RC)
LLVM_ABI void print(raw_ostream &O, const Module *M=nullptr) const
print - Implement the dump method.
const TargetRegisterClass * getIntervalRegClass(int Slot) const
Definition LiveStacks.h:80
const_iterator end() const
Definition LiveStacks.h:55
const LiveInterval & getInterval(int Slot) const
Definition LiveStacks.h:71
const_iterator begin() const
Definition LiveStacks.h:54
iterator end()
Definition LiveStacks.h:57
LLVM_ABI void init(MachineFunction &MF)
init - analysis entry point
LLVM_ABI void releaseMemory()
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
BumpPtrAllocator Allocator
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A CRTP mix-in for passes that should not be skipped.