Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1 | //===-- ARMFastISel.cpp - ARM FastISel implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ARM-specific support for the FastISel class. Some |
| 11 | // of the target-specific code is generated by tablegen in the file |
| 12 | // ARMGenFastISel.inc, which is #included here. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "ARM.h" |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 17 | #include "ARMBaseInstrInfo.h" |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 18 | #include "ARMCallingConv.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 19 | #include "ARMRegisterInfo.h" |
| 20 | #include "ARMTargetMachine.h" |
| 21 | #include "ARMSubtarget.h" |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 22 | #include "ARMConstantPoolValue.h" |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 23 | #include "MCTargetDesc/ARMAddressingModes.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 24 | #include "llvm/CallingConv.h" |
| 25 | #include "llvm/DerivedTypes.h" |
| 26 | #include "llvm/GlobalVariable.h" |
| 27 | #include "llvm/Instructions.h" |
| 28 | #include "llvm/IntrinsicInst.h" |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 29 | #include "llvm/Module.h" |
Jay Foad | 562b84b | 2011-04-11 09:35:34 +0000 | [diff] [blame] | 30 | #include "llvm/Operator.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/Analysis.h" |
| 32 | #include "llvm/CodeGen/FastISel.h" |
| 33 | #include "llvm/CodeGen/FunctionLoweringInfo.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 35 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 37 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Eric Christopher | d56d61a | 2010-10-17 01:51:42 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/MachineMemOperand.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 39 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 40 | #include "llvm/Support/CallSite.h" |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 41 | #include "llvm/Support/CommandLine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 42 | #include "llvm/Support/ErrorHandling.h" |
| 43 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 44 | #include "llvm/Target/TargetData.h" |
| 45 | #include "llvm/Target/TargetInstrInfo.h" |
| 46 | #include "llvm/Target/TargetLowering.h" |
| 47 | #include "llvm/Target/TargetMachine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 48 | #include "llvm/Target/TargetOptions.h" |
| 49 | using namespace llvm; |
| 50 | |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 51 | static cl::opt<bool> |
Eric Christopher | 6e5367d | 2010-10-18 22:53:53 +0000 | [diff] [blame] | 52 | DisableARMFastISel("disable-arm-fast-isel", |
| 53 | cl::desc("Turn off experimental ARM fast-isel support"), |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 54 | cl::init(false), cl::Hidden); |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 55 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 56 | extern cl::opt<bool> EnableARMLongCalls; |
| 57 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 58 | namespace { |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 59 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 60 | // All possible address modes, plus some. |
| 61 | typedef struct Address { |
| 62 | enum { |
| 63 | RegBase, |
| 64 | FrameIndexBase |
| 65 | } BaseType; |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 66 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 67 | union { |
| 68 | unsigned Reg; |
| 69 | int FI; |
| 70 | } Base; |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 71 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 72 | int Offset; |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 73 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 74 | // Innocuous defaults for our address. |
| 75 | Address() |
Jim Grosbach | 0c72076 | 2011-05-16 22:24:07 +0000 | [diff] [blame] | 76 | : BaseType(RegBase), Offset(0) { |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 77 | Base.Reg = 0; |
| 78 | } |
| 79 | } Address; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 80 | |
| 81 | class ARMFastISel : public FastISel { |
| 82 | |
| 83 | /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can |
| 84 | /// make the right decision when generating code for different targets. |
| 85 | const ARMSubtarget *Subtarget; |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 86 | const TargetMachine &TM; |
| 87 | const TargetInstrInfo &TII; |
| 88 | const TargetLowering &TLI; |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 89 | ARMFunctionInfo *AFI; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 90 | |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 91 | // Convenience variables to avoid some queries. |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 92 | bool isThumb2; |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 93 | LLVMContext *Context; |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 94 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 95 | public: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 96 | explicit ARMFastISel(FunctionLoweringInfo &funcInfo) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 97 | : FastISel(funcInfo), |
| 98 | TM(funcInfo.MF->getTarget()), |
| 99 | TII(*TM.getInstrInfo()), |
| 100 | TLI(*TM.getTargetLowering()) { |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 101 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 102 | AFI = funcInfo.MF->getInfo<ARMFunctionInfo>(); |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 103 | isThumb2 = AFI->isThumbFunction(); |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 104 | Context = &funcInfo.Fn->getContext(); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 107 | // Code from FastISel.cpp. |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 108 | virtual unsigned FastEmitInst_(unsigned MachineInstOpcode, |
| 109 | const TargetRegisterClass *RC); |
| 110 | virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode, |
| 111 | const TargetRegisterClass *RC, |
| 112 | unsigned Op0, bool Op0IsKill); |
| 113 | virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode, |
| 114 | const TargetRegisterClass *RC, |
| 115 | unsigned Op0, bool Op0IsKill, |
| 116 | unsigned Op1, bool Op1IsKill); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 117 | virtual unsigned FastEmitInst_rrr(unsigned MachineInstOpcode, |
| 118 | const TargetRegisterClass *RC, |
| 119 | unsigned Op0, bool Op0IsKill, |
| 120 | unsigned Op1, bool Op1IsKill, |
| 121 | unsigned Op2, bool Op2IsKill); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 122 | virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode, |
| 123 | const TargetRegisterClass *RC, |
| 124 | unsigned Op0, bool Op0IsKill, |
| 125 | uint64_t Imm); |
| 126 | virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode, |
| 127 | const TargetRegisterClass *RC, |
| 128 | unsigned Op0, bool Op0IsKill, |
| 129 | const ConstantFP *FPImm); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 130 | virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode, |
| 131 | const TargetRegisterClass *RC, |
| 132 | unsigned Op0, bool Op0IsKill, |
| 133 | unsigned Op1, bool Op1IsKill, |
| 134 | uint64_t Imm); |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 135 | virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode, |
| 136 | const TargetRegisterClass *RC, |
| 137 | uint64_t Imm); |
Eric Christopher | d94bc54 | 2011-04-29 22:07:50 +0000 | [diff] [blame] | 138 | virtual unsigned FastEmitInst_ii(unsigned MachineInstOpcode, |
| 139 | const TargetRegisterClass *RC, |
| 140 | uint64_t Imm1, uint64_t Imm2); |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 141 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 142 | virtual unsigned FastEmitInst_extractsubreg(MVT RetVT, |
| 143 | unsigned Op0, bool Op0IsKill, |
| 144 | uint32_t Idx); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 145 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 146 | // Backend specific FastISel code. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 147 | virtual bool TargetSelectInstruction(const Instruction *I); |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 148 | virtual unsigned TargetMaterializeConstant(const Constant *C); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 149 | virtual unsigned TargetMaterializeAlloca(const AllocaInst *AI); |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 150 | virtual bool TryToFoldLoad(MachineInstr *MI, unsigned OpNo, |
| 151 | const LoadInst *LI); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 152 | |
| 153 | #include "ARMGenFastISel.inc" |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 154 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 155 | // Instruction selection routines. |
Eric Christopher | 44bff90 | 2010-09-10 23:10:30 +0000 | [diff] [blame] | 156 | private: |
Eric Christopher | 1778772 | 2010-10-21 21:47:51 +0000 | [diff] [blame] | 157 | bool SelectLoad(const Instruction *I); |
| 158 | bool SelectStore(const Instruction *I); |
| 159 | bool SelectBranch(const Instruction *I); |
| 160 | bool SelectCmp(const Instruction *I); |
| 161 | bool SelectFPExt(const Instruction *I); |
| 162 | bool SelectFPTrunc(const Instruction *I); |
| 163 | bool SelectBinaryOp(const Instruction *I, unsigned ISDOpcode); |
| 164 | bool SelectSIToFP(const Instruction *I); |
| 165 | bool SelectFPToSI(const Instruction *I); |
| 166 | bool SelectSDiv(const Instruction *I); |
| 167 | bool SelectSRem(const Instruction *I); |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 168 | bool SelectCall(const Instruction *I, const char *IntrMemName); |
| 169 | bool SelectIntrinsicCall(const IntrinsicInst &I); |
Eric Christopher | 1778772 | 2010-10-21 21:47:51 +0000 | [diff] [blame] | 170 | bool SelectSelect(const Instruction *I); |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 171 | bool SelectRet(const Instruction *I); |
Chad Rosier | 0d7b231 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 172 | bool SelectTrunc(const Instruction *I); |
| 173 | bool SelectIntExt(const Instruction *I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 174 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 175 | // Utility routines. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 176 | private: |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 177 | bool isTypeLegal(Type *Ty, MVT &VT); |
| 178 | bool isLoadTypeLegal(Type *Ty, MVT &VT); |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 179 | bool ARMEmitCmp(const Value *Src1Value, const Value *Src2Value, |
| 180 | bool isZExt); |
Chad Rosier | 404ed3c | 2011-12-14 17:26:05 +0000 | [diff] [blame^] | 181 | bool ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr, |
| 182 | unsigned Alignment = 0, bool isZExt = true, |
| 183 | bool allocReg = true); |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 184 | |
Bob Wilson | 6ce2dea | 2011-12-04 00:52:23 +0000 | [diff] [blame] | 185 | bool ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr, |
| 186 | unsigned Alignment = 0); |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 187 | bool ARMComputeAddress(const Value *Obj, Address &Addr); |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 188 | void ARMSimplifyAddress(Address &Addr, EVT VT, bool useAM3); |
Chad Rosier | 2c42b8c | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 189 | bool ARMIsMemCpySmall(uint64_t Len); |
| 190 | bool ARMTryEmitSmallMemCpy(Address Dest, Address Src, uint64_t Len); |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 191 | unsigned ARMEmitIntExt(EVT SrcVT, unsigned SrcReg, EVT DestVT, bool isZExt); |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 192 | unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT); |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 193 | unsigned ARMMaterializeInt(const Constant *C, EVT VT); |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 194 | unsigned ARMMaterializeGV(const GlobalValue *GV, EVT VT); |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 195 | unsigned ARMMoveToFPReg(EVT VT, unsigned SrcReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 196 | unsigned ARMMoveToIntReg(EVT VT, unsigned SrcReg); |
Eric Christopher | 872f4a2 | 2011-02-22 01:37:10 +0000 | [diff] [blame] | 197 | unsigned ARMSelectCallOp(const GlobalValue *GV); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 198 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 199 | // Call handling routines. |
| 200 | private: |
| 201 | CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool Return); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 202 | bool ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 203 | SmallVectorImpl<unsigned> &ArgRegs, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 204 | SmallVectorImpl<MVT> &ArgVTs, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 205 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 206 | SmallVectorImpl<unsigned> &RegArgs, |
| 207 | CallingConv::ID CC, |
| 208 | unsigned &NumBytes); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 209 | bool FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 210 | const Instruction *I, CallingConv::ID CC, |
| 211 | unsigned &NumBytes); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 212 | bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call); |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 213 | |
| 214 | // OptionalDef handling routines. |
| 215 | private: |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 216 | bool isARMNEONPred(const MachineInstr *MI); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 217 | bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR); |
| 218 | const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB); |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 219 | void AddLoadStoreOperands(EVT VT, Address &Addr, |
Cameron Zwarich | c152aa6 | 2011-05-28 20:34:49 +0000 | [diff] [blame] | 220 | const MachineInstrBuilder &MIB, |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 221 | unsigned Flags, bool useAM3); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 222 | }; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 223 | |
| 224 | } // end anonymous namespace |
| 225 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 226 | #include "ARMGenCallingConv.inc" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 227 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 228 | // DefinesOptionalPredicate - This is different from DefinesPredicate in that |
| 229 | // we don't care about implicit defs here, just places we'll need to add a |
| 230 | // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR. |
| 231 | bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 232 | if (!MI->hasOptionalDef()) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 233 | return false; |
| 234 | |
| 235 | // Look to see if our OptionalDef is defining CPSR or CCR. |
| 236 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 237 | const MachineOperand &MO = MI->getOperand(i); |
Eric Christopher | f762fbe | 2010-08-20 00:36:24 +0000 | [diff] [blame] | 238 | if (!MO.isReg() || !MO.isDef()) continue; |
| 239 | if (MO.getReg() == ARM::CPSR) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 240 | *CPSR = true; |
| 241 | } |
| 242 | return true; |
| 243 | } |
| 244 | |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 245 | bool ARMFastISel::isARMNEONPred(const MachineInstr *MI) { |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 246 | const MCInstrDesc &MCID = MI->getDesc(); |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 247 | |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 248 | // If we're a thumb2 or not NEON function we were handled via isPredicable. |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 249 | if ((MCID.TSFlags & ARMII::DomainMask) != ARMII::DomainNEON || |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 250 | AFI->isThumb2Function()) |
| 251 | return false; |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 252 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 253 | for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i) |
| 254 | if (MCID.OpInfo[i].isPredicate()) |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 255 | return true; |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 256 | |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 257 | return false; |
| 258 | } |
| 259 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 260 | // If the machine is predicable go ahead and add the predicate operands, if |
| 261 | // it needs default CC operands add those. |
Eric Christopher | aaa8df4 | 2010-11-02 01:21:28 +0000 | [diff] [blame] | 262 | // TODO: If we want to support thumb1 then we'll need to deal with optional |
| 263 | // CPSR defs that need to be added before the remaining operands. See s_cc_out |
| 264 | // for descriptions why. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 265 | const MachineInstrBuilder & |
| 266 | ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) { |
| 267 | MachineInstr *MI = &*MIB; |
| 268 | |
Eric Christopher | af3dce5 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 269 | // Do we use a predicate? or... |
| 270 | // Are we NEON in ARM mode and have a predicate operand? If so, I know |
| 271 | // we're not predicable but add it anyways. |
| 272 | if (TII.isPredicable(MI) || isARMNEONPred(MI)) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 273 | AddDefaultPred(MIB); |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 274 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 275 | // Do we optionally set a predicate? Preds is size > 0 iff the predicate |
| 276 | // defines CPSR. All other OptionalDefines in ARM are the CCR register. |
Eric Christopher | 979e0a1 | 2010-08-19 15:35:27 +0000 | [diff] [blame] | 277 | bool CPSR = false; |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 278 | if (DefinesOptionalPredicate(MI, &CPSR)) { |
| 279 | if (CPSR) |
| 280 | AddDefaultT1CC(MIB); |
| 281 | else |
| 282 | AddDefaultCC(MIB); |
| 283 | } |
| 284 | return MIB; |
| 285 | } |
| 286 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 287 | unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode, |
| 288 | const TargetRegisterClass* RC) { |
| 289 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 290 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 291 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 292 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 293 | return ResultReg; |
| 294 | } |
| 295 | |
| 296 | unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode, |
| 297 | const TargetRegisterClass *RC, |
| 298 | unsigned Op0, bool Op0IsKill) { |
| 299 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 300 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 301 | |
| 302 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 303 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 304 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
| 305 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 306 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 307 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 308 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 309 | TII.get(TargetOpcode::COPY), ResultReg) |
| 310 | .addReg(II.ImplicitDefs[0])); |
| 311 | } |
| 312 | return ResultReg; |
| 313 | } |
| 314 | |
| 315 | unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode, |
| 316 | const TargetRegisterClass *RC, |
| 317 | unsigned Op0, bool Op0IsKill, |
| 318 | unsigned Op1, bool Op1IsKill) { |
| 319 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 320 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 321 | |
| 322 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 323 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 324 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 325 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
| 326 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 327 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 328 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 329 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 330 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 331 | TII.get(TargetOpcode::COPY), ResultReg) |
| 332 | .addReg(II.ImplicitDefs[0])); |
| 333 | } |
| 334 | return ResultReg; |
| 335 | } |
| 336 | |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 337 | unsigned ARMFastISel::FastEmitInst_rrr(unsigned MachineInstOpcode, |
| 338 | const TargetRegisterClass *RC, |
| 339 | unsigned Op0, bool Op0IsKill, |
| 340 | unsigned Op1, bool Op1IsKill, |
| 341 | unsigned Op2, bool Op2IsKill) { |
| 342 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 343 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 344 | |
| 345 | if (II.getNumDefs() >= 1) |
| 346 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
| 347 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 348 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 349 | .addReg(Op2, Op2IsKill * RegState::Kill)); |
| 350 | else { |
| 351 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
| 352 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 353 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 354 | .addReg(Op2, Op2IsKill * RegState::Kill)); |
| 355 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 356 | TII.get(TargetOpcode::COPY), ResultReg) |
| 357 | .addReg(II.ImplicitDefs[0])); |
| 358 | } |
| 359 | return ResultReg; |
| 360 | } |
| 361 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 362 | unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode, |
| 363 | const TargetRegisterClass *RC, |
| 364 | unsigned Op0, bool Op0IsKill, |
| 365 | uint64_t Imm) { |
| 366 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 367 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 368 | |
| 369 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 370 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 371 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 372 | .addImm(Imm)); |
| 373 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 374 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 375 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 376 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 377 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 378 | TII.get(TargetOpcode::COPY), ResultReg) |
| 379 | .addReg(II.ImplicitDefs[0])); |
| 380 | } |
| 381 | return ResultReg; |
| 382 | } |
| 383 | |
| 384 | unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode, |
| 385 | const TargetRegisterClass *RC, |
| 386 | unsigned Op0, bool Op0IsKill, |
| 387 | const ConstantFP *FPImm) { |
| 388 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 389 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 390 | |
| 391 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 392 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 393 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 394 | .addFPImm(FPImm)); |
| 395 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 396 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 397 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 398 | .addFPImm(FPImm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 399 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 400 | TII.get(TargetOpcode::COPY), ResultReg) |
| 401 | .addReg(II.ImplicitDefs[0])); |
| 402 | } |
| 403 | return ResultReg; |
| 404 | } |
| 405 | |
| 406 | unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode, |
| 407 | const TargetRegisterClass *RC, |
| 408 | unsigned Op0, bool Op0IsKill, |
| 409 | unsigned Op1, bool Op1IsKill, |
| 410 | uint64_t Imm) { |
| 411 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 412 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 413 | |
| 414 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 415 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 416 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 417 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 418 | .addImm(Imm)); |
| 419 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 420 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 421 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 422 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 423 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 424 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 425 | TII.get(TargetOpcode::COPY), ResultReg) |
| 426 | .addReg(II.ImplicitDefs[0])); |
| 427 | } |
| 428 | return ResultReg; |
| 429 | } |
| 430 | |
| 431 | unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode, |
| 432 | const TargetRegisterClass *RC, |
| 433 | uint64_t Imm) { |
| 434 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 435 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 436 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 437 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 438 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 439 | .addImm(Imm)); |
| 440 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 441 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 442 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 443 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 444 | TII.get(TargetOpcode::COPY), ResultReg) |
| 445 | .addReg(II.ImplicitDefs[0])); |
| 446 | } |
| 447 | return ResultReg; |
| 448 | } |
| 449 | |
Eric Christopher | d94bc54 | 2011-04-29 22:07:50 +0000 | [diff] [blame] | 450 | unsigned ARMFastISel::FastEmitInst_ii(unsigned MachineInstOpcode, |
| 451 | const TargetRegisterClass *RC, |
| 452 | uint64_t Imm1, uint64_t Imm2) { |
| 453 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 454 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 455 | |
Eric Christopher | d94bc54 | 2011-04-29 22:07:50 +0000 | [diff] [blame] | 456 | if (II.getNumDefs() >= 1) |
| 457 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
| 458 | .addImm(Imm1).addImm(Imm2)); |
| 459 | else { |
| 460 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
| 461 | .addImm(Imm1).addImm(Imm2)); |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 462 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | d94bc54 | 2011-04-29 22:07:50 +0000 | [diff] [blame] | 463 | TII.get(TargetOpcode::COPY), |
| 464 | ResultReg) |
| 465 | .addReg(II.ImplicitDefs[0])); |
| 466 | } |
| 467 | return ResultReg; |
| 468 | } |
| 469 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 470 | unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT, |
| 471 | unsigned Op0, bool Op0IsKill, |
| 472 | uint32_t Idx) { |
| 473 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT)); |
| 474 | assert(TargetRegisterInfo::isVirtualRegister(Op0) && |
| 475 | "Cannot yet extract from physregs"); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 476 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 477 | DL, TII.get(TargetOpcode::COPY), ResultReg) |
| 478 | .addReg(Op0, getKillRegState(Op0IsKill), Idx)); |
| 479 | return ResultReg; |
| 480 | } |
| 481 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 482 | // TODO: Don't worry about 64-bit now, but when this is fixed remove the |
| 483 | // checks from the various callers. |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 484 | unsigned ARMFastISel::ARMMoveToFPReg(EVT VT, unsigned SrcReg) { |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 485 | if (VT == MVT::f64) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 486 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 487 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 488 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 489 | TII.get(ARM::VMOVRS), MoveReg) |
| 490 | .addReg(SrcReg)); |
| 491 | return MoveReg; |
| 492 | } |
| 493 | |
| 494 | unsigned ARMFastISel::ARMMoveToIntReg(EVT VT, unsigned SrcReg) { |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 495 | if (VT == MVT::i64) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 496 | |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 497 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 498 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 499 | TII.get(ARM::VMOVSR), MoveReg) |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 500 | .addReg(SrcReg)); |
| 501 | return MoveReg; |
| 502 | } |
| 503 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 504 | // For double width floating point we need to materialize two constants |
| 505 | // (the high and the low) into integer registers then use a move to get |
| 506 | // the combined constant into an FP reg. |
| 507 | unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, EVT VT) { |
| 508 | const APFloat Val = CFP->getValueAPF(); |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 509 | bool is64bit = VT == MVT::f64; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 510 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 511 | // This checks to see if we can use VFP3 instructions to materialize |
| 512 | // a constant, otherwise we have to go through the constant pool. |
| 513 | if (TLI.isFPImmLegal(Val, VT)) { |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 514 | int Imm; |
| 515 | unsigned Opc; |
| 516 | if (is64bit) { |
| 517 | Imm = ARM_AM::getFP64Imm(Val); |
| 518 | Opc = ARM::FCONSTD; |
| 519 | } else { |
| 520 | Imm = ARM_AM::getFP32Imm(Val); |
| 521 | Opc = ARM::FCONSTS; |
| 522 | } |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 523 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 524 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 525 | DestReg) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 526 | .addImm(Imm)); |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 527 | return DestReg; |
| 528 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 529 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 530 | // Require VFP2 for loading fp constants. |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 531 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 532 | |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 533 | // MachineConstantPool wants an explicit alignment. |
| 534 | unsigned Align = TD.getPrefTypeAlignment(CFP->getType()); |
| 535 | if (Align == 0) { |
| 536 | // TODO: Figure out if this is correct. |
| 537 | Align = TD.getTypeAllocSize(CFP->getType()); |
| 538 | } |
| 539 | unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align); |
| 540 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 541 | unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 542 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 543 | // The extra reg is for addrmode5. |
Eric Christopher | f5732c4 | 2010-09-28 00:35:09 +0000 | [diff] [blame] | 544 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 545 | DestReg) |
| 546 | .addConstantPoolIndex(Idx) |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 547 | .addReg(0)); |
| 548 | return DestReg; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 551 | unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, EVT VT) { |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 552 | |
Chad Rosier | 44e8957 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 553 | if (VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8 && VT != MVT::i1) |
| 554 | return false; |
Eric Christopher | e5b13cf | 2010-11-03 20:21:17 +0000 | [diff] [blame] | 555 | |
| 556 | // If we can do this in a single instruction without a constant pool entry |
| 557 | // do so now. |
| 558 | const ConstantInt *CI = cast<ConstantInt>(C); |
Chad Rosier | a4e0727 | 2011-11-04 23:09:49 +0000 | [diff] [blame] | 559 | if (Subtarget->hasV6T2Ops() && isUInt<16>(CI->getZExtValue())) { |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 560 | unsigned Opc = isThumb2 ? ARM::t2MOVi16 : ARM::MOVi16; |
Chad Rosier | 4e89d97 | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 561 | unsigned ImmReg = createResultReg(TLI.getRegClassFor(MVT::i32)); |
Eric Christopher | e5b13cf | 2010-11-03 20:21:17 +0000 | [diff] [blame] | 562 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Chad Rosier | 44e8957 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 563 | TII.get(Opc), ImmReg) |
Chad Rosier | 42536af | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 564 | .addImm(CI->getZExtValue())); |
Chad Rosier | 44e8957 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 565 | return ImmReg; |
Eric Christopher | e5b13cf | 2010-11-03 20:21:17 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Chad Rosier | 4e89d97 | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 568 | // Use MVN to emit negative constants. |
| 569 | if (VT == MVT::i32 && Subtarget->hasV6T2Ops() && CI->isNegative()) { |
| 570 | unsigned Imm = (unsigned)~(CI->getSExtValue()); |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 571 | bool UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) : |
Chad Rosier | 4e89d97 | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 572 | (ARM_AM::getSOImmVal(Imm) != -1); |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 573 | if (UseImm) { |
Chad Rosier | 4e89d97 | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 574 | unsigned Opc = isThumb2 ? ARM::t2MVNi : ARM::MVNi; |
| 575 | unsigned ImmReg = createResultReg(TLI.getRegClassFor(MVT::i32)); |
| 576 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 577 | TII.get(Opc), ImmReg) |
| 578 | .addImm(Imm)); |
| 579 | return ImmReg; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | // Load from constant pool. For now 32-bit only. |
Chad Rosier | 44e8957 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 584 | if (VT != MVT::i32) |
| 585 | return false; |
| 586 | |
| 587 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 588 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 589 | // MachineConstantPool wants an explicit alignment. |
| 590 | unsigned Align = TD.getPrefTypeAlignment(C->getType()); |
| 591 | if (Align == 0) { |
| 592 | // TODO: Figure out if this is correct. |
| 593 | Align = TD.getTypeAllocSize(C->getType()); |
| 594 | } |
| 595 | unsigned Idx = MCP.getConstantPoolIndex(C, Align); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 596 | |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 597 | if (isThumb2) |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 598 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | fd60980 | 2010-09-28 21:55:34 +0000 | [diff] [blame] | 599 | TII.get(ARM::t2LDRpci), DestReg) |
| 600 | .addConstantPoolIndex(Idx)); |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 601 | else |
Eric Christopher | d0c82a6 | 2010-11-12 09:48:30 +0000 | [diff] [blame] | 602 | // The extra immediate is for addrmode2. |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 603 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | fd60980 | 2010-09-28 21:55:34 +0000 | [diff] [blame] | 604 | TII.get(ARM::LDRcp), DestReg) |
| 605 | .addConstantPoolIndex(Idx) |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 606 | .addImm(0)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 607 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 608 | return DestReg; |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 611 | unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, EVT VT) { |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 612 | // For now 32-bit only. |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 613 | if (VT != MVT::i32) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 614 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 615 | Reloc::Model RelocM = TM.getRelocationModel(); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 616 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 617 | // TODO: Need more magic for ARM PIC. |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 618 | if (!isThumb2 && (RelocM == Reloc::PIC_)) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 619 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 620 | // MachineConstantPool wants an explicit alignment. |
| 621 | unsigned Align = TD.getPrefTypeAlignment(GV->getType()); |
| 622 | if (Align == 0) { |
| 623 | // TODO: Figure out if this is correct. |
| 624 | Align = TD.getTypeAllocSize(GV->getType()); |
| 625 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 626 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 627 | // Grab index. |
| 628 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 629 | unsigned Id = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 630 | ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create(GV, Id, |
| 631 | ARMCP::CPValue, |
| 632 | PCAdj); |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 633 | unsigned Idx = MCP.getConstantPoolIndex(CPV, Align); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 634 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 635 | // Load value. |
| 636 | MachineInstrBuilder MIB; |
| 637 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 638 | if (isThumb2) { |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 639 | unsigned Opc = (RelocM != Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic; |
| 640 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg) |
| 641 | .addConstantPoolIndex(Idx); |
| 642 | if (RelocM == Reloc::PIC_) |
| 643 | MIB.addImm(Id); |
| 644 | } else { |
Eric Christopher | d0c82a6 | 2010-11-12 09:48:30 +0000 | [diff] [blame] | 645 | // The extra immediate is for addrmode2. |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 646 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRcp), |
| 647 | DestReg) |
| 648 | .addConstantPoolIndex(Idx) |
Eric Christopher | d0c82a6 | 2010-11-12 09:48:30 +0000 | [diff] [blame] | 649 | .addImm(0); |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 650 | } |
| 651 | AddOptionalDefs(MIB); |
Eli Friedman | d6412c9 | 2011-06-03 01:13:19 +0000 | [diff] [blame] | 652 | |
| 653 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) { |
| 654 | unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT)); |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 655 | if (isThumb2) |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 656 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 657 | TII.get(ARM::t2LDRi12), NewDestReg) |
Eli Friedman | d6412c9 | 2011-06-03 01:13:19 +0000 | [diff] [blame] | 658 | .addReg(DestReg) |
| 659 | .addImm(0); |
| 660 | else |
| 661 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRi12), |
| 662 | NewDestReg) |
| 663 | .addReg(DestReg) |
| 664 | .addImm(0); |
| 665 | DestReg = NewDestReg; |
| 666 | AddOptionalDefs(MIB); |
| 667 | } |
| 668 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 669 | return DestReg; |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 672 | unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) { |
| 673 | EVT VT = TLI.getValueType(C->getType(), true); |
| 674 | |
| 675 | // Only handle simple types. |
| 676 | if (!VT.isSimple()) return 0; |
| 677 | |
| 678 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) |
| 679 | return ARMMaterializeFP(CFP, VT); |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 680 | else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 681 | return ARMMaterializeGV(GV, VT); |
| 682 | else if (isa<ConstantInt>(C)) |
| 683 | return ARMMaterializeInt(C, VT); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 684 | |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 685 | return 0; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Chad Rosier | 944d82b | 2011-11-17 21:46:13 +0000 | [diff] [blame] | 688 | // TODO: unsigned ARMFastISel::TargetMaterializeFloatZero(const ConstantFP *CF); |
| 689 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 690 | unsigned ARMFastISel::TargetMaterializeAlloca(const AllocaInst *AI) { |
| 691 | // Don't handle dynamic allocas. |
| 692 | if (!FuncInfo.StaticAllocaMap.count(AI)) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 693 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 694 | MVT VT; |
Eric Christopher | ec8bf97 | 2010-10-17 06:07:26 +0000 | [diff] [blame] | 695 | if (!isLoadTypeLegal(AI->getType(), VT)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 696 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 697 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 698 | FuncInfo.StaticAllocaMap.find(AI); |
| 699 | |
| 700 | // This will get lowered later into the correct offsets and registers |
| 701 | // via rewriteXFrameIndex. |
| 702 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
| 703 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
| 704 | unsigned ResultReg = createResultReg(RC); |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 705 | unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri; |
Evan Cheng | ddfd137 | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 706 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 707 | TII.get(Opc), ResultReg) |
| 708 | .addFrameIndex(SI->second) |
| 709 | .addImm(0)); |
| 710 | return ResultReg; |
| 711 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 712 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 713 | return 0; |
| 714 | } |
| 715 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 716 | bool ARMFastISel::isTypeLegal(Type *Ty, MVT &VT) { |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 717 | EVT evt = TLI.getValueType(Ty, true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 718 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 719 | // Only handle simple types. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 720 | if (evt == MVT::Other || !evt.isSimple()) return false; |
| 721 | VT = evt.getSimpleVT(); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 722 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 723 | // Handle all legal types, i.e. a register that will directly hold this |
| 724 | // value. |
| 725 | return TLI.isTypeLegal(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 728 | bool ARMFastISel::isLoadTypeLegal(Type *Ty, MVT &VT) { |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 729 | if (isTypeLegal(Ty, VT)) return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 730 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 731 | // If this is a type than can be sign or zero-extended to a basic operation |
| 732 | // go ahead and accept it now. |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 733 | if (VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16) |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 734 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 735 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 736 | return false; |
| 737 | } |
| 738 | |
Eric Christopher | 88de86b | 2010-11-19 22:36:41 +0000 | [diff] [blame] | 739 | // Computes the address to get to an object. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 740 | bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 741 | // Some boilerplate from the X86 FastISel. |
| 742 | const User *U = NULL; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 743 | unsigned Opcode = Instruction::UserOp1; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 744 | if (const Instruction *I = dyn_cast<Instruction>(Obj)) { |
Eric Christopher | 2d630d7 | 2010-11-19 22:37:58 +0000 | [diff] [blame] | 745 | // Don't walk into other basic blocks unless the object is an alloca from |
| 746 | // another block, otherwise it may not have a virtual register assigned. |
Eric Christopher | 76dda7e | 2010-11-15 21:11:06 +0000 | [diff] [blame] | 747 | if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) || |
| 748 | FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) { |
| 749 | Opcode = I->getOpcode(); |
| 750 | U = I; |
| 751 | } |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 752 | } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 753 | Opcode = C->getOpcode(); |
| 754 | U = C; |
| 755 | } |
| 756 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 757 | if (PointerType *Ty = dyn_cast<PointerType>(Obj->getType())) |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 758 | if (Ty->getAddressSpace() > 255) |
| 759 | // Fast instruction selection doesn't support the special |
| 760 | // address spaces. |
| 761 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 762 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 763 | switch (Opcode) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 764 | default: |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 765 | break; |
Eric Christopher | 5532433 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 766 | case Instruction::BitCast: { |
| 767 | // Look through bitcasts. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 768 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | 5532433 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 769 | } |
| 770 | case Instruction::IntToPtr: { |
| 771 | // Look past no-op inttoptrs. |
| 772 | if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy()) |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 773 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | 5532433 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 774 | break; |
| 775 | } |
| 776 | case Instruction::PtrToInt: { |
| 777 | // Look past no-op ptrtoints. |
| 778 | if (TLI.getValueType(U->getType()) == TLI.getPointerTy()) |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 779 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | 5532433 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 780 | break; |
| 781 | } |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 782 | case Instruction::GetElementPtr: { |
Eric Christopher | b371658 | 2010-11-19 22:39:56 +0000 | [diff] [blame] | 783 | Address SavedAddr = Addr; |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 784 | int TmpOffset = Addr.Offset; |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 785 | |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 786 | // Iterate through the GEP folding the constants into offsets where |
| 787 | // we can. |
| 788 | gep_type_iterator GTI = gep_type_begin(U); |
| 789 | for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end(); |
| 790 | i != e; ++i, ++GTI) { |
| 791 | const Value *Op = *i; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 792 | if (StructType *STy = dyn_cast<StructType>(*GTI)) { |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 793 | const StructLayout *SL = TD.getStructLayout(STy); |
| 794 | unsigned Idx = cast<ConstantInt>(Op)->getZExtValue(); |
| 795 | TmpOffset += SL->getElementOffset(Idx); |
| 796 | } else { |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 797 | uint64_t S = TD.getTypeAllocSize(GTI.getIndexedType()); |
Eric Christopher | 7244d7c | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 798 | for (;;) { |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 799 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) { |
| 800 | // Constant-offset addressing. |
| 801 | TmpOffset += CI->getSExtValue() * S; |
Eric Christopher | 7244d7c | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 802 | break; |
| 803 | } |
| 804 | if (isa<AddOperator>(Op) && |
| 805 | (!isa<Instruction>(Op) || |
| 806 | FuncInfo.MBBMap[cast<Instruction>(Op)->getParent()] |
| 807 | == FuncInfo.MBB) && |
| 808 | isa<ConstantInt>(cast<AddOperator>(Op)->getOperand(1))) { |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 809 | // An add (in the same block) with a constant operand. Fold the |
Eric Christopher | 7244d7c | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 810 | // constant. |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 811 | ConstantInt *CI = |
Eric Christopher | 7244d7c | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 812 | cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1)); |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 813 | TmpOffset += CI->getSExtValue() * S; |
Eric Christopher | 7244d7c | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 814 | // Iterate on the other operand. |
| 815 | Op = cast<AddOperator>(Op)->getOperand(0); |
| 816 | continue; |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 817 | } |
Eric Christopher | 7244d7c | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 818 | // Unsupported |
| 819 | goto unsupported_gep; |
| 820 | } |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 821 | } |
| 822 | } |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 823 | |
| 824 | // Try to grab the base operand now. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 825 | Addr.Offset = TmpOffset; |
| 826 | if (ARMComputeAddress(U->getOperand(0), Addr)) return true; |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 827 | |
| 828 | // We failed, restore everything and try the other options. |
Eric Christopher | b371658 | 2010-11-19 22:39:56 +0000 | [diff] [blame] | 829 | Addr = SavedAddr; |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 830 | |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 831 | unsupported_gep: |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 832 | break; |
| 833 | } |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 834 | case Instruction::Alloca: { |
Eric Christopher | 1541877 | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 835 | const AllocaInst *AI = cast<AllocaInst>(Obj); |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 836 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 837 | FuncInfo.StaticAllocaMap.find(AI); |
| 838 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
| 839 | Addr.BaseType = Address::FrameIndexBase; |
| 840 | Addr.Base.FI = SI->second; |
| 841 | return true; |
| 842 | } |
| 843 | break; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 844 | } |
| 845 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 846 | |
Eric Christopher | a9c5751 | 2010-10-13 21:41:51 +0000 | [diff] [blame] | 847 | // Materialize the global variable's address into a reg which can |
| 848 | // then be used later to load the variable. |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 849 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) { |
Eric Christopher | ede42b0 | 2010-10-13 09:11:46 +0000 | [diff] [blame] | 850 | unsigned Tmp = ARMMaterializeGV(GV, TLI.getValueType(Obj->getType())); |
| 851 | if (Tmp == 0) return false; |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 852 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 853 | Addr.Base.Reg = Tmp; |
Eric Christopher | ede42b0 | 2010-10-13 09:11:46 +0000 | [diff] [blame] | 854 | return true; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 855 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 856 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 857 | // Try to get this in a register if nothing else has worked. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 858 | if (Addr.Base.Reg == 0) Addr.Base.Reg = getRegForValue(Obj); |
| 859 | return Addr.Base.Reg != 0; |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 862 | void ARMFastISel::ARMSimplifyAddress(Address &Addr, EVT VT, bool useAM3) { |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 863 | |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 864 | assert(VT.isSimple() && "Non-simple types are invalid here!"); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 865 | |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 866 | bool needsLowering = false; |
| 867 | switch (VT.getSimpleVT().SimpleTy) { |
| 868 | default: |
| 869 | assert(false && "Unhandled load/store type!"); |
Chad Rosier | 7346347 | 2011-11-09 21:30:12 +0000 | [diff] [blame] | 870 | break; |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 871 | case MVT::i1: |
| 872 | case MVT::i8: |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 873 | case MVT::i16: |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 874 | case MVT::i32: |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 875 | if (!useAM3) { |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 876 | // Integer loads/stores handle 12-bit offsets. |
| 877 | needsLowering = ((Addr.Offset & 0xfff) != Addr.Offset); |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 878 | // Handle negative offsets. |
Chad Rosier | e489af8 | 2011-11-14 22:34:48 +0000 | [diff] [blame] | 879 | if (needsLowering && isThumb2) |
| 880 | needsLowering = !(Subtarget->hasV6T2Ops() && Addr.Offset < 0 && |
| 881 | Addr.Offset > -256); |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 882 | } else { |
Chad Rosier | 5be833d | 2011-11-13 04:25:02 +0000 | [diff] [blame] | 883 | // ARM halfword load/stores and signed byte loads use +/-imm8 offsets. |
Chad Rosier | dc9205d | 2011-11-14 04:09:28 +0000 | [diff] [blame] | 884 | needsLowering = (Addr.Offset > 255 || Addr.Offset < -255); |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 885 | } |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 886 | break; |
| 887 | case MVT::f32: |
| 888 | case MVT::f64: |
| 889 | // Floating point operands handle 8-bit offsets. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 890 | needsLowering = ((Addr.Offset & 0xff) != Addr.Offset); |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 891 | break; |
| 892 | } |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 893 | |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 894 | // If this is a stack pointer and the offset needs to be simplified then |
| 895 | // put the alloca address into a register, set the base type back to |
| 896 | // register and continue. This should almost never happen. |
| 897 | if (needsLowering && Addr.BaseType == Address::FrameIndexBase) { |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 898 | TargetRegisterClass *RC = isThumb2 ? ARM::tGPRRegisterClass : |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 899 | ARM::GPRRegisterClass; |
| 900 | unsigned ResultReg = createResultReg(RC); |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 901 | unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri; |
Evan Cheng | ddfd137 | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 902 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 903 | TII.get(Opc), ResultReg) |
| 904 | .addFrameIndex(Addr.Base.FI) |
| 905 | .addImm(0)); |
| 906 | Addr.Base.Reg = ResultReg; |
| 907 | Addr.BaseType = Address::RegBase; |
| 908 | } |
| 909 | |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 910 | // Since the offset is too large for the load/store instruction |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 911 | // get the reg+offset into a register. |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 912 | if (needsLowering) { |
Eli Friedman | 9ebf57a | 2011-04-29 21:22:56 +0000 | [diff] [blame] | 913 | Addr.Base.Reg = FastEmit_ri_(MVT::i32, ISD::ADD, Addr.Base.Reg, |
| 914 | /*Op0IsKill*/false, Addr.Offset, MVT::i32); |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 915 | Addr.Offset = 0; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 916 | } |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 919 | void ARMFastISel::AddLoadStoreOperands(EVT VT, Address &Addr, |
Cameron Zwarich | c152aa6 | 2011-05-28 20:34:49 +0000 | [diff] [blame] | 920 | const MachineInstrBuilder &MIB, |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 921 | unsigned Flags, bool useAM3) { |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 922 | // addrmode5 output depends on the selection dag addressing dividing the |
| 923 | // offset by 4 that it then later multiplies. Do this here as well. |
| 924 | if (VT.getSimpleVT().SimpleTy == MVT::f32 || |
| 925 | VT.getSimpleVT().SimpleTy == MVT::f64) |
| 926 | Addr.Offset /= 4; |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 927 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 928 | // Frame base works a bit differently. Handle it separately. |
| 929 | if (Addr.BaseType == Address::FrameIndexBase) { |
| 930 | int FI = Addr.Base.FI; |
| 931 | int Offset = Addr.Offset; |
| 932 | MachineMemOperand *MMO = |
| 933 | FuncInfo.MF->getMachineMemOperand( |
| 934 | MachinePointerInfo::getFixedStack(FI, Offset), |
Cameron Zwarich | c152aa6 | 2011-05-28 20:34:49 +0000 | [diff] [blame] | 935 | Flags, |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 936 | MFI.getObjectSize(FI), |
| 937 | MFI.getObjectAlignment(FI)); |
| 938 | // Now add the rest of the operands. |
| 939 | MIB.addFrameIndex(FI); |
| 940 | |
Bob Wilson | 6ce2dea | 2011-12-04 00:52:23 +0000 | [diff] [blame] | 941 | // ARM halfword load/stores and signed byte loads need an additional |
| 942 | // operand. |
Chad Rosier | dc9205d | 2011-11-14 04:09:28 +0000 | [diff] [blame] | 943 | if (useAM3) { |
| 944 | signed Imm = (Addr.Offset < 0) ? (0x100 | -Addr.Offset) : Addr.Offset; |
| 945 | MIB.addReg(0); |
| 946 | MIB.addImm(Imm); |
| 947 | } else { |
| 948 | MIB.addImm(Addr.Offset); |
| 949 | } |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 950 | MIB.addMemOperand(MMO); |
| 951 | } else { |
| 952 | // Now add the rest of the operands. |
| 953 | MIB.addReg(Addr.Base.Reg); |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 954 | |
Bob Wilson | 6ce2dea | 2011-12-04 00:52:23 +0000 | [diff] [blame] | 955 | // ARM halfword load/stores and signed byte loads need an additional |
| 956 | // operand. |
Chad Rosier | dc9205d | 2011-11-14 04:09:28 +0000 | [diff] [blame] | 957 | if (useAM3) { |
| 958 | signed Imm = (Addr.Offset < 0) ? (0x100 | -Addr.Offset) : Addr.Offset; |
| 959 | MIB.addReg(0); |
| 960 | MIB.addImm(Imm); |
| 961 | } else { |
| 962 | MIB.addImm(Addr.Offset); |
| 963 | } |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 964 | } |
| 965 | AddOptionalDefs(MIB); |
| 966 | } |
| 967 | |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 968 | bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr, |
Chad Rosier | 8a9bce9 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 969 | unsigned Alignment, bool isZExt, bool allocReg) { |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 970 | assert(VT.isSimple() && "Non-simple types are invalid here!"); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 971 | unsigned Opc; |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 972 | bool useAM3 = false; |
Chad Rosier | 8a9bce9 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 973 | bool needVMOV = false; |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 974 | TargetRegisterClass *RC; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 975 | switch (VT.getSimpleVT().SimpleTy) { |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 976 | // This is mostly going to be Neon/vector support. |
| 977 | default: return false; |
Chad Rosier | 646abbf | 2011-11-11 02:38:59 +0000 | [diff] [blame] | 978 | case MVT::i1: |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 979 | case MVT::i8: |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 980 | if (isThumb2) { |
| 981 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 982 | Opc = isZExt ? ARM::t2LDRBi8 : ARM::t2LDRSBi8; |
| 983 | else |
| 984 | Opc = isZExt ? ARM::t2LDRBi12 : ARM::t2LDRSBi12; |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 985 | } else { |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 986 | if (isZExt) { |
| 987 | Opc = ARM::LDRBi12; |
| 988 | } else { |
| 989 | Opc = ARM::LDRSB; |
| 990 | useAM3 = true; |
| 991 | } |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 992 | } |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 993 | RC = ARM::GPRRegisterClass; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 994 | break; |
Chad Rosier | 7346347 | 2011-11-09 21:30:12 +0000 | [diff] [blame] | 995 | case MVT::i16: |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 996 | if (isThumb2) { |
| 997 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 998 | Opc = isZExt ? ARM::t2LDRHi8 : ARM::t2LDRSHi8; |
| 999 | else |
| 1000 | Opc = isZExt ? ARM::t2LDRHi12 : ARM::t2LDRSHi12; |
| 1001 | } else { |
| 1002 | Opc = isZExt ? ARM::LDRH : ARM::LDRSH; |
| 1003 | useAM3 = true; |
| 1004 | } |
Chad Rosier | 7346347 | 2011-11-09 21:30:12 +0000 | [diff] [blame] | 1005 | RC = ARM::GPRRegisterClass; |
| 1006 | break; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 1007 | case MVT::i32: |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 1008 | if (isThumb2) { |
| 1009 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 1010 | Opc = ARM::t2LDRi8; |
| 1011 | else |
| 1012 | Opc = ARM::t2LDRi12; |
| 1013 | } else { |
| 1014 | Opc = ARM::LDRi12; |
| 1015 | } |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 1016 | RC = ARM::GPRRegisterClass; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 1017 | break; |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 1018 | case MVT::f32: |
Chad Rosier | 8a9bce9 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1019 | // Unaligned loads need special handling. Floats require word-alignment. |
| 1020 | if (Alignment && Alignment < 4) { |
| 1021 | needVMOV = true; |
| 1022 | VT = MVT::i32; |
| 1023 | Opc = isThumb2 ? ARM::t2LDRi12 : ARM::LDRi12; |
| 1024 | RC = ARM::GPRRegisterClass; |
| 1025 | } else { |
| 1026 | Opc = ARM::VLDRS; |
| 1027 | RC = TLI.getRegClassFor(VT); |
| 1028 | } |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 1029 | break; |
| 1030 | case MVT::f64: |
Chad Rosier | 404ed3c | 2011-12-14 17:26:05 +0000 | [diff] [blame^] | 1031 | // FIXME: Unaligned loads need special handling. Doublewords require |
| 1032 | // word-alignment. |
| 1033 | if (Alignment && Alignment < 4) |
Chad Rosier | 8a9bce9 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1034 | return false; |
Chad Rosier | 404ed3c | 2011-12-14 17:26:05 +0000 | [diff] [blame^] | 1035 | |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 1036 | Opc = ARM::VLDRD; |
Eric Christopher | ee56ea6 | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 1037 | RC = TLI.getRegClassFor(VT); |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 1038 | break; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 1039 | } |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1040 | // Simplify this down to something we can handle. |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1041 | ARMSimplifyAddress(Addr, VT, useAM3); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1042 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1043 | // Create the base instruction, then add the operands. |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1044 | if (allocReg) |
| 1045 | ResultReg = createResultReg(RC); |
| 1046 | assert (ResultReg > 255 && "Expected an allocated virtual register."); |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1047 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1048 | TII.get(Opc), ResultReg); |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1049 | AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOLoad, useAM3); |
Chad Rosier | 8a9bce9 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1050 | |
| 1051 | // If we had an unaligned load of a float we've converted it to an regular |
| 1052 | // load. Now we must move from the GRP to the FP register. |
| 1053 | if (needVMOV) { |
| 1054 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(MVT::f32)); |
| 1055 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1056 | TII.get(ARM::VMOVSR), MoveReg) |
| 1057 | .addReg(ResultReg)); |
| 1058 | ResultReg = MoveReg; |
| 1059 | } |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 1060 | return true; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1063 | bool ARMFastISel::SelectLoad(const Instruction *I) { |
Eli Friedman | 4136d23 | 2011-09-02 22:33:24 +0000 | [diff] [blame] | 1064 | // Atomic loads need special handling. |
| 1065 | if (cast<LoadInst>(I)->isAtomic()) |
| 1066 | return false; |
| 1067 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1068 | // Verify we have a legal type before going any further. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1069 | MVT VT; |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1070 | if (!isLoadTypeLegal(I->getType(), VT)) |
| 1071 | return false; |
| 1072 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1073 | // See if we can handle this address. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1074 | Address Addr; |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1075 | if (!ARMComputeAddress(I->getOperand(0), Addr)) return false; |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1076 | |
| 1077 | unsigned ResultReg; |
Chad Rosier | 8a9bce9 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1078 | if (!ARMEmitLoad(VT, ResultReg, Addr, cast<LoadInst>(I)->getAlignment())) |
| 1079 | return false; |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1080 | UpdateValueMap(I, ResultReg); |
| 1081 | return true; |
| 1082 | } |
| 1083 | |
Bob Wilson | 6ce2dea | 2011-12-04 00:52:23 +0000 | [diff] [blame] | 1084 | bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr, |
| 1085 | unsigned Alignment) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1086 | unsigned StrOpc; |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1087 | bool useAM3 = false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1088 | switch (VT.getSimpleVT().SimpleTy) { |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1089 | // This is mostly going to be Neon/vector support. |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1090 | default: return false; |
Eric Christopher | 4c91412 | 2010-11-02 23:59:09 +0000 | [diff] [blame] | 1091 | case MVT::i1: { |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1092 | unsigned Res = createResultReg(isThumb2 ? ARM::tGPRRegisterClass : |
Eric Christopher | 4c91412 | 2010-11-02 23:59:09 +0000 | [diff] [blame] | 1093 | ARM::GPRRegisterClass); |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1094 | unsigned Opc = isThumb2 ? ARM::t2ANDri : ARM::ANDri; |
Eric Christopher | 4c91412 | 2010-11-02 23:59:09 +0000 | [diff] [blame] | 1095 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1096 | TII.get(Opc), Res) |
| 1097 | .addReg(SrcReg).addImm(1)); |
| 1098 | SrcReg = Res; |
| 1099 | } // Fallthrough here. |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 1100 | case MVT::i8: |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 1101 | if (isThumb2) { |
| 1102 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 1103 | StrOpc = ARM::t2STRBi8; |
| 1104 | else |
| 1105 | StrOpc = ARM::t2STRBi12; |
| 1106 | } else { |
| 1107 | StrOpc = ARM::STRBi12; |
| 1108 | } |
Eric Christopher | 1541877 | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | case MVT::i16: |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 1111 | if (isThumb2) { |
| 1112 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 1113 | StrOpc = ARM::t2STRHi8; |
| 1114 | else |
| 1115 | StrOpc = ARM::t2STRHi12; |
| 1116 | } else { |
| 1117 | StrOpc = ARM::STRH; |
| 1118 | useAM3 = true; |
| 1119 | } |
Eric Christopher | 1541877 | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 1120 | break; |
Eric Christopher | 47650ec | 2010-10-16 01:10:35 +0000 | [diff] [blame] | 1121 | case MVT::i32: |
Chad Rosier | 57b2997 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 1122 | if (isThumb2) { |
| 1123 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 1124 | StrOpc = ARM::t2STRi8; |
| 1125 | else |
| 1126 | StrOpc = ARM::t2STRi12; |
| 1127 | } else { |
| 1128 | StrOpc = ARM::STRi12; |
| 1129 | } |
Eric Christopher | 47650ec | 2010-10-16 01:10:35 +0000 | [diff] [blame] | 1130 | break; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1131 | case MVT::f32: |
| 1132 | if (!Subtarget->hasVFP2()) return false; |
| 1133 | StrOpc = ARM::VSTRS; |
Chad Rosier | ed42c5f | 2011-12-06 01:44:17 +0000 | [diff] [blame] | 1134 | // Unaligned stores need special handling. Floats require word-alignment. |
Chad Rosier | 9eff1e3 | 2011-12-03 02:21:57 +0000 | [diff] [blame] | 1135 | if (Alignment && Alignment < 4) { |
| 1136 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(MVT::i32)); |
| 1137 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1138 | TII.get(ARM::VMOVRS), MoveReg) |
| 1139 | .addReg(SrcReg)); |
| 1140 | SrcReg = MoveReg; |
| 1141 | VT = MVT::i32; |
| 1142 | StrOpc = isThumb2 ? ARM::t2STRi12 : ARM::STRi12; |
| 1143 | } |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1144 | break; |
| 1145 | case MVT::f64: |
| 1146 | if (!Subtarget->hasVFP2()) return false; |
Chad Rosier | ed42c5f | 2011-12-06 01:44:17 +0000 | [diff] [blame] | 1147 | // FIXME: Unaligned stores need special handling. Doublewords require |
| 1148 | // word-alignment. |
Chad Rosier | 404ed3c | 2011-12-14 17:26:05 +0000 | [diff] [blame^] | 1149 | if (Alignment && Alignment < 4) |
Chad Rosier | 9eff1e3 | 2011-12-03 02:21:57 +0000 | [diff] [blame] | 1150 | return false; |
Chad Rosier | 404ed3c | 2011-12-14 17:26:05 +0000 | [diff] [blame^] | 1151 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1152 | StrOpc = ARM::VSTRD; |
| 1153 | break; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1154 | } |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1155 | // Simplify this down to something we can handle. |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1156 | ARMSimplifyAddress(Addr, VT, useAM3); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1157 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1158 | // Create the base instruction, then add the operands. |
| 1159 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1160 | TII.get(StrOpc)) |
Chad Rosier | 3bdb3c9 | 2011-11-17 01:16:53 +0000 | [diff] [blame] | 1161 | .addReg(SrcReg); |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1162 | AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOStore, useAM3); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1163 | return true; |
| 1164 | } |
| 1165 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1166 | bool ARMFastISel::SelectStore(const Instruction *I) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1167 | Value *Op0 = I->getOperand(0); |
| 1168 | unsigned SrcReg = 0; |
| 1169 | |
Eli Friedman | 4136d23 | 2011-09-02 22:33:24 +0000 | [diff] [blame] | 1170 | // Atomic stores need special handling. |
| 1171 | if (cast<StoreInst>(I)->isAtomic()) |
| 1172 | return false; |
| 1173 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1174 | // Verify we have a legal type before going any further. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1175 | MVT VT; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1176 | if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT)) |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 1177 | return false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1178 | |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 1179 | // Get the value to be stored into a register. |
| 1180 | SrcReg = getRegForValue(Op0); |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1181 | if (SrcReg == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1182 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1183 | // See if we can handle this address. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1184 | Address Addr; |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1185 | if (!ARMComputeAddress(I->getOperand(1), Addr)) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1186 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1187 | |
Chad Rosier | 9eff1e3 | 2011-12-03 02:21:57 +0000 | [diff] [blame] | 1188 | if (!ARMEmitStore(VT, SrcReg, Addr, cast<StoreInst>(I)->getAlignment())) |
| 1189 | return false; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1190 | return true; |
| 1191 | } |
| 1192 | |
| 1193 | static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) { |
| 1194 | switch (Pred) { |
| 1195 | // Needs two compares... |
| 1196 | case CmpInst::FCMP_ONE: |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1197 | case CmpInst::FCMP_UEQ: |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1198 | default: |
Eric Christopher | 4053e63 | 2010-11-02 01:24:49 +0000 | [diff] [blame] | 1199 | // AL is our "false" for now. The other two need more compares. |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1200 | return ARMCC::AL; |
| 1201 | case CmpInst::ICMP_EQ: |
| 1202 | case CmpInst::FCMP_OEQ: |
| 1203 | return ARMCC::EQ; |
| 1204 | case CmpInst::ICMP_SGT: |
| 1205 | case CmpInst::FCMP_OGT: |
| 1206 | return ARMCC::GT; |
| 1207 | case CmpInst::ICMP_SGE: |
| 1208 | case CmpInst::FCMP_OGE: |
| 1209 | return ARMCC::GE; |
| 1210 | case CmpInst::ICMP_UGT: |
| 1211 | case CmpInst::FCMP_UGT: |
| 1212 | return ARMCC::HI; |
| 1213 | case CmpInst::FCMP_OLT: |
| 1214 | return ARMCC::MI; |
| 1215 | case CmpInst::ICMP_ULE: |
| 1216 | case CmpInst::FCMP_OLE: |
| 1217 | return ARMCC::LS; |
| 1218 | case CmpInst::FCMP_ORD: |
| 1219 | return ARMCC::VC; |
| 1220 | case CmpInst::FCMP_UNO: |
| 1221 | return ARMCC::VS; |
| 1222 | case CmpInst::FCMP_UGE: |
| 1223 | return ARMCC::PL; |
| 1224 | case CmpInst::ICMP_SLT: |
| 1225 | case CmpInst::FCMP_ULT: |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1226 | return ARMCC::LT; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1227 | case CmpInst::ICMP_SLE: |
| 1228 | case CmpInst::FCMP_ULE: |
| 1229 | return ARMCC::LE; |
| 1230 | case CmpInst::FCMP_UNE: |
| 1231 | case CmpInst::ICMP_NE: |
| 1232 | return ARMCC::NE; |
| 1233 | case CmpInst::ICMP_UGE: |
| 1234 | return ARMCC::HS; |
| 1235 | case CmpInst::ICMP_ULT: |
| 1236 | return ARMCC::LO; |
| 1237 | } |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1240 | bool ARMFastISel::SelectBranch(const Instruction *I) { |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1241 | const BranchInst *BI = cast<BranchInst>(I); |
| 1242 | MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)]; |
| 1243 | MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)]; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1244 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1245 | // Simple branch support. |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1246 | |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1247 | // If we can, avoid recomputing the compare - redoing it could lead to wonky |
| 1248 | // behavior. |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1249 | if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) { |
Chad Rosier | 75698f3 | 2011-10-26 23:17:28 +0000 | [diff] [blame] | 1250 | if (CI->hasOneUse() && (CI->getParent() == I->getParent())) { |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1251 | |
| 1252 | // Get the compare predicate. |
Eric Christopher | 632ae89 | 2011-04-29 21:56:31 +0000 | [diff] [blame] | 1253 | // Try to take advantage of fallthrough opportunities. |
| 1254 | CmpInst::Predicate Predicate = CI->getPredicate(); |
| 1255 | if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { |
| 1256 | std::swap(TBB, FBB); |
| 1257 | Predicate = CmpInst::getInversePredicate(Predicate); |
| 1258 | } |
| 1259 | |
| 1260 | ARMCC::CondCodes ARMPred = getComparePred(Predicate); |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1261 | |
| 1262 | // We may not handle every CC for now. |
| 1263 | if (ARMPred == ARMCC::AL) return false; |
| 1264 | |
Chad Rosier | 75698f3 | 2011-10-26 23:17:28 +0000 | [diff] [blame] | 1265 | // Emit the compare. |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1266 | if (!ARMEmitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned())) |
Chad Rosier | 75698f3 | 2011-10-26 23:17:28 +0000 | [diff] [blame] | 1267 | return false; |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1268 | |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1269 | unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc; |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1270 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
| 1271 | .addMBB(TBB).addImm(ARMPred).addReg(ARM::CPSR); |
| 1272 | FastEmitBranch(FBB, DL); |
| 1273 | FuncInfo.MBB->addSuccessor(TBB); |
| 1274 | return true; |
| 1275 | } |
Eric Christopher | bcf26ae | 2011-04-29 20:02:39 +0000 | [diff] [blame] | 1276 | } else if (TruncInst *TI = dyn_cast<TruncInst>(BI->getCondition())) { |
| 1277 | MVT SourceVT; |
| 1278 | if (TI->hasOneUse() && TI->getParent() == I->getParent() && |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 1279 | (isLoadTypeLegal(TI->getOperand(0)->getType(), SourceVT))) { |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1280 | unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri; |
Eric Christopher | bcf26ae | 2011-04-29 20:02:39 +0000 | [diff] [blame] | 1281 | unsigned OpReg = getRegForValue(TI->getOperand(0)); |
| 1282 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1283 | TII.get(TstOpc)) |
| 1284 | .addReg(OpReg).addImm(1)); |
| 1285 | |
| 1286 | unsigned CCMode = ARMCC::NE; |
| 1287 | if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { |
| 1288 | std::swap(TBB, FBB); |
| 1289 | CCMode = ARMCC::EQ; |
| 1290 | } |
| 1291 | |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1292 | unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc; |
Eric Christopher | bcf26ae | 2011-04-29 20:02:39 +0000 | [diff] [blame] | 1293 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
| 1294 | .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR); |
| 1295 | |
| 1296 | FastEmitBranch(FBB, DL); |
| 1297 | FuncInfo.MBB->addSuccessor(TBB); |
| 1298 | return true; |
| 1299 | } |
Chad Rosier | 6d64b3a | 2011-10-27 00:21:16 +0000 | [diff] [blame] | 1300 | } else if (const ConstantInt *CI = |
| 1301 | dyn_cast<ConstantInt>(BI->getCondition())) { |
| 1302 | uint64_t Imm = CI->getZExtValue(); |
| 1303 | MachineBasicBlock *Target = (Imm == 0) ? FBB : TBB; |
| 1304 | FastEmitBranch(Target, DL); |
| 1305 | return true; |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1306 | } |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1307 | |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1308 | unsigned CmpReg = getRegForValue(BI->getCondition()); |
| 1309 | if (CmpReg == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1310 | |
Stuart Hastings | c5eecbc | 2011-04-16 03:31:26 +0000 | [diff] [blame] | 1311 | // We've been divorced from our compare! Our block was split, and |
| 1312 | // now our compare lives in a predecessor block. We musn't |
| 1313 | // re-compare here, as the children of the compare aren't guaranteed |
| 1314 | // live across the block boundary (we *could* check for this). |
| 1315 | // Regardless, the compare has been done in the predecessor block, |
| 1316 | // and it left a value for us in a virtual register. Ergo, we test |
| 1317 | // the one-bit value left in the virtual register. |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1318 | unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri; |
Stuart Hastings | c5eecbc | 2011-04-16 03:31:26 +0000 | [diff] [blame] | 1319 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TstOpc)) |
| 1320 | .addReg(CmpReg).addImm(1)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1321 | |
Eric Christopher | 7a20a37 | 2011-04-28 16:52:09 +0000 | [diff] [blame] | 1322 | unsigned CCMode = ARMCC::NE; |
| 1323 | if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { |
| 1324 | std::swap(TBB, FBB); |
| 1325 | CCMode = ARMCC::EQ; |
| 1326 | } |
| 1327 | |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1328 | unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1329 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
Eric Christopher | 7a20a37 | 2011-04-28 16:52:09 +0000 | [diff] [blame] | 1330 | .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1331 | FastEmitBranch(FBB, DL); |
| 1332 | FuncInfo.MBB->addSuccessor(TBB); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1333 | return true; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1336 | bool ARMFastISel::ARMEmitCmp(const Value *Src1Value, const Value *Src2Value, |
| 1337 | bool isZExt) { |
Chad Rosier | ade6200 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1338 | Type *Ty = Src1Value->getType(); |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1339 | EVT SrcVT = TLI.getValueType(Ty, true); |
| 1340 | if (!SrcVT.isSimple()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1341 | |
Chad Rosier | ade6200 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1342 | bool isFloat = (Ty->isFloatTy() || Ty->isDoubleTy()); |
| 1343 | if (isFloat && !Subtarget->hasVFP2()) |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1344 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1345 | |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1346 | // Check to see if the 2nd operand is a constant that we can encode directly |
| 1347 | // in the compare. |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1348 | int Imm = 0; |
| 1349 | bool UseImm = false; |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1350 | bool isNegativeImm = false; |
Chad Rosier | f56c60b | 2011-11-16 00:32:20 +0000 | [diff] [blame] | 1351 | // FIXME: At -O0 we don't have anything that canonicalizes operand order. |
| 1352 | // Thus, Src1Value may be a ConstantInt, but we're missing it. |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1353 | if (const ConstantInt *ConstInt = dyn_cast<ConstantInt>(Src2Value)) { |
| 1354 | if (SrcVT == MVT::i32 || SrcVT == MVT::i16 || SrcVT == MVT::i8 || |
| 1355 | SrcVT == MVT::i1) { |
| 1356 | const APInt &CIVal = ConstInt->getValue(); |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1357 | Imm = (isZExt) ? (int)CIVal.getZExtValue() : (int)CIVal.getSExtValue(); |
| 1358 | if (Imm < 0) { |
Chad Rosier | 6cba97c | 2011-11-10 01:30:39 +0000 | [diff] [blame] | 1359 | isNegativeImm = true; |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1360 | Imm = -Imm; |
Chad Rosier | 6cba97c | 2011-11-10 01:30:39 +0000 | [diff] [blame] | 1361 | } |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1362 | UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) : |
| 1363 | (ARM_AM::getSOImmVal(Imm) != -1); |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1364 | } |
| 1365 | } else if (const ConstantFP *ConstFP = dyn_cast<ConstantFP>(Src2Value)) { |
| 1366 | if (SrcVT == MVT::f32 || SrcVT == MVT::f64) |
| 1367 | if (ConstFP->isZero() && !ConstFP->isNegative()) |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1368 | UseImm = true; |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1371 | unsigned CmpOpc; |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1372 | bool isICmp = true; |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1373 | bool needsExt = false; |
| 1374 | switch (SrcVT.getSimpleVT().SimpleTy) { |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1375 | default: return false; |
| 1376 | // TODO: Verify compares. |
| 1377 | case MVT::f32: |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1378 | isICmp = false; |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1379 | CmpOpc = UseImm ? ARM::VCMPEZS : ARM::VCMPES; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1380 | break; |
| 1381 | case MVT::f64: |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1382 | isICmp = false; |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1383 | CmpOpc = UseImm ? ARM::VCMPEZD : ARM::VCMPED; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1384 | break; |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1385 | case MVT::i1: |
| 1386 | case MVT::i8: |
| 1387 | case MVT::i16: |
| 1388 | needsExt = true; |
| 1389 | // Intentional fall-through. |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1390 | case MVT::i32: |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1391 | if (isThumb2) { |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1392 | if (!UseImm) |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1393 | CmpOpc = ARM::t2CMPrr; |
| 1394 | else |
| 1395 | CmpOpc = isNegativeImm ? ARM::t2CMNzri : ARM::t2CMPri; |
| 1396 | } else { |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1397 | if (!UseImm) |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1398 | CmpOpc = ARM::CMPrr; |
| 1399 | else |
| 1400 | CmpOpc = isNegativeImm ? ARM::CMNzri : ARM::CMPri; |
| 1401 | } |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1402 | break; |
| 1403 | } |
| 1404 | |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1405 | unsigned SrcReg1 = getRegForValue(Src1Value); |
| 1406 | if (SrcReg1 == 0) return false; |
Chad Rosier | 530f7ce | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1407 | |
Duncan Sands | 4c0c545 | 2011-11-28 10:31:27 +0000 | [diff] [blame] | 1408 | unsigned SrcReg2 = 0; |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1409 | if (!UseImm) { |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1410 | SrcReg2 = getRegForValue(Src2Value); |
| 1411 | if (SrcReg2 == 0) return false; |
| 1412 | } |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1413 | |
| 1414 | // We have i1, i8, or i16, we need to either zero extend or sign extend. |
| 1415 | if (needsExt) { |
| 1416 | unsigned ResultReg; |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1417 | ResultReg = ARMEmitIntExt(SrcVT, SrcReg1, MVT::i32, isZExt); |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1418 | if (ResultReg == 0) return false; |
| 1419 | SrcReg1 = ResultReg; |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1420 | if (!UseImm) { |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1421 | ResultReg = ARMEmitIntExt(SrcVT, SrcReg2, MVT::i32, isZExt); |
| 1422 | if (ResultReg == 0) return false; |
| 1423 | SrcReg2 = ResultReg; |
| 1424 | } |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1425 | } |
Chad Rosier | 530f7ce | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1426 | |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1427 | if (!UseImm) { |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1428 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1429 | TII.get(CmpOpc)) |
| 1430 | .addReg(SrcReg1).addReg(SrcReg2)); |
| 1431 | } else { |
| 1432 | MachineInstrBuilder MIB; |
| 1433 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 1434 | .addReg(SrcReg1); |
| 1435 | |
| 1436 | // Only add immediate for icmp as the immediate for fcmp is an implicit 0.0. |
| 1437 | if (isICmp) |
Chad Rosier | 1c47de8 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1438 | MIB.addImm(Imm); |
Chad Rosier | 2f2fe41 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1439 | AddOptionalDefs(MIB); |
| 1440 | } |
Chad Rosier | ade6200 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1441 | |
| 1442 | // For floating point we need to move the result to a comparison register |
| 1443 | // that we can then use for branches. |
| 1444 | if (Ty->isFloatTy() || Ty->isDoubleTy()) |
| 1445 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1446 | TII.get(ARM::FMSTAT))); |
Chad Rosier | 530f7ce | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1447 | return true; |
| 1448 | } |
| 1449 | |
| 1450 | bool ARMFastISel::SelectCmp(const Instruction *I) { |
| 1451 | const CmpInst *CI = cast<CmpInst>(I); |
Chad Rosier | ade6200 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1452 | Type *Ty = CI->getOperand(0)->getType(); |
Chad Rosier | 530f7ce | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1453 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1454 | // Get the compare predicate. |
| 1455 | ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate()); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1456 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1457 | // We may not handle every CC for now. |
| 1458 | if (ARMPred == ARMCC::AL) return false; |
| 1459 | |
Chad Rosier | 530f7ce | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1460 | // Emit the compare. |
Chad Rosier | e07cd5e | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1461 | if (!ARMEmitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned())) |
Chad Rosier | 530f7ce | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1462 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1463 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1464 | // Now set a register based on the comparison. Explicitly set the predicates |
| 1465 | // here. |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1466 | unsigned MovCCOpc = isThumb2 ? ARM::t2MOVCCi : ARM::MOVCCi; |
| 1467 | TargetRegisterClass *RC = isThumb2 ? ARM::rGPRRegisterClass |
Eric Christopher | 5d18d92 | 2010-10-07 05:39:19 +0000 | [diff] [blame] | 1468 | : ARM::GPRRegisterClass; |
| 1469 | unsigned DestReg = createResultReg(RC); |
Chad Rosier | ade6200 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1470 | Constant *Zero = ConstantInt::get(Type::getInt32Ty(*Context), 0); |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1471 | unsigned ZeroReg = TargetMaterializeConstant(Zero); |
Chad Rosier | ade6200 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1472 | bool isFloat = (Ty->isFloatTy() || Ty->isDoubleTy()); |
Chad Rosier | 530f7ce | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1473 | unsigned CondReg = isFloat ? ARM::FPSCR : ARM::CPSR; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1474 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), DestReg) |
| 1475 | .addReg(ZeroReg).addImm(1) |
| 1476 | .addImm(ARMPred).addReg(CondReg); |
| 1477 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1478 | UpdateValueMap(I, DestReg); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1479 | return true; |
| 1480 | } |
| 1481 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1482 | bool ARMFastISel::SelectFPExt(const Instruction *I) { |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1483 | // Make sure we have VFP and that we're extending float to double. |
| 1484 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1485 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1486 | Value *V = I->getOperand(0); |
| 1487 | if (!I->getType()->isDoubleTy() || |
| 1488 | !V->getType()->isFloatTy()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1489 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1490 | unsigned Op = getRegForValue(V); |
| 1491 | if (Op == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1492 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1493 | unsigned Result = createResultReg(ARM::DPRRegisterClass); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1494 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 1495 | TII.get(ARM::VCVTDS), Result) |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1496 | .addReg(Op)); |
| 1497 | UpdateValueMap(I, Result); |
| 1498 | return true; |
| 1499 | } |
| 1500 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1501 | bool ARMFastISel::SelectFPTrunc(const Instruction *I) { |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1502 | // Make sure we have VFP and that we're truncating double to float. |
| 1503 | if (!Subtarget->hasVFP2()) return false; |
| 1504 | |
| 1505 | Value *V = I->getOperand(0); |
Eric Christopher | 022b7fb | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1506 | if (!(I->getType()->isFloatTy() && |
| 1507 | V->getType()->isDoubleTy())) return false; |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1508 | |
| 1509 | unsigned Op = getRegForValue(V); |
| 1510 | if (Op == 0) return false; |
| 1511 | |
| 1512 | unsigned Result = createResultReg(ARM::SPRRegisterClass); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1513 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 1514 | TII.get(ARM::VCVTSD), Result) |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1515 | .addReg(Op)); |
| 1516 | UpdateValueMap(I, Result); |
| 1517 | return true; |
| 1518 | } |
| 1519 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1520 | bool ARMFastISel::SelectSIToFP(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1521 | // Make sure we have VFP. |
| 1522 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1523 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1524 | MVT DstVT; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1525 | Type *Ty = I->getType(); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1526 | if (!isTypeLegal(Ty, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1527 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1528 | |
Chad Rosier | 463fe24 | 2011-11-03 02:04:59 +0000 | [diff] [blame] | 1529 | Value *Src = I->getOperand(0); |
| 1530 | EVT SrcVT = TLI.getValueType(Src->getType(), true); |
| 1531 | if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8) |
Eli Friedman | 783c664 | 2011-05-25 19:09:45 +0000 | [diff] [blame] | 1532 | return false; |
| 1533 | |
Chad Rosier | 463fe24 | 2011-11-03 02:04:59 +0000 | [diff] [blame] | 1534 | unsigned SrcReg = getRegForValue(Src); |
| 1535 | if (SrcReg == 0) return false; |
| 1536 | |
| 1537 | // Handle sign-extension. |
| 1538 | if (SrcVT == MVT::i16 || SrcVT == MVT::i8) { |
| 1539 | EVT DestVT = MVT::i32; |
| 1540 | unsigned ResultReg = ARMEmitIntExt(SrcVT, SrcReg, DestVT, /*isZExt*/ false); |
| 1541 | if (ResultReg == 0) return false; |
| 1542 | SrcReg = ResultReg; |
| 1543 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1544 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1545 | // The conversion routine works on fp-reg to fp-reg and the operand above |
| 1546 | // was an integer, move it to the fp registers if possible. |
Chad Rosier | 463fe24 | 2011-11-03 02:04:59 +0000 | [diff] [blame] | 1547 | unsigned FP = ARMMoveToFPReg(MVT::f32, SrcReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1548 | if (FP == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1549 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1550 | unsigned Opc; |
| 1551 | if (Ty->isFloatTy()) Opc = ARM::VSITOS; |
| 1552 | else if (Ty->isDoubleTy()) Opc = ARM::VSITOD; |
Chad Rosier | dd1e751 | 2011-08-31 23:49:05 +0000 | [diff] [blame] | 1553 | else return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1554 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1555 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1556 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 1557 | ResultReg) |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1558 | .addReg(FP)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1559 | UpdateValueMap(I, ResultReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1560 | return true; |
| 1561 | } |
| 1562 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1563 | bool ARMFastISel::SelectFPToSI(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1564 | // Make sure we have VFP. |
| 1565 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1566 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1567 | MVT DstVT; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1568 | Type *RetTy = I->getType(); |
Eric Christopher | 920a208 | 2010-09-10 00:35:09 +0000 | [diff] [blame] | 1569 | if (!isTypeLegal(RetTy, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1570 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1571 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1572 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 1573 | if (Op == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1574 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1575 | unsigned Opc; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1576 | Type *OpTy = I->getOperand(0)->getType(); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1577 | if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS; |
| 1578 | else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD; |
Chad Rosier | dd1e751 | 2011-08-31 23:49:05 +0000 | [diff] [blame] | 1579 | else return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1580 | |
Eric Christopher | 022b7fb | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1581 | // f64->s32 or f32->s32 both need an intermediate f32 reg. |
| 1582 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1583 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 1584 | ResultReg) |
| 1585 | .addReg(Op)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1586 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1587 | // This result needs to be in an integer register, but the conversion only |
| 1588 | // takes place in fp-regs. |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1589 | unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1590 | if (IntReg == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1591 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1592 | UpdateValueMap(I, IntReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1593 | return true; |
| 1594 | } |
| 1595 | |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1596 | bool ARMFastISel::SelectSelect(const Instruction *I) { |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1597 | MVT VT; |
| 1598 | if (!isTypeLegal(I->getType(), VT)) |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1599 | return false; |
| 1600 | |
| 1601 | // Things need to be register sized for register moves. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1602 | if (VT != MVT::i32) return false; |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1603 | const TargetRegisterClass *RC = TLI.getRegClassFor(VT); |
| 1604 | |
| 1605 | unsigned CondReg = getRegForValue(I->getOperand(0)); |
| 1606 | if (CondReg == 0) return false; |
| 1607 | unsigned Op1Reg = getRegForValue(I->getOperand(1)); |
| 1608 | if (Op1Reg == 0) return false; |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1609 | |
Chad Rosier | a07d3fc | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1610 | // Check to see if we can use an immediate in the conditional move. |
| 1611 | int Imm = 0; |
| 1612 | bool UseImm = false; |
| 1613 | bool isNegativeImm = false; |
| 1614 | if (const ConstantInt *ConstInt = dyn_cast<ConstantInt>(I->getOperand(2))) { |
| 1615 | assert (VT == MVT::i32 && "Expecting an i32."); |
| 1616 | Imm = (int)ConstInt->getValue().getZExtValue(); |
| 1617 | if (Imm < 0) { |
| 1618 | isNegativeImm = true; |
| 1619 | Imm = ~Imm; |
| 1620 | } |
| 1621 | UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) : |
| 1622 | (ARM_AM::getSOImmVal(Imm) != -1); |
| 1623 | } |
| 1624 | |
Duncan Sands | 4c0c545 | 2011-11-28 10:31:27 +0000 | [diff] [blame] | 1625 | unsigned Op2Reg = 0; |
Chad Rosier | a07d3fc | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1626 | if (!UseImm) { |
| 1627 | Op2Reg = getRegForValue(I->getOperand(2)); |
| 1628 | if (Op2Reg == 0) return false; |
| 1629 | } |
| 1630 | |
| 1631 | unsigned CmpOpc = isThumb2 ? ARM::t2CMPri : ARM::CMPri; |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1632 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
Chad Rosier | a07d3fc | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1633 | .addReg(CondReg).addImm(0)); |
| 1634 | |
| 1635 | unsigned MovCCOpc; |
| 1636 | if (!UseImm) { |
| 1637 | MovCCOpc = isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr; |
| 1638 | } else { |
| 1639 | if (!isNegativeImm) { |
| 1640 | MovCCOpc = isThumb2 ? ARM::t2MOVCCi : ARM::MOVCCi; |
| 1641 | } else { |
| 1642 | MovCCOpc = isThumb2 ? ARM::t2MVNCCi : ARM::MVNCCi; |
| 1643 | } |
| 1644 | } |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1645 | unsigned ResultReg = createResultReg(RC); |
Chad Rosier | a07d3fc | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1646 | if (!UseImm) |
| 1647 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), ResultReg) |
| 1648 | .addReg(Op2Reg).addReg(Op1Reg).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 1649 | else |
| 1650 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), ResultReg) |
| 1651 | .addReg(Op1Reg).addImm(Imm).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1652 | UpdateValueMap(I, ResultReg); |
| 1653 | return true; |
| 1654 | } |
| 1655 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1656 | bool ARMFastISel::SelectSDiv(const Instruction *I) { |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1657 | MVT VT; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1658 | Type *Ty = I->getType(); |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1659 | if (!isTypeLegal(Ty, VT)) |
| 1660 | return false; |
| 1661 | |
| 1662 | // If we have integer div support we should have selected this automagically. |
| 1663 | // In case we have a real miss go ahead and return false and we'll pick |
| 1664 | // it up later. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1665 | if (Subtarget->hasDivide()) return false; |
| 1666 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1667 | // Otherwise emit a libcall. |
| 1668 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Eric Christopher | 7bdc4de | 2010-10-11 08:31:54 +0000 | [diff] [blame] | 1669 | if (VT == MVT::i8) |
| 1670 | LC = RTLIB::SDIV_I8; |
| 1671 | else if (VT == MVT::i16) |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1672 | LC = RTLIB::SDIV_I16; |
| 1673 | else if (VT == MVT::i32) |
| 1674 | LC = RTLIB::SDIV_I32; |
| 1675 | else if (VT == MVT::i64) |
| 1676 | LC = RTLIB::SDIV_I64; |
| 1677 | else if (VT == MVT::i128) |
| 1678 | LC = RTLIB::SDIV_I128; |
| 1679 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!"); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1680 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1681 | return ARMEmitLibcall(I, LC); |
| 1682 | } |
| 1683 | |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1684 | bool ARMFastISel::SelectSRem(const Instruction *I) { |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1685 | MVT VT; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1686 | Type *Ty = I->getType(); |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1687 | if (!isTypeLegal(Ty, VT)) |
| 1688 | return false; |
| 1689 | |
| 1690 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 1691 | if (VT == MVT::i8) |
| 1692 | LC = RTLIB::SREM_I8; |
| 1693 | else if (VT == MVT::i16) |
| 1694 | LC = RTLIB::SREM_I16; |
| 1695 | else if (VT == MVT::i32) |
| 1696 | LC = RTLIB::SREM_I32; |
| 1697 | else if (VT == MVT::i64) |
| 1698 | LC = RTLIB::SREM_I64; |
| 1699 | else if (VT == MVT::i128) |
| 1700 | LC = RTLIB::SREM_I128; |
Eric Christopher | a1640d9 | 2010-10-11 08:40:05 +0000 | [diff] [blame] | 1701 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!"); |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 1702 | |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1703 | return ARMEmitLibcall(I, LC); |
| 1704 | } |
| 1705 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1706 | bool ARMFastISel::SelectBinaryOp(const Instruction *I, unsigned ISDOpcode) { |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1707 | EVT VT = TLI.getValueType(I->getType(), true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1708 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1709 | // We can get here in the case when we want to use NEON for our fp |
| 1710 | // operations, but can't figure out how to. Just use the vfp instructions |
| 1711 | // if we have them. |
| 1712 | // FIXME: It'd be nice to use NEON instructions. |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1713 | Type *Ty = I->getType(); |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1714 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 1715 | if (isFloat && !Subtarget->hasVFP2()) |
| 1716 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1717 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1718 | unsigned Opc; |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 1719 | bool is64bit = VT == MVT::f64 || VT == MVT::i64; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1720 | switch (ISDOpcode) { |
| 1721 | default: return false; |
| 1722 | case ISD::FADD: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1723 | Opc = is64bit ? ARM::VADDD : ARM::VADDS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1724 | break; |
| 1725 | case ISD::FSUB: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1726 | Opc = is64bit ? ARM::VSUBD : ARM::VSUBS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1727 | break; |
| 1728 | case ISD::FMUL: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1729 | Opc = is64bit ? ARM::VMULD : ARM::VMULS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1730 | break; |
| 1731 | } |
Chad Rosier | 508a1f4 | 2011-11-16 18:39:44 +0000 | [diff] [blame] | 1732 | unsigned Op1 = getRegForValue(I->getOperand(0)); |
| 1733 | if (Op1 == 0) return false; |
| 1734 | |
| 1735 | unsigned Op2 = getRegForValue(I->getOperand(1)); |
| 1736 | if (Op2 == 0) return false; |
| 1737 | |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1738 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1739 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1740 | TII.get(Opc), ResultReg) |
| 1741 | .addReg(Op1).addReg(Op2)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1742 | UpdateValueMap(I, ResultReg); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1743 | return true; |
| 1744 | } |
| 1745 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1746 | // Call Handling Code |
| 1747 | |
| 1748 | // This is largely taken directly from CCAssignFnForNode - we don't support |
| 1749 | // varargs in FastISel so that part has been removed. |
| 1750 | // TODO: We may not support all of this. |
| 1751 | CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) { |
| 1752 | switch (CC) { |
| 1753 | default: |
| 1754 | llvm_unreachable("Unsupported calling convention"); |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1755 | case CallingConv::Fast: |
Evan Cheng | 1f8b40d | 2010-10-22 18:57:05 +0000 | [diff] [blame] | 1756 | // Ignore fastcc. Silence compiler warnings. |
| 1757 | (void)RetFastCC_ARM_APCS; |
| 1758 | (void)FastCC_ARM_APCS; |
| 1759 | // Fallthrough |
| 1760 | case CallingConv::C: |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1761 | // Use target triple & subtarget features to do actual dispatch. |
| 1762 | if (Subtarget->isAAPCS_ABI()) { |
| 1763 | if (Subtarget->hasVFP2() && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1764 | TM.Options.FloatABIType == FloatABI::Hard) |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1765 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1766 | else |
| 1767 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1768 | } else |
| 1769 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1770 | case CallingConv::ARM_AAPCS_VFP: |
| 1771 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1772 | case CallingConv::ARM_AAPCS: |
| 1773 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1774 | case CallingConv::ARM_APCS: |
| 1775 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1776 | } |
| 1777 | } |
| 1778 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1779 | bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
| 1780 | SmallVectorImpl<unsigned> &ArgRegs, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1781 | SmallVectorImpl<MVT> &ArgVTs, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1782 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 1783 | SmallVectorImpl<unsigned> &RegArgs, |
| 1784 | CallingConv::ID CC, |
| 1785 | unsigned &NumBytes) { |
| 1786 | SmallVector<CCValAssign, 16> ArgLocs; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 1787 | CCState CCInfo(CC, false, *FuncInfo.MF, TM, ArgLocs, *Context); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1788 | CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC, false)); |
| 1789 | |
| 1790 | // Get a count of how many bytes are to be pushed on the stack. |
| 1791 | NumBytes = CCInfo.getNextStackOffset(); |
| 1792 | |
| 1793 | // Issue CALLSEQ_START |
Evan Cheng | d5b03f2 | 2011-06-28 21:14:33 +0000 | [diff] [blame] | 1794 | unsigned AdjStackDown = TII.getCallFrameSetupOpcode(); |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 1795 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1796 | TII.get(AdjStackDown)) |
| 1797 | .addImm(NumBytes)); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1798 | |
| 1799 | // Process the args. |
| 1800 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1801 | CCValAssign &VA = ArgLocs[i]; |
| 1802 | unsigned Arg = ArgRegs[VA.getValNo()]; |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1803 | MVT ArgVT = ArgVTs[VA.getValNo()]; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1804 | |
Eric Christopher | 4a2b316 | 2011-01-27 05:44:56 +0000 | [diff] [blame] | 1805 | // We don't handle NEON/vector parameters yet. |
| 1806 | if (ArgVT.isVector() || ArgVT.getSizeInBits() > 64) |
Eric Christopher | a4633f5 | 2010-10-23 09:37:17 +0000 | [diff] [blame] | 1807 | return false; |
| 1808 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1809 | // Handle arg promotion, etc. |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1810 | switch (VA.getLocInfo()) { |
| 1811 | case CCValAssign::Full: break; |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1812 | case CCValAssign::SExt: { |
Chad Rosier | b74c865 | 2011-12-02 20:25:18 +0000 | [diff] [blame] | 1813 | MVT DestVT = VA.getLocVT(); |
Chad Rosier | 42536af | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 1814 | unsigned ResultReg = ARMEmitIntExt(ArgVT, Arg, DestVT, |
| 1815 | /*isZExt*/false); |
| 1816 | assert (ResultReg != 0 && "Failed to emit a sext"); |
| 1817 | Arg = ResultReg; |
Chad Rosier | b74c865 | 2011-12-02 20:25:18 +0000 | [diff] [blame] | 1818 | ArgVT = DestVT; |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1819 | break; |
| 1820 | } |
Chad Rosier | 42536af | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 1821 | case CCValAssign::AExt: |
| 1822 | // Intentional fall-through. Handle AExt and ZExt. |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1823 | case CCValAssign::ZExt: { |
Chad Rosier | b74c865 | 2011-12-02 20:25:18 +0000 | [diff] [blame] | 1824 | MVT DestVT = VA.getLocVT(); |
Chad Rosier | 42536af | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 1825 | unsigned ResultReg = ARMEmitIntExt(ArgVT, Arg, DestVT, |
| 1826 | /*isZExt*/true); |
| 1827 | assert (ResultReg != 0 && "Failed to emit a sext"); |
| 1828 | Arg = ResultReg; |
Chad Rosier | b74c865 | 2011-12-02 20:25:18 +0000 | [diff] [blame] | 1829 | ArgVT = DestVT; |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1830 | break; |
| 1831 | } |
| 1832 | case CCValAssign::BCvt: { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1833 | unsigned BC = FastEmit_r(ArgVT, VA.getLocVT(), ISD::BITCAST, Arg, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1834 | /*TODO: Kill=*/false); |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1835 | assert(BC != 0 && "Failed to emit a bitcast!"); |
| 1836 | Arg = BC; |
| 1837 | ArgVT = VA.getLocVT(); |
| 1838 | break; |
| 1839 | } |
| 1840 | default: llvm_unreachable("Unknown arg promotion!"); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | // Now copy/store arg to correct locations. |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 1844 | if (VA.isRegLoc() && !VA.needsCustom()) { |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1845 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1846 | VA.getLocReg()) |
Chad Rosier | 42536af | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 1847 | .addReg(Arg); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1848 | RegArgs.push_back(VA.getLocReg()); |
Eric Christopher | 2d8f6fe | 2010-10-21 00:01:47 +0000 | [diff] [blame] | 1849 | } else if (VA.needsCustom()) { |
| 1850 | // TODO: We need custom lowering for vector (v2f64) args. |
| 1851 | if (VA.getLocVT() != MVT::f64) return false; |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1852 | |
Eric Christopher | 2d8f6fe | 2010-10-21 00:01:47 +0000 | [diff] [blame] | 1853 | CCValAssign &NextVA = ArgLocs[++i]; |
| 1854 | |
| 1855 | // TODO: Only handle register args for now. |
| 1856 | if(!(VA.isRegLoc() && NextVA.isRegLoc())) return false; |
| 1857 | |
| 1858 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1859 | TII.get(ARM::VMOVRRD), VA.getLocReg()) |
| 1860 | .addReg(NextVA.getLocReg(), RegState::Define) |
| 1861 | .addReg(Arg)); |
| 1862 | RegArgs.push_back(VA.getLocReg()); |
| 1863 | RegArgs.push_back(NextVA.getLocReg()); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1864 | } else { |
Eric Christopher | 5b92480 | 2010-10-21 20:09:54 +0000 | [diff] [blame] | 1865 | assert(VA.isMemLoc()); |
| 1866 | // Need to store on the stack. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1867 | Address Addr; |
| 1868 | Addr.BaseType = Address::RegBase; |
| 1869 | Addr.Base.Reg = ARM::SP; |
| 1870 | Addr.Offset = VA.getLocMemOffset(); |
Eric Christopher | 5b92480 | 2010-10-21 20:09:54 +0000 | [diff] [blame] | 1871 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1872 | if (!ARMEmitStore(ArgVT, Arg, Addr)) return false; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1873 | } |
| 1874 | } |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1875 | return true; |
| 1876 | } |
| 1877 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1878 | bool ARMFastISel::FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1879 | const Instruction *I, CallingConv::ID CC, |
| 1880 | unsigned &NumBytes) { |
| 1881 | // Issue CALLSEQ_END |
Evan Cheng | d5b03f2 | 2011-06-28 21:14:33 +0000 | [diff] [blame] | 1882 | unsigned AdjStackUp = TII.getCallFrameDestroyOpcode(); |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 1883 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1884 | TII.get(AdjStackUp)) |
| 1885 | .addImm(NumBytes).addImm(0)); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1886 | |
| 1887 | // Now the return value. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1888 | if (RetVT != MVT::isVoid) { |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1889 | SmallVector<CCValAssign, 16> RVLocs; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 1890 | CCState CCInfo(CC, false, *FuncInfo.MF, TM, RVLocs, *Context); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1891 | CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true)); |
| 1892 | |
| 1893 | // Copy all of the result registers out of their specified physreg. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1894 | if (RVLocs.size() == 2 && RetVT == MVT::f64) { |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1895 | // For this move we copy into two registers and then move into the |
| 1896 | // double fp reg we want. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1897 | EVT DestVT = RVLocs[0].getValVT(); |
| 1898 | TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT); |
| 1899 | unsigned ResultReg = createResultReg(DstRC); |
| 1900 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1901 | TII.get(ARM::VMOVDRR), ResultReg) |
Eric Christopher | 3659ac2 | 2010-10-20 08:02:24 +0000 | [diff] [blame] | 1902 | .addReg(RVLocs[0].getLocReg()) |
| 1903 | .addReg(RVLocs[1].getLocReg())); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1904 | |
Eric Christopher | 3659ac2 | 2010-10-20 08:02:24 +0000 | [diff] [blame] | 1905 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
| 1906 | UsedRegs.push_back(RVLocs[1].getLocReg()); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1907 | |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1908 | // Finally update the result. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1909 | UpdateValueMap(I, ResultReg); |
| 1910 | } else { |
Jim Grosbach | 9536959 | 2010-10-13 23:34:31 +0000 | [diff] [blame] | 1911 | assert(RVLocs.size() == 1 &&"Can't handle non-double multi-reg retvals!"); |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1912 | EVT CopyVT = RVLocs[0].getValVT(); |
Chad Rosier | 0eff39f | 2011-11-08 00:03:32 +0000 | [diff] [blame] | 1913 | |
| 1914 | // Special handling for extended integers. |
| 1915 | if (RetVT == MVT::i1 || RetVT == MVT::i8 || RetVT == MVT::i16) |
| 1916 | CopyVT = MVT::i32; |
| 1917 | |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1918 | TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1919 | |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1920 | unsigned ResultReg = createResultReg(DstRC); |
| 1921 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1922 | ResultReg).addReg(RVLocs[0].getLocReg()); |
| 1923 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1924 | |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1925 | // Finally update the result. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1926 | UpdateValueMap(I, ResultReg); |
| 1927 | } |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1930 | return true; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1933 | bool ARMFastISel::SelectRet(const Instruction *I) { |
| 1934 | const ReturnInst *Ret = cast<ReturnInst>(I); |
| 1935 | const Function &F = *I->getParent()->getParent(); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1936 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1937 | if (!FuncInfo.CanLowerReturn) |
| 1938 | return false; |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1939 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1940 | if (F.isVarArg()) |
| 1941 | return false; |
| 1942 | |
| 1943 | CallingConv::ID CC = F.getCallingConv(); |
| 1944 | if (Ret->getNumOperands() > 0) { |
| 1945 | SmallVector<ISD::OutputArg, 4> Outs; |
| 1946 | GetReturnInfo(F.getReturnType(), F.getAttributes().getRetAttributes(), |
| 1947 | Outs, TLI); |
| 1948 | |
| 1949 | // Analyze operands of the call, assigning locations to each operand. |
| 1950 | SmallVector<CCValAssign, 16> ValLocs; |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 1951 | CCState CCInfo(CC, F.isVarArg(), *FuncInfo.MF, TM, ValLocs,I->getContext()); |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1952 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForCall(CC, true /* is Ret */)); |
| 1953 | |
| 1954 | const Value *RV = Ret->getOperand(0); |
| 1955 | unsigned Reg = getRegForValue(RV); |
| 1956 | if (Reg == 0) |
| 1957 | return false; |
| 1958 | |
| 1959 | // Only handle a single return value for now. |
| 1960 | if (ValLocs.size() != 1) |
| 1961 | return false; |
| 1962 | |
| 1963 | CCValAssign &VA = ValLocs[0]; |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1964 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1965 | // Don't bother handling odd stuff for now. |
| 1966 | if (VA.getLocInfo() != CCValAssign::Full) |
| 1967 | return false; |
| 1968 | // Only handle register returns for now. |
| 1969 | if (!VA.isRegLoc()) |
| 1970 | return false; |
Chad Rosier | f470cbb | 2011-11-04 00:50:21 +0000 | [diff] [blame] | 1971 | |
| 1972 | unsigned SrcReg = Reg + VA.getValNo(); |
| 1973 | EVT RVVT = TLI.getValueType(RV->getType()); |
| 1974 | EVT DestVT = VA.getValVT(); |
| 1975 | // Special handling for extended integers. |
| 1976 | if (RVVT != DestVT) { |
| 1977 | if (RVVT != MVT::i1 && RVVT != MVT::i8 && RVVT != MVT::i16) |
| 1978 | return false; |
| 1979 | |
| 1980 | if (!Outs[0].Flags.isZExt() && !Outs[0].Flags.isSExt()) |
| 1981 | return false; |
| 1982 | |
| 1983 | assert(DestVT == MVT::i32 && "ARM should always ext to i32"); |
| 1984 | |
| 1985 | bool isZExt = Outs[0].Flags.isZExt(); |
| 1986 | unsigned ResultReg = ARMEmitIntExt(RVVT, SrcReg, DestVT, isZExt); |
| 1987 | if (ResultReg == 0) return false; |
| 1988 | SrcReg = ResultReg; |
| 1989 | } |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1990 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1991 | // Make the copy. |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1992 | unsigned DstReg = VA.getLocReg(); |
| 1993 | const TargetRegisterClass* SrcRC = MRI.getRegClass(SrcReg); |
| 1994 | // Avoid a cross-class copy. This is very unlikely. |
| 1995 | if (!SrcRC->contains(DstReg)) |
| 1996 | return false; |
| 1997 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1998 | DstReg).addReg(SrcReg); |
| 1999 | |
| 2000 | // Mark the register as live out of the function. |
| 2001 | MRI.addLiveOut(VA.getLocReg()); |
| 2002 | } |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 2003 | |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2004 | unsigned RetOpc = isThumb2 ? ARM::tBX_RET : ARM::BX_RET; |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2005 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 2006 | TII.get(RetOpc))); |
| 2007 | return true; |
| 2008 | } |
| 2009 | |
Eric Christopher | 872f4a2 | 2011-02-22 01:37:10 +0000 | [diff] [blame] | 2010 | unsigned ARMFastISel::ARMSelectCallOp(const GlobalValue *GV) { |
| 2011 | |
Eric Christopher | 872f4a2 | 2011-02-22 01:37:10 +0000 | [diff] [blame] | 2012 | // Darwin needs the r9 versions of the opcodes. |
| 2013 | bool isDarwin = Subtarget->isTargetDarwin(); |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2014 | if (isThumb2) { |
Eric Christopher | 872f4a2 | 2011-02-22 01:37:10 +0000 | [diff] [blame] | 2015 | return isDarwin ? ARM::tBLr9 : ARM::tBL; |
| 2016 | } else { |
| 2017 | return isDarwin ? ARM::BLr9 : ARM::BL; |
| 2018 | } |
| 2019 | } |
| 2020 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2021 | // A quick function that will emit a call for a named libcall in F with the |
| 2022 | // vector of passed arguments for the Instruction in I. We can assume that we |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2023 | // can emit a call for any libcall we can produce. This is an abridged version |
| 2024 | // of the full call infrastructure since we won't need to worry about things |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2025 | // like computed function pointers or strange arguments at call sites. |
| 2026 | // TODO: Try to unify this and the normal call bits for ARM, then try to unify |
| 2027 | // with X86. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 2028 | bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) { |
| 2029 | CallingConv::ID CC = TLI.getLibcallCallingConv(Call); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2030 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2031 | // Handle *simple* calls for now. |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2032 | Type *RetTy = I->getType(); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2033 | MVT RetVT; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2034 | if (RetTy->isVoidTy()) |
| 2035 | RetVT = MVT::isVoid; |
| 2036 | else if (!isTypeLegal(RetTy, RetVT)) |
| 2037 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2038 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 2039 | // TODO: For now if we have long calls specified we don't handle the call. |
| 2040 | if (EnableARMLongCalls) return false; |
| 2041 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2042 | // Set up the argument vectors. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2043 | SmallVector<Value*, 8> Args; |
| 2044 | SmallVector<unsigned, 8> ArgRegs; |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2045 | SmallVector<MVT, 8> ArgVTs; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2046 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 2047 | Args.reserve(I->getNumOperands()); |
| 2048 | ArgRegs.reserve(I->getNumOperands()); |
| 2049 | ArgVTs.reserve(I->getNumOperands()); |
| 2050 | ArgFlags.reserve(I->getNumOperands()); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 2051 | for (unsigned i = 0; i < I->getNumOperands(); ++i) { |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2052 | Value *Op = I->getOperand(i); |
| 2053 | unsigned Arg = getRegForValue(Op); |
| 2054 | if (Arg == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2055 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2056 | Type *ArgTy = Op->getType(); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2057 | MVT ArgVT; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2058 | if (!isTypeLegal(ArgTy, ArgVT)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2059 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2060 | ISD::ArgFlagsTy Flags; |
| 2061 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 2062 | Flags.setOrigAlign(OriginalAlignment); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2063 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2064 | Args.push_back(Op); |
| 2065 | ArgRegs.push_back(Arg); |
| 2066 | ArgVTs.push_back(ArgVT); |
| 2067 | ArgFlags.push_back(Flags); |
| 2068 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2069 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2070 | // Handle the arguments now that we've gotten them. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2071 | SmallVector<unsigned, 4> RegArgs; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2072 | unsigned NumBytes; |
| 2073 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes)) |
| 2074 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2075 | |
Eric Christopher | 6344a5f | 2011-04-29 00:07:20 +0000 | [diff] [blame] | 2076 | // Issue the call, BLr9 for darwin, BL otherwise. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2077 | // TODO: Turn this into the table of arm call ops. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2078 | MachineInstrBuilder MIB; |
Eric Christopher | 872f4a2 | 2011-02-22 01:37:10 +0000 | [diff] [blame] | 2079 | unsigned CallOpc = ARMSelectCallOp(NULL); |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2080 | if(isThumb2) |
Eric Christopher | c19aadb | 2010-12-21 03:50:43 +0000 | [diff] [blame] | 2081 | // Explicitly adding the predicate here. |
| 2082 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 2083 | TII.get(CallOpc))) |
| 2084 | .addExternalSymbol(TLI.getLibcallName(Call)); |
Eric Christopher | 872f4a2 | 2011-02-22 01:37:10 +0000 | [diff] [blame] | 2085 | else |
Eric Christopher | c19aadb | 2010-12-21 03:50:43 +0000 | [diff] [blame] | 2086 | // Explicitly adding the predicate here. |
| 2087 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 2088 | TII.get(CallOpc)) |
| 2089 | .addExternalSymbol(TLI.getLibcallName(Call))); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2090 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2091 | // Add implicit physical register uses to the call. |
| 2092 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 2093 | MIB.addReg(RegArgs[i]); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2094 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2095 | // Finish off the call including any return values. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2096 | SmallVector<unsigned, 4> UsedRegs; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2097 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2098 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2099 | // Set all unused physreg defs as dead. |
| 2100 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2101 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2102 | return true; |
| 2103 | } |
| 2104 | |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2105 | bool ARMFastISel::SelectCall(const Instruction *I, |
| 2106 | const char *IntrMemName = 0) { |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2107 | const CallInst *CI = cast<CallInst>(I); |
| 2108 | const Value *Callee = CI->getCalledValue(); |
| 2109 | |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2110 | // Can't handle inline asm. |
| 2111 | if (isa<InlineAsm>(Callee)) return false; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2112 | |
Eric Christopher | 52f6c03 | 2011-05-02 20:16:33 +0000 | [diff] [blame] | 2113 | // Only handle global variable Callees. |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2114 | const GlobalValue *GV = dyn_cast<GlobalValue>(Callee); |
Eric Christopher | 52f6c03 | 2011-05-02 20:16:33 +0000 | [diff] [blame] | 2115 | if (!GV) |
Eric Christopher | e6ca677 | 2010-10-01 21:33:12 +0000 | [diff] [blame] | 2116 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2117 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2118 | // Check the calling convention. |
| 2119 | ImmutableCallSite CS(CI); |
| 2120 | CallingConv::ID CC = CS.getCallingConv(); |
Eric Christopher | 4cf34c6 | 2010-10-18 06:49:12 +0000 | [diff] [blame] | 2121 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2122 | // TODO: Avoid some calling conventions? |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2123 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2124 | // Let SDISel handle vararg functions. |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2125 | PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType()); |
| 2126 | FunctionType *FTy = cast<FunctionType>(PT->getElementType()); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2127 | if (FTy->isVarArg()) |
| 2128 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2129 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2130 | // Handle *simple* calls for now. |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2131 | Type *RetTy = I->getType(); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2132 | MVT RetVT; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2133 | if (RetTy->isVoidTy()) |
| 2134 | RetVT = MVT::isVoid; |
Chad Rosier | 0eff39f | 2011-11-08 00:03:32 +0000 | [diff] [blame] | 2135 | else if (!isTypeLegal(RetTy, RetVT) && RetVT != MVT::i16 && |
| 2136 | RetVT != MVT::i8 && RetVT != MVT::i1) |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2137 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2138 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 2139 | // TODO: For now if we have long calls specified we don't handle the call. |
| 2140 | if (EnableARMLongCalls) return false; |
Eric Christopher | 299bbb2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 2141 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2142 | // Set up the argument vectors. |
| 2143 | SmallVector<Value*, 8> Args; |
| 2144 | SmallVector<unsigned, 8> ArgRegs; |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2145 | SmallVector<MVT, 8> ArgVTs; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2146 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 2147 | Args.reserve(CS.arg_size()); |
| 2148 | ArgRegs.reserve(CS.arg_size()); |
| 2149 | ArgVTs.reserve(CS.arg_size()); |
| 2150 | ArgFlags.reserve(CS.arg_size()); |
| 2151 | for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end(); |
| 2152 | i != e; ++i) { |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2153 | // If we're lowering a memory intrinsic instead of a regular call, skip the |
| 2154 | // last two arguments, which shouldn't be passed to the underlying function. |
| 2155 | if (IntrMemName && e-i <= 2) |
| 2156 | break; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2157 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2158 | ISD::ArgFlagsTy Flags; |
| 2159 | unsigned AttrInd = i - CS.arg_begin() + 1; |
| 2160 | if (CS.paramHasAttr(AttrInd, Attribute::SExt)) |
| 2161 | Flags.setSExt(); |
| 2162 | if (CS.paramHasAttr(AttrInd, Attribute::ZExt)) |
| 2163 | Flags.setZExt(); |
| 2164 | |
Chad Rosier | 8e4a2e4 | 2011-11-04 00:58:10 +0000 | [diff] [blame] | 2165 | // FIXME: Only handle *easy* calls for now. |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2166 | if (CS.paramHasAttr(AttrInd, Attribute::InReg) || |
| 2167 | CS.paramHasAttr(AttrInd, Attribute::StructRet) || |
| 2168 | CS.paramHasAttr(AttrInd, Attribute::Nest) || |
| 2169 | CS.paramHasAttr(AttrInd, Attribute::ByVal)) |
| 2170 | return false; |
| 2171 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2172 | Type *ArgTy = (*i)->getType(); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2173 | MVT ArgVT; |
Chad Rosier | 42536af | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 2174 | if (!isTypeLegal(ArgTy, ArgVT) && ArgVT != MVT::i16 && ArgVT != MVT::i8 && |
| 2175 | ArgVT != MVT::i1) |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2176 | return false; |
Chad Rosier | 424fe0e | 2011-11-18 01:17:34 +0000 | [diff] [blame] | 2177 | |
| 2178 | unsigned Arg = getRegForValue(*i); |
| 2179 | if (Arg == 0) |
| 2180 | return false; |
| 2181 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2182 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 2183 | Flags.setOrigAlign(OriginalAlignment); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2184 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2185 | Args.push_back(*i); |
| 2186 | ArgRegs.push_back(Arg); |
| 2187 | ArgVTs.push_back(ArgVT); |
| 2188 | ArgFlags.push_back(Flags); |
| 2189 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2190 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2191 | // Handle the arguments now that we've gotten them. |
| 2192 | SmallVector<unsigned, 4> RegArgs; |
| 2193 | unsigned NumBytes; |
| 2194 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes)) |
| 2195 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2196 | |
Eric Christopher | 6344a5f | 2011-04-29 00:07:20 +0000 | [diff] [blame] | 2197 | // Issue the call, BLr9 for darwin, BL otherwise. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2198 | // TODO: Turn this into the table of arm call ops. |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2199 | MachineInstrBuilder MIB; |
Eric Christopher | 872f4a2 | 2011-02-22 01:37:10 +0000 | [diff] [blame] | 2200 | unsigned CallOpc = ARMSelectCallOp(GV); |
Eric Christopher | 7bb5996 | 2010-11-29 21:56:23 +0000 | [diff] [blame] | 2201 | // Explicitly adding the predicate here. |
Chad Rosier | 9eb6748 | 2011-11-13 09:44:21 +0000 | [diff] [blame] | 2202 | if(isThumb2) { |
Eric Christopher | c19aadb | 2010-12-21 03:50:43 +0000 | [diff] [blame] | 2203 | // Explicitly adding the predicate here. |
| 2204 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2205 | TII.get(CallOpc))); |
Chad Rosier | 9eb6748 | 2011-11-13 09:44:21 +0000 | [diff] [blame] | 2206 | if (!IntrMemName) |
| 2207 | MIB.addGlobalAddress(GV, 0, 0); |
| 2208 | else |
| 2209 | MIB.addExternalSymbol(IntrMemName, 0); |
| 2210 | } else { |
| 2211 | if (!IntrMemName) |
| 2212 | // Explicitly adding the predicate here. |
| 2213 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 2214 | TII.get(CallOpc)) |
| 2215 | .addGlobalAddress(GV, 0, 0)); |
| 2216 | else |
| 2217 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 2218 | TII.get(CallOpc)) |
| 2219 | .addExternalSymbol(IntrMemName, 0)); |
| 2220 | } |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2221 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2222 | // Add implicit physical register uses to the call. |
| 2223 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 2224 | MIB.addReg(RegArgs[i]); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2225 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2226 | // Finish off the call including any return values. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2227 | SmallVector<unsigned, 4> UsedRegs; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2228 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2229 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2230 | // Set all unused physreg defs as dead. |
| 2231 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2232 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2233 | return true; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
Chad Rosier | 2c42b8c | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2236 | bool ARMFastISel::ARMIsMemCpySmall(uint64_t Len) { |
Chad Rosier | 909cb4f | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2237 | return Len <= 16; |
| 2238 | } |
| 2239 | |
Chad Rosier | 2c42b8c | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2240 | bool ARMFastISel::ARMTryEmitSmallMemCpy(Address Dest, Address Src, uint64_t Len) { |
Chad Rosier | 909cb4f | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2241 | // Make sure we don't bloat code by inlining very large memcpy's. |
Chad Rosier | 2c42b8c | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2242 | if (!ARMIsMemCpySmall(Len)) |
Chad Rosier | 909cb4f | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2243 | return false; |
| 2244 | |
| 2245 | // We don't care about alignment here since we just emit integer accesses. |
| 2246 | while (Len) { |
| 2247 | MVT VT; |
| 2248 | if (Len >= 4) |
| 2249 | VT = MVT::i32; |
| 2250 | else if (Len >= 2) |
| 2251 | VT = MVT::i16; |
| 2252 | else { |
| 2253 | assert(Len == 1); |
| 2254 | VT = MVT::i8; |
| 2255 | } |
| 2256 | |
| 2257 | bool RV; |
| 2258 | unsigned ResultReg; |
| 2259 | RV = ARMEmitLoad(VT, ResultReg, Src); |
| 2260 | assert (RV = true && "Should be able to handle this load."); |
| 2261 | RV = ARMEmitStore(VT, ResultReg, Dest); |
| 2262 | assert (RV = true && "Should be able to handle this store."); |
| 2263 | |
| 2264 | unsigned Size = VT.getSizeInBits()/8; |
| 2265 | Len -= Size; |
| 2266 | Dest.Offset += Size; |
| 2267 | Src.Offset += Size; |
| 2268 | } |
| 2269 | |
| 2270 | return true; |
| 2271 | } |
| 2272 | |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2273 | bool ARMFastISel::SelectIntrinsicCall(const IntrinsicInst &I) { |
| 2274 | // FIXME: Handle more intrinsics. |
| 2275 | switch (I.getIntrinsicID()) { |
| 2276 | default: return false; |
| 2277 | case Intrinsic::memcpy: |
| 2278 | case Intrinsic::memmove: { |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2279 | const MemTransferInst &MTI = cast<MemTransferInst>(I); |
| 2280 | // Don't handle volatile. |
| 2281 | if (MTI.isVolatile()) |
| 2282 | return false; |
Chad Rosier | 909cb4f | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2283 | |
| 2284 | // Disable inlining for memmove before calls to ComputeAddress. Otherwise, |
| 2285 | // we would emit dead code because we don't currently handle memmoves. |
| 2286 | bool isMemCpy = (I.getIntrinsicID() == Intrinsic::memcpy); |
| 2287 | if (isa<ConstantInt>(MTI.getLength()) && isMemCpy) { |
Chad Rosier | 2c42b8c | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2288 | // Small memcpy's are common enough that we want to do them without a call |
| 2289 | // if possible. |
Chad Rosier | 909cb4f | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2290 | uint64_t Len = cast<ConstantInt>(MTI.getLength())->getZExtValue(); |
Chad Rosier | 2c42b8c | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2291 | if (ARMIsMemCpySmall(Len)) { |
Chad Rosier | 909cb4f | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2292 | Address Dest, Src; |
| 2293 | if (!ARMComputeAddress(MTI.getRawDest(), Dest) || |
| 2294 | !ARMComputeAddress(MTI.getRawSource(), Src)) |
| 2295 | return false; |
Chad Rosier | 2c42b8c | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2296 | if (ARMTryEmitSmallMemCpy(Dest, Src, Len)) |
Chad Rosier | 909cb4f | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2297 | return true; |
| 2298 | } |
| 2299 | } |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2300 | |
| 2301 | if (!MTI.getLength()->getType()->isIntegerTy(32)) |
| 2302 | return false; |
| 2303 | |
| 2304 | if (MTI.getSourceAddressSpace() > 255 || MTI.getDestAddressSpace() > 255) |
| 2305 | return false; |
| 2306 | |
| 2307 | const char *IntrMemName = isa<MemCpyInst>(I) ? "memcpy" : "memmove"; |
| 2308 | return SelectCall(&I, IntrMemName); |
| 2309 | } |
| 2310 | case Intrinsic::memset: { |
| 2311 | const MemSetInst &MSI = cast<MemSetInst>(I); |
| 2312 | // Don't handle volatile. |
| 2313 | if (MSI.isVolatile()) |
| 2314 | return false; |
| 2315 | |
| 2316 | if (!MSI.getLength()->getType()->isIntegerTy(32)) |
| 2317 | return false; |
| 2318 | |
| 2319 | if (MSI.getDestAddressSpace() > 255) |
| 2320 | return false; |
| 2321 | |
| 2322 | return SelectCall(&I, "memset"); |
| 2323 | } |
| 2324 | } |
| 2325 | return false; |
| 2326 | } |
| 2327 | |
Chad Rosier | 0d7b231 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 2328 | bool ARMFastISel::SelectTrunc(const Instruction *I) { |
| 2329 | // The high bits for a type smaller than the register size are assumed to be |
| 2330 | // undefined. |
| 2331 | Value *Op = I->getOperand(0); |
| 2332 | |
| 2333 | EVT SrcVT, DestVT; |
| 2334 | SrcVT = TLI.getValueType(Op->getType(), true); |
| 2335 | DestVT = TLI.getValueType(I->getType(), true); |
| 2336 | |
| 2337 | if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8) |
| 2338 | return false; |
| 2339 | if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1) |
| 2340 | return false; |
| 2341 | |
| 2342 | unsigned SrcReg = getRegForValue(Op); |
| 2343 | if (!SrcReg) return false; |
| 2344 | |
| 2345 | // Because the high bits are undefined, a truncate doesn't generate |
| 2346 | // any code. |
| 2347 | UpdateValueMap(I, SrcReg); |
| 2348 | return true; |
| 2349 | } |
| 2350 | |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2351 | unsigned ARMFastISel::ARMEmitIntExt(EVT SrcVT, unsigned SrcReg, EVT DestVT, |
| 2352 | bool isZExt) { |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2353 | if (DestVT != MVT::i32 && DestVT != MVT::i16 && DestVT != MVT::i8) |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2354 | return 0; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2355 | |
| 2356 | unsigned Opc; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2357 | bool isBoolZext = false; |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2358 | if (!SrcVT.isSimple()) return 0; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2359 | switch (SrcVT.getSimpleVT().SimpleTy) { |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2360 | default: return 0; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2361 | case MVT::i16: |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2362 | if (!Subtarget->hasV6Ops()) return 0; |
| 2363 | if (isZExt) |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2364 | Opc = isThumb2 ? ARM::t2UXTH : ARM::UXTH; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2365 | else |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2366 | Opc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2367 | break; |
| 2368 | case MVT::i8: |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2369 | if (!Subtarget->hasV6Ops()) return 0; |
| 2370 | if (isZExt) |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2371 | Opc = isThumb2 ? ARM::t2UXTB : ARM::UXTB; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2372 | else |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2373 | Opc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2374 | break; |
| 2375 | case MVT::i1: |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2376 | if (isZExt) { |
Chad Rosier | 66dc8ca | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2377 | Opc = isThumb2 ? ARM::t2ANDri : ARM::ANDri; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2378 | isBoolZext = true; |
| 2379 | break; |
| 2380 | } |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2381 | return 0; |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2384 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::i32)); |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2385 | MachineInstrBuilder MIB; |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2386 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), ResultReg) |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2387 | .addReg(SrcReg); |
| 2388 | if (isBoolZext) |
| 2389 | MIB.addImm(1); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 2390 | else |
| 2391 | MIB.addImm(0); |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2392 | AddOptionalDefs(MIB); |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2393 | return ResultReg; |
| 2394 | } |
| 2395 | |
| 2396 | bool ARMFastISel::SelectIntExt(const Instruction *I) { |
| 2397 | // On ARM, in general, integer casts don't involve legal types; this code |
| 2398 | // handles promotable integers. |
Chad Rosier | 8763302 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2399 | Type *DestTy = I->getType(); |
| 2400 | Value *Src = I->getOperand(0); |
| 2401 | Type *SrcTy = Src->getType(); |
| 2402 | |
| 2403 | EVT SrcVT, DestVT; |
| 2404 | SrcVT = TLI.getValueType(SrcTy, true); |
| 2405 | DestVT = TLI.getValueType(DestTy, true); |
| 2406 | |
| 2407 | bool isZExt = isa<ZExtInst>(I); |
| 2408 | unsigned SrcReg = getRegForValue(Src); |
| 2409 | if (!SrcReg) return false; |
| 2410 | |
| 2411 | unsigned ResultReg = ARMEmitIntExt(SrcVT, SrcReg, DestVT, isZExt); |
| 2412 | if (ResultReg == 0) return false; |
| 2413 | UpdateValueMap(I, ResultReg); |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2414 | return true; |
| 2415 | } |
| 2416 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 2417 | // TODO: SoftFP support. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 2418 | bool ARMFastISel::TargetSelectInstruction(const Instruction *I) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 2419 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 2420 | switch (I->getOpcode()) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 2421 | case Instruction::Load: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2422 | return SelectLoad(I); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 2423 | case Instruction::Store: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2424 | return SelectStore(I); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 2425 | case Instruction::Br: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2426 | return SelectBranch(I); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 2427 | case Instruction::ICmp: |
| 2428 | case Instruction::FCmp: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2429 | return SelectCmp(I); |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 2430 | case Instruction::FPExt: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2431 | return SelectFPExt(I); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 2432 | case Instruction::FPTrunc: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2433 | return SelectFPTrunc(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 2434 | case Instruction::SIToFP: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2435 | return SelectSIToFP(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 2436 | case Instruction::FPToSI: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2437 | return SelectFPToSI(I); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 2438 | case Instruction::FAdd: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2439 | return SelectBinaryOp(I, ISD::FADD); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 2440 | case Instruction::FSub: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2441 | return SelectBinaryOp(I, ISD::FSUB); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 2442 | case Instruction::FMul: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2443 | return SelectBinaryOp(I, ISD::FMUL); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2444 | case Instruction::SDiv: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2445 | return SelectSDiv(I); |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 2446 | case Instruction::SRem: |
| 2447 | return SelectSRem(I); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2448 | case Instruction::Call: |
Chad Rosier | 11add26 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2449 | if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) |
| 2450 | return SelectIntrinsicCall(*II); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2451 | return SelectCall(I); |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 2452 | case Instruction::Select: |
| 2453 | return SelectSelect(I); |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2454 | case Instruction::Ret: |
| 2455 | return SelectRet(I); |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2456 | case Instruction::Trunc: |
Chad Rosier | 0d7b231 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 2457 | return SelectTrunc(I); |
Eli Friedman | 76927d73 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2458 | case Instruction::ZExt: |
| 2459 | case Instruction::SExt: |
Chad Rosier | 0d7b231 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 2460 | return SelectIntExt(I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 2461 | default: break; |
| 2462 | } |
| 2463 | return false; |
| 2464 | } |
| 2465 | |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 2466 | /// TryToFoldLoad - The specified machine instr operand is a vreg, and that |
| 2467 | /// vreg is being provided by the specified load instruction. If possible, |
| 2468 | /// try to fold the load as an operand to the instruction, returning true if |
| 2469 | /// successful. |
| 2470 | bool ARMFastISel::TryToFoldLoad(MachineInstr *MI, unsigned OpNo, |
| 2471 | const LoadInst *LI) { |
| 2472 | // Verify we have a legal type before going any further. |
| 2473 | MVT VT; |
| 2474 | if (!isLoadTypeLegal(LI->getType(), VT)) |
| 2475 | return false; |
| 2476 | |
| 2477 | // Combine load followed by zero- or sign-extend. |
| 2478 | // ldrb r1, [r0] ldrb r1, [r0] |
| 2479 | // uxtb r2, r1 => |
| 2480 | // mov r3, r2 mov r3, r1 |
| 2481 | bool isZExt = true; |
| 2482 | switch(MI->getOpcode()) { |
| 2483 | default: return false; |
| 2484 | case ARM::SXTH: |
| 2485 | case ARM::t2SXTH: |
| 2486 | isZExt = false; |
| 2487 | case ARM::UXTH: |
| 2488 | case ARM::t2UXTH: |
| 2489 | if (VT != MVT::i16) |
| 2490 | return false; |
| 2491 | break; |
| 2492 | case ARM::SXTB: |
| 2493 | case ARM::t2SXTB: |
| 2494 | isZExt = false; |
| 2495 | case ARM::UXTB: |
| 2496 | case ARM::t2UXTB: |
| 2497 | if (VT != MVT::i8) |
| 2498 | return false; |
| 2499 | break; |
| 2500 | } |
| 2501 | // See if we can handle this address. |
| 2502 | Address Addr; |
| 2503 | if (!ARMComputeAddress(LI->getOperand(0), Addr)) return false; |
| 2504 | |
| 2505 | unsigned ResultReg = MI->getOperand(0).getReg(); |
Chad Rosier | 8a9bce9 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 2506 | if (!ARMEmitLoad(VT, ResultReg, Addr, LI->getAlignment(), isZExt, false)) |
Chad Rosier | b29b950 | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 2507 | return false; |
| 2508 | MI->eraseFromParent(); |
| 2509 | return true; |
| 2510 | } |
| 2511 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 2512 | namespace llvm { |
| 2513 | llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) { |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 2514 | // Completely untested on non-darwin. |
| 2515 | const TargetMachine &TM = funcInfo.MF->getTarget(); |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 2516 | |
Eric Christopher | aaa8df4 | 2010-11-02 01:21:28 +0000 | [diff] [blame] | 2517 | // Darwin and thumb1 only for now. |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 2518 | const ARMSubtarget *Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 2519 | if (Subtarget->isTargetDarwin() && !Subtarget->isThumb1Only() && |
Eric Christopher | aaa8df4 | 2010-11-02 01:21:28 +0000 | [diff] [blame] | 2520 | !DisableARMFastISel) |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 2521 | return new ARMFastISel(funcInfo); |
Evan Cheng | 0944795 | 2010-07-26 18:32:55 +0000 | [diff] [blame] | 2522 | return 0; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 2523 | } |
| 2524 | } |