Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1 | //===-- ARMFastISel.cpp - ARM FastISel implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ARM-specific support for the FastISel class. Some |
| 11 | // of the target-specific code is generated by tablegen in the file |
| 12 | // ARMGenFastISel.inc, which is #included here. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "ARM.h" |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 17 | #include "ARMBaseInstrInfo.h" |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 18 | #include "ARMCallingConv.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 19 | #include "ARMRegisterInfo.h" |
| 20 | #include "ARMTargetMachine.h" |
| 21 | #include "ARMSubtarget.h" |
| 22 | #include "llvm/CallingConv.h" |
| 23 | #include "llvm/DerivedTypes.h" |
| 24 | #include "llvm/GlobalVariable.h" |
| 25 | #include "llvm/Instructions.h" |
| 26 | #include "llvm/IntrinsicInst.h" |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 27 | #include "llvm/Module.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/Analysis.h" |
| 29 | #include "llvm/CodeGen/FastISel.h" |
| 30 | #include "llvm/CodeGen/FunctionLoweringInfo.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 32 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 34 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 35 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 36 | #include "llvm/Support/CallSite.h" |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 37 | #include "llvm/Support/CommandLine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 38 | #include "llvm/Support/ErrorHandling.h" |
| 39 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 40 | #include "llvm/Target/TargetData.h" |
| 41 | #include "llvm/Target/TargetInstrInfo.h" |
| 42 | #include "llvm/Target/TargetLowering.h" |
| 43 | #include "llvm/Target/TargetMachine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 44 | #include "llvm/Target/TargetOptions.h" |
| 45 | using namespace llvm; |
| 46 | |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 47 | static cl::opt<bool> |
| 48 | EnableARMFastISel("arm-fast-isel", |
| 49 | cl::desc("Turn on experimental ARM fast-isel support"), |
| 50 | cl::init(false), cl::Hidden); |
| 51 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 52 | namespace { |
| 53 | |
| 54 | class ARMFastISel : public FastISel { |
| 55 | |
| 56 | /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can |
| 57 | /// make the right decision when generating code for different targets. |
| 58 | const ARMSubtarget *Subtarget; |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 59 | const TargetMachine &TM; |
| 60 | const TargetInstrInfo &TII; |
| 61 | const TargetLowering &TLI; |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 62 | const ARMFunctionInfo *AFI; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 63 | |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 64 | // Convenience variable to avoid checking all the time. |
| 65 | bool isThumb; |
| 66 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 67 | public: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 68 | explicit ARMFastISel(FunctionLoweringInfo &funcInfo) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 69 | : FastISel(funcInfo), |
| 70 | TM(funcInfo.MF->getTarget()), |
| 71 | TII(*TM.getInstrInfo()), |
| 72 | TLI(*TM.getTargetLowering()) { |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 73 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 74 | AFI = funcInfo.MF->getInfo<ARMFunctionInfo>(); |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 75 | isThumb = AFI->isThumbFunction(); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 78 | // Code from FastISel.cpp. |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 79 | virtual unsigned FastEmitInst_(unsigned MachineInstOpcode, |
| 80 | const TargetRegisterClass *RC); |
| 81 | virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode, |
| 82 | const TargetRegisterClass *RC, |
| 83 | unsigned Op0, bool Op0IsKill); |
| 84 | virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode, |
| 85 | const TargetRegisterClass *RC, |
| 86 | unsigned Op0, bool Op0IsKill, |
| 87 | unsigned Op1, bool Op1IsKill); |
| 88 | virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode, |
| 89 | const TargetRegisterClass *RC, |
| 90 | unsigned Op0, bool Op0IsKill, |
| 91 | uint64_t Imm); |
| 92 | virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode, |
| 93 | const TargetRegisterClass *RC, |
| 94 | unsigned Op0, bool Op0IsKill, |
| 95 | const ConstantFP *FPImm); |
| 96 | virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode, |
| 97 | const TargetRegisterClass *RC, |
| 98 | uint64_t Imm); |
| 99 | virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode, |
| 100 | const TargetRegisterClass *RC, |
| 101 | unsigned Op0, bool Op0IsKill, |
| 102 | unsigned Op1, bool Op1IsKill, |
| 103 | uint64_t Imm); |
| 104 | virtual unsigned FastEmitInst_extractsubreg(MVT RetVT, |
| 105 | unsigned Op0, bool Op0IsKill, |
| 106 | uint32_t Idx); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 107 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 108 | // Backend specific FastISel code. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 109 | virtual bool TargetSelectInstruction(const Instruction *I); |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 110 | virtual unsigned TargetMaterializeConstant(const Constant *C); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 111 | |
| 112 | #include "ARMGenFastISel.inc" |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 113 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 114 | // Instruction selection routines. |
Eric Christopher | 44bff90 | 2010-09-10 23:10:30 +0000 | [diff] [blame] | 115 | private: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 116 | virtual bool SelectLoad(const Instruction *I); |
| 117 | virtual bool SelectStore(const Instruction *I); |
| 118 | virtual bool SelectBranch(const Instruction *I); |
| 119 | virtual bool SelectCmp(const Instruction *I); |
| 120 | virtual bool SelectFPExt(const Instruction *I); |
| 121 | virtual bool SelectFPTrunc(const Instruction *I); |
| 122 | virtual bool SelectBinaryOp(const Instruction *I, unsigned ISDOpcode); |
| 123 | virtual bool SelectSIToFP(const Instruction *I); |
| 124 | virtual bool SelectFPToSI(const Instruction *I); |
| 125 | virtual bool SelectSDiv(const Instruction *I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 126 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 127 | // Utility routines. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 128 | private: |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 129 | bool isTypeLegal(const Type *Ty, EVT &VT); |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 130 | bool isLoadTypeLegal(const Type *Ty, EVT &VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 131 | bool ARMEmitLoad(EVT VT, unsigned &ResultReg, unsigned Reg, int Offset); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 132 | bool ARMEmitStore(EVT VT, unsigned SrcReg, unsigned Reg, int Offset); |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 133 | bool ARMLoadAlloca(const Instruction *I, EVT VT); |
| 134 | bool ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT); |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 135 | bool ARMComputeRegOffset(const Value *Obj, unsigned &Reg, int &Offset); |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 136 | unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT); |
| 137 | unsigned ARMMaterializeInt(const Constant *C); |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 138 | unsigned ARMMoveToFPReg(EVT VT, unsigned SrcReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 139 | unsigned ARMMoveToIntReg(EVT VT, unsigned SrcReg); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 140 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 141 | // Call handling routines. |
| 142 | private: |
| 143 | CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool Return); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 144 | bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call); |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 145 | |
| 146 | // OptionalDef handling routines. |
| 147 | private: |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 148 | bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR); |
| 149 | const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB); |
| 150 | }; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 151 | |
| 152 | } // end anonymous namespace |
| 153 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 154 | #include "ARMGenCallingConv.inc" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 155 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 156 | // DefinesOptionalPredicate - This is different from DefinesPredicate in that |
| 157 | // we don't care about implicit defs here, just places we'll need to add a |
| 158 | // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR. |
| 159 | bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) { |
| 160 | const TargetInstrDesc &TID = MI->getDesc(); |
| 161 | if (!TID.hasOptionalDef()) |
| 162 | return false; |
| 163 | |
| 164 | // Look to see if our OptionalDef is defining CPSR or CCR. |
| 165 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 166 | const MachineOperand &MO = MI->getOperand(i); |
Eric Christopher | f762fbe | 2010-08-20 00:36:24 +0000 | [diff] [blame] | 167 | if (!MO.isReg() || !MO.isDef()) continue; |
| 168 | if (MO.getReg() == ARM::CPSR) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 169 | *CPSR = true; |
| 170 | } |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | // If the machine is predicable go ahead and add the predicate operands, if |
| 175 | // it needs default CC operands add those. |
| 176 | const MachineInstrBuilder & |
| 177 | ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) { |
| 178 | MachineInstr *MI = &*MIB; |
| 179 | |
| 180 | // Do we use a predicate? |
| 181 | if (TII.isPredicable(MI)) |
| 182 | AddDefaultPred(MIB); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 183 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 184 | // Do we optionally set a predicate? Preds is size > 0 iff the predicate |
| 185 | // defines CPSR. All other OptionalDefines in ARM are the CCR register. |
Eric Christopher | 979e0a1 | 2010-08-19 15:35:27 +0000 | [diff] [blame] | 186 | bool CPSR = false; |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 187 | if (DefinesOptionalPredicate(MI, &CPSR)) { |
| 188 | if (CPSR) |
| 189 | AddDefaultT1CC(MIB); |
| 190 | else |
| 191 | AddDefaultCC(MIB); |
| 192 | } |
| 193 | return MIB; |
| 194 | } |
| 195 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 196 | unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode, |
| 197 | const TargetRegisterClass* RC) { |
| 198 | unsigned ResultReg = createResultReg(RC); |
| 199 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 200 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 201 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 202 | return ResultReg; |
| 203 | } |
| 204 | |
| 205 | unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode, |
| 206 | const TargetRegisterClass *RC, |
| 207 | unsigned Op0, bool Op0IsKill) { |
| 208 | unsigned ResultReg = createResultReg(RC); |
| 209 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 210 | |
| 211 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 212 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 213 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
| 214 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 215 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 216 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 217 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 218 | TII.get(TargetOpcode::COPY), ResultReg) |
| 219 | .addReg(II.ImplicitDefs[0])); |
| 220 | } |
| 221 | return ResultReg; |
| 222 | } |
| 223 | |
| 224 | unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode, |
| 225 | const TargetRegisterClass *RC, |
| 226 | unsigned Op0, bool Op0IsKill, |
| 227 | unsigned Op1, bool Op1IsKill) { |
| 228 | unsigned ResultReg = createResultReg(RC); |
| 229 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 230 | |
| 231 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 232 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 233 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 234 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
| 235 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 236 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 237 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 238 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 239 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 240 | TII.get(TargetOpcode::COPY), ResultReg) |
| 241 | .addReg(II.ImplicitDefs[0])); |
| 242 | } |
| 243 | return ResultReg; |
| 244 | } |
| 245 | |
| 246 | unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode, |
| 247 | const TargetRegisterClass *RC, |
| 248 | unsigned Op0, bool Op0IsKill, |
| 249 | uint64_t Imm) { |
| 250 | unsigned ResultReg = createResultReg(RC); |
| 251 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 252 | |
| 253 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 254 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 255 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 256 | .addImm(Imm)); |
| 257 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 258 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 259 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 260 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 261 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 262 | TII.get(TargetOpcode::COPY), ResultReg) |
| 263 | .addReg(II.ImplicitDefs[0])); |
| 264 | } |
| 265 | return ResultReg; |
| 266 | } |
| 267 | |
| 268 | unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode, |
| 269 | const TargetRegisterClass *RC, |
| 270 | unsigned Op0, bool Op0IsKill, |
| 271 | const ConstantFP *FPImm) { |
| 272 | unsigned ResultReg = createResultReg(RC); |
| 273 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 274 | |
| 275 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 276 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 277 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 278 | .addFPImm(FPImm)); |
| 279 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 280 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 281 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 282 | .addFPImm(FPImm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 283 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 284 | TII.get(TargetOpcode::COPY), ResultReg) |
| 285 | .addReg(II.ImplicitDefs[0])); |
| 286 | } |
| 287 | return ResultReg; |
| 288 | } |
| 289 | |
| 290 | unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode, |
| 291 | const TargetRegisterClass *RC, |
| 292 | unsigned Op0, bool Op0IsKill, |
| 293 | unsigned Op1, bool Op1IsKill, |
| 294 | uint64_t Imm) { |
| 295 | unsigned ResultReg = createResultReg(RC); |
| 296 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 297 | |
| 298 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 299 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 300 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 301 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 302 | .addImm(Imm)); |
| 303 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 304 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 305 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 306 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 307 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 308 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 309 | TII.get(TargetOpcode::COPY), ResultReg) |
| 310 | .addReg(II.ImplicitDefs[0])); |
| 311 | } |
| 312 | return ResultReg; |
| 313 | } |
| 314 | |
| 315 | unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode, |
| 316 | const TargetRegisterClass *RC, |
| 317 | uint64_t Imm) { |
| 318 | unsigned ResultReg = createResultReg(RC); |
| 319 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 320 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 321 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 322 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 323 | .addImm(Imm)); |
| 324 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 325 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 326 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 327 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 328 | TII.get(TargetOpcode::COPY), ResultReg) |
| 329 | .addReg(II.ImplicitDefs[0])); |
| 330 | } |
| 331 | return ResultReg; |
| 332 | } |
| 333 | |
| 334 | unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT, |
| 335 | unsigned Op0, bool Op0IsKill, |
| 336 | uint32_t Idx) { |
| 337 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT)); |
| 338 | assert(TargetRegisterInfo::isVirtualRegister(Op0) && |
| 339 | "Cannot yet extract from physregs"); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 340 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 341 | DL, TII.get(TargetOpcode::COPY), ResultReg) |
| 342 | .addReg(Op0, getKillRegState(Op0IsKill), Idx)); |
| 343 | return ResultReg; |
| 344 | } |
| 345 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 346 | // TODO: Don't worry about 64-bit now, but when this is fixed remove the |
| 347 | // checks from the various callers. |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 348 | unsigned ARMFastISel::ARMMoveToFPReg(EVT VT, unsigned SrcReg) { |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 349 | if (VT.getSimpleVT().SimpleTy == MVT::f64) return 0; |
| 350 | |
| 351 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 352 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 353 | TII.get(ARM::VMOVRS), MoveReg) |
| 354 | .addReg(SrcReg)); |
| 355 | return MoveReg; |
| 356 | } |
| 357 | |
| 358 | unsigned ARMFastISel::ARMMoveToIntReg(EVT VT, unsigned SrcReg) { |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 359 | if (VT.getSimpleVT().SimpleTy == MVT::i64) return 0; |
| 360 | |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 361 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 362 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 363 | TII.get(ARM::VMOVSR), MoveReg) |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 364 | .addReg(SrcReg)); |
| 365 | return MoveReg; |
| 366 | } |
| 367 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 368 | // For double width floating point we need to materialize two constants |
| 369 | // (the high and the low) into integer registers then use a move to get |
| 370 | // the combined constant into an FP reg. |
| 371 | unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, EVT VT) { |
| 372 | const APFloat Val = CFP->getValueAPF(); |
| 373 | bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 374 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 375 | // This checks to see if we can use VFP3 instructions to materialize |
| 376 | // a constant, otherwise we have to go through the constant pool. |
| 377 | if (TLI.isFPImmLegal(Val, VT)) { |
| 378 | unsigned Opc = is64bit ? ARM::FCONSTD : ARM::FCONSTS; |
| 379 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 380 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 381 | DestReg) |
| 382 | .addFPImm(CFP)); |
| 383 | return DestReg; |
| 384 | } |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 385 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 386 | // Require VFP2 for loading fp constants. |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 387 | if (!Subtarget->hasVFP2()) return false; |
| 388 | |
| 389 | // MachineConstantPool wants an explicit alignment. |
| 390 | unsigned Align = TD.getPrefTypeAlignment(CFP->getType()); |
| 391 | if (Align == 0) { |
| 392 | // TODO: Figure out if this is correct. |
| 393 | Align = TD.getTypeAllocSize(CFP->getType()); |
| 394 | } |
| 395 | unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align); |
| 396 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 397 | unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS; |
| 398 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 399 | // The extra reg is for addrmode5. |
Eric Christopher | f5732c4 | 2010-09-28 00:35:09 +0000 | [diff] [blame] | 400 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 401 | DestReg) |
| 402 | .addConstantPoolIndex(Idx) |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 403 | .addReg(0)); |
| 404 | return DestReg; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 407 | // TODO: Verify 64-bit. |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 408 | unsigned ARMFastISel::ARMMaterializeInt(const Constant *C) { |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 409 | // MachineConstantPool wants an explicit alignment. |
| 410 | unsigned Align = TD.getPrefTypeAlignment(C->getType()); |
| 411 | if (Align == 0) { |
| 412 | // TODO: Figure out if this is correct. |
| 413 | Align = TD.getTypeAllocSize(C->getType()); |
| 414 | } |
| 415 | unsigned Idx = MCP.getConstantPoolIndex(C, Align); |
Eric Christopher | 845c575 | 2010-09-08 18:56:34 +0000 | [diff] [blame] | 416 | unsigned DestReg = createResultReg(TLI.getRegClassFor(MVT::i32)); |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 417 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 418 | if (isThumb) |
| 419 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 420 | TII.get(ARM::t2LDRpci)) |
| 421 | .addReg(DestReg).addConstantPoolIndex(Idx)); |
| 422 | else |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 423 | // The extra reg and immediate are for addrmode2. |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 424 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 425 | TII.get(ARM::LDRcp)) |
Eric Christopher | 845c575 | 2010-09-08 18:56:34 +0000 | [diff] [blame] | 426 | .addReg(DestReg).addConstantPoolIndex(Idx) |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 427 | .addReg(0).addImm(0)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 428 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 429 | return DestReg; |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 432 | unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) { |
| 433 | EVT VT = TLI.getValueType(C->getType(), true); |
| 434 | |
| 435 | // Only handle simple types. |
| 436 | if (!VT.isSimple()) return 0; |
| 437 | |
| 438 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) |
| 439 | return ARMMaterializeFP(CFP, VT); |
| 440 | return ARMMaterializeInt(C); |
| 441 | } |
| 442 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 443 | bool ARMFastISel::isTypeLegal(const Type *Ty, EVT &VT) { |
| 444 | VT = TLI.getValueType(Ty, true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 445 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 446 | // Only handle simple types. |
| 447 | if (VT == MVT::Other || !VT.isSimple()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 448 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 449 | // Handle all legal types, i.e. a register that will directly hold this |
| 450 | // value. |
| 451 | return TLI.isTypeLegal(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 454 | bool ARMFastISel::isLoadTypeLegal(const Type *Ty, EVT &VT) { |
| 455 | if (isTypeLegal(Ty, VT)) return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 456 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 457 | // If this is a type than can be sign or zero-extended to a basic operation |
| 458 | // go ahead and accept it now. |
| 459 | if (VT == MVT::i8 || VT == MVT::i16) |
| 460 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 461 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 462 | return false; |
| 463 | } |
| 464 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 465 | // Computes the Reg+Offset to get to an object. |
| 466 | bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg, |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 467 | int &Offset) { |
| 468 | // Some boilerplate from the X86 FastISel. |
| 469 | const User *U = NULL; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 470 | unsigned Opcode = Instruction::UserOp1; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 471 | if (const Instruction *I = dyn_cast<Instruction>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 472 | // Don't walk into other basic blocks; it's possible we haven't |
| 473 | // visited them yet, so the instructions may not yet be assigned |
| 474 | // virtual registers. |
| 475 | if (FuncInfo.MBBMap[I->getParent()] != FuncInfo.MBB) |
| 476 | return false; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 477 | Opcode = I->getOpcode(); |
| 478 | U = I; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 479 | } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 480 | Opcode = C->getOpcode(); |
| 481 | U = C; |
| 482 | } |
| 483 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 484 | if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType())) |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 485 | if (Ty->getAddressSpace() > 255) |
| 486 | // Fast instruction selection doesn't support the special |
| 487 | // address spaces. |
| 488 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 489 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 490 | switch (Opcode) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 491 | default: |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 492 | break; |
| 493 | case Instruction::Alloca: { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 494 | assert(false && "Alloca should have been handled earlier!"); |
| 495 | return false; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 496 | } |
| 497 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 498 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 499 | // FIXME: Handle global variables. |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 500 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 501 | (void)GV; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 502 | return false; |
| 503 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 504 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 505 | // Try to get this in a register if nothing else has worked. |
| 506 | Reg = getRegForValue(Obj); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 507 | if (Reg == 0) return false; |
| 508 | |
| 509 | // Since the offset may be too large for the load instruction |
| 510 | // get the reg+offset into a register. |
| 511 | // TODO: Verify the additions work, otherwise we'll need to add the |
| 512 | // offset instead of 0 to the instructions and do all sorts of operand |
| 513 | // munging. |
| 514 | // TODO: Optimize this somewhat. |
| 515 | if (Offset != 0) { |
| 516 | ARMCC::CondCodes Pred = ARMCC::AL; |
| 517 | unsigned PredReg = 0; |
| 518 | |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 519 | if (!isThumb) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 520 | emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 521 | Reg, Reg, Offset, Pred, PredReg, |
| 522 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 523 | else { |
| 524 | assert(AFI->isThumb2Function()); |
| 525 | emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 526 | Reg, Reg, Offset, Pred, PredReg, |
| 527 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 528 | } |
| 529 | } |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 530 | return true; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 533 | bool ARMFastISel::ARMLoadAlloca(const Instruction *I, EVT VT) { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 534 | Value *Op0 = I->getOperand(0); |
| 535 | |
| 536 | // Verify it's an alloca. |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 537 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op0)) { |
| 538 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 539 | FuncInfo.StaticAllocaMap.find(AI); |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 540 | |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 541 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 542 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 543 | unsigned ResultReg = createResultReg(RC); |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 544 | TII.loadRegFromStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt, |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 545 | ResultReg, SI->second, RC, |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 546 | TM.getRegisterInfo()); |
| 547 | UpdateValueMap(I, ResultReg); |
| 548 | return true; |
| 549 | } |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 550 | } |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 551 | return false; |
| 552 | } |
| 553 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 554 | bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg, |
| 555 | unsigned Reg, int Offset) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 556 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 557 | assert(VT.isSimple() && "Non-simple types are invalid here!"); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 558 | unsigned Opc; |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 559 | bool isFloat = false; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 560 | switch (VT.getSimpleVT().SimpleTy) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 561 | default: |
Eric Christopher | 548d1bb | 2010-08-30 23:48:26 +0000 | [diff] [blame] | 562 | assert(false && "Trying to emit for an unhandled type!"); |
| 563 | return false; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 564 | case MVT::i16: |
| 565 | Opc = isThumb ? ARM::tLDRH : ARM::LDRH; |
| 566 | VT = MVT::i32; |
| 567 | break; |
| 568 | case MVT::i8: |
| 569 | Opc = isThumb ? ARM::tLDRB : ARM::LDRB; |
| 570 | VT = MVT::i32; |
| 571 | break; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 572 | case MVT::i32: |
| 573 | Opc = isThumb ? ARM::tLDR : ARM::LDR; |
| 574 | break; |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 575 | case MVT::f32: |
| 576 | Opc = ARM::VLDRS; |
| 577 | isFloat = true; |
| 578 | break; |
| 579 | case MVT::f64: |
| 580 | Opc = ARM::VLDRD; |
| 581 | isFloat = true; |
| 582 | break; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 583 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 584 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 585 | ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 586 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 587 | // TODO: Fix the Addressing modes so that these can share some code. |
| 588 | // Since this is a Thumb1 load this will work in Thumb1 or 2 mode. |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 589 | // The thumb addressing mode has operands swapped from the arm addressing |
| 590 | // mode, the floating point one only has two operands. |
| 591 | if (isFloat) |
| 592 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 593 | TII.get(Opc), ResultReg) |
| 594 | .addReg(Reg).addImm(Offset)); |
| 595 | else if (isThumb) |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 596 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 597 | TII.get(Opc), ResultReg) |
| 598 | .addReg(Reg).addImm(Offset).addReg(0)); |
| 599 | else |
| 600 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 601 | TII.get(Opc), ResultReg) |
| 602 | .addReg(Reg).addReg(0).addImm(Offset)); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 603 | return true; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 606 | bool ARMFastISel::SelectLoad(const Instruction *I) { |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 607 | // Verify we have a legal type before going any further. |
| 608 | EVT VT; |
| 609 | if (!isLoadTypeLegal(I->getType(), VT)) |
| 610 | return false; |
| 611 | |
| 612 | // If we're an alloca we know we have a frame index and can emit the load |
| 613 | // directly in short order. |
| 614 | if (ARMLoadAlloca(I, VT)) |
| 615 | return true; |
| 616 | |
| 617 | // Our register and offset with innocuous defaults. |
| 618 | unsigned Reg = 0; |
| 619 | int Offset = 0; |
| 620 | |
| 621 | // See if we can handle this as Reg + Offset |
| 622 | if (!ARMComputeRegOffset(I->getOperand(0), Reg, Offset)) |
| 623 | return false; |
| 624 | |
| 625 | unsigned ResultReg; |
| 626 | if (!ARMEmitLoad(VT, ResultReg, Reg, Offset /* 0 */)) return false; |
| 627 | |
| 628 | UpdateValueMap(I, ResultReg); |
| 629 | return true; |
| 630 | } |
| 631 | |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 632 | bool ARMFastISel::ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT){ |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 633 | Value *Op1 = I->getOperand(1); |
| 634 | |
| 635 | // Verify it's an alloca. |
| 636 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op1)) { |
| 637 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 638 | FuncInfo.StaticAllocaMap.find(AI); |
| 639 | |
| 640 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 641 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 642 | assert(SrcReg != 0 && "Nothing to store!"); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 643 | TII.storeRegToStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt, |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 644 | SrcReg, true /*isKill*/, SI->second, RC, |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 645 | TM.getRegisterInfo()); |
| 646 | return true; |
| 647 | } |
| 648 | } |
| 649 | return false; |
| 650 | } |
| 651 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 652 | bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg, |
| 653 | unsigned DstReg, int Offset) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 654 | unsigned StrOpc; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 655 | bool isFloat = false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 656 | switch (VT.getSimpleVT().SimpleTy) { |
| 657 | default: return false; |
| 658 | case MVT::i1: |
| 659 | case MVT::i8: StrOpc = isThumb ? ARM::tSTRB : ARM::STRB; break; |
| 660 | case MVT::i16: StrOpc = isThumb ? ARM::tSTRH : ARM::STRH; break; |
| 661 | case MVT::i32: StrOpc = isThumb ? ARM::tSTR : ARM::STR; break; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 662 | case MVT::f32: |
| 663 | if (!Subtarget->hasVFP2()) return false; |
| 664 | StrOpc = ARM::VSTRS; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 665 | isFloat = true; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 666 | break; |
| 667 | case MVT::f64: |
| 668 | if (!Subtarget->hasVFP2()) return false; |
| 669 | StrOpc = ARM::VSTRD; |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 670 | isFloat = true; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 671 | break; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 672 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 673 | |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 674 | // The thumb addressing mode has operands swapped from the arm addressing |
| 675 | // mode, the floating point one only has two operands. |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 676 | if (isFloat) |
Eric Christopher | b74558a | 2010-09-18 01:23:38 +0000 | [diff] [blame] | 677 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 678 | TII.get(StrOpc), SrcReg) |
| 679 | .addReg(DstReg).addImm(Offset)); |
Eric Christopher | 6dab137 | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 680 | else if (isThumb) |
| 681 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 682 | TII.get(StrOpc), SrcReg) |
| 683 | .addReg(DstReg).addImm(Offset).addReg(0)); |
| 684 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 685 | else |
| 686 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 687 | TII.get(StrOpc), SrcReg) |
| 688 | .addReg(DstReg).addReg(0).addImm(Offset)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 689 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 690 | return true; |
| 691 | } |
| 692 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 693 | bool ARMFastISel::SelectStore(const Instruction *I) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 694 | Value *Op0 = I->getOperand(0); |
| 695 | unsigned SrcReg = 0; |
| 696 | |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 697 | // Yay type legalization |
| 698 | EVT VT; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 699 | if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT)) |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 700 | return false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 701 | |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 702 | // Get the value to be stored into a register. |
| 703 | SrcReg = getRegForValue(Op0); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 704 | if (SrcReg == 0) |
| 705 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 706 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 707 | // If we're an alloca we know we have a frame index and can emit the store |
| 708 | // quickly. |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 709 | if (ARMStoreAlloca(I, SrcReg, VT)) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 710 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 711 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 712 | // Our register and offset with innocuous defaults. |
| 713 | unsigned Reg = 0; |
| 714 | int Offset = 0; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 715 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 716 | // See if we can handle this as Reg + Offset |
| 717 | if (!ARMComputeRegOffset(I->getOperand(1), Reg, Offset)) |
| 718 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 719 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 720 | if (!ARMEmitStore(VT, SrcReg, Reg, Offset /* 0 */)) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 721 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 722 | return true; |
| 723 | } |
| 724 | |
| 725 | static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) { |
| 726 | switch (Pred) { |
| 727 | // Needs two compares... |
| 728 | case CmpInst::FCMP_ONE: |
| 729 | case CmpInst::FCMP_UEQ: |
| 730 | default: |
| 731 | assert(false && "Unhandled CmpInst::Predicate!"); |
| 732 | return ARMCC::AL; |
| 733 | case CmpInst::ICMP_EQ: |
| 734 | case CmpInst::FCMP_OEQ: |
| 735 | return ARMCC::EQ; |
| 736 | case CmpInst::ICMP_SGT: |
| 737 | case CmpInst::FCMP_OGT: |
| 738 | return ARMCC::GT; |
| 739 | case CmpInst::ICMP_SGE: |
| 740 | case CmpInst::FCMP_OGE: |
| 741 | return ARMCC::GE; |
| 742 | case CmpInst::ICMP_UGT: |
| 743 | case CmpInst::FCMP_UGT: |
| 744 | return ARMCC::HI; |
| 745 | case CmpInst::FCMP_OLT: |
| 746 | return ARMCC::MI; |
| 747 | case CmpInst::ICMP_ULE: |
| 748 | case CmpInst::FCMP_OLE: |
| 749 | return ARMCC::LS; |
| 750 | case CmpInst::FCMP_ORD: |
| 751 | return ARMCC::VC; |
| 752 | case CmpInst::FCMP_UNO: |
| 753 | return ARMCC::VS; |
| 754 | case CmpInst::FCMP_UGE: |
| 755 | return ARMCC::PL; |
| 756 | case CmpInst::ICMP_SLT: |
| 757 | case CmpInst::FCMP_ULT: |
| 758 | return ARMCC::LT; |
| 759 | case CmpInst::ICMP_SLE: |
| 760 | case CmpInst::FCMP_ULE: |
| 761 | return ARMCC::LE; |
| 762 | case CmpInst::FCMP_UNE: |
| 763 | case CmpInst::ICMP_NE: |
| 764 | return ARMCC::NE; |
| 765 | case CmpInst::ICMP_UGE: |
| 766 | return ARMCC::HS; |
| 767 | case CmpInst::ICMP_ULT: |
| 768 | return ARMCC::LO; |
| 769 | } |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 770 | } |
| 771 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 772 | bool ARMFastISel::SelectBranch(const Instruction *I) { |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 773 | const BranchInst *BI = cast<BranchInst>(I); |
| 774 | MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)]; |
| 775 | MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)]; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 776 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 777 | // Simple branch support. |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 778 | // TODO: Hopefully we've already handled the condition since we won't |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 779 | // have left an update in the value map. See the TODO below in SelectCMP. |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 780 | Value *Cond = BI->getCondition(); |
| 781 | unsigned CondReg = getRegForValue(Cond); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 782 | if (CondReg == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 783 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 784 | ARMCC::CondCodes ARMPred = ARMCC::NE; |
| 785 | CmpInst *CI = dyn_cast<CmpInst>(Cond); |
| 786 | if (!CI) return false; |
| 787 | |
| 788 | // Get the compare predicate. |
| 789 | ARMPred = getComparePred(CI->getPredicate()); |
| 790 | |
| 791 | // We may not handle every CC for now. |
| 792 | if (ARMPred == ARMCC::AL) return false; |
| 793 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 794 | unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 795 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 796 | .addMBB(TBB).addImm(ARMPred).addReg(CondReg); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 797 | FastEmitBranch(FBB, DL); |
| 798 | FuncInfo.MBB->addSuccessor(TBB); |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 799 | return true; |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 802 | bool ARMFastISel::SelectCmp(const Instruction *I) { |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 803 | const CmpInst *CI = cast<CmpInst>(I); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 804 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 805 | EVT VT; |
| 806 | const Type *Ty = CI->getOperand(0)->getType(); |
| 807 | if (!isTypeLegal(Ty, VT)) |
| 808 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 809 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 810 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 811 | if (isFloat && !Subtarget->hasVFP2()) |
| 812 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 813 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 814 | unsigned CmpOpc; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 815 | unsigned DestReg; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 816 | switch (VT.getSimpleVT().SimpleTy) { |
| 817 | default: return false; |
| 818 | // TODO: Verify compares. |
| 819 | case MVT::f32: |
| 820 | CmpOpc = ARM::VCMPES; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 821 | DestReg = ARM::FPSCR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 822 | break; |
| 823 | case MVT::f64: |
| 824 | CmpOpc = ARM::VCMPED; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 825 | DestReg = ARM::FPSCR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 826 | break; |
| 827 | case MVT::i32: |
| 828 | CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr; |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 829 | DestReg = ARM::CPSR; |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 830 | break; |
| 831 | } |
| 832 | |
| 833 | unsigned Arg1 = getRegForValue(CI->getOperand(0)); |
| 834 | if (Arg1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 835 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 836 | unsigned Arg2 = getRegForValue(CI->getOperand(1)); |
| 837 | if (Arg2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 838 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 839 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 840 | .addReg(Arg1).addReg(Arg2)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 841 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 842 | // For floating point we need to move the result to a comparison register |
| 843 | // that we can then use for branches. |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 844 | if (isFloat) |
| 845 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 846 | TII.get(ARM::FMSTAT))); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 847 | |
Eric Christopher | a5b1e68 | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 848 | // Update the value to the implicit def reg. |
| 849 | UpdateValueMap(I, DestReg); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 850 | return true; |
| 851 | } |
| 852 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 853 | bool ARMFastISel::SelectFPExt(const Instruction *I) { |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 854 | // Make sure we have VFP and that we're extending float to double. |
| 855 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 856 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 857 | Value *V = I->getOperand(0); |
| 858 | if (!I->getType()->isDoubleTy() || |
| 859 | !V->getType()->isFloatTy()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 860 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 861 | unsigned Op = getRegForValue(V); |
| 862 | if (Op == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 863 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 864 | unsigned Result = createResultReg(ARM::DPRRegisterClass); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 865 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 866 | TII.get(ARM::VCVTDS), Result) |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 867 | .addReg(Op)); |
| 868 | UpdateValueMap(I, Result); |
| 869 | return true; |
| 870 | } |
| 871 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 872 | bool ARMFastISel::SelectFPTrunc(const Instruction *I) { |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 873 | // Make sure we have VFP and that we're truncating double to float. |
| 874 | if (!Subtarget->hasVFP2()) return false; |
| 875 | |
| 876 | Value *V = I->getOperand(0); |
| 877 | if (!I->getType()->isFloatTy() || |
| 878 | !V->getType()->isDoubleTy()) return false; |
| 879 | |
| 880 | unsigned Op = getRegForValue(V); |
| 881 | if (Op == 0) return false; |
| 882 | |
| 883 | unsigned Result = createResultReg(ARM::SPRRegisterClass); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 884 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 885 | TII.get(ARM::VCVTSD), Result) |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 886 | .addReg(Op)); |
| 887 | UpdateValueMap(I, Result); |
| 888 | return true; |
| 889 | } |
| 890 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 891 | bool ARMFastISel::SelectSIToFP(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 892 | // Make sure we have VFP. |
| 893 | if (!Subtarget->hasVFP2()) return false; |
| 894 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 895 | EVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 896 | const Type *Ty = I->getType(); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 897 | if (!isTypeLegal(Ty, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 898 | return false; |
| 899 | |
| 900 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 901 | if (Op == 0) return false; |
| 902 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 903 | // The conversion routine works on fp-reg to fp-reg and the operand above |
| 904 | // was an integer, move it to the fp registers if possible. |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 905 | unsigned FP = ARMMoveToFPReg(DstVT, Op); |
| 906 | if (FP == 0) return false; |
| 907 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 908 | unsigned Opc; |
| 909 | if (Ty->isFloatTy()) Opc = ARM::VSITOS; |
| 910 | else if (Ty->isDoubleTy()) Opc = ARM::VSITOD; |
| 911 | else return 0; |
| 912 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 913 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 914 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 915 | ResultReg) |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 916 | .addReg(FP)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 917 | UpdateValueMap(I, ResultReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 918 | return true; |
| 919 | } |
| 920 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 921 | bool ARMFastISel::SelectFPToSI(const Instruction *I) { |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 922 | // Make sure we have VFP. |
| 923 | if (!Subtarget->hasVFP2()) return false; |
| 924 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 925 | EVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 926 | const Type *RetTy = I->getType(); |
Eric Christopher | 920a208 | 2010-09-10 00:35:09 +0000 | [diff] [blame] | 927 | if (!isTypeLegal(RetTy, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 928 | return false; |
| 929 | |
| 930 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 931 | if (Op == 0) return false; |
| 932 | |
| 933 | unsigned Opc; |
| 934 | const Type *OpTy = I->getOperand(0)->getType(); |
| 935 | if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS; |
| 936 | else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD; |
| 937 | else return 0; |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 938 | EVT OpVT = TLI.getValueType(OpTy, true); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 939 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 940 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(OpVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 941 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 942 | ResultReg) |
| 943 | .addReg(Op)); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 944 | |
| 945 | // This result needs to be in an integer register, but the conversion only |
| 946 | // takes place in fp-regs. |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 947 | unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 948 | if (IntReg == 0) return false; |
| 949 | |
| 950 | UpdateValueMap(I, IntReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 951 | return true; |
| 952 | } |
| 953 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 954 | bool ARMFastISel::SelectBinaryOp(const Instruction *I, unsigned ISDOpcode) { |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 955 | EVT VT = TLI.getValueType(I->getType(), true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 956 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 957 | // We can get here in the case when we want to use NEON for our fp |
| 958 | // operations, but can't figure out how to. Just use the vfp instructions |
| 959 | // if we have them. |
| 960 | // FIXME: It'd be nice to use NEON instructions. |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 961 | const Type *Ty = I->getType(); |
| 962 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 963 | if (isFloat && !Subtarget->hasVFP2()) |
| 964 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 965 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 966 | unsigned Op1 = getRegForValue(I->getOperand(0)); |
| 967 | if (Op1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 968 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 969 | unsigned Op2 = getRegForValue(I->getOperand(1)); |
| 970 | if (Op2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 971 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 972 | unsigned Opc; |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 973 | bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64 || |
| 974 | VT.getSimpleVT().SimpleTy == MVT::i64; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 975 | switch (ISDOpcode) { |
| 976 | default: return false; |
| 977 | case ISD::FADD: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 978 | Opc = is64bit ? ARM::VADDD : ARM::VADDS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 979 | break; |
| 980 | case ISD::FSUB: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 981 | Opc = is64bit ? ARM::VSUBD : ARM::VSUBS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 982 | break; |
| 983 | case ISD::FMUL: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 984 | Opc = is64bit ? ARM::VMULD : ARM::VMULS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 985 | break; |
| 986 | } |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 987 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 988 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 989 | TII.get(Opc), ResultReg) |
| 990 | .addReg(Op1).addReg(Op2)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 991 | UpdateValueMap(I, ResultReg); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 992 | return true; |
| 993 | } |
| 994 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 995 | // Call Handling Code |
| 996 | |
| 997 | // This is largely taken directly from CCAssignFnForNode - we don't support |
| 998 | // varargs in FastISel so that part has been removed. |
| 999 | // TODO: We may not support all of this. |
| 1000 | CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) { |
| 1001 | switch (CC) { |
| 1002 | default: |
| 1003 | llvm_unreachable("Unsupported calling convention"); |
| 1004 | case CallingConv::C: |
| 1005 | case CallingConv::Fast: |
| 1006 | // Use target triple & subtarget features to do actual dispatch. |
| 1007 | if (Subtarget->isAAPCS_ABI()) { |
| 1008 | if (Subtarget->hasVFP2() && |
| 1009 | FloatABIType == FloatABI::Hard) |
| 1010 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1011 | else |
| 1012 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1013 | } else |
| 1014 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1015 | case CallingConv::ARM_AAPCS_VFP: |
| 1016 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1017 | case CallingConv::ARM_AAPCS: |
| 1018 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1019 | case CallingConv::ARM_APCS: |
| 1020 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1021 | } |
| 1022 | } |
| 1023 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1024 | // A quick function that will emit a call for a named libcall in F with the |
| 1025 | // vector of passed arguments for the Instruction in I. We can assume that we |
| 1026 | // can emit a call for any libcall we can produce. This is an abridged version |
| 1027 | // of the full call infrastructure since we won't need to worry about things |
| 1028 | // like computed function pointers or strange arguments at call sites. |
| 1029 | // TODO: Try to unify this and the normal call bits for ARM, then try to unify |
| 1030 | // with X86. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1031 | bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) { |
| 1032 | CallingConv::ID CC = TLI.getLibcallCallingConv(Call); |
| 1033 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1034 | // Handle *simple* calls for now. |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1035 | const Type *RetTy = I->getType(); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1036 | EVT RetVT; |
| 1037 | if (RetTy->isVoidTy()) |
| 1038 | RetVT = MVT::isVoid; |
| 1039 | else if (!isTypeLegal(RetTy, RetVT)) |
| 1040 | return false; |
| 1041 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1042 | // For now we're using BLX etc on the assumption that we have v5t ops. |
| 1043 | if (!Subtarget->hasV5TOps()) return false; |
| 1044 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1045 | // Abridged from the X86 FastISel call selection mechanism |
| 1046 | SmallVector<Value*, 8> Args; |
| 1047 | SmallVector<unsigned, 8> ArgRegs; |
| 1048 | SmallVector<EVT, 8> ArgVTs; |
| 1049 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 1050 | Args.reserve(I->getNumOperands()); |
| 1051 | ArgRegs.reserve(I->getNumOperands()); |
| 1052 | ArgVTs.reserve(I->getNumOperands()); |
| 1053 | ArgFlags.reserve(I->getNumOperands()); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1054 | for (unsigned i = 0; i < I->getNumOperands(); ++i) { |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1055 | Value *Op = I->getOperand(i); |
| 1056 | unsigned Arg = getRegForValue(Op); |
| 1057 | if (Arg == 0) return false; |
| 1058 | |
| 1059 | const Type *ArgTy = Op->getType(); |
| 1060 | EVT ArgVT; |
| 1061 | if (!isTypeLegal(ArgTy, ArgVT)) return false; |
| 1062 | |
| 1063 | ISD::ArgFlagsTy Flags; |
| 1064 | unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy); |
| 1065 | Flags.setOrigAlign(OriginalAlignment); |
| 1066 | |
| 1067 | Args.push_back(Op); |
| 1068 | ArgRegs.push_back(Arg); |
| 1069 | ArgVTs.push_back(ArgVT); |
| 1070 | ArgFlags.push_back(Flags); |
| 1071 | } |
| 1072 | |
| 1073 | SmallVector<CCValAssign, 16> ArgLocs; |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1074 | CCState CCInfo(CC, false, TM, ArgLocs, |
| 1075 | I->getParent()->getParent()->getContext()); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1076 | CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC, false)); |
| 1077 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1078 | // Get a count of how many bytes are to be pushed on the stack. |
| 1079 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| 1080 | |
| 1081 | // Issue CALLSEQ_START |
| 1082 | unsigned AdjStackDown = TM.getRegisterInfo()->getCallFrameSetupOpcode(); |
| 1083 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(AdjStackDown)) |
| 1084 | .addImm(NumBytes); |
| 1085 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1086 | // Process the args. |
| 1087 | SmallVector<unsigned, 4> RegArgs; |
| 1088 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1089 | CCValAssign &VA = ArgLocs[i]; |
| 1090 | unsigned Arg = ArgRegs[VA.getValNo()]; |
| 1091 | EVT ArgVT = ArgVTs[VA.getValNo()]; |
| 1092 | |
| 1093 | // Should we ever have to promote? |
| 1094 | switch (VA.getLocInfo()) { |
| 1095 | case CCValAssign::Full: break; |
| 1096 | default: |
| 1097 | assert(false && "Handle arg promotion for libcalls?"); |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | // Now copy/store arg to correct locations. |
| 1102 | if (VA.isRegLoc()) { |
| 1103 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1104 | VA.getLocReg()) |
| 1105 | .addReg(Arg); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1106 | RegArgs.push_back(VA.getLocReg()); |
| 1107 | } else { |
| 1108 | // Need to store |
| 1109 | return false; |
| 1110 | } |
| 1111 | } |
| 1112 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1113 | // Issue the call, BLXr9 for darwin, BLX otherwise. This uses V5 ops. |
| 1114 | // TODO: Turn this into the table of arm call ops. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1115 | MachineInstrBuilder MIB; |
Eric Christopher | c109556 | 2010-09-18 02:32:38 +0000 | [diff] [blame] | 1116 | unsigned CallOpc; |
| 1117 | if(isThumb) |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1118 | CallOpc = Subtarget->isTargetDarwin() ? ARM::tBLXi_r9 : ARM::tBLXi; |
Eric Christopher | c109556 | 2010-09-18 02:32:38 +0000 | [diff] [blame] | 1119 | else |
| 1120 | CallOpc = Subtarget->isTargetDarwin() ? ARM::BLr9 : ARM::BL; |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1121 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CallOpc)) |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1122 | .addExternalSymbol(TLI.getLibcallName(Call)); |
| 1123 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1124 | // Add implicit physical register uses to the call. |
| 1125 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
| 1126 | MIB.addReg(RegArgs[i]); |
| 1127 | |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1128 | // Issue CALLSEQ_END |
| 1129 | unsigned AdjStackUp = TM.getRegisterInfo()->getCallFrameDestroyOpcode(); |
| 1130 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(AdjStackUp)) |
| 1131 | .addImm(NumBytes).addImm(0); |
| 1132 | |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1133 | // Now the return value. |
| 1134 | SmallVector<unsigned, 4> UsedRegs; |
| 1135 | if (RetVT.getSimpleVT().SimpleTy != MVT::isVoid) { |
| 1136 | SmallVector<CCValAssign, 16> RVLocs; |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1137 | CCState CCInfo(CC, false, TM, RVLocs, |
| 1138 | I->getParent()->getParent()->getContext()); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1139 | CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true)); |
| 1140 | |
| 1141 | // Copy all of the result registers out of their specified physreg. |
| 1142 | assert(RVLocs.size() == 1 && "Can't handle multi-value calls!"); |
| 1143 | EVT CopyVT = RVLocs[0].getValVT(); |
| 1144 | TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT); |
| 1145 | |
| 1146 | unsigned ResultReg = createResultReg(DstRC); |
| 1147 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), |
| 1148 | ResultReg).addReg(RVLocs[0].getLocReg()); |
| 1149 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
| 1150 | |
| 1151 | // Finally update the result. |
| 1152 | UpdateValueMap(I, ResultReg); |
| 1153 | } |
| 1154 | |
| 1155 | // Set all unused physreg defs as dead. |
| 1156 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1157 | return true; |
| 1158 | } |
| 1159 | |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1160 | bool ARMFastISel::SelectSDiv(const Instruction *I) { |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1161 | EVT VT; |
| 1162 | const Type *Ty = I->getType(); |
| 1163 | if (!isTypeLegal(Ty, VT)) |
| 1164 | return false; |
Eric Christopher | 1127c72 | 2010-09-27 06:08:12 +0000 | [diff] [blame] | 1165 | |
| 1166 | // If we have integer div support we should have selected this automagically. |
| 1167 | // In case we have a real miss go ahead and return false and we'll pick |
| 1168 | // it up later. |
| 1169 | if (Subtarget->hasDivide()) return false; |
| 1170 | |
| 1171 | // Otherwise emit a libcall. |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1172 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 1173 | if (VT == MVT::i16) |
| 1174 | LC = RTLIB::SDIV_I16; |
| 1175 | else if (VT == MVT::i32) |
| 1176 | LC = RTLIB::SDIV_I32; |
| 1177 | else if (VT == MVT::i64) |
| 1178 | LC = RTLIB::SDIV_I64; |
| 1179 | else if (VT == MVT::i128) |
| 1180 | LC = RTLIB::SDIV_I128; |
| 1181 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!"); |
Eric Christopher | 7ed8ec9 | 2010-09-28 01:21:42 +0000 | [diff] [blame^] | 1182 | |
| 1183 | return ARMEmitLibcall(I, LC); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1186 | // TODO: SoftFP support. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1187 | bool ARMFastISel::TargetSelectInstruction(const Instruction *I) { |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 1188 | // No Thumb-1 for now. |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 1189 | if (isThumb && !AFI->isThumb2Function()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1190 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1191 | switch (I->getOpcode()) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 1192 | case Instruction::Load: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1193 | return SelectLoad(I); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 1194 | case Instruction::Store: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1195 | return SelectStore(I); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1196 | case Instruction::Br: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1197 | return SelectBranch(I); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1198 | case Instruction::ICmp: |
| 1199 | case Instruction::FCmp: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1200 | return SelectCmp(I); |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1201 | case Instruction::FPExt: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1202 | return SelectFPExt(I); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1203 | case Instruction::FPTrunc: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1204 | return SelectFPTrunc(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1205 | case Instruction::SIToFP: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1206 | return SelectSIToFP(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1207 | case Instruction::FPToSI: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1208 | return SelectFPToSI(I); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1209 | case Instruction::FAdd: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1210 | return SelectBinaryOp(I, ISD::FADD); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1211 | case Instruction::FSub: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1212 | return SelectBinaryOp(I, ISD::FSUB); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1213 | case Instruction::FMul: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1214 | return SelectBinaryOp(I, ISD::FMUL); |
Eric Christopher | bb3e5da | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 1215 | case Instruction::SDiv: |
Eric Christopher | 43b62be | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1216 | return SelectSDiv(I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1217 | default: break; |
| 1218 | } |
| 1219 | return false; |
| 1220 | } |
| 1221 | |
| 1222 | namespace llvm { |
| 1223 | llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) { |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 1224 | if (EnableARMFastISel) return new ARMFastISel(funcInfo); |
Evan Cheng | 0944795 | 2010-07-26 18:32:55 +0000 | [diff] [blame] | 1225 | return 0; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1226 | } |
| 1227 | } |