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> |
| 49 | EnableARMFastISel("arm-fast-isel", |
| 50 | cl::desc("Turn on experimental ARM fast-isel support"), |
| 51 | cl::init(false), cl::Hidden); |
| 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 | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 130 | virtual bool SelectCall(const Instruction *I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 131 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 132 | // Utility routines. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 133 | private: |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 134 | bool isTypeLegal(const Type *Ty, EVT &VT); |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 135 | bool isLoadTypeLegal(const Type *Ty, EVT &VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 136 | bool ARMEmitLoad(EVT VT, unsigned &ResultReg, unsigned Reg, int Offset); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 137 | bool ARMEmitStore(EVT VT, unsigned SrcReg, unsigned Reg, int Offset); |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 138 | bool ARMLoadAlloca(const Instruction *I, EVT VT); |
| 139 | bool ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT); |
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 | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 150 | bool ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
| 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; |
| 366 | |
| 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; |
| 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 | 238bb16 | 2010-09-09 23:50:00 +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; |
| 404 | |
| 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; |
| 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) { |
| 424 | |
| 425 | // For now 32-bit only. |
| 426 | if (VT.getSimpleVT().SimpleTy != MVT::i32) return false; |
| 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 | db12b2b | 2010-09-10 00:34:35 +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) { |
| 452 | // Disable currently... |
| 453 | return 0; |
| 454 | } |
| 455 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 456 | unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) { |
| 457 | EVT VT = TLI.getValueType(C->getType(), true); |
| 458 | |
| 459 | // Only handle simple types. |
| 460 | if (!VT.isSimple()) return 0; |
| 461 | |
| 462 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) |
| 463 | return ARMMaterializeFP(CFP, VT); |
Eric Christopher | c9932f6 | 2010-10-01 23:24:42 +0000 | [diff] [blame^] | 464 | else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 465 | return ARMMaterializeGV(GV, VT); |
| 466 | else if (isa<ConstantInt>(C)) |
| 467 | return ARMMaterializeInt(C, VT); |
| 468 | |
| 469 | return 0; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 472 | unsigned ARMFastISel::TargetMaterializeAlloca(const AllocaInst *AI) { |
| 473 | // Don't handle dynamic allocas. |
| 474 | if (!FuncInfo.StaticAllocaMap.count(AI)) return 0; |
| 475 | |
| 476 | EVT VT; |
| 477 | if (!isTypeLegal(AI->getType(), VT)) return false; |
| 478 | |
| 479 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 480 | FuncInfo.StaticAllocaMap.find(AI); |
| 481 | |
| 482 | // This will get lowered later into the correct offsets and registers |
| 483 | // via rewriteXFrameIndex. |
| 484 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
| 485 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
| 486 | unsigned ResultReg = createResultReg(RC); |
| 487 | unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri; |
| 488 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL, |
| 489 | TII.get(Opc), ResultReg) |
| 490 | .addFrameIndex(SI->second) |
| 491 | .addImm(0)); |
| 492 | return ResultReg; |
| 493 | } |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 498 | bool ARMFastISel::isTypeLegal(const Type *Ty, EVT &VT) { |
| 499 | VT = TLI.getValueType(Ty, true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 500 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 501 | // Only handle simple types. |
| 502 | if (VT == MVT::Other || !VT.isSimple()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 503 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 504 | // Handle all legal types, i.e. a register that will directly hold this |
| 505 | // value. |
| 506 | return TLI.isTypeLegal(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 509 | bool ARMFastISel::isLoadTypeLegal(const Type *Ty, EVT &VT) { |
| 510 | if (isTypeLegal(Ty, VT)) return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 511 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 512 | // If this is a type than can be sign or zero-extended to a basic operation |
| 513 | // go ahead and accept it now. |
| 514 | if (VT == MVT::i8 || VT == MVT::i16) |
| 515 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 516 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 517 | return false; |
| 518 | } |
| 519 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 520 | // Computes the Reg+Offset to get to an object. |
| 521 | bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg, |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 522 | int &Offset) { |
| 523 | // Some boilerplate from the X86 FastISel. |
| 524 | const User *U = NULL; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 525 | unsigned Opcode = Instruction::UserOp1; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 526 | if (const Instruction *I = dyn_cast<Instruction>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 527 | // Don't walk into other basic blocks; it's possible we haven't |
| 528 | // visited them yet, so the instructions may not yet be assigned |
| 529 | // virtual registers. |
| 530 | if (FuncInfo.MBBMap[I->getParent()] != FuncInfo.MBB) |
| 531 | return false; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 532 | Opcode = I->getOpcode(); |
| 533 | U = I; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 534 | } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 535 | Opcode = C->getOpcode(); |
| 536 | U = C; |
| 537 | } |
| 538 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 539 | if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType())) |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 540 | if (Ty->getAddressSpace() > 255) |
| 541 | // Fast instruction selection doesn't support the special |
| 542 | // address spaces. |
| 543 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 544 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 545 | switch (Opcode) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 546 | default: |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 547 | break; |
| 548 | case Instruction::Alloca: { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 549 | assert(false && "Alloca should have been handled earlier!"); |
| 550 | return false; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 551 | } |
| 552 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 553 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 554 | // FIXME: Handle global variables. |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 555 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 556 | (void)GV; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 557 | return false; |
| 558 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 559 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 560 | // Try to get this in a register if nothing else has worked. |
| 561 | Reg = getRegForValue(Obj); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 562 | if (Reg == 0) return false; |
| 563 | |
| 564 | // Since the offset may be too large for the load instruction |
| 565 | // get the reg+offset into a register. |
| 566 | // TODO: Verify the additions work, otherwise we'll need to add the |
| 567 | // offset instead of 0 to the instructions and do all sorts of operand |
| 568 | // munging. |
| 569 | // TODO: Optimize this somewhat. |
| 570 | if (Offset != 0) { |
| 571 | ARMCC::CondCodes Pred = ARMCC::AL; |
| 572 | unsigned PredReg = 0; |
| 573 | |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 574 | if (!isThumb) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 575 | emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 576 | Reg, Reg, Offset, Pred, PredReg, |
| 577 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 578 | else { |
| 579 | assert(AFI->isThumb2Function()); |
| 580 | emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 581 | Reg, Reg, Offset, Pred, PredReg, |
| 582 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 583 | } |
| 584 | } |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 585 | return true; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 588 | bool ARMFastISel::ARMLoadAlloca(const Instruction *I, EVT VT) { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 589 | Value *Op0 = I->getOperand(0); |
| 590 | |
| 591 | // Verify it's an alloca. |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 592 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op0)) { |
| 593 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 594 | FuncInfo.StaticAllocaMap.find(AI); |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 595 | |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 596 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 597 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 598 | unsigned ResultReg = createResultReg(RC); |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 599 | TII.loadRegFromStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt, |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 600 | ResultReg, SI->second, RC, |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 601 | TM.getRegisterInfo()); |
| 602 | UpdateValueMap(I, ResultReg); |
| 603 | return true; |
| 604 | } |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 605 | } |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 606 | return false; |
| 607 | } |
| 608 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 609 | bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg, |
| 610 | unsigned Reg, int Offset) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 611 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 612 | assert(VT.isSimple() && "Non-simple types are invalid here!"); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 613 | unsigned Opc; |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 614 | bool isFloat = false; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 615 | switch (VT.getSimpleVT().SimpleTy) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 616 | default: |
Eric Christopher | 98de5b4 | 2010-09-29 00:49:09 +0000 | [diff] [blame] | 617 | // This is mostly going to be Neon/vector support. |
Eric Christopher | 548d1bb | 2010-08-30 23:48:26 +0000 | [diff] [blame] | 618 | return false; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 619 | case MVT::i16: |
| 620 | Opc = isThumb ? ARM::tLDRH : ARM::LDRH; |
| 621 | VT = MVT::i32; |
| 622 | break; |
| 623 | case MVT::i8: |
| 624 | Opc = isThumb ? ARM::tLDRB : ARM::LDRB; |
| 625 | VT = MVT::i32; |
| 626 | break; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 627 | case MVT::i32: |
| 628 | Opc = isThumb ? ARM::tLDR : ARM::LDR; |
| 629 | break; |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 630 | case MVT::f32: |
| 631 | Opc = ARM::VLDRS; |
| 632 | isFloat = true; |
| 633 | break; |
| 634 | case MVT::f64: |
| 635 | Opc = ARM::VLDRD; |
| 636 | isFloat = true; |
| 637 | break; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 638 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 639 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 640 | ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 641 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 642 | // TODO: Fix the Addressing modes so that these can share some code. |
| 643 | // Since this is a Thumb1 load this will work in Thumb1 or 2 mode. |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 644 | // The thumb addressing mode has operands swapped from the arm addressing |
| 645 | // mode, the floating point one only has two operands. |
| 646 | if (isFloat) |
| 647 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 648 | TII.get(Opc), ResultReg) |
| 649 | .addReg(Reg).addImm(Offset)); |
| 650 | else if (isThumb) |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 651 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 652 | TII.get(Opc), ResultReg) |
| 653 | .addReg(Reg).addImm(Offset).addReg(0)); |
| 654 | else |
| 655 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 656 | TII.get(Opc), ResultReg) |
| 657 | .addReg(Reg).addReg(0).addImm(Offset)); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 658 | return true; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 661 | bool ARMFastISel::SelectLoad(const Instruction *I) { |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 662 | // Verify we have a legal type before going any further. |
| 663 | EVT VT; |
| 664 | if (!isLoadTypeLegal(I->getType(), VT)) |
| 665 | return false; |
| 666 | |
| 667 | // If we're an alloca we know we have a frame index and can emit the load |
| 668 | // directly in short order. |
| 669 | if (ARMLoadAlloca(I, VT)) |
| 670 | return true; |
| 671 | |
| 672 | // Our register and offset with innocuous defaults. |
| 673 | unsigned Reg = 0; |
| 674 | int Offset = 0; |
| 675 | |
| 676 | // See if we can handle this as Reg + Offset |
| 677 | if (!ARMComputeRegOffset(I->getOperand(0), Reg, Offset)) |
| 678 | return false; |
| 679 | |
| 680 | unsigned ResultReg; |
| 681 | if (!ARMEmitLoad(VT, ResultReg, Reg, Offset /* 0 */)) return false; |
| 682 | |
| 683 | UpdateValueMap(I, ResultReg); |
| 684 | return true; |
| 685 | } |
| 686 | |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 687 | bool ARMFastISel::ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT){ |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 688 | Value *Op1 = I->getOperand(1); |
| 689 | |
| 690 | // Verify it's an alloca. |
| 691 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op1)) { |
| 692 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 693 | FuncInfo.StaticAllocaMap.find(AI); |
| 694 | |
| 695 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 696 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 697 | assert(SrcReg != 0 && "Nothing to store!"); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 698 | TII.storeRegToStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt, |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 699 | SrcReg, true /*isKill*/, SI->second, RC, |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 700 | TM.getRegisterInfo()); |
| 701 | return true; |
| 702 | } |
| 703 | } |
| 704 | return false; |
| 705 | } |
| 706 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 707 | bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg, |
| 708 | unsigned DstReg, int Offset) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 709 | unsigned StrOpc; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 710 | bool isFloat = false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 711 | switch (VT.getSimpleVT().SimpleTy) { |
| 712 | default: return false; |
| 713 | case MVT::i1: |
| 714 | case MVT::i8: StrOpc = isThumb ? ARM::tSTRB : ARM::STRB; break; |
| 715 | case MVT::i16: StrOpc = isThumb ? ARM::tSTRH : ARM::STRH; break; |
| 716 | case MVT::i32: StrOpc = isThumb ? ARM::tSTR : ARM::STR; break; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 717 | case MVT::f32: |
| 718 | if (!Subtarget->hasVFP2()) return false; |
| 719 | StrOpc = ARM::VSTRS; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 720 | isFloat = true; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 721 | break; |
| 722 | case MVT::f64: |
| 723 | if (!Subtarget->hasVFP2()) return false; |
| 724 | StrOpc = ARM::VSTRD; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 725 | isFloat = true; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 726 | break; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 727 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 728 | |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 729 | // The thumb addressing mode has operands swapped from the arm addressing |
| 730 | // mode, the floating point one only has two operands. |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 731 | if (isFloat) |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 732 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 45547b8 | 2010-10-01 20:46:04 +0000 | [diff] [blame] | 733 | TII.get(StrOpc)) |
| 734 | .addReg(SrcReg).addReg(DstReg).addImm(Offset)); |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 735 | else if (isThumb) |
| 736 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 45547b8 | 2010-10-01 20:46:04 +0000 | [diff] [blame] | 737 | TII.get(StrOpc)) |
| 738 | .addReg(SrcReg).addReg(DstReg).addImm(Offset).addReg(0)); |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 739 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 740 | else |
| 741 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 45547b8 | 2010-10-01 20:46:04 +0000 | [diff] [blame] | 742 | TII.get(StrOpc)) |
| 743 | .addReg(SrcReg).addReg(DstReg).addReg(0).addImm(Offset)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 744 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 745 | return true; |
| 746 | } |
| 747 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 748 | bool ARMFastISel::SelectStore(const Instruction *I) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 749 | Value *Op0 = I->getOperand(0); |
| 750 | unsigned SrcReg = 0; |
| 751 | |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 752 | // Yay type legalization |
| 753 | EVT VT; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 754 | if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT)) |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 755 | return false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 756 | |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 757 | // Get the value to be stored into a register. |
| 758 | SrcReg = getRegForValue(Op0); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 759 | if (SrcReg == 0) |
| 760 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 761 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 762 | // If we're an alloca we know we have a frame index and can emit the store |
| 763 | // quickly. |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 764 | if (ARMStoreAlloca(I, SrcReg, VT)) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 765 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 766 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 767 | // Our register and offset with innocuous defaults. |
| 768 | unsigned Reg = 0; |
| 769 | int Offset = 0; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 770 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 771 | // See if we can handle this as Reg + Offset |
| 772 | if (!ARMComputeRegOffset(I->getOperand(1), Reg, Offset)) |
| 773 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 774 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 775 | if (!ARMEmitStore(VT, SrcReg, Reg, Offset /* 0 */)) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 776 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 777 | return true; |
| 778 | } |
| 779 | |
| 780 | static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) { |
| 781 | switch (Pred) { |
| 782 | // Needs two compares... |
| 783 | case CmpInst::FCMP_ONE: |
| 784 | case CmpInst::FCMP_UEQ: |
| 785 | default: |
| 786 | assert(false && "Unhandled CmpInst::Predicate!"); |
| 787 | return ARMCC::AL; |
| 788 | case CmpInst::ICMP_EQ: |
| 789 | case CmpInst::FCMP_OEQ: |
| 790 | return ARMCC::EQ; |
| 791 | case CmpInst::ICMP_SGT: |
| 792 | case CmpInst::FCMP_OGT: |
| 793 | return ARMCC::GT; |
| 794 | case CmpInst::ICMP_SGE: |
| 795 | case CmpInst::FCMP_OGE: |
| 796 | return ARMCC::GE; |
| 797 | case CmpInst::ICMP_UGT: |
| 798 | case CmpInst::FCMP_UGT: |
| 799 | return ARMCC::HI; |
| 800 | case CmpInst::FCMP_OLT: |
| 801 | return ARMCC::MI; |
| 802 | case CmpInst::ICMP_ULE: |
| 803 | case CmpInst::FCMP_OLE: |
| 804 | return ARMCC::LS; |
| 805 | case CmpInst::FCMP_ORD: |
| 806 | return ARMCC::VC; |
| 807 | case CmpInst::FCMP_UNO: |
| 808 | return ARMCC::VS; |
| 809 | case CmpInst::FCMP_UGE: |
| 810 | return ARMCC::PL; |
| 811 | case CmpInst::ICMP_SLT: |
| 812 | case CmpInst::FCMP_ULT: |
| 813 | return ARMCC::LT; |
| 814 | case CmpInst::ICMP_SLE: |
| 815 | case CmpInst::FCMP_ULE: |
| 816 | return ARMCC::LE; |
| 817 | case CmpInst::FCMP_UNE: |
| 818 | case CmpInst::ICMP_NE: |
| 819 | return ARMCC::NE; |
| 820 | case CmpInst::ICMP_UGE: |
| 821 | return ARMCC::HS; |
| 822 | case CmpInst::ICMP_ULT: |
| 823 | return ARMCC::LO; |
| 824 | } |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 827 | bool ARMFastISel::SelectBranch(const Instruction *I) { |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 828 | const BranchInst *BI = cast<BranchInst>(I); |
| 829 | MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)]; |
| 830 | MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)]; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 831 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 832 | // Simple branch support. |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 833 | // TODO: Try to avoid the re-computation in some places. |
| 834 | unsigned CondReg = getRegForValue(BI->getCondition()); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 835 | if (CondReg == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 836 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 837 | // Re-set the flags just in case. |
| 838 | unsigned CmpOpc = isThumb ? ARM::t2CMPri : ARM::CMPri; |
| 839 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 840 | .addReg(CondReg).addImm(1)); |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 841 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 842 | unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 843 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 844 | .addMBB(TBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 845 | FastEmitBranch(FBB, DL); |
| 846 | FuncInfo.MBB->addSuccessor(TBB); |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 847 | return true; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 850 | bool ARMFastISel::SelectCmp(const Instruction *I) { |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 851 | const CmpInst *CI = cast<CmpInst>(I); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 852 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 853 | EVT VT; |
| 854 | const Type *Ty = CI->getOperand(0)->getType(); |
| 855 | if (!isTypeLegal(Ty, VT)) |
| 856 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 857 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 858 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 859 | if (isFloat && !Subtarget->hasVFP2()) |
| 860 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 861 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 862 | unsigned CmpOpc; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 863 | unsigned CondReg; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 864 | switch (VT.getSimpleVT().SimpleTy) { |
| 865 | default: return false; |
| 866 | // TODO: Verify compares. |
| 867 | case MVT::f32: |
| 868 | CmpOpc = ARM::VCMPES; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 869 | CondReg = ARM::FPSCR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 870 | break; |
| 871 | case MVT::f64: |
| 872 | CmpOpc = ARM::VCMPED; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 873 | CondReg = ARM::FPSCR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 874 | break; |
| 875 | case MVT::i32: |
| 876 | CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr; |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 877 | CondReg = ARM::CPSR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 878 | break; |
| 879 | } |
| 880 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 881 | // Get the compare predicate. |
| 882 | ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate()); |
| 883 | |
| 884 | // We may not handle every CC for now. |
| 885 | if (ARMPred == ARMCC::AL) return false; |
| 886 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 887 | unsigned Arg1 = getRegForValue(CI->getOperand(0)); |
| 888 | if (Arg1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 889 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 890 | unsigned Arg2 = getRegForValue(CI->getOperand(1)); |
| 891 | if (Arg2 == 0) 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 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 894 | .addReg(Arg1).addReg(Arg2)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 895 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 896 | // For floating point we need to move the result to a comparison register |
| 897 | // that we can then use for branches. |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 898 | if (isFloat) |
| 899 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 900 | TII.get(ARM::FMSTAT))); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 901 | |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 902 | // Now set a register based on the comparison. Explicitly set the predicates |
| 903 | // here. |
| 904 | unsigned MovCCOpc = isThumb ? ARM::tMOVCCi : ARM::MOVCCi; |
| 905 | unsigned DestReg = createResultReg(ARM::GPRRegisterClass); |
| 906 | Constant *Zero |
Eric Christopher | 8cf6c60 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 907 | = ConstantInt::get(Type::getInt32Ty(*Context), 0); |
Eric Christopher | 229207a | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 908 | unsigned ZeroReg = TargetMaterializeConstant(Zero); |
| 909 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), DestReg) |
| 910 | .addReg(ZeroReg).addImm(1) |
| 911 | .addImm(ARMPred).addReg(CondReg); |
| 912 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 913 | UpdateValueMap(I, DestReg); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 914 | return true; |
| 915 | } |
| 916 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 917 | bool ARMFastISel::SelectFPExt(const Instruction *I) { |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 918 | // Make sure we have VFP and that we're extending float to double. |
| 919 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 920 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 921 | Value *V = I->getOperand(0); |
| 922 | if (!I->getType()->isDoubleTy() || |
| 923 | !V->getType()->isFloatTy()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 924 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 925 | unsigned Op = getRegForValue(V); |
| 926 | if (Op == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 927 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 928 | unsigned Result = createResultReg(ARM::DPRRegisterClass); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 929 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 930 | TII.get(ARM::VCVTDS), Result) |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 931 | .addReg(Op)); |
| 932 | UpdateValueMap(I, Result); |
| 933 | return true; |
| 934 | } |
| 935 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 936 | bool ARMFastISel::SelectFPTrunc(const Instruction *I) { |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 937 | // Make sure we have VFP and that we're truncating double to float. |
| 938 | if (!Subtarget->hasVFP2()) return false; |
| 939 | |
| 940 | Value *V = I->getOperand(0); |
| 941 | if (!I->getType()->isFloatTy() || |
| 942 | !V->getType()->isDoubleTy()) return false; |
| 943 | |
| 944 | unsigned Op = getRegForValue(V); |
| 945 | if (Op == 0) return false; |
| 946 | |
| 947 | unsigned Result = createResultReg(ARM::SPRRegisterClass); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 948 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 949 | TII.get(ARM::VCVTSD), Result) |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 950 | .addReg(Op)); |
| 951 | UpdateValueMap(I, Result); |
| 952 | return true; |
| 953 | } |
| 954 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 955 | bool ARMFastISel::SelectSIToFP(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 956 | // Make sure we have VFP. |
| 957 | if (!Subtarget->hasVFP2()) return false; |
| 958 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 959 | EVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 960 | const Type *Ty = I->getType(); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 961 | if (!isTypeLegal(Ty, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 962 | return false; |
| 963 | |
| 964 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 965 | if (Op == 0) return false; |
| 966 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 967 | // The conversion routine works on fp-reg to fp-reg and the operand above |
| 968 | // was an integer, move it to the fp registers if possible. |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 969 | unsigned FP = ARMMoveToFPReg(DstVT, Op); |
| 970 | if (FP == 0) return false; |
| 971 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 972 | unsigned Opc; |
| 973 | if (Ty->isFloatTy()) Opc = ARM::VSITOS; |
| 974 | else if (Ty->isDoubleTy()) Opc = ARM::VSITOD; |
| 975 | else return 0; |
| 976 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 977 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 978 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 979 | ResultReg) |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 980 | .addReg(FP)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 981 | UpdateValueMap(I, ResultReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 982 | return true; |
| 983 | } |
| 984 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 985 | bool ARMFastISel::SelectFPToSI(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 986 | // Make sure we have VFP. |
| 987 | if (!Subtarget->hasVFP2()) return false; |
| 988 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 989 | EVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 990 | const Type *RetTy = I->getType(); |
Eric Christopher | 920a208 | 2010-09-10 00:35:09 +0000 | [diff] [blame] | 991 | if (!isTypeLegal(RetTy, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 992 | return false; |
| 993 | |
| 994 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 995 | if (Op == 0) return false; |
| 996 | |
| 997 | unsigned Opc; |
| 998 | const Type *OpTy = I->getOperand(0)->getType(); |
| 999 | if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS; |
| 1000 | else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD; |
| 1001 | else return 0; |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1002 | EVT OpVT = TLI.getValueType(OpTy, true); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1003 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1004 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(OpVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1005 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 1006 | ResultReg) |
| 1007 | .addReg(Op)); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1008 | |
| 1009 | // This result needs to be in an integer register, but the conversion only |
| 1010 | // takes place in fp-regs. |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1011 | unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1012 | if (IntReg == 0) return false; |
| 1013 | |
| 1014 | UpdateValueMap(I, IntReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1015 | return true; |
| 1016 | } |
| 1017 | |
Eric Christopher | 0863785 | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1018 | bool ARMFastISel::SelectSDiv(const Instruction *I) { |
| 1019 | EVT VT; |
| 1020 | const Type *Ty = I->getType(); |
| 1021 | if (!isTypeLegal(Ty, VT)) |
| 1022 | return false; |
| 1023 | |
| 1024 | // If we have integer div support we should have selected this automagically. |
| 1025 | // In case we have a real miss go ahead and return false and we'll pick |
| 1026 | // it up later. |
| 1027 | if (Subtarget->hasDivide()) return false; |
| 1028 | |
| 1029 | // Otherwise emit a libcall. |
| 1030 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 1031 | if (VT == MVT::i16) |
| 1032 | LC = RTLIB::SDIV_I16; |
| 1033 | else if (VT == MVT::i32) |
| 1034 | LC = RTLIB::SDIV_I32; |
| 1035 | else if (VT == MVT::i64) |
| 1036 | LC = RTLIB::SDIV_I64; |
| 1037 | else if (VT == MVT::i128) |
| 1038 | LC = RTLIB::SDIV_I128; |
| 1039 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!"); |
| 1040 | |
| 1041 | return ARMEmitLibcall(I, LC); |
| 1042 | } |
| 1043 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1044 | bool ARMFastISel::SelectBinaryOp(const Instruction *I, unsigned ISDOpcode) { |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1045 | EVT VT = TLI.getValueType(I->getType(), true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1046 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1047 | // We can get here in the case when we want to use NEON for our fp |
| 1048 | // operations, but can't figure out how to. Just use the vfp instructions |
| 1049 | // if we have them. |
| 1050 | // FIXME: It'd be nice to use NEON instructions. |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1051 | const Type *Ty = I->getType(); |
| 1052 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 1053 | if (isFloat && !Subtarget->hasVFP2()) |
| 1054 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1055 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1056 | unsigned Op1 = getRegForValue(I->getOperand(0)); |
| 1057 | if (Op1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1058 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1059 | unsigned Op2 = getRegForValue(I->getOperand(1)); |
| 1060 | if (Op2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1061 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1062 | unsigned Opc; |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1063 | bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64 || |
| 1064 | VT.getSimpleVT().SimpleTy == MVT::i64; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1065 | switch (ISDOpcode) { |
| 1066 | default: return false; |
| 1067 | case ISD::FADD: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1068 | Opc = is64bit ? ARM::VADDD : ARM::VADDS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1069 | break; |
| 1070 | case ISD::FSUB: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1071 | Opc = is64bit ? ARM::VSUBD : ARM::VSUBS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1072 | break; |
| 1073 | case ISD::FMUL: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1074 | Opc = is64bit ? ARM::VMULD : ARM::VMULS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1075 | break; |
| 1076 | } |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1077 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1078 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1079 | TII.get(Opc), ResultReg) |
| 1080 | .addReg(Op1).addReg(Op2)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1081 | UpdateValueMap(I, ResultReg); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1082 | return true; |
| 1083 | } |
| 1084 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1085 | // Call Handling Code |
| 1086 | |
| 1087 | // This is largely taken directly from CCAssignFnForNode - we don't support |
| 1088 | // varargs in FastISel so that part has been removed. |
| 1089 | // TODO: We may not support all of this. |
| 1090 | CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) { |
| 1091 | switch (CC) { |
| 1092 | default: |
| 1093 | llvm_unreachable("Unsupported calling convention"); |
| 1094 | case CallingConv::C: |
| 1095 | case CallingConv::Fast: |
| 1096 | // Use target triple & subtarget features to do actual dispatch. |
| 1097 | if (Subtarget->isAAPCS_ABI()) { |
| 1098 | if (Subtarget->hasVFP2() && |
| 1099 | FloatABIType == FloatABI::Hard) |
| 1100 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1101 | else |
| 1102 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1103 | } else |
| 1104 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1105 | case CallingConv::ARM_AAPCS_VFP: |
| 1106 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1107 | case CallingConv::ARM_AAPCS: |
| 1108 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1109 | case CallingConv::ARM_APCS: |
| 1110 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1111 | } |
| 1112 | } |
| 1113 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1114 | bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
| 1115 | SmallVectorImpl<unsigned> &ArgRegs, |
| 1116 | SmallVectorImpl<EVT> &ArgVTs, |
| 1117 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 1118 | SmallVectorImpl<unsigned> &RegArgs, |
| 1119 | CallingConv::ID CC, |
| 1120 | unsigned &NumBytes) { |
| 1121 | SmallVector<CCValAssign, 16> ArgLocs; |
| 1122 | CCState CCInfo(CC, false, TM, ArgLocs, *Context); |
| 1123 | CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC, false)); |
| 1124 | |
| 1125 | // Get a count of how many bytes are to be pushed on the stack. |
| 1126 | NumBytes = CCInfo.getNextStackOffset(); |
| 1127 | |
| 1128 | // Issue CALLSEQ_START |
| 1129 | unsigned AdjStackDown = TM.getRegisterInfo()->getCallFrameSetupOpcode(); |
| 1130 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(AdjStackDown)) |
| 1131 | .addImm(NumBytes); |
| 1132 | |
| 1133 | // Process the args. |
| 1134 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1135 | CCValAssign &VA = ArgLocs[i]; |
| 1136 | unsigned Arg = ArgRegs[VA.getValNo()]; |
| 1137 | EVT ArgVT = ArgVTs[VA.getValNo()]; |
| 1138 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1139 | // Handle arg promotion, etc. |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1140 | switch (VA.getLocInfo()) { |
| 1141 | case CCValAssign::Full: break; |
| 1142 | default: |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1143 | assert(false && "Handle arg promotion."); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1144 | return false; |
| 1145 | } |
| 1146 | |
| 1147 | // Now copy/store arg to correct locations. |
| 1148 | if (VA.isRegLoc()) { |
| 1149 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1150 | VA.getLocReg()) |
| 1151 | .addReg(Arg); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1152 | RegArgs.push_back(VA.getLocReg()); |
| 1153 | } else { |
| 1154 | // Need to store |
| 1155 | return false; |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | return true; |
| 1160 | } |
| 1161 | |
| 1162 | bool ARMFastISel::FinishCall(EVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
| 1163 | const Instruction *I, CallingConv::ID CC, |
| 1164 | unsigned &NumBytes) { |
| 1165 | // Issue CALLSEQ_END |
| 1166 | unsigned AdjStackUp = TM.getRegisterInfo()->getCallFrameDestroyOpcode(); |
| 1167 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(AdjStackUp)) |
| 1168 | .addImm(NumBytes).addImm(0); |
| 1169 | |
| 1170 | // Now the return value. |
| 1171 | if (RetVT.getSimpleVT().SimpleTy != MVT::isVoid) { |
| 1172 | SmallVector<CCValAssign, 16> RVLocs; |
| 1173 | CCState CCInfo(CC, false, TM, RVLocs, *Context); |
| 1174 | CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true)); |
| 1175 | |
| 1176 | // Copy all of the result registers out of their specified physreg. |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1177 | if (RVLocs.size() == 2 && RetVT.getSimpleVT().SimpleTy == MVT::f64) { |
| 1178 | // For this move we copy into two registers and then move into the |
| 1179 | // double fp reg we want. |
| 1180 | // TODO: Are the copies necessary? |
| 1181 | TargetRegisterClass *CopyRC = TLI.getRegClassFor(MVT::i32); |
| 1182 | unsigned Copy1 = createResultReg(CopyRC); |
| 1183 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1184 | Copy1).addReg(RVLocs[0].getLocReg()); |
| 1185 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
| 1186 | |
| 1187 | unsigned Copy2 = createResultReg(CopyRC); |
| 1188 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1189 | Copy2).addReg(RVLocs[1].getLocReg()); |
| 1190 | UsedRegs.push_back(RVLocs[1].getLocReg()); |
| 1191 | |
| 1192 | EVT DestVT = RVLocs[0].getValVT(); |
| 1193 | TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT); |
| 1194 | unsigned ResultReg = createResultReg(DstRC); |
| 1195 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 1196 | TII.get(ARM::VMOVDRR), ResultReg) |
| 1197 | .addReg(Copy1).addReg(Copy2)); |
| 1198 | |
| 1199 | // Finally update the result. |
| 1200 | UpdateValueMap(I, ResultReg); |
| 1201 | } else { |
| 1202 | assert(RVLocs.size() == 1 && "Can't handle non-double multi-reg retvals!"); |
| 1203 | EVT CopyVT = RVLocs[0].getValVT(); |
| 1204 | TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1205 | |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1206 | unsigned ResultReg = createResultReg(DstRC); |
| 1207 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1208 | ResultReg).addReg(RVLocs[0].getLocReg()); |
| 1209 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1210 | |
Eric Christopher | 14df882 | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 1211 | // Finally update the result. |
| 1212 | UpdateValueMap(I, ResultReg); |
| 1213 | } |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | return true; |
| 1217 | } |
| 1218 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1219 | // A quick function that will emit a call for a named libcall in F with the |
| 1220 | // vector of passed arguments for the Instruction in I. We can assume that we |
| 1221 | // can emit a call for any libcall we can produce. This is an abridged version |
| 1222 | // of the full call infrastructure since we won't need to worry about things |
| 1223 | // like computed function pointers or strange arguments at call sites. |
| 1224 | // TODO: Try to unify this and the normal call bits for ARM, then try to unify |
| 1225 | // with X86. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1226 | bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) { |
| 1227 | CallingConv::ID CC = TLI.getLibcallCallingConv(Call); |
| 1228 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1229 | // Handle *simple* calls for now. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1230 | const Type *RetTy = I->getType(); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1231 | EVT RetVT; |
| 1232 | if (RetTy->isVoidTy()) |
| 1233 | RetVT = MVT::isVoid; |
| 1234 | else if (!isTypeLegal(RetTy, RetVT)) |
| 1235 | return false; |
| 1236 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1237 | // For now we're using BLX etc on the assumption that we have v5t ops. |
| 1238 | if (!Subtarget->hasV5TOps()) return false; |
| 1239 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1240 | // Set up the argument vectors. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1241 | SmallVector<Value*, 8> Args; |
| 1242 | SmallVector<unsigned, 8> ArgRegs; |
| 1243 | SmallVector<EVT, 8> ArgVTs; |
| 1244 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 1245 | Args.reserve(I->getNumOperands()); |
| 1246 | ArgRegs.reserve(I->getNumOperands()); |
| 1247 | ArgVTs.reserve(I->getNumOperands()); |
| 1248 | ArgFlags.reserve(I->getNumOperands()); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1249 | for (unsigned i = 0; i < I->getNumOperands(); ++i) { |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1250 | Value *Op = I->getOperand(i); |
| 1251 | unsigned Arg = getRegForValue(Op); |
| 1252 | if (Arg == 0) return false; |
| 1253 | |
| 1254 | const Type *ArgTy = Op->getType(); |
| 1255 | EVT ArgVT; |
| 1256 | if (!isTypeLegal(ArgTy, ArgVT)) return false; |
| 1257 | |
| 1258 | ISD::ArgFlagsTy Flags; |
| 1259 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 1260 | Flags.setOrigAlign(OriginalAlignment); |
| 1261 | |
| 1262 | Args.push_back(Op); |
| 1263 | ArgRegs.push_back(Arg); |
| 1264 | ArgVTs.push_back(ArgVT); |
| 1265 | ArgFlags.push_back(Flags); |
| 1266 | } |
| 1267 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1268 | // Handle the arguments now that we've gotten them. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1269 | SmallVector<unsigned, 4> RegArgs; |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1270 | unsigned NumBytes; |
| 1271 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes)) |
| 1272 | return false; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1273 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1274 | // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops. |
| 1275 | // TODO: Turn this into the table of arm call ops. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1276 | MachineInstrBuilder MIB; |
Eric Christopher | c109556 | 2010-09-18 02:32:38 +0000 | [diff] [blame] | 1277 | unsigned CallOpc; |
| 1278 | if(isThumb) |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1279 | CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi; |
Eric Christopher | c109556 | 2010-09-18 02:32:38 +0000 | [diff] [blame] | 1280 | else |
| 1281 | CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1282 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CallOpc)) |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 1283 | .addExternalSymbol(TLI.getLibcallName(Call)); |
| 1284 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1285 | // Add implicit physical register uses to the call. |
| 1286 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 1287 | MIB.addReg(RegArgs[i]); |
| 1288 | |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1289 | // Finish off the call including any return values. |
| 1290 | SmallVector<unsigned, 4> UsedRegs; |
| 1291 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1292 | |
| 1293 | // Set all unused physreg defs as dead. |
| 1294 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | a9a7a1a | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1295 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1296 | return true; |
| 1297 | } |
| 1298 | |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1299 | bool ARMFastISel::SelectCall(const Instruction *I) { |
| 1300 | const CallInst *CI = cast<CallInst>(I); |
| 1301 | const Value *Callee = CI->getCalledValue(); |
| 1302 | |
| 1303 | // Can't handle inline asm or worry about intrinsics yet. |
| 1304 | if (isa<InlineAsm>(Callee) || isa<IntrinsicInst>(CI)) return false; |
| 1305 | |
Eric Christopher | e6ca677 | 2010-10-01 21:33:12 +0000 | [diff] [blame] | 1306 | // Only handle global variable Callees that are direct calls. |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1307 | const GlobalValue *GV = dyn_cast<GlobalValue>(Callee); |
Eric Christopher | e6ca677 | 2010-10-01 21:33:12 +0000 | [diff] [blame] | 1308 | if (!GV || Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel())) |
| 1309 | return false; |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1310 | |
| 1311 | // Check the calling convention. |
| 1312 | ImmutableCallSite CS(CI); |
| 1313 | CallingConv::ID CC = CS.getCallingConv(); |
| 1314 | // TODO: Avoid some calling conventions? |
| 1315 | if (CC != CallingConv::C) { |
| 1316 | errs() << "Can't handle calling convention: " << CC << "\n"; |
| 1317 | return false; |
| 1318 | } |
| 1319 | |
| 1320 | // Let SDISel handle vararg functions. |
| 1321 | const PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType()); |
| 1322 | const FunctionType *FTy = cast<FunctionType>(PT->getElementType()); |
| 1323 | if (FTy->isVarArg()) |
| 1324 | return false; |
| 1325 | |
| 1326 | // Handle *simple* calls for now. |
| 1327 | const Type *RetTy = I->getType(); |
| 1328 | EVT RetVT; |
| 1329 | if (RetTy->isVoidTy()) |
| 1330 | RetVT = MVT::isVoid; |
| 1331 | else if (!isTypeLegal(RetTy, RetVT)) |
| 1332 | return false; |
| 1333 | |
| 1334 | // For now we're using BLX etc on the assumption that we have v5t ops. |
| 1335 | // TODO: Maybe? |
| 1336 | if (!Subtarget->hasV5TOps()) return false; |
| 1337 | |
| 1338 | // Set up the argument vectors. |
| 1339 | SmallVector<Value*, 8> Args; |
| 1340 | SmallVector<unsigned, 8> ArgRegs; |
| 1341 | SmallVector<EVT, 8> ArgVTs; |
| 1342 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 1343 | Args.reserve(CS.arg_size()); |
| 1344 | ArgRegs.reserve(CS.arg_size()); |
| 1345 | ArgVTs.reserve(CS.arg_size()); |
| 1346 | ArgFlags.reserve(CS.arg_size()); |
| 1347 | for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end(); |
| 1348 | i != e; ++i) { |
| 1349 | unsigned Arg = getRegForValue(*i); |
| 1350 | |
| 1351 | if (Arg == 0) |
| 1352 | return false; |
| 1353 | ISD::ArgFlagsTy Flags; |
| 1354 | unsigned AttrInd = i - CS.arg_begin() + 1; |
| 1355 | if (CS.paramHasAttr(AttrInd, Attribute::SExt)) |
| 1356 | Flags.setSExt(); |
| 1357 | if (CS.paramHasAttr(AttrInd, Attribute::ZExt)) |
| 1358 | Flags.setZExt(); |
| 1359 | |
| 1360 | // FIXME: Only handle *easy* calls for now. |
| 1361 | if (CS.paramHasAttr(AttrInd, Attribute::InReg) || |
| 1362 | CS.paramHasAttr(AttrInd, Attribute::StructRet) || |
| 1363 | CS.paramHasAttr(AttrInd, Attribute::Nest) || |
| 1364 | CS.paramHasAttr(AttrInd, Attribute::ByVal)) |
| 1365 | return false; |
| 1366 | |
| 1367 | const Type *ArgTy = (*i)->getType(); |
| 1368 | EVT ArgVT; |
| 1369 | if (!isTypeLegal(ArgTy, ArgVT)) |
| 1370 | return false; |
| 1371 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 1372 | Flags.setOrigAlign(OriginalAlignment); |
| 1373 | |
| 1374 | Args.push_back(*i); |
| 1375 | ArgRegs.push_back(Arg); |
| 1376 | ArgVTs.push_back(ArgVT); |
| 1377 | ArgFlags.push_back(Flags); |
| 1378 | } |
| 1379 | |
| 1380 | // Handle the arguments now that we've gotten them. |
| 1381 | SmallVector<unsigned, 4> RegArgs; |
| 1382 | unsigned NumBytes; |
| 1383 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes)) |
| 1384 | return false; |
| 1385 | |
| 1386 | // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops. |
| 1387 | // TODO: Turn this into the table of arm call ops. |
| 1388 | MachineInstrBuilder MIB; |
| 1389 | unsigned CallOpc; |
| 1390 | if(isThumb) |
| 1391 | CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi; |
| 1392 | else |
| 1393 | CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL; |
| 1394 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CallOpc)) |
| 1395 | .addGlobalAddress(GV, 0, 0); |
| 1396 | |
| 1397 | // Add implicit physical register uses to the call. |
| 1398 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 1399 | MIB.addReg(RegArgs[i]); |
| 1400 | |
| 1401 | // Finish off the call including any return values. |
| 1402 | SmallVector<unsigned, 4> UsedRegs; |
| 1403 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false; |
| 1404 | |
| 1405 | // Set all unused physreg defs as dead. |
| 1406 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
| 1407 | |
| 1408 | return true; |
| 1409 | |
| 1410 | } |
| 1411 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1412 | // TODO: SoftFP support. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1413 | bool ARMFastISel::TargetSelectInstruction(const Instruction *I) { |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 1414 | // No Thumb-1 for now. |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 1415 | if (isThumb && !AFI->isThumb2Function()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1416 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1417 | switch (I->getOpcode()) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 1418 | case Instruction::Load: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1419 | return SelectLoad(I); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 1420 | case Instruction::Store: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1421 | return SelectStore(I); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1422 | case Instruction::Br: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1423 | return SelectBranch(I); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1424 | case Instruction::ICmp: |
| 1425 | case Instruction::FCmp: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1426 | return SelectCmp(I); |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1427 | case Instruction::FPExt: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1428 | return SelectFPExt(I); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1429 | case Instruction::FPTrunc: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1430 | return SelectFPTrunc(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1431 | case Instruction::SIToFP: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1432 | return SelectSIToFP(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1433 | case Instruction::FPToSI: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1434 | return SelectFPToSI(I); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1435 | case Instruction::FAdd: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1436 | return SelectBinaryOp(I, ISD::FADD); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1437 | case Instruction::FSub: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1438 | return SelectBinaryOp(I, ISD::FSUB); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1439 | case Instruction::FMul: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1440 | return SelectBinaryOp(I, ISD::FMUL); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1441 | case Instruction::SDiv: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1442 | return SelectSDiv(I); |
Eric Christopher | f9764fa | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1443 | case Instruction::Call: |
| 1444 | return SelectCall(I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1445 | default: break; |
| 1446 | } |
| 1447 | return false; |
| 1448 | } |
| 1449 | |
| 1450 | namespace llvm { |
| 1451 | llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) { |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 1452 | if (EnableARMFastISel) return new ARMFastISel(funcInfo); |
Evan Cheng | 0944795 | 2010-07-26 18:32:55 +0000 | [diff] [blame] | 1453 | return 0; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1454 | } |
| 1455 | } |