blob: e1f2759fae8f784cdabaaa38fe60769038f96ba3 [file] [log] [blame]
Eric Christopherab695882010-07-21 22:26:11 +00001//===-- ARMFastISel.cpp - ARM FastISel implementation ---------------------===//
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 the ARM-specific support for the FastISel class. Some
11// of the target-specific code is generated by tablegen in the file
12// ARMGenFastISel.inc, which is #included here.
13//
14//===----------------------------------------------------------------------===//
15
16#include "ARM.h"
Eric Christopher456144e2010-08-19 00:37:05 +000017#include "ARMBaseInstrInfo.h"
Eric Christopherd10cd7b2010-09-10 23:18:12 +000018#include "ARMCallingConv.h"
Eric Christopherab695882010-07-21 22:26:11 +000019#include "ARMRegisterInfo.h"
20#include "ARMTargetMachine.h"
21#include "ARMSubtarget.h"
Eric Christopherc9932f62010-10-01 23:24:42 +000022#include "ARMConstantPoolValue.h"
Eric Christopherab695882010-07-21 22:26:11 +000023#include "llvm/CallingConv.h"
24#include "llvm/DerivedTypes.h"
25#include "llvm/GlobalVariable.h"
26#include "llvm/Instructions.h"
27#include "llvm/IntrinsicInst.h"
Eric Christopherbb3e5da2010-09-14 23:03:37 +000028#include "llvm/Module.h"
Eric Christopherab695882010-07-21 22:26:11 +000029#include "llvm/CodeGen/Analysis.h"
30#include "llvm/CodeGen/FastISel.h"
31#include "llvm/CodeGen/FunctionLoweringInfo.h"
Eric Christopher0fe7d542010-08-17 01:25:29 +000032#include "llvm/CodeGen/MachineInstrBuilder.h"
33#include "llvm/CodeGen/MachineModuleInfo.h"
Eric Christopherab695882010-07-21 22:26:11 +000034#include "llvm/CodeGen/MachineConstantPool.h"
35#include "llvm/CodeGen/MachineFrameInfo.h"
36#include "llvm/CodeGen/MachineRegisterInfo.h"
37#include "llvm/Support/CallSite.h"
Eric Christopher038fea52010-08-17 00:46:57 +000038#include "llvm/Support/CommandLine.h"
Eric Christopherab695882010-07-21 22:26:11 +000039#include "llvm/Support/ErrorHandling.h"
40#include "llvm/Support/GetElementPtrTypeIterator.h"
Eric Christopher0fe7d542010-08-17 01:25:29 +000041#include "llvm/Target/TargetData.h"
42#include "llvm/Target/TargetInstrInfo.h"
43#include "llvm/Target/TargetLowering.h"
44#include "llvm/Target/TargetMachine.h"
Eric Christopherab695882010-07-21 22:26:11 +000045#include "llvm/Target/TargetOptions.h"
46using namespace llvm;
47
Eric Christopher038fea52010-08-17 00:46:57 +000048static cl::opt<bool>
49EnableARMFastISel("arm-fast-isel",
50 cl::desc("Turn on experimental ARM fast-isel support"),
51 cl::init(false), cl::Hidden);
52
Eric Christopherab695882010-07-21 22:26:11 +000053namespace {
54
55class ARMFastISel : public FastISel {
56
57 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
58 /// make the right decision when generating code for different targets.
59 const ARMSubtarget *Subtarget;
Eric Christopher0fe7d542010-08-17 01:25:29 +000060 const TargetMachine &TM;
61 const TargetInstrInfo &TII;
62 const TargetLowering &TLI;
Eric Christopherc9932f62010-10-01 23:24:42 +000063 ARMFunctionInfo *AFI;
Eric Christopherab695882010-07-21 22:26:11 +000064
Eric Christopher8cf6c602010-09-29 22:24:45 +000065 // Convenience variables to avoid some queries.
Eric Christophereaa204b2010-09-02 01:39:14 +000066 bool isThumb;
Eric Christopher8cf6c602010-09-29 22:24:45 +000067 LLVMContext *Context;
Eric Christophereaa204b2010-09-02 01:39:14 +000068
Eric Christopherab695882010-07-21 22:26:11 +000069 public:
Eric Christopherac1a19e2010-09-09 01:06:51 +000070 explicit ARMFastISel(FunctionLoweringInfo &funcInfo)
Eric Christopher0fe7d542010-08-17 01:25:29 +000071 : FastISel(funcInfo),
72 TM(funcInfo.MF->getTarget()),
73 TII(*TM.getInstrInfo()),
74 TLI(*TM.getTargetLowering()) {
Eric Christopherab695882010-07-21 22:26:11 +000075 Subtarget = &TM.getSubtarget<ARMSubtarget>();
Eric Christopher7fe55b72010-08-23 22:32:45 +000076 AFI = funcInfo.MF->getInfo<ARMFunctionInfo>();
Eric Christophereaa204b2010-09-02 01:39:14 +000077 isThumb = AFI->isThumbFunction();
Eric Christopher8cf6c602010-09-29 22:24:45 +000078 Context = &funcInfo.Fn->getContext();
Eric Christopherab695882010-07-21 22:26:11 +000079 }
80
Eric Christophercb592292010-08-20 00:20:31 +000081 // Code from FastISel.cpp.
Eric Christopher0fe7d542010-08-17 01:25:29 +000082 virtual unsigned FastEmitInst_(unsigned MachineInstOpcode,
83 const TargetRegisterClass *RC);
84 virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode,
85 const TargetRegisterClass *RC,
86 unsigned Op0, bool Op0IsKill);
87 virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
88 const TargetRegisterClass *RC,
89 unsigned Op0, bool Op0IsKill,
90 unsigned Op1, bool Op1IsKill);
91 virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
92 const TargetRegisterClass *RC,
93 unsigned Op0, bool Op0IsKill,
94 uint64_t Imm);
95 virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode,
96 const TargetRegisterClass *RC,
97 unsigned Op0, bool Op0IsKill,
98 const ConstantFP *FPImm);
99 virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode,
100 const TargetRegisterClass *RC,
101 uint64_t Imm);
102 virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
103 const TargetRegisterClass *RC,
104 unsigned Op0, bool Op0IsKill,
105 unsigned Op1, bool Op1IsKill,
106 uint64_t Imm);
107 virtual unsigned FastEmitInst_extractsubreg(MVT RetVT,
108 unsigned Op0, bool Op0IsKill,
109 uint32_t Idx);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000110
Eric Christophercb592292010-08-20 00:20:31 +0000111 // Backend specific FastISel code.
Eric Christopherab695882010-07-21 22:26:11 +0000112 virtual bool TargetSelectInstruction(const Instruction *I);
Eric Christopher1b61ef42010-09-02 01:48:11 +0000113 virtual unsigned TargetMaterializeConstant(const Constant *C);
Eric Christopherf9764fa2010-09-30 20:49:44 +0000114 virtual unsigned TargetMaterializeAlloca(const AllocaInst *AI);
Eric Christopherab695882010-07-21 22:26:11 +0000115
116 #include "ARMGenFastISel.inc"
Eric Christopherac1a19e2010-09-09 01:06:51 +0000117
Eric Christopher83007122010-08-23 21:44:12 +0000118 // Instruction selection routines.
Eric Christopher44bff902010-09-10 23:10:30 +0000119 private:
Eric Christopher43b62be2010-09-27 06:02:23 +0000120 virtual bool SelectLoad(const Instruction *I);
121 virtual bool SelectStore(const Instruction *I);
122 virtual bool SelectBranch(const Instruction *I);
123 virtual bool SelectCmp(const Instruction *I);
124 virtual bool SelectFPExt(const Instruction *I);
125 virtual bool SelectFPTrunc(const Instruction *I);
126 virtual bool SelectBinaryOp(const Instruction *I, unsigned ISDOpcode);
127 virtual bool SelectSIToFP(const Instruction *I);
128 virtual bool SelectFPToSI(const Instruction *I);
129 virtual bool SelectSDiv(const Instruction *I);
Eric Christopherf9764fa2010-09-30 20:49:44 +0000130 virtual bool SelectCall(const Instruction *I);
Eric Christopher3bbd3962010-10-11 08:27:59 +0000131 virtual bool SelectSelect(const Instruction *I);
Eric Christopherab695882010-07-21 22:26:11 +0000132
Eric Christopher83007122010-08-23 21:44:12 +0000133 // Utility routines.
Eric Christopher456144e2010-08-19 00:37:05 +0000134 private:
Eric Christopherb1cc8482010-08-25 07:23:49 +0000135 bool isTypeLegal(const Type *Ty, EVT &VT);
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000136 bool isLoadTypeLegal(const Type *Ty, EVT &VT);
Eric Christopherb1cc8482010-08-25 07:23:49 +0000137 bool ARMEmitLoad(EVT VT, unsigned &ResultReg, unsigned Reg, int Offset);
Eric Christopher318b6ee2010-09-02 00:53:56 +0000138 bool ARMEmitStore(EVT VT, unsigned SrcReg, unsigned Reg, int Offset);
Eric Christopher30b66332010-09-08 21:49:50 +0000139 bool ARMLoadAlloca(const Instruction *I, EVT VT);
140 bool ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT);
Eric Christophercb0b04b2010-08-24 00:07:24 +0000141 bool ARMComputeRegOffset(const Value *Obj, unsigned &Reg, int &Offset);
Eric Christopher9ed58df2010-09-09 00:19:41 +0000142 unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT);
Eric Christopher744c7c82010-09-28 22:47:54 +0000143 unsigned ARMMaterializeInt(const Constant *C, EVT VT);
Eric Christopherc9932f62010-10-01 23:24:42 +0000144 unsigned ARMMaterializeGV(const GlobalValue *GV, EVT VT);
Eric Christopheraa3ace12010-09-09 20:49:25 +0000145 unsigned ARMMoveToFPReg(EVT VT, unsigned SrcReg);
Eric Christopher9ee4ce22010-09-09 21:44:45 +0000146 unsigned ARMMoveToIntReg(EVT VT, unsigned SrcReg);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000147
Eric Christopherd10cd7b2010-09-10 23:18:12 +0000148 // Call handling routines.
149 private:
150 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool Return);
Eric Christophera9a7a1a2010-09-29 23:11:09 +0000151 bool ProcessCallArgs(SmallVectorImpl<Value*> &Args,
152 SmallVectorImpl<unsigned> &ArgRegs,
153 SmallVectorImpl<EVT> &ArgVTs,
154 SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
155 SmallVectorImpl<unsigned> &RegArgs,
156 CallingConv::ID CC,
157 unsigned &NumBytes);
158 bool FinishCall(EVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
159 const Instruction *I, CallingConv::ID CC,
160 unsigned &NumBytes);
Eric Christopher7ed8ec92010-09-28 01:21:42 +0000161 bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call);
Eric Christopherd10cd7b2010-09-10 23:18:12 +0000162
163 // OptionalDef handling routines.
164 private:
Eric Christopher456144e2010-08-19 00:37:05 +0000165 bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR);
166 const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB);
167};
Eric Christopherab695882010-07-21 22:26:11 +0000168
169} // end anonymous namespace
170
Eric Christopherd10cd7b2010-09-10 23:18:12 +0000171#include "ARMGenCallingConv.inc"
Eric Christopherab695882010-07-21 22:26:11 +0000172
Eric Christopher456144e2010-08-19 00:37:05 +0000173// DefinesOptionalPredicate - This is different from DefinesPredicate in that
174// we don't care about implicit defs here, just places we'll need to add a
175// default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR.
176bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) {
177 const TargetInstrDesc &TID = MI->getDesc();
178 if (!TID.hasOptionalDef())
179 return false;
180
181 // Look to see if our OptionalDef is defining CPSR or CCR.
182 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
183 const MachineOperand &MO = MI->getOperand(i);
Eric Christopherf762fbe2010-08-20 00:36:24 +0000184 if (!MO.isReg() || !MO.isDef()) continue;
185 if (MO.getReg() == ARM::CPSR)
Eric Christopher456144e2010-08-19 00:37:05 +0000186 *CPSR = true;
187 }
188 return true;
189}
190
191// If the machine is predicable go ahead and add the predicate operands, if
192// it needs default CC operands add those.
193const MachineInstrBuilder &
194ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) {
195 MachineInstr *MI = &*MIB;
196
197 // Do we use a predicate?
198 if (TII.isPredicable(MI))
199 AddDefaultPred(MIB);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000200
Eric Christopher456144e2010-08-19 00:37:05 +0000201 // Do we optionally set a predicate? Preds is size > 0 iff the predicate
202 // defines CPSR. All other OptionalDefines in ARM are the CCR register.
Eric Christopher979e0a12010-08-19 15:35:27 +0000203 bool CPSR = false;
Eric Christopher456144e2010-08-19 00:37:05 +0000204 if (DefinesOptionalPredicate(MI, &CPSR)) {
205 if (CPSR)
206 AddDefaultT1CC(MIB);
207 else
208 AddDefaultCC(MIB);
209 }
210 return MIB;
211}
212
Eric Christopher0fe7d542010-08-17 01:25:29 +0000213unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode,
214 const TargetRegisterClass* RC) {
215 unsigned ResultReg = createResultReg(RC);
216 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
217
Eric Christopher456144e2010-08-19 00:37:05 +0000218 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg));
Eric Christopher0fe7d542010-08-17 01:25:29 +0000219 return ResultReg;
220}
221
222unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode,
223 const TargetRegisterClass *RC,
224 unsigned Op0, bool Op0IsKill) {
225 unsigned ResultReg = createResultReg(RC);
226 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
227
228 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000229 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000230 .addReg(Op0, Op0IsKill * RegState::Kill));
231 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000232 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000233 .addReg(Op0, Op0IsKill * RegState::Kill));
Eric Christopher456144e2010-08-19 00:37:05 +0000234 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000235 TII.get(TargetOpcode::COPY), ResultReg)
236 .addReg(II.ImplicitDefs[0]));
237 }
238 return ResultReg;
239}
240
241unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode,
242 const TargetRegisterClass *RC,
243 unsigned Op0, bool Op0IsKill,
244 unsigned Op1, bool Op1IsKill) {
245 unsigned ResultReg = createResultReg(RC);
246 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
247
248 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000249 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000250 .addReg(Op0, Op0IsKill * RegState::Kill)
251 .addReg(Op1, Op1IsKill * RegState::Kill));
252 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000253 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000254 .addReg(Op0, Op0IsKill * RegState::Kill)
255 .addReg(Op1, Op1IsKill * RegState::Kill));
Eric Christopher456144e2010-08-19 00:37:05 +0000256 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000257 TII.get(TargetOpcode::COPY), ResultReg)
258 .addReg(II.ImplicitDefs[0]));
259 }
260 return ResultReg;
261}
262
263unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode,
264 const TargetRegisterClass *RC,
265 unsigned Op0, bool Op0IsKill,
266 uint64_t Imm) {
267 unsigned ResultReg = createResultReg(RC);
268 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
269
270 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000271 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000272 .addReg(Op0, Op0IsKill * RegState::Kill)
273 .addImm(Imm));
274 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000275 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000276 .addReg(Op0, Op0IsKill * RegState::Kill)
277 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000278 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000279 TII.get(TargetOpcode::COPY), ResultReg)
280 .addReg(II.ImplicitDefs[0]));
281 }
282 return ResultReg;
283}
284
285unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode,
286 const TargetRegisterClass *RC,
287 unsigned Op0, bool Op0IsKill,
288 const ConstantFP *FPImm) {
289 unsigned ResultReg = createResultReg(RC);
290 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
291
292 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000293 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000294 .addReg(Op0, Op0IsKill * RegState::Kill)
295 .addFPImm(FPImm));
296 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000297 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000298 .addReg(Op0, Op0IsKill * RegState::Kill)
299 .addFPImm(FPImm));
Eric Christopher456144e2010-08-19 00:37:05 +0000300 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000301 TII.get(TargetOpcode::COPY), ResultReg)
302 .addReg(II.ImplicitDefs[0]));
303 }
304 return ResultReg;
305}
306
307unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode,
308 const TargetRegisterClass *RC,
309 unsigned Op0, bool Op0IsKill,
310 unsigned Op1, bool Op1IsKill,
311 uint64_t Imm) {
312 unsigned ResultReg = createResultReg(RC);
313 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
314
315 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000316 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000317 .addReg(Op0, Op0IsKill * RegState::Kill)
318 .addReg(Op1, Op1IsKill * RegState::Kill)
319 .addImm(Imm));
320 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000321 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000322 .addReg(Op0, Op0IsKill * RegState::Kill)
323 .addReg(Op1, Op1IsKill * RegState::Kill)
324 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000325 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000326 TII.get(TargetOpcode::COPY), ResultReg)
327 .addReg(II.ImplicitDefs[0]));
328 }
329 return ResultReg;
330}
331
332unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode,
333 const TargetRegisterClass *RC,
334 uint64_t Imm) {
335 unsigned ResultReg = createResultReg(RC);
336 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000337
Eric Christopher0fe7d542010-08-17 01:25:29 +0000338 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000339 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000340 .addImm(Imm));
341 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000342 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000343 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000344 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000345 TII.get(TargetOpcode::COPY), ResultReg)
346 .addReg(II.ImplicitDefs[0]));
347 }
348 return ResultReg;
349}
350
351unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT,
352 unsigned Op0, bool Op0IsKill,
353 uint32_t Idx) {
354 unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT));
355 assert(TargetRegisterInfo::isVirtualRegister(Op0) &&
356 "Cannot yet extract from physregs");
Eric Christopher456144e2010-08-19 00:37:05 +0000357 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000358 DL, TII.get(TargetOpcode::COPY), ResultReg)
359 .addReg(Op0, getKillRegState(Op0IsKill), Idx));
360 return ResultReg;
361}
362
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000363// TODO: Don't worry about 64-bit now, but when this is fixed remove the
364// checks from the various callers.
Eric Christopheraa3ace12010-09-09 20:49:25 +0000365unsigned ARMFastISel::ARMMoveToFPReg(EVT VT, unsigned SrcReg) {
Eric Christopher9ee4ce22010-09-09 21:44:45 +0000366 if (VT.getSimpleVT().SimpleTy == MVT::f64) return 0;
367
368 unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
369 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
370 TII.get(ARM::VMOVRS), MoveReg)
371 .addReg(SrcReg));
372 return MoveReg;
373}
374
375unsigned ARMFastISel::ARMMoveToIntReg(EVT VT, unsigned SrcReg) {
Eric Christopher9ee4ce22010-09-09 21:44:45 +0000376 if (VT.getSimpleVT().SimpleTy == MVT::i64) return 0;
377
Eric Christopheraa3ace12010-09-09 20:49:25 +0000378 unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
379 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher9ee4ce22010-09-09 21:44:45 +0000380 TII.get(ARM::VMOVSR), MoveReg)
Eric Christopheraa3ace12010-09-09 20:49:25 +0000381 .addReg(SrcReg));
382 return MoveReg;
383}
384
Eric Christopher9ed58df2010-09-09 00:19:41 +0000385// For double width floating point we need to materialize two constants
386// (the high and the low) into integer registers then use a move to get
387// the combined constant into an FP reg.
388unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, EVT VT) {
389 const APFloat Val = CFP->getValueAPF();
390 bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000391
Eric Christopher9ed58df2010-09-09 00:19:41 +0000392 // This checks to see if we can use VFP3 instructions to materialize
393 // a constant, otherwise we have to go through the constant pool.
394 if (TLI.isFPImmLegal(Val, VT)) {
395 unsigned Opc = is64bit ? ARM::FCONSTD : ARM::FCONSTS;
396 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
397 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
398 DestReg)
399 .addFPImm(CFP));
400 return DestReg;
401 }
Eric Christopher238bb162010-09-09 23:50:00 +0000402
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000403 // Require VFP2 for loading fp constants.
Eric Christopher238bb162010-09-09 23:50:00 +0000404 if (!Subtarget->hasVFP2()) return false;
405
406 // MachineConstantPool wants an explicit alignment.
407 unsigned Align = TD.getPrefTypeAlignment(CFP->getType());
408 if (Align == 0) {
409 // TODO: Figure out if this is correct.
410 Align = TD.getTypeAllocSize(CFP->getType());
411 }
412 unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align);
413 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
414 unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS;
415
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000416 // The extra reg is for addrmode5.
Eric Christopherf5732c42010-09-28 00:35:09 +0000417 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
418 DestReg)
419 .addConstantPoolIndex(Idx)
Eric Christopher238bb162010-09-09 23:50:00 +0000420 .addReg(0));
421 return DestReg;
Eric Christopher9ed58df2010-09-09 00:19:41 +0000422}
423
Eric Christopher744c7c82010-09-28 22:47:54 +0000424unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, EVT VT) {
425
426 // For now 32-bit only.
427 if (VT.getSimpleVT().SimpleTy != MVT::i32) return false;
428
Eric Christopher56d2b722010-09-02 23:43:26 +0000429 // MachineConstantPool wants an explicit alignment.
430 unsigned Align = TD.getPrefTypeAlignment(C->getType());
431 if (Align == 0) {
432 // TODO: Figure out if this is correct.
433 Align = TD.getTypeAllocSize(C->getType());
434 }
435 unsigned Idx = MCP.getConstantPoolIndex(C, Align);
Eric Christopher744c7c82010-09-28 22:47:54 +0000436 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000437
Eric Christopher56d2b722010-09-02 23:43:26 +0000438 if (isThumb)
439 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopherfd609802010-09-28 21:55:34 +0000440 TII.get(ARM::t2LDRpci), DestReg)
441 .addConstantPoolIndex(Idx));
Eric Christopher56d2b722010-09-02 23:43:26 +0000442 else
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000443 // The extra reg and immediate are for addrmode2.
Eric Christopher56d2b722010-09-02 23:43:26 +0000444 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopherfd609802010-09-28 21:55:34 +0000445 TII.get(ARM::LDRcp), DestReg)
446 .addConstantPoolIndex(Idx)
Eric Christopher56d2b722010-09-02 23:43:26 +0000447 .addReg(0).addImm(0));
Eric Christopherac1a19e2010-09-09 01:06:51 +0000448
Eric Christopher56d2b722010-09-02 23:43:26 +0000449 return DestReg;
Eric Christopher1b61ef42010-09-02 01:48:11 +0000450}
451
Eric Christopherc9932f62010-10-01 23:24:42 +0000452unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, EVT VT) {
Eric Christopher890dbbe2010-10-02 00:32:44 +0000453 // For now 32-bit only.
454 if (VT.getSimpleVT().SimpleTy != MVT::i32) return 0;
455
456 Reloc::Model RelocM = TM.getRelocationModel();
457
458 // TODO: No external globals for now.
459 if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) return 0;
460
461 // TODO: Need more magic for ARM PIC.
462 if (!isThumb && (RelocM == Reloc::PIC_)) return 0;
463
464 // MachineConstantPool wants an explicit alignment.
465 unsigned Align = TD.getPrefTypeAlignment(GV->getType());
466 if (Align == 0) {
467 // TODO: Figure out if this is correct.
468 Align = TD.getTypeAllocSize(GV->getType());
469 }
470
471 // Grab index.
472 unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb() ? 4 : 8);
473 unsigned Id = AFI->createConstPoolEntryUId();
474 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, Id,
475 ARMCP::CPValue, PCAdj);
476 unsigned Idx = MCP.getConstantPoolIndex(CPV, Align);
477
478 // Load value.
479 MachineInstrBuilder MIB;
480 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
481 if (isThumb) {
482 unsigned Opc = (RelocM != Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic;
483 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg)
484 .addConstantPoolIndex(Idx);
485 if (RelocM == Reloc::PIC_)
486 MIB.addImm(Id);
487 } else {
488 // The extra reg and immediate are for addrmode2.
489 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRcp),
490 DestReg)
491 .addConstantPoolIndex(Idx)
492 .addReg(0).addImm(0);
493 }
494 AddOptionalDefs(MIB);
495 return DestReg;
Eric Christopherc9932f62010-10-01 23:24:42 +0000496}
497
Eric Christopher9ed58df2010-09-09 00:19:41 +0000498unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) {
499 EVT VT = TLI.getValueType(C->getType(), true);
500
501 // Only handle simple types.
502 if (!VT.isSimple()) return 0;
503
504 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
505 return ARMMaterializeFP(CFP, VT);
Eric Christopherc9932f62010-10-01 23:24:42 +0000506 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
507 return ARMMaterializeGV(GV, VT);
508 else if (isa<ConstantInt>(C))
509 return ARMMaterializeInt(C, VT);
510
511 return 0;
Eric Christopher9ed58df2010-09-09 00:19:41 +0000512}
513
Eric Christopherf9764fa2010-09-30 20:49:44 +0000514unsigned ARMFastISel::TargetMaterializeAlloca(const AllocaInst *AI) {
515 // Don't handle dynamic allocas.
516 if (!FuncInfo.StaticAllocaMap.count(AI)) return 0;
517
518 EVT VT;
519 if (!isTypeLegal(AI->getType(), VT)) return false;
520
521 DenseMap<const AllocaInst*, int>::iterator SI =
522 FuncInfo.StaticAllocaMap.find(AI);
523
524 // This will get lowered later into the correct offsets and registers
525 // via rewriteXFrameIndex.
526 if (SI != FuncInfo.StaticAllocaMap.end()) {
527 TargetRegisterClass* RC = TLI.getRegClassFor(VT);
528 unsigned ResultReg = createResultReg(RC);
529 unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri;
530 AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL,
531 TII.get(Opc), ResultReg)
532 .addFrameIndex(SI->second)
533 .addImm(0));
534 return ResultReg;
535 }
536
537 return 0;
538}
539
Eric Christopherb1cc8482010-08-25 07:23:49 +0000540bool ARMFastISel::isTypeLegal(const Type *Ty, EVT &VT) {
541 VT = TLI.getValueType(Ty, true);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000542
Eric Christopherb1cc8482010-08-25 07:23:49 +0000543 // Only handle simple types.
544 if (VT == MVT::Other || !VT.isSimple()) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000545
Eric Christopherdc908042010-08-31 01:28:42 +0000546 // Handle all legal types, i.e. a register that will directly hold this
547 // value.
548 return TLI.isTypeLegal(VT);
Eric Christopherb1cc8482010-08-25 07:23:49 +0000549}
550
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000551bool ARMFastISel::isLoadTypeLegal(const Type *Ty, EVT &VT) {
552 if (isTypeLegal(Ty, VT)) return true;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000553
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000554 // If this is a type than can be sign or zero-extended to a basic operation
555 // go ahead and accept it now.
556 if (VT == MVT::i8 || VT == MVT::i16)
557 return true;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000558
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000559 return false;
560}
561
Eric Christophercb0b04b2010-08-24 00:07:24 +0000562// Computes the Reg+Offset to get to an object.
563bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg,
Eric Christopher83007122010-08-23 21:44:12 +0000564 int &Offset) {
565 // Some boilerplate from the X86 FastISel.
566 const User *U = NULL;
Eric Christopher83007122010-08-23 21:44:12 +0000567 unsigned Opcode = Instruction::UserOp1;
Eric Christophercb0b04b2010-08-24 00:07:24 +0000568 if (const Instruction *I = dyn_cast<Instruction>(Obj)) {
Eric Christopher83007122010-08-23 21:44:12 +0000569 // Don't walk into other basic blocks; it's possible we haven't
570 // visited them yet, so the instructions may not yet be assigned
571 // virtual registers.
572 if (FuncInfo.MBBMap[I->getParent()] != FuncInfo.MBB)
573 return false;
Eric Christopher83007122010-08-23 21:44:12 +0000574 Opcode = I->getOpcode();
575 U = I;
Eric Christophercb0b04b2010-08-24 00:07:24 +0000576 } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
Eric Christopher83007122010-08-23 21:44:12 +0000577 Opcode = C->getOpcode();
578 U = C;
579 }
580
Eric Christophercb0b04b2010-08-24 00:07:24 +0000581 if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType()))
Eric Christopher83007122010-08-23 21:44:12 +0000582 if (Ty->getAddressSpace() > 255)
583 // Fast instruction selection doesn't support the special
584 // address spaces.
585 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000586
Eric Christopher83007122010-08-23 21:44:12 +0000587 switch (Opcode) {
Eric Christopherac1a19e2010-09-09 01:06:51 +0000588 default:
Eric Christopher83007122010-08-23 21:44:12 +0000589 break;
590 case Instruction::Alloca: {
Eric Christopherf06f3092010-08-24 00:50:47 +0000591 assert(false && "Alloca should have been handled earlier!");
592 return false;
Eric Christopher83007122010-08-23 21:44:12 +0000593 }
594 }
Eric Christopherac1a19e2010-09-09 01:06:51 +0000595
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000596 // FIXME: Handle global variables.
Eric Christophercb0b04b2010-08-24 00:07:24 +0000597 if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) {
Eric Christopherf06f3092010-08-24 00:50:47 +0000598 (void)GV;
Eric Christophercb0b04b2010-08-24 00:07:24 +0000599 return false;
600 }
Eric Christopherac1a19e2010-09-09 01:06:51 +0000601
Eric Christophercb0b04b2010-08-24 00:07:24 +0000602 // Try to get this in a register if nothing else has worked.
603 Reg = getRegForValue(Obj);
Eric Christopher318b6ee2010-09-02 00:53:56 +0000604 if (Reg == 0) return false;
605
606 // Since the offset may be too large for the load instruction
607 // get the reg+offset into a register.
608 // TODO: Verify the additions work, otherwise we'll need to add the
609 // offset instead of 0 to the instructions and do all sorts of operand
610 // munging.
611 // TODO: Optimize this somewhat.
612 if (Offset != 0) {
613 ARMCC::CondCodes Pred = ARMCC::AL;
614 unsigned PredReg = 0;
615
Eric Christophereaa204b2010-09-02 01:39:14 +0000616 if (!isThumb)
Eric Christopher318b6ee2010-09-02 00:53:56 +0000617 emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
618 Reg, Reg, Offset, Pred, PredReg,
619 static_cast<const ARMBaseInstrInfo&>(TII));
620 else {
621 assert(AFI->isThumb2Function());
622 emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
623 Reg, Reg, Offset, Pred, PredReg,
624 static_cast<const ARMBaseInstrInfo&>(TII));
625 }
626 }
Eric Christopher318b6ee2010-09-02 00:53:56 +0000627 return true;
Eric Christopher83007122010-08-23 21:44:12 +0000628}
629
Eric Christopher30b66332010-09-08 21:49:50 +0000630bool ARMFastISel::ARMLoadAlloca(const Instruction *I, EVT VT) {
Eric Christopherf06f3092010-08-24 00:50:47 +0000631 Value *Op0 = I->getOperand(0);
632
Eric Christopherdf1f5a92010-10-07 21:40:18 +0000633 // Promote load/store types.
634 if (VT == MVT::i8 || VT == MVT::i16) VT = MVT::i32;
635
Eric Christopherf06f3092010-08-24 00:50:47 +0000636 // Verify it's an alloca.
Eric Christophere24d66f2010-08-24 22:07:27 +0000637 if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op0)) {
638 DenseMap<const AllocaInst*, int>::iterator SI =
639 FuncInfo.StaticAllocaMap.find(AI);
Eric Christopherf06f3092010-08-24 00:50:47 +0000640
Eric Christophere24d66f2010-08-24 22:07:27 +0000641 if (SI != FuncInfo.StaticAllocaMap.end()) {
Eric Christopher30b66332010-09-08 21:49:50 +0000642 TargetRegisterClass* RC = TLI.getRegClassFor(VT);
Eric Christopherb1cc8482010-08-25 07:23:49 +0000643 unsigned ResultReg = createResultReg(RC);
Eric Christophere24d66f2010-08-24 22:07:27 +0000644 TII.loadRegFromStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt,
Eric Christopherb1cc8482010-08-25 07:23:49 +0000645 ResultReg, SI->second, RC,
Eric Christophere24d66f2010-08-24 22:07:27 +0000646 TM.getRegisterInfo());
647 UpdateValueMap(I, ResultReg);
648 return true;
649 }
Eric Christopherf06f3092010-08-24 00:50:47 +0000650 }
Eric Christopherf06f3092010-08-24 00:50:47 +0000651 return false;
652}
653
Eric Christopherb1cc8482010-08-25 07:23:49 +0000654bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg,
655 unsigned Reg, int Offset) {
Eric Christopherac1a19e2010-09-09 01:06:51 +0000656
Eric Christopherb1cc8482010-08-25 07:23:49 +0000657 assert(VT.isSimple() && "Non-simple types are invalid here!");
Eric Christopherdc908042010-08-31 01:28:42 +0000658 unsigned Opc;
Eric Christopheree56ea62010-10-07 05:50:44 +0000659 TargetRegisterClass *RC;
Eric Christopher6dab1372010-09-18 01:59:37 +0000660 bool isFloat = false;
Eric Christopherb1cc8482010-08-25 07:23:49 +0000661 switch (VT.getSimpleVT().SimpleTy) {
Eric Christopherac1a19e2010-09-09 01:06:51 +0000662 default:
Eric Christopher98de5b42010-09-29 00:49:09 +0000663 // This is mostly going to be Neon/vector support.
Eric Christopher548d1bb2010-08-30 23:48:26 +0000664 return false;
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000665 case MVT::i16:
Eric Christopher7a56f332010-10-08 01:13:17 +0000666 Opc = isThumb ? ARM::t2LDRHi8 : ARM::LDRH;
667 RC = ARM::GPRRegisterClass;
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000668 VT = MVT::i32;
669 break;
670 case MVT::i8:
Eric Christopher7a56f332010-10-08 01:13:17 +0000671 Opc = isThumb ? ARM::t2LDRBi8 : ARM::LDRB;
672 RC = ARM::GPRRegisterClass;
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000673 VT = MVT::i32;
674 break;
Eric Christopherdc908042010-08-31 01:28:42 +0000675 case MVT::i32:
Eric Christopher7a56f332010-10-08 01:13:17 +0000676 Opc = isThumb ? ARM::t2LDRi8 : ARM::LDR;
677 RC = ARM::GPRRegisterClass;
Eric Christopherdc908042010-08-31 01:28:42 +0000678 break;
Eric Christopher6dab1372010-09-18 01:59:37 +0000679 case MVT::f32:
680 Opc = ARM::VLDRS;
Eric Christopheree56ea62010-10-07 05:50:44 +0000681 RC = TLI.getRegClassFor(VT);
Eric Christopher6dab1372010-09-18 01:59:37 +0000682 isFloat = true;
683 break;
684 case MVT::f64:
685 Opc = ARM::VLDRD;
Eric Christopheree56ea62010-10-07 05:50:44 +0000686 RC = TLI.getRegClassFor(VT);
Eric Christopher6dab1372010-09-18 01:59:37 +0000687 isFloat = true;
688 break;
Eric Christopherb1cc8482010-08-25 07:23:49 +0000689 }
Eric Christopherac1a19e2010-09-09 01:06:51 +0000690
Eric Christopheree56ea62010-10-07 05:50:44 +0000691 ResultReg = createResultReg(RC);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000692
Eric Christopher7a56f332010-10-08 01:13:17 +0000693 // For now with the additions above the offset should be zero - thus we
694 // can always fit into an i8.
695 assert(Offset == 0 && "Offset not zero!");
696
697 // The thumb and floating point instructions both take 2 operands, ARM takes
698 // another register.
699 if (isFloat || isThumb)
Eric Christopher6dab1372010-09-18 01:59:37 +0000700 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
701 TII.get(Opc), ResultReg)
702 .addReg(Reg).addImm(Offset));
Eric Christopherdc908042010-08-31 01:28:42 +0000703 else
704 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
705 TII.get(Opc), ResultReg)
706 .addReg(Reg).addReg(0).addImm(Offset));
Eric Christopherdc908042010-08-31 01:28:42 +0000707 return true;
Eric Christopherb1cc8482010-08-25 07:23:49 +0000708}
709
Eric Christopher43b62be2010-09-27 06:02:23 +0000710bool ARMFastISel::SelectLoad(const Instruction *I) {
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000711 // Verify we have a legal type before going any further.
712 EVT VT;
713 if (!isLoadTypeLegal(I->getType(), VT))
714 return false;
715
716 // If we're an alloca we know we have a frame index and can emit the load
717 // directly in short order.
718 if (ARMLoadAlloca(I, VT))
719 return true;
720
721 // Our register and offset with innocuous defaults.
722 unsigned Reg = 0;
723 int Offset = 0;
724
725 // See if we can handle this as Reg + Offset
726 if (!ARMComputeRegOffset(I->getOperand(0), Reg, Offset))
727 return false;
728
729 unsigned ResultReg;
730 if (!ARMEmitLoad(VT, ResultReg, Reg, Offset /* 0 */)) return false;
731
732 UpdateValueMap(I, ResultReg);
733 return true;
734}
735
Eric Christopher30b66332010-09-08 21:49:50 +0000736bool ARMFastISel::ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT){
Eric Christopher543cf052010-09-01 22:16:27 +0000737 Value *Op1 = I->getOperand(1);
738
Eric Christopherdf1f5a92010-10-07 21:40:18 +0000739 // Promote load/store types.
740 if (VT == MVT::i8 || VT == MVT::i16) VT = MVT::i32;
741
Eric Christopher543cf052010-09-01 22:16:27 +0000742 // Verify it's an alloca.
743 if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op1)) {
744 DenseMap<const AllocaInst*, int>::iterator SI =
745 FuncInfo.StaticAllocaMap.find(AI);
746
747 if (SI != FuncInfo.StaticAllocaMap.end()) {
Eric Christopher30b66332010-09-08 21:49:50 +0000748 TargetRegisterClass* RC = TLI.getRegClassFor(VT);
Eric Christopher318b6ee2010-09-02 00:53:56 +0000749 assert(SrcReg != 0 && "Nothing to store!");
Eric Christopher543cf052010-09-01 22:16:27 +0000750 TII.storeRegToStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt,
Eric Christopher318b6ee2010-09-02 00:53:56 +0000751 SrcReg, true /*isKill*/, SI->second, RC,
Eric Christopher543cf052010-09-01 22:16:27 +0000752 TM.getRegisterInfo());
753 return true;
754 }
755 }
756 return false;
757}
758
Eric Christopher318b6ee2010-09-02 00:53:56 +0000759bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg,
760 unsigned DstReg, int Offset) {
Eric Christopher318b6ee2010-09-02 00:53:56 +0000761 unsigned StrOpc;
Eric Christopherb74558a2010-09-18 01:23:38 +0000762 bool isFloat = false;
Eric Christopher318b6ee2010-09-02 00:53:56 +0000763 switch (VT.getSimpleVT().SimpleTy) {
764 default: return false;
765 case MVT::i1:
Eric Christophere93417b2010-10-08 23:52:16 +0000766 case MVT::i8: StrOpc = isThumb ? ARM::t2STRBi8 : ARM::STRB; break;
767 case MVT::i16: StrOpc = isThumb ? ARM::t2STRHi8 : ARM::STRH; break;
768 case MVT::i32: StrOpc = isThumb ? ARM::t2STRi8 : ARM::STR; break;
Eric Christopher56d2b722010-09-02 23:43:26 +0000769 case MVT::f32:
770 if (!Subtarget->hasVFP2()) return false;
771 StrOpc = ARM::VSTRS;
Eric Christopherb74558a2010-09-18 01:23:38 +0000772 isFloat = true;
Eric Christopher56d2b722010-09-02 23:43:26 +0000773 break;
774 case MVT::f64:
775 if (!Subtarget->hasVFP2()) return false;
776 StrOpc = ARM::VSTRD;
Eric Christopherb74558a2010-09-18 01:23:38 +0000777 isFloat = true;
Eric Christopher56d2b722010-09-02 23:43:26 +0000778 break;
Eric Christopher318b6ee2010-09-02 00:53:56 +0000779 }
Eric Christopherac1a19e2010-09-09 01:06:51 +0000780
Eric Christopherb74558a2010-09-18 01:23:38 +0000781 // The thumb addressing mode has operands swapped from the arm addressing
782 // mode, the floating point one only has two operands.
Eric Christophere93417b2010-10-08 23:52:16 +0000783 if (isFloat || isThumb)
Eric Christopherb74558a2010-09-18 01:23:38 +0000784 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher45547b82010-10-01 20:46:04 +0000785 TII.get(StrOpc))
786 .addReg(SrcReg).addReg(DstReg).addImm(Offset));
Eric Christopher318b6ee2010-09-02 00:53:56 +0000787 else
788 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher45547b82010-10-01 20:46:04 +0000789 TII.get(StrOpc))
790 .addReg(SrcReg).addReg(DstReg).addReg(0).addImm(Offset));
Eric Christopherac1a19e2010-09-09 01:06:51 +0000791
Eric Christopher318b6ee2010-09-02 00:53:56 +0000792 return true;
793}
794
Eric Christopher43b62be2010-09-27 06:02:23 +0000795bool ARMFastISel::SelectStore(const Instruction *I) {
Eric Christopher318b6ee2010-09-02 00:53:56 +0000796 Value *Op0 = I->getOperand(0);
797 unsigned SrcReg = 0;
798
Eric Christopher543cf052010-09-01 22:16:27 +0000799 // Yay type legalization
800 EVT VT;
Eric Christopher318b6ee2010-09-02 00:53:56 +0000801 if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT))
Eric Christopher543cf052010-09-01 22:16:27 +0000802 return false;
Eric Christopher318b6ee2010-09-02 00:53:56 +0000803
Eric Christopher1b61ef42010-09-02 01:48:11 +0000804 // Get the value to be stored into a register.
805 SrcReg = getRegForValue(Op0);
Eric Christopher318b6ee2010-09-02 00:53:56 +0000806 if (SrcReg == 0)
807 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000808
Eric Christopher318b6ee2010-09-02 00:53:56 +0000809 // If we're an alloca we know we have a frame index and can emit the store
810 // quickly.
Eric Christopher30b66332010-09-08 21:49:50 +0000811 if (ARMStoreAlloca(I, SrcReg, VT))
Eric Christopher318b6ee2010-09-02 00:53:56 +0000812 return true;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000813
Eric Christopher318b6ee2010-09-02 00:53:56 +0000814 // Our register and offset with innocuous defaults.
815 unsigned Reg = 0;
816 int Offset = 0;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000817
Eric Christopher318b6ee2010-09-02 00:53:56 +0000818 // See if we can handle this as Reg + Offset
819 if (!ARMComputeRegOffset(I->getOperand(1), Reg, Offset))
820 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000821
Eric Christopher318b6ee2010-09-02 00:53:56 +0000822 if (!ARMEmitStore(VT, SrcReg, Reg, Offset /* 0 */)) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000823
Eric Christophera5b1e682010-09-17 22:28:18 +0000824 return true;
825}
826
827static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) {
828 switch (Pred) {
829 // Needs two compares...
830 case CmpInst::FCMP_ONE:
831 case CmpInst::FCMP_UEQ:
832 default:
833 assert(false && "Unhandled CmpInst::Predicate!");
834 return ARMCC::AL;
835 case CmpInst::ICMP_EQ:
836 case CmpInst::FCMP_OEQ:
837 return ARMCC::EQ;
838 case CmpInst::ICMP_SGT:
839 case CmpInst::FCMP_OGT:
840 return ARMCC::GT;
841 case CmpInst::ICMP_SGE:
842 case CmpInst::FCMP_OGE:
843 return ARMCC::GE;
844 case CmpInst::ICMP_UGT:
845 case CmpInst::FCMP_UGT:
846 return ARMCC::HI;
847 case CmpInst::FCMP_OLT:
848 return ARMCC::MI;
849 case CmpInst::ICMP_ULE:
850 case CmpInst::FCMP_OLE:
851 return ARMCC::LS;
852 case CmpInst::FCMP_ORD:
853 return ARMCC::VC;
854 case CmpInst::FCMP_UNO:
855 return ARMCC::VS;
856 case CmpInst::FCMP_UGE:
857 return ARMCC::PL;
858 case CmpInst::ICMP_SLT:
859 case CmpInst::FCMP_ULT:
860 return ARMCC::LT;
861 case CmpInst::ICMP_SLE:
862 case CmpInst::FCMP_ULE:
863 return ARMCC::LE;
864 case CmpInst::FCMP_UNE:
865 case CmpInst::ICMP_NE:
866 return ARMCC::NE;
867 case CmpInst::ICMP_UGE:
868 return ARMCC::HS;
869 case CmpInst::ICMP_ULT:
870 return ARMCC::LO;
871 }
Eric Christopher543cf052010-09-01 22:16:27 +0000872}
873
Eric Christopher43b62be2010-09-27 06:02:23 +0000874bool ARMFastISel::SelectBranch(const Instruction *I) {
Eric Christophere5734102010-09-03 00:35:47 +0000875 const BranchInst *BI = cast<BranchInst>(I);
876 MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)];
877 MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)];
Eric Christopherac1a19e2010-09-09 01:06:51 +0000878
Eric Christophere5734102010-09-03 00:35:47 +0000879 // Simple branch support.
Eric Christopher229207a2010-09-29 01:14:47 +0000880 // TODO: Try to avoid the re-computation in some places.
881 unsigned CondReg = getRegForValue(BI->getCondition());
Eric Christophere5734102010-09-03 00:35:47 +0000882 if (CondReg == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000883
Eric Christopher229207a2010-09-29 01:14:47 +0000884 // Re-set the flags just in case.
885 unsigned CmpOpc = isThumb ? ARM::t2CMPri : ARM::CMPri;
886 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
887 .addReg(CondReg).addImm(1));
Eric Christophera5b1e682010-09-17 22:28:18 +0000888
Eric Christophere5734102010-09-03 00:35:47 +0000889 unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc;
Eric Christophere5734102010-09-03 00:35:47 +0000890 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc))
Eric Christopher229207a2010-09-29 01:14:47 +0000891 .addMBB(TBB).addImm(ARMCC::EQ).addReg(ARM::CPSR);
Eric Christophere5734102010-09-03 00:35:47 +0000892 FastEmitBranch(FBB, DL);
893 FuncInfo.MBB->addSuccessor(TBB);
Eric Christophera5b1e682010-09-17 22:28:18 +0000894 return true;
Eric Christophere5734102010-09-03 00:35:47 +0000895}
896
Eric Christopher43b62be2010-09-27 06:02:23 +0000897bool ARMFastISel::SelectCmp(const Instruction *I) {
Eric Christopherd43393a2010-09-08 23:13:45 +0000898 const CmpInst *CI = cast<CmpInst>(I);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000899
Eric Christopherd43393a2010-09-08 23:13:45 +0000900 EVT VT;
901 const Type *Ty = CI->getOperand(0)->getType();
902 if (!isTypeLegal(Ty, VT))
903 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000904
Eric Christopherd43393a2010-09-08 23:13:45 +0000905 bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
906 if (isFloat && !Subtarget->hasVFP2())
907 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000908
Eric Christopherd43393a2010-09-08 23:13:45 +0000909 unsigned CmpOpc;
Eric Christopher229207a2010-09-29 01:14:47 +0000910 unsigned CondReg;
Eric Christopherd43393a2010-09-08 23:13:45 +0000911 switch (VT.getSimpleVT().SimpleTy) {
912 default: return false;
913 // TODO: Verify compares.
914 case MVT::f32:
915 CmpOpc = ARM::VCMPES;
Eric Christopher229207a2010-09-29 01:14:47 +0000916 CondReg = ARM::FPSCR;
Eric Christopherd43393a2010-09-08 23:13:45 +0000917 break;
918 case MVT::f64:
919 CmpOpc = ARM::VCMPED;
Eric Christopher229207a2010-09-29 01:14:47 +0000920 CondReg = ARM::FPSCR;
Eric Christopherd43393a2010-09-08 23:13:45 +0000921 break;
922 case MVT::i32:
923 CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr;
Eric Christopher229207a2010-09-29 01:14:47 +0000924 CondReg = ARM::CPSR;
Eric Christopherd43393a2010-09-08 23:13:45 +0000925 break;
926 }
927
Eric Christopher229207a2010-09-29 01:14:47 +0000928 // Get the compare predicate.
929 ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate());
930
931 // We may not handle every CC for now.
932 if (ARMPred == ARMCC::AL) return false;
933
Eric Christopherd43393a2010-09-08 23:13:45 +0000934 unsigned Arg1 = getRegForValue(CI->getOperand(0));
935 if (Arg1 == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000936
Eric Christopherd43393a2010-09-08 23:13:45 +0000937 unsigned Arg2 = getRegForValue(CI->getOperand(1));
938 if (Arg2 == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000939
Eric Christopherd43393a2010-09-08 23:13:45 +0000940 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
941 .addReg(Arg1).addReg(Arg2));
Eric Christopherac1a19e2010-09-09 01:06:51 +0000942
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000943 // For floating point we need to move the result to a comparison register
944 // that we can then use for branches.
Eric Christopherd43393a2010-09-08 23:13:45 +0000945 if (isFloat)
946 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
947 TII.get(ARM::FMSTAT)));
Eric Christopherce07b542010-09-09 20:26:31 +0000948
Eric Christopher229207a2010-09-29 01:14:47 +0000949 // Now set a register based on the comparison. Explicitly set the predicates
950 // here.
Eric Christopher338c2532010-10-07 05:31:49 +0000951 unsigned MovCCOpc = isThumb ? ARM::t2MOVCCi : ARM::MOVCCi;
Eric Christopher5d18d922010-10-07 05:39:19 +0000952 TargetRegisterClass *RC = isThumb ? ARM::rGPRRegisterClass
953 : ARM::GPRRegisterClass;
954 unsigned DestReg = createResultReg(RC);
Eric Christopher229207a2010-09-29 01:14:47 +0000955 Constant *Zero
Eric Christopher8cf6c602010-09-29 22:24:45 +0000956 = ConstantInt::get(Type::getInt32Ty(*Context), 0);
Eric Christopher229207a2010-09-29 01:14:47 +0000957 unsigned ZeroReg = TargetMaterializeConstant(Zero);
958 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), DestReg)
959 .addReg(ZeroReg).addImm(1)
960 .addImm(ARMPred).addReg(CondReg);
961
Eric Christophera5b1e682010-09-17 22:28:18 +0000962 UpdateValueMap(I, DestReg);
Eric Christopherd43393a2010-09-08 23:13:45 +0000963 return true;
964}
965
Eric Christopher43b62be2010-09-27 06:02:23 +0000966bool ARMFastISel::SelectFPExt(const Instruction *I) {
Eric Christopher46203602010-09-09 00:26:48 +0000967 // Make sure we have VFP and that we're extending float to double.
968 if (!Subtarget->hasVFP2()) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000969
Eric Christopher46203602010-09-09 00:26:48 +0000970 Value *V = I->getOperand(0);
971 if (!I->getType()->isDoubleTy() ||
972 !V->getType()->isFloatTy()) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000973
Eric Christopher46203602010-09-09 00:26:48 +0000974 unsigned Op = getRegForValue(V);
975 if (Op == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000976
Eric Christopher46203602010-09-09 00:26:48 +0000977 unsigned Result = createResultReg(ARM::DPRRegisterClass);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000978 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopheref2fdd22010-09-09 20:36:19 +0000979 TII.get(ARM::VCVTDS), Result)
Eric Christopherce07b542010-09-09 20:26:31 +0000980 .addReg(Op));
981 UpdateValueMap(I, Result);
982 return true;
983}
984
Eric Christopher43b62be2010-09-27 06:02:23 +0000985bool ARMFastISel::SelectFPTrunc(const Instruction *I) {
Eric Christopherce07b542010-09-09 20:26:31 +0000986 // Make sure we have VFP and that we're truncating double to float.
987 if (!Subtarget->hasVFP2()) return false;
988
989 Value *V = I->getOperand(0);
Eric Christopher022b7fb2010-10-05 23:13:24 +0000990 if (!(I->getType()->isFloatTy() &&
991 V->getType()->isDoubleTy())) return false;
Eric Christopherce07b542010-09-09 20:26:31 +0000992
993 unsigned Op = getRegForValue(V);
994 if (Op == 0) return false;
995
996 unsigned Result = createResultReg(ARM::SPRRegisterClass);
Eric Christopherce07b542010-09-09 20:26:31 +0000997 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopheref2fdd22010-09-09 20:36:19 +0000998 TII.get(ARM::VCVTSD), Result)
Eric Christopher46203602010-09-09 00:26:48 +0000999 .addReg(Op));
1000 UpdateValueMap(I, Result);
1001 return true;
1002}
1003
Eric Christopher43b62be2010-09-27 06:02:23 +00001004bool ARMFastISel::SelectSIToFP(const Instruction *I) {
Eric Christopher9a040492010-09-09 18:54:59 +00001005 // Make sure we have VFP.
1006 if (!Subtarget->hasVFP2()) return false;
1007
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001008 EVT DstVT;
Eric Christopher9a040492010-09-09 18:54:59 +00001009 const Type *Ty = I->getType();
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001010 if (!isTypeLegal(Ty, DstVT))
Eric Christopher9a040492010-09-09 18:54:59 +00001011 return false;
1012
1013 unsigned Op = getRegForValue(I->getOperand(0));
1014 if (Op == 0) return false;
1015
Eric Christopherdb12b2b2010-09-10 00:34:35 +00001016 // The conversion routine works on fp-reg to fp-reg and the operand above
1017 // was an integer, move it to the fp registers if possible.
Eric Christopher022b7fb2010-10-05 23:13:24 +00001018 unsigned FP = ARMMoveToFPReg(MVT::f32, Op);
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001019 if (FP == 0) return false;
1020
Eric Christopher9a040492010-09-09 18:54:59 +00001021 unsigned Opc;
1022 if (Ty->isFloatTy()) Opc = ARM::VSITOS;
1023 else if (Ty->isDoubleTy()) Opc = ARM::VSITOD;
1024 else return 0;
1025
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001026 unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT));
Eric Christopher9a040492010-09-09 18:54:59 +00001027 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
1028 ResultReg)
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001029 .addReg(FP));
Eric Christopherce07b542010-09-09 20:26:31 +00001030 UpdateValueMap(I, ResultReg);
Eric Christopher9a040492010-09-09 18:54:59 +00001031 return true;
1032}
1033
Eric Christopher43b62be2010-09-27 06:02:23 +00001034bool ARMFastISel::SelectFPToSI(const Instruction *I) {
Eric Christopher9a040492010-09-09 18:54:59 +00001035 // Make sure we have VFP.
1036 if (!Subtarget->hasVFP2()) return false;
1037
Eric Christopherdb12b2b2010-09-10 00:34:35 +00001038 EVT DstVT;
Eric Christopher9a040492010-09-09 18:54:59 +00001039 const Type *RetTy = I->getType();
Eric Christopher920a2082010-09-10 00:35:09 +00001040 if (!isTypeLegal(RetTy, DstVT))
Eric Christopher9a040492010-09-09 18:54:59 +00001041 return false;
1042
1043 unsigned Op = getRegForValue(I->getOperand(0));
1044 if (Op == 0) return false;
1045
1046 unsigned Opc;
1047 const Type *OpTy = I->getOperand(0)->getType();
1048 if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS;
1049 else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD;
1050 else return 0;
1051
Eric Christopher022b7fb2010-10-05 23:13:24 +00001052 // f64->s32 or f32->s32 both need an intermediate f32 reg.
1053 unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32));
Eric Christopher9a040492010-09-09 18:54:59 +00001054 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
1055 ResultReg)
1056 .addReg(Op));
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001057
1058 // This result needs to be in an integer register, but the conversion only
1059 // takes place in fp-regs.
Eric Christopherdb12b2b2010-09-10 00:34:35 +00001060 unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg);
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001061 if (IntReg == 0) return false;
1062
1063 UpdateValueMap(I, IntReg);
Eric Christopher9a040492010-09-09 18:54:59 +00001064 return true;
1065}
1066
Eric Christopher3bbd3962010-10-11 08:27:59 +00001067bool ARMFastISel::SelectSelect(const Instruction *I) {
1068 EVT VT = TLI.getValueType(I->getType(), /*HandleUnknown=*/true);
1069 if (VT == MVT::Other || !isTypeLegal(I->getType(), VT))
1070 return false;
1071
1072 // Things need to be register sized for register moves.
1073 if (VT.getSimpleVT().SimpleTy != MVT::i32) return false;
1074 const TargetRegisterClass *RC = TLI.getRegClassFor(VT);
1075
1076 unsigned CondReg = getRegForValue(I->getOperand(0));
1077 if (CondReg == 0) return false;
1078 unsigned Op1Reg = getRegForValue(I->getOperand(1));
1079 if (Op1Reg == 0) return false;
1080 unsigned Op2Reg = getRegForValue(I->getOperand(2));
1081 if (Op2Reg == 0) return false;
1082
1083 unsigned CmpOpc = isThumb ? ARM::t2TSTri : ARM::TSTri;
1084 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
1085 .addReg(CondReg).addImm(1));
1086 unsigned ResultReg = createResultReg(RC);
1087 unsigned MovCCOpc = isThumb ? ARM::t2MOVCCr : ARM::MOVCCr;
1088 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), ResultReg)
1089 .addReg(Op1Reg).addReg(Op2Reg)
1090 .addImm(ARMCC::EQ).addReg(ARM::CPSR);
1091 UpdateValueMap(I, ResultReg);
1092 return true;
1093}
1094
Eric Christopher08637852010-09-30 22:34:19 +00001095bool ARMFastISel::SelectSDiv(const Instruction *I) {
1096 EVT VT;
1097 const Type *Ty = I->getType();
1098 if (!isTypeLegal(Ty, VT))
1099 return false;
1100
1101 // If we have integer div support we should have selected this automagically.
1102 // In case we have a real miss go ahead and return false and we'll pick
1103 // it up later.
1104 if (Subtarget->hasDivide()) return false;
1105
1106 // Otherwise emit a libcall.
1107 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1108 if (VT == MVT::i16)
1109 LC = RTLIB::SDIV_I16;
1110 else if (VT == MVT::i32)
1111 LC = RTLIB::SDIV_I32;
1112 else if (VT == MVT::i64)
1113 LC = RTLIB::SDIV_I64;
1114 else if (VT == MVT::i128)
1115 LC = RTLIB::SDIV_I128;
1116 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!");
1117
1118 return ARMEmitLibcall(I, LC);
1119}
1120
Eric Christopher43b62be2010-09-27 06:02:23 +00001121bool ARMFastISel::SelectBinaryOp(const Instruction *I, unsigned ISDOpcode) {
Eric Christopherbd6bf082010-09-09 01:02:03 +00001122 EVT VT = TLI.getValueType(I->getType(), true);
Eric Christopherac1a19e2010-09-09 01:06:51 +00001123
Eric Christopherbc39b822010-09-09 00:53:57 +00001124 // We can get here in the case when we want to use NEON for our fp
1125 // operations, but can't figure out how to. Just use the vfp instructions
1126 // if we have them.
1127 // FIXME: It'd be nice to use NEON instructions.
Eric Christopherbd6bf082010-09-09 01:02:03 +00001128 const Type *Ty = I->getType();
1129 bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
1130 if (isFloat && !Subtarget->hasVFP2())
1131 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001132
Eric Christopherbc39b822010-09-09 00:53:57 +00001133 unsigned Op1 = getRegForValue(I->getOperand(0));
1134 if (Op1 == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001135
Eric Christopherbc39b822010-09-09 00:53:57 +00001136 unsigned Op2 = getRegForValue(I->getOperand(1));
1137 if (Op2 == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001138
Eric Christopherbc39b822010-09-09 00:53:57 +00001139 unsigned Opc;
Eric Christopherbd6bf082010-09-09 01:02:03 +00001140 bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64 ||
1141 VT.getSimpleVT().SimpleTy == MVT::i64;
Eric Christopherbc39b822010-09-09 00:53:57 +00001142 switch (ISDOpcode) {
1143 default: return false;
1144 case ISD::FADD:
Eric Christopherbd6bf082010-09-09 01:02:03 +00001145 Opc = is64bit ? ARM::VADDD : ARM::VADDS;
Eric Christopherbc39b822010-09-09 00:53:57 +00001146 break;
1147 case ISD::FSUB:
Eric Christopherbd6bf082010-09-09 01:02:03 +00001148 Opc = is64bit ? ARM::VSUBD : ARM::VSUBS;
Eric Christopherbc39b822010-09-09 00:53:57 +00001149 break;
1150 case ISD::FMUL:
Eric Christopherbd6bf082010-09-09 01:02:03 +00001151 Opc = is64bit ? ARM::VMULD : ARM::VMULS;
Eric Christopherbc39b822010-09-09 00:53:57 +00001152 break;
1153 }
Eric Christopherbd6bf082010-09-09 01:02:03 +00001154 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
Eric Christopherbc39b822010-09-09 00:53:57 +00001155 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1156 TII.get(Opc), ResultReg)
1157 .addReg(Op1).addReg(Op2));
Eric Christopherce07b542010-09-09 20:26:31 +00001158 UpdateValueMap(I, ResultReg);
Eric Christopherbc39b822010-09-09 00:53:57 +00001159 return true;
1160}
1161
Eric Christopherd10cd7b2010-09-10 23:18:12 +00001162// Call Handling Code
1163
1164// This is largely taken directly from CCAssignFnForNode - we don't support
1165// varargs in FastISel so that part has been removed.
1166// TODO: We may not support all of this.
1167CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) {
1168 switch (CC) {
1169 default:
1170 llvm_unreachable("Unsupported calling convention");
1171 case CallingConv::C:
1172 case CallingConv::Fast:
1173 // Use target triple & subtarget features to do actual dispatch.
1174 if (Subtarget->isAAPCS_ABI()) {
1175 if (Subtarget->hasVFP2() &&
1176 FloatABIType == FloatABI::Hard)
1177 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
1178 else
1179 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
1180 } else
1181 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1182 case CallingConv::ARM_AAPCS_VFP:
1183 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
1184 case CallingConv::ARM_AAPCS:
1185 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
1186 case CallingConv::ARM_APCS:
1187 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1188 }
1189}
1190
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001191bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args,
1192 SmallVectorImpl<unsigned> &ArgRegs,
1193 SmallVectorImpl<EVT> &ArgVTs,
1194 SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
1195 SmallVectorImpl<unsigned> &RegArgs,
1196 CallingConv::ID CC,
1197 unsigned &NumBytes) {
1198 SmallVector<CCValAssign, 16> ArgLocs;
1199 CCState CCInfo(CC, false, TM, ArgLocs, *Context);
1200 CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC, false));
1201
1202 // Get a count of how many bytes are to be pushed on the stack.
1203 NumBytes = CCInfo.getNextStackOffset();
1204
1205 // Issue CALLSEQ_START
1206 unsigned AdjStackDown = TM.getRegisterInfo()->getCallFrameSetupOpcode();
1207 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(AdjStackDown))
1208 .addImm(NumBytes);
1209
1210 // Process the args.
1211 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1212 CCValAssign &VA = ArgLocs[i];
1213 unsigned Arg = ArgRegs[VA.getValNo()];
1214 EVT ArgVT = ArgVTs[VA.getValNo()];
1215
Eric Christopherf9764fa2010-09-30 20:49:44 +00001216 // Handle arg promotion, etc.
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001217 switch (VA.getLocInfo()) {
1218 case CCValAssign::Full: break;
1219 default:
Eric Christopher11077342010-10-07 05:14:08 +00001220 // TODO: Handle arg promotion.
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001221 return false;
1222 }
1223
1224 // Now copy/store arg to correct locations.
1225 if (VA.isRegLoc()) {
1226 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
Eric Christopherf9764fa2010-09-30 20:49:44 +00001227 VA.getLocReg())
1228 .addReg(Arg);
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001229 RegArgs.push_back(VA.getLocReg());
1230 } else {
1231 // Need to store
1232 return false;
1233 }
1234 }
1235
1236 return true;
1237}
1238
1239bool ARMFastISel::FinishCall(EVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
1240 const Instruction *I, CallingConv::ID CC,
1241 unsigned &NumBytes) {
1242 // Issue CALLSEQ_END
1243 unsigned AdjStackUp = TM.getRegisterInfo()->getCallFrameDestroyOpcode();
1244 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(AdjStackUp))
1245 .addImm(NumBytes).addImm(0);
1246
1247 // Now the return value.
1248 if (RetVT.getSimpleVT().SimpleTy != MVT::isVoid) {
1249 SmallVector<CCValAssign, 16> RVLocs;
1250 CCState CCInfo(CC, false, TM, RVLocs, *Context);
1251 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true));
1252
1253 // Copy all of the result registers out of their specified physreg.
Eric Christopher14df8822010-10-01 00:00:11 +00001254 if (RVLocs.size() == 2 && RetVT.getSimpleVT().SimpleTy == MVT::f64) {
1255 // For this move we copy into two registers and then move into the
1256 // double fp reg we want.
1257 // TODO: Are the copies necessary?
1258 TargetRegisterClass *CopyRC = TLI.getRegClassFor(MVT::i32);
1259 unsigned Copy1 = createResultReg(CopyRC);
1260 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
1261 Copy1).addReg(RVLocs[0].getLocReg());
1262 UsedRegs.push_back(RVLocs[0].getLocReg());
1263
1264 unsigned Copy2 = createResultReg(CopyRC);
1265 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
1266 Copy2).addReg(RVLocs[1].getLocReg());
1267 UsedRegs.push_back(RVLocs[1].getLocReg());
1268
1269 EVT DestVT = RVLocs[0].getValVT();
1270 TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT);
1271 unsigned ResultReg = createResultReg(DstRC);
1272 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1273 TII.get(ARM::VMOVDRR), ResultReg)
1274 .addReg(Copy1).addReg(Copy2));
1275
1276 // Finally update the result.
1277 UpdateValueMap(I, ResultReg);
1278 } else {
1279 assert(RVLocs.size() == 1 && "Can't handle non-double multi-reg retvals!");
1280 EVT CopyVT = RVLocs[0].getValVT();
1281 TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT);
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001282
Eric Christopher14df8822010-10-01 00:00:11 +00001283 unsigned ResultReg = createResultReg(DstRC);
1284 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
1285 ResultReg).addReg(RVLocs[0].getLocReg());
1286 UsedRegs.push_back(RVLocs[0].getLocReg());
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001287
Eric Christopher14df8822010-10-01 00:00:11 +00001288 // Finally update the result.
1289 UpdateValueMap(I, ResultReg);
1290 }
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001291 }
1292
1293 return true;
1294}
1295
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001296// A quick function that will emit a call for a named libcall in F with the
1297// vector of passed arguments for the Instruction in I. We can assume that we
1298// can emit a call for any libcall we can produce. This is an abridged version
1299// of the full call infrastructure since we won't need to worry about things
1300// like computed function pointers or strange arguments at call sites.
1301// TODO: Try to unify this and the normal call bits for ARM, then try to unify
1302// with X86.
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001303bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) {
1304 CallingConv::ID CC = TLI.getLibcallCallingConv(Call);
1305
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001306 // Handle *simple* calls for now.
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001307 const Type *RetTy = I->getType();
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001308 EVT RetVT;
1309 if (RetTy->isVoidTy())
1310 RetVT = MVT::isVoid;
1311 else if (!isTypeLegal(RetTy, RetVT))
1312 return false;
1313
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001314 // For now we're using BLX etc on the assumption that we have v5t ops.
1315 if (!Subtarget->hasV5TOps()) return false;
1316
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001317 // Set up the argument vectors.
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001318 SmallVector<Value*, 8> Args;
1319 SmallVector<unsigned, 8> ArgRegs;
1320 SmallVector<EVT, 8> ArgVTs;
1321 SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
1322 Args.reserve(I->getNumOperands());
1323 ArgRegs.reserve(I->getNumOperands());
1324 ArgVTs.reserve(I->getNumOperands());
1325 ArgFlags.reserve(I->getNumOperands());
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001326 for (unsigned i = 0; i < I->getNumOperands(); ++i) {
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001327 Value *Op = I->getOperand(i);
1328 unsigned Arg = getRegForValue(Op);
1329 if (Arg == 0) return false;
1330
1331 const Type *ArgTy = Op->getType();
1332 EVT ArgVT;
1333 if (!isTypeLegal(ArgTy, ArgVT)) return false;
1334
1335 ISD::ArgFlagsTy Flags;
1336 unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy);
1337 Flags.setOrigAlign(OriginalAlignment);
1338
1339 Args.push_back(Op);
1340 ArgRegs.push_back(Arg);
1341 ArgVTs.push_back(ArgVT);
1342 ArgFlags.push_back(Flags);
1343 }
1344
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001345 // Handle the arguments now that we've gotten them.
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001346 SmallVector<unsigned, 4> RegArgs;
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001347 unsigned NumBytes;
1348 if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes))
1349 return false;
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001350
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001351 // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops.
1352 // TODO: Turn this into the table of arm call ops.
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001353 MachineInstrBuilder MIB;
Eric Christopherc1095562010-09-18 02:32:38 +00001354 unsigned CallOpc;
1355 if(isThumb)
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001356 CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi;
Eric Christopherc1095562010-09-18 02:32:38 +00001357 else
1358 CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL;
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001359 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CallOpc))
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001360 .addExternalSymbol(TLI.getLibcallName(Call));
1361
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001362 // Add implicit physical register uses to the call.
1363 for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
1364 MIB.addReg(RegArgs[i]);
1365
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001366 // Finish off the call including any return values.
1367 SmallVector<unsigned, 4> UsedRegs;
1368 if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false;
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001369
1370 // Set all unused physreg defs as dead.
1371 static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001372
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001373 return true;
1374}
1375
Eric Christopherf9764fa2010-09-30 20:49:44 +00001376bool ARMFastISel::SelectCall(const Instruction *I) {
1377 const CallInst *CI = cast<CallInst>(I);
1378 const Value *Callee = CI->getCalledValue();
1379
1380 // Can't handle inline asm or worry about intrinsics yet.
1381 if (isa<InlineAsm>(Callee) || isa<IntrinsicInst>(CI)) return false;
1382
Eric Christophere6ca6772010-10-01 21:33:12 +00001383 // Only handle global variable Callees that are direct calls.
Eric Christopherf9764fa2010-09-30 20:49:44 +00001384 const GlobalValue *GV = dyn_cast<GlobalValue>(Callee);
Eric Christophere6ca6772010-10-01 21:33:12 +00001385 if (!GV || Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel()))
1386 return false;
Eric Christopherf9764fa2010-09-30 20:49:44 +00001387
1388 // Check the calling convention.
1389 ImmutableCallSite CS(CI);
1390 CallingConv::ID CC = CS.getCallingConv();
1391 // TODO: Avoid some calling conventions?
1392 if (CC != CallingConv::C) {
Eric Christophere540a6f2010-10-05 23:50:58 +00001393 // errs() << "Can't handle calling convention: " << CC << "\n";
Eric Christopherf9764fa2010-09-30 20:49:44 +00001394 return false;
1395 }
1396
1397 // Let SDISel handle vararg functions.
1398 const PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType());
1399 const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
1400 if (FTy->isVarArg())
1401 return false;
1402
1403 // Handle *simple* calls for now.
1404 const Type *RetTy = I->getType();
1405 EVT RetVT;
1406 if (RetTy->isVoidTy())
1407 RetVT = MVT::isVoid;
1408 else if (!isTypeLegal(RetTy, RetVT))
1409 return false;
1410
1411 // For now we're using BLX etc on the assumption that we have v5t ops.
1412 // TODO: Maybe?
1413 if (!Subtarget->hasV5TOps()) return false;
1414
1415 // Set up the argument vectors.
1416 SmallVector<Value*, 8> Args;
1417 SmallVector<unsigned, 8> ArgRegs;
1418 SmallVector<EVT, 8> ArgVTs;
1419 SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
1420 Args.reserve(CS.arg_size());
1421 ArgRegs.reserve(CS.arg_size());
1422 ArgVTs.reserve(CS.arg_size());
1423 ArgFlags.reserve(CS.arg_size());
1424 for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
1425 i != e; ++i) {
1426 unsigned Arg = getRegForValue(*i);
1427
1428 if (Arg == 0)
1429 return false;
1430 ISD::ArgFlagsTy Flags;
1431 unsigned AttrInd = i - CS.arg_begin() + 1;
1432 if (CS.paramHasAttr(AttrInd, Attribute::SExt))
1433 Flags.setSExt();
1434 if (CS.paramHasAttr(AttrInd, Attribute::ZExt))
1435 Flags.setZExt();
1436
1437 // FIXME: Only handle *easy* calls for now.
1438 if (CS.paramHasAttr(AttrInd, Attribute::InReg) ||
1439 CS.paramHasAttr(AttrInd, Attribute::StructRet) ||
1440 CS.paramHasAttr(AttrInd, Attribute::Nest) ||
1441 CS.paramHasAttr(AttrInd, Attribute::ByVal))
1442 return false;
1443
1444 const Type *ArgTy = (*i)->getType();
1445 EVT ArgVT;
1446 if (!isTypeLegal(ArgTy, ArgVT))
1447 return false;
1448 unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy);
1449 Flags.setOrigAlign(OriginalAlignment);
1450
1451 Args.push_back(*i);
1452 ArgRegs.push_back(Arg);
1453 ArgVTs.push_back(ArgVT);
1454 ArgFlags.push_back(Flags);
1455 }
1456
1457 // Handle the arguments now that we've gotten them.
1458 SmallVector<unsigned, 4> RegArgs;
1459 unsigned NumBytes;
1460 if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes))
1461 return false;
1462
1463 // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops.
1464 // TODO: Turn this into the table of arm call ops.
1465 MachineInstrBuilder MIB;
1466 unsigned CallOpc;
1467 if(isThumb)
1468 CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi;
1469 else
1470 CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL;
1471 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CallOpc))
1472 .addGlobalAddress(GV, 0, 0);
1473
1474 // Add implicit physical register uses to the call.
1475 for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
1476 MIB.addReg(RegArgs[i]);
1477
1478 // Finish off the call including any return values.
1479 SmallVector<unsigned, 4> UsedRegs;
1480 if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false;
1481
1482 // Set all unused physreg defs as dead.
1483 static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
1484
1485 return true;
1486
1487}
1488
Eric Christopher56d2b722010-09-02 23:43:26 +00001489// TODO: SoftFP support.
Eric Christopherab695882010-07-21 22:26:11 +00001490bool ARMFastISel::TargetSelectInstruction(const Instruction *I) {
Eric Christopher7fe55b72010-08-23 22:32:45 +00001491 // No Thumb-1 for now.
Eric Christophereaa204b2010-09-02 01:39:14 +00001492 if (isThumb && !AFI->isThumb2Function()) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001493
Eric Christopherab695882010-07-21 22:26:11 +00001494 switch (I->getOpcode()) {
Eric Christopher83007122010-08-23 21:44:12 +00001495 case Instruction::Load:
Eric Christopher43b62be2010-09-27 06:02:23 +00001496 return SelectLoad(I);
Eric Christopher543cf052010-09-01 22:16:27 +00001497 case Instruction::Store:
Eric Christopher43b62be2010-09-27 06:02:23 +00001498 return SelectStore(I);
Eric Christophere5734102010-09-03 00:35:47 +00001499 case Instruction::Br:
Eric Christopher43b62be2010-09-27 06:02:23 +00001500 return SelectBranch(I);
Eric Christopherd43393a2010-09-08 23:13:45 +00001501 case Instruction::ICmp:
1502 case Instruction::FCmp:
Eric Christopher43b62be2010-09-27 06:02:23 +00001503 return SelectCmp(I);
Eric Christopher46203602010-09-09 00:26:48 +00001504 case Instruction::FPExt:
Eric Christopher43b62be2010-09-27 06:02:23 +00001505 return SelectFPExt(I);
Eric Christopherce07b542010-09-09 20:26:31 +00001506 case Instruction::FPTrunc:
Eric Christopher43b62be2010-09-27 06:02:23 +00001507 return SelectFPTrunc(I);
Eric Christopher9a040492010-09-09 18:54:59 +00001508 case Instruction::SIToFP:
Eric Christopher43b62be2010-09-27 06:02:23 +00001509 return SelectSIToFP(I);
Eric Christopher9a040492010-09-09 18:54:59 +00001510 case Instruction::FPToSI:
Eric Christopher43b62be2010-09-27 06:02:23 +00001511 return SelectFPToSI(I);
Eric Christopherbc39b822010-09-09 00:53:57 +00001512 case Instruction::FAdd:
Eric Christopher43b62be2010-09-27 06:02:23 +00001513 return SelectBinaryOp(I, ISD::FADD);
Eric Christopherbc39b822010-09-09 00:53:57 +00001514 case Instruction::FSub:
Eric Christopher43b62be2010-09-27 06:02:23 +00001515 return SelectBinaryOp(I, ISD::FSUB);
Eric Christopherbc39b822010-09-09 00:53:57 +00001516 case Instruction::FMul:
Eric Christopher43b62be2010-09-27 06:02:23 +00001517 return SelectBinaryOp(I, ISD::FMUL);
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001518 case Instruction::SDiv:
Eric Christopher43b62be2010-09-27 06:02:23 +00001519 return SelectSDiv(I);
Eric Christopherf9764fa2010-09-30 20:49:44 +00001520 case Instruction::Call:
1521 return SelectCall(I);
Eric Christopher3bbd3962010-10-11 08:27:59 +00001522 case Instruction::Select:
1523 return SelectSelect(I);
Eric Christopherab695882010-07-21 22:26:11 +00001524 default: break;
1525 }
1526 return false;
1527}
1528
1529namespace llvm {
1530 llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) {
Eric Christopher038fea52010-08-17 00:46:57 +00001531 if (EnableARMFastISel) return new ARMFastISel(funcInfo);
Evan Cheng09447952010-07-26 18:32:55 +00001532 return 0;
Eric Christopherab695882010-07-21 22:26:11 +00001533 }
1534}