17330f729Sjoerg //===- Mips16InstrInfo.h - Mips16 Instruction Information -------*- C++ -*-===// 27330f729Sjoerg // 37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information. 57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 67330f729Sjoerg // 77330f729Sjoerg //===----------------------------------------------------------------------===// 87330f729Sjoerg // 97330f729Sjoerg // This file contains the Mips16 implementation of the TargetInstrInfo class. 107330f729Sjoerg // 117330f729Sjoerg //===----------------------------------------------------------------------===// 127330f729Sjoerg 137330f729Sjoerg #ifndef LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H 147330f729Sjoerg #define LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H 157330f729Sjoerg 167330f729Sjoerg #include "Mips16RegisterInfo.h" 177330f729Sjoerg #include "MipsInstrInfo.h" 187330f729Sjoerg #include "llvm/CodeGen/MachineBasicBlock.h" 197330f729Sjoerg #include "llvm/Support/MathExtras.h" 207330f729Sjoerg #include <cstdint> 217330f729Sjoerg 227330f729Sjoerg namespace llvm { 237330f729Sjoerg 247330f729Sjoerg class MCInstrDesc; 257330f729Sjoerg class MipsSubtarget; 267330f729Sjoerg 277330f729Sjoerg class Mips16InstrInfo : public MipsInstrInfo { 287330f729Sjoerg const Mips16RegisterInfo RI; 297330f729Sjoerg 307330f729Sjoerg public: 317330f729Sjoerg explicit Mips16InstrInfo(const MipsSubtarget &STI); 327330f729Sjoerg 337330f729Sjoerg const MipsRegisterInfo &getRegisterInfo() const override; 347330f729Sjoerg 357330f729Sjoerg /// isLoadFromStackSlot - If the specified machine instruction is a direct 367330f729Sjoerg /// load from a stack slot, return the virtual or physical register number of 377330f729Sjoerg /// the destination along with the FrameIndex of the loaded stack slot. If 387330f729Sjoerg /// not, return 0. This predicate must return 0 if the instruction has 397330f729Sjoerg /// any side effects other than loading from the stack slot. 407330f729Sjoerg unsigned isLoadFromStackSlot(const MachineInstr &MI, 417330f729Sjoerg int &FrameIndex) const override; 427330f729Sjoerg 437330f729Sjoerg /// isStoreToStackSlot - If the specified machine instruction is a direct 447330f729Sjoerg /// store to a stack slot, return the virtual or physical register number of 457330f729Sjoerg /// the source reg along with the FrameIndex of the loaded stack slot. If 467330f729Sjoerg /// not, return 0. This predicate must return 0 if the instruction has 477330f729Sjoerg /// any side effects other than storing to the stack slot. 487330f729Sjoerg unsigned isStoreToStackSlot(const MachineInstr &MI, 497330f729Sjoerg int &FrameIndex) const override; 507330f729Sjoerg 517330f729Sjoerg void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, 52*82d56013Sjoerg const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, 537330f729Sjoerg bool KillSrc) const override; 547330f729Sjoerg 557330f729Sjoerg void storeRegToStack(MachineBasicBlock &MBB, 567330f729Sjoerg MachineBasicBlock::iterator MBBI, 57*82d56013Sjoerg Register SrcReg, bool isKill, int FrameIndex, 587330f729Sjoerg const TargetRegisterClass *RC, 597330f729Sjoerg const TargetRegisterInfo *TRI, 607330f729Sjoerg int64_t Offset) const override; 617330f729Sjoerg 627330f729Sjoerg void loadRegFromStack(MachineBasicBlock &MBB, 637330f729Sjoerg MachineBasicBlock::iterator MBBI, 64*82d56013Sjoerg Register DestReg, int FrameIndex, 657330f729Sjoerg const TargetRegisterClass *RC, 667330f729Sjoerg const TargetRegisterInfo *TRI, 677330f729Sjoerg int64_t Offset) const override; 687330f729Sjoerg 697330f729Sjoerg bool expandPostRAPseudo(MachineInstr &MI) const override; 707330f729Sjoerg 717330f729Sjoerg unsigned getOppositeBranchOpc(unsigned Opc) const override; 727330f729Sjoerg 737330f729Sjoerg // Adjust SP by FrameSize bytes. Save RA, S0, S1 747330f729Sjoerg void makeFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, 757330f729Sjoerg MachineBasicBlock::iterator I) const; 767330f729Sjoerg 777330f729Sjoerg // Adjust SP by FrameSize bytes. Restore RA, S0, S1 787330f729Sjoerg void restoreFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, 797330f729Sjoerg MachineBasicBlock::iterator I) const; 807330f729Sjoerg 817330f729Sjoerg /// Adjust SP by Amount bytes. 827330f729Sjoerg void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, 837330f729Sjoerg MachineBasicBlock::iterator I) const override; 847330f729Sjoerg 857330f729Sjoerg /// Emit a series of instructions to load an immediate. 867330f729Sjoerg // This is to adjust some FrameReg. We return the new register to be used 877330f729Sjoerg // in place of FrameReg and the adjusted immediate field (&NewImm) 887330f729Sjoerg unsigned loadImmediate(unsigned FrameReg, int64_t Imm, MachineBasicBlock &MBB, 897330f729Sjoerg MachineBasicBlock::iterator II, const DebugLoc &DL, 907330f729Sjoerg unsigned &NewImm) const; 917330f729Sjoerg 927330f729Sjoerg static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount); 937330f729Sjoerg validSpImm8(int offset)947330f729Sjoerg static bool validSpImm8(int offset) { 957330f729Sjoerg return ((offset & 7) == 0) && isInt<11>(offset); 967330f729Sjoerg } 977330f729Sjoerg 987330f729Sjoerg // build the proper one based on the Imm field 997330f729Sjoerg 1007330f729Sjoerg const MCInstrDesc& AddiuSpImm(int64_t Imm) const; 1017330f729Sjoerg 1027330f729Sjoerg void BuildAddiuSpImm 1037330f729Sjoerg (MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const; 1047330f729Sjoerg 1057330f729Sjoerg protected: 1067330f729Sjoerg /// If the specific machine instruction is a instruction that moves/copies 107*82d56013Sjoerg /// value from one register to another register return destination and source 108*82d56013Sjoerg /// registers as machine operands. 109*82d56013Sjoerg Optional<DestSourcePair> isCopyInstrImpl(const MachineInstr &MI) const override; 1107330f729Sjoerg 1117330f729Sjoerg private: 1127330f729Sjoerg unsigned getAnalyzableBrOpc(unsigned Opc) const override; 1137330f729Sjoerg 1147330f729Sjoerg void ExpandRetRA16(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, 1157330f729Sjoerg unsigned Opc) const; 1167330f729Sjoerg 1177330f729Sjoerg // Adjust SP by Amount bytes where bytes can be up to 32bit number. 1187330f729Sjoerg void adjustStackPtrBig(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, 1197330f729Sjoerg MachineBasicBlock::iterator I, 1207330f729Sjoerg unsigned Reg1, unsigned Reg2) const; 1217330f729Sjoerg 1227330f729Sjoerg // Adjust SP by Amount bytes where bytes can be up to 32bit number. 1237330f729Sjoerg void adjustStackPtrBigUnrestricted(unsigned SP, int64_t Amount, 1247330f729Sjoerg MachineBasicBlock &MBB, 1257330f729Sjoerg MachineBasicBlock::iterator I) const; 1267330f729Sjoerg }; 1277330f729Sjoerg 1287330f729Sjoerg } // end namespace llvm 1297330f729Sjoerg 1307330f729Sjoerg #endif // LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H 131