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