-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CodeGen] Use MachineInstr::all_defs (NFC) #106017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_all_defs_CodeGen
Aug 26, 2024
Merged
[CodeGen] Use MachineInstr::all_defs (NFC) #106017
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_all_defs_CodeGen
Aug 26, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-regalloc Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/106017.diff 6 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/LiveVariables.h b/llvm/include/llvm/CodeGen/LiveVariables.h
index b73850bb757ec3..89d1b5edf3fa63 100644
--- a/llvm/include/llvm/CodeGen/LiveVariables.h
+++ b/llvm/include/llvm/CodeGen/LiveVariables.h
@@ -253,8 +253,8 @@ class LiveVariables {
return false;
bool Removed = false;
- for (MachineOperand &MO : MI.operands()) {
- if (MO.isReg() && MO.isDef() && MO.getReg() == Reg) {
+ for (MachineOperand &MO : MI.all_defs()) {
+ if (MO.getReg() == Reg) {
MO.setIsDead(false);
Removed = true;
break;
diff --git a/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp b/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
index bccd9b04cd2c5c..e40248197c7c7c 100644
--- a/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
+++ b/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
@@ -402,8 +402,7 @@ void AggressiveAntiDepBreaker::PrescanInstruction(
// Scan the register defs for this instruction and update
// live-ranges.
- for (const MachineOperand &MO : MI.operands()) {
- if (!MO.isReg() || !MO.isDef()) continue;
+ for (const MachineOperand &MO : MI.all_defs()) {
Register Reg = MO.getReg();
if (Reg == 0) continue;
// Ignore KILLs and passthru registers for liveness...
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 0f2acdb12389d4..f21910ee3a444a 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -2125,19 +2125,15 @@ bool MachineInstr::addRegisterDead(Register Reg,
}
void MachineInstr::clearRegisterDeads(Register Reg) {
- for (MachineOperand &MO : operands()) {
- if (!MO.isReg() || !MO.isDef() || MO.getReg() != Reg)
- continue;
- MO.setIsDead(false);
- }
+ for (MachineOperand &MO : all_defs())
+ if (MO.getReg() == Reg)
+ MO.setIsDead(false);
}
void MachineInstr::setRegisterDefReadUndef(Register Reg, bool IsUndef) {
- for (MachineOperand &MO : operands()) {
- if (!MO.isReg() || !MO.isDef() || MO.getReg() != Reg || MO.getSubReg() == 0)
- continue;
- MO.setIsUndef(IsUndef);
- }
+ for (MachineOperand &MO : all_defs())
+ if (MO.getReg() == Reg && MO.getSubReg() != 0)
+ MO.setIsUndef(IsUndef);
}
void MachineInstr::addRegisterDefined(Register Reg,
@@ -2147,9 +2143,8 @@ void MachineInstr::addRegisterDefined(Register Reg,
if (MO)
return;
} else {
- for (const MachineOperand &MO : operands()) {
- if (MO.isReg() && MO.getReg() == Reg && MO.isDef() &&
- MO.getSubReg() == 0)
+ for (const MachineOperand &MO : all_defs()) {
+ if (MO.getReg() == Reg && MO.getSubReg() == 0)
return;
}
}
diff --git a/llvm/lib/CodeGen/ModuloSchedule.cpp b/llvm/lib/CodeGen/ModuloSchedule.cpp
index 78201d9bfb79a9..99c82bc3a2660a 100644
--- a/llvm/lib/CodeGen/ModuloSchedule.cpp
+++ b/llvm/lib/CodeGen/ModuloSchedule.cpp
@@ -2667,8 +2667,8 @@ void ModuloScheduleExpanderMVE::calcNumUnroll() {
void ModuloScheduleExpanderMVE::updateInstrDef(MachineInstr *NewMI,
ValueMapTy &VRMap,
bool LastDef) {
- for (MachineOperand &MO : NewMI->operands()) {
- if (!MO.isReg() || !MO.getReg().isVirtual() || !MO.isDef())
+ for (MachineOperand &MO : NewMI->all_defs()) {
+ if (!MO.getReg().isVirtual())
continue;
Register Reg = MO.getReg();
const TargetRegisterClass *RC = MRI.getRegClass(Reg);
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index 62f7ed29c8c819..6babd5a3f1f96f 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -1329,9 +1329,8 @@ void RegAllocFastImpl::findAndSortDefOperandIndexes(const MachineInstr &MI) {
// we assign these.
SmallVector<unsigned> RegClassDefCounts(TRI->getNumRegClasses(), 0);
- for (const MachineOperand &MO : MI.operands())
- if (MO.isReg() && MO.isDef())
- addRegClassDefCounts(RegClassDefCounts, MO.getReg());
+ for (const MachineOperand &MO : MI.all_defs())
+ addRegClassDefCounts(RegClassDefCounts, MO.getReg());
llvm::sort(DefOperandIndexes, [&](unsigned I0, unsigned I1) {
const MachineOperand &MO0 = MI.getOperand(I0);
@@ -1481,9 +1480,7 @@ void RegAllocFastImpl::allocateInstruction(MachineInstr &MI) {
// Assign virtual register defs.
while (ReArrangedImplicitOps) {
ReArrangedImplicitOps = false;
- for (MachineOperand &MO : MI.operands()) {
- if (!MO.isReg() || !MO.isDef())
- continue;
+ for (MachineOperand &MO : MI.all_defs()) {
Register Reg = MO.getReg();
if (Reg.isVirtual()) {
ReArrangedImplicitOps =
@@ -1499,10 +1496,7 @@ void RegAllocFastImpl::allocateInstruction(MachineInstr &MI) {
// Free registers occupied by defs.
// Iterate operands in reverse order, so we see the implicit super register
// defs first (we added them earlier in case of <def,read-undef>).
- for (MachineOperand &MO : reverse(MI.operands())) {
- if (!MO.isReg() || !MO.isDef())
- continue;
-
+ for (MachineOperand &MO : reverse(MI.all_defs())) {
Register Reg = MO.getReg();
// subreg defs don't free the full register. We left the subreg number
diff --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp
index f6c53f3051c2f0..97f8346df0e8fe 100644
--- a/llvm/lib/CodeGen/RegisterCoalescer.cpp
+++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp
@@ -3230,8 +3230,8 @@ void JoinVals::pruneValues(JoinVals &Other,
// Also remove dead flags since the joined live range will
// continue past this instruction.
for (MachineOperand &MO :
- Indexes->getInstructionFromIndex(Def)->operands()) {
- if (MO.isReg() && MO.isDef() && MO.getReg() == Reg) {
+ Indexes->getInstructionFromIndex(Def)->all_defs()) {
+ if (MO.getReg() == Reg) {
if (MO.getSubReg() != 0 && MO.isUndef() && !EraseImpDef)
MO.setIsUndef(false);
MO.setIsDead(false);
|
qcolombet
approved these changes
Aug 26, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.