27 #define GET_INSTRINFO_CTOR_DTOR 28 #include "RISCVGenInstrInfo.inc" 87 unsigned SrcReg,
bool KillSrc)
const {
88 if (RISCV::GPRRegClass.
contains(DstReg, SrcReg)) {
89 BuildMI(MBB, MBBI, DL,
get(RISCV::ADDI), DstReg)
97 if (RISCV::FPR32RegClass.
contains(DstReg, SrcReg))
99 else if (RISCV::FPR64RegClass.
contains(DstReg, SrcReg))
100 Opc = RISCV::FSGNJ_D;
104 BuildMI(MBB, MBBI, DL,
get(Opc), DstReg)
111 unsigned SrcReg,
bool IsKill,
int FI,
116 DL = I->getDebugLoc();
120 if (RISCV::GPRRegClass.hasSubClassEq(RC))
122 RISCV::SW : RISCV::SD;
123 else if (RISCV::FPR32RegClass.hasSubClassEq(RC))
125 else if (RISCV::FPR64RegClass.hasSubClassEq(RC))
130 BuildMI(MBB, I, DL,
get(Opcode))
138 unsigned DstReg,
int FI,
143 DL = I->getDebugLoc();
147 if (RISCV::GPRRegClass.hasSubClassEq(RC))
150 else if (RISCV::FPR32RegClass.hasSubClassEq(RC))
152 else if (RISCV::FPR64RegClass.hasSubClassEq(RC))
162 const DebugLoc &DL,
unsigned DstReg, uint64_t Val,
169 uint64_t Hi20 = ((Val + 0x800) >> 12) & 0xfffff;
170 uint64_t Lo12 = SignExtend64<12>(Val);
171 BuildMI(MBB, MBBI, DL,
get(RISCV::LUI), DstReg)
174 BuildMI(MBB, MBBI, DL,
get(RISCV::ADDI), DstReg)
187 "Unknown conditional branch");
217 bool AllowModify)
const {
223 if (I == MBB.
end() || !isUnpredicatedTerminator(*I))
229 int NumTerminators = 0;
230 for (
auto J = I.
getReverse(); J != MBB.
rend() && isUnpredicatedTerminator(*J);
233 if (J->getDesc().isUnconditionalBranch() ||
234 J->getDesc().isIndirectBranch()) {
241 if (AllowModify && FirstUncondOrIndirectBr != MBB.
end()) {
242 while (std::next(FirstUncondOrIndirectBr) != MBB.
end()) {
243 std::next(FirstUncondOrIndirectBr)->eraseFromParent();
246 I = FirstUncondOrIndirectBr;
250 if (I->getDesc().isIndirectBranch())
254 if (NumTerminators > 2)
258 if (NumTerminators == 1 && I->getDesc().isUnconditionalBranch()) {
259 TBB = I->getOperand(0).getMBB();
264 if (NumTerminators == 1 && I->getDesc().isConditionalBranch()) {
270 if (NumTerminators == 2 && std::prev(I)->
getDesc().isConditionalBranch() &&
271 I->getDesc().isUnconditionalBranch()) {
273 FBB = I->getOperand(0).getMBB();
282 int *BytesRemoved)
const {
289 if (!I->getDesc().isUnconditionalBranch() &&
290 !I->getDesc().isConditionalBranch())
294 I->eraseFromParent();
300 if (I == MBB.
begin())
303 if (!I->getDesc().isConditionalBranch())
307 I->eraseFromParent();
322 assert(TBB &&
"InsertBranch must not be told to insert a fallthrough");
324 "RISCV branch conditions have two components!");
335 unsigned Opc = Cond[0].getImm();
357 assert(RS &&
"RegScavenger required for long branching");
359 "new block should be inserted for expanding unconditional branch");
366 if (
TM.isPositionIndependent())
371 "Branch offsets outside of the signed 32-bit range not supported");
381 BuildMI(MBB, II, DL,
get(RISCV::PseudoBRIND))
396 assert((Cond.
size() == 3) &&
"Invalid branch condition!");
410 int64_t BrOffset)
const {
423 return isIntN(13, BrOffset);
425 case RISCV::PseudoBR:
426 return isIntN(21, BrOffset);
434 default: {
return get(Opcode).getSize(); }
436 case TargetOpcode::IMPLICIT_DEF:
438 case TargetOpcode::DBG_VALUE:
440 case RISCV::PseudoCALL:
441 case RISCV::PseudoTAIL:
const MachineInstrBuilder & add(const MachineOperand &MO) const
MachineBasicBlock * getMBB() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
void push_back(const T &Elt)
unsigned getReg() const
getReg - Returns the register number.
unsigned const TargetRegisterInfo * TRI
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void clearVirtRegs()
clearVirtRegs - Remove all virtual registers (after physreg assignment).
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &dl, int *BytesAdded=nullptr) const override
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
return AArch64::GPR64RegClass contains(Reg)
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool IsKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
unsigned scavengeRegisterBackwards(const TargetRegisterClass &RC, MachineBasicBlock::iterator To, bool RestoreAfter, int SPAdj)
Make a register of the specific register class available from the current position backwards to the p...
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const char * getSymbolName() const
INLINEASM - Represents an inline asm block.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
void movImm32(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned DstReg, uint64_t Val, MachineInstr::MIFlag Flag=MachineInstr::NoFlags) const
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
unsigned getKillRegState(bool B)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
This file declares the machine register scavenger class.
unsigned const MachineRegisterInfo * MRI
This instruction implements an extending load to FP stack slots.
size_t size() const
size - Get the array size.
bool isConditionalBranch() const
Return true if this is a branch which may fall through to the next instruction or may transfer contro...
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned DstReg, unsigned SrcReg, bool KillSrc) const override
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
const MachineInstrBuilder & addFrameIndex(int Idx) const
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
constexpr bool isInt< 32 >(int64_t x)
static unsigned getOppositeBranchOpcode(int Opc)
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
void enterBasicBlockEnd(MachineBasicBlock &MBB)
Start tracking liveness from the end of basic block MBB.
unsigned pred_size() const
Target - Wrapper for Target specific information.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
unsigned insertIndirectBranch(MachineBasicBlock &MBB, MachineBasicBlock &NewDestBB, const DebugLoc &DL, int64_t BrOffset, RegScavenger *RS=nullptr) const override
MachineBasicBlock * getBranchDestBlock(const MachineInstr &MI) const override
static MachineOperand CreateImm(int64_t Val)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const override
static void parseCondBranch(MachineInstr &LastInst, MachineBasicBlock *&Target, SmallVectorImpl< MachineOperand > &Cond)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setRegUsed(unsigned Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Tell the scavenger a register is used.
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
const MachineOperand & getOperand(unsigned i) const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DstReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
bool empty() const
empty - Check if the array is empty.