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