Skip to content

Commit

Permalink
[NFC][CodeGen] Rename some functions in MachineInstr.h and remove dup…
Browse files Browse the repository at this point in the history
…licated comments
  • Loading branch information
KanRobert committed Mar 16, 2022
1 parent 14d1a58 commit 37b3783
Show file tree
Hide file tree
Showing 70 changed files with 225 additions and 234 deletions.
6 changes: 3 additions & 3 deletions llvm/include/llvm/CodeGen/MachineInstr.h
Expand Up @@ -1746,7 +1746,7 @@ class MachineInstr

/// Erase an operand from an instruction, leaving it with one
/// fewer operand than it started with.
void RemoveOperand(unsigned OpNo);
void removeOperand(unsigned OpNo);

/// Clear this MachineInstr's memory reference descriptor list. This resets
/// the memrefs to their most conservative state. This should be used only
Expand Down Expand Up @@ -1865,12 +1865,12 @@ class MachineInstr
/// Unlink all of the register operands in this instruction from their
/// respective use lists. This requires that the operands already be on their
/// use lists.
void RemoveRegOperandsFromUseLists(MachineRegisterInfo&);
void removeRegOperandsFromUseLists(MachineRegisterInfo&);

/// Add all of the register operands in this instruction from their
/// respective use lists. This requires that the operands not be on their
/// use lists yet.
void AddRegOperandsToUseLists(MachineRegisterInfo&);
void addRegOperandsToUseLists(MachineRegisterInfo&);

/// Slow path for hasProperty when we're dealing with a bundle.
bool hasPropertyInBundle(uint64_t Mask, QueryType Type) const;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/EarlyIfConversion.cpp
Expand Up @@ -663,8 +663,8 @@ void SSAIfConv::rewritePHIOperands() {
PI.PHI->getOperand(i-1).setMBB(Head);
PI.PHI->getOperand(i-2).setReg(DstReg);
} else if (MBB == getFPred()) {
PI.PHI->RemoveOperand(i-1);
PI.PHI->RemoveOperand(i-2);
PI.PHI->removeOperand(i-1);
PI.PHI->removeOperand(i-2);
}
}
LLVM_DEBUG(dbgs() << " --> " << *PI.PHI);
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/ExpandPostRAPseudos.cpp
Expand Up @@ -102,8 +102,8 @@ bool ExpandPostRA::LowerSubregToReg(MachineInstr *MI) {

if (MI->allDefsAreDead()) {
MI->setDesc(TII->get(TargetOpcode::KILL));
MI->RemoveOperand(3); // SubIdx
MI->RemoveOperand(1); // Imm
MI->removeOperand(3); // SubIdx
MI->removeOperand(1); // Imm
LLVM_DEBUG(dbgs() << "subreg: replaced by: " << *MI);
return true;
}
Expand All @@ -115,8 +115,8 @@ bool ExpandPostRA::LowerSubregToReg(MachineInstr *MI) {
// We must leave %rax live.
if (DstReg != InsReg) {
MI->setDesc(TII->get(TargetOpcode::KILL));
MI->RemoveOperand(3); // SubIdx
MI->RemoveOperand(1); // Imm
MI->removeOperand(3); // SubIdx
MI->removeOperand(1); // Imm
LLVM_DEBUG(dbgs() << "subreg: replace by: " << *MI);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
Expand Up @@ -4083,7 +4083,7 @@ void CombinerHelper::applyFunnelShiftToRotate(MachineInstr &MI) {
Observer.changingInstr(MI);
MI.setDesc(Builder.getTII().get(IsFSHL ? TargetOpcode::G_ROTL
: TargetOpcode::G_ROTR));
MI.RemoveOperand(2);
MI.removeOperand(2);
Observer.changedInstr(MI);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Expand Up @@ -3317,7 +3317,7 @@ LegalizerHelper::lower(MachineInstr &MI, unsigned TypeIdx, LLT LowerHintTy) {
Observer.changingInstr(MI);
const auto &TII = MIRBuilder.getTII();
MI.setDesc(TII.get(TargetOpcode::G_MUL));
MI.RemoveOperand(1);
MI.removeOperand(1);
Observer.changedInstr(MI);

auto HiPart = MIRBuilder.buildInstr(Opcode, {Ty}, {LHS, RHS});
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/InlineSpiller.cpp
Expand Up @@ -963,7 +963,7 @@ foldMemoryOperand(ArrayRef<std::pair<MachineInstr *, unsigned>> Ops,
if (!MO.isReg() || !MO.isImplicit())
break;
if (MO.getReg() == ImpReg)
FoldMI->RemoveOperand(i - 1);
FoldMI->removeOperand(i - 1);
}

LLVM_DEBUG(dumpMachineInstrRangeWithSlotIndex(MIS.begin(), MIS.end(), LIS,
Expand Down Expand Up @@ -1607,7 +1607,7 @@ void HoistSpillHelper::hoistAllSpills() {
for (unsigned i = RMEnt->getNumOperands(); i; --i) {
MachineOperand &MO = RMEnt->getOperand(i - 1);
if (MO.isReg() && MO.isImplicit() && MO.isDef() && !MO.isDead())
RMEnt->RemoveOperand(i - 1);
RMEnt->removeOperand(i - 1);
}
}
Edit.eliminateDeadDefs(SpillsToRm, None, AA);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/LiveRangeEdit.cpp
Expand Up @@ -371,7 +371,7 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink,
const MachineOperand &MO = MI->getOperand(i-1);
if (MO.isReg() && Register::isPhysicalRegister(MO.getReg()))
continue;
MI->RemoveOperand(i-1);
MI->removeOperand(i-1);
}
LLVM_DEBUG(dbgs() << "Converted physregs to:\t" << *MI);
} else {
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/MachineBasicBlock.cpp
Expand Up @@ -132,7 +132,7 @@ void ilist_callback_traits<MachineBasicBlock>::addNodeToList(
// Make sure the instructions have their operands in the reginfo lists.
MachineRegisterInfo &RegInfo = MF.getRegInfo();
for (MachineInstr &MI : N->instrs())
MI.AddRegOperandsToUseLists(RegInfo);
MI.addRegOperandsToUseLists(RegInfo);
}

void ilist_callback_traits<MachineBasicBlock>::removeNodeFromList(
Expand All @@ -150,7 +150,7 @@ void ilist_traits<MachineInstr>::addNodeToList(MachineInstr *N) {
// Add the instruction's register operands to their corresponding
// use/def lists.
MachineFunction *MF = Parent->getParent();
N->AddRegOperandsToUseLists(MF->getRegInfo());
N->addRegOperandsToUseLists(MF->getRegInfo());
MF->handleInsertion(*N);
}

Expand All @@ -162,7 +162,7 @@ void ilist_traits<MachineInstr>::removeNodeFromList(MachineInstr *N) {
// Remove from the use/def lists.
if (MachineFunction *MF = N->getMF()) {
MF->handleRemoval(*N);
N->RemoveRegOperandsFromUseLists(MF->getRegInfo());
N->removeRegOperandsFromUseLists(MF->getRegInfo());
}

N->setParent(nullptr);
Expand Down
19 changes: 5 additions & 14 deletions llvm/lib/CodeGen/MachineInstr.cpp
Expand Up @@ -146,19 +146,13 @@ MachineRegisterInfo *MachineInstr::getRegInfo() {
return nullptr;
}

/// RemoveRegOperandsFromUseLists - Unlink all of the register operands in
/// this instruction from their respective use lists. This requires that the
/// operands already be on their use lists.
void MachineInstr::RemoveRegOperandsFromUseLists(MachineRegisterInfo &MRI) {
void MachineInstr::removeRegOperandsFromUseLists(MachineRegisterInfo &MRI) {
for (MachineOperand &MO : operands())
if (MO.isReg())
MRI.removeRegOperandFromUseList(&MO);
}

/// AddRegOperandsToUseLists - Add all of the register operands in
/// this instruction from their respective use lists. This requires that the
/// operands not be on their use lists yet.
void MachineInstr::AddRegOperandsToUseLists(MachineRegisterInfo &MRI) {
void MachineInstr::addRegOperandsToUseLists(MachineRegisterInfo &MRI) {
for (MachineOperand &MO : operands())
if (MO.isReg())
MRI.addRegOperandToUseList(&MO);
Expand Down Expand Up @@ -279,10 +273,7 @@ void MachineInstr::addOperand(MachineFunction &MF, const MachineOperand &Op) {
}
}

/// RemoveOperand - Erase an operand from an instruction, leaving it with one
/// fewer operand than it started with.
///
void MachineInstr::RemoveOperand(unsigned OpNo) {
void MachineInstr::removeOperand(unsigned OpNo) {
assert(OpNo < getNumOperands() && "Invalid operand number");
untieRegOperand(OpNo);

Expand Down Expand Up @@ -1883,7 +1874,7 @@ bool MachineInstr::addRegisterKilled(Register IncomingReg,
unsigned OpIdx = DeadOps.back();
if (getOperand(OpIdx).isImplicit() &&
(!isInlineAsm() || findInlineAsmFlagIdx(OpIdx) < 0))
RemoveOperand(OpIdx);
removeOperand(OpIdx);
else
getOperand(OpIdx).setIsKill(false);
DeadOps.pop_back();
Expand Down Expand Up @@ -1948,7 +1939,7 @@ bool MachineInstr::addRegisterDead(Register Reg,
unsigned OpIdx = DeadOps.back();
if (getOperand(OpIdx).isImplicit() &&
(!isInlineAsm() || findInlineAsmFlagIdx(OpIdx) < 0))
RemoveOperand(OpIdx);
removeOperand(OpIdx);
else
getOperand(OpIdx).setIsDead(false);
DeadOps.pop_back();
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/MachineLoopUtils.cpp
Expand Up @@ -89,15 +89,15 @@ MachineBasicBlock *llvm::PeelSingleBlockLoop(LoopPeelDirection Direction,
if (Remaps.count(R))
R = Remaps[R];
OrigPhi.getOperand(InitRegIdx).setReg(R);
MI.RemoveOperand(LoopRegIdx + 1);
MI.RemoveOperand(LoopRegIdx + 0);
MI.removeOperand(LoopRegIdx + 1);
MI.removeOperand(LoopRegIdx + 0);
} else {
// When peeling back, the initial value is the loop-carried value from
// the original loop.
Register LoopReg = OrigPhi.getOperand(LoopRegIdx).getReg();
MI.getOperand(LoopRegIdx).setReg(LoopReg);
MI.RemoveOperand(InitRegIdx + 1);
MI.RemoveOperand(InitRegIdx + 0);
MI.removeOperand(InitRegIdx + 1);
MI.removeOperand(InitRegIdx + 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachineVerifier.cpp
Expand Up @@ -443,7 +443,7 @@ unsigned MachineVerifier::verify(const MachineFunction &MF) {
for (unsigned I = 0, E = MI.getNumOperands(); I != E; ++I) {
const MachineOperand &Op = MI.getOperand(I);
if (Op.getParent() != &MI) {
// Make sure to use correct addOperand / RemoveOperand / ChangeTo
// Make sure to use correct addOperand / removeOperand / ChangeTo
// functions when replacing operands of a MachineInstr.
report("Instruction has operand with wrong parent set", &MI);
}
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/ModuloSchedule.cpp
Expand Up @@ -814,8 +814,8 @@ static void removePhis(MachineBasicBlock *BB, MachineBasicBlock *Incoming) {
break;
for (unsigned i = 1, e = MI.getNumOperands(); i != e; i += 2)
if (MI.getOperand(i + 1).getMBB() == Incoming) {
MI.RemoveOperand(i + 1);
MI.RemoveOperand(i);
MI.removeOperand(i + 1);
MI.removeOperand(i);
break;
}
}
Expand Down Expand Up @@ -1930,8 +1930,8 @@ void PeelingModuloScheduleExpander::fixupBranches() {
// blocks. Leave it to unreachable-block-elim to clean up.
Prolog->removeSuccessor(Fallthrough);
for (MachineInstr &P : Fallthrough->phis()) {
P.RemoveOperand(2);
P.RemoveOperand(1);
P.removeOperand(2);
P.removeOperand(1);
}
TII->insertUnconditionalBranch(*Prolog, Epilog, DebugLoc());
KernelDisposed = true;
Expand All @@ -1940,8 +1940,8 @@ void PeelingModuloScheduleExpander::fixupBranches() {
// Prolog always falls through; remove incoming values in epilog.
Prolog->removeSuccessor(Epilog);
for (MachineInstr &P : Epilog->phis()) {
P.RemoveOperand(4);
P.RemoveOperand(3);
P.removeOperand(4);
P.removeOperand(3);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/PeepholeOptimizer.cpp
Expand Up @@ -1021,7 +1021,7 @@ class ExtractSubregRewriter : public Rewriter {
CurrentSrcIdx = -1;
// Rewrite the operation as a COPY.
// Get rid of the sub-register index.
CopyLike.RemoveOperand(2);
CopyLike.removeOperand(2);
// Morph the operation into a COPY.
CopyLike.setDesc(TII.get(TargetOpcode::COPY));
return true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/ProcessImplicitDefs.cpp
Expand Up @@ -125,7 +125,7 @@ void ProcessImplicitDefs::processImplicitDef(MachineInstr *MI) {
// Using instr wasn't found, it could be in another block.
// Leave the physreg IMPLICIT_DEF, but trim any extra operands.
for (unsigned i = MI->getNumOperands() - 1; i; --i)
MI->RemoveOperand(i);
MI->removeOperand(i);
LLVM_DEBUG(dbgs() << "Keeping physreg: " << *MI);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/RegisterCoalescer.cpp
Expand Up @@ -1647,7 +1647,7 @@ MachineInstr *RegisterCoalescer::eliminateUndefCopy(MachineInstr *CopyMI) {
for (unsigned i = CopyMI->getNumOperands(); i != 0; --i) {
MachineOperand &MO = CopyMI->getOperand(i-1);
if (MO.isReg() && MO.isUse())
CopyMI->RemoveOperand(i-1);
CopyMI->removeOperand(i-1);
}
LLVM_DEBUG(dbgs() << "\tReplaced copy of <undef> value with an "
"implicit def\n");
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/CodeGen/TailDuplicator.cpp
Expand Up @@ -368,8 +368,8 @@ void TailDuplicator::processPHI(
return;

// Remove PredBB from the PHI node.
MI->RemoveOperand(SrcOpIdx + 1);
MI->RemoveOperand(SrcOpIdx);
MI->removeOperand(SrcOpIdx + 1);
MI->removeOperand(SrcOpIdx);
if (MI->getNumOperands() == 1)
MI->eraseFromParent();
}
Expand Down Expand Up @@ -494,15 +494,15 @@ void TailDuplicator::updateSuccessorsPHIs(
for (unsigned i = MI.getNumOperands() - 2; i != Idx; i -= 2) {
MachineOperand &MO = MI.getOperand(i + 1);
if (MO.getMBB() == FromBB) {
MI.RemoveOperand(i + 1);
MI.RemoveOperand(i);
MI.removeOperand(i + 1);
MI.removeOperand(i);
}
}
} else
Idx = 0;

// If Idx is set, the operands at Idx and Idx+1 must be removed.
// We reuse the location to avoid expensive RemoveOperand calls.
// We reuse the location to avoid expensive removeOperand calls.

DenseMap<Register, AvailableValsTy>::iterator LI =
SSAUpdateVals.find(Reg);
Expand Down Expand Up @@ -539,8 +539,8 @@ void TailDuplicator::updateSuccessorsPHIs(
}
}
if (Idx != 0) {
MI.RemoveOperand(Idx + 1);
MI.RemoveOperand(Idx);
MI.removeOperand(Idx + 1);
MI.removeOperand(Idx);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
Expand Up @@ -1731,11 +1731,11 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &Func) {
// From %reg = INSERT_SUBREG %reg, %subreg, subidx
// To %reg:subidx = COPY %subreg
unsigned SubIdx = mi->getOperand(3).getImm();
mi->RemoveOperand(3);
mi->removeOperand(3);
assert(mi->getOperand(0).getSubReg() == 0 && "Unexpected subreg idx");
mi->getOperand(0).setSubReg(SubIdx);
mi->getOperand(0).setIsUndef(mi->getOperand(1).isUndef());
mi->RemoveOperand(1);
mi->removeOperand(1);
mi->setDesc(TII->get(TargetOpcode::COPY));
LLVM_DEBUG(dbgs() << "\t\tconvert to:\t" << *mi);

Expand Down Expand Up @@ -1856,7 +1856,7 @@ eliminateRegSequence(MachineBasicBlock::iterator &MBBI) {
LLVM_DEBUG(dbgs() << "Turned: " << MI << " into an IMPLICIT_DEF");
MI.setDesc(TII->get(TargetOpcode::IMPLICIT_DEF));
for (int j = MI.getNumOperands() - 1, ee = 0; j > ee; --j)
MI.RemoveOperand(j);
MI.removeOperand(j);
} else {
if (LIS)
LIS->RemoveMachineInstrFromMaps(MI);
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/UnreachableBlockElim.cpp
Expand Up @@ -125,8 +125,8 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
for (unsigned i = start->getNumOperands() - 1; i >= 2; i-=2)
if (start->getOperand(i).isMBB() &&
start->getOperand(i).getMBB() == &BB) {
start->RemoveOperand(i);
start->RemoveOperand(i-1);
start->removeOperand(i);
start->removeOperand(i-1);
}

start++;
Expand Down Expand Up @@ -156,8 +156,8 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
while (phi != BB.end() && phi->isPHI()) {
for (unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
if (!preds.count(phi->getOperand(i).getMBB())) {
phi->RemoveOperand(i);
phi->RemoveOperand(i-1);
phi->removeOperand(i);
phi->removeOperand(i-1);
ModifiedPHI = true;
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
Expand Up @@ -247,8 +247,8 @@ void SSACCmpConv::updateTailPHIs() {
for (unsigned oi = I.getNumOperands(); oi > 2; oi -= 2) {
// PHI operands are (Reg, MBB) at (oi-2, oi-1).
if (I.getOperand(oi - 1).getMBB() == CmpBB) {
I.RemoveOperand(oi - 1);
I.RemoveOperand(oi - 2);
I.removeOperand(oi - 1);
I.removeOperand(oi - 2);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Expand Up @@ -1438,7 +1438,7 @@ bool AArch64InstrInfo::optimizeCompareInstr(
return false;
const MCInstrDesc &MCID = get(NewOpc);
CmpInstr.setDesc(MCID);
CmpInstr.RemoveOperand(DeadNZCVIdx);
CmpInstr.removeOperand(DeadNZCVIdx);
bool succeeded = UpdateOperandRegClass(CmpInstr);
(void)succeeded;
assert(succeeded && "Some operands reg class are incompatible!");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
Expand Up @@ -360,8 +360,8 @@ AArch64SLSHardening::ConvertBLRToBL(MachineBasicBlock &MBB,
assert(ImpSPOpIdx != -1);
int FirstOpIdxToRemove = std::max(ImpLROpIdx, ImpSPOpIdx);
int SecondOpIdxToRemove = std::min(ImpLROpIdx, ImpSPOpIdx);
BL->RemoveOperand(FirstOpIdxToRemove);
BL->RemoveOperand(SecondOpIdxToRemove);
BL->removeOperand(FirstOpIdxToRemove);
BL->removeOperand(SecondOpIdxToRemove);
// Now copy over the implicit operands from the original BLR
BL->copyImplicitOps(MF, BLR);
MF.moveCallSiteInfo(&BLR, BL);
Expand Down
Expand Up @@ -260,7 +260,7 @@ void applyFoldMergeToZext(MachineInstr &MI, MachineRegisterInfo &MRI,
// %d(s64) = G_ZEXT %a(s32)
Observer.changingInstr(MI);
MI.setDesc(B.getTII().get(TargetOpcode::G_ZEXT));
MI.RemoveOperand(2);
MI.removeOperand(2);
Observer.changedInstr(MI);
}

Expand Down

0 comments on commit 37b3783

Please sign in to comment.