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