[PATCH] D125565: [AMDGPU] Extract SIInstrInfo::removeModOperands. NFC.
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun May 15 06:23:16 PDT 2022
foad updated this revision to Diff 429534.
foad added a comment.
Make ModifierOpNames a constexpr.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125565/new/
https://reviews.llvm.org/D125565
Files:
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.h
Index: llvm/lib/Target/AMDGPU/SIInstrInfo.h
===================================================================
--- llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -337,6 +337,8 @@
static bool isFoldableCopy(const MachineInstr &MI);
+ void removeModOperands(MachineInstr &MI) const;
+
bool FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg,
MachineRegisterInfo *MRI) const final;
Index: llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -2900,18 +2900,15 @@
return AMDGPUAS::FLAT_ADDRESS;
}
-static void removeModOperands(MachineInstr &MI) {
- unsigned Opc = MI.getOpcode();
- int Src0ModIdx = AMDGPU::getNamedOperandIdx(Opc,
- AMDGPU::OpName::src0_modifiers);
- int Src1ModIdx = AMDGPU::getNamedOperandIdx(Opc,
- AMDGPU::OpName::src1_modifiers);
- int Src2ModIdx = AMDGPU::getNamedOperandIdx(Opc,
- AMDGPU::OpName::src2_modifiers);
+static constexpr unsigned ModifierOpNames[] = {
+ AMDGPU::OpName::src0_modifiers, AMDGPU::OpName::src1_modifiers,
+ AMDGPU::OpName::src2_modifiers, AMDGPU::OpName::clamp,
+ AMDGPU::OpName::omod};
- MI.removeOperand(Src2ModIdx);
- MI.removeOperand(Src1ModIdx);
- MI.removeOperand(Src0ModIdx);
+void SIInstrInfo::removeModOperands(MachineInstr &MI) const {
+ unsigned Opc = MI.getOpcode();
+ for (unsigned Name : reverse(ModifierOpNames))
+ MI.removeOperand(AMDGPU::getNamedOperandIdx(Opc, Name));
}
bool SIInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
@@ -3024,12 +3021,6 @@
// FIXME: This would be a lot easier if we could return a new instruction
// instead of having to modify in place.
- // Remove these first since they are at the end.
- UseMI.removeOperand(
- AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::omod));
- UseMI.removeOperand(
- AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::clamp));
-
Register Src1Reg = Src1->getReg();
unsigned Src1SubReg = Src1->getSubReg();
Src0->setReg(Src1Reg);
@@ -3107,12 +3098,6 @@
// FIXME: This would be a lot easier if we could return a new instruction
// instead of having to modify in place.
- // Remove these first since they are at the end.
- UseMI.removeOperand(
- AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::omod));
- UseMI.removeOperand(
- AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::clamp));
-
if (Opc == AMDGPU::V_MAC_F32_e64 ||
Opc == AMDGPU::V_MAC_F16_e64 ||
Opc == AMDGPU::V_FMAC_F32_e64 ||
@@ -3787,11 +3772,8 @@
}
bool SIInstrInfo::hasAnyModifiersSet(const MachineInstr &MI) const {
- return hasModifiersSet(MI, AMDGPU::OpName::src0_modifiers) ||
- hasModifiersSet(MI, AMDGPU::OpName::src1_modifiers) ||
- hasModifiersSet(MI, AMDGPU::OpName::src2_modifiers) ||
- hasModifiersSet(MI, AMDGPU::OpName::clamp) ||
- hasModifiersSet(MI, AMDGPU::OpName::omod);
+ return any_of(ModifierOpNames,
+ [&](unsigned Name) { return hasModifiersSet(MI, Name); });
}
bool SIInstrInfo::canShrink(const MachineInstr &MI,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125565.429534.patch
Type: text/x-patch
Size: 3433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220515/0bbbf7bf/attachment.bin>
More information about the llvm-commits
mailing list