xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Mips/MipsSEInstrInfo.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- MipsSEInstrInfo.h - Mips32/64 Instruction Information ---*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains the Mips32/64 implementation of the TargetInstrInfo class.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_MIPS_MIPSSEINSTRINFO_H
140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_MIPS_MIPSSEINSTRINFO_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "MipsInstrInfo.h"
170b57cec5SDimitry Andric #include "MipsSERegisterInfo.h"
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric namespace llvm {
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric class MipsSEInstrInfo : public MipsInstrInfo {
220b57cec5SDimitry Andric   const MipsSERegisterInfo RI;
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric public:
250b57cec5SDimitry Andric   explicit MipsSEInstrInfo(const MipsSubtarget &STI);
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric   const MipsRegisterInfo &getRegisterInfo() const override;
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric   /// isLoadFromStackSlot - If the specified machine instruction is a direct
300b57cec5SDimitry Andric   /// load from a stack slot, return the virtual or physical register number of
310b57cec5SDimitry Andric   /// the destination along with the FrameIndex of the loaded stack slot.  If
320b57cec5SDimitry Andric   /// not, return 0.  This predicate must return 0 if the instruction has
330b57cec5SDimitry Andric   /// any side effects other than loading from the stack slot.
34*0fca6ea1SDimitry Andric   Register isLoadFromStackSlot(const MachineInstr &MI,
350b57cec5SDimitry Andric                                int &FrameIndex) const override;
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric   /// isStoreToStackSlot - If the specified machine instruction is a direct
380b57cec5SDimitry Andric   /// store to a stack slot, return the virtual or physical register number of
390b57cec5SDimitry Andric   /// the source reg along with the FrameIndex of the loaded stack slot.  If
400b57cec5SDimitry Andric   /// not, return 0.  This predicate must return 0 if the instruction has
410b57cec5SDimitry Andric   /// any side effects other than storing to the stack slot.
42*0fca6ea1SDimitry Andric   Register isStoreToStackSlot(const MachineInstr &MI,
430b57cec5SDimitry Andric                               int &FrameIndex) const override;
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
46480093f4SDimitry Andric                    const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg,
470b57cec5SDimitry Andric                    bool KillSrc) const override;
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric   void storeRegToStack(MachineBasicBlock &MBB,
500b57cec5SDimitry Andric                        MachineBasicBlock::iterator MI,
515ffd83dbSDimitry Andric                        Register SrcReg, bool isKill, int FrameIndex,
520b57cec5SDimitry Andric                        const TargetRegisterClass *RC,
530b57cec5SDimitry Andric                        const TargetRegisterInfo *TRI,
540b57cec5SDimitry Andric                        int64_t Offset) const override;
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric   void loadRegFromStack(MachineBasicBlock &MBB,
570b57cec5SDimitry Andric                         MachineBasicBlock::iterator MI,
585ffd83dbSDimitry Andric                         Register DestReg, int FrameIndex,
590b57cec5SDimitry Andric                         const TargetRegisterClass *RC,
600b57cec5SDimitry Andric                         const TargetRegisterInfo *TRI,
610b57cec5SDimitry Andric                         int64_t Offset) const override;
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric   bool expandPostRAPseudo(MachineInstr &MI) const override;
640b57cec5SDimitry Andric 
655ffd83dbSDimitry Andric   bool isBranchWithImm(unsigned Opc) const override;
665ffd83dbSDimitry Andric 
670b57cec5SDimitry Andric   unsigned getOppositeBranchOpc(unsigned Opc) const override;
680b57cec5SDimitry Andric 
690b57cec5SDimitry Andric   /// Adjust SP by Amount bytes.
700b57cec5SDimitry Andric   void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB,
710b57cec5SDimitry Andric                       MachineBasicBlock::iterator I) const override;
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric   /// Emit a series of instructions to load an immediate. If NewImm is a
740b57cec5SDimitry Andric   /// non-NULL parameter, the last instruction is not emitted, but instead
750b57cec5SDimitry Andric   /// its immediate operand is returned in NewImm.
760b57cec5SDimitry Andric   unsigned loadImmediate(int64_t Imm, MachineBasicBlock &MBB,
770b57cec5SDimitry Andric                          MachineBasicBlock::iterator II, const DebugLoc &DL,
780b57cec5SDimitry Andric                          unsigned *NewImm) const;
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric protected:
810b57cec5SDimitry Andric   /// If the specific machine instruction is a instruction that moves/copies
82480093f4SDimitry Andric   /// value from one register to another register return destination and source
83480093f4SDimitry Andric   /// registers as machine operands.
84bdd1243dSDimitry Andric   std::optional<DestSourcePair>
85480093f4SDimitry Andric   isCopyInstrImpl(const MachineInstr &MI) const override;
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric private:
880b57cec5SDimitry Andric   unsigned getAnalyzableBrOpc(unsigned Opc) const override;
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric   void expandRetRA(MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const;
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric   void expandERet(MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const;
930b57cec5SDimitry Andric 
940b57cec5SDimitry Andric   std::pair<bool, bool> compareOpndSize(unsigned Opc,
950b57cec5SDimitry Andric                                         const MachineFunction &MF) const;
960b57cec5SDimitry Andric 
970b57cec5SDimitry Andric   void expandPseudoMFHiLo(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
980b57cec5SDimitry Andric                           unsigned NewOpc) const;
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric   void expandPseudoMTLoHi(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
1010b57cec5SDimitry Andric                           unsigned LoOpc, unsigned HiOpc,
1020b57cec5SDimitry Andric                           bool HasExplicitDef) const;
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric   /// Expand pseudo Int-to-FP conversion instructions.
1050b57cec5SDimitry Andric   ///
1060b57cec5SDimitry Andric   /// For example, the following pseudo instruction
1070b57cec5SDimitry Andric   ///  PseudoCVT_D32_W D2, A5
1080b57cec5SDimitry Andric   /// gets expanded into these two instructions:
1090b57cec5SDimitry Andric   ///  MTC1 F4, A5
1100b57cec5SDimitry Andric   ///  CVT_D32_W D2, F4
1110b57cec5SDimitry Andric   ///
1120b57cec5SDimitry Andric   /// We do this expansion post-RA to avoid inserting a floating point copy
1130b57cec5SDimitry Andric   /// instruction between MTC1 and CVT_D32_W.
1140b57cec5SDimitry Andric   void expandCvtFPInt(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
1150b57cec5SDimitry Andric                       unsigned CvtOpc, unsigned MovOpc, bool IsI64) const;
1160b57cec5SDimitry Andric 
1170b57cec5SDimitry Andric   void expandExtractElementF64(MachineBasicBlock &MBB,
1180b57cec5SDimitry Andric                                MachineBasicBlock::iterator I, bool isMicroMips,
1190b57cec5SDimitry Andric                                bool FP64) const;
1200b57cec5SDimitry Andric   void expandBuildPairF64(MachineBasicBlock &MBB,
1210b57cec5SDimitry Andric                           MachineBasicBlock::iterator I, bool isMicroMips,
1220b57cec5SDimitry Andric                           bool FP64) const;
1230b57cec5SDimitry Andric   void expandEhReturn(MachineBasicBlock &MBB,
1240b57cec5SDimitry Andric                       MachineBasicBlock::iterator I) const;
1250b57cec5SDimitry Andric };
1260b57cec5SDimitry Andric 
1270b57cec5SDimitry Andric }
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric #endif
130