blob: b428589c4e41c797fbffce99a27035c53be5e0f7 [file] [log] [blame]
Jia Liuc5707112012-02-17 08:55:11 +00001//===-- MipsISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips --------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Lopes972f5892007-06-06 07:42:06 +00007//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00009//
10// This file defines an instruction selector for the MIPS target.
11//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000013
14#define DEBUG_TYPE "mips-isel"
Akira Hatanaka554d9312013-03-14 18:27:31 +000015#include "MipsISelDAGToDAG.h"
16#include "Mips16ISelDAGToDAG.h"
17#include "MipsSEISelDAGToDAG.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000018#include "Mips.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000019#include "MCTargetDesc/MipsBaseInfo.h"
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000020#include "MipsMachineFunction.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000021#include "MipsRegisterInfo.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000022#include "llvm/CodeGen/MachineConstantPool.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000023#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000024#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000025#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000026#include "llvm/CodeGen/MachineRegisterInfo.h"
Akira Hatanaka44b6c712012-02-28 02:55:02 +000027#include "llvm/CodeGen/SelectionDAGNodes.h"
Chandler Carruth0b8c9a82013-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 Carruthd04a8d42012-12-03 16:50:05 +000032#include "llvm/Support/CFG.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000033#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000036#include "llvm/Target/TargetMachine.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000037using namespace llvm;
38
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000039//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000040// Instruction Selector Implementation
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000041//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000042
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000043//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000044// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
45// instructions for SelectionDAG operations.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000046//===----------------------------------------------------------------------===//
Akira Hatanaka7065b7b2012-03-08 01:51:59 +000047
Akira Hatanaka648f00c2012-02-24 22:34:47 +000048bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
49 bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
Jia Liubb481f82012-02-28 07:46:26 +000050
Akira Hatanakaf2835122013-03-14 18:33:23 +000051 processFunctionAfterISel(MF);
Akira Hatanaka648f00c2012-02-24 22:34:47 +000052
53 return Ret;
54}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000055
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000056/// getGlobalBaseReg - Output the instructions required to put the
57/// GOT address into a register.
Dan Gohman99114052009-06-03 20:30:14 +000058SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Akira Hatanaka648f00c2012-02-24 22:34:47 +000059 unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
Bill Wendlingba54bca2013-06-19 21:36:55 +000060 return CurDAG->getRegister(GlobalBaseReg,
61 getTargetLowering()->getPointerTy()).getNode();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000062}
63
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000064/// ComplexPattern used on MipsInstrInfo
65/// Used on Mips Load/Store instructions
Akira Hatanakaabbf9df2013-02-16 00:14:37 +000066bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
67 SDValue &Offset) const {
Akira Hatanaka554d9312013-03-14 18:27:31 +000068 llvm_unreachable("Unimplemented function.");
Akira Hatanakadc2f7922013-02-15 21:20:45 +000069 return false;
70}
71
Daniel Sanders2fd3e672013-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 Hatanakaabbf9df2013-02-16 00:14:37 +000078bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
79 SDValue &Offset) const {
Akira Hatanaka554d9312013-03-14 18:27:31 +000080 llvm_unreachable("Unimplemented function.");
81 return false;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000082}
83
Akira Hatanakaabbf9df2013-02-16 00:14:37 +000084bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
85 SDValue &Offset) const {
Akira Hatanaka554d9312013-03-14 18:27:31 +000086 llvm_unreachable("Unimplemented function.");
87 return false;
Akira Hatanakadc2f7922013-02-15 21:20:45 +000088}
89
Jack Carterda0860f2013-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 Hatanakaf2835122013-03-14 18:33:23 +000096bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
Akira Hatanaka554d9312013-03-14 18:27:31 +000097 SDValue &Offset, SDValue &Alias) {
98 llvm_unreachable("Unimplemented function.");
99 return false;
Reed Kotlerf99998a2012-10-28 06:02:37 +0000100}
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000101
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000102/// Select instructions not customized! Used for
103/// expanded, promoted and normal instructions
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000104SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000105 unsigned Opcode = Node->getOpcode();
106
107 // Dump information about the Node being selected
Chris Lattner7c306da2010-03-02 06:34:30 +0000108 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000109
110 // If we have a custom node, we already have selected!
Dan Gohmane8be6c62008-07-17 19:10:17 +0000111 if (Node->isMachineOpcode()) {
Chris Lattner7c306da2010-03-02 06:34:30 +0000112 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Tim Northover3e84ad22013-09-22 08:21:56 +0000113 Node->setNodeId(-1);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000114 return NULL;
115 }
116
Akira Hatanaka554d9312013-03-14 18:27:31 +0000117 // See if subclasses can handle this node.
Akira Hatanakaf2835122013-03-14 18:33:23 +0000118 std::pair<bool, SDNode*> Ret = selectNode(Node);
Akira Hatanaka554d9312013-03-14 18:27:31 +0000119
120 if (Ret.first)
121 return Ret.second;
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000122
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000123 switch(Opcode) {
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000124 default: break;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000125
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000126 // Get target GOT address.
127 case ISD::GLOBAL_OFFSET_TABLE:
128 return getGlobalBaseReg();
Akira Hatanakaca074792011-12-08 20:34:32 +0000129
Akira Hatanaka5a7dd432012-09-15 01:52:08 +0000130#ifndef NDEBUG
131 case ISD::LOAD:
132 case ISD::STORE:
133 assert(cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
134 cast<MemSDNode>(Node)->getAlignment() &&
135 "Unexpected unaligned loads/stores.");
136 break;
137#endif
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000138 }
139
140 // Select the default instruction
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 SDNode *ResNode = SelectCode(Node);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000142
Chris Lattner7c306da2010-03-02 06:34:30 +0000143 DEBUG(errs() << "=> ");
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000144 if (ResNode == NULL || ResNode == Node)
145 DEBUG(Node->dump(CurDAG));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000146 else
147 DEBUG(ResNode->dump(CurDAG));
Chris Lattner893e1c92009-08-23 06:49:22 +0000148 DEBUG(errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000149 return ResNode;
150}
151
Akira Hatanaka21afc632011-06-21 00:40:49 +0000152bool MipsDAGToDAGISel::
153SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
154 std::vector<SDValue> &OutOps) {
155 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
156 OutOps.push_back(Op);
157 return false;
158}
159
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000160/// createMipsISelDag - This pass converts a legalized DAG into a
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000161/// MIPS-specific DAG, ready for instruction scheduling.
162FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
Akira Hatanaka554d9312013-03-14 18:27:31 +0000163 if (TM.getSubtargetImpl()->inMips16Mode())
164 return llvm::createMips16ISelDag(TM);
165
166 return llvm::createMipsSEISelDag(TM);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000167}