43 "Live Variable Analysis",
false,
false)
58 unsigned LastDefDist = 0;
64 unsigned Dist = DistanceMap[Def];
65 if (Dist > LastDefDist) {
78 MachineInstr *LastDef = PhysRegDef[
Reg.
id()];
80 if (!LastDef && !PhysRegUse[
Reg.
id()]) {
89 MachineInstr *LastPartialDef = FindLastPartialDef(
Reg);
95 }
else if (LastDef && !PhysRegUse[
Reg.
id()] &&
103 PhysRegUse[SubReg] = &
MI;
104 TrackedRegs.set(SubReg);
111 MachineInstr *LastDef = PhysRegDef[
Reg.
id()];
112 MachineInstr *LastUse = PhysRegUse[
Reg.
id()];
113 if (!LastDef && !LastUse)
116 MachineInstr *LastRefOrPartRef = LastUse ? LastUse : LastDef;
117 unsigned LastRefOrPartRefDist = DistanceMap[LastRefOrPartRef];
119 MachineInstr *
Def = PhysRegDef[SubReg];
120 if (Def && Def != LastDef)
122 if (MachineInstr *Use = PhysRegUse[SubReg]) {
123 unsigned Dist = DistanceMap[
Use];
124 if (Dist > LastRefOrPartRefDist) {
125 LastRefOrPartRefDist = Dist;
126 LastRefOrPartRef =
Use;
131 return LastRefOrPartRef;
135 MachineInstr *LastDef = PhysRegDef[
Reg.
id()];
136 MachineInstr *LastUse = PhysRegUse[
Reg.
id()];
137 if (!LastDef && !LastUse)
140 MachineInstr *LastRefOrPartRef = LastUse ? LastUse : LastDef;
141 unsigned LastRefOrPartRefDist = DistanceMap[LastRefOrPartRef];
159 MachineInstr *LastPartDef =
nullptr;
160 unsigned LastPartDefDist = 0;
161 SmallSet<unsigned, 8> PartUses;
163 MachineInstr *
Def = PhysRegDef[SubReg];
164 if (Def && Def != LastDef) {
167 unsigned Dist = DistanceMap[
Def];
168 if (Dist > LastPartDefDist) {
169 LastPartDefDist = Dist;
174 if (MachineInstr *Use = PhysRegUse[SubReg]) {
176 unsigned Dist = DistanceMap[
Use];
177 if (Dist > LastRefOrPartRefDist) {
178 LastRefOrPartRefDist = Dist;
179 LastRefOrPartRef =
Use;
184 if (!PhysRegUse[
Reg.
id()]) {
189 PhysRegDef[
Reg.
id()]->addRegisterDead(
Reg, TRI,
true);
191 if (!PartUses.
count(SubReg))
194 if (PhysRegDef[
Reg.
id()] == PhysRegDef[SubReg]) {
195 MachineOperand *MO = PhysRegDef[
Reg.
id()]->findRegisterDefOperand(
203 PhysRegDef[
Reg.
id()]->addOperand(
205 if (!FindLastRefOrPartRef(SubReg)) {
206 for (
MCPhysReg SS : TRI->subregs_inclusive(SubReg)) {
207 PhysRegUse[
SS] = LastRefOrPartRef;
211 for (
MCPhysReg SS : TRI->subregs(SubReg))
214 }
else if (LastRefOrPartRef == PhysRegDef[
Reg.
id()] &&
215 LastRefOrPartRef !=
MI && !LastPartDef) {
232void LiveVariables::HandleRegMask(
const MachineOperand &MO,
unsigned NumRegs) {
236 for (
unsigned Reg : TrackedRegs.set_bits()) {
238 if (!PhysRegDef[
Reg] && !PhysRegUse[
Reg])
245 unsigned Super =
Reg;
247 if (SR < NumRegs && (PhysRegDef[SR] || PhysRegUse[SR]) &&
250 HandlePhysRegKill(Super,
nullptr);
256 SmallSet<unsigned, 32> Live;
257 if (PhysRegDef[
Reg.
id()] || PhysRegUse[
Reg.
id()]) {
267 if (Live.
count(SubReg))
269 if (PhysRegDef[SubReg] || PhysRegUse[SubReg])
276 HandlePhysRegKill(
Reg,
MI);
279 if (!Live.
count(SubReg))
282 HandlePhysRegKill(SubReg,
MI);
290 PhysRegDef[SubReg] = &
MI;
291 PhysRegUse[SubReg] =
nullptr;
292 TrackedRegs.set(SubReg);
297void LiveVariables::runOnInstr(
MachineInstr &
MI,
unsigned NumRegs) {
303 SmallVector<unsigned, 1> RegMasks;
312 if (!MOReg.
isPhysical() || MRI->isReserved(MOReg))
327 HandlePhysRegUse(MOReg,
MI);
330 for (
unsigned Mask : RegMasks)
331 HandleRegMask(
MI.getOperand(Mask), NumRegs);
335 HandlePhysRegDef(MOReg, &
MI);
336 UpdatePhysRegDefs(
MI, DefRegs);
343 for (MachineInstr &
MI : *
MBB) {
344 if (
MI.isDebugOrPseudoInstr())
346 DistanceMap.insert(std::make_pair(&
MI, Dist++));
348 runOnInstr(
MI, NumRegs);
353 SmallSet<MCRegister, 4> LiveOuts;
355 if (SuccMBB->isEHPad())
357 for (
const auto &LI : SuccMBB->liveins()) {
358 if (!TRI->isInAllocatableClass(LI.PhysReg))
360 LiveOuts.
insert(LI.PhysReg);
366 for (
unsigned Reg : TrackedRegs.set_bits())
368 HandlePhysRegDef(
Reg,
nullptr);
381 const unsigned NumRegs = TRI->getNumSupportedRegs(mf);
382 PhysRegDef.assign(NumRegs,
nullptr);
383 PhysRegUse.assign(NumRegs,
nullptr);
385 TrackedRegs.resize(NumRegs);
387 for (MachineBasicBlock &
MBB : mf) {
388 runOnBlock(&
MBB, NumRegs);
390 for (
unsigned Reg : TrackedRegs.set_bits()) {
391 PhysRegDef[
Reg] =
nullptr;
392 PhysRegUse[
Reg] =
nullptr;
397 for (
unsigned I = 0,
E = MRI->getNumVirtRegs();
I !=
E; ++
I) {
399 MachineInstr *
Def = MRI->getVRegDef(
Reg);
400 if (Def &&
none_of(MRI->use_nodbg_operands(
Reg),
401 [](
const MachineOperand &MO) { return MO.readsReg(); }))
402 Def->addRegisterDead(
Reg, TRI);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallSet class.
Represent the analysis usage information of a pass.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)
LiveVariablesWrapperPass()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
iterator_range< succ_iterator > successors()
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
MachineOperand * findRegisterDefOperand(Register Reg, const TargetRegisterInfo *TRI, bool isDead=false, bool Overlap=false)
Wrapper for findRegisterDefOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
LLVM_ABI bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
MachineOperand class - Representation of each machine instruction operand.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
void setIsDead(bool Val=true)
void setIsEarlyClobber(bool Val=true)
bool isEarlyClobber() const
Register getReg() const
getReg - Returns the register number.
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
constexpr unsigned id() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
void insert_range(Range &&R)
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void push_back(const T &Elt)
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
NodeAddr< DefNode * > Def
NodeAddr< UseNode * > Use
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI char & UnreachableMachineBlockElimID
UnreachableMachineBlockElimination - This pass removes unreachable machine basic blocks.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
LLVM_ABI char & LiveVariablesID
LiveVariables pass - This pass sets dead flags on register definitions.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
A special type used by analysis passes to provide an address that identifies that particular analysis...