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" |
| 36 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 37 | #include "llvm/Support/CallSite.h" |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 38 | #include "llvm/Support/CommandLine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 39 | #include "llvm/Support/ErrorHandling.h" |
| 40 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 41 | #include "llvm/Target/TargetData.h" |
| 42 | #include "llvm/Target/TargetInstrInfo.h" |
| 43 | #include "llvm/Target/TargetLowering.h" |
| 44 | #include "llvm/Target/TargetMachine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetOptions.h" |
| 46 | using namespace llvm; |
| 47 | |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 48 | static cl::opt<bool> |
Eric Christopher | 8ff9a9d | 2010-10-11 20:26:21 +0000 | [diff] [blame] | 49 | EnableARMFastISel("arm-fast-isel", |
| 50 | cl::desc("Turn on experimental ARM fast-isel support"), |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 51 | cl::init(false), cl::Hidden); |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 52 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 53 | namespace { |
| 54 | |
| 55 | class ARMFastISel : public FastISel { |
| 56 | |
| 57 | /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can |
| 58 | /// make the right decision when generating code for different targets. |
| 59 | const ARMSubtarget *Subtarget; |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 60 | const TargetMachine &TM; |
| 61 | const TargetInstrInfo &TII; |
| 62 | const TargetLowering &TLI; |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 63 | ARMFunctionInfo *AFI; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 64 | |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 65 | // Convenience variables to avoid some queries. |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 66 | bool isThumb; |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 67 | LLVMContext *Context; |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 68 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 69 | public: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 70 | explicit ARMFastISel(FunctionLoweringInfo &funcInfo) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 71 | : FastISel(funcInfo), |
| 72 | TM(funcInfo.MF->getTarget()), |
| 73 | TII(*TM.getInstrInfo()), |
| 74 | TLI(*TM.getTargetLowering()) { |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 75 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 76 | AFI = funcInfo.MF->getInfo<ARMFunctionInfo>(); |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 77 | isThumb = AFI->isThumbFunction(); |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 78 | Context = &funcInfo.Fn->getContext(); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 81 | // Code from FastISel.cpp. |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 82 | virtual unsigned FastEmitInst_(unsigned MachineInstOpcode, |
| 83 | const TargetRegisterClass *RC); |
| 84 | virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode, |
| 85 | const TargetRegisterClass *RC, |
| 86 | unsigned Op0, bool Op0IsKill); |
| 87 | virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode, |
| 88 | const TargetRegisterClass *RC, |
| 89 | unsigned Op0, bool Op0IsKill, |
| 90 | unsigned Op1, bool Op1IsKill); |
| 91 | virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode, |
| 92 | const TargetRegisterClass *RC, |
| 93 | unsigned Op0, bool Op0IsKill, |
| 94 | uint64_t Imm); |
| 95 | virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode, |
| 96 | const TargetRegisterClass *RC, |
| 97 | unsigned Op0, bool Op0IsKill, |
| 98 | const ConstantFP *FPImm); |
| 99 | virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode, |
| 100 | const TargetRegisterClass *RC, |
| 101 | uint64_t Imm); |
| 102 | virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode, |
| 103 | const TargetRegisterClass *RC, |
| 104 | unsigned Op0, bool Op0IsKill, |
| 105 | unsigned Op1, bool Op1IsKill, |
| 106 | uint64_t Imm); |
| 107 | virtual unsigned FastEmitInst_extractsubreg(MVT RetVT, |
| 108 | unsigned Op0, bool Op0IsKill, |
| 109 | uint32_t Idx); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 110 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 111 | // Backend specific FastISel code. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 112 | virtual bool TargetSelectInstruction(const Instruction *I); |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 113 | virtual unsigned TargetMaterializeConstant(const Constant *C); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 114 | virtual unsigned TargetMaterializeAlloca(const AllocaInst *AI); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 115 | |
| 116 | #include "ARMGenFastISel.inc" |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 117 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 118 | // Instruction selection routines. |
Eric Christopher | 44bff90 | 2010-09-10 23:10:30 +0000 | [diff] [blame] | 119 | private: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 120 | virtual bool SelectLoad(const Instruction *I); |
| 121 | virtual bool SelectStore(const Instruction *I); |
| 122 | virtual bool SelectBranch(const Instruction *I); |
| 123 | virtual bool SelectCmp(const Instruction *I); |
| 124 | virtual bool SelectFPExt(const Instruction *I); |
| 125 | virtual bool SelectFPTrunc(const Instruction *I); |
| 126 | virtual bool SelectBinaryOp(const Instruction *I, unsigned ISDOpcode); |
| 127 | virtual bool SelectSIToFP(const Instruction *I); |
| 128 | virtual bool SelectFPToSI(const Instruction *I); |
| 129 | virtual bool SelectSDiv(const Instruction *I); |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 130 | virtual bool SelectSRem(const Instruction *I); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 131 | virtual bool SelectCall(const Instruction *I); |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 132 | virtual bool SelectSelect(const Instruction *I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 133 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 134 | // Utility routines. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 135 | private: |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 136 | bool isTypeLegal(const Type *Ty, EVT &VT); |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 137 | bool isLoadTypeLegal(const Type *Ty, EVT &VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 138 | bool ARMEmitLoad(EVT VT, unsigned &ResultReg, unsigned Reg, int Offset); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 139 | bool ARMEmitStore(EVT VT, unsigned SrcReg, unsigned Reg, int Offset); |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 140 | bool ARMLoadAlloca(const Instruction *I, EVT VT); |
| 141 | bool ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT); |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 142 | bool ARMComputeRegOffset(const Value *Obj, unsigned &Reg, int &Offset); |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 143 | unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT); |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 144 | unsigned ARMMaterializeInt(const Constant *C, EVT VT); |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 145 | unsigned ARMMaterializeGV(const GlobalValue *GV, EVT VT); |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 146 | unsigned ARMMoveToFPReg(EVT VT, unsigned SrcReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 147 | unsigned ARMMoveToIntReg(EVT VT, unsigned SrcReg); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 148 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 149 | // Call handling routines. |
| 150 | private: |
| 151 | CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool Return); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 152 | bool ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 153 | SmallVectorImpl<unsigned> &ArgRegs, |
| 154 | SmallVectorImpl<EVT> &ArgVTs, |
| 155 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 156 | SmallVectorImpl<unsigned> &RegArgs, |
| 157 | CallingConv::ID CC, |
| 158 | unsigned &NumBytes); |
| 159 | bool FinishCall(EVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
| 160 | const Instruction *I, CallingConv::ID CC, |
| 161 | unsigned &NumBytes); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 162 | bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call); |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 163 | |
| 164 | // OptionalDef handling routines. |
| 165 | private: |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 166 | bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR); |
| 167 | const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB); |
| 168 | }; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 169 | |
| 170 | } // end anonymous namespace |
| 171 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 172 | #include "ARMGenCallingConv.inc" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 173 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 174 | // DefinesOptionalPredicate - This is different from DefinesPredicate in that |
| 175 | // we don't care about implicit defs here, just places we'll need to add a |
| 176 | // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR. |
| 177 | bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) { |
| 178 | const TargetInstrDesc &TID = MI->getDesc(); |
| 179 | if (!TID.hasOptionalDef()) |
| 180 | return false; |
| 181 | |
| 182 | // Look to see if our OptionalDef is defining CPSR or CCR. |
| 183 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 184 | const MachineOperand &MO = MI->getOperand(i); |
Eric Christopher | f762fbe | 2010-08-20 00:36:24 +0000 | [diff] [blame] | 185 | if (!MO.isReg() || !MO.isDef()) continue; |
| 186 | if (MO.getReg() == ARM::CPSR) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 187 | *CPSR = true; |
| 188 | } |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | // If the machine is predicable go ahead and add the predicate operands, if |
| 193 | // it needs default CC operands add those. |
| 194 | const MachineInstrBuilder & |
| 195 | ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) { |
| 196 | MachineInstr *MI = &*MIB; |
| 197 | |
| 198 | // Do we use a predicate? |
| 199 | if (TII.isPredicable(MI)) |
| 200 | AddDefaultPred(MIB); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 201 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 202 | // Do we optionally set a predicate? Preds is size > 0 iff the predicate |
| 203 | // defines CPSR. All other OptionalDefines in ARM are the CCR register. |
Eric Christopher | 979e0a1 | 2010-08-19 15:35:27 +0000 | [diff] [blame] | 204 | bool CPSR = false; |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 205 | if (DefinesOptionalPredicate(MI, &CPSR)) { |
| 206 | if (CPSR) |
| 207 | AddDefaultT1CC(MIB); |
| 208 | else |
| 209 | AddDefaultCC(MIB); |
| 210 | } |
| 211 | return MIB; |
| 212 | } |
| 213 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 214 | unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode, |
| 215 | const TargetRegisterClass* RC) { |
| 216 | unsigned ResultReg = createResultReg(RC); |
| 217 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 218 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 219 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 220 | return ResultReg; |
| 221 | } |
| 222 | |
| 223 | unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode, |
| 224 | const TargetRegisterClass *RC, |
| 225 | unsigned Op0, bool Op0IsKill) { |
| 226 | unsigned ResultReg = createResultReg(RC); |
| 227 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 228 | |
| 229 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 230 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 231 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
| 232 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 233 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 234 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 235 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 236 | TII.get(TargetOpcode::COPY), ResultReg) |
| 237 | .addReg(II.ImplicitDefs[0])); |
| 238 | } |
| 239 | return ResultReg; |
| 240 | } |
| 241 | |
| 242 | unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode, |
| 243 | const TargetRegisterClass *RC, |
| 244 | unsigned Op0, bool Op0IsKill, |
| 245 | unsigned Op1, bool Op1IsKill) { |
| 246 | unsigned ResultReg = createResultReg(RC); |
| 247 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 248 | |
| 249 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 250 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 251 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 252 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
| 253 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 254 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 255 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 256 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 257 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 258 | TII.get(TargetOpcode::COPY), ResultReg) |
| 259 | .addReg(II.ImplicitDefs[0])); |
| 260 | } |
| 261 | return ResultReg; |
| 262 | } |
| 263 | |
| 264 | unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode, |
| 265 | const TargetRegisterClass *RC, |
| 266 | unsigned Op0, bool Op0IsKill, |
| 267 | uint64_t Imm) { |
| 268 | unsigned ResultReg = createResultReg(RC); |
| 269 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 270 | |
| 271 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 272 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 273 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 274 | .addImm(Imm)); |
| 275 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 276 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 277 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 278 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 279 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 280 | TII.get(TargetOpcode::COPY), ResultReg) |
| 281 | .addReg(II.ImplicitDefs[0])); |
| 282 | } |
| 283 | return ResultReg; |
| 284 | } |
| 285 | |
| 286 | unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode, |
| 287 | const TargetRegisterClass *RC, |
| 288 | unsigned Op0, bool Op0IsKill, |
| 289 | const ConstantFP *FPImm) { |
| 290 | unsigned ResultReg = createResultReg(RC); |
| 291 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 292 | |
| 293 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 294 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 295 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 296 | .addFPImm(FPImm)); |
| 297 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 298 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 299 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 300 | .addFPImm(FPImm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 301 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 302 | TII.get(TargetOpcode::COPY), ResultReg) |
| 303 | .addReg(II.ImplicitDefs[0])); |
| 304 | } |
| 305 | return ResultReg; |
| 306 | } |
| 307 | |
| 308 | unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode, |
| 309 | const TargetRegisterClass *RC, |
| 310 | unsigned Op0, bool Op0IsKill, |
| 311 | unsigned Op1, bool Op1IsKill, |
| 312 | uint64_t Imm) { |
| 313 | unsigned ResultReg = createResultReg(RC); |
| 314 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 315 | |
| 316 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 317 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 318 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 319 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 320 | .addImm(Imm)); |
| 321 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 322 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 323 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 324 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 325 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 326 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 327 | TII.get(TargetOpcode::COPY), ResultReg) |
| 328 | .addReg(II.ImplicitDefs[0])); |
| 329 | } |
| 330 | return ResultReg; |
| 331 | } |
| 332 | |
| 333 | unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode, |
| 334 | const TargetRegisterClass *RC, |
| 335 | uint64_t Imm) { |
| 336 | unsigned ResultReg = createResultReg(RC); |
| 337 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 338 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 339 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 340 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 341 | .addImm(Imm)); |
| 342 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 343 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 344 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 345 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 346 | TII.get(TargetOpcode::COPY), ResultReg) |
| 347 | .addReg(II.ImplicitDefs[0])); |
| 348 | } |
| 349 | return ResultReg; |
| 350 | } |
| 351 | |
| 352 | unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT, |
| 353 | unsigned Op0, bool Op0IsKill, |
| 354 | uint32_t Idx) { |
| 355 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT)); |
| 356 | assert(TargetRegisterInfo::isVirtualRegister(Op0) && |
| 357 | "Cannot yet extract from physregs"); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 358 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 359 | DL, TII.get(TargetOpcode::COPY), ResultReg) |
| 360 | .addReg(Op0, getKillRegState(Op0IsKill), Idx)); |
| 361 | return ResultReg; |
| 362 | } |
| 363 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 364 | // TODO: Don't worry about 64-bit now, but when this is fixed remove the |
| 365 | // checks from the various callers. |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 366 | unsigned ARMFastISel::ARMMoveToFPReg(EVT VT, unsigned SrcReg) { |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 367 | if (VT.getSimpleVT().SimpleTy == MVT::f64) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 368 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 369 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 370 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 371 | TII.get(ARM::VMOVRS), MoveReg) |
| 372 | .addReg(SrcReg)); |
| 373 | return MoveReg; |
| 374 | } |
| 375 | |
| 376 | unsigned ARMFastISel::ARMMoveToIntReg(EVT VT, unsigned SrcReg) { |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 377 | if (VT.getSimpleVT().SimpleTy == MVT::i64) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 378 | |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 379 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 380 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 381 | TII.get(ARM::VMOVSR), MoveReg) |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 382 | .addReg(SrcReg)); |
| 383 | return MoveReg; |
| 384 | } |
| 385 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 386 | // For double width floating point we need to materialize two constants |
| 387 | // (the high and the low) into integer registers then use a move to get |
| 388 | // the combined constant into an FP reg. |
| 389 | unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, EVT VT) { |
| 390 | const APFloat Val = CFP->getValueAPF(); |
| 391 | bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 392 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 393 | // This checks to see if we can use VFP3 instructions to materialize |
| 394 | // a constant, otherwise we have to go through the constant pool. |
| 395 | if (TLI.isFPImmLegal(Val, VT)) { |
| 396 | unsigned Opc = is64bit ? ARM::FCONSTD : ARM::FCONSTS; |
| 397 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 398 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 399 | DestReg) |
| 400 | .addFPImm(CFP)); |
| 401 | return DestReg; |
| 402 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 403 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 404 | // Require VFP2 for loading fp constants. |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 405 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 406 | |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 407 | // MachineConstantPool wants an explicit alignment. |
| 408 | unsigned Align = TD.getPrefTypeAlignment(CFP->getType()); |
| 409 | if (Align == 0) { |
| 410 | // TODO: Figure out if this is correct. |
| 411 | Align = TD.getTypeAllocSize(CFP->getType()); |
| 412 | } |
| 413 | unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align); |
| 414 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 415 | unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 416 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 417 | // The extra reg is for addrmode5. |
Eric Christopher | f5732c4 | 2010-09-28 00:35:09 +0000 | [diff] [blame] | 418 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 419 | DestReg) |
| 420 | .addConstantPoolIndex(Idx) |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 421 | .addReg(0)); |
| 422 | return DestReg; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 425 | unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, EVT VT) { |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 426 | |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 427 | // For now 32-bit only. |
| 428 | if (VT.getSimpleVT().SimpleTy != MVT::i32) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 429 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 430 | // MachineConstantPool wants an explicit alignment. |
| 431 | unsigned Align = TD.getPrefTypeAlignment(C->getType()); |
| 432 | if (Align == 0) { |
| 433 | // TODO: Figure out if this is correct. |
| 434 | Align = TD.getTypeAllocSize(C->getType()); |
| 435 | } |
| 436 | unsigned Idx = MCP.getConstantPoolIndex(C, Align); |
Eric Christopher | 744c7c8 | 2010-09-28 22:47:54 +0000 | [diff] [blame] | 437 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 438 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 439 | if (isThumb) |
| 440 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | fd60980 | 2010-09-28 21:55:34 +0000 | [diff] [blame] | 441 | TII.get(ARM::t2LDRpci), DestReg) |
| 442 | .addConstantPoolIndex(Idx)); |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 443 | else |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 444 | // The extra reg and immediate are for addrmode2. |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 445 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | fd60980 | 2010-09-28 21:55:34 +0000 | [diff] [blame] | 446 | TII.get(ARM::LDRcp), DestReg) |
| 447 | .addConstantPoolIndex(Idx) |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 448 | .addReg(0).addImm(0)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 449 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 450 | return DestReg; |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 453 | unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, EVT VT) { |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 454 | // For now 32-bit only. |
| 455 | if (VT.getSimpleVT().SimpleTy != MVT::i32) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 456 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 457 | Reloc::Model RelocM = TM.getRelocationModel(); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 458 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 459 | // TODO: No external globals for now. |
| 460 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 461 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 462 | // TODO: Need more magic for ARM PIC. |
| 463 | if (!isThumb && (RelocM == Reloc::PIC_)) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 464 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 465 | // MachineConstantPool wants an explicit alignment. |
| 466 | unsigned Align = TD.getPrefTypeAlignment(GV->getType()); |
| 467 | if (Align == 0) { |
| 468 | // TODO: Figure out if this is correct. |
| 469 | Align = TD.getTypeAllocSize(GV->getType()); |
| 470 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 471 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 472 | // Grab index. |
| 473 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb() ? 4 : 8); |
| 474 | unsigned Id = AFI->createConstPoolEntryUId(); |
| 475 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, Id, |
| 476 | ARMCP::CPValue, PCAdj); |
| 477 | unsigned Idx = MCP.getConstantPoolIndex(CPV, Align); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 478 | |
Eric Christopher | 890dbbe | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 479 | // Load value. |
| 480 | MachineInstrBuilder MIB; |
| 481 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 482 | if (isThumb) { |
| 483 | unsigned Opc = (RelocM != Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic; |
| 484 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg) |
| 485 | .addConstantPoolIndex(Idx); |
| 486 | if (RelocM == Reloc::PIC_) |
| 487 | MIB.addImm(Id); |
| 488 | } else { |
| 489 | // The extra reg and immediate are for addrmode2. |
| 490 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRcp), |
| 491 | DestReg) |
| 492 | .addConstantPoolIndex(Idx) |
| 493 | .addReg(0).addImm(0); |
| 494 | } |
| 495 | AddOptionalDefs(MIB); |
| 496 | return DestReg; |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 499 | unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) { |
| 500 | EVT VT = TLI.getValueType(C->getType(), true); |
| 501 | |
| 502 | // Only handle simple types. |
| 503 | if (!VT.isSimple()) return 0; |
| 504 | |
| 505 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) |
| 506 | return ARMMaterializeFP(CFP, VT); |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 507 | else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 508 | return ARMMaterializeGV(GV, VT); |
| 509 | else if (isa<ConstantInt>(C)) |
| 510 | return ARMMaterializeInt(C, VT); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 511 | |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 512 | return 0; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 515 | unsigned ARMFastISel::TargetMaterializeAlloca(const AllocaInst *AI) { |
| 516 | // Don't handle dynamic allocas. |
| 517 | if (!FuncInfo.StaticAllocaMap.count(AI)) return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 518 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 519 | EVT VT; |
| 520 | if (!isTypeLegal(AI->getType(), VT)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 521 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 522 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 523 | FuncInfo.StaticAllocaMap.find(AI); |
| 524 | |
| 525 | // This will get lowered later into the correct offsets and registers |
| 526 | // via rewriteXFrameIndex. |
| 527 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
| 528 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
| 529 | unsigned ResultReg = createResultReg(RC); |
| 530 | unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri; |
| 531 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL, |
| 532 | TII.get(Opc), ResultReg) |
| 533 | .addFrameIndex(SI->second) |
| 534 | .addImm(0)); |
| 535 | return ResultReg; |
| 536 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 537 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 538 | return 0; |
| 539 | } |
| 540 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 541 | bool ARMFastISel::isTypeLegal(const Type *Ty, EVT &VT) { |
| 542 | VT = TLI.getValueType(Ty, true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 543 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 544 | // Only handle simple types. |
| 545 | if (VT == MVT::Other || !VT.isSimple()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 546 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 547 | // Handle all legal types, i.e. a register that will directly hold this |
| 548 | // value. |
| 549 | return TLI.isTypeLegal(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 552 | bool ARMFastISel::isLoadTypeLegal(const Type *Ty, EVT &VT) { |
| 553 | if (isTypeLegal(Ty, VT)) return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 554 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 555 | // If this is a type than can be sign or zero-extended to a basic operation |
| 556 | // go ahead and accept it now. |
| 557 | if (VT == MVT::i8 || VT == MVT::i16) |
| 558 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 559 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 560 | return false; |
| 561 | } |
| 562 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 563 | // Computes the Reg+Offset to get to an object. |
| 564 | bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg, |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 565 | int &Offset) { |
| 566 | // Some boilerplate from the X86 FastISel. |
| 567 | const User *U = NULL; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 568 | unsigned Opcode = Instruction::UserOp1; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 569 | if (const Instruction *I = dyn_cast<Instruction>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 570 | // Don't walk into other basic blocks; it's possible we haven't |
| 571 | // visited them yet, so the instructions may not yet be assigned |
| 572 | // virtual registers. |
| 573 | if (FuncInfo.MBBMap[I->getParent()] != FuncInfo.MBB) |
| 574 | return false; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 575 | Opcode = I->getOpcode(); |
| 576 | U = I; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 577 | } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 578 | Opcode = C->getOpcode(); |
| 579 | U = C; |
| 580 | } |
| 581 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 582 | if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType())) |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 583 | if (Ty->getAddressSpace() > 255) |
| 584 | // Fast instruction selection doesn't support the special |
| 585 | // address spaces. |
| 586 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 587 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 588 | switch (Opcode) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 589 | default: |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 590 | break; |
| 591 | case Instruction::Alloca: { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 592 | assert(false && "Alloca should have been handled earlier!"); |
| 593 | return false; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 594 | } |
| 595 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 596 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 597 | // FIXME: Handle global variables. |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 598 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 599 | (void)GV; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 600 | return false; |
| 601 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 602 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 603 | // Try to get this in a register if nothing else has worked. |
| 604 | Reg = getRegForValue(Obj); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 605 | if (Reg == 0) return false; |
| 606 | |
| 607 | // Since the offset may be too large for the load instruction |
| 608 | // get the reg+offset into a register. |
| 609 | // TODO: Verify the additions work, otherwise we'll need to add the |
| 610 | // offset instead of 0 to the instructions and do all sorts of operand |
| 611 | // munging. |
| 612 | // TODO: Optimize this somewhat. |
| 613 | if (Offset != 0) { |
| 614 | ARMCC::CondCodes Pred = ARMCC::AL; |
| 615 | unsigned PredReg = 0; |
| 616 | |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 617 | if (!isThumb) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 618 | emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 619 | Reg, Reg, Offset, Pred, PredReg, |
| 620 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 621 | else { |
| 622 | assert(AFI->isThumb2Function()); |
| 623 | emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 624 | Reg, Reg, Offset, Pred, PredReg, |
| 625 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 626 | } |
| 627 | } |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 628 | return true; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 629 | } |
| 630 | |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 631 | bool ARMFastISel::ARMLoadAlloca(const Instruction *I, EVT VT) { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 632 | Value *Op0 = I->getOperand(0); |
| 633 | |
Eric Christopher | df1f5a9 | 2010-10-07 21:40:18 +0000 | [diff] [blame] | 634 | // Promote load/store types. |
| 635 | if (VT == MVT::i8 || VT == MVT::i16) VT = MVT::i32; |
| 636 | |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 637 | // Verify it's an alloca. |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 638 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op0)) { |
| 639 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 640 | FuncInfo.StaticAllocaMap.find(AI); |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 641 | |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 642 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 643 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 644 | unsigned ResultReg = createResultReg(RC); |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 645 | TII.loadRegFromStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt, |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 646 | ResultReg, SI->second, RC, |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 647 | TM.getRegisterInfo()); |
| 648 | UpdateValueMap(I, ResultReg); |
| 649 | return true; |
| 650 | } |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 651 | } |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 652 | return false; |
| 653 | } |
| 654 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 655 | bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg, |
| 656 | unsigned Reg, int Offset) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 657 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 658 | assert(VT.isSimple() && "Non-simple types are invalid here!"); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 659 | unsigned Opc; |
Eric Christopher | ee56ea6 | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 660 | TargetRegisterClass *RC; |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 661 | bool isFloat = false; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 662 | switch (VT.getSimpleVT().SimpleTy) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 663 | default: |
Eric Christopher | 98de5b4 | 2010-09-29 00:49:09 +0000 | [diff] [blame] | 664 | // This is mostly going to be Neon/vector support. |
Eric Christopher | 548d1bb | 2010-08-30 23:48:26 +0000 | [diff] [blame] | 665 | return false; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 666 | case MVT::i16: |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 667 | Opc = isThumb ? ARM::t2LDRHi8 : ARM::LDRH; |
| 668 | RC = ARM::GPRRegisterClass; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 669 | VT = MVT::i32; |
| 670 | break; |
| 671 | case MVT::i8: |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 672 | Opc = isThumb ? ARM::t2LDRBi8 : ARM::LDRB; |
| 673 | RC = ARM::GPRRegisterClass; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 674 | VT = MVT::i32; |
| 675 | break; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 676 | case MVT::i32: |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 677 | Opc = isThumb ? ARM::t2LDRi8 : ARM::LDR; |
| 678 | RC = ARM::GPRRegisterClass; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 679 | break; |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 680 | case MVT::f32: |
| 681 | Opc = ARM::VLDRS; |
Eric Christopher | ee56ea6 | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 682 | RC = TLI.getRegClassFor(VT); |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 683 | isFloat = true; |
| 684 | break; |
| 685 | case MVT::f64: |
| 686 | Opc = ARM::VLDRD; |
Eric Christopher | ee56ea6 | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 687 | RC = TLI.getRegClassFor(VT); |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 688 | isFloat = true; |
| 689 | break; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 690 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 691 | |
Eric Christopher | ee56ea6 | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 692 | ResultReg = createResultReg(RC); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 693 | |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 694 | // For now with the additions above the offset should be zero - thus we |
| 695 | // can always fit into an i8. |
| 696 | assert(Offset == 0 && "Offset not zero!"); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 697 | |
Eric Christopher | 7a56f33 | 2010-10-08 01:13:17 +0000 | [diff] [blame] | 698 | // The thumb and floating point instructions both take 2 operands, ARM takes |
| 699 | // another register. |
| 700 | if (isFloat || isThumb) |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 701 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 702 | TII.get(Opc), ResultReg) |
| 703 | .addReg(Reg).addImm(Offset)); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 704 | else |
| 705 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 706 | TII.get(Opc), ResultReg) |
| 707 | .addReg(Reg).addReg(0).addImm(Offset)); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 708 | return true; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 711 | bool ARMFastISel::SelectLoad(const Instruction *I) { |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 712 | // Verify we have a legal type before going any further. |
| 713 | EVT VT; |
| 714 | if (!isLoadTypeLegal(I->getType(), VT)) |
| 715 | return false; |
| 716 | |
| 717 | // If we're an alloca we know we have a frame index and can emit the load |
| 718 | // directly in short order. |
| 719 | if (ARMLoadAlloca(I, VT)) |
| 720 | return true; |
| 721 | |
| 722 | // Our register and offset with innocuous defaults. |
| 723 | unsigned Reg = 0; |
| 724 | int Offset = 0; |
| 725 | |
| 726 | // See if we can handle this as Reg + Offset |
| 727 | if (!ARMComputeRegOffset(I->getOperand(0), Reg, Offset)) |
| 728 | return false; |
| 729 | |
| 730 | unsigned ResultReg; |
| 731 | if (!ARMEmitLoad(VT, ResultReg, Reg, Offset /* 0 */)) return false; |
| 732 | |
| 733 | UpdateValueMap(I, ResultReg); |
| 734 | return true; |
| 735 | } |
| 736 | |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 737 | bool ARMFastISel::ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT){ |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 738 | Value *Op1 = I->getOperand(1); |
| 739 | |
Eric Christopher | df1f5a9 | 2010-10-07 21:40:18 +0000 | [diff] [blame] | 740 | // Promote load/store types. |
| 741 | if (VT == MVT::i8 || VT == MVT::i16) VT = MVT::i32; |
| 742 | |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 743 | // Verify it's an alloca. |
| 744 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op1)) { |
| 745 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 746 | FuncInfo.StaticAllocaMap.find(AI); |
| 747 | |
| 748 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 749 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 750 | assert(SrcReg != 0 && "Nothing to store!"); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 751 | TII.storeRegToStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt, |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 752 | SrcReg, true /*isKill*/, SI->second, RC, |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 753 | TM.getRegisterInfo()); |
| 754 | return true; |
| 755 | } |
| 756 | } |
| 757 | return false; |
| 758 | } |
| 759 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 760 | bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg, |
| 761 | unsigned DstReg, int Offset) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 762 | unsigned StrOpc; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 763 | bool isFloat = false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 764 | switch (VT.getSimpleVT().SimpleTy) { |
| 765 | default: return false; |
| 766 | case MVT::i1: |
Eric Christopher | e93417b | 2010-10-08 23:52:16 +0000 | [diff] [blame] | 767 | case MVT::i8: StrOpc = isThumb ? ARM::t2STRBi8 : ARM::STRB; break; |
| 768 | case MVT::i16: StrOpc = isThumb ? ARM::t2STRHi8 : ARM::STRH; break; |
| 769 | case MVT::i32: StrOpc = isThumb ? ARM::t2STRi8 : ARM::STR; break; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 770 | case MVT::f32: |
| 771 | if (!Subtarget->hasVFP2()) return false; |
| 772 | StrOpc = ARM::VSTRS; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 773 | isFloat = true; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 774 | break; |
| 775 | case MVT::f64: |
| 776 | if (!Subtarget->hasVFP2()) return false; |
| 777 | StrOpc = ARM::VSTRD; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 778 | isFloat = true; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 779 | break; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 780 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 781 | |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 782 | // The thumb addressing mode has operands swapped from the arm addressing |
| 783 | // mode, the floating point one only has two operands. |
Eric Christopher | e93417b | 2010-10-08 23:52:16 +0000 | [diff] [blame] | 784 | if (isFloat || isThumb) |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 785 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 45547b8 | 2010-10-01 20:46:04 +0000 | [diff] [blame] | 786 | TII.get(StrOpc)) |
| 787 | .addReg(SrcReg).addReg(DstReg).addImm(Offset)); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 788 | else |
| 789 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 45547b8 | 2010-10-01 20:46:04 +0000 | [diff] [blame] | 790 | TII.get(StrOpc)) |
| 791 | .addReg(SrcReg).addReg(DstReg).addReg(0).addImm(Offset)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 792 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 793 | return true; |
| 794 | } |
| 795 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 796 | bool ARMFastISel::SelectStore(const Instruction *I) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 797 | Value *Op0 = I->getOperand(0); |
| 798 | unsigned SrcReg = 0; |
| 799 | |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 800 | // Yay type legalization |
| 801 | EVT VT; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 802 | if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT)) |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 803 | return false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 804 | |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 805 | // Get the value to be stored into a register. |
| 806 | SrcReg = getRegForValue(Op0); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 807 | if (SrcReg == 0) |
| 808 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 809 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 810 | // If we're an alloca we know we have a frame index and can emit the store |
| 811 | // quickly. |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 812 | if (ARMStoreAlloca(I, SrcReg, VT)) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 813 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 814 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 815 | // Our register and offset with innocuous defaults. |
| 816 | unsigned Reg = 0; |
| 817 | int Offset = 0; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 818 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 819 | // See if we can handle this as Reg + Offset |
| 820 | if (!ARMComputeRegOffset(I->getOperand(1), Reg, Offset)) |
| 821 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 822 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 823 | if (!ARMEmitStore(VT, SrcReg, Reg, Offset /* 0 */)) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 824 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 825 | return true; |
| 826 | } |
| 827 | |
| 828 | static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) { |
| 829 | switch (Pred) { |
| 830 | // Needs two compares... |
| 831 | case CmpInst::FCMP_ONE: |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 832 | case CmpInst::FCMP_UEQ: |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 833 | default: |
| 834 | assert(false && "Unhandled CmpInst::Predicate!"); |
| 835 | return ARMCC::AL; |
| 836 | case CmpInst::ICMP_EQ: |
| 837 | case CmpInst::FCMP_OEQ: |
| 838 | return ARMCC::EQ; |
| 839 | case CmpInst::ICMP_SGT: |
| 840 | case CmpInst::FCMP_OGT: |
| 841 | return ARMCC::GT; |
| 842 | case CmpInst::ICMP_SGE: |
| 843 | case CmpInst::FCMP_OGE: |
| 844 | return ARMCC::GE; |
| 845 | case CmpInst::ICMP_UGT: |
| 846 | case CmpInst::FCMP_UGT: |
| 847 | return ARMCC::HI; |
| 848 | case CmpInst::FCMP_OLT: |
| 849 | return ARMCC::MI; |
| 850 | case CmpInst::ICMP_ULE: |
| 851 | case CmpInst::FCMP_OLE: |
| 852 | return ARMCC::LS; |
| 853 | case CmpInst::FCMP_ORD: |
| 854 | return ARMCC::VC; |
| 855 | case CmpInst::FCMP_UNO: |
| 856 | return ARMCC::VS; |
| 857 | case CmpInst::FCMP_UGE: |
| 858 | return ARMCC::PL; |
| 859 | case CmpInst::ICMP_SLT: |
| 860 | case CmpInst::FCMP_ULT: |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 861 | return ARMCC::LT; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 862 | case CmpInst::ICMP_SLE: |
| 863 | case CmpInst::FCMP_ULE: |
| 864 | return ARMCC::LE; |
| 865 | case CmpInst::FCMP_UNE: |
| 866 | case CmpInst::ICMP_NE: |
| 867 | return ARMCC::NE; |
| 868 | case CmpInst::ICMP_UGE: |
| 869 | return ARMCC::HS; |
| 870 | case CmpInst::ICMP_ULT: |
| 871 | return ARMCC::LO; |
| 872 | } |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 875 | bool ARMFastISel::SelectBranch(const Instruction *I) { |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 876 | const BranchInst *BI = cast<BranchInst>(I); |
| 877 | MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)]; |
| 878 | MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)]; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 879 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 880 | // Simple branch support. |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 881 | // TODO: Try to avoid the re-computation in some places. |
| 882 | unsigned CondReg = getRegForValue(BI->getCondition()); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 883 | if (CondReg == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 884 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 885 | // Re-set the flags just in case. |
| 886 | unsigned CmpOpc = isThumb ? ARM::t2CMPri : ARM::CMPri; |
| 887 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 888 | .addReg(CondReg).addImm(1)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 889 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 890 | unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 891 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 892 | .addMBB(TBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 893 | FastEmitBranch(FBB, DL); |
| 894 | FuncInfo.MBB->addSuccessor(TBB); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 895 | return true; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 898 | bool ARMFastISel::SelectCmp(const Instruction *I) { |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 899 | const CmpInst *CI = cast<CmpInst>(I); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 900 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 901 | EVT VT; |
| 902 | const Type *Ty = CI->getOperand(0)->getType(); |
| 903 | if (!isTypeLegal(Ty, VT)) |
| 904 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 905 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 906 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 907 | if (isFloat && !Subtarget->hasVFP2()) |
| 908 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 909 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 910 | unsigned CmpOpc; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 911 | unsigned CondReg; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 912 | switch (VT.getSimpleVT().SimpleTy) { |
| 913 | default: return false; |
| 914 | // TODO: Verify compares. |
| 915 | case MVT::f32: |
| 916 | CmpOpc = ARM::VCMPES; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 917 | CondReg = ARM::FPSCR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 918 | break; |
| 919 | case MVT::f64: |
| 920 | CmpOpc = ARM::VCMPED; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 921 | CondReg = ARM::FPSCR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 922 | break; |
| 923 | case MVT::i32: |
| 924 | CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 925 | CondReg = ARM::CPSR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 926 | break; |
| 927 | } |
| 928 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 929 | // Get the compare predicate. |
| 930 | ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate()); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 931 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 932 | // We may not handle every CC for now. |
| 933 | if (ARMPred == ARMCC::AL) return false; |
| 934 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 935 | unsigned Arg1 = getRegForValue(CI->getOperand(0)); |
| 936 | if (Arg1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 937 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 938 | unsigned Arg2 = getRegForValue(CI->getOperand(1)); |
| 939 | if (Arg2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 940 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 941 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 942 | .addReg(Arg1).addReg(Arg2)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 943 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 944 | // For floating point we need to move the result to a comparison register |
| 945 | // that we can then use for branches. |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 946 | if (isFloat) |
| 947 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 948 | TII.get(ARM::FMSTAT))); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 949 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 950 | // Now set a register based on the comparison. Explicitly set the predicates |
| 951 | // here. |
Eric Christopher | 338c253 | 2010-10-07 05:31:49 +0000 | [diff] [blame] | 952 | unsigned MovCCOpc = isThumb ? ARM::t2MOVCCi : ARM::MOVCCi; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 953 | TargetRegisterClass *RC = isThumb ? ARM::rGPRRegisterClass |
Eric Christopher | 5d18d92 | 2010-10-07 05:39:19 +0000 | [diff] [blame] | 954 | : ARM::GPRRegisterClass; |
| 955 | unsigned DestReg = createResultReg(RC); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 956 | Constant *Zero |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 957 | = ConstantInt::get(Type::getInt32Ty(*Context), 0); |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 958 | unsigned ZeroReg = TargetMaterializeConstant(Zero); |
| 959 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), DestReg) |
| 960 | .addReg(ZeroReg).addImm(1) |
| 961 | .addImm(ARMPred).addReg(CondReg); |
| 962 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 963 | UpdateValueMap(I, DestReg); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 964 | return true; |
| 965 | } |
| 966 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 967 | bool ARMFastISel::SelectFPExt(const Instruction *I) { |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 968 | // Make sure we have VFP and that we're extending float to double. |
| 969 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 970 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 971 | Value *V = I->getOperand(0); |
| 972 | if (!I->getType()->isDoubleTy() || |
| 973 | !V->getType()->isFloatTy()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 974 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 975 | unsigned Op = getRegForValue(V); |
| 976 | if (Op == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 977 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 978 | unsigned Result = createResultReg(ARM::DPRRegisterClass); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 979 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 980 | TII.get(ARM::VCVTDS), Result) |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 981 | .addReg(Op)); |
| 982 | UpdateValueMap(I, Result); |
| 983 | return true; |
| 984 | } |
| 985 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 986 | bool ARMFastISel::SelectFPTrunc(const Instruction *I) { |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 987 | // Make sure we have VFP and that we're truncating double to float. |
| 988 | if (!Subtarget->hasVFP2()) return false; |
| 989 | |
| 990 | Value *V = I->getOperand(0); |
Eric Christopher | 022b7fb | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 991 | if (!(I->getType()->isFloatTy() && |
| 992 | V->getType()->isDoubleTy())) return false; |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 993 | |
| 994 | unsigned Op = getRegForValue(V); |
| 995 | if (Op == 0) return false; |
| 996 | |
| 997 | unsigned Result = createResultReg(ARM::SPRRegisterClass); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 998 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 999 | TII.get(ARM::VCVTSD), Result) |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1000 | .addReg(Op)); |
| 1001 | UpdateValueMap(I, Result); |
| 1002 | return true; |
| 1003 | } |
| 1004 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1005 | bool ARMFastISel::SelectSIToFP(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1006 | // Make sure we have VFP. |
| 1007 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1008 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1009 | EVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1010 | const Type *Ty = I->getType(); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1011 | if (!isTypeLegal(Ty, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1012 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1013 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1014 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 1015 | if (Op == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1016 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1017 | // The conversion routine works on fp-reg to fp-reg and the operand above |
| 1018 | // was an integer, move it to the fp registers if possible. |
Eric Christopher | 022b7fb | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1019 | unsigned FP = ARMMoveToFPReg(MVT::f32, Op); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1020 | if (FP == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1021 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1022 | unsigned Opc; |
| 1023 | if (Ty->isFloatTy()) Opc = ARM::VSITOS; |
| 1024 | else if (Ty->isDoubleTy()) Opc = ARM::VSITOD; |
| 1025 | else return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1026 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1027 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1028 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 1029 | ResultReg) |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1030 | .addReg(FP)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1031 | UpdateValueMap(I, ResultReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1032 | return true; |
| 1033 | } |
| 1034 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1035 | bool ARMFastISel::SelectFPToSI(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1036 | // Make sure we have VFP. |
| 1037 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1038 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1039 | EVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1040 | const Type *RetTy = I->getType(); |
Eric Christopher | 920a208 | 2010-09-10 00:35:09 +0000 | [diff] [blame] | 1041 | if (!isTypeLegal(RetTy, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1042 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1043 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1044 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 1045 | if (Op == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1046 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1047 | unsigned Opc; |
| 1048 | const Type *OpTy = I->getOperand(0)->getType(); |
| 1049 | if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS; |
| 1050 | else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD; |
| 1051 | else return 0; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1052 | |
Eric Christopher | 022b7fb | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1053 | // f64->s32 or f32->s32 both need an intermediate f32 reg. |
| 1054 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1055 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 1056 | ResultReg) |
| 1057 | .addReg(Op)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1058 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1059 | // This result needs to be in an integer register, but the conversion only |
| 1060 | // takes place in fp-regs. |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1061 | unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1062 | if (IntReg == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1063 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1064 | UpdateValueMap(I, IntReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1065 | return true; |
| 1066 | } |
| 1067 | |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1068 | bool ARMFastISel::SelectSelect(const Instruction *I) { |
| 1069 | EVT VT = TLI.getValueType(I->getType(), /*HandleUnknown=*/true); |
| 1070 | if (VT == MVT::Other || !isTypeLegal(I->getType(), VT)) |
| 1071 | return false; |
| 1072 | |
| 1073 | // Things need to be register sized for register moves. |
| 1074 | if (VT.getSimpleVT().SimpleTy != MVT::i32) return false; |
| 1075 | const TargetRegisterClass *RC = TLI.getRegClassFor(VT); |
| 1076 | |
| 1077 | unsigned CondReg = getRegForValue(I->getOperand(0)); |
| 1078 | if (CondReg == 0) return false; |
| 1079 | unsigned Op1Reg = getRegForValue(I->getOperand(1)); |
| 1080 | if (Op1Reg == 0) return false; |
| 1081 | unsigned Op2Reg = getRegForValue(I->getOperand(2)); |
| 1082 | if (Op2Reg == 0) return false; |
| 1083 | |
| 1084 | unsigned CmpOpc = isThumb ? ARM::t2TSTri : ARM::TSTri; |
| 1085 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 1086 | .addReg(CondReg).addImm(1)); |
| 1087 | unsigned ResultReg = createResultReg(RC); |
| 1088 | unsigned MovCCOpc = isThumb ? ARM::t2MOVCCr : ARM::MOVCCr; |
| 1089 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), ResultReg) |
| 1090 | .addReg(Op1Reg).addReg(Op2Reg) |
| 1091 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 1092 | UpdateValueMap(I, ResultReg); |
| 1093 | return true; |
| 1094 | } |
| 1095 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1096 | bool ARMFastISel::SelectSDiv(const Instruction *I) { |
| 1097 | EVT VT; |
| 1098 | const Type *Ty = I->getType(); |
| 1099 | if (!isTypeLegal(Ty, VT)) |
| 1100 | return false; |
| 1101 | |
| 1102 | // If we have integer div support we should have selected this automagically. |
| 1103 | // In case we have a real miss go ahead and return false and we'll pick |
| 1104 | // it up later. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1105 | if (Subtarget->hasDivide()) return false; |
| 1106 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1107 | // Otherwise emit a libcall. |
| 1108 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Eric Christopher | 7bdc4de | 2010-10-11 08:31:54 +0000 | [diff] [blame] | 1109 | if (VT == MVT::i8) |
| 1110 | LC = RTLIB::SDIV_I8; |
| 1111 | else if (VT == MVT::i16) |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1112 | LC = RTLIB::SDIV_I16; |
| 1113 | else if (VT == MVT::i32) |
| 1114 | LC = RTLIB::SDIV_I32; |
| 1115 | else if (VT == MVT::i64) |
| 1116 | LC = RTLIB::SDIV_I64; |
| 1117 | else if (VT == MVT::i128) |
| 1118 | LC = RTLIB::SDIV_I128; |
| 1119 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!"); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1120 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1121 | return ARMEmitLibcall(I, LC); |
| 1122 | } |
| 1123 | |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1124 | bool ARMFastISel::SelectSRem(const Instruction *I) { |
| 1125 | EVT VT; |
| 1126 | const Type *Ty = I->getType(); |
| 1127 | if (!isTypeLegal(Ty, VT)) |
| 1128 | return false; |
| 1129 | |
| 1130 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 1131 | if (VT == MVT::i8) |
| 1132 | LC = RTLIB::SREM_I8; |
| 1133 | else if (VT == MVT::i16) |
| 1134 | LC = RTLIB::SREM_I16; |
| 1135 | else if (VT == MVT::i32) |
| 1136 | LC = RTLIB::SREM_I32; |
| 1137 | else if (VT == MVT::i64) |
| 1138 | LC = RTLIB::SREM_I64; |
| 1139 | else if (VT == MVT::i128) |
| 1140 | LC = RTLIB::SREM_I128; |
Eric Christopher | a1640d9 | 2010-10-11 08:40:05 +0000 | [diff] [blame] | 1141 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!"); |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1142 | |
| 1143 | return ARMEmitLibcall(I, LC); |
| 1144 | } |
| 1145 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1146 | bool ARMFastISel::SelectBinaryOp(const Instruction *I, unsigned ISDOpcode) { |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1147 | EVT VT = TLI.getValueType(I->getType(), true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1148 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1149 | // We can get here in the case when we want to use NEON for our fp |
| 1150 | // operations, but can't figure out how to. Just use the vfp instructions |
| 1151 | // if we have them. |
| 1152 | // FIXME: It'd be nice to use NEON instructions. |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1153 | const Type *Ty = I->getType(); |
| 1154 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 1155 | if (isFloat && !Subtarget->hasVFP2()) |
| 1156 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1157 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1158 | unsigned Op1 = getRegForValue(I->getOperand(0)); |
| 1159 | if (Op1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1160 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1161 | unsigned Op2 = getRegForValue(I->getOperand(1)); |
| 1162 | if (Op2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1163 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1164 | unsigned Opc; |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1165 | bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64 || |
| 1166 | VT.getSimpleVT().SimpleTy == MVT::i64; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1167 | switch (ISDOpcode) { |
| 1168 | default: return false; |
| 1169 | case ISD::FADD: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1170 | Opc = is64bit ? ARM::VADDD : ARM::VADDS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1171 | break; |
| 1172 | case ISD::FSUB: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1173 | Opc = is64bit ? ARM::VSUBD : ARM::VSUBS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1174 | break; |
| 1175 | case ISD::FMUL: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1176 | Opc = is64bit ? ARM::VMULD : ARM::VMULS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1177 | break; |
| 1178 | } |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1179 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1180 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1181 | TII.get(Opc), ResultReg) |
| 1182 | .addReg(Op1).addReg(Op2)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1183 | UpdateValueMap(I, ResultReg); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1184 | return true; |
| 1185 | } |
| 1186 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1187 | // Call Handling Code |
| 1188 | |
| 1189 | // This is largely taken directly from CCAssignFnForNode - we don't support |
| 1190 | // varargs in FastISel so that part has been removed. |
| 1191 | // TODO: We may not support all of this. |
| 1192 | CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) { |
| 1193 | switch (CC) { |
| 1194 | default: |
| 1195 | llvm_unreachable("Unsupported calling convention"); |
| 1196 | case CallingConv::C: |
| 1197 | case CallingConv::Fast: |
| 1198 | // Use target triple & subtarget features to do actual dispatch. |
| 1199 | if (Subtarget->isAAPCS_ABI()) { |
| 1200 | if (Subtarget->hasVFP2() && |
| 1201 | FloatABIType == FloatABI::Hard) |
| 1202 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1203 | else |
| 1204 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1205 | } else |
| 1206 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1207 | case CallingConv::ARM_AAPCS_VFP: |
| 1208 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1209 | case CallingConv::ARM_AAPCS: |
| 1210 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1211 | case CallingConv::ARM_APCS: |
| 1212 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1213 | } |
| 1214 | } |
| 1215 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1216 | bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
| 1217 | SmallVectorImpl<unsigned> &ArgRegs, |
| 1218 | SmallVectorImpl<EVT> &ArgVTs, |
| 1219 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 1220 | SmallVectorImpl<unsigned> &RegArgs, |
| 1221 | CallingConv::ID CC, |
| 1222 | unsigned &NumBytes) { |
| 1223 | SmallVector<CCValAssign, 16> ArgLocs; |
| 1224 | CCState CCInfo(CC, false, TM, ArgLocs, *Context); |
| 1225 | CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC, false)); |
| 1226 | |
| 1227 | // Get a count of how many bytes are to be pushed on the stack. |
| 1228 | NumBytes = CCInfo.getNextStackOffset(); |
| 1229 | |
| 1230 | // Issue CALLSEQ_START |
| 1231 | unsigned AdjStackDown = TM.getRegisterInfo()->getCallFrameSetupOpcode(); |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame^] | 1232 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1233 | TII.get(AdjStackDown)) |
| 1234 | .addImm(NumBytes)); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1235 | |
| 1236 | // Process the args. |
| 1237 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1238 | CCValAssign &VA = ArgLocs[i]; |
| 1239 | unsigned Arg = ArgRegs[VA.getValNo()]; |
| 1240 | EVT ArgVT = ArgVTs[VA.getValNo()]; |
| 1241 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1242 | // Handle arg promotion, etc. |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1243 | switch (VA.getLocInfo()) { |
| 1244 | case CCValAssign::Full: break; |
| 1245 | default: |
Eric Christopher | 1107734 | 2010-10-07 05:14:08 +0000 | [diff] [blame] | 1246 | // TODO: Handle arg promotion. |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1247 | return false; |
| 1248 | } |
| 1249 | |
| 1250 | // Now copy/store arg to correct locations. |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame^] | 1251 | // TODO: We need custom lowering for f64 args. |
| 1252 | if (VA.isRegLoc() && !VA.needsCustom()) { |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1253 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1254 | VA.getLocReg()) |
| 1255 | .addReg(Arg); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1256 | RegArgs.push_back(VA.getLocReg()); |
| 1257 | } else { |
| 1258 | // Need to store |
| 1259 | return false; |
| 1260 | } |
| 1261 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1262 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1263 | return true; |
| 1264 | } |
| 1265 | |
| 1266 | bool ARMFastISel::FinishCall(EVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
| 1267 | const Instruction *I, CallingConv::ID CC, |
| 1268 | unsigned &NumBytes) { |
| 1269 | // Issue CALLSEQ_END |
| 1270 | unsigned AdjStackUp = TM.getRegisterInfo()->getCallFrameDestroyOpcode(); |
Eric Christopher | fb0b892 | 2010-10-11 21:20:02 +0000 | [diff] [blame^] | 1271 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1272 | TII.get(AdjStackUp)) |
| 1273 | .addImm(NumBytes).addImm(0)); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1274 | |
| 1275 | // Now the return value. |
| 1276 | if (RetVT.getSimpleVT().SimpleTy != MVT::isVoid) { |
| 1277 | SmallVector<CCValAssign, 16> RVLocs; |
| 1278 | CCState CCInfo(CC, false, TM, RVLocs, *Context); |
| 1279 | CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true)); |
| 1280 | |
| 1281 | // Copy all of the result registers out of their specified physreg. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1282 | if (RVLocs.size() == 2 && RetVT.getSimpleVT().SimpleTy == MVT::f64) { |
| 1283 | // For this move we copy into two registers and then move into the |
| 1284 | // double fp reg we want. |
| 1285 | // TODO: Are the copies necessary? |
| 1286 | TargetRegisterClass *CopyRC = TLI.getRegClassFor(MVT::i32); |
| 1287 | unsigned Copy1 = createResultReg(CopyRC); |
| 1288 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1289 | Copy1).addReg(RVLocs[0].getLocReg()); |
| 1290 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1291 | |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1292 | unsigned Copy2 = createResultReg(CopyRC); |
| 1293 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1294 | Copy2).addReg(RVLocs[1].getLocReg()); |
| 1295 | UsedRegs.push_back(RVLocs[1].getLocReg()); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1296 | |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1297 | EVT DestVT = RVLocs[0].getValVT(); |
| 1298 | TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT); |
| 1299 | unsigned ResultReg = createResultReg(DstRC); |
| 1300 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1301 | TII.get(ARM::VMOVDRR), ResultReg) |
| 1302 | .addReg(Copy1).addReg(Copy2)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1303 | |
| 1304 | // Finally update the result. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1305 | UpdateValueMap(I, ResultReg); |
| 1306 | } else { |
| 1307 | assert(RVLocs.size() == 1 && "Can't handle non-double multi-reg retvals!"); |
| 1308 | EVT CopyVT = RVLocs[0].getValVT(); |
| 1309 | TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1310 | |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1311 | unsigned ResultReg = createResultReg(DstRC); |
| 1312 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1313 | ResultReg).addReg(RVLocs[0].getLocReg()); |
| 1314 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1315 | |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1316 | // Finally update the result. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1317 | UpdateValueMap(I, ResultReg); |
| 1318 | } |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1321 | return true; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1324 | // A quick function that will emit a call for a named libcall in F with the |
| 1325 | // 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] | 1326 | // can emit a call for any libcall we can produce. This is an abridged version |
| 1327 | // 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] | 1328 | // like computed function pointers or strange arguments at call sites. |
| 1329 | // TODO: Try to unify this and the normal call bits for ARM, then try to unify |
| 1330 | // with X86. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1331 | bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) { |
| 1332 | CallingConv::ID CC = TLI.getLibcallCallingConv(Call); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1333 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1334 | // Handle *simple* calls for now. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1335 | const Type *RetTy = I->getType(); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1336 | EVT RetVT; |
| 1337 | if (RetTy->isVoidTy()) |
| 1338 | RetVT = MVT::isVoid; |
| 1339 | else if (!isTypeLegal(RetTy, RetVT)) |
| 1340 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1341 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1342 | // For now we're using BLX etc on the assumption that we have v5t ops. |
| 1343 | if (!Subtarget->hasV5TOps()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1344 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1345 | // Set up the argument vectors. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1346 | SmallVector<Value*, 8> Args; |
| 1347 | SmallVector<unsigned, 8> ArgRegs; |
| 1348 | SmallVector<EVT, 8> ArgVTs; |
| 1349 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 1350 | Args.reserve(I->getNumOperands()); |
| 1351 | ArgRegs.reserve(I->getNumOperands()); |
| 1352 | ArgVTs.reserve(I->getNumOperands()); |
| 1353 | ArgFlags.reserve(I->getNumOperands()); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1354 | for (unsigned i = 0; i < I->getNumOperands(); ++i) { |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1355 | Value *Op = I->getOperand(i); |
| 1356 | unsigned Arg = getRegForValue(Op); |
| 1357 | if (Arg == 0) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1358 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1359 | const Type *ArgTy = Op->getType(); |
| 1360 | EVT ArgVT; |
| 1361 | if (!isTypeLegal(ArgTy, ArgVT)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1362 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1363 | ISD::ArgFlagsTy Flags; |
| 1364 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 1365 | Flags.setOrigAlign(OriginalAlignment); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1366 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1367 | Args.push_back(Op); |
| 1368 | ArgRegs.push_back(Arg); |
| 1369 | ArgVTs.push_back(ArgVT); |
| 1370 | ArgFlags.push_back(Flags); |
| 1371 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1372 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1373 | // Handle the arguments now that we've gotten them. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1374 | SmallVector<unsigned, 4> RegArgs; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1375 | unsigned NumBytes; |
| 1376 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes)) |
| 1377 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1378 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1379 | // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1380 | // TODO: Turn this into the table of arm call ops. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1381 | MachineInstrBuilder MIB; |
Eric Christopher | c109556 | 2010-09-18 02:32:38 +0000 | [diff] [blame] | 1382 | unsigned CallOpc; |
| 1383 | if(isThumb) |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1384 | CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi; |
Eric Christopher | c109556 | 2010-09-18 02:32:38 +0000 | [diff] [blame] | 1385 | else |
| 1386 | CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1387 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CallOpc)) |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1388 | .addExternalSymbol(TLI.getLibcallName(Call)); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1389 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1390 | // Add implicit physical register uses to the call. |
| 1391 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 1392 | MIB.addReg(RegArgs[i]); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1393 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1394 | // Finish off the call including any return values. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1395 | SmallVector<unsigned, 4> UsedRegs; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1396 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1397 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1398 | // Set all unused physreg defs as dead. |
| 1399 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1400 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1401 | return true; |
| 1402 | } |
| 1403 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1404 | bool ARMFastISel::SelectCall(const Instruction *I) { |
| 1405 | const CallInst *CI = cast<CallInst>(I); |
| 1406 | const Value *Callee = CI->getCalledValue(); |
| 1407 | |
| 1408 | // Can't handle inline asm or worry about intrinsics yet. |
| 1409 | if (isa<InlineAsm>(Callee) || isa<IntrinsicInst>(CI)) return false; |
| 1410 | |
Eric Christopher | e6ca677 | 2010-10-01 21:33:12 +0000 | [diff] [blame] | 1411 | // Only handle global variable Callees that are direct calls. |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1412 | const GlobalValue *GV = dyn_cast<GlobalValue>(Callee); |
Eric Christopher | e6ca677 | 2010-10-01 21:33:12 +0000 | [diff] [blame] | 1413 | if (!GV || Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel())) |
| 1414 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1415 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1416 | // Check the calling convention. |
| 1417 | ImmutableCallSite CS(CI); |
| 1418 | CallingConv::ID CC = CS.getCallingConv(); |
| 1419 | // TODO: Avoid some calling conventions? |
| 1420 | if (CC != CallingConv::C) { |
Eric Christopher | e540a6f | 2010-10-05 23:50:58 +0000 | [diff] [blame] | 1421 | // errs() << "Can't handle calling convention: " << CC << "\n"; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1422 | return false; |
| 1423 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1424 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1425 | // Let SDISel handle vararg functions. |
| 1426 | const PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType()); |
| 1427 | const FunctionType *FTy = cast<FunctionType>(PT->getElementType()); |
| 1428 | if (FTy->isVarArg()) |
| 1429 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1430 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1431 | // Handle *simple* calls for now. |
| 1432 | const Type *RetTy = I->getType(); |
| 1433 | EVT RetVT; |
| 1434 | if (RetTy->isVoidTy()) |
| 1435 | RetVT = MVT::isVoid; |
| 1436 | else if (!isTypeLegal(RetTy, RetVT)) |
| 1437 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1438 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1439 | // For now we're using BLX etc on the assumption that we have v5t ops. |
| 1440 | // TODO: Maybe? |
| 1441 | if (!Subtarget->hasV5TOps()) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1442 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1443 | // Set up the argument vectors. |
| 1444 | SmallVector<Value*, 8> Args; |
| 1445 | SmallVector<unsigned, 8> ArgRegs; |
| 1446 | SmallVector<EVT, 8> ArgVTs; |
| 1447 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 1448 | Args.reserve(CS.arg_size()); |
| 1449 | ArgRegs.reserve(CS.arg_size()); |
| 1450 | ArgVTs.reserve(CS.arg_size()); |
| 1451 | ArgFlags.reserve(CS.arg_size()); |
| 1452 | for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end(); |
| 1453 | i != e; ++i) { |
| 1454 | unsigned Arg = getRegForValue(*i); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1455 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1456 | if (Arg == 0) |
| 1457 | return false; |
| 1458 | ISD::ArgFlagsTy Flags; |
| 1459 | unsigned AttrInd = i - CS.arg_begin() + 1; |
| 1460 | if (CS.paramHasAttr(AttrInd, Attribute::SExt)) |
| 1461 | Flags.setSExt(); |
| 1462 | if (CS.paramHasAttr(AttrInd, Attribute::ZExt)) |
| 1463 | Flags.setZExt(); |
| 1464 | |
| 1465 | // FIXME: Only handle *easy* calls for now. |
| 1466 | if (CS.paramHasAttr(AttrInd, Attribute::InReg) || |
| 1467 | CS.paramHasAttr(AttrInd, Attribute::StructRet) || |
| 1468 | CS.paramHasAttr(AttrInd, Attribute::Nest) || |
| 1469 | CS.paramHasAttr(AttrInd, Attribute::ByVal)) |
| 1470 | return false; |
| 1471 | |
| 1472 | const Type *ArgTy = (*i)->getType(); |
| 1473 | EVT ArgVT; |
| 1474 | if (!isTypeLegal(ArgTy, ArgVT)) |
| 1475 | return false; |
| 1476 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 1477 | Flags.setOrigAlign(OriginalAlignment); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1478 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1479 | Args.push_back(*i); |
| 1480 | ArgRegs.push_back(Arg); |
| 1481 | ArgVTs.push_back(ArgVT); |
| 1482 | ArgFlags.push_back(Flags); |
| 1483 | } |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1484 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1485 | // Handle the arguments now that we've gotten them. |
| 1486 | SmallVector<unsigned, 4> RegArgs; |
| 1487 | unsigned NumBytes; |
| 1488 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes)) |
| 1489 | return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1490 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1491 | // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1492 | // TODO: Turn this into the table of arm call ops. |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1493 | MachineInstrBuilder MIB; |
| 1494 | unsigned CallOpc; |
| 1495 | if(isThumb) |
| 1496 | CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi; |
| 1497 | else |
| 1498 | CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL; |
| 1499 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CallOpc)) |
| 1500 | .addGlobalAddress(GV, 0, 0); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1501 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1502 | // Add implicit physical register uses to the call. |
| 1503 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 1504 | MIB.addReg(RegArgs[i]); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1505 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1506 | // Finish off the call including any return values. |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1507 | SmallVector<unsigned, 4> UsedRegs; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1508 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1509 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1510 | // Set all unused physreg defs as dead. |
| 1511 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1512 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1513 | return true; |
Eric Christopher | dccd2c3 | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1514 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1517 | // TODO: SoftFP support. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1518 | bool ARMFastISel::TargetSelectInstruction(const Instruction *I) { |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 1519 | // No Thumb-1 for now. |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 1520 | if (isThumb && !AFI->isThumb2Function()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1521 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1522 | switch (I->getOpcode()) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 1523 | case Instruction::Load: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1524 | return SelectLoad(I); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 1525 | case Instruction::Store: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1526 | return SelectStore(I); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1527 | case Instruction::Br: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1528 | return SelectBranch(I); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1529 | case Instruction::ICmp: |
| 1530 | case Instruction::FCmp: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1531 | return SelectCmp(I); |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1532 | case Instruction::FPExt: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1533 | return SelectFPExt(I); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1534 | case Instruction::FPTrunc: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1535 | return SelectFPTrunc(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1536 | case Instruction::SIToFP: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1537 | return SelectSIToFP(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1538 | case Instruction::FPToSI: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1539 | return SelectFPToSI(I); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1540 | case Instruction::FAdd: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1541 | return SelectBinaryOp(I, ISD::FADD); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1542 | case Instruction::FSub: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1543 | return SelectBinaryOp(I, ISD::FSUB); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1544 | case Instruction::FMul: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1545 | return SelectBinaryOp(I, ISD::FMUL); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1546 | case Instruction::SDiv: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1547 | return SelectSDiv(I); |
Eric Christopher | 6a880d6 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1548 | case Instruction::SRem: |
| 1549 | return SelectSRem(I); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1550 | case Instruction::Call: |
| 1551 | return SelectCall(I); |
Eric Christopher | 3bbd396 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1552 | case Instruction::Select: |
| 1553 | return SelectSelect(I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1554 | default: break; |
| 1555 | } |
| 1556 | return false; |
| 1557 | } |
| 1558 | |
| 1559 | namespace llvm { |
| 1560 | llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) { |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 1561 | // Completely untested on non-darwin. |
| 1562 | const TargetMachine &TM = funcInfo.MF->getTarget(); |
| 1563 | const ARMSubtarget *Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Eric Christopher | 8ff9a9d | 2010-10-11 20:26:21 +0000 | [diff] [blame] | 1564 | if (Subtarget->isTargetDarwin() && EnableARMFastISel) |
Eric Christopher | feadddd | 2010-10-11 20:05:22 +0000 | [diff] [blame] | 1565 | return new ARMFastISel(funcInfo); |
Evan Cheng | 0944795 | 2010-07-26 18:32:55 +0000 | [diff] [blame] | 1566 | return 0; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1567 | } |
| 1568 | } |