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 "ARMBaseInstrInfo.h"
18 #include "ARMBaseRegisterInfo.h"
19 #include "ARMCallingConv.h"
20 #include "ARMConstantPoolValue.h"
21 #include "ARMISelLowering.h"
22 #include "ARMMachineFunctionInfo.h"
23 #include "ARMSubtarget.h"
24 #include "MCTargetDesc/ARMAddressingModes.h"
25 #include "MCTargetDesc/ARMBaseInfo.h"
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/ADT/APInt.h"
28 #include "llvm/ADT/DenseMap.h"
29 #include "llvm/ADT/STLExtras.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/CodeGen/CallingConvLower.h"
32 #include "llvm/CodeGen/FastISel.h"
33 #include "llvm/CodeGen/FunctionLoweringInfo.h"
34 #include "llvm/CodeGen/ISDOpcodes.h"
35 #include "llvm/CodeGen/MachineConstantPool.h"
36 #include "llvm/CodeGen/MachineFrameInfo.h"
37 #include "llvm/CodeGen/MachineInstr.h"
38 #include "llvm/CodeGen/MachineInstrBuilder.h"
39 #include "llvm/CodeGen/MachineMemOperand.h"
40 #include "llvm/CodeGen/MachineOperand.h"
41 #include "llvm/CodeGen/MachineRegisterInfo.h"
42 #include "llvm/CodeGen/MachineValueType.h"
43 #include "llvm/CodeGen/RuntimeLibcalls.h"
44 #include "llvm/CodeGen/ValueTypes.h"
45 #include "llvm/IR/Argument.h"
46 #include "llvm/IR/Attributes.h"
47 #include "llvm/IR/CallSite.h"
48 #include "llvm/IR/CallingConv.h"
49 #include "llvm/IR/Constant.h"
50 #include "llvm/IR/Constants.h"
51 #include "llvm/IR/DataLayout.h"
52 #include "llvm/IR/DerivedTypes.h"
53 #include "llvm/IR/Function.h"
54 #include "llvm/IR/GetElementPtrTypeIterator.h"
55 #include "llvm/IR/GlobalValue.h"
56 #include "llvm/IR/GlobalVariable.h"
57 #include "llvm/IR/InstrTypes.h"
58 #include "llvm/IR/Instruction.h"
59 #include "llvm/IR/Instructions.h"
60 #include "llvm/IR/IntrinsicInst.h"
61 #include "llvm/IR/Module.h"
62 #include "llvm/IR/Operator.h"
63 #include "llvm/IR/Type.h"
64 #include "llvm/IR/User.h"
65 #include "llvm/IR/Value.h"
66 #include "llvm/MC/MCInstrDesc.h"
67 #include "llvm/MC/MCRegisterInfo.h"
68 #include "llvm/Support/Casting.h"
69 #include "llvm/Support/Compiler.h"
70 #include "llvm/Support/ErrorHandling.h"
71 #include "llvm/Support/MathExtras.h"
72 #include "llvm/Target/TargetInstrInfo.h"
73 #include "llvm/Target/TargetLowering.h"
74 #include "llvm/Target/TargetMachine.h"
75 #include "llvm/Target/TargetOptions.h"
84 // All possible address modes, plus some.
85 typedef struct Address {
98 // Innocuous defaults for our address.
104 class ARMFastISel final : public FastISel {
105 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
106 /// make the right decision when generating code for different targets.
107 const ARMSubtarget *Subtarget;
109 const TargetMachine &TM;
110 const TargetInstrInfo &TII;
111 const TargetLowering &TLI;
112 ARMFunctionInfo *AFI;
114 // Convenience variables to avoid some queries.
116 LLVMContext *Context;
119 explicit ARMFastISel(FunctionLoweringInfo &funcInfo,
120 const TargetLibraryInfo *libInfo)
121 : FastISel(funcInfo, libInfo),
123 &static_cast<const ARMSubtarget &>(funcInfo.MF->getSubtarget())),
124 M(const_cast<Module &>(*funcInfo.Fn->getParent())),
125 TM(funcInfo.MF->getTarget()), TII(*Subtarget->getInstrInfo()),
126 TLI(*Subtarget->getTargetLowering()) {
127 AFI = funcInfo.MF->getInfo<ARMFunctionInfo>();
128 isThumb2 = AFI->isThumbFunction();
129 Context = &funcInfo.Fn->getContext();
133 // Code from FastISel.cpp.
135 unsigned fastEmitInst_r(unsigned MachineInstOpcode,
136 const TargetRegisterClass *RC,
137 unsigned Op0, bool Op0IsKill);
138 unsigned fastEmitInst_rr(unsigned MachineInstOpcode,
139 const TargetRegisterClass *RC,
140 unsigned Op0, bool Op0IsKill,
141 unsigned Op1, bool Op1IsKill);
142 unsigned fastEmitInst_ri(unsigned MachineInstOpcode,
143 const TargetRegisterClass *RC,
144 unsigned Op0, bool Op0IsKill,
146 unsigned fastEmitInst_i(unsigned MachineInstOpcode,
147 const TargetRegisterClass *RC,
150 // Backend specific FastISel code.
152 bool fastSelectInstruction(const Instruction *I) override;
153 unsigned fastMaterializeConstant(const Constant *C) override;
154 unsigned fastMaterializeAlloca(const AllocaInst *AI) override;
155 bool tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo,
156 const LoadInst *LI) override;
157 bool fastLowerArguments() override;
159 #include "ARMGenFastISel.inc"
161 // Instruction selection routines.
163 bool SelectLoad(const Instruction *I);
164 bool SelectStore(const Instruction *I);
165 bool SelectBranch(const Instruction *I);
166 bool SelectIndirectBr(const Instruction *I);
167 bool SelectCmp(const Instruction *I);
168 bool SelectFPExt(const Instruction *I);
169 bool SelectFPTrunc(const Instruction *I);
170 bool SelectBinaryIntOp(const Instruction *I, unsigned ISDOpcode);
171 bool SelectBinaryFPOp(const Instruction *I, unsigned ISDOpcode);
172 bool SelectIToFP(const Instruction *I, bool isSigned);
173 bool SelectFPToI(const Instruction *I, bool isSigned);
174 bool SelectDiv(const Instruction *I, bool isSigned);
175 bool SelectRem(const Instruction *I, bool isSigned);
176 bool SelectCall(const Instruction *I, const char *IntrMemName);
177 bool SelectIntrinsicCall(const IntrinsicInst &I);
178 bool SelectSelect(const Instruction *I);
179 bool SelectRet(const Instruction *I);
180 bool SelectTrunc(const Instruction *I);
181 bool SelectIntExt(const Instruction *I);
182 bool SelectShift(const Instruction *I, ARM_AM::ShiftOpc ShiftTy);
186 bool isPositionIndependent() const;
187 bool isTypeLegal(Type *Ty, MVT &VT);
188 bool isLoadTypeLegal(Type *Ty, MVT &VT);
189 bool ARMEmitCmp(const Value *Src1Value, const Value *Src2Value,
190 bool isZExt, bool isEquality);
191 bool ARMEmitLoad(MVT VT, unsigned &ResultReg, Address &Addr,
192 unsigned Alignment = 0, bool isZExt = true,
193 bool allocReg = true);
194 bool ARMEmitStore(MVT VT, unsigned SrcReg, Address &Addr,
195 unsigned Alignment = 0);
196 bool ARMComputeAddress(const Value *Obj, Address &Addr);
197 void ARMSimplifyAddress(Address &Addr, MVT VT, bool useAM3);
198 bool ARMIsMemCpySmall(uint64_t Len);
199 bool ARMTryEmitSmallMemCpy(Address Dest, Address Src, uint64_t Len,
201 unsigned ARMEmitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, bool isZExt);
202 unsigned ARMMaterializeFP(const ConstantFP *CFP, MVT VT);
203 unsigned ARMMaterializeInt(const Constant *C, MVT VT);
204 unsigned ARMMaterializeGV(const GlobalValue *GV, MVT VT);
205 unsigned ARMMoveToFPReg(MVT VT, unsigned SrcReg);
206 unsigned ARMMoveToIntReg(MVT VT, unsigned SrcReg);
207 unsigned ARMSelectCallOp(bool UseReg);
208 unsigned ARMLowerPICELF(const GlobalValue *GV, unsigned Align, MVT VT);
210 const TargetLowering *getTargetLowering() { return &TLI; }
212 // Call handling routines.
214 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC,
217 bool ProcessCallArgs(SmallVectorImpl<Value*> &Args,
218 SmallVectorImpl<unsigned> &ArgRegs,
219 SmallVectorImpl<MVT> &ArgVTs,
220 SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
221 SmallVectorImpl<unsigned> &RegArgs,
225 unsigned getLibcallReg(const Twine &Name);
226 bool FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
227 const Instruction *I, CallingConv::ID CC,
228 unsigned &NumBytes, bool isVarArg);
229 bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call);
231 // OptionalDef handling routines.
233 bool isARMNEONPred(const MachineInstr *MI);
234 bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR);
235 const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB);
236 void AddLoadStoreOperands(MVT VT, Address &Addr,
237 const MachineInstrBuilder &MIB,
238 MachineMemOperand::Flags Flags, bool useAM3);
241 } // end anonymous namespace
243 #include "ARMGenCallingConv.inc"
245 // DefinesOptionalPredicate - This is different from DefinesPredicate in that
246 // we don't care about implicit defs here, just places we'll need to add a
247 // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR.
248 bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) {
249 if (!MI->hasOptionalDef())
252 // Look to see if our OptionalDef is defining CPSR or CCR.
253 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
254 const MachineOperand &MO = MI->getOperand(i);
255 if (!MO.isReg() || !MO.isDef()) continue;
256 if (MO.getReg() == ARM::CPSR)
262 bool ARMFastISel::isARMNEONPred(const MachineInstr *MI) {
263 const MCInstrDesc &MCID = MI->getDesc();
265 // If we're a thumb2 or not NEON function we'll be handled via isPredicable.
266 if ((MCID.TSFlags & ARMII::DomainMask) != ARMII::DomainNEON ||
267 AFI->isThumb2Function())
268 return MI->isPredicable();
270 for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i)
271 if (MCID.OpInfo[i].isPredicate())
277 // If the machine is predicable go ahead and add the predicate operands, if
278 // it needs default CC operands add those.
279 // TODO: If we want to support thumb1 then we'll need to deal with optional
280 // CPSR defs that need to be added before the remaining operands. See s_cc_out
281 // for descriptions why.
282 const MachineInstrBuilder &
283 ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) {
284 MachineInstr *MI = &*MIB;
286 // Do we use a predicate? or...
287 // Are we NEON in ARM mode and have a predicate operand? If so, I know
288 // we're not predicable but add it anyways.
289 if (isARMNEONPred(MI))
290 MIB.add(predOps(ARMCC::AL));
292 // Do we optionally set a predicate? Preds is size > 0 iff the predicate
293 // defines CPSR. All other OptionalDefines in ARM are the CCR register.
295 if (DefinesOptionalPredicate(MI, &CPSR))
296 MIB.add(CPSR ? t1CondCodeOp() : condCodeOp());
300 unsigned ARMFastISel::fastEmitInst_r(unsigned MachineInstOpcode,
301 const TargetRegisterClass *RC,
302 unsigned Op0, bool Op0IsKill) {
303 unsigned ResultReg = createResultReg(RC);
304 const MCInstrDesc &II = TII.get(MachineInstOpcode);
306 // Make sure the input operand is sufficiently constrained to be legal
307 // for this instruction.
308 Op0 = constrainOperandRegClass(II, Op0, 1);
309 if (II.getNumDefs() >= 1) {
310 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II,
311 ResultReg).addReg(Op0, Op0IsKill * RegState::Kill));
313 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
314 .addReg(Op0, Op0IsKill * RegState::Kill));
315 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
316 TII.get(TargetOpcode::COPY), ResultReg)
317 .addReg(II.ImplicitDefs[0]));
322 unsigned ARMFastISel::fastEmitInst_rr(unsigned MachineInstOpcode,
323 const TargetRegisterClass *RC,
324 unsigned Op0, bool Op0IsKill,
325 unsigned Op1, bool Op1IsKill) {
326 unsigned ResultReg = createResultReg(RC);
327 const MCInstrDesc &II = TII.get(MachineInstOpcode);
329 // Make sure the input operands are sufficiently constrained to be legal
330 // for this instruction.
331 Op0 = constrainOperandRegClass(II, Op0, 1);
332 Op1 = constrainOperandRegClass(II, Op1, 2);
334 if (II.getNumDefs() >= 1) {
336 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
337 .addReg(Op0, Op0IsKill * RegState::Kill)
338 .addReg(Op1, Op1IsKill * RegState::Kill));
340 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
341 .addReg(Op0, Op0IsKill * RegState::Kill)
342 .addReg(Op1, Op1IsKill * RegState::Kill));
343 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
344 TII.get(TargetOpcode::COPY), ResultReg)
345 .addReg(II.ImplicitDefs[0]));
350 unsigned ARMFastISel::fastEmitInst_ri(unsigned MachineInstOpcode,
351 const TargetRegisterClass *RC,
352 unsigned Op0, bool Op0IsKill,
354 unsigned ResultReg = createResultReg(RC);
355 const MCInstrDesc &II = TII.get(MachineInstOpcode);
357 // Make sure the input operand is sufficiently constrained to be legal
358 // for this instruction.
359 Op0 = constrainOperandRegClass(II, Op0, 1);
360 if (II.getNumDefs() >= 1) {
362 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
363 .addReg(Op0, Op0IsKill * RegState::Kill)
366 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
367 .addReg(Op0, Op0IsKill * RegState::Kill)
369 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
370 TII.get(TargetOpcode::COPY), ResultReg)
371 .addReg(II.ImplicitDefs[0]));
376 unsigned ARMFastISel::fastEmitInst_i(unsigned MachineInstOpcode,
377 const TargetRegisterClass *RC,
379 unsigned ResultReg = createResultReg(RC);
380 const MCInstrDesc &II = TII.get(MachineInstOpcode);
382 if (II.getNumDefs() >= 1) {
383 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II,
384 ResultReg).addImm(Imm));
386 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
388 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
389 TII.get(TargetOpcode::COPY), ResultReg)
390 .addReg(II.ImplicitDefs[0]));
395 // TODO: Don't worry about 64-bit now, but when this is fixed remove the
396 // checks from the various callers.
397 unsigned ARMFastISel::ARMMoveToFPReg(MVT VT, unsigned SrcReg) {
398 if (VT == MVT::f64) return 0;
400 unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
401 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
402 TII.get(ARM::VMOVSR), MoveReg)
407 unsigned ARMFastISel::ARMMoveToIntReg(MVT VT, unsigned SrcReg) {
408 if (VT == MVT::i64) return 0;
410 unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
411 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
412 TII.get(ARM::VMOVRS), MoveReg)
417 // For double width floating point we need to materialize two constants
418 // (the high and the low) into integer registers then use a move to get
419 // the combined constant into an FP reg.
420 unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, MVT VT) {
421 const APFloat Val = CFP->getValueAPF();
422 bool is64bit = VT == MVT::f64;
424 // This checks to see if we can use VFP3 instructions to materialize
425 // a constant, otherwise we have to go through the constant pool.
426 if (TLI.isFPImmLegal(Val, VT)) {
430 Imm = ARM_AM::getFP64Imm(Val);
433 Imm = ARM_AM::getFP32Imm(Val);
436 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
437 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
438 TII.get(Opc), DestReg).addImm(Imm));
442 // Require VFP2 for loading fp constants.
443 if (!Subtarget->hasVFP2()) return false;
445 // MachineConstantPool wants an explicit alignment.
446 unsigned Align = DL.getPrefTypeAlignment(CFP->getType());
448 // TODO: Figure out if this is correct.
449 Align = DL.getTypeAllocSize(CFP->getType());
451 unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align);
452 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
453 unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS;
455 // The extra reg is for addrmode5.
457 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), DestReg)
458 .addConstantPoolIndex(Idx)
463 unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, MVT VT) {
464 if (VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8 && VT != MVT::i1)
467 // If we can do this in a single instruction without a constant pool entry
469 const ConstantInt *CI = cast<ConstantInt>(C);
470 if (Subtarget->hasV6T2Ops() && isUInt<16>(CI->getZExtValue())) {
471 unsigned Opc = isThumb2 ? ARM::t2MOVi16 : ARM::MOVi16;
472 const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass :
474 unsigned ImmReg = createResultReg(RC);
475 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
476 TII.get(Opc), ImmReg)
477 .addImm(CI->getZExtValue()));
481 // Use MVN to emit negative constants.
482 if (VT == MVT::i32 && Subtarget->hasV6T2Ops() && CI->isNegative()) {
483 unsigned Imm = (unsigned)~(CI->getSExtValue());
484 bool UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) :
485 (ARM_AM::getSOImmVal(Imm) != -1);
487 unsigned Opc = isThumb2 ? ARM::t2MVNi : ARM::MVNi;
488 const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass :
490 unsigned ImmReg = createResultReg(RC);
491 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
492 TII.get(Opc), ImmReg)
498 unsigned ResultReg = 0;
499 if (Subtarget->useMovt(*FuncInfo.MF))
500 ResultReg = fastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
505 // Load from constant pool. For now 32-bit only.
509 // MachineConstantPool wants an explicit alignment.
510 unsigned Align = DL.getPrefTypeAlignment(C->getType());
512 // TODO: Figure out if this is correct.
513 Align = DL.getTypeAllocSize(C->getType());
515 unsigned Idx = MCP.getConstantPoolIndex(C, Align);
516 ResultReg = createResultReg(TLI.getRegClassFor(VT));
518 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
519 TII.get(ARM::t2LDRpci), ResultReg)
520 .addConstantPoolIndex(Idx));
522 // The extra immediate is for addrmode2.
523 ResultReg = constrainOperandRegClass(TII.get(ARM::LDRcp), ResultReg, 0);
524 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
525 TII.get(ARM::LDRcp), ResultReg)
526 .addConstantPoolIndex(Idx)
532 bool ARMFastISel::isPositionIndependent() const {
533 return TLI.isPositionIndependent();
536 unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, MVT VT) {
537 // For now 32-bit only.
538 if (VT != MVT::i32 || GV->isThreadLocal()) return 0;
540 // ROPI/RWPI not currently supported.
541 if (Subtarget->isROPI() || Subtarget->isRWPI())
544 bool IsIndirect = Subtarget->isGVIndirectSymbol(GV);
545 const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass
547 unsigned DestReg = createResultReg(RC);
549 // FastISel TLS support on non-MachO is broken, punt to SelectionDAG.
550 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
551 bool IsThreadLocal = GVar && GVar->isThreadLocal();
552 if (!Subtarget->isTargetMachO() && IsThreadLocal) return 0;
554 bool IsPositionIndependent = isPositionIndependent();
555 // Use movw+movt when possible, it avoids constant pool entries.
556 // Non-darwin targets only support static movt relocations in FastISel.
557 if (Subtarget->useMovt(*FuncInfo.MF) &&
558 (Subtarget->isTargetMachO() || !IsPositionIndependent)) {
560 unsigned char TF = 0;
561 if (Subtarget->isTargetMachO())
562 TF = ARMII::MO_NONLAZY;
564 if (IsPositionIndependent)
565 Opc = isThumb2 ? ARM::t2MOV_ga_pcrel : ARM::MOV_ga_pcrel;
567 Opc = isThumb2 ? ARM::t2MOVi32imm : ARM::MOVi32imm;
568 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
569 TII.get(Opc), DestReg).addGlobalAddress(GV, 0, TF));
571 // MachineConstantPool wants an explicit alignment.
572 unsigned Align = DL.getPrefTypeAlignment(GV->getType());
574 // TODO: Figure out if this is correct.
575 Align = DL.getTypeAllocSize(GV->getType());
578 if (Subtarget->isTargetELF() && IsPositionIndependent)
579 return ARMLowerPICELF(GV, Align, VT);
582 unsigned PCAdj = IsPositionIndependent ? (Subtarget->isThumb() ? 4 : 8) : 0;
583 unsigned Id = AFI->createPICLabelUId();
584 ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create(GV, Id,
587 unsigned Idx = MCP.getConstantPoolIndex(CPV, Align);
590 MachineInstrBuilder MIB;
592 unsigned Opc = IsPositionIndependent ? ARM::t2LDRpci_pic : ARM::t2LDRpci;
593 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc),
594 DestReg).addConstantPoolIndex(Idx);
595 if (IsPositionIndependent)
597 AddOptionalDefs(MIB);
599 // The extra immediate is for addrmode2.
600 DestReg = constrainOperandRegClass(TII.get(ARM::LDRcp), DestReg, 0);
601 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
602 TII.get(ARM::LDRcp), DestReg)
603 .addConstantPoolIndex(Idx)
605 AddOptionalDefs(MIB);
607 if (IsPositionIndependent) {
608 unsigned Opc = IsIndirect ? ARM::PICLDR : ARM::PICADD;
609 unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT));
611 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
612 DbgLoc, TII.get(Opc), NewDestReg)
615 AddOptionalDefs(MIB);
622 MachineInstrBuilder MIB;
623 unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT));
625 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
626 TII.get(ARM::t2LDRi12), NewDestReg)
630 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
631 TII.get(ARM::LDRi12), NewDestReg)
634 DestReg = NewDestReg;
635 AddOptionalDefs(MIB);
641 unsigned ARMFastISel::fastMaterializeConstant(const Constant *C) {
642 EVT CEVT = TLI.getValueType(DL, C->getType(), true);
644 // Only handle simple types.
645 if (!CEVT.isSimple()) return 0;
646 MVT VT = CEVT.getSimpleVT();
648 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
649 return ARMMaterializeFP(CFP, VT);
650 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
651 return ARMMaterializeGV(GV, VT);
652 else if (isa<ConstantInt>(C))
653 return ARMMaterializeInt(C, VT);
658 // TODO: unsigned ARMFastISel::TargetMaterializeFloatZero(const ConstantFP *CF);
660 unsigned ARMFastISel::fastMaterializeAlloca(const AllocaInst *AI) {
661 // Don't handle dynamic allocas.
662 if (!FuncInfo.StaticAllocaMap.count(AI)) return 0;
665 if (!isLoadTypeLegal(AI->getType(), VT)) return 0;
667 DenseMap<const AllocaInst*, int>::iterator SI =
668 FuncInfo.StaticAllocaMap.find(AI);
670 // This will get lowered later into the correct offsets and registers
671 // via rewriteXFrameIndex.
672 if (SI != FuncInfo.StaticAllocaMap.end()) {
673 unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri;
674 const TargetRegisterClass* RC = TLI.getRegClassFor(VT);
675 unsigned ResultReg = createResultReg(RC);
676 ResultReg = constrainOperandRegClass(TII.get(Opc), ResultReg, 0);
678 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
679 TII.get(Opc), ResultReg)
680 .addFrameIndex(SI->second)
688 bool ARMFastISel::isTypeLegal(Type *Ty, MVT &VT) {
689 EVT evt = TLI.getValueType(DL, Ty, true);
691 // Only handle simple types.
692 if (evt == MVT::Other || !evt.isSimple()) return false;
693 VT = evt.getSimpleVT();
695 // Handle all legal types, i.e. a register that will directly hold this
697 return TLI.isTypeLegal(VT);
700 bool ARMFastISel::isLoadTypeLegal(Type *Ty, MVT &VT) {
701 if (isTypeLegal(Ty, VT)) return true;
703 // If this is a type than can be sign or zero-extended to a basic operation
704 // go ahead and accept it now.
705 if (VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16)
711 // Computes the address to get to an object.
712 bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) {
713 // Some boilerplate from the X86 FastISel.
714 const User *U = nullptr;
715 unsigned Opcode = Instruction::UserOp1;
716 if (const Instruction *I = dyn_cast<Instruction>(Obj)) {
717 // Don't walk into other basic blocks unless the object is an alloca from
718 // another block, otherwise it may not have a virtual register assigned.
719 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
720 FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) {
721 Opcode = I->getOpcode();
724 } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
725 Opcode = C->getOpcode();
729 if (PointerType *Ty = dyn_cast<PointerType>(Obj->getType()))
730 if (Ty->getAddressSpace() > 255)
731 // Fast instruction selection doesn't support the special
738 case Instruction::BitCast:
739 // Look through bitcasts.
740 return ARMComputeAddress(U->getOperand(0), Addr);
741 case Instruction::IntToPtr:
742 // Look past no-op inttoptrs.
743 if (TLI.getValueType(DL, U->getOperand(0)->getType()) ==
744 TLI.getPointerTy(DL))
745 return ARMComputeAddress(U->getOperand(0), Addr);
747 case Instruction::PtrToInt:
748 // Look past no-op ptrtoints.
749 if (TLI.getValueType(DL, U->getType()) == TLI.getPointerTy(DL))
750 return ARMComputeAddress(U->getOperand(0), Addr);
752 case Instruction::GetElementPtr: {
753 Address SavedAddr = Addr;
754 int TmpOffset = Addr.Offset;
756 // Iterate through the GEP folding the constants into offsets where
758 gep_type_iterator GTI = gep_type_begin(U);
759 for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end();
760 i != e; ++i, ++GTI) {
761 const Value *Op = *i;
762 if (StructType *STy = GTI.getStructTypeOrNull()) {
763 const StructLayout *SL = DL.getStructLayout(STy);
764 unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
765 TmpOffset += SL->getElementOffset(Idx);
767 uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
769 if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
770 // Constant-offset addressing.
771 TmpOffset += CI->getSExtValue() * S;
774 if (canFoldAddIntoGEP(U, Op)) {
775 // A compatible add with a constant operand. Fold the constant.
777 cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1));
778 TmpOffset += CI->getSExtValue() * S;
779 // Iterate on the other operand.
780 Op = cast<AddOperator>(Op)->getOperand(0);
784 goto unsupported_gep;
789 // Try to grab the base operand now.
790 Addr.Offset = TmpOffset;
791 if (ARMComputeAddress(U->getOperand(0), Addr)) return true;
793 // We failed, restore everything and try the other options.
799 case Instruction::Alloca: {
800 const AllocaInst *AI = cast<AllocaInst>(Obj);
801 DenseMap<const AllocaInst*, int>::iterator SI =
802 FuncInfo.StaticAllocaMap.find(AI);
803 if (SI != FuncInfo.StaticAllocaMap.end()) {
804 Addr.BaseType = Address::FrameIndexBase;
805 Addr.Base.FI = SI->second;
812 // Try to get this in a register if nothing else has worked.
813 if (Addr.Base.Reg == 0) Addr.Base.Reg = getRegForValue(Obj);
814 return Addr.Base.Reg != 0;
817 void ARMFastISel::ARMSimplifyAddress(Address &Addr, MVT VT, bool useAM3) {
818 bool needsLowering = false;
819 switch (VT.SimpleTy) {
820 default: llvm_unreachable("Unhandled load/store type!");
826 // Integer loads/stores handle 12-bit offsets.
827 needsLowering = ((Addr.Offset & 0xfff) != Addr.Offset);
828 // Handle negative offsets.
829 if (needsLowering && isThumb2)
830 needsLowering = !(Subtarget->hasV6T2Ops() && Addr.Offset < 0 &&
833 // ARM halfword load/stores and signed byte loads use +/-imm8 offsets.
834 needsLowering = (Addr.Offset > 255 || Addr.Offset < -255);
839 // Floating point operands handle 8-bit offsets.
840 needsLowering = ((Addr.Offset & 0xff) != Addr.Offset);
844 // If this is a stack pointer and the offset needs to be simplified then
845 // put the alloca address into a register, set the base type back to
846 // register and continue. This should almost never happen.
847 if (needsLowering && Addr.BaseType == Address::FrameIndexBase) {
848 const TargetRegisterClass *RC = isThumb2 ? &ARM::tGPRRegClass
850 unsigned ResultReg = createResultReg(RC);
851 unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri;
852 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
853 TII.get(Opc), ResultReg)
854 .addFrameIndex(Addr.Base.FI)
856 Addr.Base.Reg = ResultReg;
857 Addr.BaseType = Address::RegBase;
860 // Since the offset is too large for the load/store instruction
861 // get the reg+offset into a register.
863 Addr.Base.Reg = fastEmit_ri_(MVT::i32, ISD::ADD, Addr.Base.Reg,
864 /*Op0IsKill*/false, Addr.Offset, MVT::i32);
869 void ARMFastISel::AddLoadStoreOperands(MVT VT, Address &Addr,
870 const MachineInstrBuilder &MIB,
871 MachineMemOperand::Flags Flags,
873 // addrmode5 output depends on the selection dag addressing dividing the
874 // offset by 4 that it then later multiplies. Do this here as well.
875 if (VT.SimpleTy == MVT::f32 || VT.SimpleTy == MVT::f64)
878 // Frame base works a bit differently. Handle it separately.
879 if (Addr.BaseType == Address::FrameIndexBase) {
880 int FI = Addr.Base.FI;
881 int Offset = Addr.Offset;
882 MachineMemOperand *MMO = FuncInfo.MF->getMachineMemOperand(
883 MachinePointerInfo::getFixedStack(*FuncInfo.MF, FI, Offset), Flags,
884 MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
885 // Now add the rest of the operands.
886 MIB.addFrameIndex(FI);
888 // ARM halfword load/stores and signed byte loads need an additional
891 int Imm = (Addr.Offset < 0) ? (0x100 | -Addr.Offset) : Addr.Offset;
895 MIB.addImm(Addr.Offset);
897 MIB.addMemOperand(MMO);
899 // Now add the rest of the operands.
900 MIB.addReg(Addr.Base.Reg);
902 // ARM halfword load/stores and signed byte loads need an additional
905 int Imm = (Addr.Offset < 0) ? (0x100 | -Addr.Offset) : Addr.Offset;
909 MIB.addImm(Addr.Offset);
912 AddOptionalDefs(MIB);
915 bool ARMFastISel::ARMEmitLoad(MVT VT, unsigned &ResultReg, Address &Addr,
916 unsigned Alignment, bool isZExt, bool allocReg) {
919 bool needVMOV = false;
920 const TargetRegisterClass *RC;
921 switch (VT.SimpleTy) {
922 // This is mostly going to be Neon/vector support.
923 default: return false;
927 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
928 Opc = isZExt ? ARM::t2LDRBi8 : ARM::t2LDRSBi8;
930 Opc = isZExt ? ARM::t2LDRBi12 : ARM::t2LDRSBi12;
939 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass;
942 if (Alignment && Alignment < 2 && !Subtarget->allowsUnalignedMem())
946 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
947 Opc = isZExt ? ARM::t2LDRHi8 : ARM::t2LDRSHi8;
949 Opc = isZExt ? ARM::t2LDRHi12 : ARM::t2LDRSHi12;
951 Opc = isZExt ? ARM::LDRH : ARM::LDRSH;
954 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass;
957 if (Alignment && Alignment < 4 && !Subtarget->allowsUnalignedMem())
961 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
968 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass;
971 if (!Subtarget->hasVFP2()) return false;
972 // Unaligned loads need special handling. Floats require word-alignment.
973 if (Alignment && Alignment < 4) {
976 Opc = isThumb2 ? ARM::t2LDRi12 : ARM::LDRi12;
977 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass;
980 RC = TLI.getRegClassFor(VT);
984 if (!Subtarget->hasVFP2()) return false;
985 // FIXME: Unaligned loads need special handling. Doublewords require
987 if (Alignment && Alignment < 4)
991 RC = TLI.getRegClassFor(VT);
994 // Simplify this down to something we can handle.
995 ARMSimplifyAddress(Addr, VT, useAM3);
997 // Create the base instruction, then add the operands.
999 ResultReg = createResultReg(RC);
1000 assert(ResultReg > 255 && "Expected an allocated virtual register.");
1001 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1002 TII.get(Opc), ResultReg);
1003 AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOLoad, useAM3);
1005 // If we had an unaligned load of a float we've converted it to an regular
1006 // load. Now we must move from the GRP to the FP register.
1008 unsigned MoveReg = createResultReg(TLI.getRegClassFor(MVT::f32));
1009 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1010 TII.get(ARM::VMOVSR), MoveReg)
1011 .addReg(ResultReg));
1012 ResultReg = MoveReg;
1017 bool ARMFastISel::SelectLoad(const Instruction *I) {
1018 // Atomic loads need special handling.
1019 if (cast<LoadInst>(I)->isAtomic())
1022 const Value *SV = I->getOperand(0);
1023 if (TLI.supportSwiftError()) {
1024 // Swifterror values can come from either a function parameter with
1025 // swifterror attribute or an alloca with swifterror attribute.
1026 if (const Argument *Arg = dyn_cast<Argument>(SV)) {
1027 if (Arg->hasSwiftErrorAttr())
1031 if (const AllocaInst *Alloca = dyn_cast<AllocaInst>(SV)) {
1032 if (Alloca->isSwiftError())
1037 // Verify we have a legal type before going any further.
1039 if (!isLoadTypeLegal(I->getType(), VT))
1042 // See if we can handle this address.
1044 if (!ARMComputeAddress(I->getOperand(0), Addr)) return false;
1047 if (!ARMEmitLoad(VT, ResultReg, Addr, cast<LoadInst>(I)->getAlignment()))
1049 updateValueMap(I, ResultReg);
1053 bool ARMFastISel::ARMEmitStore(MVT VT, unsigned SrcReg, Address &Addr,
1054 unsigned Alignment) {
1056 bool useAM3 = false;
1057 switch (VT.SimpleTy) {
1058 // This is mostly going to be Neon/vector support.
1059 default: return false;
1061 unsigned Res = createResultReg(isThumb2 ? &ARM::tGPRRegClass
1062 : &ARM::GPRRegClass);
1063 unsigned Opc = isThumb2 ? ARM::t2ANDri : ARM::ANDri;
1064 SrcReg = constrainOperandRegClass(TII.get(Opc), SrcReg, 1);
1065 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1067 .addReg(SrcReg).addImm(1));
1073 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
1074 StrOpc = ARM::t2STRBi8;
1076 StrOpc = ARM::t2STRBi12;
1078 StrOpc = ARM::STRBi12;
1082 if (Alignment && Alignment < 2 && !Subtarget->allowsUnalignedMem())
1086 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
1087 StrOpc = ARM::t2STRHi8;
1089 StrOpc = ARM::t2STRHi12;
1096 if (Alignment && Alignment < 4 && !Subtarget->allowsUnalignedMem())
1100 if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops())
1101 StrOpc = ARM::t2STRi8;
1103 StrOpc = ARM::t2STRi12;
1105 StrOpc = ARM::STRi12;
1109 if (!Subtarget->hasVFP2()) return false;
1110 // Unaligned stores need special handling. Floats require word-alignment.
1111 if (Alignment && Alignment < 4) {
1112 unsigned MoveReg = createResultReg(TLI.getRegClassFor(MVT::i32));
1113 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1114 TII.get(ARM::VMOVRS), MoveReg)
1118 StrOpc = isThumb2 ? ARM::t2STRi12 : ARM::STRi12;
1120 StrOpc = ARM::VSTRS;
1124 if (!Subtarget->hasVFP2()) return false;
1125 // FIXME: Unaligned stores need special handling. Doublewords require
1127 if (Alignment && Alignment < 4)
1130 StrOpc = ARM::VSTRD;
1133 // Simplify this down to something we can handle.
1134 ARMSimplifyAddress(Addr, VT, useAM3);
1136 // Create the base instruction, then add the operands.
1137 SrcReg = constrainOperandRegClass(TII.get(StrOpc), SrcReg, 0);
1138 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1141 AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOStore, useAM3);
1145 bool ARMFastISel::SelectStore(const Instruction *I) {
1146 Value *Op0 = I->getOperand(0);
1147 unsigned SrcReg = 0;
1149 // Atomic stores need special handling.
1150 if (cast<StoreInst>(I)->isAtomic())
1153 const Value *PtrV = I->getOperand(1);
1154 if (TLI.supportSwiftError()) {
1155 // Swifterror values can come from either a function parameter with
1156 // swifterror attribute or an alloca with swifterror attribute.
1157 if (const Argument *Arg = dyn_cast<Argument>(PtrV)) {
1158 if (Arg->hasSwiftErrorAttr())
1162 if (const AllocaInst *Alloca = dyn_cast<AllocaInst>(PtrV)) {
1163 if (Alloca->isSwiftError())
1168 // Verify we have a legal type before going any further.
1170 if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT))
1173 // Get the value to be stored into a register.
1174 SrcReg = getRegForValue(Op0);
1175 if (SrcReg == 0) return false;
1177 // See if we can handle this address.
1179 if (!ARMComputeAddress(I->getOperand(1), Addr))
1182 if (!ARMEmitStore(VT, SrcReg, Addr, cast<StoreInst>(I)->getAlignment()))
1187 static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) {
1189 // Needs two compares...
1190 case CmpInst::FCMP_ONE:
1191 case CmpInst::FCMP_UEQ:
1193 // AL is our "false" for now. The other two need more compares.
1195 case CmpInst::ICMP_EQ:
1196 case CmpInst::FCMP_OEQ:
1198 case CmpInst::ICMP_SGT:
1199 case CmpInst::FCMP_OGT:
1201 case CmpInst::ICMP_SGE:
1202 case CmpInst::FCMP_OGE:
1204 case CmpInst::ICMP_UGT:
1205 case CmpInst::FCMP_UGT:
1207 case CmpInst::FCMP_OLT:
1209 case CmpInst::ICMP_ULE:
1210 case CmpInst::FCMP_OLE:
1212 case CmpInst::FCMP_ORD:
1214 case CmpInst::FCMP_UNO:
1216 case CmpInst::FCMP_UGE:
1218 case CmpInst::ICMP_SLT:
1219 case CmpInst::FCMP_ULT:
1221 case CmpInst::ICMP_SLE:
1222 case CmpInst::FCMP_ULE:
1224 case CmpInst::FCMP_UNE:
1225 case CmpInst::ICMP_NE:
1227 case CmpInst::ICMP_UGE:
1229 case CmpInst::ICMP_ULT:
1234 bool ARMFastISel::SelectBranch(const Instruction *I) {
1235 const BranchInst *BI = cast<BranchInst>(I);
1236 MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)];
1237 MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)];
1239 // Simple branch support.
1241 // If we can, avoid recomputing the compare - redoing it could lead to wonky
1243 if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) {
1244 if (CI->hasOneUse() && (CI->getParent() == I->getParent())) {
1245 // Get the compare predicate.
1246 // Try to take advantage of fallthrough opportunities.
1247 CmpInst::Predicate Predicate = CI->getPredicate();
1248 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1249 std::swap(TBB, FBB);
1250 Predicate = CmpInst::getInversePredicate(Predicate);
1253 ARMCC::CondCodes ARMPred = getComparePred(Predicate);
1255 // We may not handle every CC for now.
1256 if (ARMPred == ARMCC::AL) return false;
1258 // Emit the compare.
1259 if (!ARMEmitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned(),
1263 unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc;
1264 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc))
1265 .addMBB(TBB).addImm(ARMPred).addReg(ARM::CPSR);
1266 finishCondBranch(BI->getParent(), TBB, FBB);
1269 } else if (TruncInst *TI = dyn_cast<TruncInst>(BI->getCondition())) {
1271 if (TI->hasOneUse() && TI->getParent() == I->getParent() &&
1272 (isLoadTypeLegal(TI->getOperand(0)->getType(), SourceVT))) {
1273 unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri;
1274 unsigned OpReg = getRegForValue(TI->getOperand(0));
1275 OpReg = constrainOperandRegClass(TII.get(TstOpc), OpReg, 0);
1276 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1278 .addReg(OpReg).addImm(1));
1280 unsigned CCMode = ARMCC::NE;
1281 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1282 std::swap(TBB, FBB);
1286 unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc;
1287 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc))
1288 .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
1290 finishCondBranch(BI->getParent(), TBB, FBB);
1293 } else if (const ConstantInt *CI =
1294 dyn_cast<ConstantInt>(BI->getCondition())) {
1295 uint64_t Imm = CI->getZExtValue();
1296 MachineBasicBlock *Target = (Imm == 0) ? FBB : TBB;
1297 fastEmitBranch(Target, DbgLoc);
1301 unsigned CmpReg = getRegForValue(BI->getCondition());
1302 if (CmpReg == 0) return false;
1304 // We've been divorced from our compare! Our block was split, and
1305 // now our compare lives in a predecessor block. We musn't
1306 // re-compare here, as the children of the compare aren't guaranteed
1307 // live across the block boundary (we *could* check for this).
1308 // Regardless, the compare has been done in the predecessor block,
1309 // and it left a value for us in a virtual register. Ergo, we test
1310 // the one-bit value left in the virtual register.
1311 unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri;
1312 CmpReg = constrainOperandRegClass(TII.get(TstOpc), CmpReg, 0);
1314 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TstOpc))
1318 unsigned CCMode = ARMCC::NE;
1319 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
1320 std::swap(TBB, FBB);
1324 unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc;
1325 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc))
1326 .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
1327 finishCondBranch(BI->getParent(), TBB, FBB);
1331 bool ARMFastISel::SelectIndirectBr(const Instruction *I) {
1332 unsigned AddrReg = getRegForValue(I->getOperand(0));
1333 if (AddrReg == 0) return false;
1335 unsigned Opc = isThumb2 ? ARM::tBRIND : ARM::BX;
1336 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1337 TII.get(Opc)).addReg(AddrReg));
1339 const IndirectBrInst *IB = cast<IndirectBrInst>(I);
1340 for (const BasicBlock *SuccBB : IB->successors())
1341 FuncInfo.MBB->addSuccessor(FuncInfo.MBBMap[SuccBB]);
1346 bool ARMFastISel::ARMEmitCmp(const Value *Src1Value, const Value *Src2Value,
1347 bool isZExt, bool isEquality) {
1348 Type *Ty = Src1Value->getType();
1349 EVT SrcEVT = TLI.getValueType(DL, Ty, true);
1350 if (!SrcEVT.isSimple()) return false;
1351 MVT SrcVT = SrcEVT.getSimpleVT();
1353 if (Ty->isFloatTy() && !Subtarget->hasVFP2())
1356 if (Ty->isDoubleTy() && (!Subtarget->hasVFP2() || Subtarget->isFPOnlySP()))
1359 // Check to see if the 2nd operand is a constant that we can encode directly
1362 bool UseImm = false;
1363 bool isNegativeImm = false;
1364 // FIXME: At -O0 we don't have anything that canonicalizes operand order.
1365 // Thus, Src1Value may be a ConstantInt, but we're missing it.
1366 if (const ConstantInt *ConstInt = dyn_cast<ConstantInt>(Src2Value)) {
1367 if (SrcVT == MVT::i32 || SrcVT == MVT::i16 || SrcVT == MVT::i8 ||
1369 const APInt &CIVal = ConstInt->getValue();
1370 Imm = (isZExt) ? (int)CIVal.getZExtValue() : (int)CIVal.getSExtValue();
1371 // For INT_MIN/LONG_MIN (i.e., 0x80000000) we need to use a cmp, rather
1372 // then a cmn, because there is no way to represent 2147483648 as a
1373 // signed 32-bit int.
1374 if (Imm < 0 && Imm != (int)0x80000000) {
1375 isNegativeImm = true;
1378 UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) :
1379 (ARM_AM::getSOImmVal(Imm) != -1);
1381 } else if (const ConstantFP *ConstFP = dyn_cast<ConstantFP>(Src2Value)) {
1382 if (SrcVT == MVT::f32 || SrcVT == MVT::f64)
1383 if (ConstFP->isZero() && !ConstFP->isNegative())
1389 bool needsExt = false;
1390 switch (SrcVT.SimpleTy) {
1391 default: return false;
1392 // TODO: Verify compares.
1395 // Equality comparisons shouldn't raise Invalid on uordered inputs.
1397 CmpOpc = UseImm ? ARM::VCMPZS : ARM::VCMPS;
1399 CmpOpc = UseImm ? ARM::VCMPEZS : ARM::VCMPES;
1403 // Equality comparisons shouldn't raise Invalid on uordered inputs.
1405 CmpOpc = UseImm ? ARM::VCMPZD : ARM::VCMPD;
1407 CmpOpc = UseImm ? ARM::VCMPEZD : ARM::VCMPED;
1413 // Intentional fall-through.
1417 CmpOpc = ARM::t2CMPrr;
1419 CmpOpc = isNegativeImm ? ARM::t2CMNri : ARM::t2CMPri;
1422 CmpOpc = ARM::CMPrr;
1424 CmpOpc = isNegativeImm ? ARM::CMNri : ARM::CMPri;
1429 unsigned SrcReg1 = getRegForValue(Src1Value);
1430 if (SrcReg1 == 0) return false;
1432 unsigned SrcReg2 = 0;
1434 SrcReg2 = getRegForValue(Src2Value);
1435 if (SrcReg2 == 0) return false;
1438 // We have i1, i8, or i16, we need to either zero extend or sign extend.
1440 SrcReg1 = ARMEmitIntExt(SrcVT, SrcReg1, MVT::i32, isZExt);
1441 if (SrcReg1 == 0) return false;
1443 SrcReg2 = ARMEmitIntExt(SrcVT, SrcReg2, MVT::i32, isZExt);
1444 if (SrcReg2 == 0) return false;
1448 const MCInstrDesc &II = TII.get(CmpOpc);
1449 SrcReg1 = constrainOperandRegClass(II, SrcReg1, 0);
1451 SrcReg2 = constrainOperandRegClass(II, SrcReg2, 1);
1452 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
1453 .addReg(SrcReg1).addReg(SrcReg2));
1455 MachineInstrBuilder MIB;
1456 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
1459 // Only add immediate for icmp as the immediate for fcmp is an implicit 0.0.
1462 AddOptionalDefs(MIB);
1465 // For floating point we need to move the result to a comparison register
1466 // that we can then use for branches.
1467 if (Ty->isFloatTy() || Ty->isDoubleTy())
1468 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1469 TII.get(ARM::FMSTAT)));
1473 bool ARMFastISel::SelectCmp(const Instruction *I) {
1474 const CmpInst *CI = cast<CmpInst>(I);
1476 // Get the compare predicate.
1477 ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate());
1479 // We may not handle every CC for now.
1480 if (ARMPred == ARMCC::AL) return false;
1482 // Emit the compare.
1483 if (!ARMEmitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned(),
1487 // Now set a register based on the comparison. Explicitly set the predicates
1489 unsigned MovCCOpc = isThumb2 ? ARM::t2MOVCCi : ARM::MOVCCi;
1490 const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass
1491 : &ARM::GPRRegClass;
1492 unsigned DestReg = createResultReg(RC);
1493 Constant *Zero = ConstantInt::get(Type::getInt32Ty(*Context), 0);
1494 unsigned ZeroReg = fastMaterializeConstant(Zero);
1495 // ARMEmitCmp emits a FMSTAT when necessary, so it's always safe to use CPSR.
1496 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc), DestReg)
1497 .addReg(ZeroReg).addImm(1)
1498 .addImm(ARMPred).addReg(ARM::CPSR);
1500 updateValueMap(I, DestReg);
1504 bool ARMFastISel::SelectFPExt(const Instruction *I) {
1505 // Make sure we have VFP and that we're extending float to double.
1506 if (!Subtarget->hasVFP2() || Subtarget->isFPOnlySP()) return false;
1508 Value *V = I->getOperand(0);
1509 if (!I->getType()->isDoubleTy() ||
1510 !V->getType()->isFloatTy()) return false;
1512 unsigned Op = getRegForValue(V);
1513 if (Op == 0) return false;
1515 unsigned Result = createResultReg(&ARM::DPRRegClass);
1516 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1517 TII.get(ARM::VCVTDS), Result)
1519 updateValueMap(I, Result);
1523 bool ARMFastISel::SelectFPTrunc(const Instruction *I) {
1524 // Make sure we have VFP and that we're truncating double to float.
1525 if (!Subtarget->hasVFP2() || Subtarget->isFPOnlySP()) return false;
1527 Value *V = I->getOperand(0);
1528 if (!(I->getType()->isFloatTy() &&
1529 V->getType()->isDoubleTy())) return false;
1531 unsigned Op = getRegForValue(V);
1532 if (Op == 0) return false;
1534 unsigned Result = createResultReg(&ARM::SPRRegClass);
1535 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1536 TII.get(ARM::VCVTSD), Result)
1538 updateValueMap(I, Result);
1542 bool ARMFastISel::SelectIToFP(const Instruction *I, bool isSigned) {
1543 // Make sure we have VFP.
1544 if (!Subtarget->hasVFP2()) return false;
1547 Type *Ty = I->getType();
1548 if (!isTypeLegal(Ty, DstVT))
1551 Value *Src = I->getOperand(0);
1552 EVT SrcEVT = TLI.getValueType(DL, Src->getType(), true);
1553 if (!SrcEVT.isSimple())
1555 MVT SrcVT = SrcEVT.getSimpleVT();
1556 if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8)
1559 unsigned SrcReg = getRegForValue(Src);
1560 if (SrcReg == 0) return false;
1562 // Handle sign-extension.
1563 if (SrcVT == MVT::i16 || SrcVT == MVT::i8) {
1564 SrcReg = ARMEmitIntExt(SrcVT, SrcReg, MVT::i32,
1565 /*isZExt*/!isSigned);
1566 if (SrcReg == 0) return false;
1569 // The conversion routine works on fp-reg to fp-reg and the operand above
1570 // was an integer, move it to the fp registers if possible.
1571 unsigned FP = ARMMoveToFPReg(MVT::f32, SrcReg);
1572 if (FP == 0) return false;
1575 if (Ty->isFloatTy()) Opc = isSigned ? ARM::VSITOS : ARM::VUITOS;
1576 else if (Ty->isDoubleTy() && !Subtarget->isFPOnlySP())
1577 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() && !Subtarget->isFPOnlySP())
1603 Opc = isSigned ? ARM::VTOSIZD : ARM::VTOUIZD;
1606 // f64->s32/u32 or f32->s32/u32 both need an intermediate f32 reg.
1607 unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32));
1608 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1609 TII.get(Opc), ResultReg).addReg(Op));
1611 // This result needs to be in an integer register, but the conversion only
1612 // takes place in fp-regs.
1613 unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg);
1614 if (IntReg == 0) return false;
1616 updateValueMap(I, IntReg);
1620 bool ARMFastISel::SelectSelect(const Instruction *I) {
1622 if (!isTypeLegal(I->getType(), VT))
1625 // Things need to be register sized for register moves.
1626 if (VT != MVT::i32) return false;
1628 unsigned CondReg = getRegForValue(I->getOperand(0));
1629 if (CondReg == 0) return false;
1630 unsigned Op1Reg = getRegForValue(I->getOperand(1));
1631 if (Op1Reg == 0) return false;
1633 // Check to see if we can use an immediate in the conditional move.
1635 bool UseImm = false;
1636 bool isNegativeImm = false;
1637 if (const ConstantInt *ConstInt = dyn_cast<ConstantInt>(I->getOperand(2))) {
1638 assert(VT == MVT::i32 && "Expecting an i32.");
1639 Imm = (int)ConstInt->getValue().getZExtValue();
1641 isNegativeImm = true;
1644 UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) :
1645 (ARM_AM::getSOImmVal(Imm) != -1);
1648 unsigned Op2Reg = 0;
1650 Op2Reg = getRegForValue(I->getOperand(2));
1651 if (Op2Reg == 0) return false;
1654 unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri;
1655 CondReg = constrainOperandRegClass(TII.get(TstOpc), CondReg, 0);
1657 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TstOpc))
1662 const TargetRegisterClass *RC;
1664 RC = isThumb2 ? &ARM::tGPRRegClass : &ARM::GPRRegClass;
1665 MovCCOpc = isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr;
1667 RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRRegClass;
1669 MovCCOpc = isThumb2 ? ARM::t2MOVCCi : ARM::MOVCCi;
1671 MovCCOpc = isThumb2 ? ARM::t2MVNCCi : ARM::MVNCCi;
1673 unsigned ResultReg = createResultReg(RC);
1675 Op2Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op2Reg, 1);
1676 Op1Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op1Reg, 2);
1677 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc),
1684 Op1Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op1Reg, 1);
1685 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc),
1692 updateValueMap(I, ResultReg);
1696 bool ARMFastISel::SelectDiv(const Instruction *I, bool isSigned) {
1698 Type *Ty = I->getType();
1699 if (!isTypeLegal(Ty, VT))
1702 // If we have integer div support we should have selected this automagically.
1703 // In case we have a real miss go ahead and return false and we'll pick
1705 if (Subtarget->hasDivideInThumbMode())
1708 // Otherwise emit a libcall.
1709 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1711 LC = isSigned ? RTLIB::SDIV_I8 : RTLIB::UDIV_I8;
1712 else if (VT == MVT::i16)
1713 LC = isSigned ? RTLIB::SDIV_I16 : RTLIB::UDIV_I16;
1714 else if (VT == MVT::i32)
1715 LC = isSigned ? RTLIB::SDIV_I32 : RTLIB::UDIV_I32;
1716 else if (VT == MVT::i64)
1717 LC = isSigned ? RTLIB::SDIV_I64 : RTLIB::UDIV_I64;
1718 else if (VT == MVT::i128)
1719 LC = isSigned ? RTLIB::SDIV_I128 : RTLIB::UDIV_I128;
1720 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!");
1722 return ARMEmitLibcall(I, LC);
1725 bool ARMFastISel::SelectRem(const Instruction *I, bool isSigned) {
1727 Type *Ty = I->getType();
1728 if (!isTypeLegal(Ty, VT))
1731 // Many ABIs do not provide a libcall for standalone remainder, so we need to
1732 // use divrem (see the RTABI 4.3.1). Since FastISel can't handle non-double
1733 // multi-reg returns, we'll have to bail out.
1734 if (!TLI.hasStandaloneRem(VT)) {
1738 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1740 LC = isSigned ? RTLIB::SREM_I8 : RTLIB::UREM_I8;
1741 else if (VT == MVT::i16)
1742 LC = isSigned ? RTLIB::SREM_I16 : RTLIB::UREM_I16;
1743 else if (VT == MVT::i32)
1744 LC = isSigned ? RTLIB::SREM_I32 : RTLIB::UREM_I32;
1745 else if (VT == MVT::i64)
1746 LC = isSigned ? RTLIB::SREM_I64 : RTLIB::UREM_I64;
1747 else if (VT == MVT::i128)
1748 LC = isSigned ? RTLIB::SREM_I128 : RTLIB::UREM_I128;
1749 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!");
1751 return ARMEmitLibcall(I, LC);
1754 bool ARMFastISel::SelectBinaryIntOp(const Instruction *I, unsigned ISDOpcode) {
1755 EVT DestVT = TLI.getValueType(DL, I->getType(), true);
1757 // We can get here in the case when we have a binary operation on a non-legal
1758 // type and the target independent selector doesn't know how to handle it.
1759 if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1)
1763 switch (ISDOpcode) {
1764 default: return false;
1766 Opc = isThumb2 ? ARM::t2ADDrr : ARM::ADDrr;
1769 Opc = isThumb2 ? ARM::t2ORRrr : ARM::ORRrr;
1772 Opc = isThumb2 ? ARM::t2SUBrr : ARM::SUBrr;
1776 unsigned SrcReg1 = getRegForValue(I->getOperand(0));
1777 if (SrcReg1 == 0) return false;
1779 // TODO: Often the 2nd operand is an immediate, which can be encoded directly
1780 // in the instruction, rather then materializing the value in a register.
1781 unsigned SrcReg2 = getRegForValue(I->getOperand(1));
1782 if (SrcReg2 == 0) return false;
1784 unsigned ResultReg = createResultReg(&ARM::GPRnopcRegClass);
1785 SrcReg1 = constrainOperandRegClass(TII.get(Opc), SrcReg1, 1);
1786 SrcReg2 = constrainOperandRegClass(TII.get(Opc), SrcReg2, 2);
1787 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1788 TII.get(Opc), ResultReg)
1789 .addReg(SrcReg1).addReg(SrcReg2));
1790 updateValueMap(I, ResultReg);
1794 bool ARMFastISel::SelectBinaryFPOp(const Instruction *I, unsigned ISDOpcode) {
1795 EVT FPVT = TLI.getValueType(DL, I->getType(), true);
1796 if (!FPVT.isSimple()) return false;
1797 MVT VT = FPVT.getSimpleVT();
1799 // FIXME: Support vector types where possible.
1803 // We can get here in the case when we want to use NEON for our fp
1804 // operations, but can't figure out how to. Just use the vfp instructions
1806 // FIXME: It'd be nice to use NEON instructions.
1807 Type *Ty = I->getType();
1808 if (Ty->isFloatTy() && !Subtarget->hasVFP2())
1810 if (Ty->isDoubleTy() && (!Subtarget->hasVFP2() || Subtarget->isFPOnlySP()))
1814 bool is64bit = VT == MVT::f64 || VT == MVT::i64;
1815 switch (ISDOpcode) {
1816 default: return false;
1818 Opc = is64bit ? ARM::VADDD : ARM::VADDS;
1821 Opc = is64bit ? ARM::VSUBD : ARM::VSUBS;
1824 Opc = is64bit ? ARM::VMULD : ARM::VMULS;
1827 unsigned Op1 = getRegForValue(I->getOperand(0));
1828 if (Op1 == 0) return false;
1830 unsigned Op2 = getRegForValue(I->getOperand(1));
1831 if (Op2 == 0) return false;
1833 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT.SimpleTy));
1834 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1835 TII.get(Opc), ResultReg)
1836 .addReg(Op1).addReg(Op2));
1837 updateValueMap(I, ResultReg);
1841 // Call Handling Code
1843 // This is largely taken directly from CCAssignFnForNode
1844 // TODO: We may not support all of this.
1845 CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC,
1850 llvm_unreachable("Unsupported calling convention");
1851 case CallingConv::Fast:
1852 if (Subtarget->hasVFP2() && !isVarArg) {
1853 if (!Subtarget->isAAPCS_ABI())
1854 return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS);
1855 // For AAPCS ABI targets, just use VFP variant of the calling convention.
1856 return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP);
1859 case CallingConv::C:
1860 case CallingConv::CXX_FAST_TLS:
1861 // Use target triple & subtarget features to do actual dispatch.
1862 if (Subtarget->isAAPCS_ABI()) {
1863 if (Subtarget->hasVFP2() &&
1864 TM.Options.FloatABIType == FloatABI::Hard && !isVarArg)
1865 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
1867 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
1869 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1871 case CallingConv::ARM_AAPCS_VFP:
1872 case CallingConv::Swift:
1874 return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
1875 // Fall through to soft float variant, variadic functions don't
1876 // use hard floating point ABI.
1878 case CallingConv::ARM_AAPCS:
1879 return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
1880 case CallingConv::ARM_APCS:
1881 return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1882 case CallingConv::GHC:
1884 llvm_unreachable("Can't return in GHC call convention");
1886 return CC_ARM_APCS_GHC;
1890 bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args,
1891 SmallVectorImpl<unsigned> &ArgRegs,
1892 SmallVectorImpl<MVT> &ArgVTs,
1893 SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
1894 SmallVectorImpl<unsigned> &RegArgs,
1898 SmallVector<CCValAssign, 16> ArgLocs;
1899 CCState CCInfo(CC, isVarArg, *FuncInfo.MF, ArgLocs, *Context);
1900 CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags,
1901 CCAssignFnForCall(CC, false, isVarArg));
1903 // Check that we can handle all of the arguments. If we can't, then bail out
1904 // now before we add code to the MBB.
1905 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1906 CCValAssign &VA = ArgLocs[i];
1907 MVT ArgVT = ArgVTs[VA.getValNo()];
1909 // We don't handle NEON/vector parameters yet.
1910 if (ArgVT.isVector() || ArgVT.getSizeInBits() > 64)
1913 // Now copy/store arg to correct locations.
1914 if (VA.isRegLoc() && !VA.needsCustom()) {
1916 } else if (VA.needsCustom()) {
1917 // TODO: We need custom lowering for vector (v2f64) args.
1918 if (VA.getLocVT() != MVT::f64 ||
1919 // TODO: Only handle register args for now.
1920 !VA.isRegLoc() || !ArgLocs[++i].isRegLoc())
1923 switch (ArgVT.SimpleTy) {
1932 if (!Subtarget->hasVFP2())
1936 if (!Subtarget->hasVFP2())
1943 // At the point, we are able to handle the call's arguments in fast isel.
1945 // Get a count of how many bytes are to be pushed on the stack.
1946 NumBytes = CCInfo.getNextStackOffset();
1948 // Issue CALLSEQ_START
1949 unsigned AdjStackDown = TII.getCallFrameSetupOpcode();
1950 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1951 TII.get(AdjStackDown))
1952 .addImm(NumBytes).addImm(0));
1954 // Process the args.
1955 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1956 CCValAssign &VA = ArgLocs[i];
1957 const Value *ArgVal = Args[VA.getValNo()];
1958 unsigned Arg = ArgRegs[VA.getValNo()];
1959 MVT ArgVT = ArgVTs[VA.getValNo()];
1961 assert((!ArgVT.isVector() && ArgVT.getSizeInBits() <= 64) &&
1962 "We don't handle NEON/vector parameters yet.");
1964 // Handle arg promotion, etc.
1965 switch (VA.getLocInfo()) {
1966 case CCValAssign::Full: break;
1967 case CCValAssign::SExt: {
1968 MVT DestVT = VA.getLocVT();
1969 Arg = ARMEmitIntExt(ArgVT, Arg, DestVT, /*isZExt*/false);
1970 assert(Arg != 0 && "Failed to emit a sext");
1974 case CCValAssign::AExt:
1975 // Intentional fall-through. Handle AExt and ZExt.
1976 case CCValAssign::ZExt: {
1977 MVT DestVT = VA.getLocVT();
1978 Arg = ARMEmitIntExt(ArgVT, Arg, DestVT, /*isZExt*/true);
1979 assert(Arg != 0 && "Failed to emit a zext");
1983 case CCValAssign::BCvt: {
1984 unsigned BC = fastEmit_r(ArgVT, VA.getLocVT(), ISD::BITCAST, Arg,
1985 /*TODO: Kill=*/false);
1986 assert(BC != 0 && "Failed to emit a bitcast!");
1988 ArgVT = VA.getLocVT();
1991 default: llvm_unreachable("Unknown arg promotion!");
1994 // Now copy/store arg to correct locations.
1995 if (VA.isRegLoc() && !VA.needsCustom()) {
1996 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1997 TII.get(TargetOpcode::COPY), VA.getLocReg()).addReg(Arg);
1998 RegArgs.push_back(VA.getLocReg());
1999 } else if (VA.needsCustom()) {
2000 // TODO: We need custom lowering for vector (v2f64) args.
2001 assert(VA.getLocVT() == MVT::f64 &&
2002 "Custom lowering for v2f64 args not available");
2004 CCValAssign &NextVA = ArgLocs[++i];
2006 assert(VA.isRegLoc() && NextVA.isRegLoc() &&
2007 "We only handle register args!");
2009 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2010 TII.get(ARM::VMOVRRD), VA.getLocReg())
2011 .addReg(NextVA.getLocReg(), RegState::Define)
2013 RegArgs.push_back(VA.getLocReg());
2014 RegArgs.push_back(NextVA.getLocReg());
2016 assert(VA.isMemLoc());
2017 // Need to store on the stack.
2019 // Don't emit stores for undef values.
2020 if (isa<UndefValue>(ArgVal))
2024 Addr.BaseType = Address::RegBase;
2025 Addr.Base.Reg = ARM::SP;
2026 Addr.Offset = VA.getLocMemOffset();
2028 bool EmitRet = ARMEmitStore(ArgVT, Arg, Addr); (void)EmitRet;
2029 assert(EmitRet && "Could not emit a store for argument!");
2036 bool ARMFastISel::FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
2037 const Instruction *I, CallingConv::ID CC,
2038 unsigned &NumBytes, bool isVarArg) {
2039 // Issue CALLSEQ_END
2040 unsigned AdjStackUp = TII.getCallFrameDestroyOpcode();
2041 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2042 TII.get(AdjStackUp))
2043 .addImm(NumBytes).addImm(0));
2045 // Now the return value.
2046 if (RetVT != MVT::isVoid) {
2047 SmallVector<CCValAssign, 16> RVLocs;
2048 CCState CCInfo(CC, isVarArg, *FuncInfo.MF, RVLocs, *Context);
2049 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, isVarArg));
2051 // Copy all of the result registers out of their specified physreg.
2052 if (RVLocs.size() == 2 && RetVT == MVT::f64) {
2053 // For this move we copy into two registers and then move into the
2054 // double fp reg we want.
2055 MVT DestVT = RVLocs[0].getValVT();
2056 const TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT);
2057 unsigned ResultReg = createResultReg(DstRC);
2058 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2059 TII.get(ARM::VMOVDRR), ResultReg)
2060 .addReg(RVLocs[0].getLocReg())
2061 .addReg(RVLocs[1].getLocReg()));
2063 UsedRegs.push_back(RVLocs[0].getLocReg());
2064 UsedRegs.push_back(RVLocs[1].getLocReg());
2066 // Finally update the result.
2067 updateValueMap(I, ResultReg);
2069 assert(RVLocs.size() == 1 &&"Can't handle non-double multi-reg retvals!");
2070 MVT CopyVT = RVLocs[0].getValVT();
2072 // Special handling for extended integers.
2073 if (RetVT == MVT::i1 || RetVT == MVT::i8 || RetVT == MVT::i16)
2076 const TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT);
2078 unsigned ResultReg = createResultReg(DstRC);
2079 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2080 TII.get(TargetOpcode::COPY),
2081 ResultReg).addReg(RVLocs[0].getLocReg());
2082 UsedRegs.push_back(RVLocs[0].getLocReg());
2084 // Finally update the result.
2085 updateValueMap(I, ResultReg);
2092 bool ARMFastISel::SelectRet(const Instruction *I) {
2093 const ReturnInst *Ret = cast<ReturnInst>(I);
2094 const Function &F = *I->getParent()->getParent();
2096 if (!FuncInfo.CanLowerReturn)
2099 if (TLI.supportSwiftError() &&
2100 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError))
2103 if (TLI.supportSplitCSR(FuncInfo.MF))
2106 // Build a list of return value registers.
2107 SmallVector<unsigned, 4> RetRegs;
2109 CallingConv::ID CC = F.getCallingConv();
2110 if (Ret->getNumOperands() > 0) {
2111 SmallVector<ISD::OutputArg, 4> Outs;
2112 GetReturnInfo(F.getReturnType(), F.getAttributes(), Outs, TLI, DL);
2114 // Analyze operands of the call, assigning locations to each operand.
2115 SmallVector<CCValAssign, 16> ValLocs;
2116 CCState CCInfo(CC, F.isVarArg(), *FuncInfo.MF, ValLocs, I->getContext());
2117 CCInfo.AnalyzeReturn(Outs, CCAssignFnForCall(CC, true /* is Ret */,
2120 const Value *RV = Ret->getOperand(0);
2121 unsigned Reg = getRegForValue(RV);
2125 // Only handle a single return value for now.
2126 if (ValLocs.size() != 1)
2129 CCValAssign &VA = ValLocs[0];
2131 // Don't bother handling odd stuff for now.
2132 if (VA.getLocInfo() != CCValAssign::Full)
2134 // Only handle register returns for now.
2138 unsigned SrcReg = Reg + VA.getValNo();
2139 EVT RVEVT = TLI.getValueType(DL, RV->getType());
2140 if (!RVEVT.isSimple()) return false;
2141 MVT RVVT = RVEVT.getSimpleVT();
2142 MVT DestVT = VA.getValVT();
2143 // Special handling for extended integers.
2144 if (RVVT != DestVT) {
2145 if (RVVT != MVT::i1 && RVVT != MVT::i8 && RVVT != MVT::i16)
2148 assert(DestVT == MVT::i32 && "ARM should always ext to i32");
2150 // Perform extension if flagged as either zext or sext. Otherwise, do
2152 if (Outs[0].Flags.isZExt() || Outs[0].Flags.isSExt()) {
2153 SrcReg = ARMEmitIntExt(RVVT, SrcReg, DestVT, Outs[0].Flags.isZExt());
2154 if (SrcReg == 0) return false;
2159 unsigned DstReg = VA.getLocReg();
2160 const TargetRegisterClass* SrcRC = MRI.getRegClass(SrcReg);
2161 // Avoid a cross-class copy. This is very unlikely.
2162 if (!SrcRC->contains(DstReg))
2164 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2165 TII.get(TargetOpcode::COPY), DstReg).addReg(SrcReg);
2167 // Add register to return instruction.
2168 RetRegs.push_back(VA.getLocReg());
2171 unsigned RetOpc = isThumb2 ? ARM::tBX_RET : ARM::BX_RET;
2172 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2174 AddOptionalDefs(MIB);
2175 for (unsigned i = 0, e = RetRegs.size(); i != e; ++i)
2176 MIB.addReg(RetRegs[i], RegState::Implicit);
2180 unsigned ARMFastISel::ARMSelectCallOp(bool UseReg) {
2182 return isThumb2 ? ARM::tBLXr : ARM::BLX;
2184 return isThumb2 ? ARM::tBL : ARM::BL;
2187 unsigned ARMFastISel::getLibcallReg(const Twine &Name) {
2188 // Manually compute the global's type to avoid building it when unnecessary.
2189 Type *GVTy = Type::getInt32PtrTy(*Context, /*AS=*/0);
2190 EVT LCREVT = TLI.getValueType(DL, GVTy);
2191 if (!LCREVT.isSimple()) return 0;
2193 GlobalValue *GV = new GlobalVariable(M, Type::getInt32Ty(*Context), false,
2194 GlobalValue::ExternalLinkage, nullptr,
2196 assert(GV->getType() == GVTy && "We miscomputed the type for the global!");
2197 return ARMMaterializeGV(GV, LCREVT.getSimpleVT());
2200 // A quick function that will emit a call for a named libcall in F with the
2201 // vector of passed arguments for the Instruction in I. We can assume that we
2202 // can emit a call for any libcall we can produce. This is an abridged version
2203 // of the full call infrastructure since we won't need to worry about things
2204 // like computed function pointers or strange arguments at call sites.
2205 // TODO: Try to unify this and the normal call bits for ARM, then try to unify
2207 bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) {
2208 CallingConv::ID CC = TLI.getLibcallCallingConv(Call);
2210 // Handle *simple* calls for now.
2211 Type *RetTy = I->getType();
2213 if (RetTy->isVoidTy())
2214 RetVT = MVT::isVoid;
2215 else if (!isTypeLegal(RetTy, RetVT))
2218 // Can't handle non-double multi-reg retvals.
2219 if (RetVT != MVT::isVoid && RetVT != MVT::i32) {
2220 SmallVector<CCValAssign, 16> RVLocs;
2221 CCState CCInfo(CC, false, *FuncInfo.MF, RVLocs, *Context);
2222 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, false));
2223 if (RVLocs.size() >= 2 && RetVT != MVT::f64)
2227 // Set up the argument vectors.
2228 SmallVector<Value*, 8> Args;
2229 SmallVector<unsigned, 8> ArgRegs;
2230 SmallVector<MVT, 8> ArgVTs;
2231 SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
2232 Args.reserve(I->getNumOperands());
2233 ArgRegs.reserve(I->getNumOperands());
2234 ArgVTs.reserve(I->getNumOperands());
2235 ArgFlags.reserve(I->getNumOperands());
2236 for (unsigned i = 0; i < I->getNumOperands(); ++i) {
2237 Value *Op = I->getOperand(i);
2238 unsigned Arg = getRegForValue(Op);
2239 if (Arg == 0) return false;
2241 Type *ArgTy = Op->getType();
2243 if (!isTypeLegal(ArgTy, ArgVT)) return false;
2245 ISD::ArgFlagsTy Flags;
2246 unsigned OriginalAlignment = DL.getABITypeAlignment(ArgTy);
2247 Flags.setOrigAlign(OriginalAlignment);
2250 ArgRegs.push_back(Arg);
2251 ArgVTs.push_back(ArgVT);
2252 ArgFlags.push_back(Flags);
2255 // Handle the arguments now that we've gotten them.
2256 SmallVector<unsigned, 4> RegArgs;
2258 if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags,
2259 RegArgs, CC, NumBytes, false))
2262 unsigned CalleeReg = 0;
2263 if (Subtarget->genLongCalls()) {
2264 CalleeReg = getLibcallReg(TLI.getLibcallName(Call));
2265 if (CalleeReg == 0) return false;
2269 unsigned CallOpc = ARMSelectCallOp(Subtarget->genLongCalls());
2270 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
2271 DbgLoc, TII.get(CallOpc));
2272 // BL / BLX don't take a predicate, but tBL / tBLX do.
2274 MIB.add(predOps(ARMCC::AL));
2275 if (Subtarget->genLongCalls())
2276 MIB.addReg(CalleeReg);
2278 MIB.addExternalSymbol(TLI.getLibcallName(Call));
2280 // Add implicit physical register uses to the call.
2281 for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
2282 MIB.addReg(RegArgs[i], RegState::Implicit);
2284 // Add a register mask with the call-preserved registers.
2285 // Proper defs for return values will be added by setPhysRegsDeadExcept().
2286 MIB.addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC));
2288 // Finish off the call including any return values.
2289 SmallVector<unsigned, 4> UsedRegs;
2290 if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes, false)) return false;
2292 // Set all unused physreg defs as dead.
2293 static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
2298 bool ARMFastISel::SelectCall(const Instruction *I,
2299 const char *IntrMemName = nullptr) {
2300 const CallInst *CI = cast<CallInst>(I);
2301 const Value *Callee = CI->getCalledValue();
2303 // Can't handle inline asm.
2304 if (isa<InlineAsm>(Callee)) return false;
2306 // Allow SelectionDAG isel to handle tail calls.
2307 if (CI->isTailCall()) return false;
2309 // Check the calling convention.
2310 ImmutableCallSite CS(CI);
2311 CallingConv::ID CC = CS.getCallingConv();
2313 // TODO: Avoid some calling conventions?
2315 FunctionType *FTy = CS.getFunctionType();
2316 bool isVarArg = FTy->isVarArg();
2318 // Handle *simple* calls for now.
2319 Type *RetTy = I->getType();
2321 if (RetTy->isVoidTy())
2322 RetVT = MVT::isVoid;
2323 else if (!isTypeLegal(RetTy, RetVT) && RetVT != MVT::i16 &&
2324 RetVT != MVT::i8 && RetVT != MVT::i1)
2327 // Can't handle non-double multi-reg retvals.
2328 if (RetVT != MVT::isVoid && RetVT != MVT::i1 && RetVT != MVT::i8 &&
2329 RetVT != MVT::i16 && RetVT != MVT::i32) {
2330 SmallVector<CCValAssign, 16> RVLocs;
2331 CCState CCInfo(CC, isVarArg, *FuncInfo.MF, RVLocs, *Context);
2332 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, isVarArg));
2333 if (RVLocs.size() >= 2 && RetVT != MVT::f64)
2337 // Set up the argument vectors.
2338 SmallVector<Value*, 8> Args;
2339 SmallVector<unsigned, 8> ArgRegs;
2340 SmallVector<MVT, 8> ArgVTs;
2341 SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
2342 unsigned arg_size = CS.arg_size();
2343 Args.reserve(arg_size);
2344 ArgRegs.reserve(arg_size);
2345 ArgVTs.reserve(arg_size);
2346 ArgFlags.reserve(arg_size);
2347 for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
2349 // If we're lowering a memory intrinsic instead of a regular call, skip the
2350 // last two arguments, which shouldn't be passed to the underlying function.
2351 if (IntrMemName && e-i <= 2)
2354 ISD::ArgFlagsTy Flags;
2355 unsigned ArgIdx = i - CS.arg_begin();
2356 if (CS.paramHasAttr(ArgIdx, Attribute::SExt))
2358 if (CS.paramHasAttr(ArgIdx, Attribute::ZExt))
2361 // FIXME: Only handle *easy* calls for now.
2362 if (CS.paramHasAttr(ArgIdx, Attribute::InReg) ||
2363 CS.paramHasAttr(ArgIdx, Attribute::StructRet) ||
2364 CS.paramHasAttr(ArgIdx, Attribute::SwiftSelf) ||
2365 CS.paramHasAttr(ArgIdx, Attribute::SwiftError) ||
2366 CS.paramHasAttr(ArgIdx, Attribute::Nest) ||
2367 CS.paramHasAttr(ArgIdx, Attribute::ByVal))
2370 Type *ArgTy = (*i)->getType();
2372 if (!isTypeLegal(ArgTy, ArgVT) && ArgVT != MVT::i16 && ArgVT != MVT::i8 &&
2376 unsigned Arg = getRegForValue(*i);
2380 unsigned OriginalAlignment = DL.getABITypeAlignment(ArgTy);
2381 Flags.setOrigAlign(OriginalAlignment);
2384 ArgRegs.push_back(Arg);
2385 ArgVTs.push_back(ArgVT);
2386 ArgFlags.push_back(Flags);
2389 // Handle the arguments now that we've gotten them.
2390 SmallVector<unsigned, 4> RegArgs;
2392 if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags,
2393 RegArgs, CC, NumBytes, isVarArg))
2396 bool UseReg = false;
2397 const GlobalValue *GV = dyn_cast<GlobalValue>(Callee);
2398 if (!GV || Subtarget->genLongCalls()) UseReg = true;
2400 unsigned CalleeReg = 0;
2403 CalleeReg = getLibcallReg(IntrMemName);
2405 CalleeReg = getRegForValue(Callee);
2407 if (CalleeReg == 0) return false;
2411 unsigned CallOpc = ARMSelectCallOp(UseReg);
2412 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
2413 DbgLoc, TII.get(CallOpc));
2415 // ARM calls don't take a predicate, but tBL / tBLX do.
2417 MIB.add(predOps(ARMCC::AL));
2419 MIB.addReg(CalleeReg);
2420 else if (!IntrMemName)
2421 MIB.addGlobalAddress(GV, 0, 0);
2423 MIB.addExternalSymbol(IntrMemName, 0);
2425 // Add implicit physical register uses to the call.
2426 for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
2427 MIB.addReg(RegArgs[i], RegState::Implicit);
2429 // Add a register mask with the call-preserved registers.
2430 // Proper defs for return values will be added by setPhysRegsDeadExcept().
2431 MIB.addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC));
2433 // Finish off the call including any return values.
2434 SmallVector<unsigned, 4> UsedRegs;
2435 if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes, isVarArg))
2438 // Set all unused physreg defs as dead.
2439 static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
2444 bool ARMFastISel::ARMIsMemCpySmall(uint64_t Len) {
2448 bool ARMFastISel::ARMTryEmitSmallMemCpy(Address Dest, Address Src,
2449 uint64_t Len, unsigned Alignment) {
2450 // Make sure we don't bloat code by inlining very large memcpy's.
2451 if (!ARMIsMemCpySmall(Len))
2456 if (!Alignment || Alignment >= 4) {
2462 assert(Len == 1 && "Expected a length of 1!");
2466 // Bound based on alignment.
2467 if (Len >= 2 && Alignment == 2)
2476 RV = ARMEmitLoad(VT, ResultReg, Src);
2477 assert(RV && "Should be able to handle this load.");
2478 RV = ARMEmitStore(VT, ResultReg, Dest);
2479 assert(RV && "Should be able to handle this store.");
2482 unsigned Size = VT.getSizeInBits()/8;
2484 Dest.Offset += Size;
2491 bool ARMFastISel::SelectIntrinsicCall(const IntrinsicInst &I) {
2492 // FIXME: Handle more intrinsics.
2493 switch (I.getIntrinsicID()) {
2494 default: return false;
2495 case Intrinsic::frameaddress: {
2496 MachineFrameInfo &MFI = FuncInfo.MF->getFrameInfo();
2497 MFI.setFrameAddressIsTaken(true);
2499 unsigned LdrOpc = isThumb2 ? ARM::t2LDRi12 : ARM::LDRi12;
2500 const TargetRegisterClass *RC = isThumb2 ? &ARM::tGPRRegClass
2501 : &ARM::GPRRegClass;
2503 const ARMBaseRegisterInfo *RegInfo =
2504 static_cast<const ARMBaseRegisterInfo *>(Subtarget->getRegisterInfo());
2505 unsigned FramePtr = RegInfo->getFrameRegister(*(FuncInfo.MF));
2506 unsigned SrcReg = FramePtr;
2508 // Recursively load frame address
2514 unsigned Depth = cast<ConstantInt>(I.getOperand(0))->getZExtValue();
2516 DestReg = createResultReg(RC);
2517 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2518 TII.get(LdrOpc), DestReg)
2519 .addReg(SrcReg).addImm(0));
2522 updateValueMap(&I, SrcReg);
2525 case Intrinsic::memcpy:
2526 case Intrinsic::memmove: {
2527 const MemTransferInst &MTI = cast<MemTransferInst>(I);
2528 // Don't handle volatile.
2529 if (MTI.isVolatile())
2532 // Disable inlining for memmove before calls to ComputeAddress. Otherwise,
2533 // we would emit dead code because we don't currently handle memmoves.
2534 bool isMemCpy = (I.getIntrinsicID() == Intrinsic::memcpy);
2535 if (isa<ConstantInt>(MTI.getLength()) && isMemCpy) {
2536 // Small memcpy's are common enough that we want to do them without a call
2538 uint64_t Len = cast<ConstantInt>(MTI.getLength())->getZExtValue();
2539 if (ARMIsMemCpySmall(Len)) {
2541 if (!ARMComputeAddress(MTI.getRawDest(), Dest) ||
2542 !ARMComputeAddress(MTI.getRawSource(), Src))
2544 unsigned Alignment = MTI.getAlignment();
2545 if (ARMTryEmitSmallMemCpy(Dest, Src, Len, Alignment))
2550 if (!MTI.getLength()->getType()->isIntegerTy(32))
2553 if (MTI.getSourceAddressSpace() > 255 || MTI.getDestAddressSpace() > 255)
2556 const char *IntrMemName = isa<MemCpyInst>(I) ? "memcpy" : "memmove";
2557 return SelectCall(&I, IntrMemName);
2559 case Intrinsic::memset: {
2560 const MemSetInst &MSI = cast<MemSetInst>(I);
2561 // Don't handle volatile.
2562 if (MSI.isVolatile())
2565 if (!MSI.getLength()->getType()->isIntegerTy(32))
2568 if (MSI.getDestAddressSpace() > 255)
2571 return SelectCall(&I, "memset");
2573 case Intrinsic::trap: {
2574 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(
2575 Subtarget->useNaClTrap() ? ARM::TRAPNaCl : ARM::TRAP));
2581 bool ARMFastISel::SelectTrunc(const Instruction *I) {
2582 // The high bits for a type smaller than the register size are assumed to be
2584 Value *Op = I->getOperand(0);
2587 SrcVT = TLI.getValueType(DL, Op->getType(), true);
2588 DestVT = TLI.getValueType(DL, I->getType(), true);
2590 if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8)
2592 if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1)
2595 unsigned SrcReg = getRegForValue(Op);
2596 if (!SrcReg) return false;
2598 // Because the high bits are undefined, a truncate doesn't generate
2600 updateValueMap(I, SrcReg);
2604 unsigned ARMFastISel::ARMEmitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
2606 if (DestVT != MVT::i32 && DestVT != MVT::i16 && DestVT != MVT::i8)
2608 if (SrcVT != MVT::i16 && SrcVT != MVT::i8 && SrcVT != MVT::i1)
2611 // Table of which combinations can be emitted as a single instruction,
2612 // and which will require two.
2613 static const uint8_t isSingleInstrTbl[3][2][2][2] = {
2615 // !hasV6Ops hasV6Ops !hasV6Ops hasV6Ops
2616 // ext: s z s z s z s z
2617 /* 1 */ { { { 0, 1 }, { 0, 1 } }, { { 0, 0 }, { 0, 1 } } },
2618 /* 8 */ { { { 0, 1 }, { 1, 1 } }, { { 0, 0 }, { 1, 1 } } },
2619 /* 16 */ { { { 0, 0 }, { 1, 1 } }, { { 0, 0 }, { 1, 1 } } }
2622 // Target registers for:
2623 // - For ARM can never be PC.
2624 // - For 16-bit Thumb are restricted to lower 8 registers.
2625 // - For 32-bit Thumb are restricted to non-SP and non-PC.
2626 static const TargetRegisterClass *RCTbl[2][2] = {
2627 // Instructions: Two Single
2628 /* ARM */ { &ARM::GPRnopcRegClass, &ARM::GPRnopcRegClass },
2629 /* Thumb */ { &ARM::tGPRRegClass, &ARM::rGPRRegClass }
2632 // Table governing the instruction(s) to be emitted.
2633 static const struct InstructionTable {
2635 uint32_t hasS : 1; // Some instructions have an S bit, always set it to 0.
2636 uint32_t Shift : 7; // For shift operand addressing mode, used by MOVsi.
2637 uint32_t Imm : 8; // All instructions have either a shift or a mask.
2638 } IT[2][2][3][2] = {
2639 { // Two instructions (first is left shift, second is in this table).
2640 { // ARM Opc S Shift Imm
2641 /* 1 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 31 },
2642 /* 1 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 31 } },
2643 /* 8 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 24 },
2644 /* 8 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 24 } },
2645 /* 16 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 16 },
2646 /* 16 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 16 } }
2648 { // Thumb Opc S Shift Imm
2649 /* 1 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 31 },
2650 /* 1 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 31 } },
2651 /* 8 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 24 },
2652 /* 8 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 24 } },
2653 /* 16 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 16 },
2654 /* 16 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 16 } }
2657 { // Single instruction.
2658 { // ARM Opc S Shift Imm
2659 /* 1 bit sext */ { { ARM::KILL , 0, ARM_AM::no_shift, 0 },
2660 /* 1 bit zext */ { ARM::ANDri , 1, ARM_AM::no_shift, 1 } },
2661 /* 8 bit sext */ { { ARM::SXTB , 0, ARM_AM::no_shift, 0 },
2662 /* 8 bit zext */ { ARM::ANDri , 1, ARM_AM::no_shift, 255 } },
2663 /* 16 bit sext */ { { ARM::SXTH , 0, ARM_AM::no_shift, 0 },
2664 /* 16 bit zext */ { ARM::UXTH , 0, ARM_AM::no_shift, 0 } }
2666 { // Thumb Opc S Shift Imm
2667 /* 1 bit sext */ { { ARM::KILL , 0, ARM_AM::no_shift, 0 },
2668 /* 1 bit zext */ { ARM::t2ANDri, 1, ARM_AM::no_shift, 1 } },
2669 /* 8 bit sext */ { { ARM::t2SXTB , 0, ARM_AM::no_shift, 0 },
2670 /* 8 bit zext */ { ARM::t2ANDri, 1, ARM_AM::no_shift, 255 } },
2671 /* 16 bit sext */ { { ARM::t2SXTH , 0, ARM_AM::no_shift, 0 },
2672 /* 16 bit zext */ { ARM::t2UXTH , 0, ARM_AM::no_shift, 0 } }
2677 unsigned SrcBits = SrcVT.getSizeInBits();
2678 unsigned DestBits = DestVT.getSizeInBits();
2680 assert((SrcBits < DestBits) && "can only extend to larger types");
2681 assert((DestBits == 32 || DestBits == 16 || DestBits == 8) &&
2682 "other sizes unimplemented");
2683 assert((SrcBits == 16 || SrcBits == 8 || SrcBits == 1) &&
2684 "other sizes unimplemented");
2686 bool hasV6Ops = Subtarget->hasV6Ops();
2687 unsigned Bitness = SrcBits / 8; // {1,8,16}=>{0,1,2}
2688 assert((Bitness < 3) && "sanity-check table bounds");
2690 bool isSingleInstr = isSingleInstrTbl[Bitness][isThumb2][hasV6Ops][isZExt];
2691 const TargetRegisterClass *RC = RCTbl[isThumb2][isSingleInstr];
2692 const InstructionTable *ITP = &IT[isSingleInstr][isThumb2][Bitness][isZExt];
2693 unsigned Opc = ITP->Opc;
2694 assert(ARM::KILL != Opc && "Invalid table entry");
2695 unsigned hasS = ITP->hasS;
2696 ARM_AM::ShiftOpc Shift = (ARM_AM::ShiftOpc) ITP->Shift;
2697 assert(((Shift == ARM_AM::no_shift) == (Opc != ARM::MOVsi)) &&
2698 "only MOVsi has shift operand addressing mode");
2699 unsigned Imm = ITP->Imm;
2701 // 16-bit Thumb instructions always set CPSR (unless they're in an IT block).
2702 bool setsCPSR = &ARM::tGPRRegClass == RC;
2703 unsigned LSLOpc = isThumb2 ? ARM::tLSLri : ARM::MOVsi;
2705 // MOVsi encodes shift and immediate in shift operand addressing mode.
2706 // The following condition has the same value when emitting two
2707 // instruction sequences: both are shifts.
2708 bool ImmIsSO = (Shift != ARM_AM::no_shift);
2710 // Either one or two instructions are emitted.
2711 // They're always of the form:
2713 // CPSR is set only by 16-bit Thumb instructions.
2714 // Predicate, if any, is AL.
2715 // S bit, if available, is always 0.
2716 // When two are emitted the first's result will feed as the second's input,
2717 // that value is then dead.
2718 unsigned NumInstrsEmitted = isSingleInstr ? 1 : 2;
2719 for (unsigned Instr = 0; Instr != NumInstrsEmitted; ++Instr) {
2720 ResultReg = createResultReg(RC);
2721 bool isLsl = (0 == Instr) && !isSingleInstr;
2722 unsigned Opcode = isLsl ? LSLOpc : Opc;
2723 ARM_AM::ShiftOpc ShiftAM = isLsl ? ARM_AM::lsl : Shift;
2724 unsigned ImmEnc = ImmIsSO ? ARM_AM::getSORegOpc(ShiftAM, Imm) : Imm;
2725 bool isKill = 1 == Instr;
2726 MachineInstrBuilder MIB = BuildMI(
2727 *FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opcode), ResultReg);
2729 MIB.addReg(ARM::CPSR, RegState::Define);
2730 SrcReg = constrainOperandRegClass(TII.get(Opcode), SrcReg, 1 + setsCPSR);
2731 MIB.addReg(SrcReg, isKill * RegState::Kill)
2733 .add(predOps(ARMCC::AL));
2735 MIB.add(condCodeOp());
2736 // Second instruction consumes the first's result.
2743 bool ARMFastISel::SelectIntExt(const Instruction *I) {
2744 // On ARM, in general, integer casts don't involve legal types; this code
2745 // handles promotable integers.
2746 Type *DestTy = I->getType();
2747 Value *Src = I->getOperand(0);
2748 Type *SrcTy = Src->getType();
2750 bool isZExt = isa<ZExtInst>(I);
2751 unsigned SrcReg = getRegForValue(Src);
2752 if (!SrcReg) return false;
2754 EVT SrcEVT, DestEVT;
2755 SrcEVT = TLI.getValueType(DL, SrcTy, true);
2756 DestEVT = TLI.getValueType(DL, DestTy, true);
2757 if (!SrcEVT.isSimple()) return false;
2758 if (!DestEVT.isSimple()) return false;
2760 MVT SrcVT = SrcEVT.getSimpleVT();
2761 MVT DestVT = DestEVT.getSimpleVT();
2762 unsigned ResultReg = ARMEmitIntExt(SrcVT, SrcReg, DestVT, isZExt);
2763 if (ResultReg == 0) return false;
2764 updateValueMap(I, ResultReg);
2768 bool ARMFastISel::SelectShift(const Instruction *I,
2769 ARM_AM::ShiftOpc ShiftTy) {
2770 // We handle thumb2 mode by target independent selector
2771 // or SelectionDAG ISel.
2775 // Only handle i32 now.
2776 EVT DestVT = TLI.getValueType(DL, I->getType(), true);
2777 if (DestVT != MVT::i32)
2780 unsigned Opc = ARM::MOVsr;
2782 Value *Src2Value = I->getOperand(1);
2783 if (const ConstantInt *CI = dyn_cast<ConstantInt>(Src2Value)) {
2784 ShiftImm = CI->getZExtValue();
2786 // Fall back to selection DAG isel if the shift amount
2787 // is zero or greater than the width of the value type.
2788 if (ShiftImm == 0 || ShiftImm >=32)
2794 Value *Src1Value = I->getOperand(0);
2795 unsigned Reg1 = getRegForValue(Src1Value);
2796 if (Reg1 == 0) return false;
2799 if (Opc == ARM::MOVsr) {
2800 Reg2 = getRegForValue(Src2Value);
2801 if (Reg2 == 0) return false;
2804 unsigned ResultReg = createResultReg(&ARM::GPRnopcRegClass);
2805 if(ResultReg == 0) return false;
2807 MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2808 TII.get(Opc), ResultReg)
2811 if (Opc == ARM::MOVsi)
2812 MIB.addImm(ARM_AM::getSORegOpc(ShiftTy, ShiftImm));
2813 else if (Opc == ARM::MOVsr) {
2815 MIB.addImm(ARM_AM::getSORegOpc(ShiftTy, 0));
2818 AddOptionalDefs(MIB);
2819 updateValueMap(I, ResultReg);
2823 // TODO: SoftFP support.
2824 bool ARMFastISel::fastSelectInstruction(const Instruction *I) {
2825 switch (I->getOpcode()) {
2826 case Instruction::Load:
2827 return SelectLoad(I);
2828 case Instruction::Store:
2829 return SelectStore(I);
2830 case Instruction::Br:
2831 return SelectBranch(I);
2832 case Instruction::IndirectBr:
2833 return SelectIndirectBr(I);
2834 case Instruction::ICmp:
2835 case Instruction::FCmp:
2836 return SelectCmp(I);
2837 case Instruction::FPExt:
2838 return SelectFPExt(I);
2839 case Instruction::FPTrunc:
2840 return SelectFPTrunc(I);
2841 case Instruction::SIToFP:
2842 return SelectIToFP(I, /*isSigned*/ true);
2843 case Instruction::UIToFP:
2844 return SelectIToFP(I, /*isSigned*/ false);
2845 case Instruction::FPToSI:
2846 return SelectFPToI(I, /*isSigned*/ true);
2847 case Instruction::FPToUI:
2848 return SelectFPToI(I, /*isSigned*/ false);
2849 case Instruction::Add:
2850 return SelectBinaryIntOp(I, ISD::ADD);
2851 case Instruction::Or:
2852 return SelectBinaryIntOp(I, ISD::OR);
2853 case Instruction::Sub:
2854 return SelectBinaryIntOp(I, ISD::SUB);
2855 case Instruction::FAdd:
2856 return SelectBinaryFPOp(I, ISD::FADD);
2857 case Instruction::FSub:
2858 return SelectBinaryFPOp(I, ISD::FSUB);
2859 case Instruction::FMul:
2860 return SelectBinaryFPOp(I, ISD::FMUL);
2861 case Instruction::SDiv:
2862 return SelectDiv(I, /*isSigned*/ true);
2863 case Instruction::UDiv:
2864 return SelectDiv(I, /*isSigned*/ false);
2865 case Instruction::SRem:
2866 return SelectRem(I, /*isSigned*/ true);
2867 case Instruction::URem:
2868 return SelectRem(I, /*isSigned*/ false);
2869 case Instruction::Call:
2870 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I))
2871 return SelectIntrinsicCall(*II);
2872 return SelectCall(I);
2873 case Instruction::Select:
2874 return SelectSelect(I);
2875 case Instruction::Ret:
2876 return SelectRet(I);
2877 case Instruction::Trunc:
2878 return SelectTrunc(I);
2879 case Instruction::ZExt:
2880 case Instruction::SExt:
2881 return SelectIntExt(I);
2882 case Instruction::Shl:
2883 return SelectShift(I, ARM_AM::lsl);
2884 case Instruction::LShr:
2885 return SelectShift(I, ARM_AM::lsr);
2886 case Instruction::AShr:
2887 return SelectShift(I, ARM_AM::asr);
2895 // This table describes sign- and zero-extend instructions which can be
2896 // folded into a preceding load. All of these extends have an immediate
2897 // (sometimes a mask and sometimes a shift) that's applied after
2899 const struct FoldableLoadExtendsStruct {
2900 uint16_t Opc[2]; // ARM, Thumb.
2901 uint8_t ExpectedImm;
2903 uint8_t ExpectedVT : 7;
2904 } FoldableLoadExtends[] = {
2905 { { ARM::SXTH, ARM::t2SXTH }, 0, 0, MVT::i16 },
2906 { { ARM::UXTH, ARM::t2UXTH }, 0, 1, MVT::i16 },
2907 { { ARM::ANDri, ARM::t2ANDri }, 255, 1, MVT::i8 },
2908 { { ARM::SXTB, ARM::t2SXTB }, 0, 0, MVT::i8 },
2909 { { ARM::UXTB, ARM::t2UXTB }, 0, 1, MVT::i8 }
2912 } // end anonymous namespace
2914 /// \brief The specified machine instr operand is a vreg, and that
2915 /// vreg is being provided by the specified load instruction. If possible,
2916 /// try to fold the load as an operand to the instruction, returning true if
2918 bool ARMFastISel::tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo,
2919 const LoadInst *LI) {
2920 // Verify we have a legal type before going any further.
2922 if (!isLoadTypeLegal(LI->getType(), VT))
2925 // Combine load followed by zero- or sign-extend.
2926 // ldrb r1, [r0] ldrb r1, [r0]
2928 // mov r3, r2 mov r3, r1
2929 if (MI->getNumOperands() < 3 || !MI->getOperand(2).isImm())
2931 const uint64_t Imm = MI->getOperand(2).getImm();
2935 for (unsigned i = 0, e = array_lengthof(FoldableLoadExtends);
2937 if (FoldableLoadExtends[i].Opc[isThumb2] == MI->getOpcode() &&
2938 (uint64_t)FoldableLoadExtends[i].ExpectedImm == Imm &&
2939 MVT((MVT::SimpleValueType)FoldableLoadExtends[i].ExpectedVT) == VT) {
2941 isZExt = FoldableLoadExtends[i].isZExt;
2944 if (!Found) return false;
2946 // See if we can handle this address.
2948 if (!ARMComputeAddress(LI->getOperand(0), Addr)) return false;
2950 unsigned ResultReg = MI->getOperand(0).getReg();
2951 if (!ARMEmitLoad(VT, ResultReg, Addr, LI->getAlignment(), isZExt, false))
2953 MI->eraseFromParent();
2957 unsigned ARMFastISel::ARMLowerPICELF(const GlobalValue *GV,
2958 unsigned Align, MVT VT) {
2959 bool UseGOT_PREL = !TM.shouldAssumeDSOLocal(*GV->getParent(), GV);
2961 LLVMContext *Context = &MF->getFunction()->getContext();
2962 unsigned ARMPCLabelIndex = AFI->createPICLabelUId();
2963 unsigned PCAdj = Subtarget->isThumb() ? 4 : 8;
2964 ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create(
2965 GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj,
2966 UseGOT_PREL ? ARMCP::GOT_PREL : ARMCP::no_modifier,
2967 /*AddCurrentAddress=*/UseGOT_PREL);
2969 unsigned ConstAlign =
2970 MF->getDataLayout().getPrefTypeAlignment(Type::getInt32PtrTy(*Context));
2971 unsigned Idx = MF->getConstantPool()->getConstantPoolIndex(CPV, ConstAlign);
2973 unsigned TempReg = MF->getRegInfo().createVirtualRegister(&ARM::rGPRRegClass);
2974 unsigned Opc = isThumb2 ? ARM::t2LDRpci : ARM::LDRcp;
2975 MachineInstrBuilder MIB =
2976 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), TempReg)
2977 .addConstantPoolIndex(Idx);
2978 if (Opc == ARM::LDRcp)
2980 MIB.add(predOps(ARMCC::AL));
2982 // Fix the address by adding pc.
2983 unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
2984 Opc = Subtarget->isThumb() ? ARM::tPICADD : UseGOT_PREL ? ARM::PICLDR
2986 DestReg = constrainOperandRegClass(TII.get(Opc), DestReg, 0);
2987 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), DestReg)
2989 .addImm(ARMPCLabelIndex);
2990 if (!Subtarget->isThumb())
2991 MIB.add(predOps(ARMCC::AL));
2993 if (UseGOT_PREL && Subtarget->isThumb()) {
2994 unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT));
2995 MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2996 TII.get(ARM::t2LDRi12), NewDestReg)
2999 DestReg = NewDestReg;
3000 AddOptionalDefs(MIB);
3005 bool ARMFastISel::fastLowerArguments() {
3006 if (!FuncInfo.CanLowerReturn)
3009 const Function *F = FuncInfo.Fn;
3013 CallingConv::ID CC = F->getCallingConv();
3017 case CallingConv::Fast:
3018 case CallingConv::C:
3019 case CallingConv::ARM_AAPCS_VFP:
3020 case CallingConv::ARM_AAPCS:
3021 case CallingConv::ARM_APCS:
3022 case CallingConv::Swift:
3026 // Only handle simple cases. i.e. Up to 4 i8/i16/i32 scalar arguments
3027 // which are passed in r0 - r3.
3028 for (const Argument &Arg : F->args()) {
3029 if (Arg.getArgNo() >= 4)
3032 if (Arg.hasAttribute(Attribute::InReg) ||
3033 Arg.hasAttribute(Attribute::StructRet) ||
3034 Arg.hasAttribute(Attribute::SwiftSelf) ||
3035 Arg.hasAttribute(Attribute::SwiftError) ||
3036 Arg.hasAttribute(Attribute::ByVal))
3039 Type *ArgTy = Arg.getType();
3040 if (ArgTy->isStructTy() || ArgTy->isArrayTy() || ArgTy->isVectorTy())
3043 EVT ArgVT = TLI.getValueType(DL, ArgTy);
3044 if (!ArgVT.isSimple()) return false;
3045 switch (ArgVT.getSimpleVT().SimpleTy) {
3055 static const MCPhysReg GPRArgRegs[] = {
3056 ARM::R0, ARM::R1, ARM::R2, ARM::R3
3059 const TargetRegisterClass *RC = &ARM::rGPRRegClass;
3060 for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
3062 unsigned ArgNo = I->getArgNo();
3063 unsigned SrcReg = GPRArgRegs[ArgNo];
3064 unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC);
3065 // FIXME: Unfortunately it's necessary to emit a copy from the livein copy.
3066 // Without this, EmitLiveInCopies may eliminate the livein if its only
3067 // use is a bitcast (which isn't turned into an instruction).
3068 unsigned ResultReg = createResultReg(RC);
3069 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3070 TII.get(TargetOpcode::COPY),
3071 ResultReg).addReg(DstReg, getKillRegState(true));
3072 updateValueMap(&*I, ResultReg);
3080 FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo,
3081 const TargetLibraryInfo *libInfo) {
3082 if (funcInfo.MF->getSubtarget<ARMSubtarget>().useFastISel())
3083 return new ARMFastISel(funcInfo, libInfo);
3088 } // end namespace llvm