LLVM API Documentation

MipsISelDAGToDAG.h
Go to the documentation of this file.
00001 //===---- MipsISelDAGToDAG.h - A Dag to Dag Inst Selector for Mips --------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines an instruction selector for the MIPS target.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_LIB_TARGET_MIPS_MIPSISELDAGTODAG_H
00015 #define LLVM_LIB_TARGET_MIPS_MIPSISELDAGTODAG_H
00016 
00017 #include "Mips.h"
00018 #include "MipsSubtarget.h"
00019 #include "MipsTargetMachine.h"
00020 #include "llvm/CodeGen/SelectionDAGISel.h"
00021 
00022 //===----------------------------------------------------------------------===//
00023 // Instruction Selector Implementation
00024 //===----------------------------------------------------------------------===//
00025 
00026 //===----------------------------------------------------------------------===//
00027 // MipsDAGToDAGISel - MIPS specific code to select MIPS machine
00028 // instructions for SelectionDAG operations.
00029 //===----------------------------------------------------------------------===//
00030 namespace llvm {
00031 
00032 class MipsDAGToDAGISel : public SelectionDAGISel {
00033 public:
00034   explicit MipsDAGToDAGISel(MipsTargetMachine &TM)
00035       : SelectionDAGISel(TM), Subtarget(nullptr) {}
00036 
00037   // Pass Name
00038   const char *getPassName() const override {
00039     return "MIPS DAG->DAG Pattern Instruction Selection";
00040   }
00041 
00042   bool runOnMachineFunction(MachineFunction &MF) override;
00043 
00044 protected:
00045   SDNode *getGlobalBaseReg();
00046 
00047   /// Keep a pointer to the MipsSubtarget around so that we can make the right
00048   /// decision when generating code for different targets.
00049   const MipsSubtarget *Subtarget;
00050 
00051 private:
00052   // Include the pieces autogenerated from the target description.
00053   #include "MipsGenDAGISel.inc"
00054 
00055   // Complex Pattern.
00056   /// (reg + imm).
00057   virtual bool selectAddrRegImm(SDValue Addr, SDValue &Base,
00058                                 SDValue &Offset) const;
00059 
00060   // Complex Pattern.
00061   /// (reg + reg).
00062   virtual bool selectAddrRegReg(SDValue Addr, SDValue &Base,
00063                                 SDValue &Offset) const;
00064 
00065   /// Fall back on this function if all else fails.
00066   virtual bool selectAddrDefault(SDValue Addr, SDValue &Base,
00067                                  SDValue &Offset) const;
00068 
00069   /// Match integer address pattern.
00070   virtual bool selectIntAddr(SDValue Addr, SDValue &Base,
00071                              SDValue &Offset) const;
00072 
00073   virtual bool selectIntAddrMM(SDValue Addr, SDValue &Base,
00074                                SDValue &Offset) const;
00075 
00076   /// Match addr+simm10 and addr
00077   virtual bool selectIntAddrMSA(SDValue Addr, SDValue &Base,
00078                                 SDValue &Offset) const;
00079 
00080   virtual bool selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
00081                             SDValue &Offset, SDValue &Alias);
00082 
00083   /// \brief Select constant vector splats.
00084   virtual bool selectVSplat(SDNode *N, APInt &Imm) const;
00085   /// \brief Select constant vector splats whose value fits in a uimm1.
00086   virtual bool selectVSplatUimm1(SDValue N, SDValue &Imm) const;
00087   /// \brief Select constant vector splats whose value fits in a uimm2.
00088   virtual bool selectVSplatUimm2(SDValue N, SDValue &Imm) const;
00089   /// \brief Select constant vector splats whose value fits in a uimm3.
00090   virtual bool selectVSplatUimm3(SDValue N, SDValue &Imm) const;
00091   /// \brief Select constant vector splats whose value fits in a uimm4.
00092   virtual bool selectVSplatUimm4(SDValue N, SDValue &Imm) const;
00093   /// \brief Select constant vector splats whose value fits in a uimm5.
00094   virtual bool selectVSplatUimm5(SDValue N, SDValue &Imm) const;
00095   /// \brief Select constant vector splats whose value fits in a uimm6.
00096   virtual bool selectVSplatUimm6(SDValue N, SDValue &Imm) const;
00097   /// \brief Select constant vector splats whose value fits in a uimm8.
00098   virtual bool selectVSplatUimm8(SDValue N, SDValue &Imm) const;
00099   /// \brief Select constant vector splats whose value fits in a simm5.
00100   virtual bool selectVSplatSimm5(SDValue N, SDValue &Imm) const;
00101   /// \brief Select constant vector splats whose value is a power of 2.
00102   virtual bool selectVSplatUimmPow2(SDValue N, SDValue &Imm) const;
00103   /// \brief Select constant vector splats whose value is the inverse of a
00104   /// power of 2.
00105   virtual bool selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const;
00106   /// \brief Select constant vector splats whose value is a run of set bits
00107   /// ending at the most significant bit
00108   virtual bool selectVSplatMaskL(SDValue N, SDValue &Imm) const;
00109   /// \brief Select constant vector splats whose value is a run of set bits
00110   /// starting at bit zero.
00111   virtual bool selectVSplatMaskR(SDValue N, SDValue &Imm) const;
00112 
00113   SDNode *Select(SDNode *N) override;
00114 
00115   virtual std::pair<bool, SDNode*> selectNode(SDNode *Node) = 0;
00116 
00117   // getImm - Return a target constant with the specified value.
00118   inline SDValue getImm(const SDNode *Node, uint64_t Imm) {
00119     return CurDAG->getTargetConstant(Imm, Node->getValueType(0));
00120   }
00121 
00122   virtual void processFunctionAfterISel(MachineFunction &MF) = 0;
00123 
00124   bool SelectInlineAsmMemoryOperand(const SDValue &Op,
00125                                     char ConstraintCode,
00126                                     std::vector<SDValue> &OutOps) override;
00127 };
00128 
00129 /// createMipsISelDag - This pass converts a legalized DAG into a
00130 /// MIPS-specific DAG, ready for instruction scheduling.
00131 FunctionPass *createMipsISelDag(MipsTargetMachine &TM);
00132 
00133 }
00134 
00135 #endif