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