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