blob: 9ba54d6bb73ca708f23b2bdf04a9d23f5d6e91b5 [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00006//
Akira Hatanakae2489122011-04-15 21:51:11 +00007//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00008//
9// This file defines an instruction selector for the MIPS target.
10//
Akira Hatanakae2489122011-04-15 21:51:11 +000011//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000012
Akira Hatanaka30a84782013-03-14 18:27:31 +000013#include "MipsISelDAGToDAG.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/MipsBaseInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000015#include "Mips.h"
16#include "Mips16ISelDAGToDAG.h"
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +000017#include "MipsMachineFunction.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000018#include "MipsRegisterInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000019#include "MipsSEISelDAGToDAG.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000020#include "llvm/CodeGen/MachineConstantPool.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000023#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattnera10fff52007-12-31 04:13:23 +000024#include "llvm/CodeGen/MachineRegisterInfo.h"
Akira Hatanaka330d9012012-02-28 02:55:02 +000025#include "llvm/CodeGen/SelectionDAGNodes.h"
Matthias Braun90ad6832018-07-13 00:08:38 +000026#include "llvm/CodeGen/StackProtector.h"
Chandler Carruth1305dc32014-03-04 11:45:46 +000027#include "llvm/IR/CFG.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000028#include "llvm/IR/GlobalValue.h"
29#include "llvm/IR/Instructions.h"
30#include "llvm/IR/Intrinsics.h"
31#include "llvm/IR/Type.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000032#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000035#include "llvm/Target/TargetMachine.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000036using namespace llvm;
37
Chandler Carruth84e68b22014-04-22 02:41:26 +000038#define DEBUG_TYPE "mips-isel"
39
Akira Hatanakae2489122011-04-15 21:51:11 +000040//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000041// Instruction Selector Implementation
Akira Hatanakae2489122011-04-15 21:51:11 +000042//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000043
Akira Hatanakae2489122011-04-15 21:51:11 +000044//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000045// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
46// instructions for SelectionDAG operations.
Akira Hatanakae2489122011-04-15 21:51:11 +000047//===----------------------------------------------------------------------===//
Akira Hatanaka0b2fa912012-03-08 01:51:59 +000048
Matthias Braun90ad6832018-07-13 00:08:38 +000049void MipsDAGToDAGISel::getAnalysisUsage(AnalysisUsage &AU) const {
50 // There are multiple MipsDAGToDAGISel instances added to the pass pipeline.
51 // We need to preserve StackProtector for the next one.
52 AU.addPreserved<StackProtector>();
53 SelectionDAGISel::getAnalysisUsage(AU);
54}
55
Akira Hatanakab049aef2012-02-24 22:34:47 +000056bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
Eric Christopher96e72c62015-01-29 23:27:36 +000057 Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget());
Akira Hatanakab049aef2012-02-24 22:34:47 +000058 bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
Jia Liuf54f60f2012-02-28 07:46:26 +000059
Akira Hatanaka040d2252013-03-14 18:33:23 +000060 processFunctionAfterISel(MF);
Akira Hatanakab049aef2012-02-24 22:34:47 +000061
62 return Ret;
63}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000064
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000065/// getGlobalBaseReg - Output the instructions required to put the
66/// GOT address into a register.
Dan Gohmand5ca70642009-06-03 20:30:14 +000067SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Akira Hatanakab049aef2012-02-24 22:34:47 +000068 unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
Mehdi Amini44ede332015-07-09 02:09:04 +000069 return CurDAG->getRegister(GlobalBaseReg, getTargetLowering()->getPointerTy(
70 CurDAG->getDataLayout()))
71 .getNode();
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000072}
73
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000074/// ComplexPattern used on MipsInstrInfo
75/// Used on Mips Load/Store instructions
Akira Hatanakaa35bc832013-02-16 00:14:37 +000076bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
77 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000078 llvm_unreachable("Unimplemented function.");
Akira Hatanaka69fb3d12013-02-15 21:20:45 +000079 return false;
80}
81
Akira Hatanakaa35bc832013-02-16 00:14:37 +000082bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
83 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000084 llvm_unreachable("Unimplemented function.");
85 return false;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000086}
87
Akira Hatanakaa35bc832013-02-16 00:14:37 +000088bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
89 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000090 llvm_unreachable("Unimplemented function.");
91 return false;
Akira Hatanaka69fb3d12013-02-15 21:20:45 +000092}
93
Zlatko Buljancba9f802016-07-11 07:41:56 +000094bool MipsDAGToDAGISel::selectIntAddr11MM(SDValue Addr, SDValue &Base,
95 SDValue &Offset) const {
96 llvm_unreachable("Unimplemented function.");
97 return false;
98}
99
100bool MipsDAGToDAGISel::selectIntAddr12MM(SDValue Addr, SDValue &Base,
101 SDValue &Offset) const {
102 llvm_unreachable("Unimplemented function.");
103 return false;
104}
105
106bool MipsDAGToDAGISel::selectIntAddr16MM(SDValue Addr, SDValue &Base,
Jack Carter97700972013-08-13 20:19:16 +0000107 SDValue &Offset) const {
108 llvm_unreachable("Unimplemented function.");
109 return false;
110}
111
Zoran Jovanovic5a1a7802015-02-04 15:43:17 +0000112bool MipsDAGToDAGISel::selectIntAddrLSL2MM(SDValue Addr, SDValue &Base,
113 SDValue &Offset) const {
114 llvm_unreachable("Unimplemented function.");
115 return false;
116}
117
Hrvoje Varga00d96ee2016-08-01 06:46:20 +0000118bool MipsDAGToDAGISel::selectIntAddrSImm10(SDValue Addr, SDValue &Base,
119 SDValue &Offset) const {
120 llvm_unreachable("Unimplemented function.");
121 return false;
122}
123
124bool MipsDAGToDAGISel::selectIntAddrSImm10Lsl1(SDValue Addr, SDValue &Base,
125 SDValue &Offset) const {
126 llvm_unreachable("Unimplemented function.");
127 return false;
128}
129
130bool MipsDAGToDAGISel::selectIntAddrSImm10Lsl2(SDValue Addr, SDValue &Base,
131 SDValue &Offset) const {
132 llvm_unreachable("Unimplemented function.");
133 return false;
134}
135
136bool MipsDAGToDAGISel::selectIntAddrSImm10Lsl3(SDValue Addr, SDValue &Base,
137 SDValue &Offset) const {
Daniel Sandersfa961d72014-03-03 14:31:21 +0000138 llvm_unreachable("Unimplemented function.");
139 return false;
140}
141
Daniel Sandersde7816b2016-06-16 10:20:59 +0000142bool MipsDAGToDAGISel::selectAddr16(SDValue Addr, SDValue &Base,
143 SDValue &Offset) {
144 llvm_unreachable("Unimplemented function.");
145 return false;
146}
147
148bool MipsDAGToDAGISel::selectAddr16SP(SDValue Addr, SDValue &Base,
149 SDValue &Offset) {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000150 llvm_unreachable("Unimplemented function.");
151 return false;
Reed Kotler3589dd72012-10-28 06:02:37 +0000152}
Akira Hatanakacb2a85b2011-12-20 23:10:57 +0000153
Daniel Sandersc8cd58f2015-05-19 12:24:52 +0000154bool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm,
155 unsigned MinSizeInBits) const {
Daniel Sandersf49dd822013-09-24 13:33:07 +0000156 llvm_unreachable("Unimplemented function.");
157 return false;
158}
159
Daniel Sanders7e51fe12013-09-27 11:48:57 +0000160bool MipsDAGToDAGISel::selectVSplatUimm1(SDValue N, SDValue &Imm) const {
161 llvm_unreachable("Unimplemented function.");
162 return false;
163}
164
165bool MipsDAGToDAGISel::selectVSplatUimm2(SDValue N, SDValue &Imm) const {
166 llvm_unreachable("Unimplemented function.");
167 return false;
168}
169
Daniel Sandersf49dd822013-09-24 13:33:07 +0000170bool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const {
171 llvm_unreachable("Unimplemented function.");
172 return false;
173}
174
175bool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const {
176 llvm_unreachable("Unimplemented function.");
177 return false;
178}
179
180bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const {
181 llvm_unreachable("Unimplemented function.");
182 return false;
183}
184
185bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const {
186 llvm_unreachable("Unimplemented function.");
187 return false;
188}
189
190bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const {
191 llvm_unreachable("Unimplemented function.");
192 return false;
193}
194
195bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const {
196 llvm_unreachable("Unimplemented function.");
197 return false;
198}
199
200bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const {
201 llvm_unreachable("Unimplemented function.");
202 return false;
203}
204
Daniel Sanders3f6eb542013-11-12 10:45:18 +0000205bool MipsDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const {
206 llvm_unreachable("Unimplemented function.");
207 return false;
208}
209
Daniel Sandersd74b1302013-10-30 14:45:14 +0000210bool MipsDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const {
211 llvm_unreachable("Unimplemented function.");
212 return false;
213}
214
215bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
216 llvm_unreachable("Unimplemented function.");
217 return false;
218}
219
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000220/// Select instructions not customized! Used for
221/// expanded, promoted and normal instructions
Justin Bognereeae7512016-05-13 23:55:59 +0000222void MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000223 unsigned Opcode = Node->getOpcode();
224
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000225 // If we have a custom node, we already have selected!
Dan Gohman17059682008-07-17 19:10:17 +0000226 if (Node->isMachineOpcode()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000227 LLVM_DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Tim Northover31d093c2013-09-22 08:21:56 +0000228 Node->setNodeId(-1);
Justin Bognereeae7512016-05-13 23:55:59 +0000229 return;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000230 }
231
Akira Hatanaka30a84782013-03-14 18:27:31 +0000232 // See if subclasses can handle this node.
Justin Bognereeae7512016-05-13 23:55:59 +0000233 if (trySelect(Node))
234 return;
Akira Hatanakacb2a85b2011-12-20 23:10:57 +0000235
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000236 switch(Opcode) {
Akira Hatanaka2c8d17342011-12-20 22:58:01 +0000237 default: break;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000238
Akira Hatanaka2c8d17342011-12-20 22:58:01 +0000239 // Get target GOT address.
240 case ISD::GLOBAL_OFFSET_TABLE:
Justin Bognereeae7512016-05-13 23:55:59 +0000241 ReplaceNode(Node, getGlobalBaseReg());
242 return;
Akira Hatanakadee6c822011-12-08 20:34:32 +0000243
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000244#ifndef NDEBUG
245 case ISD::LOAD:
246 case ISD::STORE:
Eric Christopher22405e42014-07-10 17:26:51 +0000247 assert((Subtarget->systemSupportsUnalignedAccess() ||
Daniel Sandersac272632014-05-23 13:18:02 +0000248 cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
249 cast<MemSDNode>(Node)->getAlignment()) &&
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000250 "Unexpected unaligned loads/stores.");
251 break;
252#endif
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000253 }
254
255 // Select the default instruction
Justin Bognereeae7512016-05-13 23:55:59 +0000256 SelectCode(Node);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000257}
258
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000259bool MipsDAGToDAGISel::
Daniel Sanders60f1db02015-03-13 12:45:09 +0000260SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID,
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000261 std::vector<SDValue> &OutOps) {
Daniel Sandersa73d8fe2015-03-24 11:26:34 +0000262 // All memory constraints can at least accept raw pointers.
263 switch(ConstraintID) {
264 default:
265 llvm_unreachable("Unexpected asm memory constraint");
266 case InlineAsm::Constraint_i:
267 case InlineAsm::Constraint_m:
268 case InlineAsm::Constraint_R:
269 case InlineAsm::Constraint_ZC:
270 OutOps.push_back(Op);
271 return false;
272 }
273 return true;
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000274}