LLVM  14.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/InitializePasses.h"
21 #include "llvm/Pass.h"
22 #include <cassert>
23 #include <map>
24 #include <unordered_map>
25 
26 namespace llvm {
27 
28 class TargetRegisterClass;
29 class TargetRegisterInfo;
30 
32  const TargetRegisterInfo *TRI;
33 
34  /// Special pool allocator for VNInfo's (LiveInterval val#).
35  ///
36  VNInfo::Allocator VNInfoAllocator;
37 
38  /// S2IMap - Stack slot indices to live interval mapping.
39  using SS2IntervalMap = std::unordered_map<int, LiveInterval>;
40  SS2IntervalMap S2IMap;
41 
42  /// S2RCMap - Stack slot indices to register class mapping.
43  std::map<int, const TargetRegisterClass *> S2RCMap;
44 
45 public:
46  static char ID; // Pass identification, replacement for typeid
47 
50  }
51 
52  using iterator = SS2IntervalMap::iterator;
53  using const_iterator = SS2IntervalMap::const_iterator;
54 
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(); }
59 
60  unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
61 
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 
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 =
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 
91  void getAnalysisUsage(AnalysisUsage &AU) const override;
92  void releaseMemory() override;
93 
94  /// runOnMachineFunction - pass entry point
95  bool runOnMachineFunction(MachineFunction &) override;
96 
97  /// print - Implement the dump method.
98  void print(raw_ostream &O, const Module * = nullptr) const override;
99 };
100 
101 } // end namespace llvm
102 
103 #endif
llvm::LiveStacks::getVNInfoAllocator
VNInfo::Allocator & getVNInfoAllocator()
Definition: LiveStacks.h:89
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::LiveStacks::getInterval
LiveInterval & getInterval(int Slot)
Definition: LiveStacks.h:64
llvm::LiveStacks::getInterval
const LiveInterval & getInterval(int Slot) const
Definition: LiveStacks.h:71
Pass.h
llvm::LiveStacks::begin
const_iterator begin() const
Definition: LiveStacks.h:55
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::initializeLiveStacksPass
void initializeLiveStacksPass(PassRegistry &)
llvm::LiveStacks::iterator
SS2IntervalMap::iterator iterator
Definition: LiveStacks.h:52
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:233
llvm::LiveStacks::getNumIntervals
unsigned getNumIntervals() const
Definition: LiveStacks.h:60
llvm::LiveStacks::hasInterval
bool hasInterval(int Slot) const
Definition: LiveStacks.h:78
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::LiveStacks::end
const_iterator end() const
Definition: LiveStacks.h:56
llvm::LiveInterval
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:680
llvm::LiveStacks::end
iterator end()
Definition: LiveStacks.h:58
llvm::LiveStacks::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LiveStacks.cpp:35
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:197
llvm::LiveStacks::releaseMemory
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:42
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
I
#define I(x, y, z)
Definition: MD5.cpp:59
MachineFunctionPass.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::LiveStacks::const_iterator
SS2IntervalMap::const_iterator const_iterator
Definition: LiveStacks.h:53
llvm::LiveStacks::getOrCreateInterval
LiveInterval & getOrCreateInterval(int Slot, const TargetRegisterClass *RC)
Definition: LiveStacks.cpp:57
llvm::LiveStacks::print
void print(raw_ostream &O, const Module *=nullptr) const override
print - Implement the dump method.
Definition: LiveStacks.cpp:76
llvm::LiveStacks::LiveStacks
LiveStacks()
Definition: LiveStacks.h:48
LiveInterval.h
llvm::LiveStacks::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &) override
runOnMachineFunction - pass entry point
Definition: LiveStacks.cpp:49
llvm::LiveStacks::begin
iterator begin()
Definition: LiveStacks.h:57
llvm::LiveStacks::ID
static char ID
Definition: LiveStacks.h:46
InitializePasses.h
llvm::LiveStacks
Definition: LiveStacks.h:31
llvm::LiveStacks::getIntervalRegClass
const TargetRegisterClass * getIntervalRegClass(int Slot) const
Definition: LiveStacks.h:80