LLVM 24.0.0git
LiveStacks.cpp
Go to the documentation of this file.
1//===-- LiveStacks.cpp - Live Stack Slot Analysis -------------------------===//
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
18#include "llvm/IR/Function.h"
19using namespace llvm;
20
21#define DEBUG_TYPE "livestacks"
22
25 "Live Stack Slot Analysis", false, false)
28 "Live Stack Slot Analysis", false, true)
29
31
33 AU.setPreservesAll();
34 AU.addPreserved<SlotIndexesWrapperPass>();
35 AU.addRequiredTransitive<SlotIndexesWrapperPass>();
37}
38
40 // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd.
41 VNInfoAllocator.Reset();
42 S2IMap.clear();
43 S2RCMap.clear();
44}
45
47 for (auto &[Slot, LI] : S2IMap) {
48 if (none_of(LI, [&](const LiveRange::Segment &S) {
49 return SI.isStaleIndex(S.start) || SI.isStaleIndex(S.end);
50 }))
51 continue;
53 for (const LiveRange::Segment &S : LI) {
54 SlotIndex Start = SI.canonicalizeIndex(S.start);
55 SlotIndex End = S.end;
56 // The dead slot keeps a store on the preceding instruction covered.
57 if (SI.isStaleIndex(End))
58 End = SI.canonicalizeIndex(End).getDeadSlot();
59 if (Start < End)
60 Segments.push_back(LiveRange::Segment(Start, End, S.valno));
61 }
62 LI.segments.clear();
63 for (const LiveRange::Segment &S : Segments)
64 LI.addSegment(S);
65 }
66}
67
69 TRI = MF.getSubtarget().getRegisterInfo();
70 // FIXME: No analysis is being done right now. We are relying on the
71 // register allocators to provide the information.
72}
73
76 assert(Slot >= 0 && "Spill slot indice must be >= 0");
77 SS2IntervalMap::iterator I = S2IMap.find(Slot);
78 if (I == S2IMap.end()) {
79 I = S2IMap
80 .emplace(
81 std::piecewise_construct, std::forward_as_tuple(Slot),
82 std::forward_as_tuple(Register::index2StackSlot(Slot), 0.0F))
83 .first;
84 S2RCMap.insert(std::make_pair(Slot, RC));
85 } else {
86 // Use the largest common subclass register class.
87 const TargetRegisterClass *&OldRC = S2RCMap[Slot];
88 OldRC = TRI->getCommonSubClass(OldRC, RC);
89 }
90 return I->second;
91}
92
93AnalysisKey LiveStacksAnalysis::Key;
94
107
109 Impl = LiveStacks();
110 Impl.init(MF);
111 return false;
112}
113
115
117 Impl.print(OS);
118}
119
120/// print - Implement the dump method.
121void LiveStacks::print(raw_ostream &OS, const Module*) const {
122
123 OS << "********** INTERVALS **********\n";
124 for (const_iterator I = begin(), E = end(); I != E; ++I) {
125 I->second.print(OS);
126 int Slot = I->first;
128 if (RC)
129 OS << " [" << TRI->getRegClassName(RC) << "]\n";
130 else
131 OS << " [Unknown]\n";
132 }
133}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define DEBUG_TYPE
#define I(x, y, z)
Definition MD5.cpp:57
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
Module * getParent()
Get the module that this global value is contained inside of...
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)
void print(raw_ostream &O, const Module *=nullptr) const override
print - Implement the dump method.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnMachineFunction(MachineFunction &) override
runOnMachineFunction - pass entry point
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
SS2IntervalMap::const_iterator const_iterator
Definition LiveStacks.h:53
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:81
const_iterator end() const
Definition LiveStacks.h:56
LLVM_ABI void canonicalizeIndexes(const SlotIndexes &SI)
Move segment boundaries off erased instructions, ahead of compaction.
const_iterator begin() const
Definition LiveStacks.h:55
LLVM_ABI void init(MachineFunction &MF)
init - analysis entry point
LLVM_ABI void releaseMemory()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
static Register index2StackSlot(int FI)
Convert a frame index to a stack slot register value.
Definition Register.h:51
SlotIndex - An opaque wrapper around machine indexes.
Definition SlotIndexes.h:70
SlotIndexes pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
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.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
LLVM_ABI char & LiveStacksID
LiveStacks pass. An analysis keeping track of the liveness of stack slots.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1769
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
This represents a simple continuous liveness interval for a value.