1*9880d681SAndroid Build Coastguard Worker //===-- Mips16InstrInfo.h - Mips16 Instruction Information ------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file contains the Mips16 implementation of the TargetInstrInfo class. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H 15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #include "Mips16RegisterInfo.h" 18*9880d681SAndroid Build Coastguard Worker #include "MipsInstrInfo.h" 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker namespace llvm { 21*9880d681SAndroid Build Coastguard Worker class MipsSubtarget; 22*9880d681SAndroid Build Coastguard Worker class Mips16InstrInfo : public MipsInstrInfo { 23*9880d681SAndroid Build Coastguard Worker const Mips16RegisterInfo RI; 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker public: 26*9880d681SAndroid Build Coastguard Worker explicit Mips16InstrInfo(const MipsSubtarget &STI); 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker const MipsRegisterInfo &getRegisterInfo() const override; 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker /// isLoadFromStackSlot - If the specified machine instruction is a direct 31*9880d681SAndroid Build Coastguard Worker /// load from a stack slot, return the virtual or physical register number of 32*9880d681SAndroid Build Coastguard Worker /// the destination along with the FrameIndex of the loaded stack slot. If 33*9880d681SAndroid Build Coastguard Worker /// not, return 0. This predicate must return 0 if the instruction has 34*9880d681SAndroid Build Coastguard Worker /// any side effects other than loading from the stack slot. 35*9880d681SAndroid Build Coastguard Worker unsigned isLoadFromStackSlot(const MachineInstr &MI, 36*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override; 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker /// isStoreToStackSlot - If the specified machine instruction is a direct 39*9880d681SAndroid Build Coastguard Worker /// store to a stack slot, return the virtual or physical register number of 40*9880d681SAndroid Build Coastguard Worker /// the source reg along with the FrameIndex of the loaded stack slot. If 41*9880d681SAndroid Build Coastguard Worker /// not, return 0. This predicate must return 0 if the instruction has 42*9880d681SAndroid Build Coastguard Worker /// any side effects other than storing to the stack slot. 43*9880d681SAndroid Build Coastguard Worker unsigned isStoreToStackSlot(const MachineInstr &MI, 44*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override; 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, 47*9880d681SAndroid Build Coastguard Worker const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, 48*9880d681SAndroid Build Coastguard Worker bool KillSrc) const override; 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Worker void storeRegToStack(MachineBasicBlock &MBB, 51*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator MBBI, 52*9880d681SAndroid Build Coastguard Worker unsigned SrcReg, bool isKill, int FrameIndex, 53*9880d681SAndroid Build Coastguard Worker const TargetRegisterClass *RC, 54*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI, 55*9880d681SAndroid Build Coastguard Worker int64_t Offset) const override; 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Worker void loadRegFromStack(MachineBasicBlock &MBB, 58*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator MBBI, 59*9880d681SAndroid Build Coastguard Worker unsigned DestReg, int FrameIndex, 60*9880d681SAndroid Build Coastguard Worker const TargetRegisterClass *RC, 61*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI, 62*9880d681SAndroid Build Coastguard Worker int64_t Offset) const override; 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker bool expandPostRAPseudo(MachineInstr &MI) const override; 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard Worker unsigned getOppositeBranchOpc(unsigned Opc) const override; 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Worker // Adjust SP by FrameSize bytes. Save RA, S0, S1 69*9880d681SAndroid Build Coastguard Worker void makeFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, 70*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator I) const; 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Worker // Adjust SP by FrameSize bytes. Restore RA, S0, S1 73*9880d681SAndroid Build Coastguard Worker void restoreFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, 74*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator I) const; 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Worker 77*9880d681SAndroid Build Coastguard Worker /// Adjust SP by Amount bytes. 78*9880d681SAndroid Build Coastguard Worker void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, 79*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator I) const override; 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker /// Emit a series of instructions to load an immediate. 82*9880d681SAndroid Build Coastguard Worker // This is to adjust some FrameReg. We return the new register to be used 83*9880d681SAndroid Build Coastguard Worker // in place of FrameReg and the adjusted immediate field (&NewImm) 84*9880d681SAndroid Build Coastguard Worker // 85*9880d681SAndroid Build Coastguard Worker unsigned loadImmediate(unsigned FrameReg, int64_t Imm, MachineBasicBlock &MBB, 86*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator II, const DebugLoc &DL, 87*9880d681SAndroid Build Coastguard Worker unsigned &NewImm) const; 88*9880d681SAndroid Build Coastguard Worker 89*9880d681SAndroid Build Coastguard Worker static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount); 90*9880d681SAndroid Build Coastguard Worker validSpImm8(int offset)91*9880d681SAndroid Build Coastguard Worker static bool validSpImm8(int offset) { 92*9880d681SAndroid Build Coastguard Worker return ((offset & 7) == 0) && isInt<11>(offset); 93*9880d681SAndroid Build Coastguard Worker } 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard Worker // 96*9880d681SAndroid Build Coastguard Worker // build the proper one based on the Imm field 97*9880d681SAndroid Build Coastguard Worker // 98*9880d681SAndroid Build Coastguard Worker 99*9880d681SAndroid Build Coastguard Worker const MCInstrDesc& AddiuSpImm(int64_t Imm) const; 100*9880d681SAndroid Build Coastguard Worker 101*9880d681SAndroid Build Coastguard Worker void BuildAddiuSpImm 102*9880d681SAndroid Build Coastguard Worker (MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const; 103*9880d681SAndroid Build Coastguard Worker 104*9880d681SAndroid Build Coastguard Worker unsigned getInlineAsmLength(const char *Str, 105*9880d681SAndroid Build Coastguard Worker const MCAsmInfo &MAI) const override; 106*9880d681SAndroid Build Coastguard Worker private: 107*9880d681SAndroid Build Coastguard Worker unsigned getAnalyzableBrOpc(unsigned Opc) const override; 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Worker void ExpandRetRA16(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, 110*9880d681SAndroid Build Coastguard Worker unsigned Opc) const; 111*9880d681SAndroid Build Coastguard Worker 112*9880d681SAndroid Build Coastguard Worker // Adjust SP by Amount bytes where bytes can be up to 32bit number. 113*9880d681SAndroid Build Coastguard Worker void adjustStackPtrBig(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, 114*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator I, 115*9880d681SAndroid Build Coastguard Worker unsigned Reg1, unsigned Reg2) const; 116*9880d681SAndroid Build Coastguard Worker 117*9880d681SAndroid Build Coastguard Worker // Adjust SP by Amount bytes where bytes can be up to 32bit number. 118*9880d681SAndroid Build Coastguard Worker void adjustStackPtrBigUnrestricted(unsigned SP, int64_t Amount, 119*9880d681SAndroid Build Coastguard Worker MachineBasicBlock &MBB, 120*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator I) const; 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Worker }; 123*9880d681SAndroid Build Coastguard Worker 124*9880d681SAndroid Build Coastguard Worker } 125*9880d681SAndroid Build Coastguard Worker 126*9880d681SAndroid Build Coastguard Worker #endif 127