blob: ff8760da3fa6219c67e07fd05f4f56bdb408b373 [file] [log] [blame]
Akira Hatanaka29a0da32013-03-14 18:28:19 +00001//===---- MipsISelDAGToDAG.h - A Dag to Dag Inst Selector for Mips --------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the MIPS target.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_MIPS_MIPSISELDAGTODAG_H
15#define LLVM_LIB_TARGET_MIPS_MIPSISELDAGTODAG_H
Akira Hatanaka29a0da32013-03-14 18:28:19 +000016
17#include "Mips.h"
18#include "MipsSubtarget.h"
19#include "MipsTargetMachine.h"
20#include "llvm/CodeGen/SelectionDAGISel.h"
21
22//===----------------------------------------------------------------------===//
23// Instruction Selector Implementation
24//===----------------------------------------------------------------------===//
25
26//===----------------------------------------------------------------------===//
27// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
28// instructions for SelectionDAG operations.
29//===----------------------------------------------------------------------===//
30namespace llvm {
31
32class MipsDAGToDAGISel : public SelectionDAGISel {
33public:
34 explicit MipsDAGToDAGISel(MipsTargetMachine &TM)
Eric Christopher4e7d1e72014-07-18 23:41:32 +000035 : SelectionDAGISel(TM), Subtarget(nullptr) {}
Akira Hatanaka29a0da32013-03-14 18:28:19 +000036
37 // Pass Name
Craig Topper56c590a2014-04-29 07:58:02 +000038 const char *getPassName() const override {
Akira Hatanaka29a0da32013-03-14 18:28:19 +000039 return "MIPS DAG->DAG Pattern Instruction Selection";
40 }
41
Craig Topper56c590a2014-04-29 07:58:02 +000042 bool runOnMachineFunction(MachineFunction &MF) override;
Akira Hatanaka29a0da32013-03-14 18:28:19 +000043
44protected:
45 SDNode *getGlobalBaseReg();
46
47 /// Keep a pointer to the MipsSubtarget around so that we can make the right
48 /// decision when generating code for different targets.
Eric Christopher22405e42014-07-10 17:26:51 +000049 const MipsSubtarget *Subtarget;
Akira Hatanaka29a0da32013-03-14 18:28:19 +000050
51private:
52 // Include the pieces autogenerated from the target description.
53 #include "MipsGenDAGISel.inc"
54
55 // Complex Pattern.
56 /// (reg + imm).
57 virtual bool selectAddrRegImm(SDValue Addr, SDValue &Base,
58 SDValue &Offset) const;
59
Daniel Sanderse6ed5b72013-08-28 12:04:29 +000060 // Complex Pattern.
61 /// (reg + reg).
62 virtual bool selectAddrRegReg(SDValue Addr, SDValue &Base,
63 SDValue &Offset) const;
64
Akira Hatanaka29a0da32013-03-14 18:28:19 +000065 /// Fall back on this function if all else fails.
66 virtual bool selectAddrDefault(SDValue Addr, SDValue &Base,
67 SDValue &Offset) const;
68
69 /// Match integer address pattern.
70 virtual bool selectIntAddr(SDValue Addr, SDValue &Base,
71 SDValue &Offset) const;
72
Jack Carter97700972013-08-13 20:19:16 +000073 virtual bool selectIntAddrMM(SDValue Addr, SDValue &Base,
74 SDValue &Offset) const;
75
Daniel Sandersfa961d72014-03-03 14:31:21 +000076 /// Match addr+simm10 and addr
77 virtual bool selectIntAddrMSA(SDValue Addr, SDValue &Base,
78 SDValue &Offset) const;
79
Akira Hatanaka040d2252013-03-14 18:33:23 +000080 virtual bool selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
Akira Hatanaka29a0da32013-03-14 18:28:19 +000081 SDValue &Offset, SDValue &Alias);
82
Daniel Sandersf49dd822013-09-24 13:33:07 +000083 /// \brief Select constant vector splats.
84 virtual bool selectVSplat(SDNode *N, APInt &Imm) const;
Daniel Sanders7e51fe12013-09-27 11:48:57 +000085 /// \brief Select constant vector splats whose value fits in a uimm1.
86 virtual bool selectVSplatUimm1(SDValue N, SDValue &Imm) const;
87 /// \brief Select constant vector splats whose value fits in a uimm2.
88 virtual bool selectVSplatUimm2(SDValue N, SDValue &Imm) const;
Daniel Sandersf49dd822013-09-24 13:33:07 +000089 /// \brief Select constant vector splats whose value fits in a uimm3.
90 virtual bool selectVSplatUimm3(SDValue N, SDValue &Imm) const;
91 /// \brief Select constant vector splats whose value fits in a uimm4.
92 virtual bool selectVSplatUimm4(SDValue N, SDValue &Imm) const;
93 /// \brief Select constant vector splats whose value fits in a uimm5.
94 virtual bool selectVSplatUimm5(SDValue N, SDValue &Imm) const;
95 /// \brief Select constant vector splats whose value fits in a uimm6.
96 virtual bool selectVSplatUimm6(SDValue N, SDValue &Imm) const;
97 /// \brief Select constant vector splats whose value fits in a uimm8.
98 virtual bool selectVSplatUimm8(SDValue N, SDValue &Imm) const;
99 /// \brief Select constant vector splats whose value fits in a simm5.
100 virtual bool selectVSplatSimm5(SDValue N, SDValue &Imm) const;
101 /// \brief Select constant vector splats whose value is a power of 2.
102 virtual bool selectVSplatUimmPow2(SDValue N, SDValue &Imm) const;
Daniel Sanders3f6eb542013-11-12 10:45:18 +0000103 /// \brief Select constant vector splats whose value is the inverse of a
104 /// power of 2.
105 virtual bool selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const;
Daniel Sandersd74b1302013-10-30 14:45:14 +0000106 /// \brief Select constant vector splats whose value is a run of set bits
107 /// ending at the most significant bit
108 virtual bool selectVSplatMaskL(SDValue N, SDValue &Imm) const;
109 /// \brief Select constant vector splats whose value is a run of set bits
110 /// starting at bit zero.
111 virtual bool selectVSplatMaskR(SDValue N, SDValue &Imm) const;
Daniel Sandersf49dd822013-09-24 13:33:07 +0000112
Craig Topper56c590a2014-04-29 07:58:02 +0000113 SDNode *Select(SDNode *N) override;
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000114
Akira Hatanaka040d2252013-03-14 18:33:23 +0000115 virtual std::pair<bool, SDNode*> selectNode(SDNode *Node) = 0;
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000116
117 // getImm - Return a target constant with the specified value.
118 inline SDValue getImm(const SDNode *Node, uint64_t Imm) {
119 return CurDAG->getTargetConstant(Imm, Node->getValueType(0));
120 }
121
Akira Hatanaka040d2252013-03-14 18:33:23 +0000122 virtual void processFunctionAfterISel(MachineFunction &MF) = 0;
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000123
Craig Topper56c590a2014-04-29 07:58:02 +0000124 bool SelectInlineAsmMemoryOperand(const SDValue &Op,
125 char ConstraintCode,
126 std::vector<SDValue> &OutOps) override;
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000127};
128
129/// createMipsISelDag - This pass converts a legalized DAG into a
130/// MIPS-specific DAG, ready for instruction scheduling.
131FunctionPass *createMipsISelDag(MipsTargetMachine &TM);
132
133}
134
135#endif