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