LLVM: lib/CodeGen/LivePhysRegs.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
21#include "llvm/Config/llvm-config.h"
24using namespace llvm;
25
26
27
28
29
30
32 SmallVectorImpl<std::pair<MCPhysReg, const MachineOperand*>> *Clobbers) {
34 while (LRI != LiveRegs.end()) {
36 if (Clobbers)
37 Clobbers->push_back(std::make_pair(*LRI, &MO));
38 LRI = LiveRegs.erase(LRI);
39 } else
40 ++LRI;
41 }
42}
43
44
47 if (MOP.isRegMask()) {
49 continue;
50 }
51
52 if (MOP.isDef())
54 }
55}
56
57
60 if (!MOP.isReg() || !MOP.readsReg())
61 continue;
63 }
64}
65
66
67
75
76
77
78
79
81 SmallVectorImpl<std::pair<MCPhysReg, const MachineOperand*>> &Clobbers) {
82
84 if (O->isReg()) {
85 if (O->isDebug())
86 continue;
88 if (!Reg.isPhysical())
89 continue;
90 if (O->isDef()) {
91
92
93 Clobbers.push_back(std::make_pair(Reg.id(), &*O));
94 } else {
96 if (O->isKill())
98 }
99 } else if (O->isRegMask()) {
101 }
102 }
103
104
105 for (auto Reg : Clobbers) {
106
107
108 if (Reg.second->isReg() && Reg.second->isDead())
109 continue;
110 if (Reg.second->isRegMask() &&
112 continue;
114 }
115}
116
117
119 OS << "Live Registers:";
120 if (!TRI) {
121 OS << " (uninitialized)\n";
122 return;
123 }
124
126 OS << " (empty)\n";
127 return;
128 }
129
131 OS << " " << printReg(R, TRI);
132 OS << "\n";
133}
134
135#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
137 dbgs() << " " << *this;
138}
139#endif
140
143 if (LiveRegs.count(Reg.id()))
144 return false;
145 if (MRI.isReserved(Reg))
146 return false;
148 if (LiveRegs.count(*R))
149 return false;
150 }
151 return true;
152}
153
154
155void LivePhysRegs::addRegMaskPair(
160 assert(Mask.any() && "Invalid livein mask");
161 if (Mask.all() || !S.isValid()) {
163 return;
164 }
165 for (; S.isValid(); ++S) {
166 unsigned SI = S.getSubRegIndex();
167 if ((Mask & TRI->getSubRegIndexLaneMask(SI)).any())
168 addReg(S.getSubReg());
169 }
170}
171
172
175 addRegMaskPair(LI);
176}
177
178
181 addRegMaskPair(LO);
182}
183
184
188 for (const MCPhysReg *CSR = MRI.getCalleeSavedRegs(); CSR && *CSR; ++CSR)
190}
191
192void LivePhysRegs::addPristines(const MachineFunction &MF) {
193 const MachineFrameInfo &MFI = MF.getFrameInfo();
195 return;
196
197
199
200
202
205 return;
206 }
207
208
209
210
213
215 Pristine.removeReg(Info.getReg());
218}
219
221 addBlockLiveOuts(MBB);
222 if (MBB.isReturnBlock()) {
223
224
225
226
227
228
229
230
235 if (Info.isRestored())
236 addReg(Info.getReg());
237 }
238 }
239}
240
243 addPristines(MF);
245}
246
249 addPristines(MF);
250 addBlockLiveIns(MBB);
251}
252
254 addBlockLiveIns(MBB);
255}
256
267
269 assert(MBB.livein_empty() && "Expected empty live-in list");
274 if (MRI.isReserved(Reg))
275 continue;
276
278 return LiveRegs.contains(SReg) && !MRI.isReserved(SReg);
279 }))
280 continue;
281 MBB.addLiveIn(Reg);
282 }
283}
284
290
291
295
297
299 if (!MO->isReg() || !MO->isDef() || MO->isDebug())
300 continue;
301
303 if (Reg == 0)
304 continue;
305 assert(Reg.isPhysical());
306
307 bool IsNotLive = LiveRegs.available(MRI, Reg);
308
309
310
313 if (Info.getReg() == Reg.asMCReg()) {
314 IsNotLive = !Info.isRestored();
315 break;
316 }
317 }
318 }
319
320 MO->setIsDead(IsNotLive);
321 }
322
323
325
326
328 if (!MO->isReg() || !MO->readsReg() || MO->isDebug())
329 continue;
330
332 if (Reg == 0)
333 continue;
334 assert(Reg.isPhysical());
335
336 bool IsNotLive = LiveRegs.available(MRI, Reg);
337 MO->setIsKill(IsNotLive);
338 }
339
340
342 }
343}
344
350
351
352
354 assert(Reg.isPhysical() && "Apply to physical register only");
355
357
359 if (MI.readsRegister(Reg, nullptr))
360 return true;
361
362 if (MI.definesRegister(Reg, nullptr))
363 return false;
364 }
365
366
367
368 for (const auto &LO : MBB->liveouts())
369 if (LO.PhysReg == Reg.asMCReg() && LO.LaneMask.any())
370 return true;
371
372 return false;
373}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static void addCalleeSavedRegs(LivePhysRegs &LiveRegs, const MachineFunction &MF)
Adds all callee saved registers to LiveRegs.
Definition LivePhysRegs.cpp:185
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
Register const TargetRegisterInfo * TRI
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
ConstMIBundleOperands - Iterate over all operands in a const bundle of machine instructions.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
void addReg(MCRegister Reg)
Adds a physical register and all its sub-registers to the set.
void stepForward(const MachineInstr &MI, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > &Clobbers)
Simulates liveness when stepping forward over an instruction(bundle).
Definition LivePhysRegs.cpp:80
void print(raw_ostream &OS) const
Prints the currently live registers to OS.
Definition LivePhysRegs.cpp:118
void stepBackward(const MachineInstr &MI)
Simulates liveness when stepping backwards over an instruction(bundle).
Definition LivePhysRegs.cpp:68
void addLiveIns(const MachineBasicBlock &MBB)
Adds all live-in registers of basic block MBB.
Definition LivePhysRegs.cpp:247
bool available(const MachineRegisterInfo &MRI, MCRegister Reg) const
Returns true if register Reg and no aliasing register is in the set.
Definition LivePhysRegs.cpp:141
void addUses(const MachineInstr &MI)
Add uses to the set.
Definition LivePhysRegs.cpp:58
void removeDefs(const MachineInstr &MI)
Remove defined registers and regmask kills from the set.
Definition LivePhysRegs.cpp:45
void addLiveOutsNoPristines(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB but skips pristine registers.
Definition LivePhysRegs.cpp:220
void addLiveOuts(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB.
Definition LivePhysRegs.cpp:241
LivePhysRegs()=default
Constructs an unitialized set. init() needs to be called to initialize it.
void removeReg(MCRegister Reg)
Removes a physical register, all its sub-registers, and all its super-registers from the set.
void addLiveInsNoPristines(const MachineBasicBlock &MBB)
Adds all live-in registers of basic block MBB but skips pristine registers.
Definition LivePhysRegs.cpp:253
void removeRegsInMask(const MachineOperand &MO, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > *Clobbers=nullptr)
Removes physical registers clobbered by the regmask operand MO.
Definition LivePhysRegs.cpp:31
bool empty() const
Returns true if the set is empty.
void dump() const
Dumps the currently live registers to the debug output.
Definition LivePhysRegs.cpp:136
MCRegAliasIterator enumerates all registers aliasing Reg.
Wrapper class representing physical registers. Should be passed by value.
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices.
bool isValid() const
isValid - Returns true until all the operands have been visited.
MIBundleOperands - Iterate over all operands in a bundle of machine instructions.
iterator_range< liveout_iterator > liveouts() const
iterator_range< livein_iterator > liveins() const
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
typename DenseT::iterator iterator
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< filter_iterator< ConstMIBundleOperands, bool(*)(const MachineOperand &)> > phys_regs_and_masks(const MachineInstr &MI)
Returns an iterator range over all physical register and mask operands for MI and bundled instruction...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void recomputeLivenessFlags(MachineBasicBlock &MBB)
Recomputes dead and kill flags in MBB.
Definition LivePhysRegs.cpp:285
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
bool isPhysRegUsedAfter(Register Reg, MachineBasicBlock::iterator MBI)
Check if physical register Reg is used after MBI.
Definition LivePhysRegs.cpp:353
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
Definition LivePhysRegs.cpp:345
void computeLiveIns(LivePhysRegs &LiveRegs, const MachineBasicBlock &MBB)
Computes registers live-in to MBB assuming all of its successors live-in lists are up-to-date.
Definition LivePhysRegs.cpp:257
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
void addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs)
Adds registers contained in LiveRegs to the block live-in list of MBB.
Definition LivePhysRegs.cpp:268
Pair of physical register and lane mask.