blob: 55fb7c26d5a30e26a7e69d71681f8cd54b4812f8 [file] [log] [blame]
Eric Christopherab695882010-07-21 22:26:11 +00001//===-- 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 Christopher456144e2010-08-19 00:37:05 +000017#include "ARMBaseInstrInfo.h"
Eric Christopherab695882010-07-21 22:26:11 +000018#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 Christopher0fe7d542010-08-17 01:25:29 +000029#include "llvm/CodeGen/MachineInstrBuilder.h"
30#include "llvm/CodeGen/MachineModuleInfo.h"
Eric Christopherab695882010-07-21 22:26:11 +000031#include "llvm/CodeGen/MachineConstantPool.h"
32#include "llvm/CodeGen/MachineFrameInfo.h"
33#include "llvm/CodeGen/MachineRegisterInfo.h"
34#include "llvm/Support/CallSite.h"
Eric Christopher038fea52010-08-17 00:46:57 +000035#include "llvm/Support/CommandLine.h"
Eric Christopherab695882010-07-21 22:26:11 +000036#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/GetElementPtrTypeIterator.h"
Eric Christopher0fe7d542010-08-17 01:25:29 +000038#include "llvm/Target/TargetData.h"
39#include "llvm/Target/TargetInstrInfo.h"
40#include "llvm/Target/TargetLowering.h"
41#include "llvm/Target/TargetMachine.h"
Eric Christopherab695882010-07-21 22:26:11 +000042#include "llvm/Target/TargetOptions.h"
43using namespace llvm;
44
Eric Christopher038fea52010-08-17 00:46:57 +000045static cl::opt<bool>
46EnableARMFastISel("arm-fast-isel",
47 cl::desc("Turn on experimental ARM fast-isel support"),
48 cl::init(false), cl::Hidden);
49
Eric Christopherab695882010-07-21 22:26:11 +000050namespace {
51
52class 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 Christopher0fe7d542010-08-17 01:25:29 +000057 const TargetMachine &TM;
58 const TargetInstrInfo &TII;
59 const TargetLowering &TLI;
Eric Christopher7fe55b72010-08-23 22:32:45 +000060 const ARMFunctionInfo *AFI;
Eric Christopherf06f3092010-08-24 00:50:47 +000061
62 // FIXME: Remove this and replace it with queries.
63 const TargetRegisterClass *FixedRC;
Eric Christopherab695882010-07-21 22:26:11 +000064
65 public:
Eric Christopher0fe7d542010-08-17 01:25:29 +000066 explicit ARMFastISel(FunctionLoweringInfo &funcInfo)
67 : FastISel(funcInfo),
68 TM(funcInfo.MF->getTarget()),
69 TII(*TM.getInstrInfo()),
70 TLI(*TM.getTargetLowering()) {
Eric Christopherab695882010-07-21 22:26:11 +000071 Subtarget = &TM.getSubtarget<ARMSubtarget>();
Eric Christopher7fe55b72010-08-23 22:32:45 +000072 AFI = funcInfo.MF->getInfo<ARMFunctionInfo>();
Eric Christopherf06f3092010-08-24 00:50:47 +000073 FixedRC = ARM::GPRRegisterClass;
Eric Christopherab695882010-07-21 22:26:11 +000074 }
75
Eric Christophercb592292010-08-20 00:20:31 +000076 // Code from FastISel.cpp.
Eric Christopher0fe7d542010-08-17 01:25:29 +000077 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 Christophercb592292010-08-20 00:20:31 +0000105
106 // Backend specific FastISel code.
Eric Christopherab695882010-07-21 22:26:11 +0000107 virtual bool TargetSelectInstruction(const Instruction *I);
108
109 #include "ARMGenFastISel.inc"
Eric Christopher83007122010-08-23 21:44:12 +0000110
111 // Instruction selection routines.
112 virtual bool ARMSelectLoad(const Instruction *I);
Eric Christopherab695882010-07-21 22:26:11 +0000113
Eric Christopher83007122010-08-23 21:44:12 +0000114 // Utility routines.
Eric Christopher456144e2010-08-19 00:37:05 +0000115 private:
Eric Christopherf06f3092010-08-24 00:50:47 +0000116 bool ARMLoadAlloca(const Instruction *I);
Eric Christophercb0b04b2010-08-24 00:07:24 +0000117 bool ARMComputeRegOffset(const Value *Obj, unsigned &Reg, int &Offset);
Eric Christopher83007122010-08-23 21:44:12 +0000118
Eric Christopher456144e2010-08-19 00:37:05 +0000119 bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR);
120 const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB);
121};
Eric Christopherab695882010-07-21 22:26:11 +0000122
123} // end anonymous namespace
124
125// #include "ARMGenCallingConv.inc"
126
Eric Christopher456144e2010-08-19 00:37:05 +0000127// DefinesOptionalPredicate - This is different from DefinesPredicate in that
128// we don't care about implicit defs here, just places we'll need to add a
129// default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR.
130bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) {
131 const TargetInstrDesc &TID = MI->getDesc();
132 if (!TID.hasOptionalDef())
133 return false;
134
135 // Look to see if our OptionalDef is defining CPSR or CCR.
136 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
137 const MachineOperand &MO = MI->getOperand(i);
Eric Christopherf762fbe2010-08-20 00:36:24 +0000138 if (!MO.isReg() || !MO.isDef()) continue;
139 if (MO.getReg() == ARM::CPSR)
Eric Christopher456144e2010-08-19 00:37:05 +0000140 *CPSR = true;
141 }
142 return true;
143}
144
145// If the machine is predicable go ahead and add the predicate operands, if
146// it needs default CC operands add those.
147const MachineInstrBuilder &
148ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) {
149 MachineInstr *MI = &*MIB;
150
151 // Do we use a predicate?
152 if (TII.isPredicable(MI))
153 AddDefaultPred(MIB);
154
155 // Do we optionally set a predicate? Preds is size > 0 iff the predicate
156 // defines CPSR. All other OptionalDefines in ARM are the CCR register.
Eric Christopher979e0a12010-08-19 15:35:27 +0000157 bool CPSR = false;
Eric Christopher456144e2010-08-19 00:37:05 +0000158 if (DefinesOptionalPredicate(MI, &CPSR)) {
159 if (CPSR)
160 AddDefaultT1CC(MIB);
161 else
162 AddDefaultCC(MIB);
163 }
164 return MIB;
165}
166
Eric Christopher0fe7d542010-08-17 01:25:29 +0000167unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode,
168 const TargetRegisterClass* RC) {
169 unsigned ResultReg = createResultReg(RC);
170 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
171
Eric Christopher456144e2010-08-19 00:37:05 +0000172 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg));
Eric Christopher0fe7d542010-08-17 01:25:29 +0000173 return ResultReg;
174}
175
176unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode,
177 const TargetRegisterClass *RC,
178 unsigned Op0, bool Op0IsKill) {
179 unsigned ResultReg = createResultReg(RC);
180 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
181
182 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000183 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000184 .addReg(Op0, Op0IsKill * RegState::Kill));
185 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000186 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000187 .addReg(Op0, Op0IsKill * RegState::Kill));
Eric Christopher456144e2010-08-19 00:37:05 +0000188 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000189 TII.get(TargetOpcode::COPY), ResultReg)
190 .addReg(II.ImplicitDefs[0]));
191 }
192 return ResultReg;
193}
194
195unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode,
196 const TargetRegisterClass *RC,
197 unsigned Op0, bool Op0IsKill,
198 unsigned Op1, bool Op1IsKill) {
199 unsigned ResultReg = createResultReg(RC);
200 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
201
202 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000203 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000204 .addReg(Op0, Op0IsKill * RegState::Kill)
205 .addReg(Op1, Op1IsKill * RegState::Kill));
206 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000207 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000208 .addReg(Op0, Op0IsKill * RegState::Kill)
209 .addReg(Op1, Op1IsKill * RegState::Kill));
Eric Christopher456144e2010-08-19 00:37:05 +0000210 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000211 TII.get(TargetOpcode::COPY), ResultReg)
212 .addReg(II.ImplicitDefs[0]));
213 }
214 return ResultReg;
215}
216
217unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode,
218 const TargetRegisterClass *RC,
219 unsigned Op0, bool Op0IsKill,
220 uint64_t Imm) {
221 unsigned ResultReg = createResultReg(RC);
222 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
223
224 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000225 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000226 .addReg(Op0, Op0IsKill * RegState::Kill)
227 .addImm(Imm));
228 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000229 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000230 .addReg(Op0, Op0IsKill * RegState::Kill)
231 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000232 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000233 TII.get(TargetOpcode::COPY), ResultReg)
234 .addReg(II.ImplicitDefs[0]));
235 }
236 return ResultReg;
237}
238
239unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode,
240 const TargetRegisterClass *RC,
241 unsigned Op0, bool Op0IsKill,
242 const ConstantFP *FPImm) {
243 unsigned ResultReg = createResultReg(RC);
244 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
245
246 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000247 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000248 .addReg(Op0, Op0IsKill * RegState::Kill)
249 .addFPImm(FPImm));
250 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000251 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000252 .addReg(Op0, Op0IsKill * RegState::Kill)
253 .addFPImm(FPImm));
Eric Christopher456144e2010-08-19 00:37:05 +0000254 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000255 TII.get(TargetOpcode::COPY), ResultReg)
256 .addReg(II.ImplicitDefs[0]));
257 }
258 return ResultReg;
259}
260
261unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode,
262 const TargetRegisterClass *RC,
263 unsigned Op0, bool Op0IsKill,
264 unsigned Op1, bool Op1IsKill,
265 uint64_t Imm) {
266 unsigned ResultReg = createResultReg(RC);
267 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
268
269 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000270 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000271 .addReg(Op0, Op0IsKill * RegState::Kill)
272 .addReg(Op1, Op1IsKill * RegState::Kill)
273 .addImm(Imm));
274 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000275 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000276 .addReg(Op0, Op0IsKill * RegState::Kill)
277 .addReg(Op1, Op1IsKill * RegState::Kill)
278 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000279 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000280 TII.get(TargetOpcode::COPY), ResultReg)
281 .addReg(II.ImplicitDefs[0]));
282 }
283 return ResultReg;
284}
285
286unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode,
287 const TargetRegisterClass *RC,
288 uint64_t Imm) {
289 unsigned ResultReg = createResultReg(RC);
290 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
291
292 if (II.getNumDefs() >= 1)
Eric Christopher456144e2010-08-19 00:37:05 +0000293 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000294 .addImm(Imm));
295 else {
Eric Christopher456144e2010-08-19 00:37:05 +0000296 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
Eric Christopher0fe7d542010-08-17 01:25:29 +0000297 .addImm(Imm));
Eric Christopher456144e2010-08-19 00:37:05 +0000298 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000299 TII.get(TargetOpcode::COPY), ResultReg)
300 .addReg(II.ImplicitDefs[0]));
301 }
302 return ResultReg;
303}
304
305unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT,
306 unsigned Op0, bool Op0IsKill,
307 uint32_t Idx) {
308 unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT));
309 assert(TargetRegisterInfo::isVirtualRegister(Op0) &&
310 "Cannot yet extract from physregs");
Eric Christopher456144e2010-08-19 00:37:05 +0000311 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
Eric Christopher0fe7d542010-08-17 01:25:29 +0000312 DL, TII.get(TargetOpcode::COPY), ResultReg)
313 .addReg(Op0, getKillRegState(Op0IsKill), Idx));
314 return ResultReg;
315}
316
Eric Christophercb0b04b2010-08-24 00:07:24 +0000317// Computes the Reg+Offset to get to an object.
318bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg,
Eric Christopher83007122010-08-23 21:44:12 +0000319 int &Offset) {
320 // Some boilerplate from the X86 FastISel.
321 const User *U = NULL;
Eric Christopher83007122010-08-23 21:44:12 +0000322 unsigned Opcode = Instruction::UserOp1;
Eric Christophercb0b04b2010-08-24 00:07:24 +0000323 if (const Instruction *I = dyn_cast<Instruction>(Obj)) {
Eric Christopher83007122010-08-23 21:44:12 +0000324 // Don't walk into other basic blocks; it's possible we haven't
325 // visited them yet, so the instructions may not yet be assigned
326 // virtual registers.
327 if (FuncInfo.MBBMap[I->getParent()] != FuncInfo.MBB)
328 return false;
329
330 Opcode = I->getOpcode();
331 U = I;
Eric Christophercb0b04b2010-08-24 00:07:24 +0000332 } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
Eric Christopher83007122010-08-23 21:44:12 +0000333 Opcode = C->getOpcode();
334 U = C;
335 }
336
Eric Christophercb0b04b2010-08-24 00:07:24 +0000337 if (const PointerType *Ty = dyn_cast<PointerType>(Obj->getType()))
Eric Christopher83007122010-08-23 21:44:12 +0000338 if (Ty->getAddressSpace() > 255)
339 // Fast instruction selection doesn't support the special
340 // address spaces.
341 return false;
342
343 switch (Opcode) {
344 default:
345 //errs() << "Failing Opcode is: " << *Op1 << "\n";
346 break;
347 case Instruction::Alloca: {
Eric Christopherf06f3092010-08-24 00:50:47 +0000348 assert(false && "Alloca should have been handled earlier!");
349 return false;
Eric Christopher83007122010-08-23 21:44:12 +0000350 }
351 }
Eric Christophercb0b04b2010-08-24 00:07:24 +0000352
353 if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) {
354 //errs() << "Failing GV is: " << GV << "\n";
Eric Christopherf06f3092010-08-24 00:50:47 +0000355 (void)GV;
Eric Christophercb0b04b2010-08-24 00:07:24 +0000356 return false;
357 }
358
359 // Try to get this in a register if nothing else has worked.
360 Reg = getRegForValue(Obj);
361 return Reg != 0;
Eric Christopher83007122010-08-23 21:44:12 +0000362}
363
Eric Christopherf06f3092010-08-24 00:50:47 +0000364bool ARMFastISel::ARMLoadAlloca(const Instruction *I) {
365 Value *Op0 = I->getOperand(0);
366
367 // Verify it's an alloca.
368 const Instruction *Inst = dyn_cast<Instruction>(Op0);
369 if (!Inst || Inst->getOpcode() != Instruction::Alloca) return false;
370
371 const AllocaInst *AI = cast<AllocaInst>(Op0);
372 DenseMap<const AllocaInst*, int>::iterator SI =
373 FuncInfo.StaticAllocaMap.find(AI);
374
375 if (SI != FuncInfo.StaticAllocaMap.end()) {
376 unsigned ResultReg = createResultReg(FixedRC);
377 TII.loadRegFromStackSlot(*FuncInfo.MBB, *FuncInfo.InsertPt,
378 ResultReg, SI->second, FixedRC,
379 TM.getRegisterInfo());
380 UpdateValueMap(I, ResultReg);
381 return true;
382 }
383
384 return false;
385}
386
Eric Christopher83007122010-08-23 21:44:12 +0000387bool ARMFastISel::ARMSelectLoad(const Instruction *I) {
Eric Christophercb0b04b2010-08-24 00:07:24 +0000388 // Our register and offset with innocuous defaults.
389 unsigned Reg = 0;
390 int Offset = 0;
Eric Christopher83007122010-08-23 21:44:12 +0000391
Eric Christopher882d62e2010-08-24 01:10:52 +0000392 // If we're an alloca we know we have a frame index and can emit the load
393 // directly in short order.
Eric Christopherf06f3092010-08-24 00:50:47 +0000394 if (ARMLoadAlloca(I))
395 return true;
Eric Christopher8654c712010-08-23 23:14:31 +0000396
Eric Christopher83007122010-08-23 21:44:12 +0000397 // See if we can handle this as Reg + Offset
Eric Christophercb0b04b2010-08-24 00:07:24 +0000398 if (!ARMComputeRegOffset(I->getOperand(0), Reg, Offset))
Eric Christopher83007122010-08-23 21:44:12 +0000399 return false;
400
Eric Christopher8654c712010-08-23 23:14:31 +0000401 // Since the offset may be too large for the load instruction
402 // get the reg+offset into a register.
403 // TODO: Optimize this somewhat.
Eric Christopher8654c712010-08-23 23:14:31 +0000404 ARMCC::CondCodes Pred = ARMCC::AL;
405 unsigned PredReg = 0;
406
407 if (!AFI->isThumbFunction())
408 emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher1dfb4d32010-08-23 23:28:04 +0000409 Reg, Reg, Offset, Pred, PredReg,
Eric Christopher8654c712010-08-23 23:14:31 +0000410 static_cast<const ARMBaseInstrInfo&>(TII));
411 else {
412 assert(AFI->isThumb2Function());
413 emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher1dfb4d32010-08-23 23:28:04 +0000414 Reg, Reg, Offset, Pred, PredReg,
Eric Christopher8654c712010-08-23 23:14:31 +0000415 static_cast<const ARMBaseInstrInfo&>(TII));
416 }
Eric Christopher1dfb4d32010-08-23 23:28:04 +0000417
418 // FIXME: There is more than one register class in the world...
Eric Christopher2012c7b2010-08-24 01:10:04 +0000419 // TODO: Verify the additions above work, otherwise we'll need to add the
420 // offset instead of 0 and do all sorts of operand munging.
Eric Christopherf06f3092010-08-24 00:50:47 +0000421 unsigned ResultReg = createResultReg(FixedRC);
Eric Christopher2012c7b2010-08-24 01:10:04 +0000422 unsigned Opc = AFI->isThumb2Function() ? ARM::tLDR : ARM::LDR;
Eric Christopher83007122010-08-23 21:44:12 +0000423 AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
Eric Christopher2012c7b2010-08-24 01:10:04 +0000424 TII.get(Opc), ResultReg)
425 .addReg(Reg).addReg(0).addImm(0));
Eric Christopherf06f3092010-08-24 00:50:47 +0000426 UpdateValueMap(I, ResultReg);
Eric Christopher83007122010-08-23 21:44:12 +0000427
428 return true;
429}
430
Eric Christopherab695882010-07-21 22:26:11 +0000431bool ARMFastISel::TargetSelectInstruction(const Instruction *I) {
Eric Christopher7fe55b72010-08-23 22:32:45 +0000432 // No Thumb-1 for now.
433 if (AFI->isThumbFunction() && !AFI->isThumb2Function()) return false;
434
Eric Christopherab695882010-07-21 22:26:11 +0000435 switch (I->getOpcode()) {
Eric Christopher83007122010-08-23 21:44:12 +0000436 case Instruction::Load:
437 return ARMSelectLoad(I);
Eric Christopherab695882010-07-21 22:26:11 +0000438 default: break;
439 }
440 return false;
441}
442
443namespace llvm {
444 llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) {
Eric Christopher038fea52010-08-17 00:46:57 +0000445 if (EnableARMFastISel) return new ARMFastISel(funcInfo);
Evan Cheng09447952010-07-26 18:32:55 +0000446 return 0;
Eric Christopherab695882010-07-21 22:26:11 +0000447 }
448}