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