blob: ed9586897a85b8ecd7cdafea84a3f10a6ca347c7 [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"
Eli Friedmanc573e2c2011-04-29 22:48:03 +000017#include "ARMAddressingModes.h"
Eric Christopher456144e2010-08-19 00:37:05 +000018#include "ARMBaseInstrInfo.h"
Eric Christopherd10cd7b2010-09-10 23:18:12 +000019#include "ARMCallingConv.h"
Eric Christopherab695882010-07-21 22:26:11 +000020#include "ARMRegisterInfo.h"
21#include "ARMTargetMachine.h"
22#include "ARMSubtarget.h"
Eric Christopherc9932f62010-10-01 23:24:42 +000023#include "ARMConstantPoolValue.h"
Eric Christopherab695882010-07-21 22:26:11 +000024#include "llvm/CallingConv.h"
25#include "llvm/DerivedTypes.h"
26#include "llvm/GlobalVariable.h"
27#include "llvm/Instructions.h"
28#include "llvm/IntrinsicInst.h"
Eric Christopherbb3e5da2010-09-14 23:03:37 +000029#include "llvm/Module.h"
Jay Foad562b84b2011-04-11 09:35:34 +000030#include "llvm/Operator.h"
Eric Christopherab695882010-07-21 22:26:11 +000031#include "llvm/CodeGen/Analysis.h"
32#include "llvm/CodeGen/FastISel.h"
33#include "llvm/CodeGen/FunctionLoweringInfo.h"
Eric Christopher0fe7d542010-08-17 01:25:29 +000034#include "llvm/CodeGen/MachineInstrBuilder.h"
35#include "llvm/CodeGen/MachineModuleInfo.h"
Eric Christopherab695882010-07-21 22:26:11 +000036#include "llvm/CodeGen/MachineConstantPool.h"
37#include "llvm/CodeGen/MachineFrameInfo.h"
Eric Christopherd56d61a2010-10-17 01:51:42 +000038#include "llvm/CodeGen/MachineMemOperand.h"
Eric Christopherab695882010-07-21 22:26:11 +000039#include "llvm/CodeGen/MachineRegisterInfo.h"
Eric Christopherd56d61a2010-10-17 01:51:42 +000040#include "llvm/CodeGen/PseudoSourceValue.h"
Eric Christopherab695882010-07-21 22:26:11 +000041#include "llvm/Support/CallSite.h"
Eric Christopher038fea52010-08-17 00:46:57 +000042#include "llvm/Support/CommandLine.h"
Eric Christopherab695882010-07-21 22:26:11 +000043#include "llvm/Support/ErrorHandling.h"
44#include "llvm/Support/GetElementPtrTypeIterator.h"
Eric Christopher0fe7d542010-08-17 01:25:29 +000045#include "llvm/Target/TargetData.h"
46#include "llvm/Target/TargetInstrInfo.h"
47#include "llvm/Target/TargetLowering.h"
48#include "llvm/Target/TargetMachine.h"
Eric Christopherab695882010-07-21 22:26:11 +000049#include "llvm/Target/TargetOptions.h"
50using namespace llvm;
51
Eric Christopher038fea52010-08-17 00:46:57 +000052static cl::opt<bool>
Eric Christopher6e5367d2010-10-18 22:53:53 +000053DisableARMFastISel("disable-arm-fast-isel",
54 cl::desc("Turn off experimental ARM fast-isel support"),
Eric Christopherfeadddd2010-10-11 20:05:22 +000055 cl::init(false), cl::Hidden);
Eric Christopher038fea52010-08-17 00:46:57 +000056
Eric Christopher836c6242010-12-15 23:47:29 +000057extern cl::opt<bool> EnableARMLongCalls;
58
Eric Christopherab695882010-07-21 22:26:11 +000059namespace {
Eric Christopher827656d2010-11-20 22:38:27 +000060
Eric Christopher0d581222010-11-19 22:30:02 +000061 // All possible address modes, plus some.
62 typedef struct Address {
63 enum {
64 RegBase,
65 FrameIndexBase
66 } BaseType;
Eric Christopher827656d2010-11-20 22:38:27 +000067
Eric Christopher0d581222010-11-19 22:30:02 +000068 union {
69 unsigned Reg;
70 int FI;
71 } Base;
Eric Christopher827656d2010-11-20 22:38:27 +000072
Eric Christopher0d581222010-11-19 22:30:02 +000073 int Offset;
Eric Christopher827656d2010-11-20 22:38:27 +000074
Eric Christopher0d581222010-11-19 22:30:02 +000075 // Innocuous defaults for our address.
76 Address()
Jim Grosbach0c720762011-05-16 22:24:07 +000077 : BaseType(RegBase), Offset(0) {
Eric Christopher0d581222010-11-19 22:30:02 +000078 Base.Reg = 0;
79 }
80 } Address;
Eric Christopherab695882010-07-21 22:26:11 +000081
82class ARMFastISel : public FastISel {
83
84 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
85 /// make the right decision when generating code for different targets.
86 const ARMSubtarget *Subtarget;
Eric Christopher0fe7d542010-08-17 01:25:29 +000087 const TargetMachine &TM;
88 const TargetInstrInfo &TII;
89 const TargetLowering &TLI;
Eric Christopherc9932f62010-10-01 23:24:42 +000090 ARMFunctionInfo *AFI;
Eric Christopherab695882010-07-21 22:26:11 +000091
Eric Christopher8cf6c602010-09-29 22:24:45 +000092 // Convenience variables to avoid some queries.
Eric Christophereaa204b2010-09-02 01:39:14 +000093 bool isThumb;
Eric Christopher8cf6c602010-09-29 22:24:45 +000094 LLVMContext *Context;
Eric Christophereaa204b2010-09-02 01:39:14 +000095
Eric Christopherab695882010-07-21 22:26:11 +000096 public:
Eric Christopherac1a19e2010-09-09 01:06:51 +000097 explicit ARMFastISel(FunctionLoweringInfo &funcInfo)
Eric Christopher0fe7d542010-08-17 01:25:29 +000098 : FastISel(funcInfo),
99 TM(funcInfo.MF->getTarget()),
100 TII(*TM.getInstrInfo()),
101 TLI(*TM.getTargetLowering()) {
Eric Christopherab695882010-07-21 22:26:11 +0000102 Subtarget = &TM.getSubtarget<ARMSubtarget>();
Eric Christopher7fe55b72010-08-23 22:32:45 +0000103 AFI = funcInfo.MF->getInfo<ARMFunctionInfo>();
Eric Christophereaa204b2010-09-02 01:39:14 +0000104 isThumb = AFI->isThumbFunction();
Eric Christopher8cf6c602010-09-29 22:24:45 +0000105 Context = &funcInfo.Fn->getContext();
Eric Christopherab695882010-07-21 22:26:11 +0000106 }
107
Eric Christophercb592292010-08-20 00:20:31 +0000108 // Code from FastISel.cpp.
Eric Christopher0fe7d542010-08-17 01:25:29 +0000109 virtual unsigned FastEmitInst_(unsigned MachineInstOpcode,
110 const TargetRegisterClass *RC);
111 virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode,
112 const TargetRegisterClass *RC,
113 unsigned Op0, bool Op0IsKill);
114 virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
115 const TargetRegisterClass *RC,
116 unsigned Op0, bool Op0IsKill,
117 unsigned Op1, bool Op1IsKill);
Cameron Zwarichc0e6d782011-03-30 23:01:21 +0000118 virtual unsigned FastEmitInst_rrr(unsigned MachineInstOpcode,
119 const TargetRegisterClass *RC,
120 unsigned Op0, bool Op0IsKill,
121 unsigned Op1, bool Op1IsKill,
122 unsigned Op2, bool Op2IsKill);
Eric Christopher0fe7d542010-08-17 01:25:29 +0000123 virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
124 const TargetRegisterClass *RC,
125 unsigned Op0, bool Op0IsKill,
126 uint64_t Imm);
127 virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode,
128 const TargetRegisterClass *RC,
129 unsigned Op0, bool Op0IsKill,
130 const ConstantFP *FPImm);
Eric Christopher0fe7d542010-08-17 01:25:29 +0000131 virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
132 const TargetRegisterClass *RC,
133 unsigned Op0, bool Op0IsKill,
134 unsigned Op1, bool Op1IsKill,
135 uint64_t Imm);
Eric Christopheraf3dce52011-03-12 01:09:29 +0000136 virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode,
137 const TargetRegisterClass *RC,
138 uint64_t Imm);
Eric Christopherd94bc542011-04-29 22:07:50 +0000139 virtual unsigned FastEmitInst_ii(unsigned MachineInstOpcode,
140 const TargetRegisterClass *RC,
141 uint64_t Imm1, uint64_t Imm2);
Eric Christopheraf3dce52011-03-12 01:09:29 +0000142
Eric Christopher0fe7d542010-08-17 01:25:29 +0000143 virtual unsigned FastEmitInst_extractsubreg(MVT RetVT,
144 unsigned Op0, bool Op0IsKill,
145 uint32_t Idx);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000146
Eric Christophercb592292010-08-20 00:20:31 +0000147 // Backend specific FastISel code.
Eric Christopherab695882010-07-21 22:26:11 +0000148 virtual bool TargetSelectInstruction(const Instruction *I);
Eric Christopher1b61ef42010-09-02 01:48:11 +0000149 virtual unsigned TargetMaterializeConstant(const Constant *C);
Eric Christopherf9764fa2010-09-30 20:49:44 +0000150 virtual unsigned TargetMaterializeAlloca(const AllocaInst *AI);
Eric Christopherab695882010-07-21 22:26:11 +0000151
152 #include "ARMGenFastISel.inc"
Eric Christopherac1a19e2010-09-09 01:06:51 +0000153
Eric Christopher83007122010-08-23 21:44:12 +0000154 // Instruction selection routines.
Eric Christopher44bff902010-09-10 23:10:30 +0000155 private:
Eric Christopher17787722010-10-21 21:47:51 +0000156 bool SelectLoad(const Instruction *I);
157 bool SelectStore(const Instruction *I);
158 bool SelectBranch(const Instruction *I);
159 bool SelectCmp(const Instruction *I);
160 bool SelectFPExt(const Instruction *I);
161 bool SelectFPTrunc(const Instruction *I);
162 bool SelectBinaryOp(const Instruction *I, unsigned ISDOpcode);
163 bool SelectSIToFP(const Instruction *I);
164 bool SelectFPToSI(const Instruction *I);
165 bool SelectSDiv(const Instruction *I);
166 bool SelectSRem(const Instruction *I);
167 bool SelectCall(const Instruction *I);
168 bool SelectSelect(const Instruction *I);
Eric Christopher4f512ef2010-10-22 01:28:00 +0000169 bool SelectRet(const Instruction *I);
Eli Friedman76927d732011-05-25 23:49:02 +0000170 bool SelectIntCast(const Instruction *I);
Eric Christopherab695882010-07-21 22:26:11 +0000171
Eric Christopher83007122010-08-23 21:44:12 +0000172 // Utility routines.
Eric Christopher456144e2010-08-19 00:37:05 +0000173 private:
Duncan Sands1440e8b2010-11-03 11:35:31 +0000174 bool isTypeLegal(const Type *Ty, MVT &VT);
175 bool isLoadTypeLegal(const Type *Ty, MVT &VT);
Eric Christopher0d581222010-11-19 22:30:02 +0000176 bool ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr);
177 bool ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr);
178 bool ARMComputeAddress(const Value *Obj, Address &Addr);
179 void ARMSimplifyAddress(Address &Addr, EVT VT);
Eric Christopher9ed58df2010-09-09 00:19:41 +0000180 unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT);
Eric Christopher744c7c82010-09-28 22:47:54 +0000181 unsigned ARMMaterializeInt(const Constant *C, EVT VT);
Eric Christopherc9932f62010-10-01 23:24:42 +0000182 unsigned ARMMaterializeGV(const GlobalValue *GV, EVT VT);
Eric Christopheraa3ace12010-09-09 20:49:25 +0000183 unsigned ARMMoveToFPReg(EVT VT, unsigned SrcReg);
Eric Christopher9ee4ce22010-09-09 21:44:45 +0000184 unsigned ARMMoveToIntReg(EVT VT, unsigned SrcReg);
Eric Christopher872f4a22011-02-22 01:37:10 +0000185 unsigned ARMSelectCallOp(const GlobalValue *GV);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000186
Eric Christopherd10cd7b2010-09-10 23:18:12 +0000187 // Call handling routines.
188 private:
Eric Christopherfa87d662010-10-18 02:17:53 +0000189 bool FastEmitExtend(ISD::NodeType Opc, EVT DstVT, unsigned Src, EVT SrcVT,
190 unsigned &ResultReg);
Eric Christopherd10cd7b2010-09-10 23:18:12 +0000191 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool Return);
Eric Christopherdccd2c32010-10-11 08:38:55 +0000192 bool ProcessCallArgs(SmallVectorImpl<Value*> &Args,
Eric Christophera9a7a1a2010-09-29 23:11:09 +0000193 SmallVectorImpl<unsigned> &ArgRegs,
Duncan Sands1440e8b2010-11-03 11:35:31 +0000194 SmallVectorImpl<MVT> &ArgVTs,
Eric Christophera9a7a1a2010-09-29 23:11:09 +0000195 SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
196 SmallVectorImpl<unsigned> &RegArgs,
197 CallingConv::ID CC,
198 unsigned &NumBytes);
Duncan Sands1440e8b2010-11-03 11:35:31 +0000199 bool FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
Eric Christophera9a7a1a2010-09-29 23:11:09 +0000200 const Instruction *I, CallingConv::ID CC,
201 unsigned &NumBytes);
Eric Christopher7ed8ec92010-09-28 01:21:42 +0000202 bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call);
Eric Christopherd10cd7b2010-09-10 23:18:12 +0000203
204 // OptionalDef handling routines.
205 private:
Eric Christopheraf3dce52011-03-12 01:09:29 +0000206 bool isARMNEONPred(const MachineInstr *MI);
Eric Christopher456144e2010-08-19 00:37:05 +0000207 bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR);
208 const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB);
Eric Christopher564857f2010-12-01 01:40:24 +0000209 void AddLoadStoreOperands(EVT VT, Address &Addr,
Cameron Zwarichc152aa62011-05-28 20:34:49 +0000210 const MachineInstrBuilder &MIB,
211 unsigned Flags);
Eric Christopher456144e2010-08-19 00:37:05 +0000212};
Eric Christopherab695882010-07-21 22:26:11 +0000213
214} // end anonymous namespace
215
Eric Christopherd10cd7b2010-09-10 23:18:12 +0000216#include "ARMGenCallingConv.inc"
Eric Christopherab695882010-07-21 22:26:11 +0000217
Eric Christopher456144e2010-08-19 00:37:05 +0000218// DefinesOptionalPredicate - This is different from DefinesPredicate in that
219// we don't care about implicit defs here, just places we'll need to add a
220// default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR.
221bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) {
222 const TargetInstrDesc &TID = MI->getDesc();
223 if (!TID.hasOptionalDef())
224 return false;
225
226 // Look to see if our OptionalDef is defining CPSR or CCR.
227 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
228 const MachineOperand &MO = MI->getOperand(i);
Eric Christopherf762fbe2010-08-20 00:36:24 +0000229 if (!MO.isReg() || !MO.isDef()) continue;
230 if (MO.getReg() == ARM::CPSR)
Eric Christopher456144e2010-08-19 00:37:05 +0000231 *CPSR = true;
232 }
233 return true;
234}
235
Eric Christopheraf3dce52011-03-12 01:09:29 +0000236bool ARMFastISel::isARMNEONPred(const MachineInstr *MI) {
237 const TargetInstrDesc &TID = MI->getDesc();
Eric Christopher299bbb22011-04-29 00:03:10 +0000238
Eric Christopheraf3dce52011-03-12 01:09:29 +0000239 // If we're a thumb2 or not NEON function we were handled via isPredicable.
240 if ((TID.TSFlags & ARMII::DomainMask) != ARMII::DomainNEON ||
241 AFI->isThumb2Function())
242 return false;
Eric Christopher299bbb22011-04-29 00:03:10 +0000243
Eric Christopheraf3dce52011-03-12 01:09:29 +0000244 for (unsigned i = 0, e = TID.getNumOperands(); i != e; ++i)
245 if (TID.OpInfo[i].isPredicate())
246 return true;
Eric Christopher299bbb22011-04-29 00:03:10 +0000247
Eric Christopheraf3dce52011-03-12 01:09:29 +0000248 return false;
249}
250
Eric Christopher456144e2010-08-19 00:37:05 +0000251// If the machine is predicable go ahead and add the predicate operands, if
252// it needs default CC operands add those.
Eric Christopheraaa8df42010-11-02 01:21:28 +0000253// TODO: If we want to support thumb1 then we'll need to deal with optional
254// CPSR defs that need to be added before the remaining operands. See s_cc_out
255// for descriptions why.
Eric Christopher456144e2010-08-19 00:37:05 +0000256const MachineInstrBuilder &
257ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) {
258 MachineInstr *MI = &*MIB;
259
Eric Christopheraf3dce52011-03-12 01:09:29 +0000260 // Do we use a predicate? or...
261 // Are we NEON in ARM mode and have a predicate operand? If so, I know
262 // we're not predicable but add it anyways.
263 if (TII.isPredicable(MI) || isARMNEONPred(MI))
Eric Christopher456144e2010-08-19 00:37:05 +0000264 AddDefaultPred(MIB);
Eric Christopher299bbb22011-04-29 00:03:10 +0000265
Eric Christopher456144e2010-08-19 00:37:05 +0000266 // Do we optionally set a predicate? Preds is size > 0 iff the predicate
267 // defines CPSR. All other OptionalDefines in ARM are the CCR register.
Eric Christopher979e0a12010-08-19 15:35:27 +0000268 bool CPSR = false;
Eric Christopher456144e2010-08-19 00:37:05 +0000269 if (DefinesOptionalPredicate(MI, &CPSR)) {
270 if (CPSR)
271 AddDefaultT1CC(MIB);
272 else
273 AddDefaultCC(MIB);
274 }
275 return MIB;
276}
277
Eric Christopher0fe7d542010-08-17 01:25:29 +0000278unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode,
279 const TargetRegisterClass* RC) {
280 unsigned ResultReg = createResultReg(RC);
281 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
282
Eric Christopher456144e2010-08-19 00:37:05 +0000283 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg));
Eric Christopher0fe7d542010-08-17 01:25:29 +0000284 return ResultReg;
285}
286
287unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode,
288 const TargetRegisterClass *RC,
289 unsigned Op0, bool Op0IsKill) {
290 unsigned ResultReg = createResultReg(RC);
291 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
292
293 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000294 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000295 .addReg(Op0, Op0IsKill * RegState::Kill));
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));
Eric Christopher456144e2010-08-19 00:37:05 +0000299 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000300 TII.get(TargetOpcode::COPY), ResultReg)
301 .addReg(II.ImplicitDefs[0]));
302 }
303 return ResultReg;
304}
305
306unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode,
307 const TargetRegisterClass *RC,
308 unsigned Op0, bool Op0IsKill,
309 unsigned Op1, bool Op1IsKill) {
310 unsigned ResultReg = createResultReg(RC);
311 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
312
313 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000314 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000315 .addReg(Op0, Op0IsKill * RegState::Kill)
316 .addReg(Op1, Op1IsKill * RegState::Kill));
317 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000318 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000319 .addReg(Op0, Op0IsKill * RegState::Kill)
320 .addReg(Op1, Op1IsKill * RegState::Kill));
Eric Christopher456144e2010-08-19 00:37:05 +0000321 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000322 TII.get(TargetOpcode::COPY), ResultReg)
323 .addReg(II.ImplicitDefs[0]));
324 }
325 return ResultReg;
326}
327
Cameron Zwarichc0e6d782011-03-30 23:01:21 +0000328unsigned ARMFastISel::FastEmitInst_rrr(unsigned MachineInstOpcode,
329 const TargetRegisterClass *RC,
330 unsigned Op0, bool Op0IsKill,
331 unsigned Op1, bool Op1IsKill,
332 unsigned Op2, bool Op2IsKill) {
333 unsigned ResultReg = createResultReg(RC);
334 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
335
336 if (II.getNumDefs() >= 1)
337 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
338 .addReg(Op0, Op0IsKill * RegState::Kill)
339 .addReg(Op1, Op1IsKill * RegState::Kill)
340 .addReg(Op2, Op2IsKill * RegState::Kill));
341 else {
342 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
343 .addReg(Op0, Op0IsKill * RegState::Kill)
344 .addReg(Op1, Op1IsKill * RegState::Kill)
345 .addReg(Op2, Op2IsKill * RegState::Kill));
346 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
347 TII.get(TargetOpcode::COPY), ResultReg)
348 .addReg(II.ImplicitDefs[0]));
349 }
350 return ResultReg;
351}
352
Eric Christopher0fe7d542010-08-17 01:25:29 +0000353unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode,
354 const TargetRegisterClass *RC,
355 unsigned Op0, bool Op0IsKill,
356 uint64_t Imm) {
357 unsigned ResultReg = createResultReg(RC);
358 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
359
360 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000361 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000362 .addReg(Op0, Op0IsKill * RegState::Kill)
363 .addImm(Imm));
364 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000365 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000366 .addReg(Op0, Op0IsKill * RegState::Kill)
367 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000368 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000369 TII.get(TargetOpcode::COPY), ResultReg)
370 .addReg(II.ImplicitDefs[0]));
371 }
372 return ResultReg;
373}
374
375unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode,
376 const TargetRegisterClass *RC,
377 unsigned Op0, bool Op0IsKill,
378 const ConstantFP *FPImm) {
379 unsigned ResultReg = createResultReg(RC);
380 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
381
382 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000383 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000384 .addReg(Op0, Op0IsKill * RegState::Kill)
385 .addFPImm(FPImm));
386 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000387 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000388 .addReg(Op0, Op0IsKill * RegState::Kill)
389 .addFPImm(FPImm));
Eric Christopher456144e2010-08-19 00:37:05 +0000390 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000391 TII.get(TargetOpcode::COPY), ResultReg)
392 .addReg(II.ImplicitDefs[0]));
393 }
394 return ResultReg;
395}
396
397unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode,
398 const TargetRegisterClass *RC,
399 unsigned Op0, bool Op0IsKill,
400 unsigned Op1, bool Op1IsKill,
401 uint64_t Imm) {
402 unsigned ResultReg = createResultReg(RC);
403 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
404
405 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000406 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000407 .addReg(Op0, Op0IsKill * RegState::Kill)
408 .addReg(Op1, Op1IsKill * RegState::Kill)
409 .addImm(Imm));
410 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000411 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000412 .addReg(Op0, Op0IsKill * RegState::Kill)
413 .addReg(Op1, Op1IsKill * RegState::Kill)
414 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000415 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000416 TII.get(TargetOpcode::COPY), ResultReg)
417 .addReg(II.ImplicitDefs[0]));
418 }
419 return ResultReg;
420}
421
422unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode,
423 const TargetRegisterClass *RC,
424 uint64_t Imm) {
425 unsigned ResultReg = createResultReg(RC);
426 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000427
Eric Christopher0fe7d542010-08-17 01:25:29 +0000428 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000429 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000430 .addImm(Imm));
431 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000432 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000433 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000434 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000435 TII.get(TargetOpcode::COPY), ResultReg)
436 .addReg(II.ImplicitDefs[0]));
437 }
438 return ResultReg;
439}
440
Eric Christopherd94bc542011-04-29 22:07:50 +0000441unsigned ARMFastISel::FastEmitInst_ii(unsigned MachineInstOpcode,
442 const TargetRegisterClass *RC,
443 uint64_t Imm1, uint64_t Imm2) {
444 unsigned ResultReg = createResultReg(RC);
445 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
446
447 if (II.getNumDefs() >= 1)
448 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
449 .addImm(Imm1).addImm(Imm2));
450 else {
451 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
452 .addImm(Imm1).addImm(Imm2));
453 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
454 TII.get(TargetOpcode::COPY),
455 ResultReg)
456 .addReg(II.ImplicitDefs[0]));
457 }
458 return ResultReg;
459}
460
Eric Christopher0fe7d542010-08-17 01:25:29 +0000461unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT,
462 unsigned Op0, bool Op0IsKill,
463 uint32_t Idx) {
464 unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT));
465 assert(TargetRegisterInfo::isVirtualRegister(Op0) &&
466 "Cannot yet extract from physregs");
Eric Christopher456144e2010-08-19 00:37:05 +0000467 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000468 DL, TII.get(TargetOpcode::COPY), ResultReg)
469 .addReg(Op0, getKillRegState(Op0IsKill), Idx));
470 return ResultReg;
471}
472
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000473// TODO: Don't worry about 64-bit now, but when this is fixed remove the
474// checks from the various callers.
Eric Christopheraa3ace12010-09-09 20:49:25 +0000475unsigned ARMFastISel::ARMMoveToFPReg(EVT VT, unsigned SrcReg) {
Duncan Sandscdfad362010-11-03 12:17:33 +0000476 if (VT == MVT::f64) return 0;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000477
Eric Christopher9ee4ce22010-09-09 21:44:45 +0000478 unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
479 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
480 TII.get(ARM::VMOVRS), MoveReg)
481 .addReg(SrcReg));
482 return MoveReg;
483}
484
485unsigned ARMFastISel::ARMMoveToIntReg(EVT VT, unsigned SrcReg) {
Duncan Sandscdfad362010-11-03 12:17:33 +0000486 if (VT == MVT::i64) return 0;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000487
Eric Christopheraa3ace12010-09-09 20:49:25 +0000488 unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
489 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher9ee4ce22010-09-09 21:44:45 +0000490 TII.get(ARM::VMOVSR), MoveReg)
Eric Christopheraa3ace12010-09-09 20:49:25 +0000491 .addReg(SrcReg));
492 return MoveReg;
493}
494
Eric Christopher9ed58df2010-09-09 00:19:41 +0000495// For double width floating point we need to materialize two constants
496// (the high and the low) into integer registers then use a move to get
497// the combined constant into an FP reg.
498unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, EVT VT) {
499 const APFloat Val = CFP->getValueAPF();
Duncan Sandscdfad362010-11-03 12:17:33 +0000500 bool is64bit = VT == MVT::f64;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000501
Eric Christopher9ed58df2010-09-09 00:19:41 +0000502 // This checks to see if we can use VFP3 instructions to materialize
503 // a constant, otherwise we have to go through the constant pool.
504 if (TLI.isFPImmLegal(Val, VT)) {
505 unsigned Opc = is64bit ? ARM::FCONSTD : ARM::FCONSTS;
506 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
507 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
508 DestReg)
509 .addFPImm(CFP));
510 return DestReg;
511 }
Eric Christopherdccd2c32010-10-11 08:38:55 +0000512
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000513 // Require VFP2 for loading fp constants.
Eric Christopher238bb162010-09-09 23:50:00 +0000514 if (!Subtarget->hasVFP2()) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000515
Eric Christopher238bb162010-09-09 23:50:00 +0000516 // MachineConstantPool wants an explicit alignment.
517 unsigned Align = TD.getPrefTypeAlignment(CFP->getType());
518 if (Align == 0) {
519 // TODO: Figure out if this is correct.
520 Align = TD.getTypeAllocSize(CFP->getType());
521 }
522 unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align);
523 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
524 unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000525
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000526 // The extra reg is for addrmode5.
Eric Christopherf5732c42010-09-28 00:35:09 +0000527 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
528 DestReg)
529 .addConstantPoolIndex(Idx)
Eric Christopher238bb162010-09-09 23:50:00 +0000530 .addReg(0));
531 return DestReg;
Eric Christopher9ed58df2010-09-09 00:19:41 +0000532}
533
Eric Christopher744c7c82010-09-28 22:47:54 +0000534unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, EVT VT) {
Eric Christopherdccd2c32010-10-11 08:38:55 +0000535
Eric Christopher744c7c82010-09-28 22:47:54 +0000536 // For now 32-bit only.
Duncan Sandscdfad362010-11-03 12:17:33 +0000537 if (VT != MVT::i32) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000538
Eric Christophere5b13cf2010-11-03 20:21:17 +0000539 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
540
541 // If we can do this in a single instruction without a constant pool entry
542 // do so now.
543 const ConstantInt *CI = cast<ConstantInt>(C);
Eric Christopher5e262bc2010-11-06 07:53:11 +0000544 if (Subtarget->hasV6T2Ops() && isUInt<16>(CI->getSExtValue())) {
Eric Christophere5b13cf2010-11-03 20:21:17 +0000545 unsigned Opc = isThumb ? ARM::t2MOVi16 : ARM::MOVi16;
546 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Jim Grosbach3ea4daa2010-11-19 18:01:37 +0000547 TII.get(Opc), DestReg)
548 .addImm(CI->getSExtValue()));
Eric Christophere5b13cf2010-11-03 20:21:17 +0000549 return DestReg;
550 }
551
Eric Christopher56d2b722010-09-02 23:43:26 +0000552 // MachineConstantPool wants an explicit alignment.
553 unsigned Align = TD.getPrefTypeAlignment(C->getType());
554 if (Align == 0) {
555 // TODO: Figure out if this is correct.
556 Align = TD.getTypeAllocSize(C->getType());
557 }
558 unsigned Idx = MCP.getConstantPoolIndex(C, Align);
Eric Christopherdccd2c32010-10-11 08:38:55 +0000559
Eric Christopher56d2b722010-09-02 23:43:26 +0000560 if (isThumb)
561 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopherfd609802010-09-28 21:55:34 +0000562 TII.get(ARM::t2LDRpci), DestReg)
563 .addConstantPoolIndex(Idx));
Eric Christopher56d2b722010-09-02 23:43:26 +0000564 else
Eric Christopherd0c82a62010-11-12 09:48:30 +0000565 // The extra immediate is for addrmode2.
Eric Christopher56d2b722010-09-02 23:43:26 +0000566 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopherfd609802010-09-28 21:55:34 +0000567 TII.get(ARM::LDRcp), DestReg)
568 .addConstantPoolIndex(Idx)
Jim Grosbach3e556122010-10-26 22:37:02 +0000569 .addImm(0));
Eric Christopherac1a19e2010-09-09 01:06:51 +0000570
Eric Christopher56d2b722010-09-02 23:43:26 +0000571 return DestReg;
Eric Christopher1b61ef42010-09-02 01:48:11 +0000572}
573
Eric Christopherc9932f62010-10-01 23:24:42 +0000574unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, EVT VT) {
Eric Christopher890dbbe2010-10-02 00:32:44 +0000575 // For now 32-bit only.
Duncan Sandscdfad362010-11-03 12:17:33 +0000576 if (VT != MVT::i32) return 0;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000577
Eric Christopher890dbbe2010-10-02 00:32:44 +0000578 Reloc::Model RelocM = TM.getRelocationModel();
Eric Christopherdccd2c32010-10-11 08:38:55 +0000579
Eric Christopher890dbbe2010-10-02 00:32:44 +0000580 // TODO: No external globals for now.
581 if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) return 0;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000582
Eric Christopher890dbbe2010-10-02 00:32:44 +0000583 // TODO: Need more magic for ARM PIC.
584 if (!isThumb && (RelocM == Reloc::PIC_)) return 0;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000585
Eric Christopher890dbbe2010-10-02 00:32:44 +0000586 // MachineConstantPool wants an explicit alignment.
587 unsigned Align = TD.getPrefTypeAlignment(GV->getType());
588 if (Align == 0) {
589 // TODO: Figure out if this is correct.
590 Align = TD.getTypeAllocSize(GV->getType());
591 }
Eric Christopherdccd2c32010-10-11 08:38:55 +0000592
Eric Christopher890dbbe2010-10-02 00:32:44 +0000593 // Grab index.
594 unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb() ? 4 : 8);
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000595 unsigned Id = AFI->createPICLabelUId();
Eric Christopher890dbbe2010-10-02 00:32:44 +0000596 ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, Id,
597 ARMCP::CPValue, PCAdj);
598 unsigned Idx = MCP.getConstantPoolIndex(CPV, Align);
Eric Christopherdccd2c32010-10-11 08:38:55 +0000599
Eric Christopher890dbbe2010-10-02 00:32:44 +0000600 // Load value.
601 MachineInstrBuilder MIB;
602 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
603 if (isThumb) {
604 unsigned Opc = (RelocM != Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic;
605 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg)
606 .addConstantPoolIndex(Idx);
607 if (RelocM == Reloc::PIC_)
608 MIB.addImm(Id);
609 } else {
Eric Christopherd0c82a62010-11-12 09:48:30 +0000610 // The extra immediate is for addrmode2.
Eric Christopher890dbbe2010-10-02 00:32:44 +0000611 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRcp),
612 DestReg)
613 .addConstantPoolIndex(Idx)
Eric Christopherd0c82a62010-11-12 09:48:30 +0000614 .addImm(0);
Eric Christopher890dbbe2010-10-02 00:32:44 +0000615 }
616 AddOptionalDefs(MIB);
617 return DestReg;
Eric Christopherc9932f62010-10-01 23:24:42 +0000618}
619
Eric Christopher9ed58df2010-09-09 00:19:41 +0000620unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) {
621 EVT VT = TLI.getValueType(C->getType(), true);
622
623 // Only handle simple types.
624 if (!VT.isSimple()) return 0;
625
626 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
627 return ARMMaterializeFP(CFP, VT);
Eric Christopherc9932f62010-10-01 23:24:42 +0000628 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
629 return ARMMaterializeGV(GV, VT);
630 else if (isa<ConstantInt>(C))
631 return ARMMaterializeInt(C, VT);
Eric Christopherdccd2c32010-10-11 08:38:55 +0000632
Eric Christopherc9932f62010-10-01 23:24:42 +0000633 return 0;
Eric Christopher9ed58df2010-09-09 00:19:41 +0000634}
635
Eric Christopherf9764fa2010-09-30 20:49:44 +0000636unsigned ARMFastISel::TargetMaterializeAlloca(const AllocaInst *AI) {
637 // Don't handle dynamic allocas.
638 if (!FuncInfo.StaticAllocaMap.count(AI)) return 0;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000639
Duncan Sands1440e8b2010-11-03 11:35:31 +0000640 MVT VT;
Eric Christopherec8bf972010-10-17 06:07:26 +0000641 if (!isLoadTypeLegal(AI->getType(), VT)) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +0000642
Eric Christopherf9764fa2010-09-30 20:49:44 +0000643 DenseMap<const AllocaInst*, int>::iterator SI =
644 FuncInfo.StaticAllocaMap.find(AI);
645
646 // This will get lowered later into the correct offsets and registers
647 // via rewriteXFrameIndex.
648 if (SI != FuncInfo.StaticAllocaMap.end()) {
649 TargetRegisterClass* RC = TLI.getRegClassFor(VT);
650 unsigned ResultReg = createResultReg(RC);
651 unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri;
652 AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL,
653 TII.get(Opc), ResultReg)
654 .addFrameIndex(SI->second)
655 .addImm(0));
656 return ResultReg;
657 }
Eric Christopherdccd2c32010-10-11 08:38:55 +0000658
Eric Christopherf9764fa2010-09-30 20:49:44 +0000659 return 0;
660}
661
Duncan Sands1440e8b2010-11-03 11:35:31 +0000662bool ARMFastISel::isTypeLegal(const Type *Ty, MVT &VT) {
663 EVT evt = TLI.getValueType(Ty, true);
Eric Christopherac1a19e2010-09-09 01:06:51 +0000664
Eric Christopherb1cc8482010-08-25 07:23:49 +0000665 // Only handle simple types.
Duncan Sands1440e8b2010-11-03 11:35:31 +0000666 if (evt == MVT::Other || !evt.isSimple()) return false;
667 VT = evt.getSimpleVT();
Eric Christopherac1a19e2010-09-09 01:06:51 +0000668
Eric Christopherdc908042010-08-31 01:28:42 +0000669 // Handle all legal types, i.e. a register that will directly hold this
670 // value.
671 return TLI.isTypeLegal(VT);
Eric Christopherb1cc8482010-08-25 07:23:49 +0000672}
673
Duncan Sands1440e8b2010-11-03 11:35:31 +0000674bool ARMFastISel::isLoadTypeLegal(const Type *Ty, MVT &VT) {
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000675 if (isTypeLegal(Ty, VT)) return true;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000676
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000677 // If this is a type than can be sign or zero-extended to a basic operation
678 // go ahead and accept it now.
679 if (VT == MVT::i8 || VT == MVT::i16)
680 return true;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000681
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000682 return false;
683}
684
Eric Christopher88de86b2010-11-19 22:36:41 +0000685// Computes the address to get to an object.
Eric Christopher0d581222010-11-19 22:30:02 +0000686bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) {
Eric Christopher83007122010-08-23 21:44:12 +0000687 // Some boilerplate from the X86 FastISel.
688 const User *U = NULL;
Eric Christopher83007122010-08-23 21:44:12 +0000689 unsigned Opcode = Instruction::UserOp1;
Eric Christophercb0b04b2010-08-24 00:07:24 +0000690 if (const Instruction *I = dyn_cast<Instruction>(Obj)) {
Eric Christopher2d630d72010-11-19 22:37:58 +0000691 // Don't walk into other basic blocks unless the object is an alloca from
692 // another block, otherwise it may not have a virtual register assigned.
Eric Christopher76dda7e2010-11-15 21:11:06 +0000693 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
694 FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) {
695 Opcode = I->getOpcode();
696 U = I;
697 }
Eric Christophercb0b04b2010-08-24 00:07:24 +0000698 } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
Eric Christopher83007122010-08-23 21:44:12 +0000699 Opcode = C->getOpcode();
700 U = C;
701 }
702
Eric Christophercb0b04b2010-08-24 00:07:24 +0000703 if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType()))
Eric Christopher83007122010-08-23 21:44:12 +0000704 if (Ty->getAddressSpace() > 255)
705 // Fast instruction selection doesn't support the special
706 // address spaces.
707 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +0000708
Eric Christopher83007122010-08-23 21:44:12 +0000709 switch (Opcode) {
Eric Christopherac1a19e2010-09-09 01:06:51 +0000710 default:
Eric Christopher83007122010-08-23 21:44:12 +0000711 break;
Eric Christopher55324332010-10-12 00:43:21 +0000712 case Instruction::BitCast: {
713 // Look through bitcasts.
Eric Christopher0d581222010-11-19 22:30:02 +0000714 return ARMComputeAddress(U->getOperand(0), Addr);
Eric Christopher55324332010-10-12 00:43:21 +0000715 }
716 case Instruction::IntToPtr: {
717 // Look past no-op inttoptrs.
718 if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy())
Eric Christopher0d581222010-11-19 22:30:02 +0000719 return ARMComputeAddress(U->getOperand(0), Addr);
Eric Christopher55324332010-10-12 00:43:21 +0000720 break;
721 }
722 case Instruction::PtrToInt: {
723 // Look past no-op ptrtoints.
724 if (TLI.getValueType(U->getType()) == TLI.getPointerTy())
Eric Christopher0d581222010-11-19 22:30:02 +0000725 return ARMComputeAddress(U->getOperand(0), Addr);
Eric Christopher55324332010-10-12 00:43:21 +0000726 break;
727 }
Eric Christophereae84392010-10-14 09:29:41 +0000728 case Instruction::GetElementPtr: {
Eric Christopherb3716582010-11-19 22:39:56 +0000729 Address SavedAddr = Addr;
Eric Christopher0d581222010-11-19 22:30:02 +0000730 int TmpOffset = Addr.Offset;
Eric Christopher2896df82010-10-15 18:02:07 +0000731
Eric Christophereae84392010-10-14 09:29:41 +0000732 // Iterate through the GEP folding the constants into offsets where
733 // we can.
734 gep_type_iterator GTI = gep_type_begin(U);
735 for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end();
736 i != e; ++i, ++GTI) {
737 const Value *Op = *i;
738 if (const StructType *STy = dyn_cast<StructType>(*GTI)) {
739 const StructLayout *SL = TD.getStructLayout(STy);
740 unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
741 TmpOffset += SL->getElementOffset(Idx);
742 } else {
Eric Christopher2896df82010-10-15 18:02:07 +0000743 uint64_t S = TD.getTypeAllocSize(GTI.getIndexedType());
Eric Christopher7244d7c2011-03-22 19:39:17 +0000744 for (;;) {
Eric Christopher2896df82010-10-15 18:02:07 +0000745 if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
746 // Constant-offset addressing.
747 TmpOffset += CI->getSExtValue() * S;
Eric Christopher7244d7c2011-03-22 19:39:17 +0000748 break;
749 }
750 if (isa<AddOperator>(Op) &&
751 (!isa<Instruction>(Op) ||
752 FuncInfo.MBBMap[cast<Instruction>(Op)->getParent()]
753 == FuncInfo.MBB) &&
754 isa<ConstantInt>(cast<AddOperator>(Op)->getOperand(1))) {
Eric Christopher299bbb22011-04-29 00:03:10 +0000755 // An add (in the same block) with a constant operand. Fold the
Eric Christopher7244d7c2011-03-22 19:39:17 +0000756 // constant.
Eric Christopher2896df82010-10-15 18:02:07 +0000757 ConstantInt *CI =
Eric Christopher7244d7c2011-03-22 19:39:17 +0000758 cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1));
Eric Christopher2896df82010-10-15 18:02:07 +0000759 TmpOffset += CI->getSExtValue() * S;
Eric Christopher7244d7c2011-03-22 19:39:17 +0000760 // Iterate on the other operand.
761 Op = cast<AddOperator>(Op)->getOperand(0);
762 continue;
Eric Christopher299bbb22011-04-29 00:03:10 +0000763 }
Eric Christopher7244d7c2011-03-22 19:39:17 +0000764 // Unsupported
765 goto unsupported_gep;
766 }
Eric Christophereae84392010-10-14 09:29:41 +0000767 }
768 }
Eric Christopher2896df82010-10-15 18:02:07 +0000769
770 // Try to grab the base operand now.
Eric Christopher0d581222010-11-19 22:30:02 +0000771 Addr.Offset = TmpOffset;
772 if (ARMComputeAddress(U->getOperand(0), Addr)) return true;
Eric Christopher2896df82010-10-15 18:02:07 +0000773
774 // We failed, restore everything and try the other options.
Eric Christopherb3716582010-11-19 22:39:56 +0000775 Addr = SavedAddr;
Eric Christopher2896df82010-10-15 18:02:07 +0000776
Eric Christophereae84392010-10-14 09:29:41 +0000777 unsupported_gep:
Eric Christophereae84392010-10-14 09:29:41 +0000778 break;
779 }
Eric Christopher83007122010-08-23 21:44:12 +0000780 case Instruction::Alloca: {
Eric Christopher15418772010-10-12 05:39:06 +0000781 const AllocaInst *AI = cast<AllocaInst>(Obj);
Eric Christopher827656d2010-11-20 22:38:27 +0000782 DenseMap<const AllocaInst*, int>::iterator SI =
783 FuncInfo.StaticAllocaMap.find(AI);
784 if (SI != FuncInfo.StaticAllocaMap.end()) {
785 Addr.BaseType = Address::FrameIndexBase;
786 Addr.Base.FI = SI->second;
787 return true;
788 }
789 break;
Eric Christopher83007122010-08-23 21:44:12 +0000790 }
791 }
Eric Christopherac1a19e2010-09-09 01:06:51 +0000792
Eric Christophera9c57512010-10-13 21:41:51 +0000793 // Materialize the global variable's address into a reg which can
794 // then be used later to load the variable.
Eric Christophercb0b04b2010-08-24 00:07:24 +0000795 if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) {
Eric Christopherede42b02010-10-13 09:11:46 +0000796 unsigned Tmp = ARMMaterializeGV(GV, TLI.getValueType(Obj->getType()));
797 if (Tmp == 0) return false;
Eric Christopher2896df82010-10-15 18:02:07 +0000798
Eric Christopher0d581222010-11-19 22:30:02 +0000799 Addr.Base.Reg = Tmp;
Eric Christopherede42b02010-10-13 09:11:46 +0000800 return true;
Eric Christophercb0b04b2010-08-24 00:07:24 +0000801 }
Eric Christopherac1a19e2010-09-09 01:06:51 +0000802
Eric Christophercb0b04b2010-08-24 00:07:24 +0000803 // Try to get this in a register if nothing else has worked.
Eric Christopher0d581222010-11-19 22:30:02 +0000804 if (Addr.Base.Reg == 0) Addr.Base.Reg = getRegForValue(Obj);
805 return Addr.Base.Reg != 0;
Eric Christophereae84392010-10-14 09:29:41 +0000806}
807
Eric Christopher0d581222010-11-19 22:30:02 +0000808void ARMFastISel::ARMSimplifyAddress(Address &Addr, EVT VT) {
Jim Grosbach6b156392010-10-27 21:39:08 +0000809
Eric Christopher212ae932010-10-21 19:40:30 +0000810 assert(VT.isSimple() && "Non-simple types are invalid here!");
Jim Grosbach6b156392010-10-27 21:39:08 +0000811
Eric Christopher212ae932010-10-21 19:40:30 +0000812 bool needsLowering = false;
813 switch (VT.getSimpleVT().SimpleTy) {
814 default:
815 assert(false && "Unhandled load/store type!");
816 case MVT::i1:
817 case MVT::i8:
818 case MVT::i16:
819 case MVT::i32:
820 // Integer loads/stores handle 12-bit offsets.
Eric Christopher0d581222010-11-19 22:30:02 +0000821 needsLowering = ((Addr.Offset & 0xfff) != Addr.Offset);
Eric Christopher212ae932010-10-21 19:40:30 +0000822 break;
823 case MVT::f32:
824 case MVT::f64:
825 // Floating point operands handle 8-bit offsets.
Eric Christopher0d581222010-11-19 22:30:02 +0000826 needsLowering = ((Addr.Offset & 0xff) != Addr.Offset);
Eric Christopher212ae932010-10-21 19:40:30 +0000827 break;
828 }
Jim Grosbach6b156392010-10-27 21:39:08 +0000829
Eric Christopher827656d2010-11-20 22:38:27 +0000830 // If this is a stack pointer and the offset needs to be simplified then
831 // put the alloca address into a register, set the base type back to
832 // register and continue. This should almost never happen.
833 if (needsLowering && Addr.BaseType == Address::FrameIndexBase) {
834 TargetRegisterClass *RC = isThumb ? ARM::tGPRRegisterClass :
835 ARM::GPRRegisterClass;
836 unsigned ResultReg = createResultReg(RC);
837 unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri;
838 AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL,
839 TII.get(Opc), ResultReg)
840 .addFrameIndex(Addr.Base.FI)
841 .addImm(0));
842 Addr.Base.Reg = ResultReg;
843 Addr.BaseType = Address::RegBase;
844 }
845
Eric Christopher212ae932010-10-21 19:40:30 +0000846 // Since the offset is too large for the load/store instruction
Eric Christopher318b6ee2010-09-02 00:53:56 +0000847 // get the reg+offset into a register.
Eric Christopher212ae932010-10-21 19:40:30 +0000848 if (needsLowering) {
Eli Friedman9ebf57a2011-04-29 21:22:56 +0000849 Addr.Base.Reg = FastEmit_ri_(MVT::i32, ISD::ADD, Addr.Base.Reg,
850 /*Op0IsKill*/false, Addr.Offset, MVT::i32);
Eric Christopher0d581222010-11-19 22:30:02 +0000851 Addr.Offset = 0;
Eric Christopher318b6ee2010-09-02 00:53:56 +0000852 }
Eric Christopher83007122010-08-23 21:44:12 +0000853}
854
Eric Christopher564857f2010-12-01 01:40:24 +0000855void ARMFastISel::AddLoadStoreOperands(EVT VT, Address &Addr,
Cameron Zwarichc152aa62011-05-28 20:34:49 +0000856 const MachineInstrBuilder &MIB,
857 unsigned Flags) {
Eric Christopher564857f2010-12-01 01:40:24 +0000858 // addrmode5 output depends on the selection dag addressing dividing the
859 // offset by 4 that it then later multiplies. Do this here as well.
860 if (VT.getSimpleVT().SimpleTy == MVT::f32 ||
861 VT.getSimpleVT().SimpleTy == MVT::f64)
862 Addr.Offset /= 4;
Eric Christopher299bbb22011-04-29 00:03:10 +0000863
Eric Christopher564857f2010-12-01 01:40:24 +0000864 // Frame base works a bit differently. Handle it separately.
865 if (Addr.BaseType == Address::FrameIndexBase) {
866 int FI = Addr.Base.FI;
867 int Offset = Addr.Offset;
868 MachineMemOperand *MMO =
869 FuncInfo.MF->getMachineMemOperand(
870 MachinePointerInfo::getFixedStack(FI, Offset),
Cameron Zwarichc152aa62011-05-28 20:34:49 +0000871 Flags,
Eric Christopher564857f2010-12-01 01:40:24 +0000872 MFI.getObjectSize(FI),
873 MFI.getObjectAlignment(FI));
874 // Now add the rest of the operands.
875 MIB.addFrameIndex(FI);
876
877 // ARM halfword load/stores need an additional operand.
878 if (!isThumb && VT.getSimpleVT().SimpleTy == MVT::i16) MIB.addReg(0);
879
880 MIB.addImm(Addr.Offset);
881 MIB.addMemOperand(MMO);
882 } else {
883 // Now add the rest of the operands.
884 MIB.addReg(Addr.Base.Reg);
Eric Christopher299bbb22011-04-29 00:03:10 +0000885
Eric Christopher564857f2010-12-01 01:40:24 +0000886 // ARM halfword load/stores need an additional operand.
887 if (!isThumb && VT.getSimpleVT().SimpleTy == MVT::i16) MIB.addReg(0);
888
889 MIB.addImm(Addr.Offset);
890 }
891 AddOptionalDefs(MIB);
892}
893
Eric Christopher0d581222010-11-19 22:30:02 +0000894bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr) {
Eric Christopherac1a19e2010-09-09 01:06:51 +0000895
Eric Christopherb1cc8482010-08-25 07:23:49 +0000896 assert(VT.isSimple() && "Non-simple types are invalid here!");
Eric Christopherdc908042010-08-31 01:28:42 +0000897 unsigned Opc;
Eric Christopheree56ea62010-10-07 05:50:44 +0000898 TargetRegisterClass *RC;
Eric Christopherb1cc8482010-08-25 07:23:49 +0000899 switch (VT.getSimpleVT().SimpleTy) {
Eric Christopher564857f2010-12-01 01:40:24 +0000900 // This is mostly going to be Neon/vector support.
901 default: return false;
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000902 case MVT::i16:
Eric Christopher45c60712010-10-17 01:40:27 +0000903 Opc = isThumb ? ARM::t2LDRHi12 : ARM::LDRH;
Eric Christopher7a56f332010-10-08 01:13:17 +0000904 RC = ARM::GPRRegisterClass;
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000905 break;
906 case MVT::i8:
Jim Grosbachc1d30212010-10-27 00:19:44 +0000907 Opc = isThumb ? ARM::t2LDRBi12 : ARM::LDRBi12;
Eric Christopher7a56f332010-10-08 01:13:17 +0000908 RC = ARM::GPRRegisterClass;
Eric Christopher4e68c7c2010-09-01 18:01:32 +0000909 break;
Eric Christopherdc908042010-08-31 01:28:42 +0000910 case MVT::i32:
Jim Grosbach3e556122010-10-26 22:37:02 +0000911 Opc = isThumb ? ARM::t2LDRi12 : ARM::LDRi12;
Eric Christopher7a56f332010-10-08 01:13:17 +0000912 RC = ARM::GPRRegisterClass;
Eric Christopherdc908042010-08-31 01:28:42 +0000913 break;
Eric Christopher6dab1372010-09-18 01:59:37 +0000914 case MVT::f32:
915 Opc = ARM::VLDRS;
Eric Christopheree56ea62010-10-07 05:50:44 +0000916 RC = TLI.getRegClassFor(VT);
Eric Christopher6dab1372010-09-18 01:59:37 +0000917 break;
918 case MVT::f64:
919 Opc = ARM::VLDRD;
Eric Christopheree56ea62010-10-07 05:50:44 +0000920 RC = TLI.getRegClassFor(VT);
Eric Christopher6dab1372010-09-18 01:59:37 +0000921 break;
Eric Christopherb1cc8482010-08-25 07:23:49 +0000922 }
Eric Christopher564857f2010-12-01 01:40:24 +0000923 // Simplify this down to something we can handle.
Eric Christopher0d581222010-11-19 22:30:02 +0000924 ARMSimplifyAddress(Addr, VT);
Jim Grosbach6b156392010-10-27 21:39:08 +0000925
Eric Christopher564857f2010-12-01 01:40:24 +0000926 // Create the base instruction, then add the operands.
927 ResultReg = createResultReg(RC);
928 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
929 TII.get(Opc), ResultReg);
Cameron Zwarichc152aa62011-05-28 20:34:49 +0000930 AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOLoad);
Eric Christopherdc908042010-08-31 01:28:42 +0000931 return true;
Eric Christopherb1cc8482010-08-25 07:23:49 +0000932}
933
Eric Christopher43b62be2010-09-27 06:02:23 +0000934bool ARMFastISel::SelectLoad(const Instruction *I) {
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000935 // Verify we have a legal type before going any further.
Duncan Sands1440e8b2010-11-03 11:35:31 +0000936 MVT VT;
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000937 if (!isLoadTypeLegal(I->getType(), VT))
938 return false;
939
Eric Christopher564857f2010-12-01 01:40:24 +0000940 // See if we can handle this address.
Eric Christopher0d581222010-11-19 22:30:02 +0000941 Address Addr;
Eric Christopher564857f2010-12-01 01:40:24 +0000942 if (!ARMComputeAddress(I->getOperand(0), Addr)) return false;
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000943
944 unsigned ResultReg;
Eric Christopher0d581222010-11-19 22:30:02 +0000945 if (!ARMEmitLoad(VT, ResultReg, Addr)) return false;
Eric Christopherdb12b2b2010-09-10 00:34:35 +0000946 UpdateValueMap(I, ResultReg);
947 return true;
948}
949
Eric Christopher0d581222010-11-19 22:30:02 +0000950bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr) {
Eric Christopher318b6ee2010-09-02 00:53:56 +0000951 unsigned StrOpc;
952 switch (VT.getSimpleVT().SimpleTy) {
Eric Christopher564857f2010-12-01 01:40:24 +0000953 // This is mostly going to be Neon/vector support.
Eric Christopher318b6ee2010-09-02 00:53:56 +0000954 default: return false;
Eric Christopher4c914122010-11-02 23:59:09 +0000955 case MVT::i1: {
956 unsigned Res = createResultReg(isThumb ? ARM::tGPRRegisterClass :
957 ARM::GPRRegisterClass);
958 unsigned Opc = isThumb ? ARM::t2ANDri : ARM::ANDri;
959 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
960 TII.get(Opc), Res)
961 .addReg(SrcReg).addImm(1));
962 SrcReg = Res;
963 } // Fallthrough here.
Eric Christopher2896df82010-10-15 18:02:07 +0000964 case MVT::i8:
Jim Grosbach7e3383c2010-10-27 23:12:14 +0000965 StrOpc = isThumb ? ARM::t2STRBi12 : ARM::STRBi12;
Eric Christopher15418772010-10-12 05:39:06 +0000966 break;
967 case MVT::i16:
Eric Christopher45c60712010-10-17 01:40:27 +0000968 StrOpc = isThumb ? ARM::t2STRHi12 : ARM::STRH;
Eric Christopher15418772010-10-12 05:39:06 +0000969 break;
Eric Christopher47650ec2010-10-16 01:10:35 +0000970 case MVT::i32:
Jim Grosbach7e3383c2010-10-27 23:12:14 +0000971 StrOpc = isThumb ? ARM::t2STRi12 : ARM::STRi12;
Eric Christopher47650ec2010-10-16 01:10:35 +0000972 break;
Eric Christopher56d2b722010-09-02 23:43:26 +0000973 case MVT::f32:
974 if (!Subtarget->hasVFP2()) return false;
975 StrOpc = ARM::VSTRS;
976 break;
977 case MVT::f64:
978 if (!Subtarget->hasVFP2()) return false;
979 StrOpc = ARM::VSTRD;
980 break;
Eric Christopher318b6ee2010-09-02 00:53:56 +0000981 }
Eric Christopher564857f2010-12-01 01:40:24 +0000982 // Simplify this down to something we can handle.
Eric Christopher0d581222010-11-19 22:30:02 +0000983 ARMSimplifyAddress(Addr, VT);
Jim Grosbach6b156392010-10-27 21:39:08 +0000984
Eric Christopher564857f2010-12-01 01:40:24 +0000985 // Create the base instruction, then add the operands.
986 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
987 TII.get(StrOpc))
988 .addReg(SrcReg, getKillRegState(true));
Cameron Zwarichc152aa62011-05-28 20:34:49 +0000989 AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOStore);
Eric Christopher318b6ee2010-09-02 00:53:56 +0000990 return true;
991}
992
Eric Christopher43b62be2010-09-27 06:02:23 +0000993bool ARMFastISel::SelectStore(const Instruction *I) {
Eric Christopher318b6ee2010-09-02 00:53:56 +0000994 Value *Op0 = I->getOperand(0);
995 unsigned SrcReg = 0;
996
Eric Christopher564857f2010-12-01 01:40:24 +0000997 // Verify we have a legal type before going any further.
Duncan Sands1440e8b2010-11-03 11:35:31 +0000998 MVT VT;
Eric Christopher318b6ee2010-09-02 00:53:56 +0000999 if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT))
Eric Christopher543cf052010-09-01 22:16:27 +00001000 return false;
Eric Christopher318b6ee2010-09-02 00:53:56 +00001001
Eric Christopher1b61ef42010-09-02 01:48:11 +00001002 // Get the value to be stored into a register.
1003 SrcReg = getRegForValue(Op0);
Eric Christopher564857f2010-12-01 01:40:24 +00001004 if (SrcReg == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001005
Eric Christopher564857f2010-12-01 01:40:24 +00001006 // See if we can handle this address.
Eric Christopher0d581222010-11-19 22:30:02 +00001007 Address Addr;
Eric Christopher0d581222010-11-19 22:30:02 +00001008 if (!ARMComputeAddress(I->getOperand(1), Addr))
Eric Christopher318b6ee2010-09-02 00:53:56 +00001009 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001010
Eric Christopher0d581222010-11-19 22:30:02 +00001011 if (!ARMEmitStore(VT, SrcReg, Addr)) return false;
Eric Christophera5b1e682010-09-17 22:28:18 +00001012 return true;
1013}
1014
1015static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) {
1016 switch (Pred) {
1017 // Needs two compares...
1018 case CmpInst::FCMP_ONE:
Eric Christopherdccd2c32010-10-11 08:38:55 +00001019 case CmpInst::FCMP_UEQ:
Eric Christophera5b1e682010-09-17 22:28:18 +00001020 default:
Eric Christopher4053e632010-11-02 01:24:49 +00001021 // AL is our "false" for now. The other two need more compares.
Eric Christophera5b1e682010-09-17 22:28:18 +00001022 return ARMCC::AL;
1023 case CmpInst::ICMP_EQ:
1024 case CmpInst::FCMP_OEQ:
1025 return ARMCC::EQ;
1026 case CmpInst::ICMP_SGT:
1027 case CmpInst::FCMP_OGT:
1028 return ARMCC::GT;
1029 case CmpInst::ICMP_SGE:
1030 case CmpInst::FCMP_OGE:
1031 return ARMCC::GE;
1032 case CmpInst::ICMP_UGT:
1033 case CmpInst::FCMP_UGT:
1034 return ARMCC::HI;
1035 case CmpInst::FCMP_OLT:
1036 return ARMCC::MI;
1037 case CmpInst::ICMP_ULE:
1038 case CmpInst::FCMP_OLE:
1039 return ARMCC::LS;
1040 case CmpInst::FCMP_ORD:
1041 return ARMCC::VC;
1042 case CmpInst::FCMP_UNO:
1043 return ARMCC::VS;
1044 case CmpInst::FCMP_UGE:
1045 return ARMCC::PL;
1046 case CmpInst::ICMP_SLT:
1047 case CmpInst::FCMP_ULT:
Eric Christopherdccd2c32010-10-11 08:38:55 +00001048 return ARMCC::LT;
Eric Christophera5b1e682010-09-17 22:28:18 +00001049 case CmpInst::ICMP_SLE:
1050 case CmpInst::FCMP_ULE:
1051 return ARMCC::LE;
1052 case CmpInst::FCMP_UNE:
1053 case CmpInst::ICMP_NE:
1054 return ARMCC::NE;
1055 case CmpInst::ICMP_UGE:
1056 return ARMCC::HS;
1057 case CmpInst::ICMP_ULT:
1058 return ARMCC::LO;
1059 }
Eric Christopher543cf052010-09-01 22:16:27 +00001060}
1061
Eric Christopher43b62be2010-09-27 06:02:23 +00001062bool ARMFastISel::SelectBranch(const Instruction *I) {
Eric Christophere5734102010-09-03 00:35:47 +00001063 const BranchInst *BI = cast<BranchInst>(I);
1064 MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)];
1065 MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)];
Eric Christopherac1a19e2010-09-09 01:06:51 +00001066
Eric Christophere5734102010-09-03 00:35:47 +00001067 // Simple branch support.
Jim Grosbach16cb3762010-11-09 19:22:26 +00001068
Eric Christopher0e6233b2010-10-29 21:08:19 +00001069 // If we can, avoid recomputing the compare - redoing it could lead to wonky
1070 // behavior.
1071 // TODO: Factor this out.
1072 if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) {
Eric Christopher632ae892011-04-29 21:56:31 +00001073 MVT SourceVT;
1074 const Type *Ty = CI->getOperand(0)->getType();
1075 if (CI->hasOneUse() && (CI->getParent() == I->getParent())
1076 && isTypeLegal(Ty, SourceVT)) {
Eric Christopher0e6233b2010-10-29 21:08:19 +00001077 bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
1078 if (isFloat && !Subtarget->hasVFP2())
1079 return false;
1080
1081 unsigned CmpOpc;
Eric Christopher632ae892011-04-29 21:56:31 +00001082 switch (SourceVT.SimpleTy) {
Eric Christopher0e6233b2010-10-29 21:08:19 +00001083 default: return false;
1084 // TODO: Verify compares.
1085 case MVT::f32:
1086 CmpOpc = ARM::VCMPES;
Eric Christopher0e6233b2010-10-29 21:08:19 +00001087 break;
1088 case MVT::f64:
1089 CmpOpc = ARM::VCMPED;
Eric Christopher0e6233b2010-10-29 21:08:19 +00001090 break;
1091 case MVT::i32:
1092 CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr;
Eric Christopher0e6233b2010-10-29 21:08:19 +00001093 break;
1094 }
1095
1096 // Get the compare predicate.
Eric Christopher632ae892011-04-29 21:56:31 +00001097 // Try to take advantage of fallthrough opportunities.
1098 CmpInst::Predicate Predicate = CI->getPredicate();
1099 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1100 std::swap(TBB, FBB);
1101 Predicate = CmpInst::getInversePredicate(Predicate);
1102 }
1103
1104 ARMCC::CondCodes ARMPred = getComparePred(Predicate);
Eric Christopher0e6233b2010-10-29 21:08:19 +00001105
1106 // We may not handle every CC for now.
1107 if (ARMPred == ARMCC::AL) return false;
1108
1109 unsigned Arg1 = getRegForValue(CI->getOperand(0));
1110 if (Arg1 == 0) return false;
1111
1112 unsigned Arg2 = getRegForValue(CI->getOperand(1));
1113 if (Arg2 == 0) return false;
1114
1115 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1116 TII.get(CmpOpc))
1117 .addReg(Arg1).addReg(Arg2));
Jim Grosbach16cb3762010-11-09 19:22:26 +00001118
Eric Christopher0e6233b2010-10-29 21:08:19 +00001119 // For floating point we need to move the result to a comparison register
1120 // that we can then use for branches.
1121 if (isFloat)
1122 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1123 TII.get(ARM::FMSTAT)));
Jim Grosbach16cb3762010-11-09 19:22:26 +00001124
Eric Christopher0e6233b2010-10-29 21:08:19 +00001125 unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc;
1126 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc))
1127 .addMBB(TBB).addImm(ARMPred).addReg(ARM::CPSR);
1128 FastEmitBranch(FBB, DL);
1129 FuncInfo.MBB->addSuccessor(TBB);
1130 return true;
1131 }
Eric Christopherbcf26ae2011-04-29 20:02:39 +00001132 } else if (TruncInst *TI = dyn_cast<TruncInst>(BI->getCondition())) {
1133 MVT SourceVT;
1134 if (TI->hasOneUse() && TI->getParent() == I->getParent() &&
Eli Friedman76927d732011-05-25 23:49:02 +00001135 (isLoadTypeLegal(TI->getOperand(0)->getType(), SourceVT))) {
Eric Christopherbcf26ae2011-04-29 20:02:39 +00001136 unsigned TstOpc = isThumb ? ARM::t2TSTri : ARM::TSTri;
1137 unsigned OpReg = getRegForValue(TI->getOperand(0));
1138 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1139 TII.get(TstOpc))
1140 .addReg(OpReg).addImm(1));
1141
1142 unsigned CCMode = ARMCC::NE;
1143 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1144 std::swap(TBB, FBB);
1145 CCMode = ARMCC::EQ;
1146 }
1147
1148 unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc;
1149 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc))
1150 .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
1151
1152 FastEmitBranch(FBB, DL);
1153 FuncInfo.MBB->addSuccessor(TBB);
1154 return true;
1155 }
Eric Christopher0e6233b2010-10-29 21:08:19 +00001156 }
Jim Grosbach16cb3762010-11-09 19:22:26 +00001157
Eric Christopher0e6233b2010-10-29 21:08:19 +00001158 unsigned CmpReg = getRegForValue(BI->getCondition());
1159 if (CmpReg == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001160
Stuart Hastingsc5eecbc2011-04-16 03:31:26 +00001161 // We've been divorced from our compare! Our block was split, and
1162 // now our compare lives in a predecessor block. We musn't
1163 // re-compare here, as the children of the compare aren't guaranteed
1164 // live across the block boundary (we *could* check for this).
1165 // Regardless, the compare has been done in the predecessor block,
1166 // and it left a value for us in a virtual register. Ergo, we test
1167 // the one-bit value left in the virtual register.
1168 unsigned TstOpc = isThumb ? ARM::t2TSTri : ARM::TSTri;
1169 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TstOpc))
1170 .addReg(CmpReg).addImm(1));
Eric Christopherdccd2c32010-10-11 08:38:55 +00001171
Eric Christopher7a20a372011-04-28 16:52:09 +00001172 unsigned CCMode = ARMCC::NE;
1173 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1174 std::swap(TBB, FBB);
1175 CCMode = ARMCC::EQ;
1176 }
1177
Eric Christophere5734102010-09-03 00:35:47 +00001178 unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc;
Eric Christophere5734102010-09-03 00:35:47 +00001179 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc))
Eric Christopher7a20a372011-04-28 16:52:09 +00001180 .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
Eric Christophere5734102010-09-03 00:35:47 +00001181 FastEmitBranch(FBB, DL);
1182 FuncInfo.MBB->addSuccessor(TBB);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001183 return true;
Eric Christophere5734102010-09-03 00:35:47 +00001184}
1185
Eric Christopher43b62be2010-09-27 06:02:23 +00001186bool ARMFastISel::SelectCmp(const Instruction *I) {
Eric Christopherd43393a2010-09-08 23:13:45 +00001187 const CmpInst *CI = cast<CmpInst>(I);
Eric Christopherac1a19e2010-09-09 01:06:51 +00001188
Duncan Sands1440e8b2010-11-03 11:35:31 +00001189 MVT VT;
Eric Christopherd43393a2010-09-08 23:13:45 +00001190 const Type *Ty = CI->getOperand(0)->getType();
1191 if (!isTypeLegal(Ty, VT))
1192 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001193
Eric Christopherd43393a2010-09-08 23:13:45 +00001194 bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
1195 if (isFloat && !Subtarget->hasVFP2())
1196 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001197
Eric Christopherd43393a2010-09-08 23:13:45 +00001198 unsigned CmpOpc;
Eric Christopher229207a2010-09-29 01:14:47 +00001199 unsigned CondReg;
Duncan Sands1440e8b2010-11-03 11:35:31 +00001200 switch (VT.SimpleTy) {
Eric Christopherd43393a2010-09-08 23:13:45 +00001201 default: return false;
1202 // TODO: Verify compares.
1203 case MVT::f32:
1204 CmpOpc = ARM::VCMPES;
Eric Christopher229207a2010-09-29 01:14:47 +00001205 CondReg = ARM::FPSCR;
Eric Christopherd43393a2010-09-08 23:13:45 +00001206 break;
1207 case MVT::f64:
1208 CmpOpc = ARM::VCMPED;
Eric Christopher229207a2010-09-29 01:14:47 +00001209 CondReg = ARM::FPSCR;
Eric Christopherd43393a2010-09-08 23:13:45 +00001210 break;
1211 case MVT::i32:
1212 CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr;
Eric Christopher229207a2010-09-29 01:14:47 +00001213 CondReg = ARM::CPSR;
Eric Christopherd43393a2010-09-08 23:13:45 +00001214 break;
1215 }
1216
Eric Christopher229207a2010-09-29 01:14:47 +00001217 // Get the compare predicate.
1218 ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate());
Eric Christopherdccd2c32010-10-11 08:38:55 +00001219
Eric Christopher229207a2010-09-29 01:14:47 +00001220 // We may not handle every CC for now.
1221 if (ARMPred == ARMCC::AL) return false;
1222
Eric Christopherd43393a2010-09-08 23:13:45 +00001223 unsigned Arg1 = getRegForValue(CI->getOperand(0));
1224 if (Arg1 == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001225
Eric Christopherd43393a2010-09-08 23:13:45 +00001226 unsigned Arg2 = getRegForValue(CI->getOperand(1));
1227 if (Arg2 == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001228
Eric Christopherd43393a2010-09-08 23:13:45 +00001229 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
1230 .addReg(Arg1).addReg(Arg2));
Eric Christopherac1a19e2010-09-09 01:06:51 +00001231
Eric Christopherdb12b2b2010-09-10 00:34:35 +00001232 // For floating point we need to move the result to a comparison register
1233 // that we can then use for branches.
Eric Christopherd43393a2010-09-08 23:13:45 +00001234 if (isFloat)
1235 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1236 TII.get(ARM::FMSTAT)));
Eric Christopherce07b542010-09-09 20:26:31 +00001237
Eric Christopher229207a2010-09-29 01:14:47 +00001238 // Now set a register based on the comparison. Explicitly set the predicates
1239 // here.
Eric Christopher338c2532010-10-07 05:31:49 +00001240 unsigned MovCCOpc = isThumb ? ARM::t2MOVCCi : ARM::MOVCCi;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001241 TargetRegisterClass *RC = isThumb ? ARM::rGPRRegisterClass
Eric Christopher5d18d922010-10-07 05:39:19 +00001242 : ARM::GPRRegisterClass;
1243 unsigned DestReg = createResultReg(RC);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001244 Constant *Zero
Eric Christopher8cf6c602010-09-29 22:24:45 +00001245 = ConstantInt::get(Type::getInt32Ty(*Context), 0);
Eric Christopher229207a2010-09-29 01:14:47 +00001246 unsigned ZeroReg = TargetMaterializeConstant(Zero);
1247 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), DestReg)
1248 .addReg(ZeroReg).addImm(1)
1249 .addImm(ARMPred).addReg(CondReg);
1250
Eric Christophera5b1e682010-09-17 22:28:18 +00001251 UpdateValueMap(I, DestReg);
Eric Christopherd43393a2010-09-08 23:13:45 +00001252 return true;
1253}
1254
Eric Christopher43b62be2010-09-27 06:02:23 +00001255bool ARMFastISel::SelectFPExt(const Instruction *I) {
Eric Christopher46203602010-09-09 00:26:48 +00001256 // Make sure we have VFP and that we're extending float to double.
1257 if (!Subtarget->hasVFP2()) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001258
Eric Christopher46203602010-09-09 00:26:48 +00001259 Value *V = I->getOperand(0);
1260 if (!I->getType()->isDoubleTy() ||
1261 !V->getType()->isFloatTy()) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001262
Eric Christopher46203602010-09-09 00:26:48 +00001263 unsigned Op = getRegForValue(V);
1264 if (Op == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001265
Eric Christopher46203602010-09-09 00:26:48 +00001266 unsigned Result = createResultReg(ARM::DPRRegisterClass);
Eric Christopherac1a19e2010-09-09 01:06:51 +00001267 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopheref2fdd22010-09-09 20:36:19 +00001268 TII.get(ARM::VCVTDS), Result)
Eric Christopherce07b542010-09-09 20:26:31 +00001269 .addReg(Op));
1270 UpdateValueMap(I, Result);
1271 return true;
1272}
1273
Eric Christopher43b62be2010-09-27 06:02:23 +00001274bool ARMFastISel::SelectFPTrunc(const Instruction *I) {
Eric Christopherce07b542010-09-09 20:26:31 +00001275 // Make sure we have VFP and that we're truncating double to float.
1276 if (!Subtarget->hasVFP2()) return false;
1277
1278 Value *V = I->getOperand(0);
Eric Christopher022b7fb2010-10-05 23:13:24 +00001279 if (!(I->getType()->isFloatTy() &&
1280 V->getType()->isDoubleTy())) return false;
Eric Christopherce07b542010-09-09 20:26:31 +00001281
1282 unsigned Op = getRegForValue(V);
1283 if (Op == 0) return false;
1284
1285 unsigned Result = createResultReg(ARM::SPRRegisterClass);
Eric Christopherce07b542010-09-09 20:26:31 +00001286 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopheref2fdd22010-09-09 20:36:19 +00001287 TII.get(ARM::VCVTSD), Result)
Eric Christopher46203602010-09-09 00:26:48 +00001288 .addReg(Op));
1289 UpdateValueMap(I, Result);
1290 return true;
1291}
1292
Eric Christopher43b62be2010-09-27 06:02:23 +00001293bool ARMFastISel::SelectSIToFP(const Instruction *I) {
Eric Christopher9a040492010-09-09 18:54:59 +00001294 // Make sure we have VFP.
1295 if (!Subtarget->hasVFP2()) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001296
Duncan Sands1440e8b2010-11-03 11:35:31 +00001297 MVT DstVT;
Eric Christopher9a040492010-09-09 18:54:59 +00001298 const Type *Ty = I->getType();
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001299 if (!isTypeLegal(Ty, DstVT))
Eric Christopher9a040492010-09-09 18:54:59 +00001300 return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001301
Eli Friedman783c6642011-05-25 19:09:45 +00001302 // FIXME: Handle sign-extension where necessary.
1303 if (!I->getOperand(0)->getType()->isIntegerTy(32))
1304 return false;
1305
Eric Christopher9a040492010-09-09 18:54:59 +00001306 unsigned Op = getRegForValue(I->getOperand(0));
1307 if (Op == 0) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001308
Eric Christopherdb12b2b2010-09-10 00:34:35 +00001309 // The conversion routine works on fp-reg to fp-reg and the operand above
1310 // was an integer, move it to the fp registers if possible.
Eric Christopher022b7fb2010-10-05 23:13:24 +00001311 unsigned FP = ARMMoveToFPReg(MVT::f32, Op);
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001312 if (FP == 0) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001313
Eric Christopher9a040492010-09-09 18:54:59 +00001314 unsigned Opc;
1315 if (Ty->isFloatTy()) Opc = ARM::VSITOS;
1316 else if (Ty->isDoubleTy()) Opc = ARM::VSITOD;
1317 else return 0;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001318
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001319 unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT));
Eric Christopher9a040492010-09-09 18:54:59 +00001320 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
1321 ResultReg)
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001322 .addReg(FP));
Eric Christopherce07b542010-09-09 20:26:31 +00001323 UpdateValueMap(I, ResultReg);
Eric Christopher9a040492010-09-09 18:54:59 +00001324 return true;
1325}
1326
Eric Christopher43b62be2010-09-27 06:02:23 +00001327bool ARMFastISel::SelectFPToSI(const Instruction *I) {
Eric Christopher9a040492010-09-09 18:54:59 +00001328 // Make sure we have VFP.
1329 if (!Subtarget->hasVFP2()) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001330
Duncan Sands1440e8b2010-11-03 11:35:31 +00001331 MVT DstVT;
Eric Christopher9a040492010-09-09 18:54:59 +00001332 const Type *RetTy = I->getType();
Eric Christopher920a2082010-09-10 00:35:09 +00001333 if (!isTypeLegal(RetTy, DstVT))
Eric Christopher9a040492010-09-09 18:54:59 +00001334 return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001335
Eric Christopher9a040492010-09-09 18:54:59 +00001336 unsigned Op = getRegForValue(I->getOperand(0));
1337 if (Op == 0) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001338
Eric Christopher9a040492010-09-09 18:54:59 +00001339 unsigned Opc;
1340 const Type *OpTy = I->getOperand(0)->getType();
1341 if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS;
1342 else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD;
1343 else return 0;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001344
Eric Christopher022b7fb2010-10-05 23:13:24 +00001345 // f64->s32 or f32->s32 both need an intermediate f32 reg.
1346 unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32));
Eric Christopher9a040492010-09-09 18:54:59 +00001347 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
1348 ResultReg)
1349 .addReg(Op));
Eric Christopherdccd2c32010-10-11 08:38:55 +00001350
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001351 // This result needs to be in an integer register, but the conversion only
1352 // takes place in fp-regs.
Eric Christopherdb12b2b2010-09-10 00:34:35 +00001353 unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg);
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001354 if (IntReg == 0) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001355
Eric Christopher9ee4ce22010-09-09 21:44:45 +00001356 UpdateValueMap(I, IntReg);
Eric Christopher9a040492010-09-09 18:54:59 +00001357 return true;
1358}
1359
Eric Christopher3bbd3962010-10-11 08:27:59 +00001360bool ARMFastISel::SelectSelect(const Instruction *I) {
Duncan Sands1440e8b2010-11-03 11:35:31 +00001361 MVT VT;
1362 if (!isTypeLegal(I->getType(), VT))
Eric Christopher3bbd3962010-10-11 08:27:59 +00001363 return false;
1364
1365 // Things need to be register sized for register moves.
Duncan Sands1440e8b2010-11-03 11:35:31 +00001366 if (VT != MVT::i32) return false;
Eric Christopher3bbd3962010-10-11 08:27:59 +00001367 const TargetRegisterClass *RC = TLI.getRegClassFor(VT);
1368
1369 unsigned CondReg = getRegForValue(I->getOperand(0));
1370 if (CondReg == 0) return false;
1371 unsigned Op1Reg = getRegForValue(I->getOperand(1));
1372 if (Op1Reg == 0) return false;
1373 unsigned Op2Reg = getRegForValue(I->getOperand(2));
1374 if (Op2Reg == 0) return false;
1375
1376 unsigned CmpOpc = isThumb ? ARM::t2TSTri : ARM::TSTri;
1377 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
1378 .addReg(CondReg).addImm(1));
1379 unsigned ResultReg = createResultReg(RC);
1380 unsigned MovCCOpc = isThumb ? ARM::t2MOVCCr : ARM::MOVCCr;
1381 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), ResultReg)
1382 .addReg(Op1Reg).addReg(Op2Reg)
1383 .addImm(ARMCC::EQ).addReg(ARM::CPSR);
1384 UpdateValueMap(I, ResultReg);
1385 return true;
1386}
1387
Eric Christopher08637852010-09-30 22:34:19 +00001388bool ARMFastISel::SelectSDiv(const Instruction *I) {
Duncan Sands1440e8b2010-11-03 11:35:31 +00001389 MVT VT;
Eric Christopher08637852010-09-30 22:34:19 +00001390 const Type *Ty = I->getType();
1391 if (!isTypeLegal(Ty, VT))
1392 return false;
1393
1394 // If we have integer div support we should have selected this automagically.
1395 // In case we have a real miss go ahead and return false and we'll pick
1396 // it up later.
Eric Christopherdccd2c32010-10-11 08:38:55 +00001397 if (Subtarget->hasDivide()) return false;
1398
Eric Christopher08637852010-09-30 22:34:19 +00001399 // Otherwise emit a libcall.
1400 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
Eric Christopher7bdc4de2010-10-11 08:31:54 +00001401 if (VT == MVT::i8)
1402 LC = RTLIB::SDIV_I8;
1403 else if (VT == MVT::i16)
Eric Christopher08637852010-09-30 22:34:19 +00001404 LC = RTLIB::SDIV_I16;
1405 else if (VT == MVT::i32)
1406 LC = RTLIB::SDIV_I32;
1407 else if (VT == MVT::i64)
1408 LC = RTLIB::SDIV_I64;
1409 else if (VT == MVT::i128)
1410 LC = RTLIB::SDIV_I128;
1411 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!");
Eric Christopherdccd2c32010-10-11 08:38:55 +00001412
Eric Christopher08637852010-09-30 22:34:19 +00001413 return ARMEmitLibcall(I, LC);
1414}
1415
Eric Christopher6a880d62010-10-11 08:37:26 +00001416bool ARMFastISel::SelectSRem(const Instruction *I) {
Duncan Sands1440e8b2010-11-03 11:35:31 +00001417 MVT VT;
Eric Christopher6a880d62010-10-11 08:37:26 +00001418 const Type *Ty = I->getType();
1419 if (!isTypeLegal(Ty, VT))
1420 return false;
1421
1422 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1423 if (VT == MVT::i8)
1424 LC = RTLIB::SREM_I8;
1425 else if (VT == MVT::i16)
1426 LC = RTLIB::SREM_I16;
1427 else if (VT == MVT::i32)
1428 LC = RTLIB::SREM_I32;
1429 else if (VT == MVT::i64)
1430 LC = RTLIB::SREM_I64;
1431 else if (VT == MVT::i128)
1432 LC = RTLIB::SREM_I128;
Eric Christophera1640d92010-10-11 08:40:05 +00001433 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!");
Eric Christopher2896df82010-10-15 18:02:07 +00001434
Eric Christopher6a880d62010-10-11 08:37:26 +00001435 return ARMEmitLibcall(I, LC);
1436}
1437
Eric Christopher43b62be2010-09-27 06:02:23 +00001438bool ARMFastISel::SelectBinaryOp(const Instruction *I, unsigned ISDOpcode) {
Eric Christopherbd6bf082010-09-09 01:02:03 +00001439 EVT VT = TLI.getValueType(I->getType(), true);
Eric Christopherac1a19e2010-09-09 01:06:51 +00001440
Eric Christopherbc39b822010-09-09 00:53:57 +00001441 // We can get here in the case when we want to use NEON for our fp
1442 // operations, but can't figure out how to. Just use the vfp instructions
1443 // if we have them.
1444 // FIXME: It'd be nice to use NEON instructions.
Eric Christopherbd6bf082010-09-09 01:02:03 +00001445 const Type *Ty = I->getType();
1446 bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
1447 if (isFloat && !Subtarget->hasVFP2())
1448 return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001449
Eric Christopherbc39b822010-09-09 00:53:57 +00001450 unsigned Op1 = getRegForValue(I->getOperand(0));
1451 if (Op1 == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001452
Eric Christopherbc39b822010-09-09 00:53:57 +00001453 unsigned Op2 = getRegForValue(I->getOperand(1));
1454 if (Op2 == 0) return false;
Eric Christopherac1a19e2010-09-09 01:06:51 +00001455
Eric Christopherbc39b822010-09-09 00:53:57 +00001456 unsigned Opc;
Duncan Sandscdfad362010-11-03 12:17:33 +00001457 bool is64bit = VT == MVT::f64 || VT == MVT::i64;
Eric Christopherbc39b822010-09-09 00:53:57 +00001458 switch (ISDOpcode) {
1459 default: return false;
1460 case ISD::FADD:
Eric Christopherbd6bf082010-09-09 01:02:03 +00001461 Opc = is64bit ? ARM::VADDD : ARM::VADDS;
Eric Christopherbc39b822010-09-09 00:53:57 +00001462 break;
1463 case ISD::FSUB:
Eric Christopherbd6bf082010-09-09 01:02:03 +00001464 Opc = is64bit ? ARM::VSUBD : ARM::VSUBS;
Eric Christopherbc39b822010-09-09 00:53:57 +00001465 break;
1466 case ISD::FMUL:
Eric Christopherbd6bf082010-09-09 01:02:03 +00001467 Opc = is64bit ? ARM::VMULD : ARM::VMULS;
Eric Christopherbc39b822010-09-09 00:53:57 +00001468 break;
1469 }
Eric Christopherbd6bf082010-09-09 01:02:03 +00001470 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
Eric Christopherbc39b822010-09-09 00:53:57 +00001471 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1472 TII.get(Opc), ResultReg)
1473 .addReg(Op1).addReg(Op2));
Eric Christopherce07b542010-09-09 20:26:31 +00001474 UpdateValueMap(I, ResultReg);
Eric Christopherbc39b822010-09-09 00:53:57 +00001475 return true;
1476}
1477
Eric Christopherd10cd7b2010-09-10 23:18:12 +00001478// Call Handling Code
1479
Eric Christopherfa87d662010-10-18 02:17:53 +00001480bool ARMFastISel::FastEmitExtend(ISD::NodeType Opc, EVT DstVT, unsigned Src,
1481 EVT SrcVT, unsigned &ResultReg) {
1482 unsigned RR = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(), Opc,
1483 Src, /*TODO: Kill=*/false);
Jim Grosbach6b156392010-10-27 21:39:08 +00001484
Eric Christopherfa87d662010-10-18 02:17:53 +00001485 if (RR != 0) {
1486 ResultReg = RR;
1487 return true;
1488 } else
Jim Grosbach6b156392010-10-27 21:39:08 +00001489 return false;
Eric Christopherfa87d662010-10-18 02:17:53 +00001490}
1491
Eric Christopherd10cd7b2010-09-10 23:18:12 +00001492// This is largely taken directly from CCAssignFnForNode - we don't support
1493// varargs in FastISel so that part has been removed.
1494// TODO: We may not support all of this.
1495CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) {
1496 switch (CC) {
1497 default:
1498 llvm_unreachable("Unsupported calling convention");
Eric Christopherd10cd7b2010-09-10 23:18:12 +00001499 case CallingConv::Fast:
Evan Cheng1f8b40d2010-10-22 18:57:05 +00001500 // Ignore fastcc. Silence compiler warnings.
1501 (void)RetFastCC_ARM_APCS;
1502 (void)FastCC_ARM_APCS;
1503 // Fallthrough
1504 case CallingConv::C:
Eric Christopherd10cd7b2010-09-10 23:18:12 +00001505 // Use target triple & subtarget features to do actual dispatch.
1506 if (Subtarget->isAAPCS_ABI()) {
1507 if (Subtarget->hasVFP2() &&
1508 FloatABIType == FloatABI::Hard)
1509 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
1510 else
1511 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
1512 } else
1513 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1514 case CallingConv::ARM_AAPCS_VFP:
1515 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
1516 case CallingConv::ARM_AAPCS:
1517 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
1518 case CallingConv::ARM_APCS:
1519 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1520 }
1521}
1522
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001523bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args,
1524 SmallVectorImpl<unsigned> &ArgRegs,
Duncan Sands1440e8b2010-11-03 11:35:31 +00001525 SmallVectorImpl<MVT> &ArgVTs,
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001526 SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
1527 SmallVectorImpl<unsigned> &RegArgs,
1528 CallingConv::ID CC,
1529 unsigned &NumBytes) {
1530 SmallVector<CCValAssign, 16> ArgLocs;
1531 CCState CCInfo(CC, false, TM, ArgLocs, *Context);
1532 CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC, false));
1533
1534 // Get a count of how many bytes are to be pushed on the stack.
1535 NumBytes = CCInfo.getNextStackOffset();
1536
1537 // Issue CALLSEQ_START
1538 unsigned AdjStackDown = TM.getRegisterInfo()->getCallFrameSetupOpcode();
Eric Christopherfb0b8922010-10-11 21:20:02 +00001539 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1540 TII.get(AdjStackDown))
1541 .addImm(NumBytes));
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001542
1543 // Process the args.
1544 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1545 CCValAssign &VA = ArgLocs[i];
1546 unsigned Arg = ArgRegs[VA.getValNo()];
Duncan Sands1440e8b2010-11-03 11:35:31 +00001547 MVT ArgVT = ArgVTs[VA.getValNo()];
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001548
Eric Christopher4a2b3162011-01-27 05:44:56 +00001549 // We don't handle NEON/vector parameters yet.
1550 if (ArgVT.isVector() || ArgVT.getSizeInBits() > 64)
Eric Christophera4633f52010-10-23 09:37:17 +00001551 return false;
1552
Eric Christopherf9764fa2010-09-30 20:49:44 +00001553 // Handle arg promotion, etc.
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001554 switch (VA.getLocInfo()) {
1555 case CCValAssign::Full: break;
Eric Christopherfa87d662010-10-18 02:17:53 +00001556 case CCValAssign::SExt: {
1557 bool Emitted = FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(),
1558 Arg, ArgVT, Arg);
Chris Lattner54c6d6f2011-01-05 18:41:05 +00001559 assert(Emitted && "Failed to emit a sext!"); (void)Emitted;
Eric Christopherfa87d662010-10-18 02:17:53 +00001560 Emitted = true;
1561 ArgVT = VA.getLocVT();
1562 break;
1563 }
1564 case CCValAssign::ZExt: {
1565 bool Emitted = FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(),
1566 Arg, ArgVT, Arg);
Chris Lattner54c6d6f2011-01-05 18:41:05 +00001567 assert(Emitted && "Failed to emit a zext!"); (void)Emitted;
Eric Christopherfa87d662010-10-18 02:17:53 +00001568 Emitted = true;
1569 ArgVT = VA.getLocVT();
1570 break;
1571 }
1572 case CCValAssign::AExt: {
Eric Christopherfa87d662010-10-18 02:17:53 +00001573 bool Emitted = FastEmitExtend(ISD::ANY_EXTEND, VA.getLocVT(),
1574 Arg, ArgVT, Arg);
1575 if (!Emitted)
1576 Emitted = FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(),
1577 Arg, ArgVT, Arg);
1578 if (!Emitted)
1579 Emitted = FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(),
1580 Arg, ArgVT, Arg);
1581
Chris Lattner54c6d6f2011-01-05 18:41:05 +00001582 assert(Emitted && "Failed to emit a aext!"); (void)Emitted;
Eric Christopherfa87d662010-10-18 02:17:53 +00001583 ArgVT = VA.getLocVT();
1584 break;
1585 }
1586 case CCValAssign::BCvt: {
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001587 unsigned BC = FastEmit_r(ArgVT, VA.getLocVT(), ISD::BITCAST, Arg,
Duncan Sands1440e8b2010-11-03 11:35:31 +00001588 /*TODO: Kill=*/false);
Eric Christopherfa87d662010-10-18 02:17:53 +00001589 assert(BC != 0 && "Failed to emit a bitcast!");
1590 Arg = BC;
1591 ArgVT = VA.getLocVT();
1592 break;
1593 }
1594 default: llvm_unreachable("Unknown arg promotion!");
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001595 }
1596
1597 // Now copy/store arg to correct locations.
Eric Christopherfb0b8922010-10-11 21:20:02 +00001598 if (VA.isRegLoc() && !VA.needsCustom()) {
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001599 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
Eric Christopherf9764fa2010-09-30 20:49:44 +00001600 VA.getLocReg())
1601 .addReg(Arg);
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001602 RegArgs.push_back(VA.getLocReg());
Eric Christopher2d8f6fe2010-10-21 00:01:47 +00001603 } else if (VA.needsCustom()) {
1604 // TODO: We need custom lowering for vector (v2f64) args.
1605 if (VA.getLocVT() != MVT::f64) return false;
Jim Grosbach6b156392010-10-27 21:39:08 +00001606
Eric Christopher2d8f6fe2010-10-21 00:01:47 +00001607 CCValAssign &NextVA = ArgLocs[++i];
1608
1609 // TODO: Only handle register args for now.
1610 if(!(VA.isRegLoc() && NextVA.isRegLoc())) return false;
1611
1612 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1613 TII.get(ARM::VMOVRRD), VA.getLocReg())
1614 .addReg(NextVA.getLocReg(), RegState::Define)
1615 .addReg(Arg));
1616 RegArgs.push_back(VA.getLocReg());
1617 RegArgs.push_back(NextVA.getLocReg());
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001618 } else {
Eric Christopher5b924802010-10-21 20:09:54 +00001619 assert(VA.isMemLoc());
1620 // Need to store on the stack.
Eric Christopher0d581222010-11-19 22:30:02 +00001621 Address Addr;
1622 Addr.BaseType = Address::RegBase;
1623 Addr.Base.Reg = ARM::SP;
1624 Addr.Offset = VA.getLocMemOffset();
Eric Christopher5b924802010-10-21 20:09:54 +00001625
Eric Christopher0d581222010-11-19 22:30:02 +00001626 if (!ARMEmitStore(ArgVT, Arg, Addr)) return false;
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001627 }
1628 }
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001629 return true;
1630}
1631
Duncan Sands1440e8b2010-11-03 11:35:31 +00001632bool ARMFastISel::FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001633 const Instruction *I, CallingConv::ID CC,
1634 unsigned &NumBytes) {
1635 // Issue CALLSEQ_END
1636 unsigned AdjStackUp = TM.getRegisterInfo()->getCallFrameDestroyOpcode();
Eric Christopherfb0b8922010-10-11 21:20:02 +00001637 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1638 TII.get(AdjStackUp))
1639 .addImm(NumBytes).addImm(0));
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001640
1641 // Now the return value.
Duncan Sands1440e8b2010-11-03 11:35:31 +00001642 if (RetVT != MVT::isVoid) {
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001643 SmallVector<CCValAssign, 16> RVLocs;
1644 CCState CCInfo(CC, false, TM, RVLocs, *Context);
1645 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true));
1646
1647 // Copy all of the result registers out of their specified physreg.
Duncan Sands1440e8b2010-11-03 11:35:31 +00001648 if (RVLocs.size() == 2 && RetVT == MVT::f64) {
Eric Christopher14df8822010-10-01 00:00:11 +00001649 // For this move we copy into two registers and then move into the
1650 // double fp reg we want.
Eric Christopher14df8822010-10-01 00:00:11 +00001651 EVT DestVT = RVLocs[0].getValVT();
1652 TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT);
1653 unsigned ResultReg = createResultReg(DstRC);
1654 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1655 TII.get(ARM::VMOVDRR), ResultReg)
Eric Christopher3659ac22010-10-20 08:02:24 +00001656 .addReg(RVLocs[0].getLocReg())
1657 .addReg(RVLocs[1].getLocReg()));
Eric Christopherdccd2c32010-10-11 08:38:55 +00001658
Eric Christopher3659ac22010-10-20 08:02:24 +00001659 UsedRegs.push_back(RVLocs[0].getLocReg());
1660 UsedRegs.push_back(RVLocs[1].getLocReg());
Jim Grosbach6b156392010-10-27 21:39:08 +00001661
Eric Christopherdccd2c32010-10-11 08:38:55 +00001662 // Finally update the result.
Eric Christopher14df8822010-10-01 00:00:11 +00001663 UpdateValueMap(I, ResultReg);
1664 } else {
Jim Grosbach95369592010-10-13 23:34:31 +00001665 assert(RVLocs.size() == 1 &&"Can't handle non-double multi-reg retvals!");
Eric Christopher14df8822010-10-01 00:00:11 +00001666 EVT CopyVT = RVLocs[0].getValVT();
1667 TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT);
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001668
Eric Christopher14df8822010-10-01 00:00:11 +00001669 unsigned ResultReg = createResultReg(DstRC);
1670 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
1671 ResultReg).addReg(RVLocs[0].getLocReg());
1672 UsedRegs.push_back(RVLocs[0].getLocReg());
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001673
Eric Christopherdccd2c32010-10-11 08:38:55 +00001674 // Finally update the result.
Eric Christopher14df8822010-10-01 00:00:11 +00001675 UpdateValueMap(I, ResultReg);
1676 }
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001677 }
1678
Eric Christopherdccd2c32010-10-11 08:38:55 +00001679 return true;
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001680}
1681
Eric Christopher4f512ef2010-10-22 01:28:00 +00001682bool ARMFastISel::SelectRet(const Instruction *I) {
1683 const ReturnInst *Ret = cast<ReturnInst>(I);
1684 const Function &F = *I->getParent()->getParent();
Jim Grosbach6b156392010-10-27 21:39:08 +00001685
Eric Christopher4f512ef2010-10-22 01:28:00 +00001686 if (!FuncInfo.CanLowerReturn)
1687 return false;
Jim Grosbach6b156392010-10-27 21:39:08 +00001688
Eric Christopher4f512ef2010-10-22 01:28:00 +00001689 if (F.isVarArg())
1690 return false;
1691
1692 CallingConv::ID CC = F.getCallingConv();
1693 if (Ret->getNumOperands() > 0) {
1694 SmallVector<ISD::OutputArg, 4> Outs;
1695 GetReturnInfo(F.getReturnType(), F.getAttributes().getRetAttributes(),
1696 Outs, TLI);
1697
1698 // Analyze operands of the call, assigning locations to each operand.
1699 SmallVector<CCValAssign, 16> ValLocs;
1700 CCState CCInfo(CC, F.isVarArg(), TM, ValLocs, I->getContext());
1701 CCInfo.AnalyzeReturn(Outs, CCAssignFnForCall(CC, true /* is Ret */));
1702
1703 const Value *RV = Ret->getOperand(0);
1704 unsigned Reg = getRegForValue(RV);
1705 if (Reg == 0)
1706 return false;
1707
1708 // Only handle a single return value for now.
1709 if (ValLocs.size() != 1)
1710 return false;
1711
1712 CCValAssign &VA = ValLocs[0];
Jim Grosbach6b156392010-10-27 21:39:08 +00001713
Eric Christopher4f512ef2010-10-22 01:28:00 +00001714 // Don't bother handling odd stuff for now.
1715 if (VA.getLocInfo() != CCValAssign::Full)
1716 return false;
1717 // Only handle register returns for now.
1718 if (!VA.isRegLoc())
1719 return false;
1720 // TODO: For now, don't try to handle cases where getLocInfo()
1721 // says Full but the types don't match.
Duncan Sands1e96bab2010-11-04 10:49:57 +00001722 if (TLI.getValueType(RV->getType()) != VA.getValVT())
Eric Christopher4f512ef2010-10-22 01:28:00 +00001723 return false;
Jim Grosbach6b156392010-10-27 21:39:08 +00001724
Eric Christopher4f512ef2010-10-22 01:28:00 +00001725 // Make the copy.
1726 unsigned SrcReg = Reg + VA.getValNo();
1727 unsigned DstReg = VA.getLocReg();
1728 const TargetRegisterClass* SrcRC = MRI.getRegClass(SrcReg);
1729 // Avoid a cross-class copy. This is very unlikely.
1730 if (!SrcRC->contains(DstReg))
1731 return false;
1732 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
1733 DstReg).addReg(SrcReg);
1734
1735 // Mark the register as live out of the function.
1736 MRI.addLiveOut(VA.getLocReg());
1737 }
Jim Grosbach6b156392010-10-27 21:39:08 +00001738
Eric Christopher4f512ef2010-10-22 01:28:00 +00001739 unsigned RetOpc = isThumb ? ARM::tBX_RET : ARM::BX_RET;
1740 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1741 TII.get(RetOpc)));
1742 return true;
1743}
1744
Eric Christopher872f4a22011-02-22 01:37:10 +00001745unsigned ARMFastISel::ARMSelectCallOp(const GlobalValue *GV) {
1746
Eric Christopher872f4a22011-02-22 01:37:10 +00001747 // Darwin needs the r9 versions of the opcodes.
1748 bool isDarwin = Subtarget->isTargetDarwin();
Eric Christopher04356612011-04-05 00:39:26 +00001749 if (isThumb) {
Eric Christopher872f4a22011-02-22 01:37:10 +00001750 return isDarwin ? ARM::tBLr9 : ARM::tBL;
1751 } else {
1752 return isDarwin ? ARM::BLr9 : ARM::BL;
1753 }
1754}
1755
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001756// A quick function that will emit a call for a named libcall in F with the
1757// vector of passed arguments for the Instruction in I. We can assume that we
Eric Christopherdccd2c32010-10-11 08:38:55 +00001758// can emit a call for any libcall we can produce. This is an abridged version
1759// of the full call infrastructure since we won't need to worry about things
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001760// like computed function pointers or strange arguments at call sites.
1761// TODO: Try to unify this and the normal call bits for ARM, then try to unify
1762// with X86.
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001763bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) {
1764 CallingConv::ID CC = TLI.getLibcallCallingConv(Call);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001765
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001766 // Handle *simple* calls for now.
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001767 const Type *RetTy = I->getType();
Duncan Sands1440e8b2010-11-03 11:35:31 +00001768 MVT RetVT;
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001769 if (RetTy->isVoidTy())
1770 RetVT = MVT::isVoid;
1771 else if (!isTypeLegal(RetTy, RetVT))
1772 return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001773
Eric Christopher836c6242010-12-15 23:47:29 +00001774 // TODO: For now if we have long calls specified we don't handle the call.
1775 if (EnableARMLongCalls) return false;
1776
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001777 // Set up the argument vectors.
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001778 SmallVector<Value*, 8> Args;
1779 SmallVector<unsigned, 8> ArgRegs;
Duncan Sands1440e8b2010-11-03 11:35:31 +00001780 SmallVector<MVT, 8> ArgVTs;
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001781 SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
1782 Args.reserve(I->getNumOperands());
1783 ArgRegs.reserve(I->getNumOperands());
1784 ArgVTs.reserve(I->getNumOperands());
1785 ArgFlags.reserve(I->getNumOperands());
Eric Christopher7ed8ec92010-09-28 01:21:42 +00001786 for (unsigned i = 0; i < I->getNumOperands(); ++i) {
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001787 Value *Op = I->getOperand(i);
1788 unsigned Arg = getRegForValue(Op);
1789 if (Arg == 0) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001790
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001791 const Type *ArgTy = Op->getType();
Duncan Sands1440e8b2010-11-03 11:35:31 +00001792 MVT ArgVT;
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001793 if (!isTypeLegal(ArgTy, ArgVT)) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001794
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001795 ISD::ArgFlagsTy Flags;
1796 unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy);
1797 Flags.setOrigAlign(OriginalAlignment);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001798
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001799 Args.push_back(Op);
1800 ArgRegs.push_back(Arg);
1801 ArgVTs.push_back(ArgVT);
1802 ArgFlags.push_back(Flags);
1803 }
Eric Christopherdccd2c32010-10-11 08:38:55 +00001804
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001805 // Handle the arguments now that we've gotten them.
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001806 SmallVector<unsigned, 4> RegArgs;
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001807 unsigned NumBytes;
1808 if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes))
1809 return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001810
Eric Christopher6344a5f2011-04-29 00:07:20 +00001811 // Issue the call, BLr9 for darwin, BL otherwise.
Eric Christopherdccd2c32010-10-11 08:38:55 +00001812 // TODO: Turn this into the table of arm call ops.
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001813 MachineInstrBuilder MIB;
Eric Christopher872f4a22011-02-22 01:37:10 +00001814 unsigned CallOpc = ARMSelectCallOp(NULL);
1815 if(isThumb)
Eric Christopherc19aadb2010-12-21 03:50:43 +00001816 // Explicitly adding the predicate here.
1817 MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1818 TII.get(CallOpc)))
1819 .addExternalSymbol(TLI.getLibcallName(Call));
Eric Christopher872f4a22011-02-22 01:37:10 +00001820 else
Eric Christopherc19aadb2010-12-21 03:50:43 +00001821 // Explicitly adding the predicate here.
1822 MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1823 TII.get(CallOpc))
1824 .addExternalSymbol(TLI.getLibcallName(Call)));
Eric Christopherdccd2c32010-10-11 08:38:55 +00001825
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001826 // Add implicit physical register uses to the call.
1827 for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
1828 MIB.addReg(RegArgs[i]);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001829
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001830 // Finish off the call including any return values.
Eric Christopherdccd2c32010-10-11 08:38:55 +00001831 SmallVector<unsigned, 4> UsedRegs;
Eric Christophera9a7a1a2010-09-29 23:11:09 +00001832 if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001833
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001834 // Set all unused physreg defs as dead.
1835 static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001836
Eric Christopherbb3e5da2010-09-14 23:03:37 +00001837 return true;
1838}
1839
Eric Christopherf9764fa2010-09-30 20:49:44 +00001840bool ARMFastISel::SelectCall(const Instruction *I) {
1841 const CallInst *CI = cast<CallInst>(I);
1842 const Value *Callee = CI->getCalledValue();
1843
1844 // Can't handle inline asm or worry about intrinsics yet.
1845 if (isa<InlineAsm>(Callee) || isa<IntrinsicInst>(CI)) return false;
1846
Eric Christopher52f6c032011-05-02 20:16:33 +00001847 // Only handle global variable Callees.
Eric Christopherf9764fa2010-09-30 20:49:44 +00001848 const GlobalValue *GV = dyn_cast<GlobalValue>(Callee);
Eric Christopher52f6c032011-05-02 20:16:33 +00001849 if (!GV)
Eric Christophere6ca6772010-10-01 21:33:12 +00001850 return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001851
Eric Christopherf9764fa2010-09-30 20:49:44 +00001852 // Check the calling convention.
1853 ImmutableCallSite CS(CI);
1854 CallingConv::ID CC = CS.getCallingConv();
Eric Christopher4cf34c62010-10-18 06:49:12 +00001855
Eric Christopherf9764fa2010-09-30 20:49:44 +00001856 // TODO: Avoid some calling conventions?
Eric Christopherdccd2c32010-10-11 08:38:55 +00001857
Eric Christopherf9764fa2010-09-30 20:49:44 +00001858 // Let SDISel handle vararg functions.
1859 const PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType());
1860 const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
1861 if (FTy->isVarArg())
1862 return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001863
Eric Christopherf9764fa2010-09-30 20:49:44 +00001864 // Handle *simple* calls for now.
1865 const Type *RetTy = I->getType();
Duncan Sands1440e8b2010-11-03 11:35:31 +00001866 MVT RetVT;
Eric Christopherf9764fa2010-09-30 20:49:44 +00001867 if (RetTy->isVoidTy())
1868 RetVT = MVT::isVoid;
1869 else if (!isTypeLegal(RetTy, RetVT))
1870 return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001871
Eric Christopher836c6242010-12-15 23:47:29 +00001872 // TODO: For now if we have long calls specified we don't handle the call.
1873 if (EnableARMLongCalls) return false;
Eric Christopher299bbb22011-04-29 00:03:10 +00001874
Eric Christopherf9764fa2010-09-30 20:49:44 +00001875 // Set up the argument vectors.
1876 SmallVector<Value*, 8> Args;
1877 SmallVector<unsigned, 8> ArgRegs;
Duncan Sands1440e8b2010-11-03 11:35:31 +00001878 SmallVector<MVT, 8> ArgVTs;
Eric Christopherf9764fa2010-09-30 20:49:44 +00001879 SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
1880 Args.reserve(CS.arg_size());
1881 ArgRegs.reserve(CS.arg_size());
1882 ArgVTs.reserve(CS.arg_size());
1883 ArgFlags.reserve(CS.arg_size());
1884 for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
1885 i != e; ++i) {
1886 unsigned Arg = getRegForValue(*i);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001887
Eric Christopherf9764fa2010-09-30 20:49:44 +00001888 if (Arg == 0)
1889 return false;
1890 ISD::ArgFlagsTy Flags;
1891 unsigned AttrInd = i - CS.arg_begin() + 1;
1892 if (CS.paramHasAttr(AttrInd, Attribute::SExt))
1893 Flags.setSExt();
1894 if (CS.paramHasAttr(AttrInd, Attribute::ZExt))
1895 Flags.setZExt();
1896
1897 // FIXME: Only handle *easy* calls for now.
1898 if (CS.paramHasAttr(AttrInd, Attribute::InReg) ||
1899 CS.paramHasAttr(AttrInd, Attribute::StructRet) ||
1900 CS.paramHasAttr(AttrInd, Attribute::Nest) ||
1901 CS.paramHasAttr(AttrInd, Attribute::ByVal))
1902 return false;
1903
1904 const Type *ArgTy = (*i)->getType();
Duncan Sands1440e8b2010-11-03 11:35:31 +00001905 MVT ArgVT;
Eric Christopherf9764fa2010-09-30 20:49:44 +00001906 if (!isTypeLegal(ArgTy, ArgVT))
1907 return false;
1908 unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy);
1909 Flags.setOrigAlign(OriginalAlignment);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001910
Eric Christopherf9764fa2010-09-30 20:49:44 +00001911 Args.push_back(*i);
1912 ArgRegs.push_back(Arg);
1913 ArgVTs.push_back(ArgVT);
1914 ArgFlags.push_back(Flags);
1915 }
Eric Christopherdccd2c32010-10-11 08:38:55 +00001916
Eric Christopherf9764fa2010-09-30 20:49:44 +00001917 // Handle the arguments now that we've gotten them.
1918 SmallVector<unsigned, 4> RegArgs;
1919 unsigned NumBytes;
1920 if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes))
1921 return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001922
Eric Christopher6344a5f2011-04-29 00:07:20 +00001923 // Issue the call, BLr9 for darwin, BL otherwise.
Eric Christopherdccd2c32010-10-11 08:38:55 +00001924 // TODO: Turn this into the table of arm call ops.
Eric Christopherf9764fa2010-09-30 20:49:44 +00001925 MachineInstrBuilder MIB;
Eric Christopher872f4a22011-02-22 01:37:10 +00001926 unsigned CallOpc = ARMSelectCallOp(GV);
Eric Christopher7bb59962010-11-29 21:56:23 +00001927 // Explicitly adding the predicate here.
Eric Christopher872f4a22011-02-22 01:37:10 +00001928 if(isThumb)
Eric Christopherc19aadb2010-12-21 03:50:43 +00001929 // Explicitly adding the predicate here.
1930 MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1931 TII.get(CallOpc)))
1932 .addGlobalAddress(GV, 0, 0);
Eric Christopher872f4a22011-02-22 01:37:10 +00001933 else
Eric Christopherc19aadb2010-12-21 03:50:43 +00001934 // Explicitly adding the predicate here.
1935 MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
1936 TII.get(CallOpc))
1937 .addGlobalAddress(GV, 0, 0));
Eric Christopher299bbb22011-04-29 00:03:10 +00001938
Eric Christopherf9764fa2010-09-30 20:49:44 +00001939 // Add implicit physical register uses to the call.
1940 for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
1941 MIB.addReg(RegArgs[i]);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001942
Eric Christopherf9764fa2010-09-30 20:49:44 +00001943 // Finish off the call including any return values.
Eric Christopherdccd2c32010-10-11 08:38:55 +00001944 SmallVector<unsigned, 4> UsedRegs;
Eric Christopherf9764fa2010-09-30 20:49:44 +00001945 if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001946
Eric Christopherf9764fa2010-09-30 20:49:44 +00001947 // Set all unused physreg defs as dead.
1948 static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
Eric Christopherdccd2c32010-10-11 08:38:55 +00001949
Eric Christopherf9764fa2010-09-30 20:49:44 +00001950 return true;
Eric Christopherdccd2c32010-10-11 08:38:55 +00001951
Eric Christopherf9764fa2010-09-30 20:49:44 +00001952}
1953
Eli Friedman76927d732011-05-25 23:49:02 +00001954bool ARMFastISel::SelectIntCast(const Instruction *I) {
1955 // On ARM, in general, integer casts don't involve legal types; this code
1956 // handles promotable integers. The high bits for a type smaller than
1957 // the register size are assumed to be undefined.
1958 const Type *DestTy = I->getType();
1959 Value *Op = I->getOperand(0);
1960 const Type *SrcTy = Op->getType();
1961
1962 EVT SrcVT, DestVT;
1963 SrcVT = TLI.getValueType(SrcTy, true);
1964 DestVT = TLI.getValueType(DestTy, true);
1965
1966 if (isa<TruncInst>(I)) {
1967 if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8)
1968 return false;
1969 if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1)
1970 return false;
1971
1972 unsigned SrcReg = getRegForValue(Op);
1973 if (!SrcReg) return false;
1974
1975 // Because the high bits are undefined, a truncate doesn't generate
1976 // any code.
1977 UpdateValueMap(I, SrcReg);
1978 return true;
1979 }
1980 if (DestVT != MVT::i32 && DestVT != MVT::i16 && DestVT != MVT::i8)
1981 return false;
1982
1983 unsigned Opc;
1984 bool isZext = isa<ZExtInst>(I);
1985 bool isBoolZext = false;
Eli Friedmana4d487f2011-05-27 18:02:04 +00001986 if (!SrcVT.isSimple())
1987 return false;
Eli Friedman76927d732011-05-25 23:49:02 +00001988 switch (SrcVT.getSimpleVT().SimpleTy) {
1989 default: return false;
1990 case MVT::i16:
1991 if (isZext)
1992 Opc = isThumb ? ARM::t2UXTHr : ARM::UXTHr;
1993 else
1994 Opc = isThumb ? ARM::t2SXTHr : ARM::SXTHr;
1995 break;
1996 case MVT::i8:
1997 if (isZext)
1998 Opc = isThumb ? ARM::t2UXTBr : ARM::UXTBr;
1999 else
2000 Opc = isThumb ? ARM::t2SXTBr : ARM::SXTBr;
2001 break;
2002 case MVT::i1:
2003 if (isZext) {
2004 Opc = isThumb ? ARM::t2ANDri : ARM::ANDri;
2005 isBoolZext = true;
2006 break;
2007 }
2008 return false;
2009 }
2010
2011 // FIXME: We could save an instruction in many cases by special-casing
2012 // load instructions.
2013 unsigned SrcReg = getRegForValue(Op);
2014 if (!SrcReg) return false;
2015
2016 unsigned DestReg = createResultReg(TLI.getRegClassFor(MVT::i32));
2017 MachineInstrBuilder MIB;
2018 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg)
2019 .addReg(SrcReg);
2020 if (isBoolZext)
2021 MIB.addImm(1);
2022 AddOptionalDefs(MIB);
2023 UpdateValueMap(I, DestReg);
2024 return true;
2025}
2026
Eric Christopher56d2b722010-09-02 23:43:26 +00002027// TODO: SoftFP support.
Eric Christopherab695882010-07-21 22:26:11 +00002028bool ARMFastISel::TargetSelectInstruction(const Instruction *I) {
Eric Christopherac1a19e2010-09-09 01:06:51 +00002029
Eric Christopherab695882010-07-21 22:26:11 +00002030 switch (I->getOpcode()) {
Eric Christopher83007122010-08-23 21:44:12 +00002031 case Instruction::Load:
Eric Christopher43b62be2010-09-27 06:02:23 +00002032 return SelectLoad(I);
Eric Christopher543cf052010-09-01 22:16:27 +00002033 case Instruction::Store:
Eric Christopher43b62be2010-09-27 06:02:23 +00002034 return SelectStore(I);
Eric Christophere5734102010-09-03 00:35:47 +00002035 case Instruction::Br:
Eric Christopher43b62be2010-09-27 06:02:23 +00002036 return SelectBranch(I);
Eric Christopherd43393a2010-09-08 23:13:45 +00002037 case Instruction::ICmp:
2038 case Instruction::FCmp:
Eric Christopher43b62be2010-09-27 06:02:23 +00002039 return SelectCmp(I);
Eric Christopher46203602010-09-09 00:26:48 +00002040 case Instruction::FPExt:
Eric Christopher43b62be2010-09-27 06:02:23 +00002041 return SelectFPExt(I);
Eric Christopherce07b542010-09-09 20:26:31 +00002042 case Instruction::FPTrunc:
Eric Christopher43b62be2010-09-27 06:02:23 +00002043 return SelectFPTrunc(I);
Eric Christopher9a040492010-09-09 18:54:59 +00002044 case Instruction::SIToFP:
Eric Christopher43b62be2010-09-27 06:02:23 +00002045 return SelectSIToFP(I);
Eric Christopher9a040492010-09-09 18:54:59 +00002046 case Instruction::FPToSI:
Eric Christopher43b62be2010-09-27 06:02:23 +00002047 return SelectFPToSI(I);
Eric Christopherbc39b822010-09-09 00:53:57 +00002048 case Instruction::FAdd:
Eric Christopher43b62be2010-09-27 06:02:23 +00002049 return SelectBinaryOp(I, ISD::FADD);
Eric Christopherbc39b822010-09-09 00:53:57 +00002050 case Instruction::FSub:
Eric Christopher43b62be2010-09-27 06:02:23 +00002051 return SelectBinaryOp(I, ISD::FSUB);
Eric Christopherbc39b822010-09-09 00:53:57 +00002052 case Instruction::FMul:
Eric Christopher43b62be2010-09-27 06:02:23 +00002053 return SelectBinaryOp(I, ISD::FMUL);
Eric Christopherbb3e5da2010-09-14 23:03:37 +00002054 case Instruction::SDiv:
Eric Christopher43b62be2010-09-27 06:02:23 +00002055 return SelectSDiv(I);
Eric Christopher6a880d62010-10-11 08:37:26 +00002056 case Instruction::SRem:
2057 return SelectSRem(I);
Eric Christopherf9764fa2010-09-30 20:49:44 +00002058 case Instruction::Call:
2059 return SelectCall(I);
Eric Christopher3bbd3962010-10-11 08:27:59 +00002060 case Instruction::Select:
2061 return SelectSelect(I);
Eric Christopher4f512ef2010-10-22 01:28:00 +00002062 case Instruction::Ret:
2063 return SelectRet(I);
Eli Friedman76927d732011-05-25 23:49:02 +00002064 case Instruction::Trunc:
2065 case Instruction::ZExt:
2066 case Instruction::SExt:
2067 return SelectIntCast(I);
Eric Christopherab695882010-07-21 22:26:11 +00002068 default: break;
2069 }
2070 return false;
2071}
2072
2073namespace llvm {
2074 llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) {
Eric Christopherfeadddd2010-10-11 20:05:22 +00002075 // Completely untested on non-darwin.
2076 const TargetMachine &TM = funcInfo.MF->getTarget();
Jim Grosbach16cb3762010-11-09 19:22:26 +00002077
Eric Christopheraaa8df42010-11-02 01:21:28 +00002078 // Darwin and thumb1 only for now.
Eric Christopherfeadddd2010-10-11 20:05:22 +00002079 const ARMSubtarget *Subtarget = &TM.getSubtarget<ARMSubtarget>();
Jim Grosbach16cb3762010-11-09 19:22:26 +00002080 if (Subtarget->isTargetDarwin() && !Subtarget->isThumb1Only() &&
Eric Christopheraaa8df42010-11-02 01:21:28 +00002081 !DisableARMFastISel)
Eric Christopherfeadddd2010-10-11 20:05:22 +00002082 return new ARMFastISel(funcInfo);
Evan Cheng09447952010-07-26 18:32:55 +00002083 return 0;
Eric Christopherab695882010-07-21 22:26:11 +00002084 }
2085}