1 //===---- MipsISelDAGToDAG.h - A Dag to Dag Inst Selector for Mips --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an instruction selector for the MIPS target.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_MIPS_MIPSISELDAGTODAG_H
15 #define LLVM_LIB_TARGET_MIPS_MIPSISELDAGTODAG_H
18 #include "MipsSubtarget.h"
19 #include "MipsTargetMachine.h"
20 #include "llvm/CodeGen/SelectionDAGISel.h"
22 //===----------------------------------------------------------------------===//
23 // Instruction Selector Implementation
24 //===----------------------------------------------------------------------===//
26 //===----------------------------------------------------------------------===//
27 // MipsDAGToDAGISel - MIPS specific code to select MIPS machine
28 // instructions for SelectionDAG operations.
29 //===----------------------------------------------------------------------===//
32 class MipsDAGToDAGISel : public SelectionDAGISel {
34 explicit MipsDAGToDAGISel(MipsTargetMachine &TM)
35 : SelectionDAGISel(TM), Subtarget(nullptr) {}
38 const char *getPassName() const override {
39 return "MIPS DAG->DAG Pattern Instruction Selection";
42 bool runOnMachineFunction(MachineFunction &MF) override;
45 SDNode *getGlobalBaseReg();
47 /// Keep a pointer to the MipsSubtarget around so that we can make the right
48 /// decision when generating code for different targets.
49 const MipsSubtarget *Subtarget;
52 // Include the pieces autogenerated from the target description.
53 #include "MipsGenDAGISel.inc"
57 virtual bool selectAddrRegImm(SDValue Addr, SDValue &Base,
58 SDValue &Offset) const;
62 virtual bool selectAddrRegReg(SDValue Addr, SDValue &Base,
63 SDValue &Offset) const;
65 /// Fall back on this function if all else fails.
66 virtual bool selectAddrDefault(SDValue Addr, SDValue &Base,
67 SDValue &Offset) const;
69 /// Match integer address pattern.
70 virtual bool selectIntAddr(SDValue Addr, SDValue &Base,
71 SDValue &Offset) const;
73 virtual bool selectIntAddrMM(SDValue Addr, SDValue &Base,
74 SDValue &Offset) const;
76 virtual bool selectIntAddrLSL2MM(SDValue Addr, SDValue &Base,
77 SDValue &Offset) const;
79 /// Match addr+simm10 and addr
80 virtual bool selectIntAddrMSA(SDValue Addr, SDValue &Base,
81 SDValue &Offset) const;
83 virtual bool selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
84 SDValue &Offset, SDValue &Alias);
86 /// \brief Select constant vector splats.
87 virtual bool selectVSplat(SDNode *N, APInt &Imm) const;
88 /// \brief Select constant vector splats whose value fits in a uimm1.
89 virtual bool selectVSplatUimm1(SDValue N, SDValue &Imm) const;
90 /// \brief Select constant vector splats whose value fits in a uimm2.
91 virtual bool selectVSplatUimm2(SDValue N, SDValue &Imm) const;
92 /// \brief Select constant vector splats whose value fits in a uimm3.
93 virtual bool selectVSplatUimm3(SDValue N, SDValue &Imm) const;
94 /// \brief Select constant vector splats whose value fits in a uimm4.
95 virtual bool selectVSplatUimm4(SDValue N, SDValue &Imm) const;
96 /// \brief Select constant vector splats whose value fits in a uimm5.
97 virtual bool selectVSplatUimm5(SDValue N, SDValue &Imm) const;
98 /// \brief Select constant vector splats whose value fits in a uimm6.
99 virtual bool selectVSplatUimm6(SDValue N, SDValue &Imm) const;
100 /// \brief Select constant vector splats whose value fits in a uimm8.
101 virtual bool selectVSplatUimm8(SDValue N, SDValue &Imm) const;
102 /// \brief Select constant vector splats whose value fits in a simm5.
103 virtual bool selectVSplatSimm5(SDValue N, SDValue &Imm) const;
104 /// \brief Select constant vector splats whose value is a power of 2.
105 virtual bool selectVSplatUimmPow2(SDValue N, SDValue &Imm) const;
106 /// \brief Select constant vector splats whose value is the inverse of a
108 virtual bool selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const;
109 /// \brief Select constant vector splats whose value is a run of set bits
110 /// ending at the most significant bit
111 virtual bool selectVSplatMaskL(SDValue N, SDValue &Imm) const;
112 /// \brief Select constant vector splats whose value is a run of set bits
113 /// starting at bit zero.
114 virtual bool selectVSplatMaskR(SDValue N, SDValue &Imm) const;
116 SDNode *Select(SDNode *N) override;
118 virtual std::pair<bool, SDNode*> selectNode(SDNode *Node) = 0;
120 // getImm - Return a target constant with the specified value.
121 inline SDValue getImm(const SDNode *Node, uint64_t Imm) {
122 return CurDAG->getTargetConstant(Imm, Node->getValueType(0));
125 virtual void processFunctionAfterISel(MachineFunction &MF) = 0;
127 bool SelectInlineAsmMemoryOperand(const SDValue &Op,
129 std::vector<SDValue> &OutOps) override;