LLVM  16.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/InitializePasses.h"
19 using namespace llvm;
20 
21 #define DEBUG_TYPE "livestacks"
22 
23 char LiveStacks::ID = 0;
25  "Live Stack Slot Analysis", false, false)
28  "Live Stack Slot Analysis", false, false)
29 
31 
32 void LiveStacks::getAnalysisUsage(AnalysisUsage &AU) const {
33  AU.setPreservesAll();
34  AU.addPreserved<SlotIndexes>();
35  AU.addRequiredTransitive<SlotIndexes>();
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  TRI = MF.getSubtarget().getRegisterInfo();
48  // FIXME: No analysis is being done right now. We are relying on the
49  // register allocators to provide the information.
50  return false;
51 }
52 
55  assert(Slot >= 0 && "Spill slot indice must be >= 0");
56  SS2IntervalMap::iterator I = S2IMap.find(Slot);
57  if (I == S2IMap.end()) {
58  I = S2IMap
59  .emplace(
60  std::piecewise_construct, std::forward_as_tuple(Slot),
61  std::forward_as_tuple(Register::index2StackSlot(Slot), 0.0F))
62  .first;
63  S2RCMap.insert(std::make_pair(Slot, RC));
64  } else {
65  // Use the largest common subclass register class.
66  const TargetRegisterClass *OldRC = S2RCMap[Slot];
67  S2RCMap[Slot] = TRI->getCommonSubClass(OldRC, RC);
68  }
69  return I->second;
70 }
71 
72 /// print - Implement the dump method.
73 void LiveStacks::print(raw_ostream &OS, const Module*) const {
74 
75  OS << "********** INTERVALS **********\n";
76  for (const_iterator I = begin(), E = end(); I != E; ++I) {
77  I->second.print(OS);
78  int Slot = I->first;
79  const TargetRegisterClass *RC = getIntervalRegClass(Slot);
80  if (RC)
81  OS << " [" << TRI->getRegClassName(RC) << "]\n";
82  else
83  OS << " [Unknown]\n";
84  }
85 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::LiveStacksID
char & LiveStacksID
LiveStacks pass. An analysis keeping track of the liveness of stack slots.
Definition: LiveStacks.cpp:30
llvm::BumpPtrAllocatorImpl::Reset
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
Definition: Allocator.h:123
llvm::LiveStacks::begin
const_iterator begin() const
Definition: LiveStacks.h:59
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition: TargetSubtargetInfo.h:127
DEBUG_TYPE
#define DEBUG_TYPE
Definition: LiveStacks.cpp:21
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:167
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::Register::index2StackSlot
static Register index2StackSlot(int FI)
Convert a non-negative frame index to a stack slot register value.
Definition: Register.h:58
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
false
Definition: StackSlotColoring.cpp:141
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:60
llvm::SlotIndexes
SlotIndexes pass.
Definition: SlotIndexes.h:319
llvm::LiveInterval
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:686
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:657
llvm::TargetRegisterInfo::getRegClassName
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
Definition: TargetRegisterInfo.h:777
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
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:39
I
#define I(x, y, z)
Definition: MD5.cpp:58
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetRegisterInfo::getCommonSubClass
const TargetRegisterClass * getCommonSubClass(const TargetRegisterClass *A, const TargetRegisterClass *B) const
Find the largest common subclass of A and B.
Definition: TargetRegisterInfo.cpp:289
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::LiveStacks::const_iterator
SS2IntervalMap::const_iterator const_iterator
Definition: LiveStacks.h:57
TargetSubtargetInfo.h
llvm::LiveStacks::getOrCreateInterval
LiveInterval & getOrCreateInterval(int Slot, const TargetRegisterClass *RC)
Definition: LiveStacks.cpp:54
llvm::LiveStacks::print
void print(raw_ostream &O, const Module *=nullptr) const override
print - Implement the dump method.
Definition: LiveStacks.cpp:73
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(LiveStacks, DEBUG_TYPE, "Live Stack Slot Analysis", false, false) INITIALIZE_PASS_END(LiveStacks
llvm::LiveStacks::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &) override
runOnMachineFunction - pass entry point
Definition: LiveStacks.cpp:46
LiveStacks.h
llvm::LiveStacks::ID
static char ID
Definition: LiveStacks.h:50
InitializePasses.h
llvm::LiveStacks
Definition: LiveStacks.h:35
TargetRegisterInfo.h
llvm::LiveStacks::getIntervalRegClass
const TargetRegisterClass * getIntervalRegClass(int Slot) const
Definition: LiveStacks.h:84