From b29a2b0c4c69971a179652cb262e970fde5fc9ed Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sat, 5 Apr 2014 22:42:04 +0000 Subject: [PATCH] MachineInstr: introduce explicit_operands and implicit_operands ranges Makes iteration over implicit and explicit machine operands more explicit (har har). Insipired by code review discussion for r205565. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205680 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineInstr.h | 16 ++++++++++++++++ .../ARM64/ARM64DeadRegisterDefinitionsPass.cpp | 5 +---- lib/Target/R600/AMDGPUMCInstLower.cpp | 4 +--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index 440d3a1302f..217d2b16668 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -293,6 +293,22 @@ public: iterator_range operands() const { return iterator_range(operands_begin(), operands_end()); } + iterator_range explicit_operands() { + return iterator_range( + operands_begin(), operands_begin() + getNumExplicitOperands()); + } + iterator_range explicit_operands() const { + return iterator_range( + operands_begin(), operands_begin() + getNumExplicitOperands()); + } + iterator_range implicit_operands() { + return iterator_range(explicit_operands().end(), + operands_end()); + } + iterator_range implicit_operands() const { + return iterator_range(explicit_operands().end(), + operands_end()); + } /// Access to memory operands of the instruction mmo_iterator memoperands_begin() const { return MemRefs; } diff --git a/lib/Target/ARM64/ARM64DeadRegisterDefinitionsPass.cpp b/lib/Target/ARM64/ARM64DeadRegisterDefinitionsPass.cpp index f85dbaa806f..f6034dcf4d0 100644 --- a/lib/Target/ARM64/ARM64DeadRegisterDefinitionsPass.cpp +++ b/lib/Target/ARM64/ARM64DeadRegisterDefinitionsPass.cpp @@ -50,13 +50,10 @@ char ARM64DeadRegisterDefinitions::ID = 0; bool ARM64DeadRegisterDefinitions::implicitlyDefinesSubReg( unsigned Reg, const MachineInstr *MI) { - for (unsigned i = MI->getNumExplicitOperands(), e = MI->getNumOperands(); - i != e; ++i) { - const MachineOperand &MO = MI->getOperand(i); + for (const MachineOperand &MO : MI->implicit_operands()) if (MO.isReg() && MO.isDef()) if (TRI->isSubRegister(Reg, MO.getReg())) return true; - } return false; } diff --git a/lib/Target/R600/AMDGPUMCInstLower.cpp b/lib/Target/R600/AMDGPUMCInstLower.cpp index 2c9909ff9d9..d65b00f018c 100644 --- a/lib/Target/R600/AMDGPUMCInstLower.cpp +++ b/lib/Target/R600/AMDGPUMCInstLower.cpp @@ -38,9 +38,7 @@ AMDGPUMCInstLower::AMDGPUMCInstLower(MCContext &ctx): void AMDGPUMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const { OutMI.setOpcode(MI->getOpcode()); - for (unsigned i = 0, e = MI->getNumExplicitOperands(); i != e; ++i) { - const MachineOperand &MO = MI->getOperand(i); - + for (const MachineOperand &MO : MI->explicit_operands()) { MCOperand MCOp; switch (MO.getType()) { default: -- 2.34.1