Skip to content

Commit 6de4865

Browse files
[llvm] Use hasSingleElement (NFC)
1 parent e53472d commit 6de4865

File tree

5 files changed

+8
-27
lines changed

5 files changed

+8
-27
lines changed

llvm/include/llvm/CodeGen/MachineRegisterInfo.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,7 @@ class MachineRegisterInfo {
442442
/// Return true if there is exactly one operand defining the specified
443443
/// register.
444444
bool hasOneDef(Register RegNo) const {
445-
def_iterator DI = def_begin(RegNo);
446-
if (DI == def_end())
447-
return false;
448-
return ++DI == def_end();
445+
return hasSingleElement(def_operands(RegNo));
449446
}
450447

451448
/// Returns the defining operand if there is exactly one operand defining the
@@ -511,10 +508,7 @@ class MachineRegisterInfo {
511508
/// hasOneUse - Return true if there is exactly one instruction using the
512509
/// specified register.
513510
bool hasOneUse(Register RegNo) const {
514-
use_iterator UI = use_begin(RegNo);
515-
if (UI == use_end())
516-
return false;
517-
return ++UI == use_end();
511+
return hasSingleElement(use_operands(RegNo));
518512
}
519513

520514
/// use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,7 @@ END_TWO_BYTE_PACK()
689689
bool use_empty() const { return UseList == nullptr; }
690690

691691
/// Return true if there is exactly one use of this node.
692-
bool hasOneUse() const {
693-
return !use_empty() && std::next(use_begin()) == use_end();
694-
}
692+
bool hasOneUse() const { return hasSingleElement(uses()); }
695693

696694
/// Return the number of uses of this node. This method takes
697695
/// time proportional to the number of uses.

llvm/include/llvm/IR/Value.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,7 @@ class Value {
434434
///
435435
/// This is specialized because it is a common request and does not require
436436
/// traversing the whole use list.
437-
bool hasOneUse() const {
438-
const_use_iterator I = use_begin(), E = use_end();
439-
if (I == E) return false;
440-
return ++I == E;
441-
}
437+
bool hasOneUse() const { return hasSingleElement(uses()); }
442438

443439
/// Return true if this Value has exactly N uses.
444440
bool hasNUses(unsigned N) const;

llvm/lib/CodeGen/MachineRegisterInfo.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,17 +417,11 @@ MachineInstr *MachineRegisterInfo::getUniqueVRegDef(Register Reg) const {
417417
}
418418

419419
bool MachineRegisterInfo::hasOneNonDBGUse(Register RegNo) const {
420-
use_nodbg_iterator UI = use_nodbg_begin(RegNo);
421-
if (UI == use_nodbg_end())
422-
return false;
423-
return ++UI == use_nodbg_end();
420+
return hasSingleElement(use_nodbg_operands(RegNo));
424421
}
425422

426423
bool MachineRegisterInfo::hasOneNonDBGUser(Register RegNo) const {
427-
use_instr_nodbg_iterator UI = use_instr_nodbg_begin(RegNo);
428-
if (UI == use_instr_nodbg_end())
429-
return false;
430-
return ++UI == use_instr_nodbg_end();
424+
return hasSingleElement(use_nodbg_instructions(RegNo));
431425
}
432426

433427
/// clearKillFlags - Iterate over all the uses of the given register and

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,12 @@ Optional<object::SectionedAddress>
194194
DWARFUnit::getAddrOffsetSectionItem(uint32_t Index) const {
195195
if (IsDWO) {
196196
auto R = Context.info_section_units();
197-
auto I = R.begin();
198197
// Surprising if a DWO file has more than one skeleton unit in it - this
199198
// probably shouldn't be valid, but if a use case is found, here's where to
200199
// support it (probably have to linearly search for the matching skeleton CU
201200
// here)
202-
if (I != R.end() && std::next(I) == R.end())
203-
return (*I)->getAddrOffsetSectionItem(Index);
201+
if (hasSingleElement(R))
202+
return (*R.begin())->getAddrOffsetSectionItem(Index);
204203
}
205204
if (!AddrOffsetSectionBase)
206205
return None;

0 commit comments

Comments
 (0)