Skip to content

Commit 6325446

Browse files
author
Evan Cheng
committed
Refactor code. Remove duplicated functions that basically do the same thing as
findRegisterUseOperandIdx, findRegisterDefOperandIndx. Fix some naming inconsistencies. llvm-svn: 47927
1 parent f9c67f6 commit 6325446

16 files changed

+170
-187
lines changed

llvm/include/llvm/CodeGen/LiveVariables.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class LiveVariables : public MachineFunctionPass {
130130
private: // Intermediate data structures
131131
MachineFunction *MF;
132132

133-
const TargetRegisterInfo *RegInfo;
133+
const TargetRegisterInfo *TRI;
134134

135135
// PhysRegInfo - Keep track of which instruction was the last def/use of a
136136
// physical register. This is a purely local property, because all physical
@@ -175,18 +175,10 @@ class LiveVariables : public MachineFunctionPass {
175175

176176
virtual bool runOnMachineFunction(MachineFunction &MF);
177177

178-
/// KillsRegister - Return true if the specified instruction kills the
179-
/// specified register.
180-
bool KillsRegister(MachineInstr *MI, unsigned Reg) const;
181-
182178
/// RegisterDefIsDead - Return true if the specified instruction defines the
183179
/// specified register, but that definition is dead.
184180
bool RegisterDefIsDead(MachineInstr *MI, unsigned Reg) const;
185181

186-
/// ModifiesRegister - Return true if the specified instruction modifies the
187-
/// specified register.
188-
bool ModifiesRegister(MachineInstr *MI, unsigned Reg) const;
189-
190182
//===--------------------------------------------------------------------===//
191183
// API to update live variable information
192184

@@ -202,7 +194,7 @@ class LiveVariables : public MachineFunctionPass {
202194
/// not found.
203195
void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
204196
bool AddIfNotFound = false) {
205-
if (MI->addRegisterKilled(IncomingReg, RegInfo, AddIfNotFound))
197+
if (MI->addRegisterKilled(IncomingReg, TRI, AddIfNotFound))
206198
getVarInfo(IncomingReg).Kills.push_back(MI);
207199
}
208200

@@ -239,7 +231,7 @@ class LiveVariables : public MachineFunctionPass {
239231
/// AddIfNotFound is true, add a implicit operand if it's not found.
240232
void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI,
241233
bool AddIfNotFound = false) {
242-
if (MI->addRegisterDead(IncomingReg, RegInfo, AddIfNotFound))
234+
if (MI->addRegisterDead(IncomingReg, TRI, AddIfNotFound))
243235
getVarInfo(IncomingReg).Kills.push_back(MI);
244236
}
245237

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,65 @@ class MachineInstr {
138138
///
139139
bool isDebugLabel() const;
140140

141+
/// readsRegister - Return true if the MachineInstr reads the specified
142+
/// register. If TargetRegisterInfo is passed, then it also checks if there
143+
/// is a read of a super-register.
144+
bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
145+
return findRegisterUseOperandIdx(Reg, false, TRI) != -1;
146+
}
147+
148+
/// killsRegister - Return true if the MachineInstr kills the specified
149+
/// register. If TargetRegisterInfo is passed, then it also checks if there is
150+
/// a kill of a super-register.
151+
bool killsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
152+
return findRegisterUseOperandIdx(Reg, true, TRI) != -1;
153+
}
154+
155+
/// modifiesRegister - Return true if the MachineInstr modifies the
156+
/// specified register. If TargetRegisterInfo is passed, then it also checks
157+
/// if there is a def of a super-register.
158+
bool modifiesRegister(unsigned Reg,
159+
const TargetRegisterInfo *TRI = NULL) const {
160+
return findRegisterDefOperandIdx(Reg, false, TRI) != -1;
161+
}
162+
163+
/// registerDefIsDead - Returns true if the register is dead in this machine
164+
/// instruction. If TargetRegisterInfo is passed, then it also checks
165+
/// if there is a dead def of a super-register.
166+
bool registerDefIsDead(unsigned Reg,
167+
const TargetRegisterInfo *TRI = NULL) const {
168+
return findRegisterDefOperandIdx(Reg, true, TRI) != -1;
169+
}
170+
141171
/// findRegisterUseOperandIdx() - Returns the operand index that is a use of
142172
/// the specific register or -1 if it is not found. It further tightening
143173
/// the search criteria to a use that kills the register if isKill is true.
144-
int findRegisterUseOperandIdx(unsigned Reg, bool isKill = false) const;
174+
int findRegisterUseOperandIdx(unsigned Reg, bool isKill = false,
175+
const TargetRegisterInfo *TRI = NULL) const;
176+
177+
/// findRegisterUseOperand - Wrapper for findRegisterUseOperandIdx, it returns
178+
/// a pointer to the MachineOperand rather than an index.
179+
MachineOperand *findRegisterUseOperand(unsigned Reg,bool isKill = false,
180+
const TargetRegisterInfo *TRI = NULL) {
181+
int Idx = findRegisterUseOperandIdx(Reg, isKill, TRI);
182+
return (Idx == -1) ? NULL : &getOperand(Idx);
183+
}
145184

146-
/// findRegisterDefOperand() - Returns the MachineOperand that is a def of
147-
/// the specific register or NULL if it is not found.
148-
MachineOperand *findRegisterDefOperand(unsigned Reg);
185+
/// findRegisterDefOperandIdx() - Returns the operand index that is a def of
186+
/// the specific register or -1 if it is not found. It further tightening
187+
/// the search criteria to a def that is dead the register if isDead is true.
188+
/// If TargetRegisterInfo is passed, then it also checks if there is a def of
189+
/// a super-register.
190+
int findRegisterDefOperandIdx(unsigned Reg, bool isDead = false,
191+
const TargetRegisterInfo *TRI = NULL) const;
192+
193+
/// findRegisterDefOperand - Wrapper for findRegisterDefOperandIdx, it returns
194+
/// a pointer to the MachineOperand rather than an index.
195+
MachineOperand *findRegisterDefOperand(unsigned Reg,bool isDead = false,
196+
const TargetRegisterInfo *TRI = NULL) {
197+
int Idx = findRegisterDefOperandIdx(Reg, isDead, TRI);
198+
return (Idx == -1) ? NULL : &getOperand(Idx);
199+
}
149200

150201
/// findFirstPredOperandIdx() - Find the index of the first operand in the
151202
/// operand list that is used to represent the predicate. It returns -1 if

llvm/include/llvm/CodeGen/RegisterScavenging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class RegScavenger {
127127
}
128128

129129
private:
130-
const TargetRegisterInfo *RegInfo;
130+
const TargetRegisterInfo *TRI;
131131
const TargetInstrInfo *TII;
132132

133133
/// CalleeSavedrRegs - A bitvector of callee saved registers for the target.

llvm/lib/CodeGen/LiveIntervalAnalysis.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
324324

325325
// If this redefinition is dead, we need to add a dummy unit live
326326
// range covering the def slot.
327-
if (lv_->RegisterDefIsDead(mi, interval.reg))
327+
if (mi->registerDefIsDead(interval.reg, tri_))
328328
interval.addRange(LiveRange(RedefIndex, RedefIndex+1, OldValNo));
329329

330330
DOUT << " RESULT: ";
@@ -399,7 +399,7 @@ void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock *MBB,
399399
// If it is not used after definition, it is considered dead at
400400
// the instruction defining it. Hence its interval is:
401401
// [defSlot(def), defSlot(def)+1)
402-
if (lv_->RegisterDefIsDead(mi, interval.reg)) {
402+
if (mi->registerDefIsDead(interval.reg, tri_)) {
403403
DOUT << " dead";
404404
end = getDefIndex(start) + 1;
405405
goto exit;
@@ -410,11 +410,11 @@ void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock *MBB,
410410
// [defSlot(def), useSlot(kill)+1)
411411
while (++mi != MBB->end()) {
412412
baseIndex += InstrSlots::NUM;
413-
if (lv_->KillsRegister(mi, interval.reg)) {
413+
if (mi->killsRegister(interval.reg, tri_)) {
414414
DOUT << " killed";
415415
end = getUseIndex(baseIndex) + 1;
416416
goto exit;
417-
} else if (lv_->ModifiesRegister(mi, interval.reg)) {
417+
} else if (mi->modifiesRegister(interval.reg, tri_)) {
418418
// Another instruction redefines the register before it is ever read.
419419
// Then the register is essentially dead at the instruction that defines
420420
// it. Hence its interval is:
@@ -459,8 +459,9 @@ void LiveIntervals::handleRegisterDef(MachineBasicBlock *MBB,
459459
handlePhysicalRegisterDef(MBB, MI, MIIdx, getOrCreateInterval(reg), CopyMI);
460460
// Def of a register also defines its sub-registers.
461461
for (const unsigned* AS = tri_->getSubRegisters(reg); *AS; ++AS)
462-
// Avoid processing some defs more than once.
463-
if (!MI->findRegisterDefOperand(*AS))
462+
// If MI also modifies the sub-register explicitly, avoid processing it
463+
// more than once. Do not pass in TRI here so it checks for exact match.
464+
if (!MI->modifiesRegister(*AS))
464465
handlePhysicalRegisterDef(MBB, MI, MIIdx, getOrCreateInterval(*AS), 0);
465466
}
466467
}
@@ -477,11 +478,11 @@ void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB,
477478
unsigned start = baseIndex;
478479
unsigned end = start;
479480
while (mi != MBB->end()) {
480-
if (lv_->KillsRegister(mi, interval.reg)) {
481+
if (mi->killsRegister(interval.reg, tri_)) {
481482
DOUT << " killed";
482483
end = getUseIndex(baseIndex) + 1;
483484
goto exit;
484-
} else if (lv_->ModifiesRegister(mi, interval.reg)) {
485+
} else if (mi->modifiesRegister(interval.reg, tri_)) {
485486
// Another instruction redefines the register before it is ever read.
486487
// Then the register is essentially dead at the instruction that defines
487488
// it. Hence its interval is:
@@ -842,9 +843,9 @@ void LiveIntervals::rewriteImplicitOps(const LiveInterval &li,
842843
if (!vrm.isReMaterialized(Reg))
843844
continue;
844845
MachineInstr *ReMatMI = vrm.getReMaterializedMI(Reg);
845-
int OpIdx = ReMatMI->findRegisterUseOperandIdx(li.reg);
846-
if (OpIdx != -1)
847-
ReMatMI->getOperand(OpIdx).setReg(NewVReg);
846+
MachineOperand *UseMO = ReMatMI->findRegisterUseOperand(li.reg);
847+
if (UseMO)
848+
UseMO->setReg(NewVReg);
848849
}
849850
}
850851

@@ -1605,7 +1606,7 @@ addIntervalsForSpills(const LiveInterval &li,
16051606
LiveRange *LR = &LI->ranges[LI->ranges.size()-1];
16061607
unsigned LastUseIdx = getBaseIndex(LR->end);
16071608
MachineInstr *LastUse = getInstructionFromIndex(LastUseIdx);
1608-
int UseIdx = LastUse->findRegisterUseOperandIdx(LI->reg);
1609+
int UseIdx = LastUse->findRegisterUseOperandIdx(LI->reg, false);
16091610
assert(UseIdx != -1);
16101611
if (LastUse->getOperand(UseIdx).isImplicit() ||
16111612
LastUse->getDesc().getOperandConstraint(UseIdx,TOI::TIED_TO) == -1){

0 commit comments

Comments
 (0)