[llvm] [CodeGen] Use MachineInstr::{all_uses, all_defs} (NFC) (PR #106404)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 08:08:20 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/106404
None
>From 3ede70c0c272d5904e720f2cc933ad724198ec9b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 28 Aug 2024 07:43:34 -0700
Subject: [PATCH] [CodeGen] Use MachineInstr::{all_uses,all_defs} (NFC)
---
.../CodeGen/MachineConvergenceVerifier.cpp | 4 +---
llvm/lib/CodeGen/MachineInstr.cpp | 20 +++++++------------
llvm/lib/CodeGen/RegAllocFast.cpp | 4 +---
3 files changed, 9 insertions(+), 19 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineConvergenceVerifier.cpp b/llvm/lib/CodeGen/MachineConvergenceVerifier.cpp
index 3d3c55faa82465..ac6b04a202c533 100644
--- a/llvm/lib/CodeGen/MachineConvergenceVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineConvergenceVerifier.cpp
@@ -51,9 +51,7 @@ GenericConvergenceVerifier<MachineSSAContext>::findAndCheckConvergenceTokenUsed(
const MachineRegisterInfo &MRI = Context.getFunction()->getRegInfo();
const MachineInstr *TokenDef = nullptr;
- for (const MachineOperand &MO : MI.operands()) {
- if (!MO.isReg() || !MO.isUse())
- continue;
+ for (const MachineOperand &MO : MI.all_uses()) {
Register OpReg = MO.getReg();
if (!OpReg.isVirtual())
continue;
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index f21910ee3a444a..7f81aeb545d328 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -1041,10 +1041,9 @@ unsigned MachineInstr::getBundleSize() const {
/// Returns true if the MachineInstr has an implicit-use operand of exactly
/// the given register (not considering sub/super-registers).
bool MachineInstr::hasRegisterImplicitUseOperand(Register Reg) const {
- for (const MachineOperand &MO : operands()) {
- if (MO.isReg() && MO.isUse() && MO.isImplicit() && MO.getReg() == Reg)
+ for (const MachineOperand &MO : all_uses())
+ if (MO.isImplicit() && MO.getReg() == Reg)
return true;
- }
return false;
}
@@ -1264,10 +1263,8 @@ unsigned MachineInstr::findTiedOperandIdx(unsigned OpIdx) const {
/// clearKillInfo - Clears kill flags on all operands.
///
void MachineInstr::clearKillInfo() {
- for (MachineOperand &MO : operands()) {
- if (MO.isReg() && MO.isUse())
- MO.setIsKill(false);
- }
+ for (MachineOperand &MO : all_uses())
+ MO.setIsKill(false);
}
void MachineInstr::substituteRegister(Register FromReg, Register ToReg,
@@ -1549,12 +1546,9 @@ bool MachineInstr::isLoadFoldBarrier() const {
/// allDefsAreDead - Return true if all the defs of this instruction are dead.
///
bool MachineInstr::allDefsAreDead() const {
- for (const MachineOperand &MO : operands()) {
- if (!MO.isReg() || MO.isUse())
- continue;
+ for (const MachineOperand &MO : all_defs())
if (!MO.isDead())
return false;
- }
return true;
}
@@ -2063,8 +2057,8 @@ void MachineInstr::clearRegisterKills(Register Reg,
const TargetRegisterInfo *RegInfo) {
if (!Reg.isPhysical())
RegInfo = nullptr;
- for (MachineOperand &MO : operands()) {
- if (!MO.isReg() || !MO.isUse() || !MO.isKill())
+ for (MachineOperand &MO : all_uses()) {
+ if (!MO.isKill())
continue;
Register OpReg = MO.getReg();
if ((RegInfo && RegInfo->regsOverlap(Reg, OpReg)) || Reg == OpReg)
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index 6babd5a3f1f96f..a0a8a8897af7f2 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -1563,9 +1563,7 @@ void RegAllocFastImpl::allocateInstruction(MachineInstr &MI) {
bool ReArrangedImplicitMOs = true;
while (ReArrangedImplicitMOs) {
ReArrangedImplicitMOs = false;
- for (MachineOperand &MO : MI.operands()) {
- if (!MO.isReg() || !MO.isUse())
- continue;
+ for (MachineOperand &MO : MI.all_uses()) {
Register Reg = MO.getReg();
if (!Reg.isVirtual() || !shouldAllocateRegister(Reg))
continue;
More information about the llvm-commits
mailing list