1 //===-- ARMFastISel.cpp - ARM FastISel implementation ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
17 #include "ARMBaseRegisterInfo.h"
18 #include "ARMCallingConv.h"
19 #include "ARMConstantPoolValue.h"
20 #include "ARMISelLowering.h"
21 #include "ARMMachineFunctionInfo.h"
22 #include "ARMSubtarget.h"
23 #include "MCTargetDesc/ARMAddressingModes.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/CodeGen/Analysis.h"
26 #include "llvm/CodeGen/FastISel.h"
27 #include "llvm/CodeGen/FunctionLoweringInfo.h"
28 #include "llvm/CodeGen/MachineConstantPool.h"
29 #include "llvm/CodeGen/MachineFrameInfo.h"
30 #include "llvm/CodeGen/MachineInstrBuilder.h"
31 #include "llvm/CodeGen/MachineMemOperand.h"
32 #include "llvm/CodeGen/MachineModuleInfo.h"
33 #include "llvm/CodeGen/MachineRegisterInfo.h"
34 #include "llvm/IR/CallSite.h"
35 #include "llvm/IR/CallingConv.h"
36 #include "llvm/IR/DataLayout.h"
37 #include "llvm/IR/DerivedTypes.h"
38 #include "llvm/IR/GetElementPtrTypeIterator.h"
39 #include "llvm/IR/GlobalVariable.h"
40 #include "llvm/IR/Instructions.h"
41 #include "llvm/IR/IntrinsicInst.h"
42 #include "llvm/IR/Module.h"
43 #include "llvm/IR/Operator.h"
44 #include "llvm/Support/CommandLine.h"
45 #include "llvm/Support/ErrorHandling.h"
46 #include "llvm/Target/TargetInstrInfo.h"
47 #include "llvm/Target/TargetLowering.h"
48 #include "llvm/Target/TargetMachine.h"
49 #include "llvm/Target/TargetOptions.h"
54 // All possible address modes, plus some.
55 typedef struct Address {
68 // Innocuous defaults for our address.
70 : BaseType(RegBase), Offset(0) {
75 class ARMFastISel final : public FastISel {
77 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
78 /// make the right decision when generating code for different targets.
79 const ARMSubtarget *Subtarget;
81 const TargetMachine &TM;
82 const TargetInstrInfo &TII;
83 const TargetLowering &TLI;
86 // Convenience variables to avoid some queries.
91 explicit ARMFastISel(FunctionLoweringInfo &funcInfo,
92 const TargetLibraryInfo *libInfo)
93 : FastISel(funcInfo, libInfo),
95 &static_cast<const ARMSubtarget &>(funcInfo.MF->getSubtarget())),
96 M(const_cast<Module &>(*funcInfo.Fn->getParent())),
97 TM(funcInfo.MF->getTarget()), TII(*Subtarget->getInstrInfo()),
98 TLI(*Subtarget->getTargetLowering()) {
99 AFI = funcInfo.MF->getInfo<ARMFunctionInfo>();
100 isThumb2 = AFI->isThumbFunction();
101 Context = &funcInfo.Fn->getContext();
104 // Code from FastISel.cpp.
106 unsigned fastEmitInst_r(unsigned MachineInstOpcode,
107 const TargetRegisterClass *RC,
108 unsigned Op0, bool Op0IsKill);
109 unsigned fastEmitInst_rr(unsigned MachineInstOpcode,
110 const TargetRegisterClass *RC,
111 unsigned Op0, bool Op0IsKill,
112 unsigned Op1, bool Op1IsKill);
113 unsigned fastEmitInst_rrr(unsigned MachineInstOpcode,
114 const TargetRegisterClass *RC,
115 unsigned Op0, bool Op0IsKill,
116 unsigned Op1, bool Op1IsKill,
117 unsigned Op2, bool Op2IsKill);
118 unsigned fastEmitInst_ri(unsigned MachineInstOpcode,
119 const TargetRegisterClass *RC,
120 unsigned Op0, bool Op0IsKill,
122 unsigned fastEmitInst_rri(unsigned MachineInstOpcode,
123 const TargetRegisterClass *RC,
124 unsigned Op0, bool Op0IsKill,
125 unsigned Op1, bool Op1IsKill,
127 unsigned fastEmitInst_i(unsigned MachineInstOpcode,
128 const TargetRegisterClass *RC,
131 // Backend specific FastISel code.
133 bool fastSelectInstruction(const Instruction *I) override;
134 unsigned fastMaterializeConstant(const Constant *C) override;
135 unsigned fastMaterializeAlloca(const AllocaInst *AI) override;
136 bool tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo,
137 const LoadInst *LI) override;
138 bool fastLowerArguments() override;
140 #include "ARMGenFastISel.inc"
142 // Instruction selection routines.
144 bool SelectLoad(const Instruction *I);
145 bool SelectStore(const Instruction *I);
146 bool SelectBranch(const Instruction *I);
147 bool SelectIndirectBr(const Instruction *I);
148 bool SelectCmp(const Instruction *I);
149 bool SelectFPExt(const Instruction *I);
150 bool SelectFPTrunc(const Instruction *I);
151 bool SelectBinaryIntOp(const Instruction *I, unsigned ISDOpcode);
152 bool SelectBinaryFPOp(const Instruction *I, unsigned ISDOpcode);
153 bool SelectIToFP(const Instruction *I, bool isSigned);
154 bool SelectFPToI(const Instruction *I, bool isSigned);
155 bool SelectDiv(const Instruction *I, bool isSigned);
156 bool SelectRem(const Instruction *I, bool isSigned);
157 bool SelectCall(const Instruction *I, const char *IntrMemName);
158 bool SelectIntrinsicCall(const IntrinsicInst &I);
159 bool SelectSelect(const Instruction *I);
160 bool SelectRet(const Instruction *I);
161 bool SelectTrunc(const Instruction *I);
162 bool SelectIntExt(const Instruction *I);
163 bool SelectShift(const Instruction *I, ARM_AM::ShiftOpc ShiftTy);
167 bool isTypeLegal(Type *Ty, MVT &VT);
168 bool isLoadTypeLegal(Type *Ty, MVT &VT);
169 bool ARMEmitCmp(const Value *Src1Value, const Value *Src2Value,
171 bool ARMEmitLoad(MVT VT, unsigned &ResultReg, Address &Addr,
172 unsigned Alignment = 0, bool isZExt = true,
173 bool allocReg = true);
174 bool ARMEmitStore(MVT VT, unsigned SrcReg, Address &Addr,
175 unsigned Alignment = 0);
176 bool ARMComputeAddress(const Value *Obj, Address &Addr);
177 void ARMSimplifyAddress(Address &Addr, MVT VT, bool useAM3);
178 bool ARMIsMemCpySmall(uint64_t Len);
179 bool ARMTryEmitSmallMemCpy(Address Dest, Address Src, uint64_t Len,
181 unsigned ARMEmitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, bool isZExt);
182 unsigned ARMMaterializeFP(const ConstantFP *CFP, MVT VT);
183 unsigned ARMMaterializeInt(const Constant *C, MVT VT);
184 unsigned ARMMaterializeGV(const GlobalValue *GV, MVT VT);
185 unsigned ARMMoveToFPReg(MVT VT, unsigned SrcReg);
186 unsigned ARMMoveToIntReg(MVT VT, unsigned SrcReg);
187 unsigned ARMSelectCallOp(bool UseReg);
188 unsigned ARMLowerPICELF(const GlobalValue *GV, unsigned Align, MVT VT);
190 const TargetLowering *getTargetLowering() { return &TLI; }
192 // Call handling routines.
194 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC,
197 bool ProcessCallArgs(SmallVectorImpl<Value*> &Args,
198 SmallVectorImpl<unsigned> &ArgRegs,
199 SmallVectorImpl<MVT> &ArgVTs,
200 SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
201 SmallVectorImpl<unsigned> &RegArgs,
205 unsigned getLibcallReg(const Twine &Name);
206 bool FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
207 const Instruction *I, CallingConv::ID CC,
208 unsigned &NumBytes, bool isVarArg);
209 bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call);
211 // OptionalDef handling routines.
213 bool isARMNEONPred(const MachineInstr *MI);
214 bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR);
215 const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB);
216 void AddLoadStoreOperands(MVT VT, Address &Addr,
217 const MachineInstrBuilder &MIB,
218 unsigned Flags, bool useAM3);
221 } // end anonymous namespace
223 #include "ARMGenCallingConv.inc"
225 // DefinesOptionalPredicate - This is different from DefinesPredicate in that
226 // we don't care about implicit defs here, just places we'll need to add a
227 // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR.
228 bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) {
229 if (!MI->hasOptionalDef())
232 // Look to see if our OptionalDef is defining CPSR or CCR.
233 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
234 const MachineOperand &MO = MI->getOperand(i);
235 if (!MO.isReg() || !MO.isDef()) continue;
236 if (MO.getReg() == ARM::CPSR)
242 bool ARMFastISel::isARMNEONPred(const MachineInstr *MI) {
243 const MCInstrDesc &MCID = MI->getDesc();
245 // If we're a thumb2 or not NEON function we'll be handled via isPredicable.
246 if ((MCID.TSFlags & ARMII::DomainMask) != ARMII::DomainNEON ||
247 AFI->isThumb2Function())
248 return MI->isPredicable();
250 for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i)
251 if (MCID.OpInfo[i].isPredicate())
257 // If the machine is predicable go ahead and add the predicate operands, if
258 // it needs default CC operands add those.
259 // TODO: If we want to support thumb1 then we'll need to deal with optional
260 // CPSR defs that need to be added before the remaining operands. See s_cc_out
261 // for descriptions why.
262 const MachineInstrBuilder &
263 ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) {
264 MachineInstr *MI = &*MIB;
266 // Do we use a predicate? or...
267 // Are we NEON in ARM mode and have a predicate operand? If so, I know
268 // we're not predicable but add it anyways.
269 if (isARMNEONPred(MI))
272 // Do we optionally set a predicate? Preds is size > 0 iff the predicate
273 // defines CPSR. All other OptionalDefines in ARM are the CCR register.
275 if (DefinesOptionalPredicate(MI, &CPSR)) {
284 unsigned ARMFastISel::fastEmitInst_r(unsigned MachineInstOpcode,
285 const TargetRegisterClass *RC,
286 unsigned Op0, bool Op0IsKill) {
287 unsigned ResultReg = createResultReg(RC);
288 const MCInstrDesc &II = TII.get(MachineInstOpcode);
290 // Make sure the input operand is sufficiently constrained to be legal
291 // for this instruction.
292 Op0 = constrainOperandRegClass(II, Op0, 1);
293 if (II.getNumDefs() >= 1) {
294 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II,
295 ResultReg).addReg(Op0, Op0IsKill * RegState::Kill));
297 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
298 .addReg(Op0, Op0IsKill * RegState::Kill));
299 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
300 TII.get(TargetOpcode::COPY), ResultReg)
301 .addReg(II.ImplicitDefs[0]));
306 unsigned 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 MCInstrDesc &II = TII.get(MachineInstOpcode);
313 // Make sure the input operands are sufficiently constrained to be legal
314 // for this instruction.
315 Op0 = constrainOperandRegClass(II, Op0, 1);
316 Op1 = constrainOperandRegClass(II, Op1, 2);
318 if (II.getNumDefs() >= 1) {
320 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
321 .addReg(Op0, Op0IsKill * RegState::Kill)
322 .addReg(Op1, Op1IsKill * RegState::Kill));
324 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
325 .addReg(Op0, Op0IsKill * RegState::Kill)
326 .addReg(Op1, Op1IsKill * RegState::Kill));
327 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
328 TII.get(TargetOpcode::COPY), ResultReg)
329 .addReg(II.ImplicitDefs[0]));
334 unsigned ARMFastISel::fastEmitInst_rrr(unsigned MachineInstOpcode,
335 const TargetRegisterClass *RC,
336 unsigned Op0, bool Op0IsKill,
337 unsigned Op1, bool Op1IsKill,
338 unsigned Op2, bool Op2IsKill) {
339 unsigned ResultReg = createResultReg(RC);
340 const MCInstrDesc &II = TII.get(MachineInstOpcode);
342 // Make sure the input operands are sufficiently constrained to be legal
343 // for this instruction.
344 Op0 = constrainOperandRegClass(II, Op0, 1);
345 Op1 = constrainOperandRegClass(II, Op1, 2);
346 Op2 = constrainOperandRegClass(II, Op1, 3);
348 if (II.getNumDefs() >= 1) {
350 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
351 .addReg(Op0, Op0IsKill * RegState::Kill)
352 .addReg(Op1, Op1IsKill * RegState::Kill)
353 .addReg(Op2, Op2IsKill * RegState::Kill));
355 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
356 .addReg(Op0, Op0IsKill * RegState::Kill)
357 .addReg(Op1, Op1IsKill * RegState::Kill)
358 .addReg(Op2, Op2IsKill * RegState::Kill));
359 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
360 TII.get(TargetOpcode::COPY), ResultReg)
361 .addReg(II.ImplicitDefs[0]));
366 unsigned ARMFastISel::fastEmitInst_ri(unsigned MachineInstOpcode,
367 const TargetRegisterClass *RC,
368 unsigned Op0, bool Op0IsKill,
370 unsigned ResultReg = createResultReg(RC);
371 const MCInstrDesc &II = TII.get(MachineInstOpcode);
373 // Make sure the input operand is sufficiently constrained to be legal
374 // for this instruction.
375 Op0 = constrainOperandRegClass(II, Op0, 1);
376 if (II.getNumDefs() >= 1) {
378 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
379 .addReg(Op0, Op0IsKill * RegState::Kill)
382 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
383 .addReg(Op0, Op0IsKill * RegState::Kill)
385 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
386 TII.get(TargetOpcode::COPY), ResultReg)
387 .addReg(II.ImplicitDefs[0]));
392 unsigned ARMFastISel::fastEmitInst_rri(unsigned MachineInstOpcode,
393 const TargetRegisterClass *RC,
394 unsigned Op0, bool Op0IsKill,
395 unsigned Op1, bool Op1IsKill,
397 unsigned ResultReg = createResultReg(RC);
398 const MCInstrDesc &II = TII.get(MachineInstOpcode);
400 // Make sure the input operands are sufficiently constrained to be legal
401 // for this instruction.
402 Op0 = constrainOperandRegClass(II, Op0, 1);
403 Op1 = constrainOperandRegClass(II, Op1, 2);
404 if (II.getNumDefs() >= 1) {
406 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
407 .addReg(Op0, Op0IsKill * RegState::Kill)
408 .addReg(Op1, Op1IsKill * RegState::Kill)
411 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
412 .addReg(Op0, Op0IsKill * RegState::Kill)
413 .addReg(Op1, Op1IsKill * RegState::Kill)
415 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
416 TII.get(TargetOpcode::COPY), ResultReg)
417 .addReg(II.ImplicitDefs[0]));
422 unsigned ARMFastISel::fastEmitInst_i(unsigned MachineInstOpcode,
423 const TargetRegisterClass *RC,
425 unsigned ResultReg = createResultReg(RC);
426 const MCInstrDesc &II = TII.get(MachineInstOpcode);
428 if (II.getNumDefs() >= 1) {
429 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II,
430 ResultReg).addImm(Imm));
432 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
434 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
435 TII.get(TargetOpcode::COPY), ResultReg)
436 .addReg(II.ImplicitDefs[0]));
441 // TODO: Don't worry about 64-bit now, but when this is fixed remove the
442 // checks from the various callers.
443 unsigned ARMFastISel::ARMMoveToFPReg(MVT VT, unsigned SrcReg) {
444 if (VT == MVT::f64) return 0;
446 unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
447 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
448 TII.get(ARM::VMOVSR), MoveReg)
453 unsigned ARMFastISel::ARMMoveToIntReg(MVT VT, unsigned SrcReg) {
454 if (VT == MVT::i64) return 0;
456 unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
457 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
458 TII.get(ARM::VMOVRS), MoveReg)
463 // For double width floating point we need to materialize two constants
464 // (the high and the low) into integer registers then use a move to get
465 // the combined constant into an FP reg.
466 unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, MVT VT) {
467 const APFloat Val = CFP->getValueAPF();
468 bool is64bit = VT == MVT::f64;
470 // This checks to see if we can use VFP3 instructions to materialize
471 // a constant, otherwise we have to go through the constant pool.
472 if (TLI.isFPImmLegal(Val, VT)) {
476 Imm = ARM_AM::getFP64Imm(Val);
479 Imm = ARM_AM::getFP32Imm(Val);
482 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
483 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
484 TII.get(Opc), DestReg).addImm(Imm));
488 // Require VFP2 for loading fp constants.
489 if (!Subtarget->hasVFP2()) return false;
491 // MachineConstantPool wants an explicit alignment.
492 unsigned Align = DL.getPrefTypeAlignment(CFP->getType());
494 // TODO: Figure out if this is correct.
495 Align = DL.getTypeAllocSize(CFP->getType());
497 unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align);
498 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
499 unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS;
501 // The extra reg is for addrmode5.
503 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), DestReg)
504 .addConstantPoolIndex(Idx)
509 unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, MVT VT) {
511 if (VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8 && VT != MVT::i1)
514 // If we can do this in a single instruction without a constant pool entry
516 const ConstantInt *CI = cast<ConstantInt>(C);
517 if (Subtarget->hasV6T2Ops() && isUInt<16>(CI->getZExtValue())) {
518 unsigned Opc = isThumb2 ? ARM::t2MOVi16 : ARM::MOVi16;
519 const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass :
521 unsigned ImmReg = createResultReg(RC);
522 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
523 TII.get(Opc), ImmReg)
524 .addImm(CI->getZExtValue()));
528 // Use MVN to emit negative constants.
529 if (VT == MVT::i32 && Subtarget->hasV6T2Ops() && CI->isNegative()) {
530 unsigned Imm = (unsigned)~(CI->getSExtValue());
531 bool UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) :
532 (ARM_AM::getSOImmVal(Imm) != -1);
534 unsigned Opc = isThumb2 ? ARM::t2MVNi : ARM::MVNi;
535 const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass :
537 unsigned ImmReg = createResultReg(RC);
538 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
539 TII.get(Opc), ImmReg)
545 unsigned ResultReg = 0;
546 if (Subtarget->useMovt(*FuncInfo.MF))
547 ResultReg = fastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
552 // Load from constant pool. For now 32-bit only.
556 // MachineConstantPool wants an explicit alignment.
557 unsigned Align = DL.getPrefTypeAlignment(C->getType());
559 // TODO: Figure out if this is correct.
560 Align = DL.getTypeAllocSize(C->getType());
562 unsigned Idx = MCP.getConstantPoolIndex(C, Align);
563 ResultReg = createResultReg(TLI.getRegClassFor(VT));
565 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
566 TII.get(ARM::t2LDRpci), ResultReg)
567 .addConstantPoolIndex(Idx));
569 // The extra immediate is for addrmode2.
570 ResultReg = constrainOperandRegClass(TII.get(ARM::LDRcp), ResultReg, 0);
571 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
572 TII.get(ARM::LDRcp), ResultReg)
573 .addConstantPoolIndex(Idx)
579 unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, MVT VT) {
580 // For now 32-bit only.
581 if (VT != MVT::i32 || GV->isThreadLocal()) return 0;
583 Reloc::Model RelocM = TM.getRelocationModel();
584 bool IsIndirect = Subtarget->GVIsIndirectSymbol(GV, RelocM);
585 const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass
587 unsigned DestReg = createResultReg(RC);
589 // FastISel TLS support on non-MachO is broken, punt to SelectionDAG.
590 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
591 bool IsThreadLocal = GVar && GVar->isThreadLocal();
592 if (!Subtarget->isTargetMachO() && IsThreadLocal) return 0;
594 // Use movw+movt when possible, it avoids constant pool entries.
595 // Non-darwin targets only support static movt relocations in FastISel.
596 if (Subtarget->useMovt(*FuncInfo.MF) &&
597 (Subtarget->isTargetMachO() || RelocM == Reloc::Static)) {
599 unsigned char TF = 0;
600 if (Subtarget->isTargetMachO())
601 TF = ARMII::MO_NONLAZY;
605 Opc = isThumb2 ? ARM::t2MOV_ga_pcrel : ARM::MOV_ga_pcrel;
608 Opc = isThumb2 ? ARM::t2MOVi32imm : ARM::MOVi32imm;
611 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
612 TII.get(Opc), DestReg).addGlobalAddress(GV, 0, TF));
614 // MachineConstantPool wants an explicit alignment.
615 unsigned Align = DL.getPrefTypeAlignment(GV->getType());
617 // TODO: Figure out if this is correct.
618 Align = DL.getTypeAllocSize(GV->getType());
621 if (Subtarget->isTargetELF() && RelocM == Reloc::PIC_)
622 return ARMLowerPICELF(GV, Align, VT);
625 unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 :
626 (Subtarget->isThumb() ? 4 : 8);
627 unsigned Id = AFI->createPICLabelUId();
628 ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create(GV, Id,
631 unsigned Idx = MCP.getConstantPoolIndex(CPV, Align);
634 MachineInstrBuilder MIB;
636 unsigned Opc = (RelocM!=Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic;
637 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc),
638 DestReg).addConstantPoolIndex(Idx);
639 if (RelocM == Reloc::PIC_)
641 AddOptionalDefs(MIB);
643 // The extra immediate is for addrmode2.
644 DestReg = constrainOperandRegClass(TII.get(ARM::LDRcp), DestReg, 0);
645 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
646 TII.get(ARM::LDRcp), DestReg)
647 .addConstantPoolIndex(Idx)
649 AddOptionalDefs(MIB);
651 if (RelocM == Reloc::PIC_) {
652 unsigned Opc = IsIndirect ? ARM::PICLDR : ARM::PICADD;
653 unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT));
655 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
656 DbgLoc, TII.get(Opc), NewDestReg)
659 AddOptionalDefs(MIB);
666 MachineInstrBuilder MIB;
667 unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT));
669 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
670 TII.get(ARM::t2LDRi12), NewDestReg)
674 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
675 TII.get(ARM::LDRi12), NewDestReg)
678 DestReg = NewDestReg;
679 AddOptionalDefs(MIB);
685 unsigned ARMFastISel::fastMaterializeConstant(const Constant *C) {
686 EVT CEVT = TLI.getValueType(DL, C->getType(), true);
688 // Only handle simple types.
689 if (!CEVT.isSimple()) return 0;
690 MVT VT = CEVT.getSimpleVT();
692 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
693 return ARMMaterializeFP(CFP, VT);
694 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
695 return ARMMaterializeGV(GV, VT);
696 else if (isa<ConstantInt>(C))
697 return ARMMaterializeInt(C, VT);
702 // TODO: unsigned ARMFastISel::TargetMaterializeFloatZero(const ConstantFP *CF);
704 unsigned ARMFastISel::fastMaterializeAlloca(const AllocaInst *AI) {
705 // Don't handle dynamic allocas.
706 if (!FuncInfo.StaticAllocaMap.count(AI)) return 0;
709 if (!isLoadTypeLegal(AI->getType(), VT)) return 0;
711 DenseMap<const AllocaInst*, int>::iterator SI =
712 FuncInfo.StaticAllocaMap.find(AI);
714 // This will get lowered later into the correct offsets and registers
715 // via rewriteXFrameIndex.
716 if (SI != FuncInfo.StaticAllocaMap.end()) {
717 unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri;
718 const TargetRegisterClass* RC = TLI.getRegClassFor(VT);
719 unsigned ResultReg = createResultReg(RC);
720 ResultReg = constrainOperandRegClass(TII.get(Opc), ResultReg, 0);
722 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
723 TII.get(Opc), ResultReg)
724 .addFrameIndex(SI->second)
732 bool ARMFastISel::isTypeLegal(Type *Ty, MVT &VT) {
733 EVT evt = TLI.getValueType(DL, Ty, true);
735 // Only handle simple types.
736 if (evt == MVT::Other || !evt.isSimple()) return false;
737 VT = evt.getSimpleVT();
739 // Handle all legal types, i.e. a register that will directly hold this
741 return TLI.isTypeLegal(VT);
744 bool ARMFastISel::isLoadTypeLegal(Type *Ty, MVT &VT) {
745 if (isTypeLegal(Ty, VT)) return true;
747 // If this is a type than can be sign or zero-extended to a basic operation
748 // go ahead and accept it now.
749 if (VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16)
755 // Computes the address to get to an object.
756 bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) {
757 // Some boilerplate from the X86 FastISel.
758 const User *U = nullptr;
759 unsigned Opcode = Instruction::UserOp1;
760 if (const Instruction *I = dyn_cast<Instruction>(Obj)) {
761 // Don't walk into other basic blocks unless the object is an alloca from
762 // another block, otherwise it may not have a virtual register assigned.
763 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
764 FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) {
765 Opcode = I->getOpcode();
768 } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
769 Opcode = C->getOpcode();
773 if (PointerType *Ty = dyn_cast<PointerType>(Obj->getType()))
774 if (Ty->getAddressSpace() > 255)
775 // Fast instruction selection doesn't support the special
782 case Instruction::BitCast:
783 // Look through bitcasts.
784 return ARMComputeAddress(U->getOperand(0), Addr);
785 case Instruction::IntToPtr:
786 // Look past no-op inttoptrs.
787 if (TLI.getValueType(DL, U->getOperand(0)->getType()) ==
788 TLI.getPointerTy(DL))
789 return ARMComputeAddress(U->getOperand(0), Addr);
791 case Instruction::PtrToInt:
792 // Look past no-op ptrtoints.
793 if (TLI.getValueType(DL, U->getType()) == TLI.getPointerTy(DL))
794 return ARMComputeAddress(U->getOperand(0), Addr);
796 case Instruction::GetElementPtr: {
797 Address SavedAddr = Addr;
798 int TmpOffset = Addr.Offset;
800 // Iterate through the GEP folding the constants into offsets where
802 gep_type_iterator GTI = gep_type_begin(U);
803 for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end();
804 i != e; ++i, ++GTI) {
805 const Value *Op = *i;
806 if (StructType *STy = dyn_cast<StructType>(*GTI)) {
807 const StructLayout *SL = DL.getStructLayout(STy);
808 unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
809 TmpOffset += SL->getElementOffset(Idx);
811 uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
813 if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
814 // Constant-offset addressing.
815 TmpOffset += CI->getSExtValue() * S;
818 if (canFoldAddIntoGEP(U, Op)) {
819 // A compatible add with a constant operand. Fold the constant.
821 cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1));
822 TmpOffset += CI->getSExtValue() * S;
823 // Iterate on the other operand.
824 Op = cast<AddOperator>(Op)->getOperand(0);
828 goto unsupported_gep;
833 // Try to grab the base operand now.
834 Addr.Offset = TmpOffset;
835 if (ARMComputeAddress(U->getOperand(0), Addr)) return true;
837 // We failed, restore everything and try the other options.
843 case Instruction::Alloca: {
844 const AllocaInst *AI = cast<AllocaInst>(Obj);
845 DenseMap<const AllocaInst*, int>::iterator SI =
846 FuncInfo.StaticAllocaMap.find(AI);
847 if (SI != FuncInfo.StaticAllocaMap.end()) {
848 Addr.BaseType = Address::FrameIndexBase;
849 Addr.Base.FI = SI->second;
856 // Try to get this in a register if nothing else has worked.
857 if (Addr.Base.Reg == 0) Addr.Base.Reg = getRegForValue(Obj);
858 return Addr.Base.Reg != 0;
861 void ARMFastISel::ARMSimplifyAddress(Address &Addr, MVT VT, bool useAM3) {
862 bool needsLowering = false;
863 switch (VT.SimpleTy) {
864 default: llvm_unreachable("Unhandled load/store type!");
870 // Integer loads/stores handle 12-bit offsets.
871 needsLowering = ((Addr.Offset & 0xfff) != Addr.Offset);
872 // Handle negative offsets.
873 if (needsLowering && isThumb2)
874 needsLowering = !(Subtarget->hasV6T2Ops() && Addr.Offset < 0 &&
877 // ARM halfword load/stores and signed byte loads use +/-imm8 offsets.
878 needsLowering = (Addr.Offset > 255 || Addr.Offset < -255);
883 // Floating point operands handle 8-bit offsets.
884 needsLowering = ((Addr.Offset & 0xff) != Addr.Offset);
888 // If this is a stack pointer and the offset needs to be simplified then
889 // put the alloca address into a register, set the base type back to
890 // register and continue. This should almost never happen.
891 if (needsLowering && Addr.BaseType == Address::FrameIndexBase) {
892 const TargetRegisterClass *RC = isThumb2 ? &ARM::tGPRRegClass
894 unsigned ResultReg = createResultReg(RC);
895 unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri;
896 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
897 TII.get(Opc), ResultReg)
898 .addFrameIndex(Addr.Base.FI)
900 Addr.Base.Reg = ResultReg;
901 Addr.BaseType = Address::RegBase;
904 // Since the offset is too large for the load/store instruction
905 // get the reg+offset into a register.
907 Addr.Base.Reg = fastEmit_ri_(MVT::i32, ISD::ADD, Addr.Base.Reg,
908 /*Op0IsKill*/false, Addr.Offset, MVT::i32);
913 void ARMFastISel::AddLoadStoreOperands(MVT VT, Address &Addr,
914 const MachineInstrBuilder &MIB,
915 unsigned Flags, bool useAM3) {
916 // addrmode5 output depends on the selection dag addressing dividing the
917 // offset by 4 that it then later multiplies. Do this here as well.
918 if (VT.SimpleTy == MVT::f32 || VT.SimpleTy == MVT::f64)
921 // Frame base works a bit differently. Handle it separately.
922 if (Addr.BaseType == Address::FrameIndexBase) {
923 int FI = Addr.Base.FI;
924 int Offset = Addr.Offset;
925 MachineMemOperand *MMO = FuncInfo.MF->getMachineMemOperand(
926 MachinePointerInfo::getFixedStack(*FuncInfo.MF, FI, Offset), Flags,
927 MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
928 // Now add the rest of the operands.
929 MIB.addFrameIndex(FI);
931 // ARM halfword load/stores and signed byte loads need an additional
934 signed Imm = (Addr.Offset < 0) ? (0x100 | -Addr.Offset) : Addr.Offset;
938 MIB.addImm(Addr.Offset);
940 MIB.addMemOperand(MMO);
942 // Now add the rest of the operands.
943 MIB.addReg(Addr.Base.Reg);
945 // ARM halfword load/stores and signed byte loads need an additional
948 signed Imm = (Addr.Offset < 0) ? (0x100 | -Addr.Offset) : Addr.Offset;
952 MIB.addImm(Addr.Offset);
955 AddOptionalDefs(MIB);
958 bool ARMFastISel::ARMEmitLoad(MVT VT, unsigned &ResultReg, Address &Addr,
959 unsigned Alignment, bool isZExt, bool allocReg) {
962 bool needVMOV = false;
963 const TargetRegisterClass *RC;
964 switch (VT.SimpleTy) {
965 // This is mostly going to be Neon/vector support.
966 default: return false;
970 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
971 Opc = isZExt ? ARM::t2LDRBi8 : ARM::t2LDRSBi8;
973 Opc = isZExt ? ARM::t2LDRBi12 : ARM::t2LDRSBi12;
982 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass;
985 if (Alignment && Alignment < 2 && !Subtarget->allowsUnalignedMem())
989 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
990 Opc = isZExt ? ARM::t2LDRHi8 : ARM::t2LDRSHi8;
992 Opc = isZExt ? ARM::t2LDRHi12 : ARM::t2LDRSHi12;
994 Opc = isZExt ? ARM::LDRH : ARM::LDRSH;
997 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass;
1000 if (Alignment && Alignment < 4 && !Subtarget->allowsUnalignedMem())
1004 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
1007 Opc = ARM::t2LDRi12;
1011 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass;
1014 if (!Subtarget->hasVFP2()) return false;
1015 // Unaligned loads need special handling. Floats require word-alignment.
1016 if (Alignment && Alignment < 4) {
1019 Opc = isThumb2 ? ARM::t2LDRi12 : ARM::LDRi12;
1020 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass;
1023 RC = TLI.getRegClassFor(VT);
1027 if (!Subtarget->hasVFP2()) return false;
1028 // FIXME: Unaligned loads need special handling. Doublewords require
1030 if (Alignment && Alignment < 4)
1034 RC = TLI.getRegClassFor(VT);
1037 // Simplify this down to something we can handle.
1038 ARMSimplifyAddress(Addr, VT, useAM3);
1040 // Create the base instruction, then add the operands.
1042 ResultReg = createResultReg(RC);
1043 assert (ResultReg > 255 && "Expected an allocated virtual register.");
1044 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1045 TII.get(Opc), ResultReg);
1046 AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOLoad, useAM3);
1048 // If we had an unaligned load of a float we've converted it to an regular
1049 // load. Now we must move from the GRP to the FP register.
1051 unsigned MoveReg = createResultReg(TLI.getRegClassFor(MVT::f32));
1052 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1053 TII.get(ARM::VMOVSR), MoveReg)
1054 .addReg(ResultReg));
1055 ResultReg = MoveReg;
1060 bool ARMFastISel::SelectLoad(const Instruction *I) {
1061 // Atomic loads need special handling.
1062 if (cast<LoadInst>(I)->isAtomic())
1065 // Verify we have a legal type before going any further.
1067 if (!isLoadTypeLegal(I->getType(), VT))
1070 // See if we can handle this address.
1072 if (!ARMComputeAddress(I->getOperand(0), Addr)) return false;
1075 if (!ARMEmitLoad(VT, ResultReg, Addr, cast<LoadInst>(I)->getAlignment()))
1077 updateValueMap(I, ResultReg);
1081 bool ARMFastISel::ARMEmitStore(MVT VT, unsigned SrcReg, Address &Addr,
1082 unsigned Alignment) {
1084 bool useAM3 = false;
1085 switch (VT.SimpleTy) {
1086 // This is mostly going to be Neon/vector support.
1087 default: return false;
1089 unsigned Res = createResultReg(isThumb2 ? &ARM::tGPRRegClass
1090 : &ARM::GPRRegClass);
1091 unsigned Opc = isThumb2 ? ARM::t2ANDri : ARM::ANDri;
1092 SrcReg = constrainOperandRegClass(TII.get(Opc), SrcReg, 1);
1093 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1095 .addReg(SrcReg).addImm(1));
1097 } // Fallthrough here.
1100 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
1101 StrOpc = ARM::t2STRBi8;
1103 StrOpc = ARM::t2STRBi12;
1105 StrOpc = ARM::STRBi12;
1109 if (Alignment && Alignment < 2 && !Subtarget->allowsUnalignedMem())
1113 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
1114 StrOpc = ARM::t2STRHi8;
1116 StrOpc = ARM::t2STRHi12;
1123 if (Alignment && Alignment < 4 && !Subtarget->allowsUnalignedMem())
1127 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
1128 StrOpc = ARM::t2STRi8;
1130 StrOpc = ARM::t2STRi12;
1132 StrOpc = ARM::STRi12;
1136 if (!Subtarget->hasVFP2()) return false;
1137 // Unaligned stores need special handling. Floats require word-alignment.
1138 if (Alignment && Alignment < 4) {
1139 unsigned MoveReg = createResultReg(TLI.getRegClassFor(MVT::i32));
1140 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1141 TII.get(ARM::VMOVRS), MoveReg)
1145 StrOpc = isThumb2 ? ARM::t2STRi12 : ARM::STRi12;
1147 StrOpc = ARM::VSTRS;
1151 if (!Subtarget->hasVFP2()) return false;
1152 // FIXME: Unaligned stores need special handling. Doublewords require
1154 if (Alignment && Alignment < 4)
1157 StrOpc = ARM::VSTRD;
1160 // Simplify this down to something we can handle.
1161 ARMSimplifyAddress(Addr, VT, useAM3);
1163 // Create the base instruction, then add the operands.
1164 SrcReg = constrainOperandRegClass(TII.get(StrOpc), SrcReg, 0);
1165 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1168 AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOStore, useAM3);
1172 bool ARMFastISel::SelectStore(const Instruction *I) {
1173 Value *Op0 = I->getOperand(0);
1174 unsigned SrcReg = 0;
1176 // Atomic stores need special handling.
1177 if (cast<StoreInst>(I)->isAtomic())
1180 // Verify we have a legal type before going any further.
1182 if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT))
1185 // Get the value to be stored into a register.
1186 SrcReg = getRegForValue(Op0);
1187 if (SrcReg == 0) return false;
1189 // See if we can handle this address.
1191 if (!ARMComputeAddress(I->getOperand(1), Addr))
1194 if (!ARMEmitStore(VT, SrcReg, Addr, cast<StoreInst>(I)->getAlignment()))
1199 static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) {
1201 // Needs two compares...
1202 case CmpInst::FCMP_ONE:
1203 case CmpInst::FCMP_UEQ:
1205 // AL is our "false" for now. The other two need more compares.
1207 case CmpInst::ICMP_EQ:
1208 case CmpInst::FCMP_OEQ:
1210 case CmpInst::ICMP_SGT:
1211 case CmpInst::FCMP_OGT:
1213 case CmpInst::ICMP_SGE:
1214 case CmpInst::FCMP_OGE:
1216 case CmpInst::ICMP_UGT:
1217 case CmpInst::FCMP_UGT:
1219 case CmpInst::FCMP_OLT:
1221 case CmpInst::ICMP_ULE:
1222 case CmpInst::FCMP_OLE:
1224 case CmpInst::FCMP_ORD:
1226 case CmpInst::FCMP_UNO:
1228 case CmpInst::FCMP_UGE:
1230 case CmpInst::ICMP_SLT:
1231 case CmpInst::FCMP_ULT:
1233 case CmpInst::ICMP_SLE:
1234 case CmpInst::FCMP_ULE:
1236 case CmpInst::FCMP_UNE:
1237 case CmpInst::ICMP_NE:
1239 case CmpInst::ICMP_UGE:
1241 case CmpInst::ICMP_ULT:
1246 bool ARMFastISel::SelectBranch(const Instruction *I) {
1247 const BranchInst *BI = cast<BranchInst>(I);
1248 MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)];
1249 MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)];
1251 // Simple branch support.
1253 // If we can, avoid recomputing the compare - redoing it could lead to wonky
1255 if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) {
1256 if (CI->hasOneUse() && (CI->getParent() == I->getParent())) {
1258 // Get the compare predicate.
1259 // Try to take advantage of fallthrough opportunities.
1260 CmpInst::Predicate Predicate = CI->getPredicate();
1261 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1262 std::swap(TBB, FBB);
1263 Predicate = CmpInst::getInversePredicate(Predicate);
1266 ARMCC::CondCodes ARMPred = getComparePred(Predicate);
1268 // We may not handle every CC for now.
1269 if (ARMPred == ARMCC::AL) return false;
1271 // Emit the compare.
1272 if (!ARMEmitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned()))
1275 unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc;
1276 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc))
1277 .addMBB(TBB).addImm(ARMPred).addReg(ARM::CPSR);
1278 finishCondBranch(BI->getParent(), TBB, FBB);
1281 } else if (TruncInst *TI = dyn_cast<TruncInst>(BI->getCondition())) {
1283 if (TI->hasOneUse() && TI->getParent() == I->getParent() &&
1284 (isLoadTypeLegal(TI->getOperand(0)->getType(), SourceVT))) {
1285 unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri;
1286 unsigned OpReg = getRegForValue(TI->getOperand(0));
1287 OpReg = constrainOperandRegClass(TII.get(TstOpc), OpReg, 0);
1288 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1290 .addReg(OpReg).addImm(1));
1292 unsigned CCMode = ARMCC::NE;
1293 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1294 std::swap(TBB, FBB);
1298 unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc;
1299 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc))
1300 .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
1302 finishCondBranch(BI->getParent(), TBB, FBB);
1305 } else if (const ConstantInt *CI =
1306 dyn_cast<ConstantInt>(BI->getCondition())) {
1307 uint64_t Imm = CI->getZExtValue();
1308 MachineBasicBlock *Target = (Imm == 0) ? FBB : TBB;
1309 fastEmitBranch(Target, DbgLoc);
1313 unsigned CmpReg = getRegForValue(BI->getCondition());
1314 if (CmpReg == 0) return false;
1316 // We've been divorced from our compare! Our block was split, and
1317 // now our compare lives in a predecessor block. We musn't
1318 // re-compare here, as the children of the compare aren't guaranteed
1319 // live across the block boundary (we *could* check for this).
1320 // Regardless, the compare has been done in the predecessor block,
1321 // and it left a value for us in a virtual register. Ergo, we test
1322 // the one-bit value left in the virtual register.
1323 unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri;
1324 CmpReg = constrainOperandRegClass(TII.get(TstOpc), CmpReg, 0);
1326 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TstOpc))
1330 unsigned CCMode = ARMCC::NE;
1331 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1332 std::swap(TBB, FBB);
1336 unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc;
1337 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc))
1338 .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
1339 finishCondBranch(BI->getParent(), TBB, FBB);
1343 bool ARMFastISel::SelectIndirectBr(const Instruction *I) {
1344 unsigned AddrReg = getRegForValue(I->getOperand(0));
1345 if (AddrReg == 0) return false;
1347 unsigned Opc = isThumb2 ? ARM::tBRIND : ARM::BX;
1348 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1349 TII.get(Opc)).addReg(AddrReg));
1351 const IndirectBrInst *IB = cast<IndirectBrInst>(I);
1352 for (const BasicBlock *SuccBB : IB->successors())
1353 FuncInfo.MBB->addSuccessor(FuncInfo.MBBMap[SuccBB]);
1358 bool ARMFastISel::ARMEmitCmp(const Value *Src1Value, const Value *Src2Value,
1360 Type *Ty = Src1Value->getType();
1361 EVT SrcEVT = TLI.getValueType(DL, Ty, true);
1362 if (!SrcEVT.isSimple()) return false;
1363 MVT SrcVT = SrcEVT.getSimpleVT();
1365 bool isFloat = (Ty->isFloatTy() || Ty->isDoubleTy());
1366 if (isFloat && !Subtarget->hasVFP2())
1369 // Check to see if the 2nd operand is a constant that we can encode directly
1372 bool UseImm = false;
1373 bool isNegativeImm = false;
1374 // FIXME: At -O0 we don't have anything that canonicalizes operand order.
1375 // Thus, Src1Value may be a ConstantInt, but we're missing it.
1376 if (const ConstantInt *ConstInt = dyn_cast<ConstantInt>(Src2Value)) {
1377 if (SrcVT == MVT::i32 || SrcVT == MVT::i16 || SrcVT == MVT::i8 ||
1379 const APInt &CIVal = ConstInt->getValue();
1380 Imm = (isZExt) ? (int)CIVal.getZExtValue() : (int)CIVal.getSExtValue();
1381 // For INT_MIN/LONG_MIN (i.e., 0x80000000) we need to use a cmp, rather
1382 // then a cmn, because there is no way to represent 2147483648 as a
1383 // signed 32-bit int.
1384 if (Imm < 0 && Imm != (int)0x80000000) {
1385 isNegativeImm = true;
1388 UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) :
1389 (ARM_AM::getSOImmVal(Imm) != -1);
1391 } else if (const ConstantFP *ConstFP = dyn_cast<ConstantFP>(Src2Value)) {
1392 if (SrcVT == MVT::f32 || SrcVT == MVT::f64)
1393 if (ConstFP->isZero() && !ConstFP->isNegative())
1399 bool needsExt = false;
1400 switch (SrcVT.SimpleTy) {
1401 default: return false;
1402 // TODO: Verify compares.
1405 CmpOpc = UseImm ? ARM::VCMPEZS : ARM::VCMPES;
1409 CmpOpc = UseImm ? ARM::VCMPEZD : ARM::VCMPED;
1415 // Intentional fall-through.
1419 CmpOpc = ARM::t2CMPrr;
1421 CmpOpc = isNegativeImm ? ARM::t2CMNri : ARM::t2CMPri;
1424 CmpOpc = ARM::CMPrr;
1426 CmpOpc = isNegativeImm ? ARM::CMNri : ARM::CMPri;
1431 unsigned SrcReg1 = getRegForValue(Src1Value);
1432 if (SrcReg1 == 0) return false;
1434 unsigned SrcReg2 = 0;
1436 SrcReg2 = getRegForValue(Src2Value);
1437 if (SrcReg2 == 0) return false;
1440 // We have i1, i8, or i16, we need to either zero extend or sign extend.
1442 SrcReg1 = ARMEmitIntExt(SrcVT, SrcReg1, MVT::i32, isZExt);
1443 if (SrcReg1 == 0) return false;
1445 SrcReg2 = ARMEmitIntExt(SrcVT, SrcReg2, MVT::i32, isZExt);
1446 if (SrcReg2 == 0) return false;
1450 const MCInstrDesc &II = TII.get(CmpOpc);
1451 SrcReg1 = constrainOperandRegClass(II, SrcReg1, 0);
1453 SrcReg2 = constrainOperandRegClass(II, SrcReg2, 1);
1454 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
1455 .addReg(SrcReg1).addReg(SrcReg2));
1457 MachineInstrBuilder MIB;
1458 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
1461 // Only add immediate for icmp as the immediate for fcmp is an implicit 0.0.
1464 AddOptionalDefs(MIB);
1467 // For floating point we need to move the result to a comparison register
1468 // that we can then use for branches.
1469 if (Ty->isFloatTy() || Ty->isDoubleTy())
1470 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1471 TII.get(ARM::FMSTAT)));
1475 bool ARMFastISel::SelectCmp(const Instruction *I) {
1476 const CmpInst *CI = cast<CmpInst>(I);
1478 // Get the compare predicate.
1479 ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate());
1481 // We may not handle every CC for now.
1482 if (ARMPred == ARMCC::AL) return false;
1484 // Emit the compare.
1485 if (!ARMEmitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned()))
1488 // Now set a register based on the comparison. Explicitly set the predicates
1490 unsigned MovCCOpc = isThumb2 ? ARM::t2MOVCCi : ARM::MOVCCi;
1491 const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass
1492 : &ARM::GPRRegClass;
1493 unsigned DestReg = createResultReg(RC);
1494 Constant *Zero = ConstantInt::get(Type::getInt32Ty(*Context), 0);
1495 unsigned ZeroReg = fastMaterializeConstant(Zero);
1496 // ARMEmitCmp emits a FMSTAT when necessary, so it's always safe to use CPSR.
1497 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc), DestReg)
1498 .addReg(ZeroReg).addImm(1)
1499 .addImm(ARMPred).addReg(ARM::CPSR);
1501 updateValueMap(I, DestReg);
1505 bool ARMFastISel::SelectFPExt(const Instruction *I) {
1506 // Make sure we have VFP and that we're extending float to double.
1507 if (!Subtarget->hasVFP2()) return false;
1509 Value *V = I->getOperand(0);
1510 if (!I->getType()->isDoubleTy() ||
1511 !V->getType()->isFloatTy()) return false;
1513 unsigned Op = getRegForValue(V);
1514 if (Op == 0) return false;
1516 unsigned Result = createResultReg(&ARM::DPRRegClass);
1517 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1518 TII.get(ARM::VCVTDS), Result)
1520 updateValueMap(I, Result);
1524 bool ARMFastISel::SelectFPTrunc(const Instruction *I) {
1525 // Make sure we have VFP and that we're truncating double to float.
1526 if (!Subtarget->hasVFP2()) return false;
1528 Value *V = I->getOperand(0);
1529 if (!(I->getType()->isFloatTy() &&
1530 V->getType()->isDoubleTy())) return false;
1532 unsigned Op = getRegForValue(V);
1533 if (Op == 0) return false;
1535 unsigned Result = createResultReg(&ARM::SPRRegClass);
1536 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1537 TII.get(ARM::VCVTSD), Result)
1539 updateValueMap(I, Result);
1543 bool ARMFastISel::SelectIToFP(const Instruction *I, bool isSigned) {
1544 // Make sure we have VFP.
1545 if (!Subtarget->hasVFP2()) return false;
1548 Type *Ty = I->getType();
1549 if (!isTypeLegal(Ty, DstVT))
1552 Value *Src = I->getOperand(0);
1553 EVT SrcEVT = TLI.getValueType(DL, Src->getType(), true);
1554 if (!SrcEVT.isSimple())
1556 MVT SrcVT = SrcEVT.getSimpleVT();
1557 if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8)
1560 unsigned SrcReg = getRegForValue(Src);
1561 if (SrcReg == 0) return false;
1563 // Handle sign-extension.
1564 if (SrcVT == MVT::i16 || SrcVT == MVT::i8) {
1565 SrcReg = ARMEmitIntExt(SrcVT, SrcReg, MVT::i32,
1566 /*isZExt*/!isSigned);
1567 if (SrcReg == 0) return false;
1570 // The conversion routine works on fp-reg to fp-reg and the operand above
1571 // was an integer, move it to the fp registers if possible.
1572 unsigned FP = ARMMoveToFPReg(MVT::f32, SrcReg);
1573 if (FP == 0) return false;
1576 if (Ty->isFloatTy()) Opc = isSigned ? ARM::VSITOS : ARM::VUITOS;
1577 else if (Ty->isDoubleTy()) Opc = isSigned ? ARM::VSITOD : ARM::VUITOD;
1580 unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT));
1581 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1582 TII.get(Opc), ResultReg).addReg(FP));
1583 updateValueMap(I, ResultReg);
1587 bool ARMFastISel::SelectFPToI(const Instruction *I, bool isSigned) {
1588 // Make sure we have VFP.
1589 if (!Subtarget->hasVFP2()) return false;
1592 Type *RetTy = I->getType();
1593 if (!isTypeLegal(RetTy, DstVT))
1596 unsigned Op = getRegForValue(I->getOperand(0));
1597 if (Op == 0) return false;
1600 Type *OpTy = I->getOperand(0)->getType();
1601 if (OpTy->isFloatTy()) Opc = isSigned ? ARM::VTOSIZS : ARM::VTOUIZS;
1602 else if (OpTy->isDoubleTy()) Opc = isSigned ? ARM::VTOSIZD : ARM::VTOUIZD;
1605 // f64->s32/u32 or f32->s32/u32 both need an intermediate f32 reg.
1606 unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32));
1607 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1608 TII.get(Opc), ResultReg).addReg(Op));
1610 // This result needs to be in an integer register, but the conversion only
1611 // takes place in fp-regs.
1612 unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg);
1613 if (IntReg == 0) return false;
1615 updateValueMap(I, IntReg);
1619 bool ARMFastISel::SelectSelect(const Instruction *I) {
1621 if (!isTypeLegal(I->getType(), VT))
1624 // Things need to be register sized for register moves.
1625 if (VT != MVT::i32) return false;
1627 unsigned CondReg = getRegForValue(I->getOperand(0));
1628 if (CondReg == 0) return false;
1629 unsigned Op1Reg = getRegForValue(I->getOperand(1));
1630 if (Op1Reg == 0) return false;
1632 // Check to see if we can use an immediate in the conditional move.
1634 bool UseImm = false;
1635 bool isNegativeImm = false;
1636 if (const ConstantInt *ConstInt = dyn_cast<ConstantInt>(I->getOperand(2))) {
1637 assert (VT == MVT::i32 && "Expecting an i32.");
1638 Imm = (int)ConstInt->getValue().getZExtValue();
1640 isNegativeImm = true;
1643 UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) :
1644 (ARM_AM::getSOImmVal(Imm) != -1);
1647 unsigned Op2Reg = 0;
1649 Op2Reg = getRegForValue(I->getOperand(2));
1650 if (Op2Reg == 0) return false;
1653 unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri;
1654 CondReg = constrainOperandRegClass(TII.get(TstOpc), CondReg, 0);
1656 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TstOpc))
1661 const TargetRegisterClass *RC;
1663 RC = isThumb2 ? &ARM::tGPRRegClass : &ARM::GPRRegClass;
1664 MovCCOpc = isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr;
1666 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRRegClass;
1668 MovCCOpc = isThumb2 ? ARM::t2MOVCCi : ARM::MOVCCi;
1670 MovCCOpc = isThumb2 ? ARM::t2MVNCCi : ARM::MVNCCi;
1672 unsigned ResultReg = createResultReg(RC);
1674 Op2Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op2Reg, 1);
1675 Op1Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op1Reg, 2);
1676 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc),
1683 Op1Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op1Reg, 1);
1684 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc),
1691 updateValueMap(I, ResultReg);
1695 bool ARMFastISel::SelectDiv(const Instruction *I, bool isSigned) {
1697 Type *Ty = I->getType();
1698 if (!isTypeLegal(Ty, VT))
1701 // If we have integer div support we should have selected this automagically.
1702 // In case we have a real miss go ahead and return false and we'll pick
1704 if (Subtarget->hasDivide()) return false;
1706 // Otherwise emit a libcall.
1707 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1709 LC = isSigned ? RTLIB::SDIV_I8 : RTLIB::UDIV_I8;
1710 else if (VT == MVT::i16)
1711 LC = isSigned ? RTLIB::SDIV_I16 : RTLIB::UDIV_I16;
1712 else if (VT == MVT::i32)
1713 LC = isSigned ? RTLIB::SDIV_I32 : RTLIB::UDIV_I32;
1714 else if (VT == MVT::i64)
1715 LC = isSigned ? RTLIB::SDIV_I64 : RTLIB::UDIV_I64;
1716 else if (VT == MVT::i128)
1717 LC = isSigned ? RTLIB::SDIV_I128 : RTLIB::UDIV_I128;
1718 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!");
1720 return ARMEmitLibcall(I, LC);
1723 bool ARMFastISel::SelectRem(const Instruction *I, bool isSigned) {
1725 Type *Ty = I->getType();
1726 if (!isTypeLegal(Ty, VT))
1729 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1731 LC = isSigned ? RTLIB::SREM_I8 : RTLIB::UREM_I8;
1732 else if (VT == MVT::i16)
1733 LC = isSigned ? RTLIB::SREM_I16 : RTLIB::UREM_I16;
1734 else if (VT == MVT::i32)
1735 LC = isSigned ? RTLIB::SREM_I32 : RTLIB::UREM_I32;
1736 else if (VT == MVT::i64)
1737 LC = isSigned ? RTLIB::SREM_I64 : RTLIB::UREM_I64;
1738 else if (VT == MVT::i128)
1739 LC = isSigned ? RTLIB::SREM_I128 : RTLIB::UREM_I128;
1740 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!");
1742 return ARMEmitLibcall(I, LC);
1745 bool ARMFastISel::SelectBinaryIntOp(const Instruction *I, unsigned ISDOpcode) {
1746 EVT DestVT = TLI.getValueType(DL, I->getType(), true);
1748 // We can get here in the case when we have a binary operation on a non-legal
1749 // type and the target independent selector doesn't know how to handle it.
1750 if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1)
1754 switch (ISDOpcode) {
1755 default: return false;
1757 Opc = isThumb2 ? ARM::t2ADDrr : ARM::ADDrr;
1760 Opc = isThumb2 ? ARM::t2ORRrr : ARM::ORRrr;
1763 Opc = isThumb2 ? ARM::t2SUBrr : ARM::SUBrr;
1767 unsigned SrcReg1 = getRegForValue(I->getOperand(0));
1768 if (SrcReg1 == 0) return false;
1770 // TODO: Often the 2nd operand is an immediate, which can be encoded directly
1771 // in the instruction, rather then materializing the value in a register.
1772 unsigned SrcReg2 = getRegForValue(I->getOperand(1));
1773 if (SrcReg2 == 0) return false;
1775 unsigned ResultReg = createResultReg(&ARM::GPRnopcRegClass);
1776 SrcReg1 = constrainOperandRegClass(TII.get(Opc), SrcReg1, 1);
1777 SrcReg2 = constrainOperandRegClass(TII.get(Opc), SrcReg2, 2);
1778 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1779 TII.get(Opc), ResultReg)
1780 .addReg(SrcReg1).addReg(SrcReg2));
1781 updateValueMap(I, ResultReg);
1785 bool ARMFastISel::SelectBinaryFPOp(const Instruction *I, unsigned ISDOpcode) {
1786 EVT FPVT = TLI.getValueType(DL, I->getType(), true);
1787 if (!FPVT.isSimple()) return false;
1788 MVT VT = FPVT.getSimpleVT();
1790 // FIXME: Support vector types where possible.
1794 // We can get here in the case when we want to use NEON for our fp
1795 // operations, but can't figure out how to. Just use the vfp instructions
1797 // FIXME: It'd be nice to use NEON instructions.
1798 Type *Ty = I->getType();
1799 bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
1800 if (isFloat && !Subtarget->hasVFP2())
1804 bool is64bit = VT == MVT::f64 || VT == MVT::i64;
1805 switch (ISDOpcode) {
1806 default: return false;
1808 Opc = is64bit ? ARM::VADDD : ARM::VADDS;
1811 Opc = is64bit ? ARM::VSUBD : ARM::VSUBS;
1814 Opc = is64bit ? ARM::VMULD : ARM::VMULS;
1817 unsigned Op1 = getRegForValue(I->getOperand(0));
1818 if (Op1 == 0) return false;
1820 unsigned Op2 = getRegForValue(I->getOperand(1));
1821 if (Op2 == 0) return false;
1823 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT.SimpleTy));
1824 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1825 TII.get(Opc), ResultReg)
1826 .addReg(Op1).addReg(Op2));
1827 updateValueMap(I, ResultReg);
1831 // Call Handling Code
1833 // This is largely taken directly from CCAssignFnForNode
1834 // TODO: We may not support all of this.
1835 CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC,
1840 llvm_unreachable("Unsupported calling convention");
1841 case CallingConv::Fast:
1842 if (Subtarget->hasVFP2() && !isVarArg) {
1843 if (!Subtarget->isAAPCS_ABI())
1844 return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS);
1845 // For AAPCS ABI targets, just use VFP variant of the calling convention.
1846 return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP);
1849 case CallingConv::C:
1850 // Use target triple & subtarget features to do actual dispatch.
1851 if (Subtarget->isAAPCS_ABI()) {
1852 if (Subtarget->hasVFP2() &&
1853 TM.Options.FloatABIType == FloatABI::Hard && !isVarArg)
1854 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
1856 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
1858 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1860 case CallingConv::ARM_AAPCS_VFP:
1862 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
1863 // Fall through to soft float variant, variadic functions don't
1864 // use hard floating point ABI.
1865 case CallingConv::ARM_AAPCS:
1866 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
1867 case CallingConv::ARM_APCS:
1868 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1869 case CallingConv::GHC:
1871 llvm_unreachable("Can't return in GHC call convention");
1873 return CC_ARM_APCS_GHC;
1877 bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args,
1878 SmallVectorImpl<unsigned> &ArgRegs,
1879 SmallVectorImpl<MVT> &ArgVTs,
1880 SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
1881 SmallVectorImpl<unsigned> &RegArgs,
1885 SmallVector<CCValAssign, 16> ArgLocs;
1886 CCState CCInfo(CC, isVarArg, *FuncInfo.MF, ArgLocs, *Context);
1887 CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags,
1888 CCAssignFnForCall(CC, false, isVarArg));
1890 // Check that we can handle all of the arguments. If we can't, then bail out
1891 // now before we add code to the MBB.
1892 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1893 CCValAssign &VA = ArgLocs[i];
1894 MVT ArgVT = ArgVTs[VA.getValNo()];
1896 // We don't handle NEON/vector parameters yet.
1897 if (ArgVT.isVector() || ArgVT.getSizeInBits() > 64)
1900 // Now copy/store arg to correct locations.
1901 if (VA.isRegLoc() && !VA.needsCustom()) {
1903 } else if (VA.needsCustom()) {
1904 // TODO: We need custom lowering for vector (v2f64) args.
1905 if (VA.getLocVT() != MVT::f64 ||
1906 // TODO: Only handle register args for now.
1907 !VA.isRegLoc() || !ArgLocs[++i].isRegLoc())
1910 switch (ArgVT.SimpleTy) {
1919 if (!Subtarget->hasVFP2())
1923 if (!Subtarget->hasVFP2())
1930 // At the point, we are able to handle the call's arguments in fast isel.
1932 // Get a count of how many bytes are to be pushed on the stack.
1933 NumBytes = CCInfo.getNextStackOffset();
1935 // Issue CALLSEQ_START
1936 unsigned AdjStackDown = TII.getCallFrameSetupOpcode();
1937 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1938 TII.get(AdjStackDown))
1941 // Process the args.
1942 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1943 CCValAssign &VA = ArgLocs[i];
1944 const Value *ArgVal = Args[VA.getValNo()];
1945 unsigned Arg = ArgRegs[VA.getValNo()];
1946 MVT ArgVT = ArgVTs[VA.getValNo()];
1948 assert((!ArgVT.isVector() && ArgVT.getSizeInBits() <= 64) &&
1949 "We don't handle NEON/vector parameters yet.");
1951 // Handle arg promotion, etc.
1952 switch (VA.getLocInfo()) {
1953 case CCValAssign::Full: break;
1954 case CCValAssign::SExt: {
1955 MVT DestVT = VA.getLocVT();
1956 Arg = ARMEmitIntExt(ArgVT, Arg, DestVT, /*isZExt*/false);
1957 assert (Arg != 0 && "Failed to emit a sext");
1961 case CCValAssign::AExt:
1962 // Intentional fall-through. Handle AExt and ZExt.
1963 case CCValAssign::ZExt: {
1964 MVT DestVT = VA.getLocVT();
1965 Arg = ARMEmitIntExt(ArgVT, Arg, DestVT, /*isZExt*/true);
1966 assert (Arg != 0 && "Failed to emit a zext");
1970 case CCValAssign::BCvt: {
1971 unsigned BC = fastEmit_r(ArgVT, VA.getLocVT(), ISD::BITCAST, Arg,
1972 /*TODO: Kill=*/false);
1973 assert(BC != 0 && "Failed to emit a bitcast!");
1975 ArgVT = VA.getLocVT();
1978 default: llvm_unreachable("Unknown arg promotion!");
1981 // Now copy/store arg to correct locations.
1982 if (VA.isRegLoc() && !VA.needsCustom()) {
1983 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1984 TII.get(TargetOpcode::COPY), VA.getLocReg()).addReg(Arg);
1985 RegArgs.push_back(VA.getLocReg());
1986 } else if (VA.needsCustom()) {
1987 // TODO: We need custom lowering for vector (v2f64) args.
1988 assert(VA.getLocVT() == MVT::f64 &&
1989 "Custom lowering for v2f64 args not available");
1991 CCValAssign &NextVA = ArgLocs[++i];
1993 assert(VA.isRegLoc() && NextVA.isRegLoc() &&
1994 "We only handle register args!");
1996 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1997 TII.get(ARM::VMOVRRD), VA.getLocReg())
1998 .addReg(NextVA.getLocReg(), RegState::Define)
2000 RegArgs.push_back(VA.getLocReg());
2001 RegArgs.push_back(NextVA.getLocReg());
2003 assert(VA.isMemLoc());
2004 // Need to store on the stack.
2006 // Don't emit stores for undef values.
2007 if (isa<UndefValue>(ArgVal))
2011 Addr.BaseType = Address::RegBase;
2012 Addr.Base.Reg = ARM::SP;
2013 Addr.Offset = VA.getLocMemOffset();
2015 bool EmitRet = ARMEmitStore(ArgVT, Arg, Addr); (void)EmitRet;
2016 assert(EmitRet && "Could not emit a store for argument!");
2023 bool ARMFastISel::FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
2024 const Instruction *I, CallingConv::ID CC,
2025 unsigned &NumBytes, bool isVarArg) {
2026 // Issue CALLSEQ_END
2027 unsigned AdjStackUp = TII.getCallFrameDestroyOpcode();
2028 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2029 TII.get(AdjStackUp))
2030 .addImm(NumBytes).addImm(0));
2032 // Now the return value.
2033 if (RetVT != MVT::isVoid) {
2034 SmallVector<CCValAssign, 16> RVLocs;
2035 CCState CCInfo(CC, isVarArg, *FuncInfo.MF, RVLocs, *Context);
2036 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, isVarArg));
2038 // Copy all of the result registers out of their specified physreg.
2039 if (RVLocs.size() == 2 && RetVT == MVT::f64) {
2040 // For this move we copy into two registers and then move into the
2041 // double fp reg we want.
2042 MVT DestVT = RVLocs[0].getValVT();
2043 const TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT);
2044 unsigned ResultReg = createResultReg(DstRC);
2045 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2046 TII.get(ARM::VMOVDRR), ResultReg)
2047 .addReg(RVLocs[0].getLocReg())
2048 .addReg(RVLocs[1].getLocReg()));
2050 UsedRegs.push_back(RVLocs[0].getLocReg());
2051 UsedRegs.push_back(RVLocs[1].getLocReg());
2053 // Finally update the result.
2054 updateValueMap(I, ResultReg);
2056 assert(RVLocs.size() == 1 &&"Can't handle non-double multi-reg retvals!");
2057 MVT CopyVT = RVLocs[0].getValVT();
2059 // Special handling for extended integers.
2060 if (RetVT == MVT::i1 || RetVT == MVT::i8 || RetVT == MVT::i16)
2063 const TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT);
2065 unsigned ResultReg = createResultReg(DstRC);
2066 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2067 TII.get(TargetOpcode::COPY),
2068 ResultReg).addReg(RVLocs[0].getLocReg());
2069 UsedRegs.push_back(RVLocs[0].getLocReg());
2071 // Finally update the result.
2072 updateValueMap(I, ResultReg);
2079 bool ARMFastISel::SelectRet(const Instruction *I) {
2080 const ReturnInst *Ret = cast<ReturnInst>(I);
2081 const Function &F = *I->getParent()->getParent();
2083 if (!FuncInfo.CanLowerReturn)
2086 if (TLI.supportSplitCSR(FuncInfo.MF))
2089 // Build a list of return value registers.
2090 SmallVector<unsigned, 4> RetRegs;
2092 CallingConv::ID CC = F.getCallingConv();
2093 if (Ret->getNumOperands() > 0) {
2094 SmallVector<ISD::OutputArg, 4> Outs;
2095 GetReturnInfo(F.getReturnType(), F.getAttributes(), Outs, TLI, DL);
2097 // Analyze operands of the call, assigning locations to each operand.
2098 SmallVector<CCValAssign, 16> ValLocs;
2099 CCState CCInfo(CC, F.isVarArg(), *FuncInfo.MF, ValLocs, I->getContext());
2100 CCInfo.AnalyzeReturn(Outs, CCAssignFnForCall(CC, true /* is Ret */,
2103 const Value *RV = Ret->getOperand(0);
2104 unsigned Reg = getRegForValue(RV);
2108 // Only handle a single return value for now.
2109 if (ValLocs.size() != 1)
2112 CCValAssign &VA = ValLocs[0];
2114 // Don't bother handling odd stuff for now.
2115 if (VA.getLocInfo() != CCValAssign::Full)
2117 // Only handle register returns for now.
2121 unsigned SrcReg = Reg + VA.getValNo();
2122 EVT RVEVT = TLI.getValueType(DL, RV->getType());
2123 if (!RVEVT.isSimple()) return false;
2124 MVT RVVT = RVEVT.getSimpleVT();
2125 MVT DestVT = VA.getValVT();
2126 // Special handling for extended integers.
2127 if (RVVT != DestVT) {
2128 if (RVVT != MVT::i1 && RVVT != MVT::i8 && RVVT != MVT::i16)
2131 assert(DestVT == MVT::i32 && "ARM should always ext to i32");
2133 // Perform extension if flagged as either zext or sext. Otherwise, do
2135 if (Outs[0].Flags.isZExt() || Outs[0].Flags.isSExt()) {
2136 SrcReg = ARMEmitIntExt(RVVT, SrcReg, DestVT, Outs[0].Flags.isZExt());
2137 if (SrcReg == 0) return false;
2142 unsigned DstReg = VA.getLocReg();
2143 const TargetRegisterClass* SrcRC = MRI.getRegClass(SrcReg);
2144 // Avoid a cross-class copy. This is very unlikely.
2145 if (!SrcRC->contains(DstReg))
2147 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2148 TII.get(TargetOpcode::COPY), DstReg).addReg(SrcReg);
2150 // Add register to return instruction.
2151 RetRegs.push_back(VA.getLocReg());
2154 unsigned RetOpc = isThumb2 ? ARM::tBX_RET : ARM::BX_RET;
2155 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2157 AddOptionalDefs(MIB);
2158 for (unsigned i = 0, e = RetRegs.size(); i != e; ++i)
2159 MIB.addReg(RetRegs[i], RegState::Implicit);
2163 unsigned ARMFastISel::ARMSelectCallOp(bool UseReg) {
2165 return isThumb2 ? ARM::tBLXr : ARM::BLX;
2167 return isThumb2 ? ARM::tBL : ARM::BL;
2170 unsigned ARMFastISel::getLibcallReg(const Twine &Name) {
2171 // Manually compute the global's type to avoid building it when unnecessary.
2172 Type *GVTy = Type::getInt32PtrTy(*Context, /*AS=*/0);
2173 EVT LCREVT = TLI.getValueType(DL, GVTy);
2174 if (!LCREVT.isSimple()) return 0;
2176 GlobalValue *GV = new GlobalVariable(M, Type::getInt32Ty(*Context), false,
2177 GlobalValue::ExternalLinkage, nullptr,
2179 assert(GV->getType() == GVTy && "We miscomputed the type for the global!");
2180 return ARMMaterializeGV(GV, LCREVT.getSimpleVT());
2183 // A quick function that will emit a call for a named libcall in F with the
2184 // vector of passed arguments for the Instruction in I. We can assume that we
2185 // can emit a call for any libcall we can produce. This is an abridged version
2186 // of the full call infrastructure since we won't need to worry about things
2187 // like computed function pointers or strange arguments at call sites.
2188 // TODO: Try to unify this and the normal call bits for ARM, then try to unify
2190 bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) {
2191 CallingConv::ID CC = TLI.getLibcallCallingConv(Call);
2193 // Handle *simple* calls for now.
2194 Type *RetTy = I->getType();
2196 if (RetTy->isVoidTy())
2197 RetVT = MVT::isVoid;
2198 else if (!isTypeLegal(RetTy, RetVT))
2201 // Can't handle non-double multi-reg retvals.
2202 if (RetVT != MVT::isVoid && RetVT != MVT::i32) {
2203 SmallVector<CCValAssign, 16> RVLocs;
2204 CCState CCInfo(CC, false, *FuncInfo.MF, RVLocs, *Context);
2205 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, false));
2206 if (RVLocs.size() >= 2 && RetVT != MVT::f64)
2210 // Set up the argument vectors.
2211 SmallVector<Value*, 8> Args;
2212 SmallVector<unsigned, 8> ArgRegs;
2213 SmallVector<MVT, 8> ArgVTs;
2214 SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
2215 Args.reserve(I->getNumOperands());
2216 ArgRegs.reserve(I->getNumOperands());
2217 ArgVTs.reserve(I->getNumOperands());
2218 ArgFlags.reserve(I->getNumOperands());
2219 for (unsigned i = 0; i < I->getNumOperands(); ++i) {
2220 Value *Op = I->getOperand(i);
2221 unsigned Arg = getRegForValue(Op);
2222 if (Arg == 0) return false;
2224 Type *ArgTy = Op->getType();
2226 if (!isTypeLegal(ArgTy, ArgVT)) return false;
2228 ISD::ArgFlagsTy Flags;
2229 unsigned OriginalAlignment = DL.getABITypeAlignment(ArgTy);
2230 Flags.setOrigAlign(OriginalAlignment);
2233 ArgRegs.push_back(Arg);
2234 ArgVTs.push_back(ArgVT);
2235 ArgFlags.push_back(Flags);
2238 // Handle the arguments now that we've gotten them.
2239 SmallVector<unsigned, 4> RegArgs;
2241 if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags,
2242 RegArgs, CC, NumBytes, false))
2245 unsigned CalleeReg = 0;
2246 if (Subtarget->genLongCalls()) {
2247 CalleeReg = getLibcallReg(TLI.getLibcallName(Call));
2248 if (CalleeReg == 0) return false;
2252 unsigned CallOpc = ARMSelectCallOp(Subtarget->genLongCalls());
2253 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
2254 DbgLoc, TII.get(CallOpc));
2255 // BL / BLX don't take a predicate, but tBL / tBLX do.
2257 AddDefaultPred(MIB);
2258 if (Subtarget->genLongCalls())
2259 MIB.addReg(CalleeReg);
2261 MIB.addExternalSymbol(TLI.getLibcallName(Call));
2263 // Add implicit physical register uses to the call.
2264 for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
2265 MIB.addReg(RegArgs[i], RegState::Implicit);
2267 // Add a register mask with the call-preserved registers.
2268 // Proper defs for return values will be added by setPhysRegsDeadExcept().
2269 MIB.addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC));
2271 // Finish off the call including any return values.
2272 SmallVector<unsigned, 4> UsedRegs;
2273 if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes, false)) return false;
2275 // Set all unused physreg defs as dead.
2276 static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
2281 bool ARMFastISel::SelectCall(const Instruction *I,
2282 const char *IntrMemName = nullptr) {
2283 const CallInst *CI = cast<CallInst>(I);
2284 const Value *Callee = CI->getCalledValue();
2286 // Can't handle inline asm.
2287 if (isa<InlineAsm>(Callee)) return false;
2289 // Allow SelectionDAG isel to handle tail calls.
2290 if (CI->isTailCall()) return false;
2292 // Check the calling convention.
2293 ImmutableCallSite CS(CI);
2294 CallingConv::ID CC = CS.getCallingConv();
2296 // TODO: Avoid some calling conventions?
2298 PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType());
2299 FunctionType *FTy = cast<FunctionType>(PT->getElementType());
2300 bool isVarArg = FTy->isVarArg();
2302 // Handle *simple* calls for now.
2303 Type *RetTy = I->getType();
2305 if (RetTy->isVoidTy())
2306 RetVT = MVT::isVoid;
2307 else if (!isTypeLegal(RetTy, RetVT) && RetVT != MVT::i16 &&
2308 RetVT != MVT::i8 && RetVT != MVT::i1)
2311 // Can't handle non-double multi-reg retvals.
2312 if (RetVT != MVT::isVoid && RetVT != MVT::i1 && RetVT != MVT::i8 &&
2313 RetVT != MVT::i16 && RetVT != MVT::i32) {
2314 SmallVector<CCValAssign, 16> RVLocs;
2315 CCState CCInfo(CC, isVarArg, *FuncInfo.MF, RVLocs, *Context);
2316 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, isVarArg));
2317 if (RVLocs.size() >= 2 && RetVT != MVT::f64)
2321 // Set up the argument vectors.
2322 SmallVector<Value*, 8> Args;
2323 SmallVector<unsigned, 8> ArgRegs;
2324 SmallVector<MVT, 8> ArgVTs;
2325 SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
2326 unsigned arg_size = CS.arg_size();
2327 Args.reserve(arg_size);
2328 ArgRegs.reserve(arg_size);
2329 ArgVTs.reserve(arg_size);
2330 ArgFlags.reserve(arg_size);
2331 for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
2333 // If we're lowering a memory intrinsic instead of a regular call, skip the
2334 // last two arguments, which shouldn't be passed to the underlying function.
2335 if (IntrMemName && e-i <= 2)
2338 ISD::ArgFlagsTy Flags;
2339 unsigned AttrInd = i - CS.arg_begin() + 1;
2340 if (CS.paramHasAttr(AttrInd, Attribute::SExt))
2342 if (CS.paramHasAttr(AttrInd, Attribute::ZExt))
2345 // FIXME: Only handle *easy* calls for now.
2346 if (CS.paramHasAttr(AttrInd, Attribute::InReg) ||
2347 CS.paramHasAttr(AttrInd, Attribute::StructRet) ||
2348 CS.paramHasAttr(AttrInd, Attribute::Nest) ||
2349 CS.paramHasAttr(AttrInd, Attribute::ByVal))
2352 Type *ArgTy = (*i)->getType();
2354 if (!isTypeLegal(ArgTy, ArgVT) && ArgVT != MVT::i16 && ArgVT != MVT::i8 &&
2358 unsigned Arg = getRegForValue(*i);
2362 unsigned OriginalAlignment = DL.getABITypeAlignment(ArgTy);
2363 Flags.setOrigAlign(OriginalAlignment);
2366 ArgRegs.push_back(Arg);
2367 ArgVTs.push_back(ArgVT);
2368 ArgFlags.push_back(Flags);
2371 // Handle the arguments now that we've gotten them.
2372 SmallVector<unsigned, 4> RegArgs;
2374 if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags,
2375 RegArgs, CC, NumBytes, isVarArg))
2378 bool UseReg = false;
2379 const GlobalValue *GV = dyn_cast<GlobalValue>(Callee);
2380 if (!GV || Subtarget->genLongCalls()) UseReg = true;
2382 unsigned CalleeReg = 0;
2385 CalleeReg = getLibcallReg(IntrMemName);
2387 CalleeReg = getRegForValue(Callee);
2389 if (CalleeReg == 0) return false;
2393 unsigned CallOpc = ARMSelectCallOp(UseReg);
2394 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
2395 DbgLoc, TII.get(CallOpc));
2397 unsigned char OpFlags = 0;
2399 // Add MO_PLT for global address or external symbol in the PIC relocation
2401 if (Subtarget->isTargetELF() && TM.getRelocationModel() == Reloc::PIC_)
2402 OpFlags = ARMII::MO_PLT;
2404 // ARM calls don't take a predicate, but tBL / tBLX do.
2406 AddDefaultPred(MIB);
2408 MIB.addReg(CalleeReg);
2409 else if (!IntrMemName)
2410 MIB.addGlobalAddress(GV, 0, OpFlags);
2412 MIB.addExternalSymbol(IntrMemName, OpFlags);
2414 // Add implicit physical register uses to the call.
2415 for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
2416 MIB.addReg(RegArgs[i], RegState::Implicit);
2418 // Add a register mask with the call-preserved registers.
2419 // Proper defs for return values will be added by setPhysRegsDeadExcept().
2420 MIB.addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC));
2422 // Finish off the call including any return values.
2423 SmallVector<unsigned, 4> UsedRegs;
2424 if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes, isVarArg))
2427 // Set all unused physreg defs as dead.
2428 static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
2433 bool ARMFastISel::ARMIsMemCpySmall(uint64_t Len) {
2437 bool ARMFastISel::ARMTryEmitSmallMemCpy(Address Dest, Address Src,
2438 uint64_t Len, unsigned Alignment) {
2439 // Make sure we don't bloat code by inlining very large memcpy's.
2440 if (!ARMIsMemCpySmall(Len))
2445 if (!Alignment || Alignment >= 4) {
2451 assert (Len == 1 && "Expected a length of 1!");
2455 // Bound based on alignment.
2456 if (Len >= 2 && Alignment == 2)
2465 RV = ARMEmitLoad(VT, ResultReg, Src);
2466 assert (RV == true && "Should be able to handle this load.");
2467 RV = ARMEmitStore(VT, ResultReg, Dest);
2468 assert (RV == true && "Should be able to handle this store.");
2471 unsigned Size = VT.getSizeInBits()/8;
2473 Dest.Offset += Size;
2480 bool ARMFastISel::SelectIntrinsicCall(const IntrinsicInst &I) {
2481 // FIXME: Handle more intrinsics.
2482 switch (I.getIntrinsicID()) {
2483 default: return false;
2484 case Intrinsic::frameaddress: {
2485 MachineFrameInfo *MFI = FuncInfo.MF->getFrameInfo();
2486 MFI->setFrameAddressIsTaken(true);
2488 unsigned LdrOpc = isThumb2 ? ARM::t2LDRi12 : ARM::LDRi12;
2489 const TargetRegisterClass *RC = isThumb2 ? &ARM::tGPRRegClass
2490 : &ARM::GPRRegClass;
2492 const ARMBaseRegisterInfo *RegInfo =
2493 static_cast<const ARMBaseRegisterInfo *>(Subtarget->getRegisterInfo());
2494 unsigned FramePtr = RegInfo->getFrameRegister(*(FuncInfo.MF));
2495 unsigned SrcReg = FramePtr;
2497 // Recursively load frame address
2503 unsigned Depth = cast<ConstantInt>(I.getOperand(0))->getZExtValue();
2505 DestReg = createResultReg(RC);
2506 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2507 TII.get(LdrOpc), DestReg)
2508 .addReg(SrcReg).addImm(0));
2511 updateValueMap(&I, SrcReg);
2514 case Intrinsic::memcpy:
2515 case Intrinsic::memmove: {
2516 const MemTransferInst &MTI = cast<MemTransferInst>(I);
2517 // Don't handle volatile.
2518 if (MTI.isVolatile())
2521 // Disable inlining for memmove before calls to ComputeAddress. Otherwise,
2522 // we would emit dead code because we don't currently handle memmoves.
2523 bool isMemCpy = (I.getIntrinsicID() == Intrinsic::memcpy);
2524 if (isa<ConstantInt>(MTI.getLength()) && isMemCpy) {
2525 // Small memcpy's are common enough that we want to do them without a call
2527 uint64_t Len = cast<ConstantInt>(MTI.getLength())->getZExtValue();
2528 if (ARMIsMemCpySmall(Len)) {
2530 if (!ARMComputeAddress(MTI.getRawDest(), Dest) ||
2531 !ARMComputeAddress(MTI.getRawSource(), Src))
2533 unsigned Alignment = MTI.getAlignment();
2534 if (ARMTryEmitSmallMemCpy(Dest, Src, Len, Alignment))
2539 if (!MTI.getLength()->getType()->isIntegerTy(32))
2542 if (MTI.getSourceAddressSpace() > 255 || MTI.getDestAddressSpace() > 255)
2545 const char *IntrMemName = isa<MemCpyInst>(I) ? "memcpy" : "memmove";
2546 return SelectCall(&I, IntrMemName);
2548 case Intrinsic::memset: {
2549 const MemSetInst &MSI = cast<MemSetInst>(I);
2550 // Don't handle volatile.
2551 if (MSI.isVolatile())
2554 if (!MSI.getLength()->getType()->isIntegerTy(32))
2557 if (MSI.getDestAddressSpace() > 255)
2560 return SelectCall(&I, "memset");
2562 case Intrinsic::trap: {
2563 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(
2564 Subtarget->useNaClTrap() ? ARM::TRAPNaCl : ARM::TRAP));
2570 bool ARMFastISel::SelectTrunc(const Instruction *I) {
2571 // The high bits for a type smaller than the register size are assumed to be
2573 Value *Op = I->getOperand(0);
2576 SrcVT = TLI.getValueType(DL, Op->getType(), true);
2577 DestVT = TLI.getValueType(DL, I->getType(), true);
2579 if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8)
2581 if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1)
2584 unsigned SrcReg = getRegForValue(Op);
2585 if (!SrcReg) return false;
2587 // Because the high bits are undefined, a truncate doesn't generate
2589 updateValueMap(I, SrcReg);
2593 unsigned ARMFastISel::ARMEmitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
2595 if (DestVT != MVT::i32 && DestVT != MVT::i16 && DestVT != MVT::i8)
2597 if (SrcVT != MVT::i16 && SrcVT != MVT::i8 && SrcVT != MVT::i1)
2600 // Table of which combinations can be emitted as a single instruction,
2601 // and which will require two.
2602 static const uint8_t isSingleInstrTbl[3][2][2][2] = {
2604 // !hasV6Ops hasV6Ops !hasV6Ops hasV6Ops
2605 // ext: s z s z s z s z
2606 /* 1 */ { { { 0, 1 }, { 0, 1 } }, { { 0, 0 }, { 0, 1 } } },
2607 /* 8 */ { { { 0, 1 }, { 1, 1 } }, { { 0, 0 }, { 1, 1 } } },
2608 /* 16 */ { { { 0, 0 }, { 1, 1 } }, { { 0, 0 }, { 1, 1 } } }
2611 // Target registers for:
2612 // - For ARM can never be PC.
2613 // - For 16-bit Thumb are restricted to lower 8 registers.
2614 // - For 32-bit Thumb are restricted to non-SP and non-PC.
2615 static const TargetRegisterClass *RCTbl[2][2] = {
2616 // Instructions: Two Single
2617 /* ARM */ { &ARM::GPRnopcRegClass, &ARM::GPRnopcRegClass },
2618 /* Thumb */ { &ARM::tGPRRegClass, &ARM::rGPRRegClass }
2621 // Table governing the instruction(s) to be emitted.
2622 static const struct InstructionTable {
2624 uint32_t hasS : 1; // Some instructions have an S bit, always set it to 0.
2625 uint32_t Shift : 7; // For shift operand addressing mode, used by MOVsi.
2626 uint32_t Imm : 8; // All instructions have either a shift or a mask.
2627 } IT[2][2][3][2] = {
2628 { // Two instructions (first is left shift, second is in this table).
2629 { // ARM Opc S Shift Imm
2630 /* 1 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 31 },
2631 /* 1 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 31 } },
2632 /* 8 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 24 },
2633 /* 8 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 24 } },
2634 /* 16 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 16 },
2635 /* 16 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 16 } }
2637 { // Thumb Opc S Shift Imm
2638 /* 1 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 31 },
2639 /* 1 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 31 } },
2640 /* 8 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 24 },
2641 /* 8 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 24 } },
2642 /* 16 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 16 },
2643 /* 16 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 16 } }
2646 { // Single instruction.
2647 { // ARM Opc S Shift Imm
2648 /* 1 bit sext */ { { ARM::KILL , 0, ARM_AM::no_shift, 0 },
2649 /* 1 bit zext */ { ARM::ANDri , 1, ARM_AM::no_shift, 1 } },
2650 /* 8 bit sext */ { { ARM::SXTB , 0, ARM_AM::no_shift, 0 },
2651 /* 8 bit zext */ { ARM::ANDri , 1, ARM_AM::no_shift, 255 } },
2652 /* 16 bit sext */ { { ARM::SXTH , 0, ARM_AM::no_shift, 0 },
2653 /* 16 bit zext */ { ARM::UXTH , 0, ARM_AM::no_shift, 0 } }
2655 { // Thumb Opc S Shift Imm
2656 /* 1 bit sext */ { { ARM::KILL , 0, ARM_AM::no_shift, 0 },
2657 /* 1 bit zext */ { ARM::t2ANDri, 1, ARM_AM::no_shift, 1 } },
2658 /* 8 bit sext */ { { ARM::t2SXTB , 0, ARM_AM::no_shift, 0 },
2659 /* 8 bit zext */ { ARM::t2ANDri, 1, ARM_AM::no_shift, 255 } },
2660 /* 16 bit sext */ { { ARM::t2SXTH , 0, ARM_AM::no_shift, 0 },
2661 /* 16 bit zext */ { ARM::t2UXTH , 0, ARM_AM::no_shift, 0 } }
2666 unsigned SrcBits = SrcVT.getSizeInBits();
2667 unsigned DestBits = DestVT.getSizeInBits();
2669 assert((SrcBits < DestBits) && "can only extend to larger types");
2670 assert((DestBits == 32 || DestBits == 16 || DestBits == 8) &&
2671 "other sizes unimplemented");
2672 assert((SrcBits == 16 || SrcBits == 8 || SrcBits == 1) &&
2673 "other sizes unimplemented");
2675 bool hasV6Ops = Subtarget->hasV6Ops();
2676 unsigned Bitness = SrcBits / 8; // {1,8,16}=>{0,1,2}
2677 assert((Bitness < 3) && "sanity-check table bounds");
2679 bool isSingleInstr = isSingleInstrTbl[Bitness][isThumb2][hasV6Ops][isZExt];
2680 const TargetRegisterClass *RC = RCTbl[isThumb2][isSingleInstr];
2681 const InstructionTable *ITP = &IT[isSingleInstr][isThumb2][Bitness][isZExt];
2682 unsigned Opc = ITP->Opc;
2683 assert(ARM::KILL != Opc && "Invalid table entry");
2684 unsigned hasS = ITP->hasS;
2685 ARM_AM::ShiftOpc Shift = (ARM_AM::ShiftOpc) ITP->Shift;
2686 assert(((Shift == ARM_AM::no_shift) == (Opc != ARM::MOVsi)) &&
2687 "only MOVsi has shift operand addressing mode");
2688 unsigned Imm = ITP->Imm;
2690 // 16-bit Thumb instructions always set CPSR (unless they're in an IT block).
2691 bool setsCPSR = &ARM::tGPRRegClass == RC;
2692 unsigned LSLOpc = isThumb2 ? ARM::tLSLri : ARM::MOVsi;
2694 // MOVsi encodes shift and immediate in shift operand addressing mode.
2695 // The following condition has the same value when emitting two
2696 // instruction sequences: both are shifts.
2697 bool ImmIsSO = (Shift != ARM_AM::no_shift);
2699 // Either one or two instructions are emitted.
2700 // They're always of the form:
2702 // CPSR is set only by 16-bit Thumb instructions.
2703 // Predicate, if any, is AL.
2704 // S bit, if available, is always 0.
2705 // When two are emitted the first's result will feed as the second's input,
2706 // that value is then dead.
2707 unsigned NumInstrsEmitted = isSingleInstr ? 1 : 2;
2708 for (unsigned Instr = 0; Instr != NumInstrsEmitted; ++Instr) {
2709 ResultReg = createResultReg(RC);
2710 bool isLsl = (0 == Instr) && !isSingleInstr;
2711 unsigned Opcode = isLsl ? LSLOpc : Opc;
2712 ARM_AM::ShiftOpc ShiftAM = isLsl ? ARM_AM::lsl : Shift;
2713 unsigned ImmEnc = ImmIsSO ? ARM_AM::getSORegOpc(ShiftAM, Imm) : Imm;
2714 bool isKill = 1 == Instr;
2715 MachineInstrBuilder MIB = BuildMI(
2716 *FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opcode), ResultReg);
2718 MIB.addReg(ARM::CPSR, RegState::Define);
2719 SrcReg = constrainOperandRegClass(TII.get(Opcode), SrcReg, 1 + setsCPSR);
2720 AddDefaultPred(MIB.addReg(SrcReg, isKill * RegState::Kill).addImm(ImmEnc));
2723 // Second instruction consumes the first's result.
2730 bool ARMFastISel::SelectIntExt(const Instruction *I) {
2731 // On ARM, in general, integer casts don't involve legal types; this code
2732 // handles promotable integers.
2733 Type *DestTy = I->getType();
2734 Value *Src = I->getOperand(0);
2735 Type *SrcTy = Src->getType();
2737 bool isZExt = isa<ZExtInst>(I);
2738 unsigned SrcReg = getRegForValue(Src);
2739 if (!SrcReg) return false;
2741 EVT SrcEVT, DestEVT;
2742 SrcEVT = TLI.getValueType(DL, SrcTy, true);
2743 DestEVT = TLI.getValueType(DL, DestTy, true);
2744 if (!SrcEVT.isSimple()) return false;
2745 if (!DestEVT.isSimple()) return false;
2747 MVT SrcVT = SrcEVT.getSimpleVT();
2748 MVT DestVT = DestEVT.getSimpleVT();
2749 unsigned ResultReg = ARMEmitIntExt(SrcVT, SrcReg, DestVT, isZExt);
2750 if (ResultReg == 0) return false;
2751 updateValueMap(I, ResultReg);
2755 bool ARMFastISel::SelectShift(const Instruction *I,
2756 ARM_AM::ShiftOpc ShiftTy) {
2757 // We handle thumb2 mode by target independent selector
2758 // or SelectionDAG ISel.
2762 // Only handle i32 now.
2763 EVT DestVT = TLI.getValueType(DL, I->getType(), true);
2764 if (DestVT != MVT::i32)
2767 unsigned Opc = ARM::MOVsr;
2769 Value *Src2Value = I->getOperand(1);
2770 if (const ConstantInt *CI = dyn_cast<ConstantInt>(Src2Value)) {
2771 ShiftImm = CI->getZExtValue();
2773 // Fall back to selection DAG isel if the shift amount
2774 // is zero or greater than the width of the value type.
2775 if (ShiftImm == 0 || ShiftImm >=32)
2781 Value *Src1Value = I->getOperand(0);
2782 unsigned Reg1 = getRegForValue(Src1Value);
2783 if (Reg1 == 0) return false;
2786 if (Opc == ARM::MOVsr) {
2787 Reg2 = getRegForValue(Src2Value);
2788 if (Reg2 == 0) return false;
2791 unsigned ResultReg = createResultReg(&ARM::GPRnopcRegClass);
2792 if(ResultReg == 0) return false;
2794 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2795 TII.get(Opc), ResultReg)
2798 if (Opc == ARM::MOVsi)
2799 MIB.addImm(ARM_AM::getSORegOpc(ShiftTy, ShiftImm));
2800 else if (Opc == ARM::MOVsr) {
2802 MIB.addImm(ARM_AM::getSORegOpc(ShiftTy, 0));
2805 AddOptionalDefs(MIB);
2806 updateValueMap(I, ResultReg);
2810 // TODO: SoftFP support.
2811 bool ARMFastISel::fastSelectInstruction(const Instruction *I) {
2813 switch (I->getOpcode()) {
2814 case Instruction::Load:
2815 return SelectLoad(I);
2816 case Instruction::Store:
2817 return SelectStore(I);
2818 case Instruction::Br:
2819 return SelectBranch(I);
2820 case Instruction::IndirectBr:
2821 return SelectIndirectBr(I);
2822 case Instruction::ICmp:
2823 case Instruction::FCmp:
2824 return SelectCmp(I);
2825 case Instruction::FPExt:
2826 return SelectFPExt(I);
2827 case Instruction::FPTrunc:
2828 return SelectFPTrunc(I);
2829 case Instruction::SIToFP:
2830 return SelectIToFP(I, /*isSigned*/ true);
2831 case Instruction::UIToFP:
2832 return SelectIToFP(I, /*isSigned*/ false);
2833 case Instruction::FPToSI:
2834 return SelectFPToI(I, /*isSigned*/ true);
2835 case Instruction::FPToUI:
2836 return SelectFPToI(I, /*isSigned*/ false);
2837 case Instruction::Add:
2838 return SelectBinaryIntOp(I, ISD::ADD);
2839 case Instruction::Or:
2840 return SelectBinaryIntOp(I, ISD::OR);
2841 case Instruction::Sub:
2842 return SelectBinaryIntOp(I, ISD::SUB);
2843 case Instruction::FAdd:
2844 return SelectBinaryFPOp(I, ISD::FADD);
2845 case Instruction::FSub:
2846 return SelectBinaryFPOp(I, ISD::FSUB);
2847 case Instruction::FMul:
2848 return SelectBinaryFPOp(I, ISD::FMUL);
2849 case Instruction::SDiv:
2850 return SelectDiv(I, /*isSigned*/ true);
2851 case Instruction::UDiv:
2852 return SelectDiv(I, /*isSigned*/ false);
2853 case Instruction::SRem:
2854 return SelectRem(I, /*isSigned*/ true);
2855 case Instruction::URem:
2856 return SelectRem(I, /*isSigned*/ false);
2857 case Instruction::Call:
2858 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I))
2859 return SelectIntrinsicCall(*II);
2860 return SelectCall(I);
2861 case Instruction::Select:
2862 return SelectSelect(I);
2863 case Instruction::Ret:
2864 return SelectRet(I);
2865 case Instruction::Trunc:
2866 return SelectTrunc(I);
2867 case Instruction::ZExt:
2868 case Instruction::SExt:
2869 return SelectIntExt(I);
2870 case Instruction::Shl:
2871 return SelectShift(I, ARM_AM::lsl);
2872 case Instruction::LShr:
2873 return SelectShift(I, ARM_AM::lsr);
2874 case Instruction::AShr:
2875 return SelectShift(I, ARM_AM::asr);
2882 // This table describes sign- and zero-extend instructions which can be
2883 // folded into a preceding load. All of these extends have an immediate
2884 // (sometimes a mask and sometimes a shift) that's applied after
2886 const struct FoldableLoadExtendsStruct {
2887 uint16_t Opc[2]; // ARM, Thumb.
2888 uint8_t ExpectedImm;
2890 uint8_t ExpectedVT : 7;
2891 } FoldableLoadExtends[] = {
2892 { { ARM::SXTH, ARM::t2SXTH }, 0, 0, MVT::i16 },
2893 { { ARM::UXTH, ARM::t2UXTH }, 0, 1, MVT::i16 },
2894 { { ARM::ANDri, ARM::t2ANDri }, 255, 1, MVT::i8 },
2895 { { ARM::SXTB, ARM::t2SXTB }, 0, 0, MVT::i8 },
2896 { { ARM::UXTB, ARM::t2UXTB }, 0, 1, MVT::i8 }
2900 /// \brief The specified machine instr operand is a vreg, and that
2901 /// vreg is being provided by the specified load instruction. If possible,
2902 /// try to fold the load as an operand to the instruction, returning true if
2904 bool ARMFastISel::tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo,
2905 const LoadInst *LI) {
2906 // Verify we have a legal type before going any further.
2908 if (!isLoadTypeLegal(LI->getType(), VT))
2911 // Combine load followed by zero- or sign-extend.
2912 // ldrb r1, [r0] ldrb r1, [r0]
2914 // mov r3, r2 mov r3, r1
2915 if (MI->getNumOperands() < 3 || !MI->getOperand(2).isImm())
2917 const uint64_t Imm = MI->getOperand(2).getImm();
2921 for (unsigned i = 0, e = array_lengthof(FoldableLoadExtends);
2923 if (FoldableLoadExtends[i].Opc[isThumb2] == MI->getOpcode() &&
2924 (uint64_t)FoldableLoadExtends[i].ExpectedImm == Imm &&
2925 MVT((MVT::SimpleValueType)FoldableLoadExtends[i].ExpectedVT) == VT) {
2927 isZExt = FoldableLoadExtends[i].isZExt;
2930 if (!Found) return false;
2932 // See if we can handle this address.
2934 if (!ARMComputeAddress(LI->getOperand(0), Addr)) return false;
2936 unsigned ResultReg = MI->getOperand(0).getReg();
2937 if (!ARMEmitLoad(VT, ResultReg, Addr, LI->getAlignment(), isZExt, false))
2939 MI->eraseFromParent();
2943 unsigned ARMFastISel::ARMLowerPICELF(const GlobalValue *GV,
2944 unsigned Align, MVT VT) {
2946 !(GV->hasHiddenVisibility() || GV->hasLocalLinkage());
2948 LLVMContext *Context = &MF->getFunction()->getContext();
2949 unsigned ARMPCLabelIndex = AFI->createPICLabelUId();
2950 unsigned PCAdj = Subtarget->isThumb() ? 4 : 8;
2951 ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create(
2952 GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj,
2953 UseGOT_PREL ? ARMCP::GOT_PREL : ARMCP::no_modifier,
2954 /*AddCurrentAddress=*/UseGOT_PREL);
2956 unsigned ConstAlign =
2957 MF->getDataLayout().getPrefTypeAlignment(Type::getInt32PtrTy(*Context));
2958 unsigned Idx = MF->getConstantPool()->getConstantPoolIndex(CPV, ConstAlign);
2960 unsigned TempReg = MF->getRegInfo().createVirtualRegister(&ARM::rGPRRegClass);
2961 unsigned Opc = isThumb2 ? ARM::t2LDRpci : ARM::LDRcp;
2962 MachineInstrBuilder MIB =
2963 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), TempReg)
2964 .addConstantPoolIndex(Idx);
2965 if (Opc == ARM::LDRcp)
2967 AddDefaultPred(MIB);
2969 // Fix the address by adding pc.
2970 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
2971 Opc = Subtarget->isThumb() ? ARM::tPICADD : UseGOT_PREL ? ARM::PICLDR
2973 DestReg = constrainOperandRegClass(TII.get(Opc), DestReg, 0);
2974 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), DestReg)
2976 .addImm(ARMPCLabelIndex);
2977 if (!Subtarget->isThumb())
2978 AddDefaultPred(MIB);
2980 if (UseGOT_PREL && Subtarget->isThumb()) {
2981 unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT));
2982 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2983 TII.get(ARM::t2LDRi12), NewDestReg)
2986 DestReg = NewDestReg;
2987 AddOptionalDefs(MIB);
2992 bool ARMFastISel::fastLowerArguments() {
2993 if (!FuncInfo.CanLowerReturn)
2996 const Function *F = FuncInfo.Fn;
3000 CallingConv::ID CC = F->getCallingConv();
3004 case CallingConv::Fast:
3005 case CallingConv::C:
3006 case CallingConv::ARM_AAPCS_VFP:
3007 case CallingConv::ARM_AAPCS:
3008 case CallingConv::ARM_APCS:
3012 // Only handle simple cases. i.e. Up to 4 i8/i16/i32 scalar arguments
3013 // which are passed in r0 - r3.
3015 for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
3016 I != E; ++I, ++Idx) {
3020 if (F->getAttributes().hasAttribute(Idx, Attribute::InReg) ||
3021 F->getAttributes().hasAttribute(Idx, Attribute::StructRet) ||
3022 F->getAttributes().hasAttribute(Idx, Attribute::ByVal))
3025 Type *ArgTy = I->getType();
3026 if (ArgTy->isStructTy() || ArgTy->isArrayTy() || ArgTy->isVectorTy())
3029 EVT ArgVT = TLI.getValueType(DL, ArgTy);
3030 if (!ArgVT.isSimple()) return false;
3031 switch (ArgVT.getSimpleVT().SimpleTy) {
3042 static const MCPhysReg GPRArgRegs[] = {
3043 ARM::R0, ARM::R1, ARM::R2, ARM::R3
3046 const TargetRegisterClass *RC = &ARM::rGPRRegClass;
3048 for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
3049 I != E; ++I, ++Idx) {
3050 unsigned SrcReg = GPRArgRegs[Idx];
3051 unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC);
3052 // FIXME: Unfortunately it's necessary to emit a copy from the livein copy.
3053 // Without this, EmitLiveInCopies may eliminate the livein if its only
3054 // use is a bitcast (which isn't turned into an instruction).
3055 unsigned ResultReg = createResultReg(RC);
3056 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3057 TII.get(TargetOpcode::COPY),
3058 ResultReg).addReg(DstReg, getKillRegState(true));
3059 updateValueMap(&*I, ResultReg);
3066 FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo,
3067 const TargetLibraryInfo *libInfo) {
3068 if (funcInfo.MF->getSubtarget<ARMSubtarget>().useFastISel())
3069 return new ARMFastISel(funcInfo, libInfo);