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" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 23 | #include "llvm/CallingConv.h" |
| 24 | #include "llvm/DerivedTypes.h" |
| 25 | #include "llvm/GlobalVariable.h" |
| 26 | #include "llvm/Instructions.h" |
| 27 | #include "llvm/IntrinsicInst.h" |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 28 | #include "llvm/Module.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/Analysis.h" |
| 30 | #include "llvm/CodeGen/FastISel.h" |
| 31 | #include "llvm/CodeGen/FunctionLoweringInfo.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 33 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 35 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Eric Christopher | d56d61a | 2010-10-17 01:51:42 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/MachineMemOperand.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Eric Christopher | d56d61a | 2010-10-17 01:51:42 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 39 | #include "llvm/Support/CallSite.h" |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 40 | #include "llvm/Support/CommandLine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 41 | #include "llvm/Support/ErrorHandling.h" |
| 42 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 43 | #include "llvm/Target/TargetData.h" |
| 44 | #include "llvm/Target/TargetInstrInfo.h" |
| 45 | #include "llvm/Target/TargetLowering.h" |
| 46 | #include "llvm/Target/TargetMachine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 47 | #include "llvm/Target/TargetOptions.h" |
| 48 | using namespace llvm; |
| 49 | |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 50 | static cl::opt<bool> |
Eric Christopher | 6e5367d | 2010-10-18 22:53:53 +0000 | [diff] [blame] | 51 | DisableARMFastISel("disable-arm-fast-isel", |
| 52 | cl::desc("Turn off experimental ARM fast-isel support"), |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 53 | cl::init(false), cl::Hidden); |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 54 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 55 | extern cl::opt<bool> EnableARMLongCalls; |
| 56 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 57 | namespace { |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 58 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 59 | // All possible address modes, plus some. |
| 60 | typedef struct Address { |
| 61 | enum { |
| 62 | RegBase, |
| 63 | FrameIndexBase |
| 64 | } BaseType; |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 65 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 66 | union { |
| 67 | unsigned Reg; |
| 68 | int FI; |
| 69 | } Base; |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 70 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 71 | int Offset; |
| 72 | unsigned Scale; |
| 73 | unsigned PlusReg; |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 74 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 75 | // Innocuous defaults for our address. |
| 76 | Address() |
| 77 | : BaseType(RegBase), Offset(0), Scale(0), PlusReg(0) { |
| 78 | Base.Reg = 0; |
| 79 | } |
| 80 | } Address; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 81 | |
| 82 | class ARMFastISel : public FastISel { |
| 83 | |
| 84 | /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can |
| 85 | /// make the right decision when generating code for different targets. |
| 86 | const ARMSubtarget *Subtarget; |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 87 | const TargetMachine &TM; |
| 88 | const TargetInstrInfo &TII; |
| 89 | const TargetLowering &TLI; |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 90 | ARMFunctionInfo *AFI; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 91 | |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 92 | // Convenience variables to avoid some queries. |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 93 | bool isThumb; |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 94 | LLVMContext *Context; |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 95 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 96 | public: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 97 | explicit ARMFastISel(FunctionLoweringInfo &funcInfo) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 98 | : FastISel(funcInfo), |
| 99 | TM(funcInfo.MF->getTarget()), |
| 100 | TII(*TM.getInstrInfo()), |
| 101 | TLI(*TM.getTargetLowering()) { |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 102 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 103 | AFI = funcInfo.MF->getInfo<ARMFunctionInfo>(); |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 104 | isThumb = AFI->isThumbFunction(); |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 105 | Context = &funcInfo.Fn->getContext(); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 108 | // Code from FastISel.cpp. |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 109 | virtual unsigned FastEmitInst_(unsigned MachineInstOpcode, |
| 110 | const TargetRegisterClass *RC); |
| 111 | virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode, |
| 112 | const TargetRegisterClass *RC, |
| 113 | unsigned Op0, bool Op0IsKill); |
| 114 | virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode, |
| 115 | const TargetRegisterClass *RC, |
| 116 | unsigned Op0, bool Op0IsKill, |
| 117 | unsigned Op1, bool Op1IsKill); |
| 118 | virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode, |
| 119 | const TargetRegisterClass *RC, |
| 120 | unsigned Op0, bool Op0IsKill, |
| 121 | uint64_t Imm); |
| 122 | virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode, |
| 123 | const TargetRegisterClass *RC, |
| 124 | unsigned Op0, bool Op0IsKill, |
| 125 | const ConstantFP *FPImm); |
| 126 | virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode, |
| 127 | const TargetRegisterClass *RC, |
| 128 | uint64_t Imm); |
| 129 | virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode, |
| 130 | const TargetRegisterClass *RC, |
| 131 | unsigned Op0, bool Op0IsKill, |
| 132 | unsigned Op1, bool Op1IsKill, |
| 133 | uint64_t Imm); |
| 134 | virtual unsigned FastEmitInst_extractsubreg(MVT RetVT, |
| 135 | unsigned Op0, bool Op0IsKill, |
| 136 | uint32_t Idx); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 137 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 138 | // Backend specific FastISel code. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 139 | virtual bool TargetSelectInstruction(const Instruction *I); |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 140 | virtual unsigned TargetMaterializeConstant(const Constant *C); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 141 | virtual unsigned TargetMaterializeAlloca(const AllocaInst *AI); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 142 | |
| 143 | #include "ARMGenFastISel.inc" |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 144 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 145 | // Instruction selection routines. |
Eric Christopher | 44bff90 | 2010-09-10 23:10:30 +0000 | [diff] [blame] | 146 | private: |
Eric Christopher | 1778772 | 2010-10-21 21:47:51 +0000 | [diff] [blame] | 147 | bool SelectLoad(const Instruction *I); |
| 148 | bool SelectStore(const Instruction *I); |
| 149 | bool SelectBranch(const Instruction *I); |
| 150 | bool SelectCmp(const Instruction *I); |
| 151 | bool SelectFPExt(const Instruction *I); |
| 152 | bool SelectFPTrunc(const Instruction *I); |
| 153 | bool SelectBinaryOp(const Instruction *I, unsigned ISDOpcode); |
| 154 | bool SelectSIToFP(const Instruction *I); |
| 155 | bool SelectFPToSI(const Instruction *I); |
| 156 | bool SelectSDiv(const Instruction *I); |
| 157 | bool SelectSRem(const Instruction *I); |
| 158 | bool SelectCall(const Instruction *I); |
| 159 | bool SelectSelect(const Instruction *I); |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 160 | bool SelectRet(const Instruction *I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 161 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 162 | // Utility routines. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 163 | private: |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 164 | bool isTypeLegal(const Type *Ty, MVT &VT); |
| 165 | bool isLoadTypeLegal(const Type *Ty, MVT &VT); |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 166 | bool ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr); |
| 167 | bool ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr); |
| 168 | bool ARMComputeAddress(const Value *Obj, Address &Addr); |
| 169 | void ARMSimplifyAddress(Address &Addr, EVT VT); |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 170 | unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT); |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 171 | unsigned ARMMaterializeInt(const Constant *C, EVT VT); |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 172 | unsigned ARMMaterializeGV(const GlobalValue *GV, EVT VT); |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 173 | unsigned ARMMoveToFPReg(EVT VT, unsigned SrcReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 174 | unsigned ARMMoveToIntReg(EVT VT, unsigned SrcReg); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 175 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 176 | // Call handling routines. |
| 177 | private: |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 178 | bool FastEmitExtend(ISD::NodeType Opc, EVT DstVT, unsigned Src, EVT SrcVT, |
| 179 | unsigned &ResultReg); |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 180 | CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool Return); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 181 | bool ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 182 | SmallVectorImpl<unsigned> &ArgRegs, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 183 | SmallVectorImpl<MVT> &ArgVTs, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 184 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 185 | SmallVectorImpl<unsigned> &RegArgs, |
| 186 | CallingConv::ID CC, |
| 187 | unsigned &NumBytes); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 188 | bool FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 189 | const Instruction *I, CallingConv::ID CC, |
| 190 | unsigned &NumBytes); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 191 | bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call); |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 192 | |
| 193 | // OptionalDef handling routines. |
| 194 | private: |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 195 | bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR); |
| 196 | const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB); |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 197 | void AddLoadStoreOperands(EVT VT, Address &Addr, |
| 198 | const MachineInstrBuilder &MIB); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 199 | }; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 200 | |
| 201 | } // end anonymous namespace |
| 202 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 203 | #include "ARMGenCallingConv.inc" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 204 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 205 | // DefinesOptionalPredicate - This is different from DefinesPredicate in that |
| 206 | // we don't care about implicit defs here, just places we'll need to add a |
| 207 | // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR. |
| 208 | bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) { |
| 209 | const TargetInstrDesc &TID = MI->getDesc(); |
| 210 | if (!TID.hasOptionalDef()) |
| 211 | return false; |
| 212 | |
| 213 | // Look to see if our OptionalDef is defining CPSR or CCR. |
| 214 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 215 | const MachineOperand &MO = MI->getOperand(i); |
Eric Christopher | f762fbe | 2010-08-20 00:36:24 +0000 | [diff] [blame] | 216 | if (!MO.isReg() || !MO.isDef()) continue; |
| 217 | if (MO.getReg() == ARM::CPSR) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 218 | *CPSR = true; |
| 219 | } |
| 220 | return true; |
| 221 | } |
| 222 | |
| 223 | // If the machine is predicable go ahead and add the predicate operands, if |
| 224 | // it needs default CC operands add those. |
Eric Christopher | aaa8df4 | 2010-11-02 01:21:28 +0000 | [diff] [blame] | 225 | // TODO: If we want to support thumb1 then we'll need to deal with optional |
| 226 | // CPSR defs that need to be added before the remaining operands. See s_cc_out |
| 227 | // for descriptions why. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 228 | const MachineInstrBuilder & |
| 229 | ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) { |
| 230 | MachineInstr *MI = &*MIB; |
| 231 | |
| 232 | // Do we use a predicate? |
| 233 | if (TII.isPredicable(MI)) |
| 234 | AddDefaultPred(MIB); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 235 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 236 | // Do we optionally set a predicate? Preds is size > 0 iff the predicate |
| 237 | // defines CPSR. All other OptionalDefines in ARM are the CCR register. |
Eric Christopher | 979e0a1 | 2010-08-19 15:35:27 +0000 | [diff] [blame] | 238 | bool CPSR = false; |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 239 | if (DefinesOptionalPredicate(MI, &CPSR)) { |
| 240 | if (CPSR) |
| 241 | AddDefaultT1CC(MIB); |
| 242 | else |
| 243 | AddDefaultCC(MIB); |
| 244 | } |
| 245 | return MIB; |
| 246 | } |
| 247 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 248 | unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode, |
| 249 | const TargetRegisterClass* RC) { |
| 250 | unsigned ResultReg = createResultReg(RC); |
| 251 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 252 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 253 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 254 | return ResultReg; |
| 255 | } |
| 256 | |
| 257 | unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode, |
| 258 | const TargetRegisterClass *RC, |
| 259 | unsigned Op0, bool Op0IsKill) { |
| 260 | unsigned ResultReg = createResultReg(RC); |
| 261 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 262 | |
| 263 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 264 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 265 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
| 266 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 267 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 268 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 269 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 270 | TII.get(TargetOpcode::COPY), ResultReg) |
| 271 | .addReg(II.ImplicitDefs[0])); |
| 272 | } |
| 273 | return ResultReg; |
| 274 | } |
| 275 | |
| 276 | unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode, |
| 277 | const TargetRegisterClass *RC, |
| 278 | unsigned Op0, bool Op0IsKill, |
| 279 | unsigned Op1, bool Op1IsKill) { |
| 280 | unsigned ResultReg = createResultReg(RC); |
| 281 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 282 | |
| 283 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 284 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 285 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 286 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
| 287 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 288 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 289 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 290 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 291 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 292 | TII.get(TargetOpcode::COPY), ResultReg) |
| 293 | .addReg(II.ImplicitDefs[0])); |
| 294 | } |
| 295 | return ResultReg; |
| 296 | } |
| 297 | |
| 298 | unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode, |
| 299 | const TargetRegisterClass *RC, |
| 300 | unsigned Op0, bool Op0IsKill, |
| 301 | uint64_t Imm) { |
| 302 | unsigned ResultReg = createResultReg(RC); |
| 303 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 304 | |
| 305 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 306 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 307 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 308 | .addImm(Imm)); |
| 309 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 310 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 311 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 312 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 313 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 314 | TII.get(TargetOpcode::COPY), ResultReg) |
| 315 | .addReg(II.ImplicitDefs[0])); |
| 316 | } |
| 317 | return ResultReg; |
| 318 | } |
| 319 | |
| 320 | unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode, |
| 321 | const TargetRegisterClass *RC, |
| 322 | unsigned Op0, bool Op0IsKill, |
| 323 | const ConstantFP *FPImm) { |
| 324 | unsigned ResultReg = createResultReg(RC); |
| 325 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 326 | |
| 327 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 328 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 329 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 330 | .addFPImm(FPImm)); |
| 331 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 332 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 333 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 334 | .addFPImm(FPImm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 335 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 336 | TII.get(TargetOpcode::COPY), ResultReg) |
| 337 | .addReg(II.ImplicitDefs[0])); |
| 338 | } |
| 339 | return ResultReg; |
| 340 | } |
| 341 | |
| 342 | unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode, |
| 343 | const TargetRegisterClass *RC, |
| 344 | unsigned Op0, bool Op0IsKill, |
| 345 | unsigned Op1, bool Op1IsKill, |
| 346 | uint64_t Imm) { |
| 347 | unsigned ResultReg = createResultReg(RC); |
| 348 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 349 | |
| 350 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 351 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 352 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 353 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 354 | .addImm(Imm)); |
| 355 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 356 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 357 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 358 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 359 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 360 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 361 | TII.get(TargetOpcode::COPY), ResultReg) |
| 362 | .addReg(II.ImplicitDefs[0])); |
| 363 | } |
| 364 | return ResultReg; |
| 365 | } |
| 366 | |
| 367 | unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode, |
| 368 | const TargetRegisterClass *RC, |
| 369 | uint64_t Imm) { |
| 370 | unsigned ResultReg = createResultReg(RC); |
| 371 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 372 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 373 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 374 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 375 | .addImm(Imm)); |
| 376 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 377 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 378 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 379 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 380 | TII.get(TargetOpcode::COPY), ResultReg) |
| 381 | .addReg(II.ImplicitDefs[0])); |
| 382 | } |
| 383 | return ResultReg; |
| 384 | } |
| 385 | |
| 386 | unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT, |
| 387 | unsigned Op0, bool Op0IsKill, |
| 388 | uint32_t Idx) { |
| 389 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT)); |
| 390 | assert(TargetRegisterInfo::isVirtualRegister(Op0) && |
| 391 | "Cannot yet extract from physregs"); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 392 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 393 | DL, TII.get(TargetOpcode::COPY), ResultReg) |
| 394 | .addReg(Op0, getKillRegState(Op0IsKill), Idx)); |
| 395 | return ResultReg; |
| 396 | } |
| 397 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 398 | // TODO: Don't worry about 64-bit now, but when this is fixed remove the |
| 399 | // checks from the various callers. |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 400 | unsigned ARMFastISel::ARMMoveToFPReg(EVT VT, unsigned SrcReg) { |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 401 | if (VT == MVT::f64) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 402 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 403 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 404 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 405 | TII.get(ARM::VMOVRS), MoveReg) |
| 406 | .addReg(SrcReg)); |
| 407 | return MoveReg; |
| 408 | } |
| 409 | |
| 410 | unsigned ARMFastISel::ARMMoveToIntReg(EVT VT, unsigned SrcReg) { |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 411 | if (VT == MVT::i64) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 412 | |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 413 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 414 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 415 | TII.get(ARM::VMOVSR), MoveReg) |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 416 | .addReg(SrcReg)); |
| 417 | return MoveReg; |
| 418 | } |
| 419 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 420 | // For double width floating point we need to materialize two constants |
| 421 | // (the high and the low) into integer registers then use a move to get |
| 422 | // the combined constant into an FP reg. |
| 423 | unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, EVT VT) { |
| 424 | const APFloat Val = CFP->getValueAPF(); |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 425 | bool is64bit = VT == MVT::f64; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 426 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 427 | // This checks to see if we can use VFP3 instructions to materialize |
| 428 | // a constant, otherwise we have to go through the constant pool. |
| 429 | if (TLI.isFPImmLegal(Val, VT)) { |
| 430 | unsigned Opc = is64bit ? ARM::FCONSTD : ARM::FCONSTS; |
| 431 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 432 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 433 | DestReg) |
| 434 | .addFPImm(CFP)); |
| 435 | return DestReg; |
| 436 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 437 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 438 | // Require VFP2 for loading fp constants. |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 439 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 440 | |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 441 | // MachineConstantPool wants an explicit alignment. |
| 442 | unsigned Align = TD.getPrefTypeAlignment(CFP->getType()); |
| 443 | if (Align == 0) { |
| 444 | // TODO: Figure out if this is correct. |
| 445 | Align = TD.getTypeAllocSize(CFP->getType()); |
| 446 | } |
| 447 | unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align); |
| 448 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 449 | unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 450 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 451 | // The extra reg is for addrmode5. |
Eric Christopher | f5732c4 | 2010-09-28 00:35:09 +0000 | [diff] [blame] | 452 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 453 | DestReg) |
| 454 | .addConstantPoolIndex(Idx) |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 455 | .addReg(0)); |
| 456 | return DestReg; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 459 | unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, EVT VT) { |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 460 | |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 461 | // For now 32-bit only. |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 462 | if (VT != MVT::i32) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 463 | |
Eric Christopher | e5b13cf | 2010-11-03 20:21:17 +0000 | [diff] [blame] | 464 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 465 | |
| 466 | // If we can do this in a single instruction without a constant pool entry |
| 467 | // do so now. |
| 468 | const ConstantInt *CI = cast<ConstantInt>(C); |
Eric Christopher | 5e262bc | 2010-11-06 07:53:11 +0000 | [diff] [blame] | 469 | if (Subtarget->hasV6T2Ops() && isUInt<16>(CI->getSExtValue())) { |
Eric Christopher | e5b13cf | 2010-11-03 20:21:17 +0000 | [diff] [blame] | 470 | unsigned Opc = isThumb ? ARM::t2MOVi16 : ARM::MOVi16; |
| 471 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Jim Grosbach | 3ea4daa | 2010-11-19 18:01:37 +0000 | [diff] [blame] | 472 | TII.get(Opc), DestReg) |
| 473 | .addImm(CI->getSExtValue())); |
Eric Christopher | e5b13cf | 2010-11-03 20:21:17 +0000 | [diff] [blame] | 474 | return DestReg; |
| 475 | } |
| 476 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 477 | // MachineConstantPool wants an explicit alignment. |
| 478 | unsigned Align = TD.getPrefTypeAlignment(C->getType()); |
| 479 | if (Align == 0) { |
| 480 | // TODO: Figure out if this is correct. |
| 481 | Align = TD.getTypeAllocSize(C->getType()); |
| 482 | } |
| 483 | unsigned Idx = MCP.getConstantPoolIndex(C, Align); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 484 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 485 | if (isThumb) |
| 486 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | fd60980 | 2010-09-28 21:55:34 +0000 | [diff] [blame] | 487 | TII.get(ARM::t2LDRpci), DestReg) |
| 488 | .addConstantPoolIndex(Idx)); |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 489 | else |
Eric Christopher | d0c82a6 | 2010-11-12 09:48:30 +0000 | [diff] [blame] | 490 | // The extra immediate is for addrmode2. |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 491 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | fd60980 | 2010-09-28 21:55:34 +0000 | [diff] [blame] | 492 | TII.get(ARM::LDRcp), DestReg) |
| 493 | .addConstantPoolIndex(Idx) |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 494 | .addImm(0)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 495 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 496 | return DestReg; |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 499 | unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, EVT VT) { |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 500 | // For now 32-bit only. |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 501 | if (VT != MVT::i32) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 502 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 503 | Reloc::Model RelocM = TM.getRelocationModel(); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 504 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 505 | // TODO: No external globals for now. |
| 506 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 507 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 508 | // TODO: Need more magic for ARM PIC. |
| 509 | if (!isThumb && (RelocM == Reloc::PIC_)) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 510 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 511 | // MachineConstantPool wants an explicit alignment. |
| 512 | unsigned Align = TD.getPrefTypeAlignment(GV->getType()); |
| 513 | if (Align == 0) { |
| 514 | // TODO: Figure out if this is correct. |
| 515 | Align = TD.getTypeAllocSize(GV->getType()); |
| 516 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 517 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 518 | // Grab index. |
| 519 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb() ? 4 : 8); |
| 520 | unsigned Id = AFI->createConstPoolEntryUId(); |
| 521 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, Id, |
| 522 | ARMCP::CPValue, PCAdj); |
| 523 | unsigned Idx = MCP.getConstantPoolIndex(CPV, Align); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 524 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 525 | // Load value. |
| 526 | MachineInstrBuilder MIB; |
| 527 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 528 | if (isThumb) { |
| 529 | unsigned Opc = (RelocM != Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic; |
| 530 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg) |
| 531 | .addConstantPoolIndex(Idx); |
| 532 | if (RelocM == Reloc::PIC_) |
| 533 | MIB.addImm(Id); |
| 534 | } else { |
Eric Christopher | d0c82a6 | 2010-11-12 09:48:30 +0000 | [diff] [blame] | 535 | // The extra immediate is for addrmode2. |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 536 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRcp), |
| 537 | DestReg) |
| 538 | .addConstantPoolIndex(Idx) |
Eric Christopher | d0c82a6 | 2010-11-12 09:48:30 +0000 | [diff] [blame] | 539 | .addImm(0); |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 540 | } |
| 541 | AddOptionalDefs(MIB); |
| 542 | return DestReg; |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 545 | unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) { |
| 546 | EVT VT = TLI.getValueType(C->getType(), true); |
| 547 | |
| 548 | // Only handle simple types. |
| 549 | if (!VT.isSimple()) return 0; |
| 550 | |
| 551 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) |
| 552 | return ARMMaterializeFP(CFP, VT); |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 553 | else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 554 | return ARMMaterializeGV(GV, VT); |
| 555 | else if (isa<ConstantInt>(C)) |
| 556 | return ARMMaterializeInt(C, VT); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 557 | |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 558 | return 0; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 561 | unsigned ARMFastISel::TargetMaterializeAlloca(const AllocaInst *AI) { |
| 562 | // Don't handle dynamic allocas. |
| 563 | if (!FuncInfo.StaticAllocaMap.count(AI)) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 564 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 565 | MVT VT; |
Eric Christopher | ec8bf97 | 2010-10-17 06:07:26 +0000 | [diff] [blame] | 566 | if (!isLoadTypeLegal(AI->getType(), VT)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 567 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 568 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 569 | FuncInfo.StaticAllocaMap.find(AI); |
| 570 | |
| 571 | // This will get lowered later into the correct offsets and registers |
| 572 | // via rewriteXFrameIndex. |
| 573 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
| 574 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
| 575 | unsigned ResultReg = createResultReg(RC); |
| 576 | unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri; |
| 577 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL, |
| 578 | TII.get(Opc), ResultReg) |
| 579 | .addFrameIndex(SI->second) |
| 580 | .addImm(0)); |
| 581 | return ResultReg; |
| 582 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 583 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 584 | return 0; |
| 585 | } |
| 586 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 587 | bool ARMFastISel::isTypeLegal(const Type *Ty, MVT &VT) { |
| 588 | EVT evt = TLI.getValueType(Ty, true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 589 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 590 | // Only handle simple types. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 591 | if (evt == MVT::Other || !evt.isSimple()) return false; |
| 592 | VT = evt.getSimpleVT(); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 593 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 594 | // Handle all legal types, i.e. a register that will directly hold this |
| 595 | // value. |
| 596 | return TLI.isTypeLegal(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 599 | bool ARMFastISel::isLoadTypeLegal(const Type *Ty, MVT &VT) { |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 600 | if (isTypeLegal(Ty, VT)) return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 601 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 602 | // If this is a type than can be sign or zero-extended to a basic operation |
| 603 | // go ahead and accept it now. |
| 604 | if (VT == MVT::i8 || VT == MVT::i16) |
| 605 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 606 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 607 | return false; |
| 608 | } |
| 609 | |
Eric Christopher | 88de86b | 2010-11-19 22:36:41 +0000 | [diff] [blame] | 610 | // Computes the address to get to an object. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 611 | bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 612 | // Some boilerplate from the X86 FastISel. |
| 613 | const User *U = NULL; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 614 | unsigned Opcode = Instruction::UserOp1; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 615 | if (const Instruction *I = dyn_cast<Instruction>(Obj)) { |
Eric Christopher | 2d630d7 | 2010-11-19 22:37:58 +0000 | [diff] [blame] | 616 | // Don't walk into other basic blocks unless the object is an alloca from |
| 617 | // another block, otherwise it may not have a virtual register assigned. |
Eric Christopher | 76dda7e | 2010-11-15 21:11:06 +0000 | [diff] [blame] | 618 | if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) || |
| 619 | FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) { |
| 620 | Opcode = I->getOpcode(); |
| 621 | U = I; |
| 622 | } |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 623 | } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 624 | Opcode = C->getOpcode(); |
| 625 | U = C; |
| 626 | } |
| 627 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 628 | if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType())) |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 629 | if (Ty->getAddressSpace() > 255) |
| 630 | // Fast instruction selection doesn't support the special |
| 631 | // address spaces. |
| 632 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 633 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 634 | switch (Opcode) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 635 | default: |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 636 | break; |
Eric Christopher | 5532433 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 637 | case Instruction::BitCast: { |
| 638 | // Look through bitcasts. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 639 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | 5532433 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 640 | } |
| 641 | case Instruction::IntToPtr: { |
| 642 | // Look past no-op inttoptrs. |
| 643 | if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy()) |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 644 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | 5532433 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 645 | break; |
| 646 | } |
| 647 | case Instruction::PtrToInt: { |
| 648 | // Look past no-op ptrtoints. |
| 649 | if (TLI.getValueType(U->getType()) == TLI.getPointerTy()) |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 650 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | 5532433 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 651 | break; |
| 652 | } |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 653 | case Instruction::GetElementPtr: { |
Eric Christopher | b371658 | 2010-11-19 22:39:56 +0000 | [diff] [blame] | 654 | Address SavedAddr = Addr; |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 655 | int TmpOffset = Addr.Offset; |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 656 | |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 657 | // Iterate through the GEP folding the constants into offsets where |
| 658 | // we can. |
| 659 | gep_type_iterator GTI = gep_type_begin(U); |
| 660 | for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end(); |
| 661 | i != e; ++i, ++GTI) { |
| 662 | const Value *Op = *i; |
| 663 | if (const StructType *STy = dyn_cast<StructType>(*GTI)) { |
| 664 | const StructLayout *SL = TD.getStructLayout(STy); |
| 665 | unsigned Idx = cast<ConstantInt>(Op)->getZExtValue(); |
| 666 | TmpOffset += SL->getElementOffset(Idx); |
| 667 | } else { |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 668 | uint64_t S = TD.getTypeAllocSize(GTI.getIndexedType()); |
| 669 | SmallVector<const Value *, 4> Worklist; |
| 670 | Worklist.push_back(Op); |
| 671 | do { |
| 672 | Op = Worklist.pop_back_val(); |
| 673 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) { |
| 674 | // Constant-offset addressing. |
| 675 | TmpOffset += CI->getSExtValue() * S; |
Eric Christopher | dc0b0ef | 2010-10-17 01:41:46 +0000 | [diff] [blame] | 676 | } else if (isa<AddOperator>(Op) && |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 677 | isa<ConstantInt>(cast<AddOperator>(Op)->getOperand(1))) { |
| 678 | // An add with a constant operand. Fold the constant. |
| 679 | ConstantInt *CI = |
| 680 | cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1)); |
| 681 | TmpOffset += CI->getSExtValue() * S; |
| 682 | // Add the other operand back to the work list. |
| 683 | Worklist.push_back(cast<AddOperator>(Op)->getOperand(0)); |
| 684 | } else |
| 685 | goto unsupported_gep; |
| 686 | } while (!Worklist.empty()); |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 687 | } |
| 688 | } |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 689 | |
| 690 | // Try to grab the base operand now. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 691 | Addr.Offset = TmpOffset; |
| 692 | if (ARMComputeAddress(U->getOperand(0), Addr)) return true; |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 693 | |
| 694 | // We failed, restore everything and try the other options. |
Eric Christopher | b371658 | 2010-11-19 22:39:56 +0000 | [diff] [blame] | 695 | Addr = SavedAddr; |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 696 | |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 697 | unsupported_gep: |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 698 | break; |
| 699 | } |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 700 | case Instruction::Alloca: { |
Eric Christopher | 1541877 | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 701 | const AllocaInst *AI = cast<AllocaInst>(Obj); |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 702 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 703 | FuncInfo.StaticAllocaMap.find(AI); |
| 704 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
| 705 | Addr.BaseType = Address::FrameIndexBase; |
| 706 | Addr.Base.FI = SI->second; |
| 707 | return true; |
| 708 | } |
| 709 | break; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 710 | } |
| 711 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 712 | |
Eric Christopher | a9c5751 | 2010-10-13 21:41:51 +0000 | [diff] [blame] | 713 | // Materialize the global variable's address into a reg which can |
| 714 | // then be used later to load the variable. |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 715 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) { |
Eric Christopher | ede42b0 | 2010-10-13 09:11:46 +0000 | [diff] [blame] | 716 | unsigned Tmp = ARMMaterializeGV(GV, TLI.getValueType(Obj->getType())); |
| 717 | if (Tmp == 0) return false; |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 718 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 719 | Addr.Base.Reg = Tmp; |
Eric Christopher | ede42b0 | 2010-10-13 09:11:46 +0000 | [diff] [blame] | 720 | return true; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 721 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 722 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 723 | // Try to get this in a register if nothing else has worked. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 724 | if (Addr.Base.Reg == 0) Addr.Base.Reg = getRegForValue(Obj); |
| 725 | return Addr.Base.Reg != 0; |
Eric Christopher | eae8439 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 728 | void ARMFastISel::ARMSimplifyAddress(Address &Addr, EVT VT) { |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 729 | |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 730 | assert(VT.isSimple() && "Non-simple types are invalid here!"); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 731 | |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 732 | bool needsLowering = false; |
| 733 | switch (VT.getSimpleVT().SimpleTy) { |
| 734 | default: |
| 735 | assert(false && "Unhandled load/store type!"); |
| 736 | case MVT::i1: |
| 737 | case MVT::i8: |
| 738 | case MVT::i16: |
| 739 | case MVT::i32: |
| 740 | // Integer loads/stores handle 12-bit offsets. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 741 | needsLowering = ((Addr.Offset & 0xfff) != Addr.Offset); |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 742 | break; |
| 743 | case MVT::f32: |
| 744 | case MVT::f64: |
| 745 | // Floating point operands handle 8-bit offsets. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 746 | needsLowering = ((Addr.Offset & 0xff) != Addr.Offset); |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 747 | break; |
| 748 | } |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 749 | |
Eric Christopher | 827656d | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 750 | // If this is a stack pointer and the offset needs to be simplified then |
| 751 | // put the alloca address into a register, set the base type back to |
| 752 | // register and continue. This should almost never happen. |
| 753 | if (needsLowering && Addr.BaseType == Address::FrameIndexBase) { |
| 754 | TargetRegisterClass *RC = isThumb ? ARM::tGPRRegisterClass : |
| 755 | ARM::GPRRegisterClass; |
| 756 | unsigned ResultReg = createResultReg(RC); |
| 757 | unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri; |
| 758 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL, |
| 759 | TII.get(Opc), ResultReg) |
| 760 | .addFrameIndex(Addr.Base.FI) |
| 761 | .addImm(0)); |
| 762 | Addr.Base.Reg = ResultReg; |
| 763 | Addr.BaseType = Address::RegBase; |
| 764 | } |
| 765 | |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 766 | // Since the offset is too large for the load/store instruction |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 767 | // get the reg+offset into a register. |
Eric Christopher | 212ae93 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 768 | if (needsLowering) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 769 | ARMCC::CondCodes Pred = ARMCC::AL; |
| 770 | unsigned PredReg = 0; |
| 771 | |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 772 | TargetRegisterClass *RC = isThumb ? ARM::tGPRRegisterClass : |
| 773 | ARM::GPRRegisterClass; |
| 774 | unsigned BaseReg = createResultReg(RC); |
| 775 | |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 776 | if (!isThumb) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 777 | emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 778 | BaseReg, Addr.Base.Reg, Addr.Offset, |
| 779 | Pred, PredReg, |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 780 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 781 | else { |
| 782 | assert(AFI->isThumb2Function()); |
| 783 | emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 784 | BaseReg, Addr.Base.Reg, Addr.Offset, Pred, PredReg, |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 785 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 786 | } |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 787 | Addr.Offset = 0; |
| 788 | Addr.Base.Reg = BaseReg; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 789 | } |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 792 | void ARMFastISel::AddLoadStoreOperands(EVT VT, Address &Addr, |
| 793 | const MachineInstrBuilder &MIB) { |
| 794 | // addrmode5 output depends on the selection dag addressing dividing the |
| 795 | // offset by 4 that it then later multiplies. Do this here as well. |
| 796 | if (VT.getSimpleVT().SimpleTy == MVT::f32 || |
| 797 | VT.getSimpleVT().SimpleTy == MVT::f64) |
| 798 | Addr.Offset /= 4; |
| 799 | |
| 800 | // Frame base works a bit differently. Handle it separately. |
| 801 | if (Addr.BaseType == Address::FrameIndexBase) { |
| 802 | int FI = Addr.Base.FI; |
| 803 | int Offset = Addr.Offset; |
| 804 | MachineMemOperand *MMO = |
| 805 | FuncInfo.MF->getMachineMemOperand( |
| 806 | MachinePointerInfo::getFixedStack(FI, Offset), |
| 807 | MachineMemOperand::MOLoad, |
| 808 | MFI.getObjectSize(FI), |
| 809 | MFI.getObjectAlignment(FI)); |
| 810 | // Now add the rest of the operands. |
| 811 | MIB.addFrameIndex(FI); |
| 812 | |
| 813 | // ARM halfword load/stores need an additional operand. |
| 814 | if (!isThumb && VT.getSimpleVT().SimpleTy == MVT::i16) MIB.addReg(0); |
| 815 | |
| 816 | MIB.addImm(Addr.Offset); |
| 817 | MIB.addMemOperand(MMO); |
| 818 | } else { |
| 819 | // Now add the rest of the operands. |
| 820 | MIB.addReg(Addr.Base.Reg); |
| 821 | |
| 822 | // ARM halfword load/stores need an additional operand. |
| 823 | if (!isThumb && VT.getSimpleVT().SimpleTy == MVT::i16) MIB.addReg(0); |
| 824 | |
| 825 | MIB.addImm(Addr.Offset); |
| 826 | } |
| 827 | AddOptionalDefs(MIB); |
| 828 | } |
| 829 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 830 | bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 831 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 832 | assert(VT.isSimple() && "Non-simple types are invalid here!"); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 833 | unsigned Opc; |
Eric Christopher | ee56ea6 | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 834 | TargetRegisterClass *RC; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 835 | switch (VT.getSimpleVT().SimpleTy) { |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 836 | // This is mostly going to be Neon/vector support. |
| 837 | default: return false; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 838 | case MVT::i16: |
Eric Christopher | 45c6071 | 2010-10-17 01:40:27 +0000 | [diff] [blame] | 839 | Opc = isThumb ? ARM::t2LDRHi12 : ARM::LDRH; |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 840 | RC = ARM::GPRRegisterClass; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 841 | break; |
| 842 | case MVT::i8: |
Jim Grosbach | c1d3021 | 2010-10-27 00:19:44 +0000 | [diff] [blame] | 843 | Opc = isThumb ? ARM::t2LDRBi12 : ARM::LDRBi12; |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 844 | RC = ARM::GPRRegisterClass; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 845 | break; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 846 | case MVT::i32: |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 847 | Opc = isThumb ? ARM::t2LDRi12 : ARM::LDRi12; |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 848 | RC = ARM::GPRRegisterClass; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 849 | break; |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 850 | case MVT::f32: |
| 851 | Opc = ARM::VLDRS; |
Eric Christopher | ee56ea6 | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 852 | RC = TLI.getRegClassFor(VT); |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 853 | break; |
| 854 | case MVT::f64: |
| 855 | Opc = ARM::VLDRD; |
Eric Christopher | ee56ea6 | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 856 | RC = TLI.getRegClassFor(VT); |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 857 | break; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 858 | } |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 859 | // Simplify this down to something we can handle. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 860 | ARMSimplifyAddress(Addr, VT); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 861 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 862 | // Create the base instruction, then add the operands. |
| 863 | ResultReg = createResultReg(RC); |
| 864 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 865 | TII.get(Opc), ResultReg); |
| 866 | AddLoadStoreOperands(VT, Addr, MIB); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 867 | return true; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 870 | bool ARMFastISel::SelectLoad(const Instruction *I) { |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 871 | // Verify we have a legal type before going any further. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 872 | MVT VT; |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 873 | if (!isLoadTypeLegal(I->getType(), VT)) |
| 874 | return false; |
| 875 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 876 | // See if we can handle this address. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 877 | Address Addr; |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 878 | if (!ARMComputeAddress(I->getOperand(0), Addr)) return false; |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 879 | |
| 880 | unsigned ResultReg; |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 881 | if (!ARMEmitLoad(VT, ResultReg, Addr)) return false; |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 882 | UpdateValueMap(I, ResultReg); |
| 883 | return true; |
| 884 | } |
| 885 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 886 | bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 887 | unsigned StrOpc; |
| 888 | switch (VT.getSimpleVT().SimpleTy) { |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 889 | // This is mostly going to be Neon/vector support. |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 890 | default: return false; |
Eric Christopher | 4c91412 | 2010-11-02 23:59:09 +0000 | [diff] [blame] | 891 | case MVT::i1: { |
| 892 | unsigned Res = createResultReg(isThumb ? ARM::tGPRRegisterClass : |
| 893 | ARM::GPRRegisterClass); |
| 894 | unsigned Opc = isThumb ? ARM::t2ANDri : ARM::ANDri; |
| 895 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 896 | TII.get(Opc), Res) |
| 897 | .addReg(SrcReg).addImm(1)); |
| 898 | SrcReg = Res; |
| 899 | } // Fallthrough here. |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 900 | case MVT::i8: |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 901 | StrOpc = isThumb ? ARM::t2STRBi12 : ARM::STRBi12; |
Eric Christopher | 1541877 | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 902 | break; |
| 903 | case MVT::i16: |
Eric Christopher | 45c6071 | 2010-10-17 01:40:27 +0000 | [diff] [blame] | 904 | StrOpc = isThumb ? ARM::t2STRHi12 : ARM::STRH; |
Eric Christopher | 1541877 | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 905 | break; |
Eric Christopher | 47650ec | 2010-10-16 01:10:35 +0000 | [diff] [blame] | 906 | case MVT::i32: |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 907 | StrOpc = isThumb ? ARM::t2STRi12 : ARM::STRi12; |
Eric Christopher | 47650ec | 2010-10-16 01:10:35 +0000 | [diff] [blame] | 908 | break; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 909 | case MVT::f32: |
| 910 | if (!Subtarget->hasVFP2()) return false; |
| 911 | StrOpc = ARM::VSTRS; |
| 912 | break; |
| 913 | case MVT::f64: |
| 914 | if (!Subtarget->hasVFP2()) return false; |
| 915 | StrOpc = ARM::VSTRD; |
| 916 | break; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 917 | } |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 918 | // Simplify this down to something we can handle. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 919 | ARMSimplifyAddress(Addr, VT); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 920 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 921 | // Create the base instruction, then add the operands. |
| 922 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 923 | TII.get(StrOpc)) |
| 924 | .addReg(SrcReg, getKillRegState(true)); |
| 925 | AddLoadStoreOperands(VT, Addr, MIB); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 926 | return true; |
| 927 | } |
| 928 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 929 | bool ARMFastISel::SelectStore(const Instruction *I) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 930 | Value *Op0 = I->getOperand(0); |
| 931 | unsigned SrcReg = 0; |
| 932 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 933 | // Verify we have a legal type before going any further. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 934 | MVT VT; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 935 | if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT)) |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 936 | return false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 937 | |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 938 | // Get the value to be stored into a register. |
| 939 | SrcReg = getRegForValue(Op0); |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 940 | if (SrcReg == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 941 | |
Eric Christopher | 564857f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 942 | // See if we can handle this address. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 943 | Address Addr; |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 944 | if (!ARMComputeAddress(I->getOperand(1), Addr)) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 945 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 946 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 947 | if (!ARMEmitStore(VT, SrcReg, Addr)) return false; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 948 | return true; |
| 949 | } |
| 950 | |
| 951 | static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) { |
| 952 | switch (Pred) { |
| 953 | // Needs two compares... |
| 954 | case CmpInst::FCMP_ONE: |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 955 | case CmpInst::FCMP_UEQ: |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 956 | default: |
Eric Christopher | 4053e63 | 2010-11-02 01:24:49 +0000 | [diff] [blame] | 957 | // AL is our "false" for now. The other two need more compares. |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 958 | return ARMCC::AL; |
| 959 | case CmpInst::ICMP_EQ: |
| 960 | case CmpInst::FCMP_OEQ: |
| 961 | return ARMCC::EQ; |
| 962 | case CmpInst::ICMP_SGT: |
| 963 | case CmpInst::FCMP_OGT: |
| 964 | return ARMCC::GT; |
| 965 | case CmpInst::ICMP_SGE: |
| 966 | case CmpInst::FCMP_OGE: |
| 967 | return ARMCC::GE; |
| 968 | case CmpInst::ICMP_UGT: |
| 969 | case CmpInst::FCMP_UGT: |
| 970 | return ARMCC::HI; |
| 971 | case CmpInst::FCMP_OLT: |
| 972 | return ARMCC::MI; |
| 973 | case CmpInst::ICMP_ULE: |
| 974 | case CmpInst::FCMP_OLE: |
| 975 | return ARMCC::LS; |
| 976 | case CmpInst::FCMP_ORD: |
| 977 | return ARMCC::VC; |
| 978 | case CmpInst::FCMP_UNO: |
| 979 | return ARMCC::VS; |
| 980 | case CmpInst::FCMP_UGE: |
| 981 | return ARMCC::PL; |
| 982 | case CmpInst::ICMP_SLT: |
| 983 | case CmpInst::FCMP_ULT: |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 984 | return ARMCC::LT; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 985 | case CmpInst::ICMP_SLE: |
| 986 | case CmpInst::FCMP_ULE: |
| 987 | return ARMCC::LE; |
| 988 | case CmpInst::FCMP_UNE: |
| 989 | case CmpInst::ICMP_NE: |
| 990 | return ARMCC::NE; |
| 991 | case CmpInst::ICMP_UGE: |
| 992 | return ARMCC::HS; |
| 993 | case CmpInst::ICMP_ULT: |
| 994 | return ARMCC::LO; |
| 995 | } |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 998 | bool ARMFastISel::SelectBranch(const Instruction *I) { |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 999 | const BranchInst *BI = cast<BranchInst>(I); |
| 1000 | MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)]; |
| 1001 | MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)]; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1002 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1003 | // Simple branch support. |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1004 | |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1005 | // If we can, avoid recomputing the compare - redoing it could lead to wonky |
| 1006 | // behavior. |
| 1007 | // TODO: Factor this out. |
| 1008 | if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) { |
| 1009 | if (CI->hasOneUse() && (CI->getParent() == I->getParent())) { |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1010 | MVT VT; |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1011 | const Type *Ty = CI->getOperand(0)->getType(); |
Eric Christopher | 76d6147 | 2010-10-30 21:25:26 +0000 | [diff] [blame] | 1012 | if (!isTypeLegal(Ty, VT)) |
| 1013 | return false; |
| 1014 | |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1015 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 1016 | if (isFloat && !Subtarget->hasVFP2()) |
| 1017 | return false; |
| 1018 | |
| 1019 | unsigned CmpOpc; |
| 1020 | unsigned CondReg; |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1021 | switch (VT.SimpleTy) { |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1022 | default: return false; |
| 1023 | // TODO: Verify compares. |
| 1024 | case MVT::f32: |
| 1025 | CmpOpc = ARM::VCMPES; |
| 1026 | CondReg = ARM::FPSCR; |
| 1027 | break; |
| 1028 | case MVT::f64: |
| 1029 | CmpOpc = ARM::VCMPED; |
| 1030 | CondReg = ARM::FPSCR; |
| 1031 | break; |
| 1032 | case MVT::i32: |
| 1033 | CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr; |
| 1034 | CondReg = ARM::CPSR; |
| 1035 | break; |
| 1036 | } |
| 1037 | |
| 1038 | // Get the compare predicate. |
| 1039 | ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate()); |
| 1040 | |
| 1041 | // We may not handle every CC for now. |
| 1042 | if (ARMPred == ARMCC::AL) return false; |
| 1043 | |
| 1044 | unsigned Arg1 = getRegForValue(CI->getOperand(0)); |
| 1045 | if (Arg1 == 0) return false; |
| 1046 | |
| 1047 | unsigned Arg2 = getRegForValue(CI->getOperand(1)); |
| 1048 | if (Arg2 == 0) return false; |
| 1049 | |
| 1050 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1051 | TII.get(CmpOpc)) |
| 1052 | .addReg(Arg1).addReg(Arg2)); |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1053 | |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1054 | // For floating point we need to move the result to a comparison register |
| 1055 | // that we can then use for branches. |
| 1056 | if (isFloat) |
| 1057 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1058 | TII.get(ARM::FMSTAT))); |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1059 | |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1060 | unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc; |
| 1061 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
| 1062 | .addMBB(TBB).addImm(ARMPred).addReg(ARM::CPSR); |
| 1063 | FastEmitBranch(FBB, DL); |
| 1064 | FuncInfo.MBB->addSuccessor(TBB); |
| 1065 | return true; |
| 1066 | } |
| 1067 | } |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1068 | |
Eric Christopher | 0e6233b | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1069 | unsigned CmpReg = getRegForValue(BI->getCondition()); |
| 1070 | if (CmpReg == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1071 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1072 | // Re-set the flags just in case. |
| 1073 | unsigned CmpOpc = isThumb ? ARM::t2CMPri : ARM::CMPri; |
| 1074 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
Eric Christopher | 000cf70 | 2010-11-03 04:29:11 +0000 | [diff] [blame] | 1075 | .addReg(CmpReg).addImm(0)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1076 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1077 | unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1078 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
Eric Christopher | 000cf70 | 2010-11-03 04:29:11 +0000 | [diff] [blame] | 1079 | .addMBB(TBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1080 | FastEmitBranch(FBB, DL); |
| 1081 | FuncInfo.MBB->addSuccessor(TBB); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1082 | return true; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1085 | bool ARMFastISel::SelectCmp(const Instruction *I) { |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1086 | const CmpInst *CI = cast<CmpInst>(I); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1087 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1088 | MVT VT; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1089 | const Type *Ty = CI->getOperand(0)->getType(); |
| 1090 | if (!isTypeLegal(Ty, VT)) |
| 1091 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1092 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1093 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 1094 | if (isFloat && !Subtarget->hasVFP2()) |
| 1095 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1096 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1097 | unsigned CmpOpc; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1098 | unsigned CondReg; |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1099 | switch (VT.SimpleTy) { |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1100 | default: return false; |
| 1101 | // TODO: Verify compares. |
| 1102 | case MVT::f32: |
| 1103 | CmpOpc = ARM::VCMPES; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1104 | CondReg = ARM::FPSCR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1105 | break; |
| 1106 | case MVT::f64: |
| 1107 | CmpOpc = ARM::VCMPED; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1108 | CondReg = ARM::FPSCR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | case MVT::i32: |
| 1111 | CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1112 | CondReg = ARM::CPSR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1113 | break; |
| 1114 | } |
| 1115 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1116 | // Get the compare predicate. |
| 1117 | ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate()); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1118 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1119 | // We may not handle every CC for now. |
| 1120 | if (ARMPred == ARMCC::AL) return false; |
| 1121 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1122 | unsigned Arg1 = getRegForValue(CI->getOperand(0)); |
| 1123 | if (Arg1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1124 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1125 | unsigned Arg2 = getRegForValue(CI->getOperand(1)); |
| 1126 | if (Arg2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1127 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1128 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 1129 | .addReg(Arg1).addReg(Arg2)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1130 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1131 | // For floating point we need to move the result to a comparison register |
| 1132 | // that we can then use for branches. |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1133 | if (isFloat) |
| 1134 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1135 | TII.get(ARM::FMSTAT))); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1136 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1137 | // Now set a register based on the comparison. Explicitly set the predicates |
| 1138 | // here. |
Eric Christopher | 338c253 | 2010-10-07 05:31:49 +0000 | [diff] [blame] | 1139 | unsigned MovCCOpc = isThumb ? ARM::t2MOVCCi : ARM::MOVCCi; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1140 | TargetRegisterClass *RC = isThumb ? ARM::rGPRRegisterClass |
Eric Christopher | 5d18d92 | 2010-10-07 05:39:19 +0000 | [diff] [blame] | 1141 | : ARM::GPRRegisterClass; |
| 1142 | unsigned DestReg = createResultReg(RC); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1143 | Constant *Zero |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 1144 | = ConstantInt::get(Type::getInt32Ty(*Context), 0); |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1145 | unsigned ZeroReg = TargetMaterializeConstant(Zero); |
| 1146 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), DestReg) |
| 1147 | .addReg(ZeroReg).addImm(1) |
| 1148 | .addImm(ARMPred).addReg(CondReg); |
| 1149 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1150 | UpdateValueMap(I, DestReg); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1151 | return true; |
| 1152 | } |
| 1153 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1154 | bool ARMFastISel::SelectFPExt(const Instruction *I) { |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1155 | // Make sure we have VFP and that we're extending float to double. |
| 1156 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1157 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1158 | Value *V = I->getOperand(0); |
| 1159 | if (!I->getType()->isDoubleTy() || |
| 1160 | !V->getType()->isFloatTy()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1161 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1162 | unsigned Op = getRegForValue(V); |
| 1163 | if (Op == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1164 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1165 | unsigned Result = createResultReg(ARM::DPRRegisterClass); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1166 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 1167 | TII.get(ARM::VCVTDS), Result) |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1168 | .addReg(Op)); |
| 1169 | UpdateValueMap(I, Result); |
| 1170 | return true; |
| 1171 | } |
| 1172 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1173 | bool ARMFastISel::SelectFPTrunc(const Instruction *I) { |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1174 | // Make sure we have VFP and that we're truncating double to float. |
| 1175 | if (!Subtarget->hasVFP2()) return false; |
| 1176 | |
| 1177 | Value *V = I->getOperand(0); |
Eric Christopher | 022b7fb | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1178 | if (!(I->getType()->isFloatTy() && |
| 1179 | V->getType()->isDoubleTy())) return false; |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1180 | |
| 1181 | unsigned Op = getRegForValue(V); |
| 1182 | if (Op == 0) return false; |
| 1183 | |
| 1184 | unsigned Result = createResultReg(ARM::SPRRegisterClass); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1185 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 1186 | TII.get(ARM::VCVTSD), Result) |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1187 | .addReg(Op)); |
| 1188 | UpdateValueMap(I, Result); |
| 1189 | return true; |
| 1190 | } |
| 1191 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1192 | bool ARMFastISel::SelectSIToFP(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1193 | // Make sure we have VFP. |
| 1194 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1195 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1196 | MVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1197 | const Type *Ty = I->getType(); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1198 | if (!isTypeLegal(Ty, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1199 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1200 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1201 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 1202 | if (Op == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1203 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1204 | // The conversion routine works on fp-reg to fp-reg and the operand above |
| 1205 | // was an integer, move it to the fp registers if possible. |
Eric Christopher | 022b7fb | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1206 | unsigned FP = ARMMoveToFPReg(MVT::f32, Op); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1207 | if (FP == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1208 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1209 | unsigned Opc; |
| 1210 | if (Ty->isFloatTy()) Opc = ARM::VSITOS; |
| 1211 | else if (Ty->isDoubleTy()) Opc = ARM::VSITOD; |
| 1212 | else return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1213 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1214 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1215 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 1216 | ResultReg) |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1217 | .addReg(FP)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1218 | UpdateValueMap(I, ResultReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1219 | return true; |
| 1220 | } |
| 1221 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1222 | bool ARMFastISel::SelectFPToSI(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1223 | // Make sure we have VFP. |
| 1224 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1225 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1226 | MVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1227 | const Type *RetTy = I->getType(); |
Eric Christopher | 920a208 | 2010-09-10 00:35:09 +0000 | [diff] [blame] | 1228 | if (!isTypeLegal(RetTy, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1229 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1230 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1231 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 1232 | if (Op == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1233 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1234 | unsigned Opc; |
| 1235 | const Type *OpTy = I->getOperand(0)->getType(); |
| 1236 | if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS; |
| 1237 | else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD; |
| 1238 | else return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1239 | |
Eric Christopher | 022b7fb | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1240 | // f64->s32 or f32->s32 both need an intermediate f32 reg. |
| 1241 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1242 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 1243 | ResultReg) |
| 1244 | .addReg(Op)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1245 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1246 | // This result needs to be in an integer register, but the conversion only |
| 1247 | // takes place in fp-regs. |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1248 | unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1249 | if (IntReg == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1250 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1251 | UpdateValueMap(I, IntReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1252 | return true; |
| 1253 | } |
| 1254 | |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1255 | bool ARMFastISel::SelectSelect(const Instruction *I) { |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1256 | MVT VT; |
| 1257 | if (!isTypeLegal(I->getType(), VT)) |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1258 | return false; |
| 1259 | |
| 1260 | // Things need to be register sized for register moves. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1261 | if (VT != MVT::i32) return false; |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1262 | const TargetRegisterClass *RC = TLI.getRegClassFor(VT); |
| 1263 | |
| 1264 | unsigned CondReg = getRegForValue(I->getOperand(0)); |
| 1265 | if (CondReg == 0) return false; |
| 1266 | unsigned Op1Reg = getRegForValue(I->getOperand(1)); |
| 1267 | if (Op1Reg == 0) return false; |
| 1268 | unsigned Op2Reg = getRegForValue(I->getOperand(2)); |
| 1269 | if (Op2Reg == 0) return false; |
| 1270 | |
| 1271 | unsigned CmpOpc = isThumb ? ARM::t2TSTri : ARM::TSTri; |
| 1272 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 1273 | .addReg(CondReg).addImm(1)); |
| 1274 | unsigned ResultReg = createResultReg(RC); |
| 1275 | unsigned MovCCOpc = isThumb ? ARM::t2MOVCCr : ARM::MOVCCr; |
| 1276 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), ResultReg) |
| 1277 | .addReg(Op1Reg).addReg(Op2Reg) |
| 1278 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 1279 | UpdateValueMap(I, ResultReg); |
| 1280 | return true; |
| 1281 | } |
| 1282 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1283 | bool ARMFastISel::SelectSDiv(const Instruction *I) { |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1284 | MVT VT; |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1285 | const Type *Ty = I->getType(); |
| 1286 | if (!isTypeLegal(Ty, VT)) |
| 1287 | return false; |
| 1288 | |
| 1289 | // If we have integer div support we should have selected this automagically. |
| 1290 | // In case we have a real miss go ahead and return false and we'll pick |
| 1291 | // it up later. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1292 | if (Subtarget->hasDivide()) return false; |
| 1293 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1294 | // Otherwise emit a libcall. |
| 1295 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Eric Christopher | 7bdc4de | 2010-10-11 08:31:54 +0000 | [diff] [blame] | 1296 | if (VT == MVT::i8) |
| 1297 | LC = RTLIB::SDIV_I8; |
| 1298 | else if (VT == MVT::i16) |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1299 | LC = RTLIB::SDIV_I16; |
| 1300 | else if (VT == MVT::i32) |
| 1301 | LC = RTLIB::SDIV_I32; |
| 1302 | else if (VT == MVT::i64) |
| 1303 | LC = RTLIB::SDIV_I64; |
| 1304 | else if (VT == MVT::i128) |
| 1305 | LC = RTLIB::SDIV_I128; |
| 1306 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!"); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1307 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1308 | return ARMEmitLibcall(I, LC); |
| 1309 | } |
| 1310 | |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1311 | bool ARMFastISel::SelectSRem(const Instruction *I) { |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1312 | MVT VT; |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1313 | const Type *Ty = I->getType(); |
| 1314 | if (!isTypeLegal(Ty, VT)) |
| 1315 | return false; |
| 1316 | |
| 1317 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 1318 | if (VT == MVT::i8) |
| 1319 | LC = RTLIB::SREM_I8; |
| 1320 | else if (VT == MVT::i16) |
| 1321 | LC = RTLIB::SREM_I16; |
| 1322 | else if (VT == MVT::i32) |
| 1323 | LC = RTLIB::SREM_I32; |
| 1324 | else if (VT == MVT::i64) |
| 1325 | LC = RTLIB::SREM_I64; |
| 1326 | else if (VT == MVT::i128) |
| 1327 | LC = RTLIB::SREM_I128; |
Eric Christopher | a1640d9 | 2010-10-11 08:40:05 +0000 | [diff] [blame] | 1328 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!"); |
Eric Christopher | 2896df8 | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 1329 | |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1330 | return ARMEmitLibcall(I, LC); |
| 1331 | } |
| 1332 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1333 | bool ARMFastISel::SelectBinaryOp(const Instruction *I, unsigned ISDOpcode) { |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1334 | EVT VT = TLI.getValueType(I->getType(), true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1335 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1336 | // We can get here in the case when we want to use NEON for our fp |
| 1337 | // operations, but can't figure out how to. Just use the vfp instructions |
| 1338 | // if we have them. |
| 1339 | // FIXME: It'd be nice to use NEON instructions. |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1340 | const Type *Ty = I->getType(); |
| 1341 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 1342 | if (isFloat && !Subtarget->hasVFP2()) |
| 1343 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1344 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1345 | unsigned Op1 = getRegForValue(I->getOperand(0)); |
| 1346 | if (Op1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1347 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1348 | unsigned Op2 = getRegForValue(I->getOperand(1)); |
| 1349 | if (Op2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1350 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1351 | unsigned Opc; |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 1352 | bool is64bit = VT == MVT::f64 || VT == MVT::i64; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1353 | switch (ISDOpcode) { |
| 1354 | default: return false; |
| 1355 | case ISD::FADD: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1356 | Opc = is64bit ? ARM::VADDD : ARM::VADDS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1357 | break; |
| 1358 | case ISD::FSUB: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1359 | Opc = is64bit ? ARM::VSUBD : ARM::VSUBS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1360 | break; |
| 1361 | case ISD::FMUL: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1362 | Opc = is64bit ? ARM::VMULD : ARM::VMULS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1363 | break; |
| 1364 | } |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1365 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1366 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1367 | TII.get(Opc), ResultReg) |
| 1368 | .addReg(Op1).addReg(Op2)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1369 | UpdateValueMap(I, ResultReg); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1370 | return true; |
| 1371 | } |
| 1372 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1373 | // Call Handling Code |
| 1374 | |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1375 | bool ARMFastISel::FastEmitExtend(ISD::NodeType Opc, EVT DstVT, unsigned Src, |
| 1376 | EVT SrcVT, unsigned &ResultReg) { |
| 1377 | unsigned RR = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(), Opc, |
| 1378 | Src, /*TODO: Kill=*/false); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1379 | |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1380 | if (RR != 0) { |
| 1381 | ResultReg = RR; |
| 1382 | return true; |
| 1383 | } else |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1384 | return false; |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1387 | // This is largely taken directly from CCAssignFnForNode - we don't support |
| 1388 | // varargs in FastISel so that part has been removed. |
| 1389 | // TODO: We may not support all of this. |
| 1390 | CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) { |
| 1391 | switch (CC) { |
| 1392 | default: |
| 1393 | llvm_unreachable("Unsupported calling convention"); |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1394 | case CallingConv::Fast: |
Evan Cheng | 1f8b40d | 2010-10-22 18:57:05 +0000 | [diff] [blame] | 1395 | // Ignore fastcc. Silence compiler warnings. |
| 1396 | (void)RetFastCC_ARM_APCS; |
| 1397 | (void)FastCC_ARM_APCS; |
| 1398 | // Fallthrough |
| 1399 | case CallingConv::C: |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1400 | // Use target triple & subtarget features to do actual dispatch. |
| 1401 | if (Subtarget->isAAPCS_ABI()) { |
| 1402 | if (Subtarget->hasVFP2() && |
| 1403 | FloatABIType == FloatABI::Hard) |
| 1404 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1405 | else |
| 1406 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1407 | } else |
| 1408 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1409 | case CallingConv::ARM_AAPCS_VFP: |
| 1410 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1411 | case CallingConv::ARM_AAPCS: |
| 1412 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1413 | case CallingConv::ARM_APCS: |
| 1414 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1415 | } |
| 1416 | } |
| 1417 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1418 | bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
| 1419 | SmallVectorImpl<unsigned> &ArgRegs, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1420 | SmallVectorImpl<MVT> &ArgVTs, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1421 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 1422 | SmallVectorImpl<unsigned> &RegArgs, |
| 1423 | CallingConv::ID CC, |
| 1424 | unsigned &NumBytes) { |
| 1425 | SmallVector<CCValAssign, 16> ArgLocs; |
| 1426 | CCState CCInfo(CC, false, TM, ArgLocs, *Context); |
| 1427 | CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC, false)); |
| 1428 | |
| 1429 | // Get a count of how many bytes are to be pushed on the stack. |
| 1430 | NumBytes = CCInfo.getNextStackOffset(); |
| 1431 | |
| 1432 | // Issue CALLSEQ_START |
| 1433 | unsigned AdjStackDown = TM.getRegisterInfo()->getCallFrameSetupOpcode(); |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 1434 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1435 | TII.get(AdjStackDown)) |
| 1436 | .addImm(NumBytes)); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1437 | |
| 1438 | // Process the args. |
| 1439 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1440 | CCValAssign &VA = ArgLocs[i]; |
| 1441 | unsigned Arg = ArgRegs[VA.getValNo()]; |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1442 | MVT ArgVT = ArgVTs[VA.getValNo()]; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1443 | |
Eric Christopher | a4633f5 | 2010-10-23 09:37:17 +0000 | [diff] [blame] | 1444 | // We don't handle NEON parameters yet. |
| 1445 | if (VA.getLocVT().isVector() && VA.getLocVT().getSizeInBits() > 64) |
| 1446 | return false; |
| 1447 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1448 | // Handle arg promotion, etc. |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1449 | switch (VA.getLocInfo()) { |
| 1450 | case CCValAssign::Full: break; |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1451 | case CCValAssign::SExt: { |
| 1452 | bool Emitted = FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(), |
| 1453 | Arg, ArgVT, Arg); |
| 1454 | assert(Emitted && "Failed to emit a sext!"); Emitted=Emitted; |
| 1455 | Emitted = true; |
| 1456 | ArgVT = VA.getLocVT(); |
| 1457 | break; |
| 1458 | } |
| 1459 | case CCValAssign::ZExt: { |
| 1460 | bool Emitted = FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(), |
| 1461 | Arg, ArgVT, Arg); |
| 1462 | assert(Emitted && "Failed to emit a zext!"); Emitted=Emitted; |
| 1463 | Emitted = true; |
| 1464 | ArgVT = VA.getLocVT(); |
| 1465 | break; |
| 1466 | } |
| 1467 | case CCValAssign::AExt: { |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1468 | bool Emitted = FastEmitExtend(ISD::ANY_EXTEND, VA.getLocVT(), |
| 1469 | Arg, ArgVT, Arg); |
| 1470 | if (!Emitted) |
| 1471 | Emitted = FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(), |
| 1472 | Arg, ArgVT, Arg); |
| 1473 | if (!Emitted) |
| 1474 | Emitted = FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(), |
| 1475 | Arg, ArgVT, Arg); |
| 1476 | |
| 1477 | assert(Emitted && "Failed to emit a aext!"); Emitted=Emitted; |
| 1478 | ArgVT = VA.getLocVT(); |
| 1479 | break; |
| 1480 | } |
| 1481 | case CCValAssign::BCvt: { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1482 | unsigned BC = FastEmit_r(ArgVT, VA.getLocVT(), ISD::BITCAST, Arg, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1483 | /*TODO: Kill=*/false); |
Eric Christopher | fa87d66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1484 | assert(BC != 0 && "Failed to emit a bitcast!"); |
| 1485 | Arg = BC; |
| 1486 | ArgVT = VA.getLocVT(); |
| 1487 | break; |
| 1488 | } |
| 1489 | default: llvm_unreachable("Unknown arg promotion!"); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | // Now copy/store arg to correct locations. |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 1493 | if (VA.isRegLoc() && !VA.needsCustom()) { |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1494 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1495 | VA.getLocReg()) |
| 1496 | .addReg(Arg); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1497 | RegArgs.push_back(VA.getLocReg()); |
Eric Christopher | 2d8f6fe | 2010-10-21 00:01:47 +0000 | [diff] [blame] | 1498 | } else if (VA.needsCustom()) { |
| 1499 | // TODO: We need custom lowering for vector (v2f64) args. |
| 1500 | if (VA.getLocVT() != MVT::f64) return false; |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1501 | |
Eric Christopher | 2d8f6fe | 2010-10-21 00:01:47 +0000 | [diff] [blame] | 1502 | CCValAssign &NextVA = ArgLocs[++i]; |
| 1503 | |
| 1504 | // TODO: Only handle register args for now. |
| 1505 | if(!(VA.isRegLoc() && NextVA.isRegLoc())) return false; |
| 1506 | |
| 1507 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1508 | TII.get(ARM::VMOVRRD), VA.getLocReg()) |
| 1509 | .addReg(NextVA.getLocReg(), RegState::Define) |
| 1510 | .addReg(Arg)); |
| 1511 | RegArgs.push_back(VA.getLocReg()); |
| 1512 | RegArgs.push_back(NextVA.getLocReg()); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1513 | } else { |
Eric Christopher | 5b92480 | 2010-10-21 20:09:54 +0000 | [diff] [blame] | 1514 | assert(VA.isMemLoc()); |
| 1515 | // Need to store on the stack. |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1516 | Address Addr; |
| 1517 | Addr.BaseType = Address::RegBase; |
| 1518 | Addr.Base.Reg = ARM::SP; |
| 1519 | Addr.Offset = VA.getLocMemOffset(); |
Eric Christopher | 5b92480 | 2010-10-21 20:09:54 +0000 | [diff] [blame] | 1520 | |
Eric Christopher | 0d58122 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1521 | if (!ARMEmitStore(ArgVT, Arg, Addr)) return false; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1522 | } |
| 1523 | } |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1524 | return true; |
| 1525 | } |
| 1526 | |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1527 | bool ARMFastISel::FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1528 | const Instruction *I, CallingConv::ID CC, |
| 1529 | unsigned &NumBytes) { |
| 1530 | // Issue CALLSEQ_END |
| 1531 | unsigned AdjStackUp = TM.getRegisterInfo()->getCallFrameDestroyOpcode(); |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 1532 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1533 | TII.get(AdjStackUp)) |
| 1534 | .addImm(NumBytes).addImm(0)); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1535 | |
| 1536 | // Now the return value. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1537 | if (RetVT != MVT::isVoid) { |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1538 | SmallVector<CCValAssign, 16> RVLocs; |
| 1539 | CCState CCInfo(CC, false, TM, RVLocs, *Context); |
| 1540 | CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true)); |
| 1541 | |
| 1542 | // Copy all of the result registers out of their specified physreg. |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1543 | if (RVLocs.size() == 2 && RetVT == MVT::f64) { |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1544 | // For this move we copy into two registers and then move into the |
| 1545 | // double fp reg we want. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1546 | EVT DestVT = RVLocs[0].getValVT(); |
| 1547 | TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT); |
| 1548 | unsigned ResultReg = createResultReg(DstRC); |
| 1549 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1550 | TII.get(ARM::VMOVDRR), ResultReg) |
Eric Christopher | 3659ac2 | 2010-10-20 08:02:24 +0000 | [diff] [blame] | 1551 | .addReg(RVLocs[0].getLocReg()) |
| 1552 | .addReg(RVLocs[1].getLocReg())); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1553 | |
Eric Christopher | 3659ac2 | 2010-10-20 08:02:24 +0000 | [diff] [blame] | 1554 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
| 1555 | UsedRegs.push_back(RVLocs[1].getLocReg()); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1556 | |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1557 | // Finally update the result. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1558 | UpdateValueMap(I, ResultReg); |
| 1559 | } else { |
Jim Grosbach | 9536959 | 2010-10-13 23:34:31 +0000 | [diff] [blame] | 1560 | assert(RVLocs.size() == 1 &&"Can't handle non-double multi-reg retvals!"); |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1561 | EVT CopyVT = RVLocs[0].getValVT(); |
| 1562 | TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1563 | |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1564 | unsigned ResultReg = createResultReg(DstRC); |
| 1565 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1566 | ResultReg).addReg(RVLocs[0].getLocReg()); |
| 1567 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1568 | |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1569 | // Finally update the result. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1570 | UpdateValueMap(I, ResultReg); |
| 1571 | } |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1574 | return true; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1577 | bool ARMFastISel::SelectRet(const Instruction *I) { |
| 1578 | const ReturnInst *Ret = cast<ReturnInst>(I); |
| 1579 | const Function &F = *I->getParent()->getParent(); |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1580 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1581 | if (!FuncInfo.CanLowerReturn) |
| 1582 | return false; |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1583 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1584 | if (F.isVarArg()) |
| 1585 | return false; |
| 1586 | |
| 1587 | CallingConv::ID CC = F.getCallingConv(); |
| 1588 | if (Ret->getNumOperands() > 0) { |
| 1589 | SmallVector<ISD::OutputArg, 4> Outs; |
| 1590 | GetReturnInfo(F.getReturnType(), F.getAttributes().getRetAttributes(), |
| 1591 | Outs, TLI); |
| 1592 | |
| 1593 | // Analyze operands of the call, assigning locations to each operand. |
| 1594 | SmallVector<CCValAssign, 16> ValLocs; |
| 1595 | CCState CCInfo(CC, F.isVarArg(), TM, ValLocs, I->getContext()); |
| 1596 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForCall(CC, true /* is Ret */)); |
| 1597 | |
| 1598 | const Value *RV = Ret->getOperand(0); |
| 1599 | unsigned Reg = getRegForValue(RV); |
| 1600 | if (Reg == 0) |
| 1601 | return false; |
| 1602 | |
| 1603 | // Only handle a single return value for now. |
| 1604 | if (ValLocs.size() != 1) |
| 1605 | return false; |
| 1606 | |
| 1607 | CCValAssign &VA = ValLocs[0]; |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1608 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1609 | // Don't bother handling odd stuff for now. |
| 1610 | if (VA.getLocInfo() != CCValAssign::Full) |
| 1611 | return false; |
| 1612 | // Only handle register returns for now. |
| 1613 | if (!VA.isRegLoc()) |
| 1614 | return false; |
| 1615 | // TODO: For now, don't try to handle cases where getLocInfo() |
| 1616 | // says Full but the types don't match. |
Duncan Sands | 1e96bab | 2010-11-04 10:49:57 +0000 | [diff] [blame] | 1617 | if (TLI.getValueType(RV->getType()) != VA.getValVT()) |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1618 | return false; |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1619 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1620 | // Make the copy. |
| 1621 | unsigned SrcReg = Reg + VA.getValNo(); |
| 1622 | unsigned DstReg = VA.getLocReg(); |
| 1623 | const TargetRegisterClass* SrcRC = MRI.getRegClass(SrcReg); |
| 1624 | // Avoid a cross-class copy. This is very unlikely. |
| 1625 | if (!SrcRC->contains(DstReg)) |
| 1626 | return false; |
| 1627 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1628 | DstReg).addReg(SrcReg); |
| 1629 | |
| 1630 | // Mark the register as live out of the function. |
| 1631 | MRI.addLiveOut(VA.getLocReg()); |
| 1632 | } |
Jim Grosbach | 6b15639 | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1633 | |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1634 | unsigned RetOpc = isThumb ? ARM::tBX_RET : ARM::BX_RET; |
| 1635 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1636 | TII.get(RetOpc))); |
| 1637 | return true; |
| 1638 | } |
| 1639 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1640 | // A quick function that will emit a call for a named libcall in F with the |
| 1641 | // 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] | 1642 | // can emit a call for any libcall we can produce. This is an abridged version |
| 1643 | // 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] | 1644 | // like computed function pointers or strange arguments at call sites. |
| 1645 | // TODO: Try to unify this and the normal call bits for ARM, then try to unify |
| 1646 | // with X86. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1647 | bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) { |
| 1648 | CallingConv::ID CC = TLI.getLibcallCallingConv(Call); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1649 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1650 | // Handle *simple* calls for now. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1651 | const Type *RetTy = I->getType(); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1652 | MVT RetVT; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1653 | if (RetTy->isVoidTy()) |
| 1654 | RetVT = MVT::isVoid; |
| 1655 | else if (!isTypeLegal(RetTy, RetVT)) |
| 1656 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1657 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1658 | // For now we're using BLX etc on the assumption that we have v5t ops. |
| 1659 | if (!Subtarget->hasV5TOps()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1660 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 1661 | // TODO: For now if we have long calls specified we don't handle the call. |
| 1662 | if (EnableARMLongCalls) return false; |
| 1663 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1664 | // Set up the argument vectors. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1665 | SmallVector<Value*, 8> Args; |
| 1666 | SmallVector<unsigned, 8> ArgRegs; |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1667 | SmallVector<MVT, 8> ArgVTs; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1668 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 1669 | Args.reserve(I->getNumOperands()); |
| 1670 | ArgRegs.reserve(I->getNumOperands()); |
| 1671 | ArgVTs.reserve(I->getNumOperands()); |
| 1672 | ArgFlags.reserve(I->getNumOperands()); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1673 | for (unsigned i = 0; i < I->getNumOperands(); ++i) { |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1674 | Value *Op = I->getOperand(i); |
| 1675 | unsigned Arg = getRegForValue(Op); |
| 1676 | if (Arg == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1677 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1678 | const Type *ArgTy = Op->getType(); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1679 | MVT ArgVT; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1680 | if (!isTypeLegal(ArgTy, ArgVT)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1681 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1682 | ISD::ArgFlagsTy Flags; |
| 1683 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 1684 | Flags.setOrigAlign(OriginalAlignment); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1685 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1686 | Args.push_back(Op); |
| 1687 | ArgRegs.push_back(Arg); |
| 1688 | ArgVTs.push_back(ArgVT); |
| 1689 | ArgFlags.push_back(Flags); |
| 1690 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1691 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1692 | // Handle the arguments now that we've gotten them. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1693 | SmallVector<unsigned, 4> RegArgs; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1694 | unsigned NumBytes; |
| 1695 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes)) |
| 1696 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1697 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1698 | // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1699 | // TODO: Turn this into the table of arm call ops. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1700 | MachineInstrBuilder MIB; |
Eric Christopher | c109556 | 2010-09-18 02:32:38 +0000 | [diff] [blame] | 1701 | unsigned CallOpc; |
Eric Christopher | c19aadb | 2010-12-21 03:50:43 +0000 | [diff] [blame] | 1702 | if(isThumb) { |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1703 | CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi; |
Eric Christopher | c19aadb | 2010-12-21 03:50:43 +0000 | [diff] [blame] | 1704 | // Explicitly adding the predicate here. |
| 1705 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1706 | TII.get(CallOpc))) |
| 1707 | .addExternalSymbol(TLI.getLibcallName(Call)); |
| 1708 | } else { |
Eric Christopher | c109556 | 2010-09-18 02:32:38 +0000 | [diff] [blame] | 1709 | CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL; |
Eric Christopher | c19aadb | 2010-12-21 03:50:43 +0000 | [diff] [blame] | 1710 | // Explicitly adding the predicate here. |
| 1711 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1712 | TII.get(CallOpc)) |
| 1713 | .addExternalSymbol(TLI.getLibcallName(Call))); |
| 1714 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1715 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1716 | // Add implicit physical register uses to the call. |
| 1717 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 1718 | MIB.addReg(RegArgs[i]); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1719 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1720 | // Finish off the call including any return values. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1721 | SmallVector<unsigned, 4> UsedRegs; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1722 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1723 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1724 | // Set all unused physreg defs as dead. |
| 1725 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1726 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1727 | return true; |
| 1728 | } |
| 1729 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1730 | bool ARMFastISel::SelectCall(const Instruction *I) { |
| 1731 | const CallInst *CI = cast<CallInst>(I); |
| 1732 | const Value *Callee = CI->getCalledValue(); |
| 1733 | |
| 1734 | // Can't handle inline asm or worry about intrinsics yet. |
| 1735 | if (isa<InlineAsm>(Callee) || isa<IntrinsicInst>(CI)) return false; |
| 1736 | |
Eric Christopher | e6ca677 | 2010-10-01 21:33:12 +0000 | [diff] [blame] | 1737 | // Only handle global variable Callees that are direct calls. |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1738 | const GlobalValue *GV = dyn_cast<GlobalValue>(Callee); |
Eric Christopher | e6ca677 | 2010-10-01 21:33:12 +0000 | [diff] [blame] | 1739 | if (!GV || Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel())) |
| 1740 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1741 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1742 | // Check the calling convention. |
| 1743 | ImmutableCallSite CS(CI); |
| 1744 | CallingConv::ID CC = CS.getCallingConv(); |
Eric Christopher | 4cf34c6 | 2010-10-18 06:49:12 +0000 | [diff] [blame] | 1745 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1746 | // TODO: Avoid some calling conventions? |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1747 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1748 | // Let SDISel handle vararg functions. |
| 1749 | const PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType()); |
| 1750 | const FunctionType *FTy = cast<FunctionType>(PT->getElementType()); |
| 1751 | if (FTy->isVarArg()) |
| 1752 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1753 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1754 | // Handle *simple* calls for now. |
| 1755 | const Type *RetTy = I->getType(); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1756 | MVT RetVT; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1757 | if (RetTy->isVoidTy()) |
| 1758 | RetVT = MVT::isVoid; |
| 1759 | else if (!isTypeLegal(RetTy, RetVT)) |
| 1760 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1761 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1762 | // For now we're using BLX etc on the assumption that we have v5t ops. |
| 1763 | // TODO: Maybe? |
| 1764 | if (!Subtarget->hasV5TOps()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1765 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 1766 | // TODO: For now if we have long calls specified we don't handle the call. |
| 1767 | if (EnableARMLongCalls) return false; |
| 1768 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1769 | // Set up the argument vectors. |
| 1770 | SmallVector<Value*, 8> Args; |
| 1771 | SmallVector<unsigned, 8> ArgRegs; |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1772 | SmallVector<MVT, 8> ArgVTs; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1773 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 1774 | Args.reserve(CS.arg_size()); |
| 1775 | ArgRegs.reserve(CS.arg_size()); |
| 1776 | ArgVTs.reserve(CS.arg_size()); |
| 1777 | ArgFlags.reserve(CS.arg_size()); |
| 1778 | for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end(); |
| 1779 | i != e; ++i) { |
| 1780 | unsigned Arg = getRegForValue(*i); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1781 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1782 | if (Arg == 0) |
| 1783 | return false; |
| 1784 | ISD::ArgFlagsTy Flags; |
| 1785 | unsigned AttrInd = i - CS.arg_begin() + 1; |
| 1786 | if (CS.paramHasAttr(AttrInd, Attribute::SExt)) |
| 1787 | Flags.setSExt(); |
| 1788 | if (CS.paramHasAttr(AttrInd, Attribute::ZExt)) |
| 1789 | Flags.setZExt(); |
| 1790 | |
| 1791 | // FIXME: Only handle *easy* calls for now. |
| 1792 | if (CS.paramHasAttr(AttrInd, Attribute::InReg) || |
| 1793 | CS.paramHasAttr(AttrInd, Attribute::StructRet) || |
| 1794 | CS.paramHasAttr(AttrInd, Attribute::Nest) || |
| 1795 | CS.paramHasAttr(AttrInd, Attribute::ByVal)) |
| 1796 | return false; |
| 1797 | |
| 1798 | const Type *ArgTy = (*i)->getType(); |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1799 | MVT ArgVT; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1800 | if (!isTypeLegal(ArgTy, ArgVT)) |
| 1801 | return false; |
| 1802 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 1803 | Flags.setOrigAlign(OriginalAlignment); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1804 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1805 | Args.push_back(*i); |
| 1806 | ArgRegs.push_back(Arg); |
| 1807 | ArgVTs.push_back(ArgVT); |
| 1808 | ArgFlags.push_back(Flags); |
| 1809 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1810 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1811 | // Handle the arguments now that we've gotten them. |
| 1812 | SmallVector<unsigned, 4> RegArgs; |
| 1813 | unsigned NumBytes; |
| 1814 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes)) |
| 1815 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1816 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1817 | // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1818 | // TODO: Turn this into the table of arm call ops. |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1819 | MachineInstrBuilder MIB; |
| 1820 | unsigned CallOpc; |
Eric Christopher | 7bb5996 | 2010-11-29 21:56:23 +0000 | [diff] [blame] | 1821 | // Explicitly adding the predicate here. |
Eric Christopher | c19aadb | 2010-12-21 03:50:43 +0000 | [diff] [blame] | 1822 | if(isThumb) { |
| 1823 | CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi; |
| 1824 | // Explicitly adding the predicate here. |
| 1825 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1826 | TII.get(CallOpc))) |
| 1827 | .addGlobalAddress(GV, 0, 0); |
| 1828 | } else { |
| 1829 | CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL; |
| 1830 | // Explicitly adding the predicate here. |
| 1831 | MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1832 | TII.get(CallOpc)) |
| 1833 | .addGlobalAddress(GV, 0, 0)); |
| 1834 | } |
| 1835 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1836 | // Add implicit physical register uses to the call. |
| 1837 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 1838 | MIB.addReg(RegArgs[i]); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1839 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1840 | // Finish off the call including any return values. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1841 | SmallVector<unsigned, 4> UsedRegs; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1842 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1843 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1844 | // Set all unused physreg defs as dead. |
| 1845 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1846 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1847 | return true; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1848 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1851 | // TODO: SoftFP support. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1852 | bool ARMFastISel::TargetSelectInstruction(const Instruction *I) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1853 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1854 | switch (I->getOpcode()) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 1855 | case Instruction::Load: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1856 | return SelectLoad(I); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 1857 | case Instruction::Store: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1858 | return SelectStore(I); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1859 | case Instruction::Br: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1860 | return SelectBranch(I); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1861 | case Instruction::ICmp: |
| 1862 | case Instruction::FCmp: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1863 | return SelectCmp(I); |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1864 | case Instruction::FPExt: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1865 | return SelectFPExt(I); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1866 | case Instruction::FPTrunc: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1867 | return SelectFPTrunc(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1868 | case Instruction::SIToFP: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1869 | return SelectSIToFP(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1870 | case Instruction::FPToSI: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1871 | return SelectFPToSI(I); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1872 | case Instruction::FAdd: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1873 | return SelectBinaryOp(I, ISD::FADD); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1874 | case Instruction::FSub: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1875 | return SelectBinaryOp(I, ISD::FSUB); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1876 | case Instruction::FMul: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1877 | return SelectBinaryOp(I, ISD::FMUL); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1878 | case Instruction::SDiv: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1879 | return SelectSDiv(I); |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1880 | case Instruction::SRem: |
| 1881 | return SelectSRem(I); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1882 | case Instruction::Call: |
| 1883 | return SelectCall(I); |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1884 | case Instruction::Select: |
| 1885 | return SelectSelect(I); |
Eric Christopher | 4f512ef | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 1886 | case Instruction::Ret: |
| 1887 | return SelectRet(I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1888 | default: break; |
| 1889 | } |
| 1890 | return false; |
| 1891 | } |
| 1892 | |
| 1893 | namespace llvm { |
| 1894 | llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) { |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 1895 | // Completely untested on non-darwin. |
| 1896 | const TargetMachine &TM = funcInfo.MF->getTarget(); |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1897 | |
Eric Christopher | aaa8df4 | 2010-11-02 01:21:28 +0000 | [diff] [blame] | 1898 | // Darwin and thumb1 only for now. |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 1899 | const ARMSubtarget *Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Jim Grosbach | 16cb376 | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1900 | if (Subtarget->isTargetDarwin() && !Subtarget->isThumb1Only() && |
Eric Christopher | aaa8df4 | 2010-11-02 01:21:28 +0000 | [diff] [blame] | 1901 | !DisableARMFastISel) |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 1902 | return new ARMFastISel(funcInfo); |
Evan Cheng | 0944795 | 2010-07-26 18:32:55 +0000 | [diff] [blame] | 1903 | return 0; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1904 | } |
| 1905 | } |