blob: 15e43d48cf3e3196c756c1e41754e81de7603788 [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
Akira Hatanakaabbf9df2013-02-16 00:14:37 +000072bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
73 SDValue &Offset) const {
Akira Hatanaka554d9312013-03-14 18:27:31 +000074 llvm_unreachable("Unimplemented function.");
75 return false;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000076}
77
Akira Hatanakaabbf9df2013-02-16 00:14:37 +000078bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
79 SDValue &Offset) const {
Akira Hatanaka554d9312013-03-14 18:27:31 +000080 llvm_unreachable("Unimplemented function.");
81 return false;
Akira Hatanakadc2f7922013-02-15 21:20:45 +000082}
83
Jack Carterda0860f2013-08-13 20:19:16 +000084bool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base,
85 SDValue &Offset) const {
86 llvm_unreachable("Unimplemented function.");
87 return false;
88}
89
Akira Hatanakaf2835122013-03-14 18:33:23 +000090bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
Akira Hatanaka554d9312013-03-14 18:27:31 +000091 SDValue &Offset, SDValue &Alias) {
92 llvm_unreachable("Unimplemented function.");
93 return false;
Reed Kotlerf99998a2012-10-28 06:02:37 +000094}
Akira Hatanaka2fd04752011-12-20 23:10:57 +000095
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000096/// Select instructions not customized! Used for
97/// expanded, promoted and normal instructions
Dan Gohmaneeb3a002010-01-05 01:24:18 +000098SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000099 unsigned Opcode = Node->getOpcode();
100
101 // Dump information about the Node being selected
Chris Lattner7c306da2010-03-02 06:34:30 +0000102 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000103
104 // If we have a custom node, we already have selected!
Dan Gohmane8be6c62008-07-17 19:10:17 +0000105 if (Node->isMachineOpcode()) {
Chris Lattner7c306da2010-03-02 06:34:30 +0000106 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000107 return NULL;
108 }
109
Akira Hatanaka554d9312013-03-14 18:27:31 +0000110 // See if subclasses can handle this node.
Akira Hatanakaf2835122013-03-14 18:33:23 +0000111 std::pair<bool, SDNode*> Ret = selectNode(Node);
Akira Hatanaka554d9312013-03-14 18:27:31 +0000112
113 if (Ret.first)
114 return Ret.second;
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000115
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000116 switch(Opcode) {
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000117 default: break;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000118
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000119 // Get target GOT address.
120 case ISD::GLOBAL_OFFSET_TABLE:
121 return getGlobalBaseReg();
Akira Hatanakaca074792011-12-08 20:34:32 +0000122
Akira Hatanaka5a7dd432012-09-15 01:52:08 +0000123#ifndef NDEBUG
124 case ISD::LOAD:
125 case ISD::STORE:
126 assert(cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
127 cast<MemSDNode>(Node)->getAlignment() &&
128 "Unexpected unaligned loads/stores.");
129 break;
130#endif
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000131 }
132
133 // Select the default instruction
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000134 SDNode *ResNode = SelectCode(Node);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000135
Chris Lattner7c306da2010-03-02 06:34:30 +0000136 DEBUG(errs() << "=> ");
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000137 if (ResNode == NULL || ResNode == Node)
138 DEBUG(Node->dump(CurDAG));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000139 else
140 DEBUG(ResNode->dump(CurDAG));
Chris Lattner893e1c92009-08-23 06:49:22 +0000141 DEBUG(errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000142 return ResNode;
143}
144
Akira Hatanaka21afc632011-06-21 00:40:49 +0000145bool MipsDAGToDAGISel::
146SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
147 std::vector<SDValue> &OutOps) {
148 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
149 OutOps.push_back(Op);
150 return false;
151}
152
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000153/// createMipsISelDag - This pass converts a legalized DAG into a
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000154/// MIPS-specific DAG, ready for instruction scheduling.
155FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
Akira Hatanaka554d9312013-03-14 18:27:31 +0000156 if (TM.getSubtargetImpl()->inMips16Mode())
157 return llvm::createMips16ISelDag(TM);
158
159 return llvm::createMipsSEISelDag(TM);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000160}