blob: f99f3a1b3e0affe44c6d296419b025e04f244bd4 [file] [log] [blame]
Jia Liu9f610112012-02-17 08:55:11 +00001//===-- MipsISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips --------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00009//
10// This file defines an instruction selector for the MIPS target.
11//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000013
Akira Hatanaka30a84782013-03-14 18:27:31 +000014#include "MipsISelDAGToDAG.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "MCTargetDesc/MipsBaseInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000016#include "Mips.h"
17#include "Mips16ISelDAGToDAG.h"
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +000018#include "MipsMachineFunction.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000019#include "MipsRegisterInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000020#include "MipsSEISelDAGToDAG.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000021#include "llvm/CodeGen/MachineConstantPool.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000022#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000024#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattnera10fff52007-12-31 04:13:23 +000025#include "llvm/CodeGen/MachineRegisterInfo.h"
Akira Hatanaka330d9012012-02-28 02:55:02 +000026#include "llvm/CodeGen/SelectionDAGNodes.h"
Matthias Braun90ad6832018-07-13 00:08:38 +000027#include "llvm/CodeGen/StackProtector.h"
Chandler Carruth1305dc32014-03-04 11:45:46 +000028#include "llvm/IR/CFG.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000029#include "llvm/IR/GlobalValue.h"
30#include "llvm/IR/Instructions.h"
31#include "llvm/IR/Intrinsics.h"
32#include "llvm/IR/Type.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000033#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/Target/TargetMachine.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000037using namespace llvm;
38
Chandler Carruth84e68b22014-04-22 02:41:26 +000039#define DEBUG_TYPE "mips-isel"
40
Akira Hatanakae2489122011-04-15 21:51:11 +000041//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000042// Instruction Selector Implementation
Akira Hatanakae2489122011-04-15 21:51:11 +000043//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000044
Akira Hatanakae2489122011-04-15 21:51:11 +000045//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000046// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
47// instructions for SelectionDAG operations.
Akira Hatanakae2489122011-04-15 21:51:11 +000048//===----------------------------------------------------------------------===//
Akira Hatanaka0b2fa912012-03-08 01:51:59 +000049
Matthias Braun90ad6832018-07-13 00:08:38 +000050void MipsDAGToDAGISel::getAnalysisUsage(AnalysisUsage &AU) const {
51 // There are multiple MipsDAGToDAGISel instances added to the pass pipeline.
52 // We need to preserve StackProtector for the next one.
53 AU.addPreserved<StackProtector>();
54 SelectionDAGISel::getAnalysisUsage(AU);
55}
56
Akira Hatanakab049aef2012-02-24 22:34:47 +000057bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
Eric Christopher96e72c62015-01-29 23:27:36 +000058 Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget());
Akira Hatanakab049aef2012-02-24 22:34:47 +000059 bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
Jia Liuf54f60f2012-02-28 07:46:26 +000060
Akira Hatanaka040d2252013-03-14 18:33:23 +000061 processFunctionAfterISel(MF);
Akira Hatanakab049aef2012-02-24 22:34:47 +000062
63 return Ret;
64}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000065
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000066/// getGlobalBaseReg - Output the instructions required to put the
67/// GOT address into a register.
Dan Gohmand5ca70642009-06-03 20:30:14 +000068SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Akira Hatanakab049aef2012-02-24 22:34:47 +000069 unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
Mehdi Amini44ede332015-07-09 02:09:04 +000070 return CurDAG->getRegister(GlobalBaseReg, getTargetLowering()->getPointerTy(
71 CurDAG->getDataLayout()))
72 .getNode();
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000073}
74
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000075/// ComplexPattern used on MipsInstrInfo
76/// Used on Mips Load/Store instructions
Akira Hatanakaa35bc832013-02-16 00:14:37 +000077bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
78 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000079 llvm_unreachable("Unimplemented function.");
Akira Hatanaka69fb3d12013-02-15 21:20:45 +000080 return false;
81}
82
Akira Hatanakaa35bc832013-02-16 00:14:37 +000083bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
84 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000085 llvm_unreachable("Unimplemented function.");
86 return false;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000087}
88
Akira Hatanakaa35bc832013-02-16 00:14:37 +000089bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
90 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000091 llvm_unreachable("Unimplemented function.");
92 return false;
Akira Hatanaka69fb3d12013-02-15 21:20:45 +000093}
94
Zlatko Buljancba9f802016-07-11 07:41:56 +000095bool MipsDAGToDAGISel::selectIntAddr11MM(SDValue Addr, SDValue &Base,
96 SDValue &Offset) const {
97 llvm_unreachable("Unimplemented function.");
98 return false;
99}
100
101bool MipsDAGToDAGISel::selectIntAddr12MM(SDValue Addr, SDValue &Base,
102 SDValue &Offset) const {
103 llvm_unreachable("Unimplemented function.");
104 return false;
105}
106
107bool MipsDAGToDAGISel::selectIntAddr16MM(SDValue Addr, SDValue &Base,
Jack Carter97700972013-08-13 20:19:16 +0000108 SDValue &Offset) const {
109 llvm_unreachable("Unimplemented function.");
110 return false;
111}
112
Zoran Jovanovic5a1a7802015-02-04 15:43:17 +0000113bool MipsDAGToDAGISel::selectIntAddrLSL2MM(SDValue Addr, SDValue &Base,
114 SDValue &Offset) const {
115 llvm_unreachable("Unimplemented function.");
116 return false;
117}
118
Hrvoje Varga00d96ee2016-08-01 06:46:20 +0000119bool MipsDAGToDAGISel::selectIntAddrSImm10(SDValue Addr, SDValue &Base,
120 SDValue &Offset) const {
121 llvm_unreachable("Unimplemented function.");
122 return false;
123}
124
125bool MipsDAGToDAGISel::selectIntAddrSImm10Lsl1(SDValue Addr, SDValue &Base,
126 SDValue &Offset) const {
127 llvm_unreachable("Unimplemented function.");
128 return false;
129}
130
131bool MipsDAGToDAGISel::selectIntAddrSImm10Lsl2(SDValue Addr, SDValue &Base,
132 SDValue &Offset) const {
133 llvm_unreachable("Unimplemented function.");
134 return false;
135}
136
137bool MipsDAGToDAGISel::selectIntAddrSImm10Lsl3(SDValue Addr, SDValue &Base,
138 SDValue &Offset) const {
Daniel Sandersfa961d72014-03-03 14:31:21 +0000139 llvm_unreachable("Unimplemented function.");
140 return false;
141}
142
Daniel Sandersde7816b2016-06-16 10:20:59 +0000143bool MipsDAGToDAGISel::selectAddr16(SDValue Addr, SDValue &Base,
144 SDValue &Offset) {
145 llvm_unreachable("Unimplemented function.");
146 return false;
147}
148
149bool MipsDAGToDAGISel::selectAddr16SP(SDValue Addr, SDValue &Base,
150 SDValue &Offset) {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000151 llvm_unreachable("Unimplemented function.");
152 return false;
Reed Kotler3589dd72012-10-28 06:02:37 +0000153}
Akira Hatanakacb2a85b2011-12-20 23:10:57 +0000154
Daniel Sandersc8cd58f2015-05-19 12:24:52 +0000155bool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm,
156 unsigned MinSizeInBits) const {
Daniel Sandersf49dd822013-09-24 13:33:07 +0000157 llvm_unreachable("Unimplemented function.");
158 return false;
159}
160
Daniel Sanders7e51fe12013-09-27 11:48:57 +0000161bool MipsDAGToDAGISel::selectVSplatUimm1(SDValue N, SDValue &Imm) const {
162 llvm_unreachable("Unimplemented function.");
163 return false;
164}
165
166bool MipsDAGToDAGISel::selectVSplatUimm2(SDValue N, SDValue &Imm) const {
167 llvm_unreachable("Unimplemented function.");
168 return false;
169}
170
Daniel Sandersf49dd822013-09-24 13:33:07 +0000171bool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const {
172 llvm_unreachable("Unimplemented function.");
173 return false;
174}
175
176bool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const {
177 llvm_unreachable("Unimplemented function.");
178 return false;
179}
180
181bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const {
182 llvm_unreachable("Unimplemented function.");
183 return false;
184}
185
186bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const {
187 llvm_unreachable("Unimplemented function.");
188 return false;
189}
190
191bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const {
192 llvm_unreachable("Unimplemented function.");
193 return false;
194}
195
196bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const {
197 llvm_unreachable("Unimplemented function.");
198 return false;
199}
200
201bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const {
202 llvm_unreachable("Unimplemented function.");
203 return false;
204}
205
Daniel Sanders3f6eb542013-11-12 10:45:18 +0000206bool MipsDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const {
207 llvm_unreachable("Unimplemented function.");
208 return false;
209}
210
Daniel Sandersd74b1302013-10-30 14:45:14 +0000211bool MipsDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const {
212 llvm_unreachable("Unimplemented function.");
213 return false;
214}
215
216bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
217 llvm_unreachable("Unimplemented function.");
218 return false;
219}
220
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000221/// Select instructions not customized! Used for
222/// expanded, promoted and normal instructions
Justin Bognereeae7512016-05-13 23:55:59 +0000223void MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000224 unsigned Opcode = Node->getOpcode();
225
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000226 // If we have a custom node, we already have selected!
Dan Gohman17059682008-07-17 19:10:17 +0000227 if (Node->isMachineOpcode()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000228 LLVM_DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Tim Northover31d093c2013-09-22 08:21:56 +0000229 Node->setNodeId(-1);
Justin Bognereeae7512016-05-13 23:55:59 +0000230 return;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000231 }
232
Akira Hatanaka30a84782013-03-14 18:27:31 +0000233 // See if subclasses can handle this node.
Justin Bognereeae7512016-05-13 23:55:59 +0000234 if (trySelect(Node))
235 return;
Akira Hatanakacb2a85b2011-12-20 23:10:57 +0000236
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000237 switch(Opcode) {
Akira Hatanaka2c8d17342011-12-20 22:58:01 +0000238 default: break;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000239
Akira Hatanaka2c8d17342011-12-20 22:58:01 +0000240 // Get target GOT address.
241 case ISD::GLOBAL_OFFSET_TABLE:
Justin Bognereeae7512016-05-13 23:55:59 +0000242 ReplaceNode(Node, getGlobalBaseReg());
243 return;
Akira Hatanakadee6c822011-12-08 20:34:32 +0000244
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000245#ifndef NDEBUG
246 case ISD::LOAD:
247 case ISD::STORE:
Eric Christopher22405e42014-07-10 17:26:51 +0000248 assert((Subtarget->systemSupportsUnalignedAccess() ||
Daniel Sandersac272632014-05-23 13:18:02 +0000249 cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
250 cast<MemSDNode>(Node)->getAlignment()) &&
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000251 "Unexpected unaligned loads/stores.");
252 break;
253#endif
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000254 }
255
256 // Select the default instruction
Justin Bognereeae7512016-05-13 23:55:59 +0000257 SelectCode(Node);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000258}
259
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000260bool MipsDAGToDAGISel::
Daniel Sanders60f1db02015-03-13 12:45:09 +0000261SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID,
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000262 std::vector<SDValue> &OutOps) {
Daniel Sandersa73d8fe2015-03-24 11:26:34 +0000263 // All memory constraints can at least accept raw pointers.
264 switch(ConstraintID) {
265 default:
266 llvm_unreachable("Unexpected asm memory constraint");
267 case InlineAsm::Constraint_i:
268 case InlineAsm::Constraint_m:
269 case InlineAsm::Constraint_R:
270 case InlineAsm::Constraint_ZC:
271 OutOps.push_back(Op);
272 return false;
273 }
274 return true;
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000275}