[mips][msa] Added bnz.df, bnz.v, bz.df, and bz.v
[oota-llvm.git] / lib / Target / Mips / MipsISelDAGToDAG.cpp
1 //===-- MipsISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips --------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines an instruction selector for the MIPS target.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "mips-isel"
15 #include "MipsISelDAGToDAG.h"
16 #include "Mips16ISelDAGToDAG.h"
17 #include "MipsSEISelDAGToDAG.h"
18 #include "Mips.h"
19 #include "MCTargetDesc/MipsBaseInfo.h"
20 #include "MipsMachineFunction.h"
21 #include "MipsRegisterInfo.h"
22 #include "llvm/CodeGen/MachineConstantPool.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
24 #include "llvm/CodeGen/MachineFunction.h"
25 #include "llvm/CodeGen/MachineInstrBuilder.h"
26 #include "llvm/CodeGen/MachineRegisterInfo.h"
27 #include "llvm/CodeGen/SelectionDAGNodes.h"
28 #include "llvm/IR/GlobalValue.h"
29 #include "llvm/IR/Instructions.h"
30 #include "llvm/IR/Intrinsics.h"
31 #include "llvm/IR/Type.h"
32 #include "llvm/Support/CFG.h"
33 #include "llvm/Support/Debug.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/raw_ostream.h"
36 #include "llvm/Target/TargetMachine.h"
37 using namespace llvm;
38
39 //===----------------------------------------------------------------------===//
40 // Instruction Selector Implementation
41 //===----------------------------------------------------------------------===//
42
43 //===----------------------------------------------------------------------===//
44 // MipsDAGToDAGISel - MIPS specific code to select MIPS machine
45 // instructions for SelectionDAG operations.
46 //===----------------------------------------------------------------------===//
47
48 bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
49   bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
50
51   processFunctionAfterISel(MF);
52
53   return Ret;
54 }
55
56 /// getGlobalBaseReg - Output the instructions required to put the
57 /// GOT address into a register.
58 SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
59   unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
60   return CurDAG->getRegister(GlobalBaseReg,
61                              getTargetLowering()->getPointerTy()).getNode();
62 }
63
64 /// ComplexPattern used on MipsInstrInfo
65 /// Used on Mips Load/Store instructions
66 bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
67                                         SDValue &Offset) const {
68   llvm_unreachable("Unimplemented function.");
69   return false;
70 }
71
72 bool MipsDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base,
73                                         SDValue &Offset) const {
74   llvm_unreachable("Unimplemented function.");
75   return false;
76 }
77
78 bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
79                                          SDValue &Offset) const {
80   llvm_unreachable("Unimplemented function.");
81   return false;
82 }
83
84 bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
85                                      SDValue &Offset) const {
86   llvm_unreachable("Unimplemented function.");
87   return false;
88 }
89
90 bool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base,
91                                        SDValue &Offset) const {
92   llvm_unreachable("Unimplemented function.");
93   return false;
94 }
95
96 bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
97                                     SDValue &Offset, SDValue &Alias) {
98   llvm_unreachable("Unimplemented function.");
99   return false;
100 }
101
102 /// Select instructions not customized! Used for
103 /// expanded, promoted and normal instructions
104 SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
105   unsigned Opcode = Node->getOpcode();
106
107   // Dump information about the Node being selected
108   DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
109
110   // If we have a custom node, we already have selected!
111   if (Node->isMachineOpcode()) {
112     DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
113     return NULL;
114   }
115
116   // See if subclasses can handle this node.
117   std::pair<bool, SDNode*> Ret = selectNode(Node);
118
119   if (Ret.first)
120     return Ret.second;
121
122   switch(Opcode) {
123   default: break;
124
125   // Get target GOT address.
126   case ISD::GLOBAL_OFFSET_TABLE:
127     return getGlobalBaseReg();
128
129 #ifndef NDEBUG
130   case ISD::LOAD:
131   case ISD::STORE:
132     assert(cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
133            cast<MemSDNode>(Node)->getAlignment() &&
134            "Unexpected unaligned loads/stores.");
135     break;
136 #endif
137   }
138
139   // Select the default instruction
140   SDNode *ResNode = SelectCode(Node);
141
142   DEBUG(errs() << "=> ");
143   if (ResNode == NULL || ResNode == Node)
144     DEBUG(Node->dump(CurDAG));
145   else
146     DEBUG(ResNode->dump(CurDAG));
147   DEBUG(errs() << "\n");
148   return ResNode;
149 }
150
151 bool MipsDAGToDAGISel::
152 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
153                              std::vector<SDValue> &OutOps) {
154   assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
155   OutOps.push_back(Op);
156   return false;
157 }
158
159 /// createMipsISelDag - This pass converts a legalized DAG into a
160 /// MIPS-specific DAG, ready for instruction scheduling.
161 FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
162   if (TM.getSubtargetImpl()->inMips16Mode())
163     return llvm::createMips16ISelDag(TM);
164
165   return llvm::createMipsSEISelDag(TM);
166 }