1 //=- LoongArchInstrInfo.h - LoongArch Instruction Information ---*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains the LoongArch implementation of the TargetInstrInfo class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHINSTRINFO_H 14 #define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHINSTRINFO_H 15 16 #include "LoongArchRegisterInfo.h" 17 #include "llvm/CodeGen/TargetInstrInfo.h" 18 19 #define GET_INSTRINFO_HEADER 20 #include "LoongArchGenInstrInfo.inc" 21 22 namespace llvm { 23 24 class LoongArchSubtarget; 25 26 class LoongArchInstrInfo : public LoongArchGenInstrInfo { 27 public: 28 explicit LoongArchInstrInfo(LoongArchSubtarget &STI); 29 30 MCInst getNop() const override; 31 32 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, 33 const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg, 34 bool KillSrc) const override; 35 36 void storeRegToStackSlot(MachineBasicBlock &MBB, 37 MachineBasicBlock::iterator MBBI, Register SrcReg, 38 bool IsKill, int FrameIndex, 39 const TargetRegisterClass *RC, 40 const TargetRegisterInfo *TRI, 41 Register VReg) const override; 42 void loadRegFromStackSlot(MachineBasicBlock &MBB, 43 MachineBasicBlock::iterator MBBI, Register DstReg, 44 int FrameIndex, const TargetRegisterClass *RC, 45 const TargetRegisterInfo *TRI, 46 Register VReg) const override; 47 48 // Materializes the given integer Val into DstReg. 49 void movImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, 50 const DebugLoc &DL, Register DstReg, uint64_t Val, 51 MachineInstr::MIFlag Flag = MachineInstr::NoFlags) const; 52 53 unsigned getInstSizeInBytes(const MachineInstr &MI) const override; 54 55 bool isAsCheapAsAMove(const MachineInstr &MI) const override; 56 57 MachineBasicBlock *getBranchDestBlock(const MachineInstr &MI) const override; 58 59 bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, 60 MachineBasicBlock *&FBB, 61 SmallVectorImpl<MachineOperand> &Cond, 62 bool AllowModify) const override; 63 64 bool isBranchOffsetInRange(unsigned BranchOpc, 65 int64_t BrOffset) const override; 66 67 unsigned removeBranch(MachineBasicBlock &MBB, 68 int *BytesRemoved = nullptr) const override; 69 70 unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, 71 MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond, 72 const DebugLoc &dl, 73 int *BytesAdded = nullptr) const override; 74 75 void insertIndirectBranch(MachineBasicBlock &MBB, 76 MachineBasicBlock &NewDestBB, 77 MachineBasicBlock &RestoreBB, const DebugLoc &DL, 78 int64_t BrOffset, RegScavenger *RS) const override; 79 80 bool 81 reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; 82 83 std::pair<unsigned, unsigned> 84 decomposeMachineOperandsTargetFlags(unsigned TF) const override; 85 86 ArrayRef<std::pair<unsigned, const char *>> 87 getSerializableDirectMachineOperandTargetFlags() const override; 88 89 protected: 90 const LoongArchSubtarget &STI; 91 }; 92 93 namespace LoongArch { 94 95 // Returns true if this is the sext.w pattern, addi.w rd, rs, 0. 96 bool isSEXT_W(const MachineInstr &MI); 97 98 // Mask assignments for floating-point. 99 static constexpr unsigned FClassMaskSignalingNaN = 0x001; 100 static constexpr unsigned FClassMaskQuietNaN = 0x002; 101 static constexpr unsigned FClassMaskNegativeInfinity = 0x004; 102 static constexpr unsigned FClassMaskNegativeNormal = 0x008; 103 static constexpr unsigned FClassMaskNegativeSubnormal = 0x010; 104 static constexpr unsigned FClassMaskNegativeZero = 0x020; 105 static constexpr unsigned FClassMaskPositiveInfinity = 0x040; 106 static constexpr unsigned FClassMaskPositiveNormal = 0x080; 107 static constexpr unsigned FClassMaskPositiveSubnormal = 0x100; 108 static constexpr unsigned FClassMaskPositiveZero = 0x200; 109 } // namespace LoongArch 110 111 } // end namespace llvm 112 #endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHINSTRINFO_H 113