1*9880d681SAndroid Build Coastguard Worker //===---- MipsISelDAGToDAG.h - A Dag to Dag Inst Selector for Mips --------===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file defines an instruction selector for the MIPS target. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_MIPS_MIPSISELDAGTODAG_H 15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_MIPS_MIPSISELDAGTODAG_H 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #include "Mips.h" 18*9880d681SAndroid Build Coastguard Worker #include "MipsSubtarget.h" 19*9880d681SAndroid Build Coastguard Worker #include "MipsTargetMachine.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/SelectionDAGISel.h" 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 23*9880d681SAndroid Build Coastguard Worker // Instruction Selector Implementation 24*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 27*9880d681SAndroid Build Coastguard Worker // MipsDAGToDAGISel - MIPS specific code to select MIPS machine 28*9880d681SAndroid Build Coastguard Worker // instructions for SelectionDAG operations. 29*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 30*9880d681SAndroid Build Coastguard Worker namespace llvm { 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Worker class MipsDAGToDAGISel : public SelectionDAGISel { 33*9880d681SAndroid Build Coastguard Worker public: MipsDAGToDAGISel(MipsTargetMachine & TM,CodeGenOpt::Level OL)34*9880d681SAndroid Build Coastguard Worker explicit MipsDAGToDAGISel(MipsTargetMachine &TM, CodeGenOpt::Level OL) 35*9880d681SAndroid Build Coastguard Worker : SelectionDAGISel(TM, OL), Subtarget(nullptr) {} 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Worker // Pass Name getPassName()38*9880d681SAndroid Build Coastguard Worker const char *getPassName() const override { 39*9880d681SAndroid Build Coastguard Worker return "MIPS DAG->DAG Pattern Instruction Selection"; 40*9880d681SAndroid Build Coastguard Worker } 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker bool runOnMachineFunction(MachineFunction &MF) override; 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard Worker protected: 45*9880d681SAndroid Build Coastguard Worker SDNode *getGlobalBaseReg(); 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Worker /// Keep a pointer to the MipsSubtarget around so that we can make the right 48*9880d681SAndroid Build Coastguard Worker /// decision when generating code for different targets. 49*9880d681SAndroid Build Coastguard Worker const MipsSubtarget *Subtarget; 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Worker private: 52*9880d681SAndroid Build Coastguard Worker // Include the pieces autogenerated from the target description. 53*9880d681SAndroid Build Coastguard Worker #include "MipsGenDAGISel.inc" 54*9880d681SAndroid Build Coastguard Worker 55*9880d681SAndroid Build Coastguard Worker // Complex Pattern. 56*9880d681SAndroid Build Coastguard Worker /// (reg + imm). 57*9880d681SAndroid Build Coastguard Worker virtual bool selectAddrRegImm(SDValue Addr, SDValue &Base, 58*9880d681SAndroid Build Coastguard Worker SDValue &Offset) const; 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Worker /// Fall back on this function if all else fails. 61*9880d681SAndroid Build Coastguard Worker virtual bool selectAddrDefault(SDValue Addr, SDValue &Base, 62*9880d681SAndroid Build Coastguard Worker SDValue &Offset) const; 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker /// Match integer address pattern. 65*9880d681SAndroid Build Coastguard Worker virtual bool selectIntAddr(SDValue Addr, SDValue &Base, 66*9880d681SAndroid Build Coastguard Worker SDValue &Offset) const; 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Worker virtual bool selectIntAddr11MM(SDValue Addr, SDValue &Base, 69*9880d681SAndroid Build Coastguard Worker SDValue &Offset) const; 70*9880d681SAndroid Build Coastguard Worker 71*9880d681SAndroid Build Coastguard Worker virtual bool selectIntAddr12MM(SDValue Addr, SDValue &Base, 72*9880d681SAndroid Build Coastguard Worker SDValue &Offset) const; 73*9880d681SAndroid Build Coastguard Worker 74*9880d681SAndroid Build Coastguard Worker virtual bool selectIntAddr16MM(SDValue Addr, SDValue &Base, 75*9880d681SAndroid Build Coastguard Worker SDValue &Offset) const; 76*9880d681SAndroid Build Coastguard Worker 77*9880d681SAndroid Build Coastguard Worker virtual bool selectIntAddrLSL2MM(SDValue Addr, SDValue &Base, 78*9880d681SAndroid Build Coastguard Worker SDValue &Offset) const; 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Worker /// Match addr+simm10 and addr 81*9880d681SAndroid Build Coastguard Worker virtual bool selectIntAddrMSA(SDValue Addr, SDValue &Base, 82*9880d681SAndroid Build Coastguard Worker SDValue &Offset) const; 83*9880d681SAndroid Build Coastguard Worker 84*9880d681SAndroid Build Coastguard Worker virtual bool selectAddr16(SDValue Addr, SDValue &Base, SDValue &Offset); 85*9880d681SAndroid Build Coastguard Worker virtual bool selectAddr16SP(SDValue Addr, SDValue &Base, SDValue &Offset); 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats. 88*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplat(SDNode *N, APInt &Imm, 89*9880d681SAndroid Build Coastguard Worker unsigned MinSizeInBits) const; 90*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value fits in a uimm1. 91*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimm1(SDValue N, SDValue &Imm) const; 92*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value fits in a uimm2. 93*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimm2(SDValue N, SDValue &Imm) const; 94*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value fits in a uimm3. 95*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimm3(SDValue N, SDValue &Imm) const; 96*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value fits in a uimm4. 97*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimm4(SDValue N, SDValue &Imm) const; 98*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value fits in a uimm5. 99*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimm5(SDValue N, SDValue &Imm) const; 100*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value fits in a uimm6. 101*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimm6(SDValue N, SDValue &Imm) const; 102*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value fits in a uimm8. 103*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimm8(SDValue N, SDValue &Imm) const; 104*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value fits in a simm5. 105*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatSimm5(SDValue N, SDValue &Imm) const; 106*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value is a power of 2. 107*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimmPow2(SDValue N, SDValue &Imm) const; 108*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value is the inverse of a 109*9880d681SAndroid Build Coastguard Worker /// power of 2. 110*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const; 111*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value is a run of set bits 112*9880d681SAndroid Build Coastguard Worker /// ending at the most significant bit 113*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatMaskL(SDValue N, SDValue &Imm) const; 114*9880d681SAndroid Build Coastguard Worker /// \brief Select constant vector splats whose value is a run of set bits 115*9880d681SAndroid Build Coastguard Worker /// starting at bit zero. 116*9880d681SAndroid Build Coastguard Worker virtual bool selectVSplatMaskR(SDValue N, SDValue &Imm) const; 117*9880d681SAndroid Build Coastguard Worker 118*9880d681SAndroid Build Coastguard Worker void Select(SDNode *N) override; 119*9880d681SAndroid Build Coastguard Worker 120*9880d681SAndroid Build Coastguard Worker virtual bool trySelect(SDNode *Node) = 0; 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Worker // getImm - Return a target constant with the specified value. getImm(const SDNode * Node,uint64_t Imm)123*9880d681SAndroid Build Coastguard Worker inline SDValue getImm(const SDNode *Node, uint64_t Imm) { 124*9880d681SAndroid Build Coastguard Worker return CurDAG->getTargetConstant(Imm, SDLoc(Node), Node->getValueType(0)); 125*9880d681SAndroid Build Coastguard Worker } 126*9880d681SAndroid Build Coastguard Worker 127*9880d681SAndroid Build Coastguard Worker virtual void processFunctionAfterISel(MachineFunction &MF) = 0; 128*9880d681SAndroid Build Coastguard Worker 129*9880d681SAndroid Build Coastguard Worker bool SelectInlineAsmMemoryOperand(const SDValue &Op, 130*9880d681SAndroid Build Coastguard Worker unsigned ConstraintID, 131*9880d681SAndroid Build Coastguard Worker std::vector<SDValue> &OutOps) override; 132*9880d681SAndroid Build Coastguard Worker }; 133*9880d681SAndroid Build Coastguard Worker } 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Worker #endif 136