Make TargetTransformInfo keeping a reference to the Module DataLayout
[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 #include "MipsISelDAGToDAG.h"
15 #include "MCTargetDesc/MipsBaseInfo.h"
16 #include "Mips.h"
17 #include "Mips16ISelDAGToDAG.h"
18 #include "MipsMachineFunction.h"
19 #include "MipsRegisterInfo.h"
20 #include "MipsSEISelDAGToDAG.h"
21 #include "llvm/CodeGen/MachineConstantPool.h"
22 #include "llvm/CodeGen/MachineFrameInfo.h"
23 #include "llvm/CodeGen/MachineFunction.h"
24 #include "llvm/CodeGen/MachineInstrBuilder.h"
25 #include "llvm/CodeGen/MachineRegisterInfo.h"
26 #include "llvm/CodeGen/SelectionDAGNodes.h"
27 #include "llvm/IR/CFG.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/Debug.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/raw_ostream.h"
35 #include "llvm/Target/TargetMachine.h"
36 using namespace llvm;
37
38 #define DEBUG_TYPE "mips-isel"
39
40 //===----------------------------------------------------------------------===//
41 // Instruction Selector Implementation
42 //===----------------------------------------------------------------------===//
43
44 //===----------------------------------------------------------------------===//
45 // MipsDAGToDAGISel - MIPS specific code to select MIPS machine
46 // instructions for SelectionDAG operations.
47 //===----------------------------------------------------------------------===//
48
49 bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
50   Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget());
51   bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
52
53   processFunctionAfterISel(MF);
54
55   return Ret;
56 }
57
58 /// getGlobalBaseReg - Output the instructions required to put the
59 /// GOT address into a register.
60 SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
61   unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
62   return CurDAG->getRegister(GlobalBaseReg,
63                              getTargetLowering()->getPointerTy()).getNode();
64 }
65
66 /// ComplexPattern used on MipsInstrInfo
67 /// Used on Mips Load/Store instructions
68 bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
69                                         SDValue &Offset) const {
70   llvm_unreachable("Unimplemented function.");
71   return false;
72 }
73
74 bool MipsDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base,
75                                         SDValue &Offset) const {
76   llvm_unreachable("Unimplemented function.");
77   return false;
78 }
79
80 bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
81                                          SDValue &Offset) const {
82   llvm_unreachable("Unimplemented function.");
83   return false;
84 }
85
86 bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
87                                      SDValue &Offset) const {
88   llvm_unreachable("Unimplemented function.");
89   return false;
90 }
91
92 bool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base,
93                                        SDValue &Offset) const {
94   llvm_unreachable("Unimplemented function.");
95   return false;
96 }
97
98 bool MipsDAGToDAGISel::selectIntAddrLSL2MM(SDValue Addr, SDValue &Base,
99                                            SDValue &Offset) const {
100   llvm_unreachable("Unimplemented function.");
101   return false;
102 }
103
104 bool MipsDAGToDAGISel::selectIntAddrMSA(SDValue Addr, SDValue &Base,
105                                         SDValue &Offset) const {
106   llvm_unreachable("Unimplemented function.");
107   return false;
108 }
109
110 bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
111                                     SDValue &Offset, SDValue &Alias) {
112   llvm_unreachable("Unimplemented function.");
113   return false;
114 }
115
116 bool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm,
117                                     unsigned MinSizeInBits) const {
118   llvm_unreachable("Unimplemented function.");
119   return false;
120 }
121
122 bool MipsDAGToDAGISel::selectVSplatUimm1(SDValue N, SDValue &Imm) const {
123   llvm_unreachable("Unimplemented function.");
124   return false;
125 }
126
127 bool MipsDAGToDAGISel::selectVSplatUimm2(SDValue N, SDValue &Imm) const {
128   llvm_unreachable("Unimplemented function.");
129   return false;
130 }
131
132 bool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const {
133   llvm_unreachable("Unimplemented function.");
134   return false;
135 }
136
137 bool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const {
138   llvm_unreachable("Unimplemented function.");
139   return false;
140 }
141
142 bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const {
143   llvm_unreachable("Unimplemented function.");
144   return false;
145 }
146
147 bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const {
148   llvm_unreachable("Unimplemented function.");
149   return false;
150 }
151
152 bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const {
153   llvm_unreachable("Unimplemented function.");
154   return false;
155 }
156
157 bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const {
158   llvm_unreachable("Unimplemented function.");
159   return false;
160 }
161
162 bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const {
163   llvm_unreachable("Unimplemented function.");
164   return false;
165 }
166
167 bool MipsDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const {
168   llvm_unreachable("Unimplemented function.");
169   return false;
170 }
171
172 bool MipsDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const {
173   llvm_unreachable("Unimplemented function.");
174   return false;
175 }
176
177 bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
178   llvm_unreachable("Unimplemented function.");
179   return false;
180 }
181
182 /// Select instructions not customized! Used for
183 /// expanded, promoted and normal instructions
184 SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
185   unsigned Opcode = Node->getOpcode();
186
187   // Dump information about the Node being selected
188   DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
189
190   // If we have a custom node, we already have selected!
191   if (Node->isMachineOpcode()) {
192     DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
193     Node->setNodeId(-1);
194     return nullptr;
195   }
196
197   // See if subclasses can handle this node.
198   std::pair<bool, SDNode*> Ret = selectNode(Node);
199
200   if (Ret.first)
201     return Ret.second;
202
203   switch(Opcode) {
204   default: break;
205
206   // Get target GOT address.
207   case ISD::GLOBAL_OFFSET_TABLE:
208     return getGlobalBaseReg();
209
210 #ifndef NDEBUG
211   case ISD::LOAD:
212   case ISD::STORE:
213     assert((Subtarget->systemSupportsUnalignedAccess() ||
214             cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
215             cast<MemSDNode>(Node)->getAlignment()) &&
216            "Unexpected unaligned loads/stores.");
217     break;
218 #endif
219   }
220
221   // Select the default instruction
222   SDNode *ResNode = SelectCode(Node);
223
224   DEBUG(errs() << "=> ");
225   if (ResNode == nullptr || ResNode == Node)
226     DEBUG(Node->dump(CurDAG));
227   else
228     DEBUG(ResNode->dump(CurDAG));
229   DEBUG(errs() << "\n");
230   return ResNode;
231 }
232
233 bool MipsDAGToDAGISel::
234 SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID,
235                              std::vector<SDValue> &OutOps) {
236   // All memory constraints can at least accept raw pointers.
237   switch(ConstraintID) {
238   default:
239     llvm_unreachable("Unexpected asm memory constraint");
240   case InlineAsm::Constraint_i:
241   case InlineAsm::Constraint_m:
242   case InlineAsm::Constraint_R:
243   case InlineAsm::Constraint_ZC:
244     OutOps.push_back(Op);
245     return false;
246   }
247   return true;
248 }