14 #define DEBUG_TYPE "mips-isel"
44 void MipsSEDAGToDAGISel::addDSPCtrlRegOperands(
bool IsDef,
MachineInstr &
MI,
51 MIB.addReg(Mips::DSPPos, Flag);
54 MIB.addReg(Mips::DSPSCount, Flag);
57 MIB.addReg(Mips::DSPCarry, Flag);
60 MIB.addReg(Mips::DSPOutFlag, Flag);
63 MIB.addReg(Mips::DSPCCond, Flag);
66 MIB.addReg(Mips::DSPEFI, Flag);
69 unsigned MipsSEDAGToDAGISel::getMSACtrlReg(
const SDValue RegIdx)
const {
70 switch (cast<ConstantSDNode>(RegIdx)->getZExtValue()) {
73 case 0:
return Mips::MSAIR;
74 case 1:
return Mips::MSACSR;
75 case 2:
return Mips::MSAAccess;
76 case 3:
return Mips::MSASave;
77 case 4:
return Mips::MSAModify;
78 case 5:
return Mips::MSARequest;
79 case 6:
return Mips::MSAMap;
80 case 7:
return Mips::MSAUnmap;
86 unsigned DstReg = 0, ZeroReg = 0;
94 }
else if ((MI.
getOpcode() == Mips::DADDiu) &&
98 ZeroReg = Mips::ZERO_64;
108 unsigned OpNo = U.getOperandNo();
154 BuildMI(MBB, I, DL, TII.
get(Mips::DADDu), V1).addReg(V0)
211 .addReg(Mips::V0).
addReg(Mips::T9);
214 void MipsSEDAGToDAGISel::processFunctionAfterISel(
MachineFunction &MF) {
215 initGlobalBaseReg(MF);
222 if (I->getOpcode() == Mips::RDDSP)
223 addDSPCtrlRegOperands(
false, *I, MF);
224 else if (I->getOpcode() == Mips::WRDSP)
225 addDSPCtrlRegOperands(
true, *I, MF);
227 replaceUsesWithZeroReg(MRI, *I);
231 SDNode *MipsSEDAGToDAGISel::selectAddESubE(
unsigned MOp,
SDValue InFlag,
234 unsigned Opc = InFlag.
getOpcode(); (void)Opc;
238 "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
253 bool MipsSEDAGToDAGISel::selectAddrRegImm(
SDValue Addr,
SDValue &Base,
307 if (isa<ConstantPoolSDNode>(Opnd0) || isa<GlobalAddressSDNode>(Opnd0) ||
308 isa<JumpTableSDNode>(Opnd0)) {
321 bool MipsSEDAGToDAGISel::selectAddrRegReg(
SDValue Addr,
SDValue &Base,
333 bool MipsSEDAGToDAGISel::selectAddrDefault(
SDValue Addr,
SDValue &Base,
340 bool MipsSEDAGToDAGISel::selectIntAddr(
SDValue Addr,
SDValue &Base,
342 return selectAddrRegImm(Addr, Base, Offset) ||
343 selectAddrDefault(Addr, Base, Offset);
347 bool MipsSEDAGToDAGISel::selectAddrRegImm12(
SDValue Addr,
SDValue &Base,
371 bool MipsSEDAGToDAGISel::selectIntAddrMM(
SDValue Addr,
SDValue &Base,
373 return selectAddrRegImm12(Addr, Base, Offset) ||
374 selectAddrDefault(Addr, Base, Offset);
382 bool MipsSEDAGToDAGISel::selectVSplat(
SDNode *
N,
APInt &Imm)
const {
391 APInt SplatValue, SplatUndef;
392 unsigned SplatBitSize;
421 bool MipsSEDAGToDAGISel::
423 unsigned ImmBitSize)
const {
430 if (selectVSplat (N.
getNode(), ImmValue) &&
433 (!Signed && ImmValue.
isIntN(ImmBitSize))) {
443 bool MipsSEDAGToDAGISel::
445 return selectVSplatCommon(N, Imm,
false, 1);
448 bool MipsSEDAGToDAGISel::
450 return selectVSplatCommon(N, Imm,
false, 2);
453 bool MipsSEDAGToDAGISel::
455 return selectVSplatCommon(N, Imm,
false, 3);
459 bool MipsSEDAGToDAGISel::
461 return selectVSplatCommon(N, Imm,
false, 4);
465 bool MipsSEDAGToDAGISel::
467 return selectVSplatCommon(N, Imm,
false, 5);
471 bool MipsSEDAGToDAGISel::
473 return selectVSplatCommon(N, Imm,
false, 6);
477 bool MipsSEDAGToDAGISel::
479 return selectVSplatCommon(N, Imm,
false, 8);
483 bool MipsSEDAGToDAGISel::
485 return selectVSplatCommon(N, Imm,
true, 5);
498 bool MipsSEDAGToDAGISel::selectVSplatUimmPow2(
SDValue N,
SDValue &Imm)
const {
505 if (selectVSplat (N.
getNode(), ImmValue) &&
529 bool MipsSEDAGToDAGISel::selectVSplatMaskL(
SDValue N,
SDValue &Imm)
const {
536 if (selectVSplat(N.
getNode(), ImmValue) &&
541 if (ImmValue == ~(~ImmValue & ~(~ImmValue + 1))) {
562 bool MipsSEDAGToDAGISel::selectVSplatMaskR(
SDValue N,
SDValue &Imm)
const {
569 if (selectVSplat(N.
getNode(), ImmValue) &&
573 if (ImmValue == (ImmValue & ~(ImmValue + 1))) {
582 bool MipsSEDAGToDAGISel::selectVSplatUimmInvPow2(
SDValue N,
590 if (selectVSplat(N.
getNode(), ImmValue) &&
592 int32_t Log2 = (~ImmValue).exactLogBase2();
603 std::pair<bool, SDNode*> MipsSEDAGToDAGISel::selectNode(
SDNode *Node) {
618 Result = selectAddESubE(Mips::SUBu, InFlag, InFlag.
getOperand(0), DL, Node);
619 return std::make_pair(
true, Result);
626 Result = selectAddESubE(Mips::ADDu, InFlag, InFlag.
getValue(0), DL, Node);
627 return std::make_pair(
true, Result);
649 return std::make_pair(
true, Result);
665 AnalyzeImm.
Analyze(Imm, Size,
false);
676 if (Inst->Opc == Mips::LUi64)
685 for (++Inst; Inst != Seq.
end(); ++Inst) {
692 return std::make_pair(
true, RegOpnd);
696 switch (cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue()) {
705 return std::make_pair(
true, Reg.
getNode());
712 switch (cast<ConstantSDNode>(Node->
getOperand(0))->getZExtValue()) {
719 return std::make_pair(
true,
728 switch (cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue()) {
737 getMSACtrlReg(RegIdx), Value);
738 return std::make_pair(
true, ChainOut.
getNode());
746 unsigned RdhwrOpc, DestReg;
749 RdhwrOpc = Mips::RDHWR;
752 RdhwrOpc = Mips::RDHWR64;
753 DestReg = Mips::V1_64;
764 return std::make_pair(
true, ResNode.
getNode());
781 APInt SplatValue, SplatUndef;
782 unsigned SplatBitSize;
789 return std::make_pair(
false, (
SDNode*)NULL);
794 return std::make_pair(
false, (
SDNode*)NULL);
796 switch (SplatBitSize) {
798 return std::make_pair(
false, (
SDNode*)NULL);
817 if (!SplatValue.isSignedIntN(10))
818 return std::make_pair(
false, (
SDNode*)NULL);
825 if (ResVecTy != ViaVecTy) {
839 return std::make_pair(
true, Res);
844 return std::make_pair(
false, (
SDNode*)NULL);
unsigned getValueSizeInBits(unsigned ResNo) const
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=0) const
SDValue getValue(unsigned R) const
MachineInstr * getParent()
bool isExactlyValue(double V) const
SDValue getCopyToReg(SDValue Chain, SDLoc dl, unsigned Reg, SDValue N)
Reloc::Model getRelocationModel() const
void ReplaceUses(SDValue F, SDValue T)
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
void addLiveIn(unsigned Reg, unsigned vreg=0)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isPseudo(QueryType Type=IgnoreBundle) const
unsigned getOpcode() const
void addLiveIn(unsigned Reg)
const SDValue & getOperand(unsigned Num) const
const Function * getFunction() const
FunctionPass * createMipsSEISelDag(MipsTargetMachine &TM)
static use_iterator use_end()
const HexagonInstrInfo * TII
#define llvm_unreachable(msg)
EVT getValueType(unsigned ResNo) const
const TargetLowering * getTargetLowering() const
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
virtual MVT getPointerTy(uint32_t=0) const
EVT getVectorElementType() const
const MachineBasicBlock & front() const
SDValue getTargetFrameIndex(int FI, EVT VT)
Simple integer binary arithmetic operators.
MachineRegisterInfo * RegInfo
bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef, unsigned &SplatBitSize, bool &HasAnyUndefs, unsigned MinSplatBits=0, bool isBigEndian=false)
SDNode * getNode() const
get the SDNode which holds the desired result
bundle_iterator< MachineInstr, instr_iterator > iterator
const SDValue & getOperand(unsigned i) const
const MachineOperand & getOperand(unsigned i) const
SDValue getCopyFromReg(SDValue Chain, SDLoc dl, unsigned Reg, EVT VT)
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getOpcode() const
unsigned countPopulation() const
Count the number of bits set.
bool inMips16Mode() const
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
const MCInstrDesc & get(unsigned Opcode) const
virtual bool runOnMachineFunction(MachineFunction &MF)
virtual const TargetInstrInfo * getInstrInfo() const
bool isBaseWithConstantOffset(SDValue Op) const
unsigned getGlobalBaseReg()
SDNode * SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT)
int32_t exactLogBase2() const
Class for arbitrary precision integers.
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
int64_t getSExtValue() const
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
MachineRegisterInfo & getRegInfo()
use_iterator use_begin(unsigned RegNo) const
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
unsigned getSizeInBits() const
getSizeInBits - Return the size of the specified value type in bits.
void setReg(unsigned Reg)
const TargetMachine & getTarget() const
MachineSDNode * getMachineNode(unsigned Opcode, SDLoc dl, EVT VT)
bool isInt< 16 >(int64_t x)
bool globalBaseRegSet() const
bool is128BitVector() const
is128BitVector - Return true if this is a 128-bit vector type.
unsigned getReg() const
getReg - Returns the register number.
const MipsSubtarget & Subtarget
LLVM Value Representation.
SDValue getRegister(unsigned Reg, EVT VT)
BasicBlockListType::iterator iterator
const MCRegisterInfo & MRI
SDValue getTargetConstant(uint64_t Val, EVT VT)
SDValue getEntryNode() const
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
uint64_t getZExtValue() const