28#define GET_INSTRINFO_CTOR_DTOR
29#include "SparcGenInstrInfo.inc"
33 cl::desc(
"Restrict range of BPcc/FBPfcc instructions (DEBUG)"));
36void SparcInstrInfo::anchor() {}
48 int &FrameIndex)
const {
49 if (
MI.getOpcode() == SP::LDri ||
MI.getOpcode() == SP::LDXri ||
50 MI.getOpcode() == SP::LDFri ||
MI.getOpcode() == SP::LDDFri ||
51 MI.getOpcode() == SP::LDQFri) {
52 if (
MI.getOperand(1).isFI() &&
MI.getOperand(2).isImm() &&
53 MI.getOperand(2).getImm() == 0) {
54 FrameIndex =
MI.getOperand(1).getIndex();
55 return MI.getOperand(0).getReg();
67 int &FrameIndex)
const {
68 if (
MI.getOpcode() == SP::STri ||
MI.getOpcode() == SP::STXri ||
69 MI.getOpcode() == SP::STFri ||
MI.getOpcode() == SP::STDFri ||
70 MI.getOpcode() == SP::STQFri) {
71 if (
MI.getOperand(0).isFI() &&
MI.getOperand(1).isImm() &&
72 MI.getOperand(1).getImm() == 0) {
73 FrameIndex =
MI.getOperand(0).getIndex();
74 return MI.getOperand(2).getReg();
160 return Opc == SP::BCOND || Opc == SP::BPICC || Opc == SP::BPICCA ||
161 Opc == SP::BPICCNT || Opc == SP::BPICCANT;
165 return Opc == SP::BPXCC || Opc == SP::BPXCCA || Opc == SP::BPXCCNT ||
170 return Opc == SP::FBCOND || Opc == SP::FBCONDA || Opc == SP::FBCOND_V9 ||
171 Opc == SP::FBCONDA_V9;
180 return Opc == SP::BINDrr || Opc == SP::BINDri;
198 switch (
MI.getOpcode()) {
220 return MI.getOperand(0).getMBB();
228 bool AllowModify)
const {
233 if (!isUnpredicatedTerminator(*
I))
238 unsigned LastOpc = LastInst->
getOpcode();
241 if (
I ==
MBB.
begin() || !isUnpredicatedTerminator(*--
I)) {
256 unsigned SecondLastOpc = SecondLastInst->
getOpcode();
263 LastInst = SecondLastInst;
265 if (
I ==
MBB.
begin() || !isUnpredicatedTerminator(*--
I)) {
270 SecondLastInst = &*
I;
271 SecondLastOpc = SecondLastInst->
getOpcode();
277 if (SecondLastInst &&
I !=
MBB.
begin() && isUnpredicatedTerminator(*--
I))
299 I->eraseFromParent();
312 int *BytesAdded)
const {
313 assert(
TBB &&
"insertBranch must not be told to insert a fallthrough");
315 "Sparc branch conditions should have at most two components!");
318 assert(!FBB &&
"Unconditional branch with multiple successors!");
326 unsigned Opc =
Cond[0].getImm();
327 unsigned CC =
Cond[1].getImm();
343 int *BytesRemoved)
const {
350 if (
I->isDebugInstr())
358 I->eraseFromParent();
364 *BytesRemoved = Removed;
378 assert((
Offset & 0b11) == 0 &&
"Malformed branch offset");
411 unsigned numSubRegs = 0;
413 const unsigned *subRegIdx =
nullptr;
414 bool ExtraG0 =
false;
416 const unsigned DW_SubRegsIdx[] = { SP::sub_even, SP::sub_odd };
417 const unsigned DFP_FP_SubRegsIdx[] = { SP::sub_even, SP::sub_odd };
418 const unsigned QFP_DFP_SubRegsIdx[] = { SP::sub_even64, SP::sub_odd64 };
419 const unsigned QFP_FP_SubRegsIdx[] = { SP::sub_even, SP::sub_odd,
420 SP::sub_odd64_then_sub_even,
421 SP::sub_odd64_then_sub_odd };
423 if (SP::IntRegsRegClass.
contains(DestReg, SrcReg))
426 else if (SP::IntPairRegClass.
contains(DestReg, SrcReg)) {
427 subRegIdx = DW_SubRegsIdx;
431 }
else if (SP::FPRegsRegClass.
contains(DestReg, SrcReg))
434 else if (SP::DFPRegsRegClass.
contains(DestReg, SrcReg)) {
435 if (Subtarget.
isV9()) {
440 subRegIdx = DFP_FP_SubRegsIdx;
444 }
else if (SP::QFPRegsRegClass.
contains(DestReg, SrcReg)) {
445 if (Subtarget.
isV9()) {
451 subRegIdx = QFP_DFP_SubRegsIdx;
457 subRegIdx = QFP_FP_SubRegsIdx;
461 }
else if (SP::ASRRegsRegClass.
contains(DestReg) &&
462 SP::IntRegsRegClass.
contains(SrcReg)) {
466 }
else if (SP::IntRegsRegClass.
contains(DestReg) &&
467 SP::ASRRegsRegClass.
contains(SrcReg)) {
473 if (numSubRegs == 0 || subRegIdx ==
nullptr || movOpc == 0)
479 for (
unsigned i = 0; i != numSubRegs; ++i) {
480 Register Dst =
TRI->getSubReg(DestReg, subRegIdx[i]);
481 Register Src =
TRI->getSubReg(SrcReg, subRegIdx[i]);
482 assert(Dst && Src &&
"Bad sub-register");
498 Register SrcReg,
bool isKill,
int FI,
512 if (RC == &SP::I64RegsRegClass)
515 else if (RC == &SP::IntRegsRegClass)
518 else if (RC == &SP::IntPairRegClass)
521 else if (RC == &SP::FPRegsRegClass)
524 else if (SP::DFPRegsRegClass.hasSubClassEq(RC))
527 else if (SP::QFPRegsRegClass.hasSubClassEq(RC))
551 if (RC == &SP::I64RegsRegClass)
554 else if (RC == &SP::IntRegsRegClass)
557 else if (RC == &SP::IntPairRegClass)
560 else if (RC == &SP::FPRegsRegClass)
563 else if (SP::DFPRegsRegClass.hasSubClassEq(RC))
566 else if (SP::QFPRegsRegClass.hasSubClassEq(RC))
579 return GlobalBaseReg;
587 Subtarget.
is64Bit() ? &SP::I64RegsRegClass : &SP::IntRegsRegClass;
594 return GlobalBaseReg;
598 unsigned Opcode =
MI.getOpcode();
600 if (
MI.isInlineAsm()) {
602 const char *AsmStr =
MI.getOperand(0).getSymbolName();
609 if (
MI.hasDelaySlot())
610 return get(Opcode).getSize() * 2;
611 return get(Opcode).getSize();
615 switch (
MI.getOpcode()) {
616 case TargetOpcode::LOAD_STACK_GUARD: {
618 "Only Linux target is expected to contain LOAD_STACK_GUARD");
621 MI.setDesc(
get(Subtarget.
is64Bit() ? SP::LDXri : SP::LDri));
static void parseCondBranch(MachineInstr *LastInst, MachineBasicBlock *&Target, SmallVectorImpl< MachineOperand > &Cond)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
SmallVector< MachineOperand, 4 > Cond
unsigned const TargetRegisterInfo * TRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static bool isFCondBranchOpcode(int Opc)
static SPCC::CondCodes GetOppositeBranchCondition(SPCC::CondCodes CC)
static bool isI32CondBranchOpcode(int Opc)
static cl::opt< unsigned > BPccDisplacementBits("sparc-bpcc-offset-bits", cl::Hidden, cl::init(19), cl::desc("Restrict range of BPcc/FBPfcc instructions (DEBUG)"))
static bool isI64CondBranchOpcode(int Opc)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Wrapper class representing physical registers. Should be passed by value.
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool addRegisterKilled(Register IncomingReg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI kills a register.
void addRegisterDefined(Register Reg, const TargetRegisterInfo *RegInfo=nullptr)
We have determined MI defines a register.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineBasicBlock * getMBB() const
static MachineOperand CreateImm(int64_t Val)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Wrapper class representing virtual and physical registers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
isStoreToStackSlot - If the specified machine instruction is a direct store to a stack slot,...
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t Offset) const override
Determine if the branch target is in range.
SparcInstrInfo(SparcSubtarget &ST)
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
Register getGlobalBaseReg(MachineFunction *MF) const
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, bool KillSrc) const override
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
MachineBasicBlock * getBranchDestBlock(const MachineInstr &MI) const override
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify=false) const override
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
isLoadFromStackSlot - If the specified machine instruction is a direct load from a stack slot,...
const SparcRegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
GetInstSize - Return the number of bytes of code the specified instruction may be.
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
bool expandPostRAPseudo(MachineInstr &MI) const override
Register getGlobalBaseReg() const
void setGlobalBaseReg(Register Reg)
bool isTargetLinux() const
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Target - Wrapper for Target specific information.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
static bool isCondBranchOpcode(int Opc)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool isIndirectBranchOpcode(int Opc)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
unsigned getKillRegState(bool B)
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
static bool isUncondBranchOpcode(int Opc)
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.