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