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