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