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 | |
| 62 | public: |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 63 | explicit ARMFastISel(FunctionLoweringInfo &funcInfo) |
| 64 | : FastISel(funcInfo), |
| 65 | TM(funcInfo.MF->getTarget()), |
| 66 | TII(*TM.getInstrInfo()), |
| 67 | TLI(*TM.getTargetLowering()) { |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 68 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 69 | AFI = funcInfo.MF->getInfo<ARMFunctionInfo>(); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 72 | // Code from FastISel.cpp. |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 73 | virtual unsigned FastEmitInst_(unsigned MachineInstOpcode, |
| 74 | const TargetRegisterClass *RC); |
| 75 | virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode, |
| 76 | const TargetRegisterClass *RC, |
| 77 | unsigned Op0, bool Op0IsKill); |
| 78 | virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode, |
| 79 | const TargetRegisterClass *RC, |
| 80 | unsigned Op0, bool Op0IsKill, |
| 81 | unsigned Op1, bool Op1IsKill); |
| 82 | virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode, |
| 83 | const TargetRegisterClass *RC, |
| 84 | unsigned Op0, bool Op0IsKill, |
| 85 | uint64_t Imm); |
| 86 | virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode, |
| 87 | const TargetRegisterClass *RC, |
| 88 | unsigned Op0, bool Op0IsKill, |
| 89 | const ConstantFP *FPImm); |
| 90 | virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode, |
| 91 | const TargetRegisterClass *RC, |
| 92 | uint64_t Imm); |
| 93 | virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode, |
| 94 | const TargetRegisterClass *RC, |
| 95 | unsigned Op0, bool Op0IsKill, |
| 96 | unsigned Op1, bool Op1IsKill, |
| 97 | uint64_t Imm); |
| 98 | virtual unsigned FastEmitInst_extractsubreg(MVT RetVT, |
| 99 | unsigned Op0, bool Op0IsKill, |
| 100 | uint32_t Idx); |
Eric Christopher | cb59229 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 101 | |
| 102 | // Backend specific FastISel code. |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 103 | virtual bool TargetSelectInstruction(const Instruction *I); |
| 104 | |
| 105 | #include "ARMGenFastISel.inc" |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 106 | |
| 107 | // Instruction selection routines. |
| 108 | virtual bool ARMSelectLoad(const Instruction *I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 109 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 110 | // Utility routines. |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 111 | private: |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 112 | bool ARMComputeRegOffset(const Value *Obj, unsigned &Reg, int &Offset); |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 113 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 114 | bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR); |
| 115 | const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB); |
| 116 | }; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 117 | |
| 118 | } // end anonymous namespace |
| 119 | |
| 120 | // #include "ARMGenCallingConv.inc" |
| 121 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 122 | // DefinesOptionalPredicate - This is different from DefinesPredicate in that |
| 123 | // we don't care about implicit defs here, just places we'll need to add a |
| 124 | // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR. |
| 125 | bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) { |
| 126 | const TargetInstrDesc &TID = MI->getDesc(); |
| 127 | if (!TID.hasOptionalDef()) |
| 128 | return false; |
| 129 | |
| 130 | // Look to see if our OptionalDef is defining CPSR or CCR. |
| 131 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 132 | const MachineOperand &MO = MI->getOperand(i); |
Eric Christopher | f762fbe | 2010-08-20 00:36:24 +0000 | [diff] [blame] | 133 | if (!MO.isReg() || !MO.isDef()) continue; |
| 134 | if (MO.getReg() == ARM::CPSR) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 135 | *CPSR = true; |
| 136 | } |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | // If the machine is predicable go ahead and add the predicate operands, if |
| 141 | // it needs default CC operands add those. |
| 142 | const MachineInstrBuilder & |
| 143 | ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) { |
| 144 | MachineInstr *MI = &*MIB; |
| 145 | |
| 146 | // Do we use a predicate? |
| 147 | if (TII.isPredicable(MI)) |
| 148 | AddDefaultPred(MIB); |
| 149 | |
| 150 | // Do we optionally set a predicate? Preds is size > 0 iff the predicate |
| 151 | // defines CPSR. All other OptionalDefines in ARM are the CCR register. |
Eric Christopher | 979e0a1 | 2010-08-19 15:35:27 +0000 | [diff] [blame] | 152 | bool CPSR = false; |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 153 | if (DefinesOptionalPredicate(MI, &CPSR)) { |
| 154 | if (CPSR) |
| 155 | AddDefaultT1CC(MIB); |
| 156 | else |
| 157 | AddDefaultCC(MIB); |
| 158 | } |
| 159 | return MIB; |
| 160 | } |
| 161 | |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 162 | unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode, |
| 163 | const TargetRegisterClass* RC) { |
| 164 | unsigned ResultReg = createResultReg(RC); |
| 165 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 166 | |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 167 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)); |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 168 | return ResultReg; |
| 169 | } |
| 170 | |
| 171 | unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode, |
| 172 | const TargetRegisterClass *RC, |
| 173 | unsigned Op0, bool Op0IsKill) { |
| 174 | unsigned ResultReg = createResultReg(RC); |
| 175 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 176 | |
| 177 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 178 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 179 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
| 180 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 181 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 182 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 183 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 184 | TII.get(TargetOpcode::COPY), ResultReg) |
| 185 | .addReg(II.ImplicitDefs[0])); |
| 186 | } |
| 187 | return ResultReg; |
| 188 | } |
| 189 | |
| 190 | unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode, |
| 191 | const TargetRegisterClass *RC, |
| 192 | unsigned Op0, bool Op0IsKill, |
| 193 | unsigned Op1, bool Op1IsKill) { |
| 194 | unsigned ResultReg = createResultReg(RC); |
| 195 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 196 | |
| 197 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 198 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 199 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 200 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
| 201 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 202 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 203 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 204 | .addReg(Op1, Op1IsKill * 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_ri(unsigned MachineInstOpcode, |
| 213 | const TargetRegisterClass *RC, |
| 214 | unsigned Op0, bool Op0IsKill, |
| 215 | uint64_t Imm) { |
| 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 | .addImm(Imm)); |
| 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 | .addImm(Imm)); |
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_rf(unsigned MachineInstOpcode, |
| 235 | const TargetRegisterClass *RC, |
| 236 | unsigned Op0, bool Op0IsKill, |
| 237 | const ConstantFP *FPImm) { |
| 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 | .addFPImm(FPImm)); |
| 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 | .addFPImm(FPImm)); |
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_rri(unsigned MachineInstOpcode, |
| 257 | const TargetRegisterClass *RC, |
| 258 | unsigned Op0, bool Op0IsKill, |
| 259 | unsigned Op1, bool Op1IsKill, |
| 260 | uint64_t Imm) { |
| 261 | unsigned ResultReg = createResultReg(RC); |
| 262 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 263 | |
| 264 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 265 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 266 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 267 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 268 | .addImm(Imm)); |
| 269 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 270 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 271 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 272 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 273 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 274 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 275 | TII.get(TargetOpcode::COPY), ResultReg) |
| 276 | .addReg(II.ImplicitDefs[0])); |
| 277 | } |
| 278 | return ResultReg; |
| 279 | } |
| 280 | |
| 281 | unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode, |
| 282 | const TargetRegisterClass *RC, |
| 283 | uint64_t Imm) { |
| 284 | unsigned ResultReg = createResultReg(RC); |
| 285 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 286 | |
| 287 | if (II.getNumDefs() >= 1) |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 288 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 289 | .addImm(Imm)); |
| 290 | else { |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 291 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II) |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 292 | .addImm(Imm)); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 293 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 294 | TII.get(TargetOpcode::COPY), ResultReg) |
| 295 | .addReg(II.ImplicitDefs[0])); |
| 296 | } |
| 297 | return ResultReg; |
| 298 | } |
| 299 | |
| 300 | unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT, |
| 301 | unsigned Op0, bool Op0IsKill, |
| 302 | uint32_t Idx) { |
| 303 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT)); |
| 304 | assert(TargetRegisterInfo::isVirtualRegister(Op0) && |
| 305 | "Cannot yet extract from physregs"); |
Eric Christopher | 456144e | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 306 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Eric Christopher | 0fe7d54 | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 307 | DL, TII.get(TargetOpcode::COPY), ResultReg) |
| 308 | .addReg(Op0, getKillRegState(Op0IsKill), Idx)); |
| 309 | return ResultReg; |
| 310 | } |
| 311 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 312 | // Computes the Reg+Offset to get to an object. |
| 313 | bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg, |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 314 | int &Offset) { |
| 315 | // Some boilerplate from the X86 FastISel. |
| 316 | const User *U = NULL; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 317 | unsigned Opcode = Instruction::UserOp1; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 318 | if (const Instruction *I = dyn_cast<Instruction>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 319 | // Don't walk into other basic blocks; it's possible we haven't |
| 320 | // visited them yet, so the instructions may not yet be assigned |
| 321 | // virtual registers. |
| 322 | if (FuncInfo.MBBMap[I->getParent()] != FuncInfo.MBB) |
| 323 | return false; |
| 324 | |
| 325 | Opcode = I->getOpcode(); |
| 326 | U = I; |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 327 | } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 328 | Opcode = C->getOpcode(); |
| 329 | U = C; |
| 330 | } |
| 331 | |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 332 | if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType())) |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 333 | if (Ty->getAddressSpace() > 255) |
| 334 | // Fast instruction selection doesn't support the special |
| 335 | // address spaces. |
| 336 | return false; |
| 337 | |
| 338 | switch (Opcode) { |
| 339 | default: |
| 340 | //errs() << "Failing Opcode is: " << *Op1 << "\n"; |
| 341 | break; |
| 342 | case Instruction::Alloca: { |
| 343 | // Do static allocas. |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 344 | const AllocaInst *A = cast<AllocaInst>(Obj); |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 345 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 346 | FuncInfo.StaticAllocaMap.find(A); |
| 347 | if (SI != FuncInfo.StaticAllocaMap.end()) |
| 348 | Offset = |
| 349 | TM.getRegisterInfo()->getFrameIndexReference(*FuncInfo.MF, |
| 350 | SI->second, Reg); |
| 351 | else |
| 352 | return false; |
| 353 | return true; |
| 354 | } |
| 355 | } |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 356 | |
| 357 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) { |
| 358 | //errs() << "Failing GV is: " << GV << "\n"; |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | // Try to get this in a register if nothing else has worked. |
| 363 | Reg = getRegForValue(Obj); |
| 364 | return Reg != 0; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | bool ARMFastISel::ARMSelectLoad(const Instruction *I) { |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 368 | // Our register and offset with innocuous defaults. |
| 369 | unsigned Reg = 0; |
| 370 | int Offset = 0; |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 371 | |
Eric Christopher | 8654c71 | 2010-08-23 23:14:31 +0000 | [diff] [blame] | 372 | // TODO: Think about using loadRegFromStackSlot() here when we can. |
| 373 | |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 374 | // See if we can handle this as Reg + Offset |
Eric Christopher | cb0b04b | 2010-08-24 00:07:24 +0000 | [diff] [blame^] | 375 | if (!ARMComputeRegOffset(I->getOperand(0), Reg, Offset)) |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 376 | return false; |
| 377 | |
Eric Christopher | 8654c71 | 2010-08-23 23:14:31 +0000 | [diff] [blame] | 378 | // Since the offset may be too large for the load instruction |
| 379 | // get the reg+offset into a register. |
| 380 | // TODO: Optimize this somewhat. |
Eric Christopher | 8654c71 | 2010-08-23 23:14:31 +0000 | [diff] [blame] | 381 | ARMCC::CondCodes Pred = ARMCC::AL; |
| 382 | unsigned PredReg = 0; |
| 383 | |
| 384 | if (!AFI->isThumbFunction()) |
| 385 | emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 1dfb4d3 | 2010-08-23 23:28:04 +0000 | [diff] [blame] | 386 | Reg, Reg, Offset, Pred, PredReg, |
Eric Christopher | 8654c71 | 2010-08-23 23:14:31 +0000 | [diff] [blame] | 387 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 388 | else { |
| 389 | assert(AFI->isThumb2Function()); |
| 390 | emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
Eric Christopher | 1dfb4d3 | 2010-08-23 23:28:04 +0000 | [diff] [blame] | 391 | Reg, Reg, Offset, Pred, PredReg, |
Eric Christopher | 8654c71 | 2010-08-23 23:14:31 +0000 | [diff] [blame] | 392 | static_cast<const ARMBaseInstrInfo&>(TII)); |
| 393 | } |
Eric Christopher | 1dfb4d3 | 2010-08-23 23:28:04 +0000 | [diff] [blame] | 394 | |
| 395 | // FIXME: There is more than one register class in the world... |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 396 | unsigned ResultReg = createResultReg(ARM::GPRRegisterClass); |
| 397 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, |
| 398 | TII.get(ARM::LDR), ResultReg) |
| 399 | .addImm(0).addReg(Reg).addImm(Offset)); |
| 400 | |
| 401 | return true; |
| 402 | } |
| 403 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 404 | bool ARMFastISel::TargetSelectInstruction(const Instruction *I) { |
Eric Christopher | 7fe55b7 | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 405 | // No Thumb-1 for now. |
| 406 | if (AFI->isThumbFunction() && !AFI->isThumb2Function()) return false; |
| 407 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 408 | switch (I->getOpcode()) { |
Eric Christopher | 8300712 | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 409 | case Instruction::Load: |
| 410 | return ARMSelectLoad(I); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 411 | default: break; |
| 412 | } |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | namespace llvm { |
| 417 | llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) { |
Eric Christopher | 038fea5 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 418 | if (EnableARMFastISel) return new ARMFastISel(funcInfo); |
Evan Cheng | 0944795 | 2010-07-26 18:32:55 +0000 | [diff] [blame] | 419 | return 0; |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 420 | } |
| 421 | } |