LLVM: lib/CodeGen/RegUsageInfoCollector.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
31
32using namespace llvm;
33
34#define DEBUG_TYPE "ip-regalloc"
35
37 "Number of functions optimized for callee saved registers");
38
39namespace {
40
41class RegUsageInfoCollector {
43
44public:
46 bool run(MachineFunction &MF);
47
48
49
50 static void computeCalleeSavedRegs(BitVector &SavedRegs, MachineFunction &MF);
51};
52
54public:
55 static char ID;
56 RegUsageInfoCollectorLegacy() : MachineFunctionPass(ID) {
58 }
59
60 StringRef getPassName() const override {
61 return "Register Usage Information Collector Pass";
62 }
63
64 void getAnalysisUsage(AnalysisUsage &AU) const override {
65 AU.addRequired();
68 }
69
70 bool runOnMachineFunction(MachineFunction &MF) override;
71};
72}
73
74char RegUsageInfoCollectorLegacy::ID = 0;
75
77 "Register Usage Information Collector", false, false)
80 "Register Usage Information Collector", false, false)
81
83 return new RegUsageInfoCollectorLegacy();
84}
85
86
87
88
89
90
101 return false;
102 default:
103 return true;
104 }
105}
106
112 .getCachedResult(MFA);
113 assert(PRUI && "PhysicalRegisterUsageAnalysis not available");
116}
117
118bool RegUsageInfoCollectorLegacy::runOnMachineFunction(MachineFunction &MF) {
120 getAnalysis().getPRUI();
122}
123
128
131 << " -------------------- Register Usage Information Collector Pass"
132 << " -------------------- \nFunction Name : " << MF.getName() << '\n');
133
134
136 LLVM_DEBUG(dbgs() << "Not analyzing non-callable function\n");
137 return false;
138 }
139
140
141
143 LLVM_DEBUG(dbgs() << "Not analyzing function with no callers\n");
144 return false;
145 }
146
147 std::vector<uint32_t> RegMask;
148
149
150
151
153 RegMask.resize(RegMaskSize, ~((uint32_t)0));
154
156
158
160
162 computeCalleeSavedRegs(SavedRegs, MF);
163
164 const BitVector &UsedPhysRegsMask = MRI->getUsedPhysRegsMask();
165 auto SetRegAsDefined = [&RegMask](MCRegister Reg) {
166 RegMask[Reg.id() / 32] &= ~(1u << Reg.id() % 32);
167 };
168
169
171
172
173
174 for (const MCPhysReg Reg : TRI->getIntraCallClobberedRegs(&MF))
176 SetRegAsDefined(*AI);
177
178
179
180
181 for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) {
182
183 if (SavedRegs.test(PReg))
184 continue;
185
186
187 if (->def_empty(PReg)) {
189 if (!SavedRegs.test((*AI).id()))
190 SetRegAsDefined(*AI);
191 continue;
192 }
193
194
195
196 if (UsedPhysRegsMask.test(PReg))
197 SetRegAsDefined(PReg);
198 }
199
202 ++NumCSROpt;
204 << " function optimized for not having CSR.\n");
205 }
206
208 for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) {
209 if (MachineOperand::clobbersPhysReg(&(RegMask[0]), PReg))
210 dbgs() << printReg(PReg, TRI) << " ";
211 }
212
213 dbgs() << " \n----------------------------------------\n";
214 );
215
217
218 return false;
219}
220
221void RegUsageInfoCollector::
225
226
227 SavedRegs.clear();
229 if (SavedRegs.none())
230 return;
231
232
233 const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(&MF);
234 for (unsigned i = 0; CSRegs[i]; ++i) {
236 if (SavedRegs.test(Reg)) {
237
239 SavedRegs.set(SR);
240 }
241 }
242}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
RegUsageInfoCollector
Definition RegUsageInfoCollector.cpp:79
static bool isCallableFunction(const MachineFunction &MF)
Definition RegUsageInfoCollector.cpp:91
This pass is required to take advantage of the interprocedural register allocation infrastructure.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool test(unsigned Idx) const
void clear()
clear - Removes all bits from the bitvector.
bool none() const
none - Returns true if none of the bits are set.
FunctionPass class - This class is used to implement most global optimizations.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Module * getParent()
Get the module that this global value is contained inside of...
MCRegAliasIterator enumerates all registers aliasing Reg.
Wrapper class representing physical registers. Should be passed by value.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
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.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
static unsigned getRegMaskSize(unsigned NumRegs)
Returns number of elements needed for a regmask array.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void setTargetMachine(const TargetMachine &TM)
Set TargetMachine which is used to print analysis.
void storeUpdateRegUsageInfo(const Function &FP, ArrayRef< uint32_t > RegMask)
To store RegMask for given Function *.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition RegUsageInfoCollector.cpp:108
constexpr unsigned id() const
Information about stack frame layout on the target.
virtual void getCalleeSaves(const MachineFunction &MF, BitVector &SavedRegs) const
Returns the callee-saved registers as computed by determineCalleeSaves in the BitVector SavedRegs.
virtual bool isProfitableForNoCSROpt(const Function &F) const
Check if the no-CSR optimisation is profitable for the given function.
static bool isSafeForNoCSROpt(const Function &F)
Check if given function is safe for not having callee saved registers.
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI FunctionPass * createRegUsageInfoCollector()
This pass is executed POST-RA to collect which physical registers are preserved by given machine func...
Definition RegUsageInfoCollector.cpp:82
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
LLVM_ABI void initializeRegUsageInfoCollectorLegacyPass(PassRegistry &)