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