From 6de4865545da73687dd6d28d153cd345ed5e7918 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 20 Jan 2021 21:35:55 -0800 Subject: [PATCH] [llvm] Use hasSingleElement (NFC) --- llvm/include/llvm/CodeGen/MachineRegisterInfo.h | 10 ++-------- llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 4 +--- llvm/include/llvm/IR/Value.h | 6 +----- llvm/lib/CodeGen/MachineRegisterInfo.cpp | 10 ++-------- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp | 5 ++--- 5 files changed, 8 insertions(+), 27 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h index a1a6705..57086b4 100644 --- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h @@ -442,10 +442,7 @@ public: /// Return true if there is exactly one operand defining the specified /// register. bool hasOneDef(Register RegNo) const { - def_iterator DI = def_begin(RegNo); - if (DI == def_end()) - return false; - return ++DI == def_end(); + return hasSingleElement(def_operands(RegNo)); } /// Returns the defining operand if there is exactly one operand defining the @@ -511,10 +508,7 @@ public: /// hasOneUse - Return true if there is exactly one instruction using the /// specified register. bool hasOneUse(Register RegNo) const { - use_iterator UI = use_begin(RegNo); - if (UI == use_end()) - return false; - return ++UI == use_end(); + return hasSingleElement(use_operands(RegNo)); } /// use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index 3d12240..000e383 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -689,9 +689,7 @@ public: bool use_empty() const { return UseList == nullptr; } /// Return true if there is exactly one use of this node. - bool hasOneUse() const { - return !use_empty() && std::next(use_begin()) == use_end(); - } + bool hasOneUse() const { return hasSingleElement(uses()); } /// Return the number of uses of this node. This method takes /// time proportional to the number of uses. diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h index e84840a..2a9912d 100644 --- a/llvm/include/llvm/IR/Value.h +++ b/llvm/include/llvm/IR/Value.h @@ -434,11 +434,7 @@ public: /// /// This is specialized because it is a common request and does not require /// traversing the whole use list. - bool hasOneUse() const { - const_use_iterator I = use_begin(), E = use_end(); - if (I == E) return false; - return ++I == E; - } + bool hasOneUse() const { return hasSingleElement(uses()); } /// Return true if this Value has exactly N uses. bool hasNUses(unsigned N) const; diff --git a/llvm/lib/CodeGen/MachineRegisterInfo.cpp b/llvm/lib/CodeGen/MachineRegisterInfo.cpp index 9165d6d..b34ea81 100644 --- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp +++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp @@ -417,17 +417,11 @@ MachineInstr *MachineRegisterInfo::getUniqueVRegDef(Register Reg) const { } bool MachineRegisterInfo::hasOneNonDBGUse(Register RegNo) const { - use_nodbg_iterator UI = use_nodbg_begin(RegNo); - if (UI == use_nodbg_end()) - return false; - return ++UI == use_nodbg_end(); + return hasSingleElement(use_nodbg_operands(RegNo)); } bool MachineRegisterInfo::hasOneNonDBGUser(Register RegNo) const { - use_instr_nodbg_iterator UI = use_instr_nodbg_begin(RegNo); - if (UI == use_instr_nodbg_end()) - return false; - return ++UI == use_instr_nodbg_end(); + return hasSingleElement(use_nodbg_instructions(RegNo)); } /// clearKillFlags - Iterate over all the uses of the given register and diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index ffd7d1e..8493950 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -194,13 +194,12 @@ Optional DWARFUnit::getAddrOffsetSectionItem(uint32_t Index) const { if (IsDWO) { auto R = Context.info_section_units(); - auto I = R.begin(); // Surprising if a DWO file has more than one skeleton unit in it - this // probably shouldn't be valid, but if a use case is found, here's where to // support it (probably have to linearly search for the matching skeleton CU // here) - if (I != R.end() && std::next(I) == R.end()) - return (*I)->getAddrOffsetSectionItem(Index); + if (hasSingleElement(R)) + return (*R.begin())->getAddrOffsetSectionItem(Index); } if (!AddrOffsetSectionBase) return None; -- 2.7.4