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" |
| 27 | #include "llvm/CodeGen/Analysis.h" |
| 28 | #include "llvm/CodeGen/FastISel.h" |
| 29 | #include "llvm/CodeGen/FunctionLoweringInfo.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 31 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 33 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 34 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 35 | #include "llvm/Support/CallSite.h" |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 36 | #include "llvm/Support/CommandLine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 37 | #include "llvm/Support/ErrorHandling.h" |
| 38 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 39 | #include "llvm/Target/TargetData.h" |
| 40 | #include "llvm/Target/TargetInstrInfo.h" |
| 41 | #include "llvm/Target/TargetLowering.h" |
| 42 | #include "llvm/Target/TargetMachine.h" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 43 | #include "llvm/Target/TargetOptions.h" |
| 44 | using namespace llvm; |
| 45 | |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 46 | static cl::opt<bool> |
| 47 | EnableARMFastISel("arm-fast-isel", |
| 48 | cl::desc("Turn on experimental ARM fast-isel support"), |
| 49 | cl::init(false), cl::Hidden); |
| 50 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 51 | namespace { |
| 52 | |
| 53 | class ARMFastISel : public FastISel { |
| 54 | |
| 55 | /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can |
| 56 | /// make the right decision when generating code for different targets. |
| 57 | const ARMSubtarget *Subtarget; |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 58 | const TargetMachine &TM; |
| 59 | const TargetInstrInfo &TII; |
| 60 | const TargetLowering &TLI; |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 61 | const ARMFunctionInfo *AFI; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 62 | |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 63 | // Convenience variable to avoid checking all the time. |
| 64 | bool isThumb; |
| 65 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 66 | public: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 67 | explicit ARMFastISel(FunctionLoweringInfo &funcInfo) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 68 | : FastISel(funcInfo), |
| 69 | TM(funcInfo.MF->getTarget()), |
| 70 | TII(*TM.getInstrInfo()), |
| 71 | TLI(*TM.getTargetLowering()) { |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 72 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 73 | AFI = funcInfo.MF->getInfo<ARMFunctionInfo>(); |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 74 | isThumb = AFI->isThumbFunction(); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 77 | // Code from FastISel.cpp. |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 78 | virtual unsigned FastEmitInst_(unsigned MachineInstOpcode, |
| 79 | const TargetRegisterClass *RC); |
| 80 | virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode, |
| 81 | const TargetRegisterClass *RC, |
| 82 | unsigned Op0, bool Op0IsKill); |
| 83 | virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode, |
| 84 | const TargetRegisterClass *RC, |
| 85 | unsigned Op0, bool Op0IsKill, |
| 86 | unsigned Op1, bool Op1IsKill); |
| 87 | virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode, |
| 88 | const TargetRegisterClass *RC, |
| 89 | unsigned Op0, bool Op0IsKill, |
| 90 | uint64_t Imm); |
| 91 | virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode, |
| 92 | const TargetRegisterClass *RC, |
| 93 | unsigned Op0, bool Op0IsKill, |
| 94 | const ConstantFP *FPImm); |
| 95 | virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode, |
| 96 | const TargetRegisterClass *RC, |
| 97 | uint64_t Imm); |
| 98 | virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode, |
| 99 | const TargetRegisterClass *RC, |
| 100 | unsigned Op0, bool Op0IsKill, |
| 101 | unsigned Op1, bool Op1IsKill, |
| 102 | uint64_t Imm); |
| 103 | virtual unsigned FastEmitInst_extractsubreg(MVT RetVT, |
| 104 | unsigned Op0, bool Op0IsKill, |
| 105 | uint32_t Idx); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 106 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 107 | // Backend specific FastISel code. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 108 | virtual bool TargetSelectInstruction(const Instruction *I); |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 109 | virtual unsigned TargetMaterializeConstant(const Constant *C); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 110 | |
| 111 | #include "ARMGenFastISel.inc" |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 112 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 113 | // Instruction selection routines. |
Eric Christopher | 44bff90 | 2010-09-10 23:10:30 +0000 | [diff] [blame] | 114 | private: |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 115 | virtual bool ARMSelectLoad(const Instruction *I); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 116 | virtual bool ARMSelectStore(const Instruction *I); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 117 | virtual bool ARMSelectBranch(const Instruction *I); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 118 | virtual bool ARMSelectCmp(const Instruction *I); |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 119 | virtual bool ARMSelectFPExt(const Instruction *I); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 120 | virtual bool ARMSelectFPTrunc(const Instruction *I); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 121 | virtual bool ARMSelectBinaryOp(const Instruction *I, unsigned ISDOpcode); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 122 | virtual bool ARMSelectSIToFP(const Instruction *I); |
| 123 | virtual bool ARMSelectFPToSI(const Instruction *I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 124 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 125 | // Utility routines. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 126 | private: |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 127 | bool isTypeLegal(const Type *Ty, EVT &VT); |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 128 | bool isLoadTypeLegal(const Type *Ty, EVT &VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 129 | bool ARMEmitLoad(EVT VT, unsigned &ResultReg, unsigned Reg, int Offset); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 130 | bool ARMEmitStore(EVT VT, unsigned SrcReg, unsigned Reg, int Offset); |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 131 | bool ARMLoadAlloca(const Instruction *I, EVT VT); |
| 132 | bool ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT); |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 133 | bool ARMComputeRegOffset(const Value *Obj, unsigned &Reg, int &Offset); |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 134 | unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT); |
| 135 | unsigned ARMMaterializeInt(const Constant *C); |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 136 | unsigned ARMMoveToFPReg(EVT VT, unsigned SrcReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 137 | unsigned ARMMoveToIntReg(EVT VT, unsigned SrcReg); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 138 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame^] | 139 | // Call handling routines. |
| 140 | private: |
| 141 | CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool Return); |
| 142 | |
| 143 | // OptionalDef handling routines. |
| 144 | private: |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 145 | bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR); |
| 146 | const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB); |
| 147 | }; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 148 | |
| 149 | } // end anonymous namespace |
| 150 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame^] | 151 | #include "ARMGenCallingConv.inc" |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 152 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 153 | // DefinesOptionalPredicate - This is different from DefinesPredicate in that |
| 154 | // we don't care about implicit defs here, just places we'll need to add a |
| 155 | // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR. |
| 156 | bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) { |
| 157 | const TargetInstrDesc &TID = MI->getDesc(); |
| 158 | if (!TID.hasOptionalDef()) |
| 159 | return false; |
| 160 | |
| 161 | // Look to see if our OptionalDef is defining CPSR or CCR. |
| 162 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 163 | const MachineOperand &MO = MI->getOperand(i); |
Eric Christopher | f762fbe | 2010-08-20 00:36:24 +0000 | [diff] [blame] | 164 | if (!MO.isReg() || !MO.isDef()) continue; |
| 165 | if (MO.getReg() == ARM::CPSR) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 166 | *CPSR = true; |
| 167 | } |
| 168 | return true; |
| 169 | } |
| 170 | |
| 171 | // If the machine is predicable go ahead and add the predicate operands, if |
| 172 | // it needs default CC operands add those. |
| 173 | const MachineInstrBuilder & |
| 174 | ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) { |
| 175 | MachineInstr *MI = &*MIB; |
| 176 | |
| 177 | // Do we use a predicate? |
| 178 | if (TII.isPredicable(MI)) |
| 179 | AddDefaultPred(MIB); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 180 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 181 | // Do we optionally set a predicate? Preds is size > 0 iff the predicate |
| 182 | // defines CPSR. All other OptionalDefines in ARM are the CCR register. |
Eric Christopher | 979e0a1 | 2010-08-19 15:35:27 +0000 | [diff] [blame] | 183 | bool CPSR = false; |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 184 | if (DefinesOptionalPredicate(MI, &CPSR)) { |
| 185 | if (CPSR) |
| 186 | AddDefaultT1CC(MIB); |
| 187 | else |
| 188 | AddDefaultCC(MIB); |
| 189 | } |
| 190 | return MIB; |
| 191 | } |
| 192 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 193 | unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode, |
| 194 | const TargetRegisterClass* RC) { |
| 195 | unsigned ResultReg = createResultReg(RC); |
| 196 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 197 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 198 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 199 | return ResultReg; |
| 200 | } |
| 201 | |
| 202 | unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode, |
| 203 | const TargetRegisterClass *RC, |
| 204 | unsigned Op0, bool Op0IsKill) { |
| 205 | unsigned ResultReg = createResultReg(RC); |
| 206 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 207 | |
| 208 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 209 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 210 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
| 211 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 212 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 213 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 214 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 215 | TII.get(TargetOpcode::COPY), ResultReg) |
| 216 | .addReg(II.ImplicitDefs[0])); |
| 217 | } |
| 218 | return ResultReg; |
| 219 | } |
| 220 | |
| 221 | unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode, |
| 222 | const TargetRegisterClass *RC, |
| 223 | unsigned Op0, bool Op0IsKill, |
| 224 | unsigned Op1, bool Op1IsKill) { |
| 225 | unsigned ResultReg = createResultReg(RC); |
| 226 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 227 | |
| 228 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 229 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 230 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 231 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
| 232 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 233 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 234 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 235 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 236 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 237 | TII.get(TargetOpcode::COPY), ResultReg) |
| 238 | .addReg(II.ImplicitDefs[0])); |
| 239 | } |
| 240 | return ResultReg; |
| 241 | } |
| 242 | |
| 243 | unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode, |
| 244 | const TargetRegisterClass *RC, |
| 245 | unsigned Op0, bool Op0IsKill, |
| 246 | uint64_t Imm) { |
| 247 | unsigned ResultReg = createResultReg(RC); |
| 248 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 249 | |
| 250 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 251 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 252 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 253 | .addImm(Imm)); |
| 254 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 255 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 256 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 257 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 258 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 259 | TII.get(TargetOpcode::COPY), ResultReg) |
| 260 | .addReg(II.ImplicitDefs[0])); |
| 261 | } |
| 262 | return ResultReg; |
| 263 | } |
| 264 | |
| 265 | unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode, |
| 266 | const TargetRegisterClass *RC, |
| 267 | unsigned Op0, bool Op0IsKill, |
| 268 | const ConstantFP *FPImm) { |
| 269 | unsigned ResultReg = createResultReg(RC); |
| 270 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 271 | |
| 272 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 273 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 274 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 275 | .addFPImm(FPImm)); |
| 276 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 277 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 278 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 279 | .addFPImm(FPImm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 280 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 281 | TII.get(TargetOpcode::COPY), ResultReg) |
| 282 | .addReg(II.ImplicitDefs[0])); |
| 283 | } |
| 284 | return ResultReg; |
| 285 | } |
| 286 | |
| 287 | unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode, |
| 288 | const TargetRegisterClass *RC, |
| 289 | unsigned Op0, bool Op0IsKill, |
| 290 | unsigned Op1, bool Op1IsKill, |
| 291 | uint64_t Imm) { |
| 292 | unsigned ResultReg = createResultReg(RC); |
| 293 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 294 | |
| 295 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 296 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 297 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 298 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 299 | .addImm(Imm)); |
| 300 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 301 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 302 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 303 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 304 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 305 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 306 | TII.get(TargetOpcode::COPY), ResultReg) |
| 307 | .addReg(II.ImplicitDefs[0])); |
| 308 | } |
| 309 | return ResultReg; |
| 310 | } |
| 311 | |
| 312 | unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode, |
| 313 | const TargetRegisterClass *RC, |
| 314 | uint64_t Imm) { |
| 315 | unsigned ResultReg = createResultReg(RC); |
| 316 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 317 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 318 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 319 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 320 | .addImm(Imm)); |
| 321 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 322 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 323 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 324 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 325 | TII.get(TargetOpcode::COPY), ResultReg) |
| 326 | .addReg(II.ImplicitDefs[0])); |
| 327 | } |
| 328 | return ResultReg; |
| 329 | } |
| 330 | |
| 331 | unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT, |
| 332 | unsigned Op0, bool Op0IsKill, |
| 333 | uint32_t Idx) { |
| 334 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT)); |
| 335 | assert(TargetRegisterInfo::isVirtualRegister(Op0) && |
| 336 | "Cannot yet extract from physregs"); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 337 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 338 | DL, TII.get(TargetOpcode::COPY), ResultReg) |
| 339 | .addReg(Op0, getKillRegState(Op0IsKill), Idx)); |
| 340 | return ResultReg; |
| 341 | } |
| 342 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 343 | // TODO: Don't worry about 64-bit now, but when this is fixed remove the |
| 344 | // checks from the various callers. |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 345 | unsigned ARMFastISel::ARMMoveToFPReg(EVT VT, unsigned SrcReg) { |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 346 | if (VT.getSimpleVT().SimpleTy == MVT::f64) return 0; |
| 347 | |
| 348 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 349 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 350 | TII.get(ARM::VMOVRS), MoveReg) |
| 351 | .addReg(SrcReg)); |
| 352 | return MoveReg; |
| 353 | } |
| 354 | |
| 355 | unsigned ARMFastISel::ARMMoveToIntReg(EVT VT, unsigned SrcReg) { |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 356 | if (VT.getSimpleVT().SimpleTy == MVT::i64) return 0; |
| 357 | |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 358 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
| 359 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 360 | TII.get(ARM::VMOVSR), MoveReg) |
Eric Christopher | aa3ace1 | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 361 | .addReg(SrcReg)); |
| 362 | return MoveReg; |
| 363 | } |
| 364 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 365 | // For double width floating point we need to materialize two constants |
| 366 | // (the high and the low) into integer registers then use a move to get |
| 367 | // the combined constant into an FP reg. |
| 368 | unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, EVT VT) { |
| 369 | const APFloat Val = CFP->getValueAPF(); |
| 370 | bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 371 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 372 | // This checks to see if we can use VFP3 instructions to materialize |
| 373 | // a constant, otherwise we have to go through the constant pool. |
| 374 | if (TLI.isFPImmLegal(Val, VT)) { |
| 375 | unsigned Opc = is64bit ? ARM::FCONSTD : ARM::FCONSTS; |
| 376 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 377 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 378 | DestReg) |
| 379 | .addFPImm(CFP)); |
| 380 | return DestReg; |
| 381 | } |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 382 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 383 | // Require VFP2 for loading fp constants. |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 384 | if (!Subtarget->hasVFP2()) return false; |
| 385 | |
| 386 | // MachineConstantPool wants an explicit alignment. |
| 387 | unsigned Align = TD.getPrefTypeAlignment(CFP->getType()); |
| 388 | if (Align == 0) { |
| 389 | // TODO: Figure out if this is correct. |
| 390 | Align = TD.getTypeAllocSize(CFP->getType()); |
| 391 | } |
| 392 | unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align); |
| 393 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 394 | unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS; |
| 395 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 396 | // The extra reg is for addrmode5. |
Eric Christopher | 238bb16 | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 397 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc)) |
| 398 | .addReg(DestReg).addConstantPoolIndex(Idx) |
| 399 | .addReg(0)); |
| 400 | return DestReg; |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 403 | // TODO: Verify 64-bit. |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 404 | unsigned ARMFastISel::ARMMaterializeInt(const Constant *C) { |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 405 | // MachineConstantPool wants an explicit alignment. |
| 406 | unsigned Align = TD.getPrefTypeAlignment(C->getType()); |
| 407 | if (Align == 0) { |
| 408 | // TODO: Figure out if this is correct. |
| 409 | Align = TD.getTypeAllocSize(C->getType()); |
| 410 | } |
| 411 | unsigned Idx = MCP.getConstantPoolIndex(C, Align); |
Eric Christopher | 845c575 | 2010-09-08 18:56:34 +0000 | [diff] [blame] | 412 | unsigned DestReg = createResultReg(TLI.getRegClassFor(MVT::i32)); |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 413 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 414 | if (isThumb) |
| 415 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 416 | TII.get(ARM::t2LDRpci)) |
| 417 | .addReg(DestReg).addConstantPoolIndex(Idx)); |
| 418 | else |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 419 | // The extra reg and immediate are for addrmode2. |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 420 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 421 | TII.get(ARM::LDRcp)) |
Eric Christopher | 845c575 | 2010-09-08 18:56:34 +0000 | [diff] [blame] | 422 | .addReg(DestReg).addConstantPoolIndex(Idx) |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 423 | .addReg(0).addImm(0)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 424 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 425 | return DestReg; |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Eric Christopher | 9ed58df | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 428 | unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) { |
| 429 | EVT VT = TLI.getValueType(C->getType(), true); |
| 430 | |
| 431 | // Only handle simple types. |
| 432 | if (!VT.isSimple()) return 0; |
| 433 | |
| 434 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) |
| 435 | return ARMMaterializeFP(CFP, VT); |
| 436 | return ARMMaterializeInt(C); |
| 437 | } |
| 438 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 439 | bool ARMFastISel::isTypeLegal(const Type *Ty, EVT &VT) { |
| 440 | VT = TLI.getValueType(Ty, true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 441 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 442 | // Only handle simple types. |
| 443 | if (VT == MVT::Other || !VT.isSimple()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 444 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 445 | // Handle all legal types, i.e. a register that will directly hold this |
| 446 | // value. |
| 447 | return TLI.isTypeLegal(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 450 | bool ARMFastISel::isLoadTypeLegal(const Type *Ty, EVT &VT) { |
| 451 | if (isTypeLegal(Ty, VT)) return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 452 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 453 | // If this is a type than can be sign or zero-extended to a basic operation |
| 454 | // go ahead and accept it now. |
| 455 | if (VT == MVT::i8 || VT == MVT::i16) |
| 456 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 457 | |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 458 | return false; |
| 459 | } |
| 460 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 461 | // Computes the Reg+Offset to get to an object. |
| 462 | bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg, |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 463 | int &Offset) { |
| 464 | // Some boilerplate from the X86 FastISel. |
| 465 | const User *U = NULL; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 466 | unsigned Opcode = Instruction::UserOp1; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 467 | if (const Instruction *I = dyn_cast<Instruction>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 468 | // Don't walk into other basic blocks; it's possible we haven't |
| 469 | // visited them yet, so the instructions may not yet be assigned |
| 470 | // virtual registers. |
| 471 | if (FuncInfo.MBBMap[I->getParent()] != FuncInfo.MBB) |
| 472 | return false; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 473 | Opcode = I->getOpcode(); |
| 474 | U = I; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 475 | } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 476 | Opcode = C->getOpcode(); |
| 477 | U = C; |
| 478 | } |
| 479 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 480 | if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType())) |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 481 | if (Ty->getAddressSpace() > 255) |
| 482 | // Fast instruction selection doesn't support the special |
| 483 | // address spaces. |
| 484 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 485 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 486 | switch (Opcode) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 487 | default: |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 488 | break; |
| 489 | case Instruction::Alloca: { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 490 | assert(false && "Alloca should have been handled earlier!"); |
| 491 | return false; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 492 | } |
| 493 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 494 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 495 | // FIXME: Handle global variables. |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 496 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 497 | (void)GV; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 498 | return false; |
| 499 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 500 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 501 | // Try to get this in a register if nothing else has worked. |
| 502 | Reg = getRegForValue(Obj); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 503 | if (Reg == 0) return false; |
| 504 | |
| 505 | // Since the offset may be too large for the load instruction |
| 506 | // get the reg+offset into a register. |
| 507 | // TODO: Verify the additions work, otherwise we'll need to add the |
| 508 | // offset instead of 0 to the instructions and do all sorts of operand |
| 509 | // munging. |
| 510 | // TODO: Optimize this somewhat. |
| 511 | if (Offset != 0) { |
| 512 | ARMCC::CondCodes Pred = ARMCC::AL; |
| 513 | unsigned PredReg = 0; |
| 514 | |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 515 | if (!isThumb) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 516 | emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 517 | Reg, Reg, Offset, Pred, PredReg, |
| 518 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 519 | else { |
| 520 | assert(AFI->isThumb2Function()); |
| 521 | emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 522 | Reg, Reg, Offset, Pred, PredReg, |
| 523 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 524 | } |
| 525 | } |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 526 | return true; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 529 | bool ARMFastISel::ARMLoadAlloca(const Instruction *I, EVT VT) { |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 530 | Value *Op0 = I->getOperand(0); |
| 531 | |
| 532 | // Verify it's an alloca. |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 533 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op0)) { |
| 534 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 535 | FuncInfo.StaticAllocaMap.find(AI); |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 536 | |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 537 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 538 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 539 | unsigned ResultReg = createResultReg(RC); |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 540 | TII.loadRegFromStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt, |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 541 | ResultReg, SI->second, RC, |
Eric Christopher | e24d66f | 2010-08-24 22:07:27 +0000 | [diff] [blame] | 542 | TM.getRegisterInfo()); |
| 543 | UpdateValueMap(I, ResultReg); |
| 544 | return true; |
| 545 | } |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 546 | } |
Eric Christopher | f06f309 | 2010-08-24 00:50:47 +0000 | [diff] [blame] | 547 | return false; |
| 548 | } |
| 549 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 550 | bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg, |
| 551 | unsigned Reg, int Offset) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 552 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 553 | assert(VT.isSimple() && "Non-simple types are invalid here!"); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 554 | unsigned Opc; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 555 | |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 556 | switch (VT.getSimpleVT().SimpleTy) { |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 557 | default: |
Eric Christopher | 548d1bb | 2010-08-30 23:48:26 +0000 | [diff] [blame] | 558 | assert(false && "Trying to emit for an unhandled type!"); |
| 559 | return false; |
Eric Christopher | 4e68c7c | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 560 | case MVT::i16: |
| 561 | Opc = isThumb ? ARM::tLDRH : ARM::LDRH; |
| 562 | VT = MVT::i32; |
| 563 | break; |
| 564 | case MVT::i8: |
| 565 | Opc = isThumb ? ARM::tLDRB : ARM::LDRB; |
| 566 | VT = MVT::i32; |
| 567 | break; |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 568 | case MVT::i32: |
| 569 | Opc = isThumb ? ARM::tLDR : ARM::LDR; |
| 570 | break; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 571 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 572 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 573 | ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 574 | |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 575 | // TODO: Fix the Addressing modes so that these can share some code. |
| 576 | // Since this is a Thumb1 load this will work in Thumb1 or 2 mode. |
| 577 | if (isThumb) |
| 578 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 579 | TII.get(Opc), ResultReg) |
| 580 | .addReg(Reg).addImm(Offset).addReg(0)); |
| 581 | else |
| 582 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 583 | TII.get(Opc), ResultReg) |
| 584 | .addReg(Reg).addReg(0).addImm(Offset)); |
Eric Christopher | dc90804 | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 585 | return true; |
Eric Christopher | b1cc848 | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 588 | bool ARMFastISel::ARMSelectLoad(const Instruction *I) { |
| 589 | // Verify we have a legal type before going any further. |
| 590 | EVT VT; |
| 591 | if (!isLoadTypeLegal(I->getType(), VT)) |
| 592 | return false; |
| 593 | |
| 594 | // If we're an alloca we know we have a frame index and can emit the load |
| 595 | // directly in short order. |
| 596 | if (ARMLoadAlloca(I, VT)) |
| 597 | return true; |
| 598 | |
| 599 | // Our register and offset with innocuous defaults. |
| 600 | unsigned Reg = 0; |
| 601 | int Offset = 0; |
| 602 | |
| 603 | // See if we can handle this as Reg + Offset |
| 604 | if (!ARMComputeRegOffset(I->getOperand(0), Reg, Offset)) |
| 605 | return false; |
| 606 | |
| 607 | unsigned ResultReg; |
| 608 | if (!ARMEmitLoad(VT, ResultReg, Reg, Offset /* 0 */)) return false; |
| 609 | |
| 610 | UpdateValueMap(I, ResultReg); |
| 611 | return true; |
| 612 | } |
| 613 | |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 614 | bool ARMFastISel::ARMStoreAlloca(const Instruction *I, unsigned SrcReg, EVT VT){ |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 615 | Value *Op1 = I->getOperand(1); |
| 616 | |
| 617 | // Verify it's an alloca. |
| 618 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Op1)) { |
| 619 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 620 | FuncInfo.StaticAllocaMap.find(AI); |
| 621 | |
| 622 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 623 | TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 624 | assert(SrcReg != 0 && "Nothing to store!"); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 625 | TII.storeRegToStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt, |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 626 | SrcReg, true /*isKill*/, SI->second, RC, |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 627 | TM.getRegisterInfo()); |
| 628 | return true; |
| 629 | } |
| 630 | } |
| 631 | return false; |
| 632 | } |
| 633 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 634 | bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg, |
| 635 | unsigned DstReg, int Offset) { |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 636 | unsigned StrOpc; |
| 637 | switch (VT.getSimpleVT().SimpleTy) { |
| 638 | default: return false; |
| 639 | case MVT::i1: |
| 640 | case MVT::i8: StrOpc = isThumb ? ARM::tSTRB : ARM::STRB; break; |
| 641 | case MVT::i16: StrOpc = isThumb ? ARM::tSTRH : ARM::STRH; break; |
| 642 | case MVT::i32: StrOpc = isThumb ? ARM::tSTR : ARM::STR; break; |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 643 | case MVT::f32: |
| 644 | if (!Subtarget->hasVFP2()) return false; |
| 645 | StrOpc = ARM::VSTRS; |
| 646 | break; |
| 647 | case MVT::f64: |
| 648 | if (!Subtarget->hasVFP2()) return false; |
| 649 | StrOpc = ARM::VSTRD; |
| 650 | break; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 651 | } |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 652 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 653 | if (isThumb) |
| 654 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 655 | TII.get(StrOpc), SrcReg) |
| 656 | .addReg(DstReg).addImm(Offset).addReg(0)); |
| 657 | else |
| 658 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 659 | TII.get(StrOpc), SrcReg) |
| 660 | .addReg(DstReg).addReg(0).addImm(Offset)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 661 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 662 | return true; |
| 663 | } |
| 664 | |
| 665 | bool ARMFastISel::ARMSelectStore(const Instruction *I) { |
| 666 | Value *Op0 = I->getOperand(0); |
| 667 | unsigned SrcReg = 0; |
| 668 | |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 669 | // Yay type legalization |
| 670 | EVT VT; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 671 | if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT)) |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 672 | return false; |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 673 | |
Eric Christopher | 1b61ef4 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 674 | // Get the value to be stored into a register. |
| 675 | SrcReg = getRegForValue(Op0); |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 676 | if (SrcReg == 0) |
| 677 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 678 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 679 | // If we're an alloca we know we have a frame index and can emit the store |
| 680 | // quickly. |
Eric Christopher | 30b6633 | 2010-09-08 21:49:50 +0000 | [diff] [blame] | 681 | if (ARMStoreAlloca(I, SrcReg, VT)) |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 682 | return true; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 683 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 684 | // Our register and offset with innocuous defaults. |
| 685 | unsigned Reg = 0; |
| 686 | int Offset = 0; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 687 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 688 | // See if we can handle this as Reg + Offset |
| 689 | if (!ARMComputeRegOffset(I->getOperand(1), Reg, Offset)) |
| 690 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 691 | |
Eric Christopher | 318b6ee | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 692 | if (!ARMEmitStore(VT, SrcReg, Reg, Offset /* 0 */)) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 693 | |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 694 | return false; |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 697 | bool ARMFastISel::ARMSelectBranch(const Instruction *I) { |
| 698 | const BranchInst *BI = cast<BranchInst>(I); |
| 699 | MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)]; |
| 700 | MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)]; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 701 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 702 | // Simple branch support. |
| 703 | unsigned CondReg = getRegForValue(BI->getCondition()); |
| 704 | if (CondReg == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 705 | |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 706 | unsigned CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr; |
| 707 | unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc; |
| 708 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 709 | .addReg(CondReg).addReg(CondReg)); |
| 710 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc)) |
| 711 | .addMBB(TBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 712 | FastEmitBranch(FBB, DL); |
| 713 | FuncInfo.MBB->addSuccessor(TBB); |
| 714 | return true; |
| 715 | } |
| 716 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 717 | bool ARMFastISel::ARMSelectCmp(const Instruction *I) { |
| 718 | const CmpInst *CI = cast<CmpInst>(I); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 719 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 720 | EVT VT; |
| 721 | const Type *Ty = CI->getOperand(0)->getType(); |
| 722 | if (!isTypeLegal(Ty, VT)) |
| 723 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 724 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 725 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 726 | if (isFloat && !Subtarget->hasVFP2()) |
| 727 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 728 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 729 | unsigned CmpOpc; |
| 730 | switch (VT.getSimpleVT().SimpleTy) { |
| 731 | default: return false; |
| 732 | // TODO: Verify compares. |
| 733 | case MVT::f32: |
| 734 | CmpOpc = ARM::VCMPES; |
| 735 | break; |
| 736 | case MVT::f64: |
| 737 | CmpOpc = ARM::VCMPED; |
| 738 | break; |
| 739 | case MVT::i32: |
| 740 | CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr; |
| 741 | break; |
| 742 | } |
| 743 | |
| 744 | unsigned Arg1 = getRegForValue(CI->getOperand(0)); |
| 745 | if (Arg1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 746 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 747 | unsigned Arg2 = getRegForValue(CI->getOperand(1)); |
| 748 | if (Arg2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 749 | |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 750 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc)) |
| 751 | .addReg(Arg1).addReg(Arg2)); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 752 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 753 | // For floating point we need to move the result to a comparison register |
| 754 | // that we can then use for branches. |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 755 | if (isFloat) |
| 756 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 757 | TII.get(ARM::FMSTAT))); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 758 | |
| 759 | // TODO: How to update the value map when there's no result reg? |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 760 | return true; |
| 761 | } |
| 762 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 763 | bool ARMFastISel::ARMSelectFPExt(const Instruction *I) { |
| 764 | // Make sure we have VFP and that we're extending float to double. |
| 765 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 766 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 767 | Value *V = I->getOperand(0); |
| 768 | if (!I->getType()->isDoubleTy() || |
| 769 | !V->getType()->isFloatTy()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 770 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 771 | unsigned Op = getRegForValue(V); |
| 772 | if (Op == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 773 | |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 774 | unsigned Result = createResultReg(ARM::DPRRegisterClass); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 775 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 776 | TII.get(ARM::VCVTDS), Result) |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 777 | .addReg(Op)); |
| 778 | UpdateValueMap(I, Result); |
| 779 | return true; |
| 780 | } |
| 781 | |
| 782 | bool ARMFastISel::ARMSelectFPTrunc(const Instruction *I) { |
| 783 | // Make sure we have VFP and that we're truncating double to float. |
| 784 | if (!Subtarget->hasVFP2()) return false; |
| 785 | |
| 786 | Value *V = I->getOperand(0); |
| 787 | if (!I->getType()->isFloatTy() || |
| 788 | !V->getType()->isDoubleTy()) return false; |
| 789 | |
| 790 | unsigned Op = getRegForValue(V); |
| 791 | if (Op == 0) return false; |
| 792 | |
| 793 | unsigned Result = createResultReg(ARM::SPRRegisterClass); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 794 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | ef2fdd2 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 795 | TII.get(ARM::VCVTSD), Result) |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 796 | .addReg(Op)); |
| 797 | UpdateValueMap(I, Result); |
| 798 | return true; |
| 799 | } |
| 800 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 801 | bool ARMFastISel::ARMSelectSIToFP(const Instruction *I) { |
| 802 | // Make sure we have VFP. |
| 803 | if (!Subtarget->hasVFP2()) return false; |
| 804 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 805 | EVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 806 | const Type *Ty = I->getType(); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 807 | if (!isTypeLegal(Ty, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 808 | return false; |
| 809 | |
| 810 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 811 | if (Op == 0) return false; |
| 812 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 813 | // The conversion routine works on fp-reg to fp-reg and the operand above |
| 814 | // was an integer, move it to the fp registers if possible. |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 815 | unsigned FP = ARMMoveToFPReg(DstVT, Op); |
| 816 | if (FP == 0) return false; |
| 817 | |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 818 | unsigned Opc; |
| 819 | if (Ty->isFloatTy()) Opc = ARM::VSITOS; |
| 820 | else if (Ty->isDoubleTy()) Opc = ARM::VSITOD; |
| 821 | else return 0; |
| 822 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 823 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 824 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 825 | ResultReg) |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 826 | .addReg(FP)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 827 | UpdateValueMap(I, ResultReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 828 | return true; |
| 829 | } |
| 830 | |
| 831 | bool ARMFastISel::ARMSelectFPToSI(const Instruction *I) { |
| 832 | // Make sure we have VFP. |
| 833 | if (!Subtarget->hasVFP2()) return false; |
| 834 | |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 835 | EVT DstVT; |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 836 | const Type *RetTy = I->getType(); |
Eric Christopher | 920a208 | 2010-09-10 00:35:09 +0000 | [diff] [blame] | 837 | if (!isTypeLegal(RetTy, DstVT)) |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 838 | return false; |
| 839 | |
| 840 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 841 | if (Op == 0) return false; |
| 842 | |
| 843 | unsigned Opc; |
| 844 | const Type *OpTy = I->getOperand(0)->getType(); |
| 845 | if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS; |
| 846 | else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD; |
| 847 | else return 0; |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 848 | EVT OpVT = TLI.getValueType(OpTy, true); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 849 | |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 850 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(OpVT)); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 851 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), |
| 852 | ResultReg) |
| 853 | .addReg(Op)); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 854 | |
| 855 | // This result needs to be in an integer register, but the conversion only |
| 856 | // takes place in fp-regs. |
Eric Christopher | db12b2b | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 857 | unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg); |
Eric Christopher | 9ee4ce2 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 858 | if (IntReg == 0) return false; |
| 859 | |
| 860 | UpdateValueMap(I, IntReg); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 861 | return true; |
| 862 | } |
| 863 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 864 | bool ARMFastISel::ARMSelectBinaryOp(const Instruction *I, unsigned ISDOpcode) { |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 865 | EVT VT = TLI.getValueType(I->getType(), true); |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 866 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 867 | // We can get here in the case when we want to use NEON for our fp |
| 868 | // operations, but can't figure out how to. Just use the vfp instructions |
| 869 | // if we have them. |
| 870 | // FIXME: It'd be nice to use NEON instructions. |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 871 | const Type *Ty = I->getType(); |
| 872 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 873 | if (isFloat && !Subtarget->hasVFP2()) |
| 874 | return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 875 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 876 | unsigned Op1 = getRegForValue(I->getOperand(0)); |
| 877 | if (Op1 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 878 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 879 | unsigned Op2 = getRegForValue(I->getOperand(1)); |
| 880 | if (Op2 == 0) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 881 | |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 882 | unsigned Opc; |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 883 | bool is64bit = VT.getSimpleVT().SimpleTy == MVT::f64 || |
| 884 | VT.getSimpleVT().SimpleTy == MVT::i64; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 885 | switch (ISDOpcode) { |
| 886 | default: return false; |
| 887 | case ISD::FADD: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 888 | Opc = is64bit ? ARM::VADDD : ARM::VADDS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 889 | break; |
| 890 | case ISD::FSUB: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 891 | Opc = is64bit ? ARM::VSUBD : ARM::VSUBS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 892 | break; |
| 893 | case ISD::FMUL: |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 894 | Opc = is64bit ? ARM::VMULD : ARM::VMULS; |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 895 | break; |
| 896 | } |
Eric Christopher | bd6bf08 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 897 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 898 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 899 | TII.get(Opc), ResultReg) |
| 900 | .addReg(Op1).addReg(Op2)); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 901 | UpdateValueMap(I, ResultReg); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 902 | return true; |
| 903 | } |
| 904 | |
Eric Christopher | d10cd7b | 2010-09-10 23:18:12 +0000 | [diff] [blame^] | 905 | // Call Handling Code |
| 906 | |
| 907 | // This is largely taken directly from CCAssignFnForNode - we don't support |
| 908 | // varargs in FastISel so that part has been removed. |
| 909 | // TODO: We may not support all of this. |
| 910 | CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) { |
| 911 | switch (CC) { |
| 912 | default: |
| 913 | llvm_unreachable("Unsupported calling convention"); |
| 914 | case CallingConv::C: |
| 915 | case CallingConv::Fast: |
| 916 | // Use target triple & subtarget features to do actual dispatch. |
| 917 | if (Subtarget->isAAPCS_ABI()) { |
| 918 | if (Subtarget->hasVFP2() && |
| 919 | FloatABIType == FloatABI::Hard) |
| 920 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 921 | else |
| 922 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 923 | } else |
| 924 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 925 | case CallingConv::ARM_AAPCS_VFP: |
| 926 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 927 | case CallingConv::ARM_AAPCS: |
| 928 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 929 | case CallingConv::ARM_APCS: |
| 930 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 931 | } |
| 932 | } |
| 933 | |
Eric Christopher | 56d2b72 | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 934 | // TODO: SoftFP support. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 935 | bool ARMFastISel::TargetSelectInstruction(const Instruction *I) { |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 936 | // No Thumb-1 for now. |
Eric Christopher | eaa204b | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 937 | if (isThumb && !AFI->isThumb2Function()) return false; |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 938 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 939 | switch (I->getOpcode()) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 940 | case Instruction::Load: |
| 941 | return ARMSelectLoad(I); |
Eric Christopher | 543cf05 | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 942 | case Instruction::Store: |
| 943 | return ARMSelectStore(I); |
Eric Christopher | e573410 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 944 | case Instruction::Br: |
| 945 | return ARMSelectBranch(I); |
Eric Christopher | d43393a | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 946 | case Instruction::ICmp: |
| 947 | case Instruction::FCmp: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 948 | return ARMSelectCmp(I); |
Eric Christopher | 4620360 | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 949 | case Instruction::FPExt: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 950 | return ARMSelectFPExt(I); |
Eric Christopher | ce07b54 | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 951 | case Instruction::FPTrunc: |
| 952 | return ARMSelectFPTrunc(I); |
Eric Christopher | 9a04049 | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 953 | case Instruction::SIToFP: |
| 954 | return ARMSelectSIToFP(I); |
| 955 | case Instruction::FPToSI: |
| 956 | return ARMSelectFPToSI(I); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 957 | case Instruction::FAdd: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 958 | return ARMSelectBinaryOp(I, ISD::FADD); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 959 | case Instruction::FSub: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 960 | return ARMSelectBinaryOp(I, ISD::FSUB); |
Eric Christopher | bc39b82 | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 961 | case Instruction::FMul: |
Eric Christopher | ac1a19e | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 962 | return ARMSelectBinaryOp(I, ISD::FMUL); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 963 | default: break; |
| 964 | } |
| 965 | return false; |
| 966 | } |
| 967 | |
| 968 | namespace llvm { |
| 969 | llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) { |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 970 | if (EnableARMFastISel) return new ARMFastISel(funcInfo); |
Evan Cheng | 0944795 | 2010-07-26 18:32:55 +0000 | [diff] [blame] | 971 | return 0; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 972 | } |
| 973 | } |