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