blob: 90cff631931f69134e898192b777af1a38d5c92f [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"
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
Akira Hatanakab049aef2012-02-24 22:34:47 +000049bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
50 bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
Jia Liuf54f60f2012-02-28 07:46:26 +000051
Akira Hatanaka040d2252013-03-14 18:33:23 +000052 processFunctionAfterISel(MF);
Akira Hatanakab049aef2012-02-24 22:34:47 +000053
54 return Ret;
55}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000056
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000057/// getGlobalBaseReg - Output the instructions required to put the
58/// GOT address into a register.
Dan Gohmand5ca70642009-06-03 20:30:14 +000059SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Akira Hatanakab049aef2012-02-24 22:34:47 +000060 unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
Bill Wendlinga3cd3502013-06-19 21:36:55 +000061 return CurDAG->getRegister(GlobalBaseReg,
62 getTargetLowering()->getPointerTy()).getNode();
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000063}
64
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000065/// ComplexPattern used on MipsInstrInfo
66/// Used on Mips Load/Store instructions
Akira Hatanakaa35bc832013-02-16 00:14:37 +000067bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
68 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000069 llvm_unreachable("Unimplemented function.");
Akira Hatanaka69fb3d12013-02-15 21:20:45 +000070 return false;
71}
72
Daniel Sanderse6ed5b72013-08-28 12:04:29 +000073bool MipsDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base,
74 SDValue &Offset) const {
75 llvm_unreachable("Unimplemented function.");
76 return false;
77}
78
Akira Hatanakaa35bc832013-02-16 00:14:37 +000079bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
80 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000081 llvm_unreachable("Unimplemented function.");
82 return false;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000083}
84
Akira Hatanakaa35bc832013-02-16 00:14:37 +000085bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
86 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000087 llvm_unreachable("Unimplemented function.");
88 return false;
Akira Hatanaka69fb3d12013-02-15 21:20:45 +000089}
90
Jack Carter97700972013-08-13 20:19:16 +000091bool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base,
92 SDValue &Offset) const {
93 llvm_unreachable("Unimplemented function.");
94 return false;
95}
96
Daniel Sandersfa961d72014-03-03 14:31:21 +000097bool MipsDAGToDAGISel::selectIntAddrMSA(SDValue Addr, SDValue &Base,
98 SDValue &Offset) const {
99 llvm_unreachable("Unimplemented function.");
100 return false;
101}
102
Akira Hatanaka040d2252013-03-14 18:33:23 +0000103bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
Akira Hatanaka30a84782013-03-14 18:27:31 +0000104 SDValue &Offset, SDValue &Alias) {
105 llvm_unreachable("Unimplemented function.");
106 return false;
Reed Kotler3589dd72012-10-28 06:02:37 +0000107}
Akira Hatanakacb2a85b2011-12-20 23:10:57 +0000108
Daniel Sandersf49dd822013-09-24 13:33:07 +0000109bool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm) const {
110 llvm_unreachable("Unimplemented function.");
111 return false;
112}
113
Daniel Sanders7e51fe12013-09-27 11:48:57 +0000114bool MipsDAGToDAGISel::selectVSplatUimm1(SDValue N, SDValue &Imm) const {
115 llvm_unreachable("Unimplemented function.");
116 return false;
117}
118
119bool MipsDAGToDAGISel::selectVSplatUimm2(SDValue N, SDValue &Imm) const {
120 llvm_unreachable("Unimplemented function.");
121 return false;
122}
123
Daniel Sandersf49dd822013-09-24 13:33:07 +0000124bool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const {
125 llvm_unreachable("Unimplemented function.");
126 return false;
127}
128
129bool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const {
130 llvm_unreachable("Unimplemented function.");
131 return false;
132}
133
134bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const {
135 llvm_unreachable("Unimplemented function.");
136 return false;
137}
138
139bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const {
140 llvm_unreachable("Unimplemented function.");
141 return false;
142}
143
144bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const {
145 llvm_unreachable("Unimplemented function.");
146 return false;
147}
148
149bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const {
150 llvm_unreachable("Unimplemented function.");
151 return false;
152}
153
154bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const {
155 llvm_unreachable("Unimplemented function.");
156 return false;
157}
158
Daniel Sanders3f6eb542013-11-12 10:45:18 +0000159bool MipsDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const {
160 llvm_unreachable("Unimplemented function.");
161 return false;
162}
163
Daniel Sandersd74b1302013-10-30 14:45:14 +0000164bool MipsDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const {
165 llvm_unreachable("Unimplemented function.");
166 return false;
167}
168
169bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
170 llvm_unreachable("Unimplemented function.");
171 return false;
172}
173
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000174/// Select instructions not customized! Used for
175/// expanded, promoted and normal instructions
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000176SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000177 unsigned Opcode = Node->getOpcode();
178
179 // Dump information about the Node being selected
Chris Lattnerf98f1242010-03-02 06:34:30 +0000180 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000181
182 // If we have a custom node, we already have selected!
Dan Gohman17059682008-07-17 19:10:17 +0000183 if (Node->isMachineOpcode()) {
Chris Lattnerf98f1242010-03-02 06:34:30 +0000184 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Tim Northover31d093c2013-09-22 08:21:56 +0000185 Node->setNodeId(-1);
Craig Topper062a2ba2014-04-25 05:30:21 +0000186 return nullptr;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000187 }
188
Akira Hatanaka30a84782013-03-14 18:27:31 +0000189 // See if subclasses can handle this node.
Akira Hatanaka040d2252013-03-14 18:33:23 +0000190 std::pair<bool, SDNode*> Ret = selectNode(Node);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000191
192 if (Ret.first)
193 return Ret.second;
Akira Hatanakacb2a85b2011-12-20 23:10:57 +0000194
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000195 switch(Opcode) {
Akira Hatanaka2c8d17342011-12-20 22:58:01 +0000196 default: break;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000197
Akira Hatanaka2c8d17342011-12-20 22:58:01 +0000198 // Get target GOT address.
199 case ISD::GLOBAL_OFFSET_TABLE:
200 return getGlobalBaseReg();
Akira Hatanakadee6c822011-12-08 20:34:32 +0000201
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000202#ifndef NDEBUG
203 case ISD::LOAD:
204 case ISD::STORE:
Daniel Sandersac272632014-05-23 13:18:02 +0000205 assert((Subtarget.systemSupportsUnalignedAccess() ||
206 cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
207 cast<MemSDNode>(Node)->getAlignment()) &&
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000208 "Unexpected unaligned loads/stores.");
209 break;
210#endif
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000211 }
212
213 // Select the default instruction
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000214 SDNode *ResNode = SelectCode(Node);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000215
Chris Lattnerf98f1242010-03-02 06:34:30 +0000216 DEBUG(errs() << "=> ");
Craig Topper062a2ba2014-04-25 05:30:21 +0000217 if (ResNode == nullptr || ResNode == Node)
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000218 DEBUG(Node->dump(CurDAG));
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000219 else
220 DEBUG(ResNode->dump(CurDAG));
Chris Lattneraf29ea62009-08-23 06:49:22 +0000221 DEBUG(errs() << "\n");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000222 return ResNode;
223}
224
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000225bool MipsDAGToDAGISel::
226SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
227 std::vector<SDValue> &OutOps) {
228 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
229 OutOps.push_back(Op);
230 return false;
231}
232
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000233/// createMipsISelDag - This pass converts a legalized DAG into a
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000234/// MIPS-specific DAG, ready for instruction scheduling.
235FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000236 if (TM.getSubtargetImpl()->inMips16Mode())
237 return llvm::createMips16ISelDag(TM);
238
239 return llvm::createMipsSEISelDag(TM);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000240}