From 6c0b2ab1c1fcd04e06461ebad88cf064bc8114b4 Mon Sep 17 00:00:00 2001 From: Sai Abhinay Anubola Date: Fri, 7 Nov 2025 21:53:36 +0530 Subject: [PATCH] [AIEX][NFC] Refactor put_ms instruction selection to use unified getMvVal2MS interface --- llvm/lib/Target/AIE/AIE2InstrInfo.cpp | 31 ++++++++--------- llvm/lib/Target/AIE/AIE2InstrInfo.h | 5 +-- llvm/lib/Target/AIE/AIEBaseInstrInfo.h | 12 ++----- .../Target/AIE/AIEBaseInstructionSelector.cpp | 8 ++--- llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.cpp | 33 ++++++++++--------- llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.h | 5 +-- 6 files changed, 41 insertions(+), 53 deletions(-) diff --git a/llvm/lib/Target/AIE/AIE2InstrInfo.cpp b/llvm/lib/Target/AIE/AIE2InstrInfo.cpp index 4eadd4ef3dcb..1604da578f7c 100644 --- a/llvm/lib/Target/AIE/AIE2InstrInfo.cpp +++ b/llvm/lib/Target/AIE/AIE2InstrInfo.cpp @@ -467,6 +467,10 @@ unsigned AIE2InstrInfo::getOpCode(MachineInstr &I) const { else return isSigned ? AIE2::VUNPACK_S16_S8 : AIE2::VUNPACK_D16_D8; } + case Intrinsic::aie2_put_ms: + return AIE2::MOV_mv_scl2ms_doTlast_reg; + case Intrinsic::aie2_put_ms_nb: + return AIE2::MOV_NB_mv_scl2ms_doTlast_reg; default: llvm_unreachable("Unexpected Intrinsic ID"); } @@ -950,21 +954,18 @@ unsigned AIE2InstrInfo::getMvSclMultiSlotPseudoOpcode() const { unsigned AIE2InstrInfo::getAddSclOpcode() const { return AIE2::ADD; } -unsigned AIE2InstrInfo::getMvScl2MSTlastRegOpcode() const { - return AIE2::MOV_mv_scl2ms_doTlast_reg; -} - -unsigned AIE2InstrInfo::getMvNBScl2MSTlastRegOpcode() const { - return AIE2::MOV_NB_mv_scl2ms_doTlast_reg; -} - -unsigned AIE2InstrInfo::getMvScl2MS(unsigned ConstTLastVal) const { - return (ConstTLastVal == 0 ? AIE2::MOV_mv_scl2ms : AIE2::MOV_TLAST_mv_scl2ms); -} - -unsigned AIE2InstrInfo::getMvNBScl2MS(unsigned ConstTLastVal) const { - return (ConstTLastVal == 0 ? AIE2::MOV_NB_mv_scl2ms - : AIE2::MOV_NB_TLAST_mv_scl2ms); +unsigned AIE2InstrInfo::getMvVal2MS(MachineInstr &I, + unsigned ConstTLastVal) const { + const bool UseTLastImm = (ConstTLastVal == 0); + const unsigned IntrinsicID = cast(I).getIntrinsicID(); + switch (IntrinsicID) { + case Intrinsic::aie2_put_ms: + return UseTLastImm ? AIE2::MOV_mv_scl2ms : AIE2::MOV_TLAST_mv_scl2ms; + case Intrinsic::aie2_put_ms_nb: + return UseTLastImm ? AIE2::MOV_NB_mv_scl2ms : AIE2::MOV_NB_TLAST_mv_scl2ms; + default: + llvm_unreachable("Unexpected Intrinsic ID"); + } } unsigned AIE2InstrInfo::getCycleSeparatorOpcode() const { diff --git a/llvm/lib/Target/AIE/AIE2InstrInfo.h b/llvm/lib/Target/AIE/AIE2InstrInfo.h index 5e39aa44c9ba..57fde74a7036 100644 --- a/llvm/lib/Target/AIE/AIE2InstrInfo.h +++ b/llvm/lib/Target/AIE/AIE2InstrInfo.h @@ -48,10 +48,7 @@ class AIE2InstrInfo : public AIE2GenInstrInfo { unsigned getPtrAdd3DOpcode() const override; unsigned getMvSclMultiSlotPseudoOpcode() const override; unsigned getAddSclOpcode() const override; - unsigned getMvScl2MS(unsigned ConstTLastVal) const override; - unsigned getMvNBScl2MS(unsigned ConstTLastVal) const override; - unsigned getMvScl2MSTlastRegOpcode() const override; - unsigned getMvNBScl2MSTlastRegOpcode() const override; + unsigned getMvVal2MS(MachineInstr &I, unsigned ConstTLastVal) const override; Register getSSStatusReg() const override; Register getMSStatusReg() const override; Register getPackSignCReg() const override; diff --git a/llvm/lib/Target/AIE/AIEBaseInstrInfo.h b/llvm/lib/Target/AIE/AIEBaseInstrInfo.h index 3a9dbd15ebc2..655bce1901f6 100644 --- a/llvm/lib/Target/AIE/AIEBaseInstrInfo.h +++ b/llvm/lib/Target/AIE/AIEBaseInstrInfo.h @@ -444,22 +444,14 @@ struct AIEBaseInstrInfo : public TargetInstrInfo { virtual Register getMSStatusReg() const { llvm_unreachable("Target didn't implement getMSStatusReg"); } - virtual unsigned getMvScl2MS(unsigned ConstTLastVal) const { - llvm_unreachable("Target didn't implement getMvScl2MS"); + virtual unsigned getMvVal2MS(MachineInstr &I, unsigned ConstTLastVal) const { + llvm_unreachable("Target didn't implement getMvVal2MS"); } virtual unsigned getMvNBScl2MS(unsigned ConstTLastVal) const { llvm_unreachable("Target didn't implement getMvNBScl2MS"); } - virtual unsigned getMvScl2MSTlastRegOpcode() const { - llvm_unreachable("Target didn't implement getMvScl2MSTlastRegOpcode"); - } - - virtual unsigned getMvNBScl2MSTlastRegOpcode() const { - llvm_unreachable("Target didn't implement getMvNBScl2MSTlastRegOpcode"); - } - virtual Register getPackSignCReg() const { llvm_unreachable("Target didn't implement getPackSignCReg"); } diff --git a/llvm/lib/Target/AIE/AIEBaseInstructionSelector.cpp b/llvm/lib/Target/AIE/AIEBaseInstructionSelector.cpp index 96db5eb4e73d..65e5a81c3d6e 100644 --- a/llvm/lib/Target/AIE/AIEBaseInstructionSelector.cpp +++ b/llvm/lib/Target/AIE/AIEBaseInstructionSelector.cpp @@ -535,10 +535,10 @@ bool AIEBaseInstructionSelector::selectPutMSB(MachineInstr &I, Register ValReg = I.getOperand(1).getReg(); Register TLastReg = I.getOperand(2).getReg(); auto TLastVal = getIConstantVRegValWithLookThrough(TLastReg, MRI); - unsigned OpCode = TII.getMvScl2MSTlastRegOpcode(); + unsigned OpCode = TII.getOpCode(I); if (TLastVal) { unsigned ConstTLastVal = TLastVal->Value.getZExtValue(); - OpCode = TII.getMvScl2MS(ConstTLastVal); + OpCode = TII.getMvVal2MS(I, ConstTLastVal); } MachineInstrBuilder MI = MIB.buildInstr(OpCode, {}, {ValReg}); if (!TLastVal) { @@ -557,10 +557,10 @@ bool AIEBaseInstructionSelector::selectPutMSNB(MachineInstr &I, Register ValReg = I.getOperand(2).getReg(); Register TLastReg = I.getOperand(3).getReg(); auto TLastVal = getIConstantVRegValWithLookThrough(TLastReg, MRI); - unsigned OpCode = TII.getMvNBScl2MSTlastRegOpcode(); + unsigned OpCode = TII.getOpCode(I); if (TLastVal) { unsigned ConstTLastVal = TLastVal->Value.getZExtValue(); - OpCode = TII.getMvNBScl2MS(ConstTLastVal); + OpCode = TII.getMvVal2MS(I, ConstTLastVal); } MachineInstrBuilder MI = MIB.buildInstr(OpCode, {}, {ValReg}); if (!TLastVal) { diff --git a/llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.cpp b/llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.cpp index 0b685ffe54e3..bed2cf7b6bdb 100644 --- a/llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.cpp +++ b/llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.cpp @@ -562,6 +562,10 @@ unsigned AIE2PInstrInfo::getOpCode(MachineInstr &I) const { } case Intrinsic::aie2p_vshuffle_576_bfp16: return AIE2P::VSHUFFLE_vec_shuffle_ex; + case Intrinsic::aie2p_put_ms: + return AIE2P::MOV_st_mMStream_tlast_reg; + case Intrinsic::aie2p_put_ms_nb: + return AIE2P::MOV_nb_st_mMStream_tlast_reg; default: llvm_unreachable("Unexpected Intrinsic ID"); } @@ -1970,22 +1974,19 @@ Register AIE2PInstrInfo::getSSStatusReg() const { return AIE2P::srSS0; } Register AIE2PInstrInfo::getMSStatusReg() const { return AIE2P::srMS0; } -unsigned AIE2PInstrInfo::getMvScl2MSTlastRegOpcode() const { - return AIE2P::MOV_st_mMStream_tlast_reg; -} - -unsigned AIE2PInstrInfo::getMvNBScl2MSTlastRegOpcode() const { - return AIE2P::MOV_nb_st_mMStream_tlast_reg; -} - -unsigned AIE2PInstrInfo::getMvScl2MS(unsigned ConstTLastVal) const { - return (ConstTLastVal == 0) ? AIE2P::MOV_st_mMStream_tlast_imm - : AIE2P::MOV_tlast; -} - -unsigned AIE2PInstrInfo::getMvNBScl2MS(unsigned ConstTLastVal) const { - return (ConstTLastVal == 0) ? AIE2P::MOV_nb_st_mMStream_tlast_imm - : AIE2P::MOV_nb_tlast; +unsigned AIE2PInstrInfo::getMvVal2MS(MachineInstr &I, + unsigned ConstTLastVal) const { + const bool UseTLastImm = (ConstTLastVal == 0); + const unsigned IntrinsicID = cast(I).getIntrinsicID(); + switch (IntrinsicID) { + case Intrinsic::aie2p_put_ms: + return UseTLastImm ? AIE2P::MOV_st_mMStream_tlast_imm : AIE2P::MOV_tlast; + case Intrinsic::aie2p_put_ms_nb: + return UseTLastImm ? AIE2P::MOV_nb_st_mMStream_tlast_imm + : AIE2P::MOV_nb_tlast; + default: + llvm_unreachable("Unexpected Intrinsic ID"); + } } Register AIE2PInstrInfo::getPackSignCReg() const { return AIE2P::packSign0; } diff --git a/llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.h b/llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.h index e226eb86b1dc..b9ac1b56bd59 100644 --- a/llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.h +++ b/llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.h @@ -46,10 +46,7 @@ class AIE2PInstrInfo : public AIE2PGenInstrInfo { unsigned getConstantMovOpcode(MachineRegisterInfo &MRI, unsigned int Reg, APInt &Val) const override; unsigned getScalarMovOpcode(Register DstReg, Register SrcReg) const override; - unsigned getMvScl2MS(unsigned ConstTLastVal) const override; - unsigned getMvNBScl2MS(unsigned ConstTLastVal) const override; - unsigned getMvScl2MSTlastRegOpcode() const override; - unsigned getMvNBScl2MSTlastRegOpcode() const override; + unsigned getMvVal2MS(MachineInstr &I, unsigned ConstTLastVal) const override; Register getSSStatusReg() const override; Register getMSStatusReg() const override; Register getPackSignCReg() const override;