blob: 09003459d180eb707d68afca95b7e0e1b863e4df [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:
Daniel Sanders46fe6552016-07-14 13:25:22 +000034 explicit MipsDAGToDAGISel(MipsTargetMachine &TM, CodeGenOpt::Level OL)
35 : SelectionDAGISel(TM, OL), Subtarget(nullptr) {}
Akira Hatanaka29a0da32013-03-14 18:28:19 +000036
37 // Pass Name
Mehdi Amini117296c2016-10-01 02:56:57 +000038 StringRef 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
Matthias Braun90ad6832018-07-13 00:08:38 +000044 void getAnalysisUsage(AnalysisUsage &AU) const override;
45
Akira Hatanaka29a0da32013-03-14 18:28:19 +000046protected:
47 SDNode *getGlobalBaseReg();
48
49 /// Keep a pointer to the MipsSubtarget around so that we can make the right
50 /// decision when generating code for different targets.
Eric Christopher22405e42014-07-10 17:26:51 +000051 const MipsSubtarget *Subtarget;
Akira Hatanaka29a0da32013-03-14 18:28:19 +000052
53private:
54 // Include the pieces autogenerated from the target description.
55 #include "MipsGenDAGISel.inc"
56
57 // Complex Pattern.
58 /// (reg + imm).
59 virtual bool selectAddrRegImm(SDValue Addr, SDValue &Base,
60 SDValue &Offset) const;
61
62 /// Fall back on this function if all else fails.
63 virtual bool selectAddrDefault(SDValue Addr, SDValue &Base,
64 SDValue &Offset) const;
65
66 /// Match integer address pattern.
67 virtual bool selectIntAddr(SDValue Addr, SDValue &Base,
68 SDValue &Offset) const;
69
Zlatko Buljancba9f802016-07-11 07:41:56 +000070 virtual bool selectIntAddr11MM(SDValue Addr, SDValue &Base,
71 SDValue &Offset) const;
72
73 virtual bool selectIntAddr12MM(SDValue Addr, SDValue &Base,
Jack Carter97700972013-08-13 20:19:16 +000074 SDValue &Offset) const;
75
Zlatko Buljancba9f802016-07-11 07:41:56 +000076 virtual bool selectIntAddr16MM(SDValue Addr, SDValue &Base,
77 SDValue &Offset) const;
78
Zoran Jovanovic5a1a7802015-02-04 15:43:17 +000079 virtual bool selectIntAddrLSL2MM(SDValue Addr, SDValue &Base,
80 SDValue &Offset) const;
81
Daniel Sandersfa961d72014-03-03 14:31:21 +000082 /// Match addr+simm10 and addr
Hrvoje Varga00d96ee2016-08-01 06:46:20 +000083 virtual bool selectIntAddrSImm10(SDValue Addr, SDValue &Base,
84 SDValue &Offset) const;
85
86 virtual bool selectIntAddrSImm10Lsl1(SDValue Addr, SDValue &Base,
87 SDValue &Offset) const;
88
89 virtual bool selectIntAddrSImm10Lsl2(SDValue Addr, SDValue &Base,
90 SDValue &Offset) const;
91
92 virtual bool selectIntAddrSImm10Lsl3(SDValue Addr, SDValue &Base,
93 SDValue &Offset) const;
Daniel Sandersfa961d72014-03-03 14:31:21 +000094
Daniel Sandersde7816b2016-06-16 10:20:59 +000095 virtual bool selectAddr16(SDValue Addr, SDValue &Base, SDValue &Offset);
96 virtual bool selectAddr16SP(SDValue Addr, SDValue &Base, SDValue &Offset);
Akira Hatanaka29a0da32013-03-14 18:28:19 +000097
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000098 /// Select constant vector splats.
Daniel Sandersc8cd58f2015-05-19 12:24:52 +000099 virtual bool selectVSplat(SDNode *N, APInt &Imm,
100 unsigned MinSizeInBits) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000101 /// Select constant vector splats whose value fits in a uimm1.
Daniel Sanders7e51fe12013-09-27 11:48:57 +0000102 virtual bool selectVSplatUimm1(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000103 /// Select constant vector splats whose value fits in a uimm2.
Daniel Sanders7e51fe12013-09-27 11:48:57 +0000104 virtual bool selectVSplatUimm2(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000105 /// Select constant vector splats whose value fits in a uimm3.
Daniel Sandersf49dd822013-09-24 13:33:07 +0000106 virtual bool selectVSplatUimm3(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000107 /// Select constant vector splats whose value fits in a uimm4.
Daniel Sandersf49dd822013-09-24 13:33:07 +0000108 virtual bool selectVSplatUimm4(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000109 /// Select constant vector splats whose value fits in a uimm5.
Daniel Sandersf49dd822013-09-24 13:33:07 +0000110 virtual bool selectVSplatUimm5(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000111 /// Select constant vector splats whose value fits in a uimm6.
Daniel Sandersf49dd822013-09-24 13:33:07 +0000112 virtual bool selectVSplatUimm6(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000113 /// Select constant vector splats whose value fits in a uimm8.
Daniel Sandersf49dd822013-09-24 13:33:07 +0000114 virtual bool selectVSplatUimm8(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000115 /// Select constant vector splats whose value fits in a simm5.
Daniel Sandersf49dd822013-09-24 13:33:07 +0000116 virtual bool selectVSplatSimm5(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000117 /// Select constant vector splats whose value is a power of 2.
Daniel Sandersf49dd822013-09-24 13:33:07 +0000118 virtual bool selectVSplatUimmPow2(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000119 /// Select constant vector splats whose value is the inverse of a
Daniel Sanders3f6eb542013-11-12 10:45:18 +0000120 /// power of 2.
121 virtual bool selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000122 /// Select constant vector splats whose value is a run of set bits
Daniel Sandersd74b1302013-10-30 14:45:14 +0000123 /// ending at the most significant bit
124 virtual bool selectVSplatMaskL(SDValue N, SDValue &Imm) const;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000125 /// Select constant vector splats whose value is a run of set bits
Daniel Sandersd74b1302013-10-30 14:45:14 +0000126 /// starting at bit zero.
127 virtual bool selectVSplatMaskR(SDValue N, SDValue &Imm) const;
Daniel Sandersf49dd822013-09-24 13:33:07 +0000128
Justin Bognereeae7512016-05-13 23:55:59 +0000129 void Select(SDNode *N) override;
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000130
Justin Bognereeae7512016-05-13 23:55:59 +0000131 virtual bool trySelect(SDNode *Node) = 0;
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000132
133 // getImm - Return a target constant with the specified value.
134 inline SDValue getImm(const SDNode *Node, uint64_t Imm) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000135 return CurDAG->getTargetConstant(Imm, SDLoc(Node), Node->getValueType(0));
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000136 }
137
Akira Hatanaka040d2252013-03-14 18:33:23 +0000138 virtual void processFunctionAfterISel(MachineFunction &MF) = 0;
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000139
Craig Topper56c590a2014-04-29 07:58:02 +0000140 bool SelectInlineAsmMemoryOperand(const SDValue &Op,
Daniel Sanders60f1db02015-03-13 12:45:09 +0000141 unsigned ConstraintID,
Craig Topper56c590a2014-04-29 07:58:02 +0000142 std::vector<SDValue> &OutOps) override;
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000143};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000144}
Akira Hatanaka29a0da32013-03-14 18:28:19 +0000145
146#endif