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