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