Skip to content

Commit

Permalink
[CodeGen] Remove atEnd method from defusechain iterators (llvm#120610)
Browse files Browse the repository at this point in the history
This was not used much and there are better ways of writing it.
  • Loading branch information
jayfoad authored Jan 2, 2025
1 parent f739aa4 commit 1849244
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
6 changes: 0 additions & 6 deletions llvm/include/llvm/CodeGen/MachineRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,6 @@ class MachineRegisterInfo {
return !operator==(x);
}

/// atEnd - return true if this iterator is equal to reg_end() on the value.
bool atEnd() const { return Op == nullptr; }

// Iterator traversal: forward iteration only
defusechain_iterator &operator++() { // Preincrement
assert(Op && "Cannot increment end iterator!");
Expand Down Expand Up @@ -1203,9 +1200,6 @@ class MachineRegisterInfo {
return !operator==(x);
}

/// atEnd - return true if this iterator is equal to reg_end() on the value.
bool atEnd() const { return Op == nullptr; }

// Iterator traversal: forward iteration only
defusechain_instr_iterator &operator++() { // Preincrement
assert(Op && "Cannot increment end iterator!");
Expand Down
8 changes: 5 additions & 3 deletions llvm/lib/CodeGen/MachineRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,11 @@ void MachineRegisterInfo::replaceRegWith(Register FromReg, Register ToReg) {
MachineInstr *MachineRegisterInfo::getVRegDef(Register Reg) const {
// Since we are in SSA form, we can use the first definition.
def_instr_iterator I = def_instr_begin(Reg);
assert((I.atEnd() || std::next(I) == def_instr_end()) &&
"getVRegDef assumes a single definition or no definition");
return !I.atEnd() ? &*I : nullptr;
if (I == def_instr_end())
return nullptr;
assert(std::next(I) == def_instr_end() &&
"getVRegDef assumes at most one definition");
return &*I;
}

/// getUniqueVRegDef - Return the unique machine instr that defines the
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/CodeGen/MachineTraceMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,10 @@ struct DataDep {
DataDep(const MachineRegisterInfo *MRI, unsigned VirtReg, unsigned UseOp)
: UseOp(UseOp) {
assert(Register::isVirtualRegister(VirtReg));
MachineRegisterInfo::def_iterator DefI = MRI->def_begin(VirtReg);
assert(!DefI.atEnd() && "Register has no defs");
DefMI = DefI->getParent();
DefOp = DefI.getOperandNo();
assert((++DefI).atEnd() && "Register has multiple defs");
MachineOperand *DefMO = MRI->getOneDef(VirtReg);
assert(DefMO && "Register does not have unique def");
DefMI = DefMO->getParent();
DefOp = DefMO->getOperandNo();
}
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SwiftErrorValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void SwiftErrorValueTracking::propagateVRegs() {
for (const auto &Use : VRegUpwardsUse) {
const MachineBasicBlock *UseBB = Use.first.first;
Register VReg = Use.second;
if (!MRI.def_begin(VReg).atEnd())
if (!MRI.def_empty(VReg))
continue;

#ifdef EXPENSIVE_CHECKS
Expand Down

0 comments on commit 1849244

Please sign in to comment.