[llvm] dfb006c - [AMDGPU] Extract SIInstrInfo::removeModOperands. NFC.
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Mon May 16 01:51:52 PDT 2022
Author: Jay Foad
Date: 2022-05-16T09:43:41+01:00
New Revision: dfb006c0c969fbccfde3be6af3c0636e0643fc83
URL: https://github.com/llvm/llvm-project/commit/dfb006c0c969fbccfde3be6af3c0636e0643fc83
DIFF: https://github.com/llvm/llvm-project/commit/dfb006c0c969fbccfde3be6af3c0636e0643fc83.diff
LOG: [AMDGPU] Extract SIInstrInfo::removeModOperands. NFC.
Make this an externally callable function for use in a future patch.
Differential Revision: https://reviews.llvm.org/D125565
Added:
Modified:
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index ab511349a4683..d7fd36b001c38 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -2900,18 +2900,15 @@ unsigned SIInstrInfo::getAddressSpaceForPseudoSourceKind(
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 @@ bool SIInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
// 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 @@ bool SIInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
// 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::hasModifiersSet(const MachineInstr &MI,
}
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,
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 4b7589002a718..2d2cacb64dd36 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -337,6 +337,8 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
static bool isFoldableCopy(const MachineInstr &MI);
+ void removeModOperands(MachineInstr &MI) const;
+
bool FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg,
MachineRegisterInfo *MRI) const final;
More information about the llvm-commits
mailing list