blob: d0a41e755ee007c3cdc3792bba0451ae5607614f [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
14#define DEBUG_TYPE "mips-isel"
Akira Hatanaka30a84782013-03-14 18:27:31 +000015#include "MipsISelDAGToDAG.h"
16#include "Mips16ISelDAGToDAG.h"
17#include "MipsSEISelDAGToDAG.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000018#include "Mips.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000019#include "MCTargetDesc/MipsBaseInfo.h"
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +000020#include "MipsMachineFunction.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000021#include "MipsRegisterInfo.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000022#include "llvm/CodeGen/MachineConstantPool.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000023#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000025#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattnera10fff52007-12-31 04:13:23 +000026#include "llvm/CodeGen/MachineRegisterInfo.h"
Akira Hatanaka330d9012012-02-28 02:55:02 +000027#include "llvm/CodeGen/SelectionDAGNodes.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"
Chandler Carruthed0881b2012-12-03 16:50:05 +000032#include "llvm/Support/CFG.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
Akira Hatanakae2489122011-04-15 21:51:11 +000039//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000040// Instruction Selector Implementation
Akira Hatanakae2489122011-04-15 21:51:11 +000041//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000042
Akira Hatanakae2489122011-04-15 21:51:11 +000043//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000044// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
45// instructions for SelectionDAG operations.
Akira Hatanakae2489122011-04-15 21:51:11 +000046//===----------------------------------------------------------------------===//
Akira Hatanaka0b2fa912012-03-08 01:51:59 +000047
Akira Hatanakab049aef2012-02-24 22:34:47 +000048bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
49 bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
Jia Liuf54f60f2012-02-28 07:46:26 +000050
Akira Hatanaka040d2252013-03-14 18:33:23 +000051 processFunctionAfterISel(MF);
Akira Hatanakab049aef2012-02-24 22:34:47 +000052
53 return Ret;
54}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000055
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000056/// getGlobalBaseReg - Output the instructions required to put the
57/// GOT address into a register.
Dan Gohmand5ca70642009-06-03 20:30:14 +000058SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Akira Hatanakab049aef2012-02-24 22:34:47 +000059 unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
Bill Wendlinga3cd3502013-06-19 21:36:55 +000060 return CurDAG->getRegister(GlobalBaseReg,
61 getTargetLowering()->getPointerTy()).getNode();
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000062}
63
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000064/// ComplexPattern used on MipsInstrInfo
65/// Used on Mips Load/Store instructions
Akira Hatanakaa35bc832013-02-16 00:14:37 +000066bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
67 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000068 llvm_unreachable("Unimplemented function.");
Akira Hatanaka69fb3d12013-02-15 21:20:45 +000069 return false;
70}
71
Daniel Sanderse6ed5b72013-08-28 12:04:29 +000072bool MipsDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base,
73 SDValue &Offset) const {
74 llvm_unreachable("Unimplemented function.");
75 return false;
76}
77
Akira Hatanakaa35bc832013-02-16 00:14:37 +000078bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
79 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000080 llvm_unreachable("Unimplemented function.");
81 return false;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000082}
83
Akira Hatanakaa35bc832013-02-16 00:14:37 +000084bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
85 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +000086 llvm_unreachable("Unimplemented function.");
87 return false;
Akira Hatanaka69fb3d12013-02-15 21:20:45 +000088}
89
Jack Carter97700972013-08-13 20:19:16 +000090bool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base,
91 SDValue &Offset) const {
92 llvm_unreachable("Unimplemented function.");
93 return false;
94}
95
Akira Hatanaka040d2252013-03-14 18:33:23 +000096bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
Akira Hatanaka30a84782013-03-14 18:27:31 +000097 SDValue &Offset, SDValue &Alias) {
98 llvm_unreachable("Unimplemented function.");
99 return false;
Reed Kotler3589dd72012-10-28 06:02:37 +0000100}
Akira Hatanakacb2a85b2011-12-20 23:10:57 +0000101
Daniel Sandersf49dd822013-09-24 13:33:07 +0000102bool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm) const {
103 llvm_unreachable("Unimplemented function.");
104 return false;
105}
106
Daniel Sanders7e51fe12013-09-27 11:48:57 +0000107bool MipsDAGToDAGISel::selectVSplatUimm1(SDValue N, SDValue &Imm) const {
108 llvm_unreachable("Unimplemented function.");
109 return false;
110}
111
112bool MipsDAGToDAGISel::selectVSplatUimm2(SDValue N, SDValue &Imm) const {
113 llvm_unreachable("Unimplemented function.");
114 return false;
115}
116
Daniel Sandersf49dd822013-09-24 13:33:07 +0000117bool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const {
118 llvm_unreachable("Unimplemented function.");
119 return false;
120}
121
122bool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const {
123 llvm_unreachable("Unimplemented function.");
124 return false;
125}
126
127bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const {
128 llvm_unreachable("Unimplemented function.");
129 return false;
130}
131
132bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const {
133 llvm_unreachable("Unimplemented function.");
134 return false;
135}
136
137bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const {
138 llvm_unreachable("Unimplemented function.");
139 return false;
140}
141
142bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const {
143 llvm_unreachable("Unimplemented function.");
144 return false;
145}
146
147bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const {
148 llvm_unreachable("Unimplemented function.");
149 return false;
150}
151
Daniel Sandersd74b1302013-10-30 14:45:14 +0000152bool MipsDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const {
153 llvm_unreachable("Unimplemented function.");
154 return false;
155}
156
157bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
158 llvm_unreachable("Unimplemented function.");
159 return false;
160}
161
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000162/// Select instructions not customized! Used for
163/// expanded, promoted and normal instructions
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000164SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000165 unsigned Opcode = Node->getOpcode();
166
167 // Dump information about the Node being selected
Chris Lattnerf98f1242010-03-02 06:34:30 +0000168 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000169
170 // If we have a custom node, we already have selected!
Dan Gohman17059682008-07-17 19:10:17 +0000171 if (Node->isMachineOpcode()) {
Chris Lattnerf98f1242010-03-02 06:34:30 +0000172 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Tim Northover31d093c2013-09-22 08:21:56 +0000173 Node->setNodeId(-1);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000174 return NULL;
175 }
176
Akira Hatanaka30a84782013-03-14 18:27:31 +0000177 // See if subclasses can handle this node.
Akira Hatanaka040d2252013-03-14 18:33:23 +0000178 std::pair<bool, SDNode*> Ret = selectNode(Node);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000179
180 if (Ret.first)
181 return Ret.second;
Akira Hatanakacb2a85b2011-12-20 23:10:57 +0000182
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000183 switch(Opcode) {
Akira Hatanaka2c8d17342011-12-20 22:58:01 +0000184 default: break;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000185
Akira Hatanaka2c8d17342011-12-20 22:58:01 +0000186 // Get target GOT address.
187 case ISD::GLOBAL_OFFSET_TABLE:
188 return getGlobalBaseReg();
Akira Hatanakadee6c822011-12-08 20:34:32 +0000189
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000190#ifndef NDEBUG
191 case ISD::LOAD:
192 case ISD::STORE:
193 assert(cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
194 cast<MemSDNode>(Node)->getAlignment() &&
195 "Unexpected unaligned loads/stores.");
196 break;
197#endif
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000198 }
199
200 // Select the default instruction
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000201 SDNode *ResNode = SelectCode(Node);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000202
Chris Lattnerf98f1242010-03-02 06:34:30 +0000203 DEBUG(errs() << "=> ");
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000204 if (ResNode == NULL || ResNode == Node)
205 DEBUG(Node->dump(CurDAG));
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000206 else
207 DEBUG(ResNode->dump(CurDAG));
Chris Lattneraf29ea62009-08-23 06:49:22 +0000208 DEBUG(errs() << "\n");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000209 return ResNode;
210}
211
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000212bool MipsDAGToDAGISel::
213SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
214 std::vector<SDValue> &OutOps) {
215 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
216 OutOps.push_back(Op);
217 return false;
218}
219
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000220/// createMipsISelDag - This pass converts a legalized DAG into a
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000221/// MIPS-specific DAG, ready for instruction scheduling.
222FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000223 if (TM.getSubtargetImpl()->inMips16Mode())
224 return llvm::createMips16ISelDag(TM);
225
226 return llvm::createMipsSEISelDag(TM);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000227}