[PATCH] D125565: [AMDGPU] Extract SIInstrInfo::removeModOperands. NFC.
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 10:21:09 PDT 2022
foad created this revision.
foad added reviewers: arsenm, rampitec, piotr.
Herald added subscribers: kosarev, jsilvanus, hsmhsm, kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
Herald added a project: All.
foad requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Make this an externally callable function for use in a future patch.
Repository:
rG LLVM Github Monorepo
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,18 @@
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 ArrayRef<unsigned> getModifierOpNames() {
+ static const unsigned OpNames[] = {
+ AMDGPU::OpName::src0_modifiers, AMDGPU::OpName::src1_modifiers,
+ AMDGPU::OpName::src2_modifiers, AMDGPU::OpName::clamp,
+ AMDGPU::OpName::omod};
+ return OpNames;
+}
- MI.removeOperand(Src2ModIdx);
- MI.removeOperand(Src1ModIdx);
- MI.removeOperand(Src0ModIdx);
+void SIInstrInfo::removeModOperands(MachineInstr &MI) const {
+ unsigned Opc = MI.getOpcode();
+ for (unsigned Name : reverse(getModifierOpNames()))
+ MI.removeOperand(AMDGPU::getNamedOperandIdx(Opc, Name));
}
bool SIInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
@@ -3024,12 +3024,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 +3101,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 +3775,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(getModifierOpNames(),
+ [&](unsigned Name) { return hasModifiersSet(MI, Name); });
}
bool SIInstrInfo::canShrink(const MachineInstr &MI,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125565.429284.patch
Type: text/x-patch
Size: 3511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/8fccb6f9/attachment.bin>
More information about the llvm-commits
mailing list