1 //===-- RISCVInstrInfo.h - RISCV 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 RISCV implementation of the TargetInstrInfo class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_TARGET_RISCV_RISCVINSTRINFO_H 14 #define LLVM_LIB_TARGET_RISCV_RISCVINSTRINFO_H 15 16 #include "RISCVRegisterInfo.h" 17 #include "llvm/CodeGen/TargetInstrInfo.h" 18 19 #define GET_INSTRINFO_HEADER 20 #include "RISCVGenInstrInfo.inc" 21 22 namespace llvm { 23 24 class RISCVSubtarget; 25 26 class RISCVInstrInfo : public RISCVGenInstrInfo { 27 28 public: 29 explicit RISCVInstrInfo(RISCVSubtarget &STI); 30 31 unsigned isLoadFromStackSlot(const MachineInstr &MI, 32 int &FrameIndex) const override; 33 unsigned isStoreToStackSlot(const MachineInstr &MI, 34 int &FrameIndex) const override; 35 36 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, 37 const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg, 38 bool KillSrc) const override; 39 40 void storeRegToStackSlot(MachineBasicBlock &MBB, 41 MachineBasicBlock::iterator MBBI, Register SrcReg, 42 bool IsKill, int FrameIndex, 43 const TargetRegisterClass *RC, 44 const TargetRegisterInfo *TRI) const override; 45 46 void loadRegFromStackSlot(MachineBasicBlock &MBB, 47 MachineBasicBlock::iterator MBBI, Register DstReg, 48 int FrameIndex, const TargetRegisterClass *RC, 49 const TargetRegisterInfo *TRI) const override; 50 51 // Materializes the given integer Val into DstReg. 52 void movImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, 53 const DebugLoc &DL, Register DstReg, uint64_t Val, 54 MachineInstr::MIFlag Flag = MachineInstr::NoFlags) const; 55 56 unsigned getInstSizeInBytes(const MachineInstr &MI) const override; 57 58 bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, 59 MachineBasicBlock *&FBB, 60 SmallVectorImpl<MachineOperand> &Cond, 61 bool AllowModify) const override; 62 63 unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, 64 MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond, 65 const DebugLoc &dl, 66 int *BytesAdded = nullptr) const override; 67 68 unsigned insertIndirectBranch(MachineBasicBlock &MBB, 69 MachineBasicBlock &NewDestBB, 70 const DebugLoc &DL, int64_t BrOffset, 71 RegScavenger *RS = nullptr) const override; 72 73 unsigned removeBranch(MachineBasicBlock &MBB, 74 int *BytesRemoved = nullptr) const override; 75 76 bool 77 reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; 78 79 MachineBasicBlock *getBranchDestBlock(const MachineInstr &MI) const override; 80 81 bool isBranchOffsetInRange(unsigned BranchOpc, 82 int64_t BrOffset) const override; 83 84 bool isAsCheapAsAMove(const MachineInstr &MI) const override; 85 86 Optional<DestSourcePair> 87 isCopyInstrImpl(const MachineInstr &MI) const override; 88 89 bool verifyInstruction(const MachineInstr &MI, 90 StringRef &ErrInfo) const override; 91 92 bool getMemOperandWithOffsetWidth(const MachineInstr &LdSt, 93 const MachineOperand *&BaseOp, 94 int64_t &Offset, unsigned &Width, 95 const TargetRegisterInfo *TRI) const; 96 97 bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, 98 const MachineInstr &MIb) const override; 99 100 101 std::pair<unsigned, unsigned> 102 decomposeMachineOperandsTargetFlags(unsigned TF) const override; 103 104 ArrayRef<std::pair<unsigned, const char *>> 105 getSerializableDirectMachineOperandTargetFlags() const override; 106 107 // Return true if the function can safely be outlined from. 108 virtual bool 109 isFunctionSafeToOutlineFrom(MachineFunction &MF, 110 bool OutlineFromLinkOnceODRs) const override; 111 112 // Return true if MBB is safe to outline from, and return any target-specific 113 // information in Flags. 114 virtual bool isMBBSafeToOutlineFrom(MachineBasicBlock &MBB, 115 unsigned &Flags) const override; 116 117 // Calculate target-specific information for a set of outlining candidates. 118 outliner::OutlinedFunction getOutliningCandidateInfo( 119 std::vector<outliner::Candidate> &RepeatedSequenceLocs) const override; 120 121 // Return if/how a given MachineInstr should be outlined. 122 virtual outliner::InstrType 123 getOutliningType(MachineBasicBlock::iterator &MBBI, 124 unsigned Flags) const override; 125 126 // Insert a custom frame for outlined functions. 127 virtual void 128 buildOutlinedFrame(MachineBasicBlock &MBB, MachineFunction &MF, 129 const outliner::OutlinedFunction &OF) const override; 130 131 // Insert a call to an outlined function into a given basic block. 132 virtual MachineBasicBlock::iterator 133 insertOutlinedCall(Module &M, MachineBasicBlock &MBB, 134 MachineBasicBlock::iterator &It, MachineFunction &MF, 135 const outliner::Candidate &C) const override; 136 protected: 137 const RISCVSubtarget &STI; 138 }; 139 140 } // end namespace llvm 141 #endif 142