blob: 36d8a079708557f7e6bde5fcb52b4d454987b80e [file] [log] [blame]
Jim Grosbach31c24bf2009-11-07 22:00:39 +00001//===- ARMBaseInstrInfo.cpp - ARM Instruction Information -------*- C++ -*-===//
David Goodwin334c2642009-07-08 16:09:28 +00002//
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 contains the Base ARM implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARMBaseInstrInfo.h"
15#include "ARM.h"
16#include "ARMAddressingModes.h"
Evan Chengd457e6e2009-11-07 04:04:34 +000017#include "ARMConstantPoolValue.h"
David Goodwin334c2642009-07-08 16:09:28 +000018#include "ARMMachineFunctionInfo.h"
Anton Korobeynikovf95215f2009-11-02 00:10:38 +000019#include "ARMRegisterInfo.h"
Chris Lattner4dbbe342010-07-20 21:17:29 +000020#include "ARMGenInstrInfo.inc"
Evan Chengfdc83402009-11-08 00:15:23 +000021#include "llvm/Constants.h"
22#include "llvm/Function.h"
23#include "llvm/GlobalValue.h"
David Goodwin334c2642009-07-08 16:09:28 +000024#include "llvm/CodeGen/LiveVariables.h"
Evan Chengd457e6e2009-11-07 04:04:34 +000025#include "llvm/CodeGen/MachineConstantPool.h"
David Goodwin334c2642009-07-08 16:09:28 +000026#include "llvm/CodeGen/MachineFrameInfo.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/MachineJumpTableInfo.h"
Anton Korobeynikov249fb332009-10-07 00:06:35 +000029#include "llvm/CodeGen/MachineMemOperand.h"
Evan Cheng2457f2c2010-05-22 01:47:14 +000030#include "llvm/CodeGen/MachineRegisterInfo.h"
Anton Korobeynikov249fb332009-10-07 00:06:35 +000031#include "llvm/CodeGen/PseudoSourceValue.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000032#include "llvm/MC/MCAsmInfo.h"
David Goodwin334c2642009-07-08 16:09:28 +000033#include "llvm/Support/CommandLine.h"
Anton Korobeynikovf95215f2009-11-02 00:10:38 +000034#include "llvm/Support/Debug.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000035#include "llvm/Support/ErrorHandling.h"
Bill Wendling40a5eb12010-11-01 20:41:43 +000036#include "llvm/ADT/STLExtras.h"
David Goodwin334c2642009-07-08 16:09:28 +000037using namespace llvm;
38
39static cl::opt<bool>
40EnableARM3Addr("enable-arm-3-addr-conv", cl::Hidden,
41 cl::desc("Enable ARM 2-addr to 3-addr conv"));
42
Anton Korobeynikovf95215f2009-11-02 00:10:38 +000043ARMBaseInstrInfo::ARMBaseInstrInfo(const ARMSubtarget& STI)
44 : TargetInstrInfoImpl(ARMInsts, array_lengthof(ARMInsts)),
45 Subtarget(STI) {
David Goodwin334c2642009-07-08 16:09:28 +000046}
47
48MachineInstr *
49ARMBaseInstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
50 MachineBasicBlock::iterator &MBBI,
51 LiveVariables *LV) const {
Evan Cheng78703dd2009-07-27 18:44:00 +000052 // FIXME: Thumb2 support.
53
David Goodwin334c2642009-07-08 16:09:28 +000054 if (!EnableARM3Addr)
55 return NULL;
56
57 MachineInstr *MI = MBBI;
58 MachineFunction &MF = *MI->getParent()->getParent();
Bruno Cardoso Lopes99405df2010-06-08 22:51:23 +000059 uint64_t TSFlags = MI->getDesc().TSFlags;
David Goodwin334c2642009-07-08 16:09:28 +000060 bool isPre = false;
61 switch ((TSFlags & ARMII::IndexModeMask) >> ARMII::IndexModeShift) {
62 default: return NULL;
63 case ARMII::IndexModePre:
64 isPre = true;
65 break;
66 case ARMII::IndexModePost:
67 break;
68 }
69
70 // Try splitting an indexed load/store to an un-indexed one plus an add/sub
71 // operation.
72 unsigned MemOpc = getUnindexedOpcode(MI->getOpcode());
73 if (MemOpc == 0)
74 return NULL;
75
76 MachineInstr *UpdateMI = NULL;
77 MachineInstr *MemMI = NULL;
78 unsigned AddrMode = (TSFlags & ARMII::AddrModeMask);
79 const TargetInstrDesc &TID = MI->getDesc();
80 unsigned NumOps = TID.getNumOperands();
81 bool isLoad = !TID.mayStore();
82 const MachineOperand &WB = isLoad ? MI->getOperand(1) : MI->getOperand(0);
83 const MachineOperand &Base = MI->getOperand(2);
84 const MachineOperand &Offset = MI->getOperand(NumOps-3);
85 unsigned WBReg = WB.getReg();
86 unsigned BaseReg = Base.getReg();
87 unsigned OffReg = Offset.getReg();
88 unsigned OffImm = MI->getOperand(NumOps-2).getImm();
89 ARMCC::CondCodes Pred = (ARMCC::CondCodes)MI->getOperand(NumOps-1).getImm();
90 switch (AddrMode) {
91 default:
92 assert(false && "Unknown indexed op!");
93 return NULL;
94 case ARMII::AddrMode2: {
95 bool isSub = ARM_AM::getAM2Op(OffImm) == ARM_AM::sub;
96 unsigned Amt = ARM_AM::getAM2Offset(OffImm);
97 if (OffReg == 0) {
Evan Chenge7cbe412009-07-08 21:03:57 +000098 if (ARM_AM::getSOImmVal(Amt) == -1)
David Goodwin334c2642009-07-08 16:09:28 +000099 // Can't encode it in a so_imm operand. This transformation will
100 // add more than 1 instruction. Abandon!
101 return NULL;
102 UpdateMI = BuildMI(MF, MI->getDebugLoc(),
Evan Cheng78703dd2009-07-27 18:44:00 +0000103 get(isSub ? ARM::SUBri : ARM::ADDri), WBReg)
Evan Chenge7cbe412009-07-08 21:03:57 +0000104 .addReg(BaseReg).addImm(Amt)
David Goodwin334c2642009-07-08 16:09:28 +0000105 .addImm(Pred).addReg(0).addReg(0);
106 } else if (Amt != 0) {
107 ARM_AM::ShiftOpc ShOpc = ARM_AM::getAM2ShiftOpc(OffImm);
108 unsigned SOOpc = ARM_AM::getSORegOpc(ShOpc, Amt);
109 UpdateMI = BuildMI(MF, MI->getDebugLoc(),
Evan Cheng78703dd2009-07-27 18:44:00 +0000110 get(isSub ? ARM::SUBrs : ARM::ADDrs), WBReg)
David Goodwin334c2642009-07-08 16:09:28 +0000111 .addReg(BaseReg).addReg(OffReg).addReg(0).addImm(SOOpc)
112 .addImm(Pred).addReg(0).addReg(0);
113 } else
114 UpdateMI = BuildMI(MF, MI->getDebugLoc(),
Evan Cheng78703dd2009-07-27 18:44:00 +0000115 get(isSub ? ARM::SUBrr : ARM::ADDrr), WBReg)
David Goodwin334c2642009-07-08 16:09:28 +0000116 .addReg(BaseReg).addReg(OffReg)
117 .addImm(Pred).addReg(0).addReg(0);
118 break;
119 }
120 case ARMII::AddrMode3 : {
121 bool isSub = ARM_AM::getAM3Op(OffImm) == ARM_AM::sub;
122 unsigned Amt = ARM_AM::getAM3Offset(OffImm);
123 if (OffReg == 0)
124 // Immediate is 8-bits. It's guaranteed to fit in a so_imm operand.
125 UpdateMI = BuildMI(MF, MI->getDebugLoc(),
Evan Cheng78703dd2009-07-27 18:44:00 +0000126 get(isSub ? ARM::SUBri : ARM::ADDri), WBReg)
David Goodwin334c2642009-07-08 16:09:28 +0000127 .addReg(BaseReg).addImm(Amt)
128 .addImm(Pred).addReg(0).addReg(0);
129 else
130 UpdateMI = BuildMI(MF, MI->getDebugLoc(),
Evan Cheng78703dd2009-07-27 18:44:00 +0000131 get(isSub ? ARM::SUBrr : ARM::ADDrr), WBReg)
David Goodwin334c2642009-07-08 16:09:28 +0000132 .addReg(BaseReg).addReg(OffReg)
133 .addImm(Pred).addReg(0).addReg(0);
134 break;
135 }
136 }
137
138 std::vector<MachineInstr*> NewMIs;
139 if (isPre) {
140 if (isLoad)
141 MemMI = BuildMI(MF, MI->getDebugLoc(),
142 get(MemOpc), MI->getOperand(0).getReg())
Jim Grosbach3e556122010-10-26 22:37:02 +0000143 .addReg(WBReg).addImm(0).addImm(Pred);
David Goodwin334c2642009-07-08 16:09:28 +0000144 else
145 MemMI = BuildMI(MF, MI->getDebugLoc(),
146 get(MemOpc)).addReg(MI->getOperand(1).getReg())
147 .addReg(WBReg).addReg(0).addImm(0).addImm(Pred);
148 NewMIs.push_back(MemMI);
149 NewMIs.push_back(UpdateMI);
150 } else {
151 if (isLoad)
152 MemMI = BuildMI(MF, MI->getDebugLoc(),
153 get(MemOpc), MI->getOperand(0).getReg())
Jim Grosbach3e556122010-10-26 22:37:02 +0000154 .addReg(BaseReg).addImm(0).addImm(Pred);
David Goodwin334c2642009-07-08 16:09:28 +0000155 else
156 MemMI = BuildMI(MF, MI->getDebugLoc(),
157 get(MemOpc)).addReg(MI->getOperand(1).getReg())
158 .addReg(BaseReg).addReg(0).addImm(0).addImm(Pred);
159 if (WB.isDead())
160 UpdateMI->getOperand(0).setIsDead();
161 NewMIs.push_back(UpdateMI);
162 NewMIs.push_back(MemMI);
163 }
164
165 // Transfer LiveVariables states, kill / dead info.
166 if (LV) {
167 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
168 MachineOperand &MO = MI->getOperand(i);
169 if (MO.isReg() && MO.getReg() &&
170 TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
171 unsigned Reg = MO.getReg();
172
173 LiveVariables::VarInfo &VI = LV->getVarInfo(Reg);
174 if (MO.isDef()) {
175 MachineInstr *NewMI = (Reg == WBReg) ? UpdateMI : MemMI;
176 if (MO.isDead())
177 LV->addVirtualRegisterDead(Reg, NewMI);
178 }
179 if (MO.isUse() && MO.isKill()) {
180 for (unsigned j = 0; j < 2; ++j) {
181 // Look at the two new MI's in reverse order.
182 MachineInstr *NewMI = NewMIs[j];
183 if (!NewMI->readsRegister(Reg))
184 continue;
185 LV->addVirtualRegisterKilled(Reg, NewMI);
186 if (VI.removeKill(MI))
187 VI.Kills.push_back(NewMI);
188 break;
189 }
190 }
191 }
192 }
193 }
194
195 MFI->insert(MBBI, NewMIs[1]);
196 MFI->insert(MBBI, NewMIs[0]);
197 return NewMIs[0];
198}
199
Evan Cheng2457f2c2010-05-22 01:47:14 +0000200bool
201ARMBaseInstrInfo::spillCalleeSavedRegisters(MachineBasicBlock &MBB,
Jim Grosbach18f30e62010-06-02 21:53:11 +0000202 MachineBasicBlock::iterator MI,
203 const std::vector<CalleeSavedInfo> &CSI,
204 const TargetRegisterInfo *TRI) const {
Evan Cheng2457f2c2010-05-22 01:47:14 +0000205 if (CSI.empty())
206 return false;
207
208 DebugLoc DL;
209 if (MI != MBB.end()) DL = MI->getDebugLoc();
210
Eric Christopher391f2282010-11-11 19:26:03 +0000211 MachineInstrBuilder MIB = BuildMI(MBB, MI, DL, get(ARM::tPUSH));
212 AddDefaultPred(MIB);
213 for (unsigned i = CSI.size(); i != 0; --i) {
214 unsigned Reg = CSI[i-1].getReg();
Evan Cheng2457f2c2010-05-22 01:47:14 +0000215 bool isKill = true;
216
217 // Add the callee-saved register as live-in unless it's LR and
218 // @llvm.returnaddress is called. If LR is returned for @llvm.returnaddress
219 // then it's already added to the function and entry block live-in sets.
220 if (Reg == ARM::LR) {
221 MachineFunction &MF = *MBB.getParent();
222 if (MF.getFrameInfo()->isReturnAddressTaken() &&
223 MF.getRegInfo().isLiveIn(Reg))
224 isKill = false;
225 }
226
227 if (isKill)
228 MBB.addLiveIn(Reg);
229
Eric Christopher391f2282010-11-11 19:26:03 +0000230 if (!isARMPushRegister(Reg)) {
231 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
232 storeRegToStackSlot(MBB, MI, Reg, isKill,
233 CSI[i-1].getFrameIdx(), RC, TRI);
234 } else
235 MIB.addReg(Reg, getKillRegState(isKill));
Evan Cheng2457f2c2010-05-22 01:47:14 +0000236 }
237 return true;
238}
239
Eric Christopher391f2282010-11-11 19:26:03 +0000240bool
241ARMBaseInstrInfo::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
242 MachineBasicBlock::iterator MI,
243 const std::vector<CalleeSavedInfo> &CSI,
244 const TargetRegisterInfo *TRI) const {
245 MachineFunction &MF = *MBB.getParent();
246 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
247 if (CSI.empty())
248 return false;
249
250 bool isVarArg = AFI->getVarArgsRegSaveSize() > 0;
251 DebugLoc DL = MI->getDebugLoc();
252 MachineInstrBuilder MIB = BuildMI(MF, DL, get(ARM::tPOP));
253 AddDefaultPred(MIB);
254
255 bool NumRegs = false;
256 for (unsigned i = CSI.size(); i != 0; --i) {
257 unsigned Reg = CSI[i-1].getReg();
258 if (Reg == ARM::LR && !isVarArg) {
259 Reg = ARM::PC;
260 (*MIB).setDesc(get(ARM::tPOP_RET));
261 MI = MBB.erase(MI);
262 }
263
264 if (!isARMPushRegister(Reg)) {
265 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
266 loadRegFromStackSlot(MBB, MI, Reg, CSI[i-1].getFrameIdx(), RC, TRI);
267 } else
268 MIB.addReg(Reg, getDefRegState(true));
269 NumRegs = true;
270 }
271
272 // It's illegal to emit pop instruction without operands.
273 if (NumRegs)
274 MBB.insert(MI, &*MIB);
275 else
276 MF.DeleteMachineInstr(MIB);
277
278 return true;
279}
280
281
David Goodwin334c2642009-07-08 16:09:28 +0000282// Branch analysis.
283bool
284ARMBaseInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
285 MachineBasicBlock *&FBB,
286 SmallVectorImpl<MachineOperand> &Cond,
287 bool AllowModify) const {
288 // If the block has no terminators, it just falls into the block after it.
289 MachineBasicBlock::iterator I = MBB.end();
Dale Johannesen93d6a7e2010-04-02 01:38:09 +0000290 if (I == MBB.begin())
291 return false;
292 --I;
293 while (I->isDebugValue()) {
294 if (I == MBB.begin())
295 return false;
296 --I;
297 }
298 if (!isUnpredicatedTerminator(I))
David Goodwin334c2642009-07-08 16:09:28 +0000299 return false;
300
301 // Get the last instruction in the block.
302 MachineInstr *LastInst = I;
303
304 // If there is only one terminator instruction, process it.
305 unsigned LastOpc = LastInst->getOpcode();
306 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
Evan Cheng5ca53a72009-07-27 18:20:05 +0000307 if (isUncondBranchOpcode(LastOpc)) {
David Goodwin334c2642009-07-08 16:09:28 +0000308 TBB = LastInst->getOperand(0).getMBB();
309 return false;
310 }
Evan Cheng5ca53a72009-07-27 18:20:05 +0000311 if (isCondBranchOpcode(LastOpc)) {
David Goodwin334c2642009-07-08 16:09:28 +0000312 // Block ends with fall-through condbranch.
313 TBB = LastInst->getOperand(0).getMBB();
314 Cond.push_back(LastInst->getOperand(1));
315 Cond.push_back(LastInst->getOperand(2));
316 return false;
317 }
318 return true; // Can't handle indirect branch.
319 }
320
321 // Get the instruction before it if it is a terminator.
322 MachineInstr *SecondLastInst = I;
Evan Cheng108c8722010-09-23 06:54:40 +0000323 unsigned SecondLastOpc = SecondLastInst->getOpcode();
324
325 // If AllowModify is true and the block ends with two or more unconditional
326 // branches, delete all but the first unconditional branch.
327 if (AllowModify && isUncondBranchOpcode(LastOpc)) {
328 while (isUncondBranchOpcode(SecondLastOpc)) {
329 LastInst->eraseFromParent();
330 LastInst = SecondLastInst;
331 LastOpc = LastInst->getOpcode();
Evan Cheng676e2582010-09-23 19:42:03 +0000332 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
333 // Return now the only terminator is an unconditional branch.
334 TBB = LastInst->getOperand(0).getMBB();
335 return false;
336 } else {
Evan Cheng108c8722010-09-23 06:54:40 +0000337 SecondLastInst = I;
338 SecondLastOpc = SecondLastInst->getOpcode();
339 }
340 }
341 }
David Goodwin334c2642009-07-08 16:09:28 +0000342
343 // If there are three terminators, we don't know what sort of block this is.
344 if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(--I))
345 return true;
346
Evan Cheng5ca53a72009-07-27 18:20:05 +0000347 // If the block ends with a B and a Bcc, handle it.
Evan Cheng5ca53a72009-07-27 18:20:05 +0000348 if (isCondBranchOpcode(SecondLastOpc) && isUncondBranchOpcode(LastOpc)) {
David Goodwin334c2642009-07-08 16:09:28 +0000349 TBB = SecondLastInst->getOperand(0).getMBB();
350 Cond.push_back(SecondLastInst->getOperand(1));
351 Cond.push_back(SecondLastInst->getOperand(2));
352 FBB = LastInst->getOperand(0).getMBB();
353 return false;
354 }
355
356 // If the block ends with two unconditional branches, handle it. The second
357 // one is not executed, so remove it.
Evan Cheng5ca53a72009-07-27 18:20:05 +0000358 if (isUncondBranchOpcode(SecondLastOpc) && isUncondBranchOpcode(LastOpc)) {
David Goodwin334c2642009-07-08 16:09:28 +0000359 TBB = SecondLastInst->getOperand(0).getMBB();
360 I = LastInst;
361 if (AllowModify)
362 I->eraseFromParent();
363 return false;
364 }
365
366 // ...likewise if it ends with a branch table followed by an unconditional
367 // branch. The branch folder can create these, and we must get rid of them for
368 // correctness of Thumb constant islands.
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000369 if ((isJumpTableBranchOpcode(SecondLastOpc) ||
370 isIndirectBranchOpcode(SecondLastOpc)) &&
Evan Cheng5ca53a72009-07-27 18:20:05 +0000371 isUncondBranchOpcode(LastOpc)) {
David Goodwin334c2642009-07-08 16:09:28 +0000372 I = LastInst;
373 if (AllowModify)
374 I->eraseFromParent();
375 return true;
376 }
377
378 // Otherwise, can't handle this.
379 return true;
380}
381
382
383unsigned ARMBaseInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
David Goodwin334c2642009-07-08 16:09:28 +0000384 MachineBasicBlock::iterator I = MBB.end();
385 if (I == MBB.begin()) return 0;
386 --I;
Dale Johannesen93d6a7e2010-04-02 01:38:09 +0000387 while (I->isDebugValue()) {
388 if (I == MBB.begin())
389 return 0;
390 --I;
391 }
Evan Cheng5ca53a72009-07-27 18:20:05 +0000392 if (!isUncondBranchOpcode(I->getOpcode()) &&
393 !isCondBranchOpcode(I->getOpcode()))
David Goodwin334c2642009-07-08 16:09:28 +0000394 return 0;
395
396 // Remove the branch.
397 I->eraseFromParent();
398
399 I = MBB.end();
400
401 if (I == MBB.begin()) return 1;
402 --I;
Evan Cheng5ca53a72009-07-27 18:20:05 +0000403 if (!isCondBranchOpcode(I->getOpcode()))
David Goodwin334c2642009-07-08 16:09:28 +0000404 return 1;
405
406 // Remove the branch.
407 I->eraseFromParent();
408 return 2;
409}
410
411unsigned
412ARMBaseInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000413 MachineBasicBlock *FBB,
414 const SmallVectorImpl<MachineOperand> &Cond,
415 DebugLoc DL) const {
Evan Cheng6495f632009-07-28 05:48:47 +0000416 ARMFunctionInfo *AFI = MBB.getParent()->getInfo<ARMFunctionInfo>();
417 int BOpc = !AFI->isThumbFunction()
418 ? ARM::B : (AFI->isThumb2Function() ? ARM::t2B : ARM::tB);
419 int BccOpc = !AFI->isThumbFunction()
420 ? ARM::Bcc : (AFI->isThumb2Function() ? ARM::t2Bcc : ARM::tBcc);
David Goodwin334c2642009-07-08 16:09:28 +0000421
422 // Shouldn't be a fall through.
423 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
424 assert((Cond.size() == 2 || Cond.size() == 0) &&
425 "ARM branch conditions have two components!");
426
427 if (FBB == 0) {
428 if (Cond.empty()) // Unconditional branch?
Stuart Hastings3bf91252010-06-17 22:43:56 +0000429 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
David Goodwin334c2642009-07-08 16:09:28 +0000430 else
Stuart Hastings3bf91252010-06-17 22:43:56 +0000431 BuildMI(&MBB, DL, get(BccOpc)).addMBB(TBB)
David Goodwin334c2642009-07-08 16:09:28 +0000432 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg());
433 return 1;
434 }
435
436 // Two-way conditional branch.
Stuart Hastings3bf91252010-06-17 22:43:56 +0000437 BuildMI(&MBB, DL, get(BccOpc)).addMBB(TBB)
David Goodwin334c2642009-07-08 16:09:28 +0000438 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg());
Stuart Hastings3bf91252010-06-17 22:43:56 +0000439 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
David Goodwin334c2642009-07-08 16:09:28 +0000440 return 2;
441}
442
443bool ARMBaseInstrInfo::
444ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
445 ARMCC::CondCodes CC = (ARMCC::CondCodes)(int)Cond[0].getImm();
446 Cond[0].setImm(ARMCC::getOppositeCondition(CC));
447 return false;
448}
449
David Goodwin334c2642009-07-08 16:09:28 +0000450bool ARMBaseInstrInfo::
451PredicateInstruction(MachineInstr *MI,
452 const SmallVectorImpl<MachineOperand> &Pred) const {
453 unsigned Opc = MI->getOpcode();
Evan Cheng5ca53a72009-07-27 18:20:05 +0000454 if (isUncondBranchOpcode(Opc)) {
455 MI->setDesc(get(getMatchingCondBranchOpcode(Opc)));
David Goodwin334c2642009-07-08 16:09:28 +0000456 MI->addOperand(MachineOperand::CreateImm(Pred[0].getImm()));
457 MI->addOperand(MachineOperand::CreateReg(Pred[1].getReg(), false));
458 return true;
459 }
460
461 int PIdx = MI->findFirstPredOperandIdx();
462 if (PIdx != -1) {
463 MachineOperand &PMO = MI->getOperand(PIdx);
464 PMO.setImm(Pred[0].getImm());
465 MI->getOperand(PIdx+1).setReg(Pred[1].getReg());
466 return true;
467 }
468 return false;
469}
470
471bool ARMBaseInstrInfo::
472SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
473 const SmallVectorImpl<MachineOperand> &Pred2) const {
474 if (Pred1.size() > 2 || Pred2.size() > 2)
475 return false;
476
477 ARMCC::CondCodes CC1 = (ARMCC::CondCodes)Pred1[0].getImm();
478 ARMCC::CondCodes CC2 = (ARMCC::CondCodes)Pred2[0].getImm();
479 if (CC1 == CC2)
480 return true;
481
482 switch (CC1) {
483 default:
484 return false;
485 case ARMCC::AL:
486 return true;
487 case ARMCC::HS:
488 return CC2 == ARMCC::HI;
489 case ARMCC::LS:
490 return CC2 == ARMCC::LO || CC2 == ARMCC::EQ;
491 case ARMCC::GE:
492 return CC2 == ARMCC::GT;
493 case ARMCC::LE:
494 return CC2 == ARMCC::LT;
495 }
496}
497
498bool ARMBaseInstrInfo::DefinesPredicate(MachineInstr *MI,
499 std::vector<MachineOperand> &Pred) const {
Evan Cheng8fb90362009-08-08 03:20:32 +0000500 // FIXME: This confuses implicit_def with optional CPSR def.
David Goodwin334c2642009-07-08 16:09:28 +0000501 const TargetInstrDesc &TID = MI->getDesc();
502 if (!TID.getImplicitDefs() && !TID.hasOptionalDef())
503 return false;
504
505 bool Found = false;
506 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
507 const MachineOperand &MO = MI->getOperand(i);
508 if (MO.isReg() && MO.getReg() == ARM::CPSR) {
509 Pred.push_back(MO);
510 Found = true;
511 }
512 }
513
514 return Found;
515}
516
Evan Chengac0869d2009-11-21 06:21:52 +0000517/// isPredicable - Return true if the specified instruction can be predicated.
518/// By default, this returns true for every instruction with a
519/// PredicateOperand.
520bool ARMBaseInstrInfo::isPredicable(MachineInstr *MI) const {
521 const TargetInstrDesc &TID = MI->getDesc();
522 if (!TID.isPredicable())
523 return false;
524
525 if ((TID.TSFlags & ARMII::DomainMask) == ARMII::DomainNEON) {
526 ARMFunctionInfo *AFI =
527 MI->getParent()->getParent()->getInfo<ARMFunctionInfo>();
Evan Chengd7f08102009-11-24 08:06:15 +0000528 return AFI->isThumb2Function();
Evan Chengac0869d2009-11-21 06:21:52 +0000529 }
530 return true;
531}
David Goodwin334c2642009-07-08 16:09:28 +0000532
Chris Lattner56856b12009-12-03 06:58:32 +0000533/// FIXME: Works around a gcc miscompilation with -fstrict-aliasing.
Chandler Carruth19e57022010-10-23 08:40:19 +0000534LLVM_ATTRIBUTE_NOINLINE
David Goodwin334c2642009-07-08 16:09:28 +0000535static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT,
Chris Lattner56856b12009-12-03 06:58:32 +0000536 unsigned JTI);
David Goodwin334c2642009-07-08 16:09:28 +0000537static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT,
538 unsigned JTI) {
Chris Lattner56856b12009-12-03 06:58:32 +0000539 assert(JTI < JT.size());
David Goodwin334c2642009-07-08 16:09:28 +0000540 return JT[JTI].MBBs.size();
541}
542
543/// GetInstSize - Return the size of the specified MachineInstr.
544///
545unsigned ARMBaseInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const {
546 const MachineBasicBlock &MBB = *MI->getParent();
547 const MachineFunction *MF = MBB.getParent();
Chris Lattner33adcfb2009-08-22 21:43:10 +0000548 const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo();
David Goodwin334c2642009-07-08 16:09:28 +0000549
550 // Basic size info comes from the TSFlags field.
551 const TargetInstrDesc &TID = MI->getDesc();
Bruno Cardoso Lopes99405df2010-06-08 22:51:23 +0000552 uint64_t TSFlags = TID.TSFlags;
David Goodwin334c2642009-07-08 16:09:28 +0000553
Evan Chenga0ee8622009-07-31 22:22:22 +0000554 unsigned Opc = MI->getOpcode();
David Goodwin334c2642009-07-08 16:09:28 +0000555 switch ((TSFlags & ARMII::SizeMask) >> ARMII::SizeShift) {
556 default: {
557 // If this machine instr is an inline asm, measure it.
558 if (MI->getOpcode() == ARM::INLINEASM)
Chris Lattner33adcfb2009-08-22 21:43:10 +0000559 return getInlineAsmLength(MI->getOperand(0).getSymbolName(), *MAI);
David Goodwin334c2642009-07-08 16:09:28 +0000560 if (MI->isLabel())
561 return 0;
Evan Chenga0ee8622009-07-31 22:22:22 +0000562 switch (Opc) {
David Goodwin334c2642009-07-08 16:09:28 +0000563 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000564 llvm_unreachable("Unknown or unset size field for instr!");
Chris Lattner518bb532010-02-09 19:54:29 +0000565 case TargetOpcode::IMPLICIT_DEF:
566 case TargetOpcode::KILL:
Bill Wendling7431bea2010-07-16 22:20:36 +0000567 case TargetOpcode::PROLOG_LABEL:
Chris Lattner518bb532010-02-09 19:54:29 +0000568 case TargetOpcode::EH_LABEL:
Dale Johannesen375be772010-04-07 19:51:44 +0000569 case TargetOpcode::DBG_VALUE:
David Goodwin334c2642009-07-08 16:09:28 +0000570 return 0;
571 }
572 break;
573 }
Evan Cheng78947622009-07-24 18:20:44 +0000574 case ARMII::Size8Bytes: return 8; // ARM instruction x 2.
575 case ARMII::Size4Bytes: return 4; // ARM / Thumb2 instruction.
576 case ARMII::Size2Bytes: return 2; // Thumb1 instruction.
David Goodwin334c2642009-07-08 16:09:28 +0000577 case ARMII::SizeSpecial: {
Evan Chenga0ee8622009-07-31 22:22:22 +0000578 switch (Opc) {
Jim Grosbach3c38f962010-10-06 22:01:26 +0000579 case ARM::MOVi32imm:
580 case ARM::t2MOVi32imm:
581 return 8;
David Goodwin334c2642009-07-08 16:09:28 +0000582 case ARM::CONSTPOOL_ENTRY:
583 // If this machine instr is a constant pool entry, its size is recorded as
584 // operand #2.
585 return MI->getOperand(2).getImm();
Jim Grosbach5eb19512010-05-22 01:06:18 +0000586 case ARM::Int_eh_sjlj_longjmp:
587 return 16;
588 case ARM::tInt_eh_sjlj_longjmp:
589 return 10;
Evan Cheng78947622009-07-24 18:20:44 +0000590 case ARM::Int_eh_sjlj_setjmp:
Jim Grosbachd1007552010-04-28 20:33:09 +0000591 case ARM::Int_eh_sjlj_setjmp_nofp:
Jim Grosbach0798edd2010-05-27 23:49:24 +0000592 return 20;
Jim Grosbachd1228742009-12-01 18:10:36 +0000593 case ARM::tInt_eh_sjlj_setjmp:
Jim Grosbach5aa16842009-08-11 19:42:21 +0000594 case ARM::t2Int_eh_sjlj_setjmp:
Jim Grosbachd1007552010-04-28 20:33:09 +0000595 case ARM::t2Int_eh_sjlj_setjmp_nofp:
Jim Grosbach0798edd2010-05-27 23:49:24 +0000596 return 12;
David Goodwin334c2642009-07-08 16:09:28 +0000597 case ARM::BR_JTr:
598 case ARM::BR_JTm:
599 case ARM::BR_JTadd:
Evan Chenga0ee8622009-07-31 22:22:22 +0000600 case ARM::tBR_JTr:
Evan Chengd26b14c2009-07-31 18:28:05 +0000601 case ARM::t2BR_JT:
602 case ARM::t2TBB:
603 case ARM::t2TBH: {
David Goodwin334c2642009-07-08 16:09:28 +0000604 // These are jumptable branches, i.e. a branch followed by an inlined
Evan Chengd26b14c2009-07-31 18:28:05 +0000605 // jumptable. The size is 4 + 4 * number of entries. For TBB, each
606 // entry is one byte; TBH two byte each.
Evan Chenga0ee8622009-07-31 22:22:22 +0000607 unsigned EntrySize = (Opc == ARM::t2TBB)
608 ? 1 : ((Opc == ARM::t2TBH) ? 2 : 4);
David Goodwin334c2642009-07-08 16:09:28 +0000609 unsigned NumOps = TID.getNumOperands();
610 MachineOperand JTOP =
611 MI->getOperand(NumOps - (TID.isPredicable() ? 3 : 2));
612 unsigned JTI = JTOP.getIndex();
613 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
Chris Lattnerb1e80392010-01-25 23:22:00 +0000614 assert(MJTI != 0);
David Goodwin334c2642009-07-08 16:09:28 +0000615 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
616 assert(JTI < JT.size());
617 // Thumb instructions are 2 byte aligned, but JT entries are 4 byte
618 // 4 aligned. The assembler / linker may add 2 byte padding just before
619 // the JT entries. The size does not include this padding; the
620 // constant islands pass does separate bookkeeping for it.
621 // FIXME: If we know the size of the function is less than (1 << 16) *2
622 // bytes, we can use 16-bit entries instead. Then there won't be an
623 // alignment issue.
Evan Cheng25f7cfc2009-08-01 06:13:52 +0000624 unsigned InstSize = (Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT) ? 2 : 4;
625 unsigned NumEntries = getNumJTEntries(JT, JTI);
626 if (Opc == ARM::t2TBB && (NumEntries & 1))
627 // Make sure the instruction that follows TBB is 2-byte aligned.
628 // FIXME: Constant island pass should insert an "ALIGN" instruction
629 // instead.
630 ++NumEntries;
631 return NumEntries * EntrySize + InstSize;
David Goodwin334c2642009-07-08 16:09:28 +0000632 }
633 default:
634 // Otherwise, pseudo-instruction sizes are zero.
635 return 0;
636 }
637 }
638 }
639 return 0; // Not reached
640}
641
Jakob Stoklund Olesenac273662010-07-11 06:33:54 +0000642void ARMBaseInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
643 MachineBasicBlock::iterator I, DebugLoc DL,
644 unsigned DestReg, unsigned SrcReg,
645 bool KillSrc) const {
646 bool GPRDest = ARM::GPRRegClass.contains(DestReg);
647 bool GPRSrc = ARM::GPRRegClass.contains(SrcReg);
Bob Wilson1665b0a2010-02-16 17:24:15 +0000648
Jakob Stoklund Olesenac273662010-07-11 06:33:54 +0000649 if (GPRDest && GPRSrc) {
650 AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::MOVr), DestReg)
651 .addReg(SrcReg, getKillRegState(KillSrc))));
652 return;
David Goodwin7bfdca02009-08-05 21:02:22 +0000653 }
David Goodwin334c2642009-07-08 16:09:28 +0000654
Jakob Stoklund Olesenac273662010-07-11 06:33:54 +0000655 bool SPRDest = ARM::SPRRegClass.contains(DestReg);
656 bool SPRSrc = ARM::SPRRegClass.contains(SrcReg);
657
658 unsigned Opc;
659 if (SPRDest && SPRSrc)
660 Opc = ARM::VMOVS;
661 else if (GPRDest && SPRSrc)
662 Opc = ARM::VMOVRS;
663 else if (SPRDest && GPRSrc)
664 Opc = ARM::VMOVSR;
665 else if (ARM::DPRRegClass.contains(DestReg, SrcReg))
666 Opc = ARM::VMOVD;
667 else if (ARM::QPRRegClass.contains(DestReg, SrcReg))
668 Opc = ARM::VMOVQ;
669 else if (ARM::QQPRRegClass.contains(DestReg, SrcReg))
670 Opc = ARM::VMOVQQ;
671 else if (ARM::QQQQPRRegClass.contains(DestReg, SrcReg))
672 Opc = ARM::VMOVQQQQ;
673 else
674 llvm_unreachable("Impossible reg-to-reg copy");
675
676 MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(Opc), DestReg);
677 MIB.addReg(SrcReg, getKillRegState(KillSrc));
678 if (Opc != ARM::VMOVQQ && Opc != ARM::VMOVQQQQ)
679 AddDefaultPred(MIB);
David Goodwin334c2642009-07-08 16:09:28 +0000680}
681
Evan Chengc10b5af2010-05-07 00:24:52 +0000682static const
683MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB,
684 unsigned Reg, unsigned SubIdx, unsigned State,
685 const TargetRegisterInfo *TRI) {
686 if (!SubIdx)
687 return MIB.addReg(Reg, State);
688
689 if (TargetRegisterInfo::isPhysicalRegister(Reg))
690 return MIB.addReg(TRI->getSubReg(Reg, SubIdx), State);
691 return MIB.addReg(Reg, State, SubIdx);
692}
693
David Goodwin334c2642009-07-08 16:09:28 +0000694void ARMBaseInstrInfo::
695storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
696 unsigned SrcReg, bool isKill, int FI,
Evan Cheng746ad692010-05-06 19:06:44 +0000697 const TargetRegisterClass *RC,
698 const TargetRegisterInfo *TRI) const {
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000699 DebugLoc DL;
David Goodwin334c2642009-07-08 16:09:28 +0000700 if (I != MBB.end()) DL = I->getDebugLoc();
Anton Korobeynikov249fb332009-10-07 00:06:35 +0000701 MachineFunction &MF = *MBB.getParent();
702 MachineFrameInfo &MFI = *MF.getFrameInfo();
Jim Grosbach31bc8492009-11-08 00:27:19 +0000703 unsigned Align = MFI.getObjectAlignment(FI);
Anton Korobeynikov249fb332009-10-07 00:06:35 +0000704
705 MachineMemOperand *MMO =
Chris Lattner59db5492010-09-21 04:39:43 +0000706 MF.getMachineMemOperand(MachinePointerInfo(
707 PseudoSourceValue::getFixedStack(FI)),
708 MachineMemOperand::MOStore,
Anton Korobeynikov249fb332009-10-07 00:06:35 +0000709 MFI.getObjectSize(FI),
Jim Grosbach31bc8492009-11-08 00:27:19 +0000710 Align);
David Goodwin334c2642009-07-08 16:09:28 +0000711
Bob Wilson0eb0c742010-02-16 22:01:59 +0000712 // tGPR is used sometimes in ARM instructions that need to avoid using
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000713 // certain registers. Just treat it as GPR here. Likewise, rGPR.
714 if (RC == ARM::tGPRRegisterClass || RC == ARM::tcGPRRegisterClass
715 || RC == ARM::rGPRRegisterClass)
Bob Wilson0eb0c742010-02-16 22:01:59 +0000716 RC = ARM::GPRRegisterClass;
717
Bob Wilsonebe99b22010-06-18 21:32:42 +0000718 switch (RC->getID()) {
719 case ARM::GPRRegClassID:
Jim Grosbach7e3383c2010-10-27 23:12:14 +0000720 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::STRi12))
David Goodwin334c2642009-07-08 16:09:28 +0000721 .addReg(SrcReg, getKillRegState(isKill))
Jim Grosbach7e3383c2010-10-27 23:12:14 +0000722 .addFrameIndex(FI).addImm(0).addMemOperand(MMO));
Bob Wilsonebe99b22010-06-18 21:32:42 +0000723 break;
724 case ARM::SPRRegClassID:
Evan Chengd31c5492010-05-06 01:34:11 +0000725 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRS))
726 .addReg(SrcReg, getKillRegState(isKill))
727 .addFrameIndex(FI).addImm(0).addMemOperand(MMO));
Bob Wilsonebe99b22010-06-18 21:32:42 +0000728 break;
729 case ARM::DPRRegClassID:
730 case ARM::DPR_VFP2RegClassID:
731 case ARM::DPR_8RegClassID:
Jim Grosbache5165492009-11-09 00:11:35 +0000732 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRD))
David Goodwin334c2642009-07-08 16:09:28 +0000733 .addReg(SrcReg, getKillRegState(isKill))
Anton Korobeynikov249fb332009-10-07 00:06:35 +0000734 .addFrameIndex(FI).addImm(0).addMemOperand(MMO));
Bob Wilsonebe99b22010-06-18 21:32:42 +0000735 break;
736 case ARM::QPRRegClassID:
737 case ARM::QPR_VFP2RegClassID:
738 case ARM::QPR_8RegClassID:
Jim Grosbach0cfcf932010-09-08 00:26:59 +0000739 if (Align >= 16 && getRegisterInfo().needsStackRealignment(MF)) {
Bob Wilson168f3822010-09-15 01:48:05 +0000740 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VST1q64Pseudo))
Bob Wilsonf967ca02010-07-06 21:26:18 +0000741 .addFrameIndex(FI).addImm(16)
Evan Cheng69b9f982010-05-13 01:12:06 +0000742 .addReg(SrcReg, getKillRegState(isKill))
743 .addMemOperand(MMO));
Jim Grosbach31bc8492009-11-08 00:27:19 +0000744 } else {
Evan Cheng69b9f982010-05-13 01:12:06 +0000745 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMQ))
746 .addReg(SrcReg, getKillRegState(isKill))
747 .addFrameIndex(FI)
Bob Wilsond4bfd542010-08-27 23:18:17 +0000748 .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia))
Evan Cheng69b9f982010-05-13 01:12:06 +0000749 .addMemOperand(MMO));
Jim Grosbach31bc8492009-11-08 00:27:19 +0000750 }
Bob Wilsonebe99b22010-06-18 21:32:42 +0000751 break;
752 case ARM::QQPRRegClassID:
753 case ARM::QQPR_VFP2RegClassID:
Evan Cheng435d4992010-05-07 02:04:02 +0000754 if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) {
Evan Cheng22c687b2010-05-14 02:13:41 +0000755 // FIXME: It's possible to only store part of the QQ register if the
756 // spilled def has a sub-register index.
Bob Wilson168f3822010-09-15 01:48:05 +0000757 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VST1d64QPseudo))
758 .addFrameIndex(FI).addImm(16)
759 .addReg(SrcReg, getKillRegState(isKill))
760 .addMemOperand(MMO));
Evan Cheng435d4992010-05-07 02:04:02 +0000761 } else {
762 MachineInstrBuilder MIB =
763 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMD))
764 .addFrameIndex(FI)
Bob Wilsond4bfd542010-08-27 23:18:17 +0000765 .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia)))
Evan Cheng435d4992010-05-07 02:04:02 +0000766 .addMemOperand(MMO);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000767 MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI);
768 MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI);
769 MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI);
770 AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI);
Evan Cheng435d4992010-05-07 02:04:02 +0000771 }
Bob Wilsonebe99b22010-06-18 21:32:42 +0000772 break;
773 case ARM::QQQQPRRegClassID: {
Evan Cheng22c687b2010-05-14 02:13:41 +0000774 MachineInstrBuilder MIB =
775 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMD))
776 .addFrameIndex(FI)
Bob Wilsond4bfd542010-08-27 23:18:17 +0000777 .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia)))
Evan Cheng22c687b2010-05-14 02:13:41 +0000778 .addMemOperand(MMO);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000779 MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI);
780 MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI);
781 MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI);
782 MIB = AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI);
783 MIB = AddDReg(MIB, SrcReg, ARM::dsub_4, 0, TRI);
784 MIB = AddDReg(MIB, SrcReg, ARM::dsub_5, 0, TRI);
785 MIB = AddDReg(MIB, SrcReg, ARM::dsub_6, 0, TRI);
786 AddDReg(MIB, SrcReg, ARM::dsub_7, 0, TRI);
Bob Wilsonebe99b22010-06-18 21:32:42 +0000787 break;
788 }
789 default:
790 llvm_unreachable("Unknown regclass!");
David Goodwin334c2642009-07-08 16:09:28 +0000791 }
792}
793
Jakob Stoklund Olesen34327852010-09-15 16:36:26 +0000794unsigned
795ARMBaseInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
796 int &FrameIndex) const {
797 switch (MI->getOpcode()) {
798 default: break;
Jim Grosbach7e3383c2010-10-27 23:12:14 +0000799 case ARM::STRrs:
Jakob Stoklund Olesen34327852010-09-15 16:36:26 +0000800 case ARM::t2STRs: // FIXME: don't use t2STRs to access frame.
801 if (MI->getOperand(1).isFI() &&
802 MI->getOperand(2).isReg() &&
803 MI->getOperand(3).isImm() &&
804 MI->getOperand(2).getReg() == 0 &&
805 MI->getOperand(3).getImm() == 0) {
806 FrameIndex = MI->getOperand(1).getIndex();
807 return MI->getOperand(0).getReg();
808 }
809 break;
Jim Grosbach7e3383c2010-10-27 23:12:14 +0000810 case ARM::STRi12:
Jakob Stoklund Olesen34327852010-09-15 16:36:26 +0000811 case ARM::t2STRi12:
812 case ARM::tSpill:
813 case ARM::VSTRD:
814 case ARM::VSTRS:
815 if (MI->getOperand(1).isFI() &&
816 MI->getOperand(2).isImm() &&
817 MI->getOperand(2).getImm() == 0) {
818 FrameIndex = MI->getOperand(1).getIndex();
819 return MI->getOperand(0).getReg();
820 }
821 break;
Jakob Stoklund Olesend64816a2010-09-15 17:27:09 +0000822 case ARM::VST1q64Pseudo:
823 if (MI->getOperand(0).isFI() &&
824 MI->getOperand(2).getSubReg() == 0) {
825 FrameIndex = MI->getOperand(0).getIndex();
826 return MI->getOperand(2).getReg();
827 }
Jakob Stoklund Olesen31bbc512010-09-15 21:40:09 +0000828 break;
Jakob Stoklund Olesend64816a2010-09-15 17:27:09 +0000829 case ARM::VSTMQ:
830 if (MI->getOperand(1).isFI() &&
831 MI->getOperand(2).isImm() &&
832 MI->getOperand(2).getImm() == ARM_AM::getAM4ModeImm(ARM_AM::ia) &&
833 MI->getOperand(0).getSubReg() == 0) {
834 FrameIndex = MI->getOperand(1).getIndex();
835 return MI->getOperand(0).getReg();
836 }
837 break;
Jakob Stoklund Olesen34327852010-09-15 16:36:26 +0000838 }
839
840 return 0;
841}
842
David Goodwin334c2642009-07-08 16:09:28 +0000843void ARMBaseInstrInfo::
844loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
845 unsigned DestReg, int FI,
Evan Cheng746ad692010-05-06 19:06:44 +0000846 const TargetRegisterClass *RC,
847 const TargetRegisterInfo *TRI) const {
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000848 DebugLoc DL;
David Goodwin334c2642009-07-08 16:09:28 +0000849 if (I != MBB.end()) DL = I->getDebugLoc();
Anton Korobeynikov249fb332009-10-07 00:06:35 +0000850 MachineFunction &MF = *MBB.getParent();
851 MachineFrameInfo &MFI = *MF.getFrameInfo();
Jim Grosbach31bc8492009-11-08 00:27:19 +0000852 unsigned Align = MFI.getObjectAlignment(FI);
Anton Korobeynikov249fb332009-10-07 00:06:35 +0000853 MachineMemOperand *MMO =
Chris Lattner59db5492010-09-21 04:39:43 +0000854 MF.getMachineMemOperand(
855 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
856 MachineMemOperand::MOLoad,
Anton Korobeynikov249fb332009-10-07 00:06:35 +0000857 MFI.getObjectSize(FI),
Jim Grosbach31bc8492009-11-08 00:27:19 +0000858 Align);
David Goodwin334c2642009-07-08 16:09:28 +0000859
Bob Wilson0eb0c742010-02-16 22:01:59 +0000860 // tGPR is used sometimes in ARM instructions that need to avoid using
861 // certain registers. Just treat it as GPR here.
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000862 if (RC == ARM::tGPRRegisterClass || RC == ARM::tcGPRRegisterClass
863 || RC == ARM::rGPRRegisterClass)
Bob Wilson0eb0c742010-02-16 22:01:59 +0000864 RC = ARM::GPRRegisterClass;
865
Bob Wilsonebe99b22010-06-18 21:32:42 +0000866 switch (RC->getID()) {
867 case ARM::GPRRegClassID:
Jim Grosbach3e556122010-10-26 22:37:02 +0000868 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::LDRi12), DestReg)
869 .addFrameIndex(FI).addImm(0).addMemOperand(MMO));
Bob Wilsonebe99b22010-06-18 21:32:42 +0000870 break;
871 case ARM::SPRRegClassID:
Evan Chengd31c5492010-05-06 01:34:11 +0000872 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRS), DestReg)
873 .addFrameIndex(FI).addImm(0).addMemOperand(MMO));
Bob Wilsonebe99b22010-06-18 21:32:42 +0000874 break;
875 case ARM::DPRRegClassID:
876 case ARM::DPR_VFP2RegClassID:
877 case ARM::DPR_8RegClassID:
Jim Grosbache5165492009-11-09 00:11:35 +0000878 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRD), DestReg)
Anton Korobeynikov249fb332009-10-07 00:06:35 +0000879 .addFrameIndex(FI).addImm(0).addMemOperand(MMO));
Bob Wilsonebe99b22010-06-18 21:32:42 +0000880 break;
881 case ARM::QPRRegClassID:
882 case ARM::QPR_VFP2RegClassID:
883 case ARM::QPR_8RegClassID:
Jim Grosbach0cfcf932010-09-08 00:26:59 +0000884 if (Align >= 16 && getRegisterInfo().needsStackRealignment(MF)) {
Bob Wilson168f3822010-09-15 01:48:05 +0000885 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLD1q64Pseudo), DestReg)
Bob Wilsonf967ca02010-07-06 21:26:18 +0000886 .addFrameIndex(FI).addImm(16)
Evan Cheng69b9f982010-05-13 01:12:06 +0000887 .addMemOperand(MMO));
Jim Grosbach31bc8492009-11-08 00:27:19 +0000888 } else {
Evan Cheng69b9f982010-05-13 01:12:06 +0000889 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMQ), DestReg)
890 .addFrameIndex(FI)
Bob Wilsond4bfd542010-08-27 23:18:17 +0000891 .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia))
Evan Cheng69b9f982010-05-13 01:12:06 +0000892 .addMemOperand(MMO));
Jim Grosbach31bc8492009-11-08 00:27:19 +0000893 }
Bob Wilsonebe99b22010-06-18 21:32:42 +0000894 break;
895 case ARM::QQPRRegClassID:
896 case ARM::QQPR_VFP2RegClassID:
Evan Cheng435d4992010-05-07 02:04:02 +0000897 if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) {
Bob Wilson168f3822010-09-15 01:48:05 +0000898 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLD1d64QPseudo), DestReg)
899 .addFrameIndex(FI).addImm(16)
900 .addMemOperand(MMO));
Evan Cheng435d4992010-05-07 02:04:02 +0000901 } else {
902 MachineInstrBuilder MIB =
903 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMD))
904 .addFrameIndex(FI)
Bob Wilsond4bfd542010-08-27 23:18:17 +0000905 .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia)))
Evan Cheng435d4992010-05-07 02:04:02 +0000906 .addMemOperand(MMO);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000907 MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI);
908 MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI);
909 MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI);
910 AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI);
Evan Cheng435d4992010-05-07 02:04:02 +0000911 }
Bob Wilsonebe99b22010-06-18 21:32:42 +0000912 break;
913 case ARM::QQQQPRRegClassID: {
914 MachineInstrBuilder MIB =
915 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMD))
916 .addFrameIndex(FI)
Bob Wilsond4bfd542010-08-27 23:18:17 +0000917 .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia)))
Bob Wilsonebe99b22010-06-18 21:32:42 +0000918 .addMemOperand(MMO);
919 MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI);
920 MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI);
921 MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI);
922 MIB = AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI);
923 MIB = AddDReg(MIB, DestReg, ARM::dsub_4, RegState::Define, TRI);
924 MIB = AddDReg(MIB, DestReg, ARM::dsub_5, RegState::Define, TRI);
925 MIB = AddDReg(MIB, DestReg, ARM::dsub_6, RegState::Define, TRI);
926 AddDReg(MIB, DestReg, ARM::dsub_7, RegState::Define, TRI);
927 break;
928 }
929 default:
930 llvm_unreachable("Unknown regclass!");
David Goodwin334c2642009-07-08 16:09:28 +0000931 }
932}
933
Jakob Stoklund Olesen34327852010-09-15 16:36:26 +0000934unsigned
935ARMBaseInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
936 int &FrameIndex) const {
937 switch (MI->getOpcode()) {
938 default: break;
Jim Grosbach3e556122010-10-26 22:37:02 +0000939 case ARM::LDRrs:
Jakob Stoklund Olesen34327852010-09-15 16:36:26 +0000940 case ARM::t2LDRs: // FIXME: don't use t2LDRs to access frame.
941 if (MI->getOperand(1).isFI() &&
942 MI->getOperand(2).isReg() &&
943 MI->getOperand(3).isImm() &&
944 MI->getOperand(2).getReg() == 0 &&
945 MI->getOperand(3).getImm() == 0) {
946 FrameIndex = MI->getOperand(1).getIndex();
947 return MI->getOperand(0).getReg();
948 }
949 break;
Jim Grosbach3e556122010-10-26 22:37:02 +0000950 case ARM::LDRi12:
Jakob Stoklund Olesen34327852010-09-15 16:36:26 +0000951 case ARM::t2LDRi12:
952 case ARM::tRestore:
953 case ARM::VLDRD:
954 case ARM::VLDRS:
955 if (MI->getOperand(1).isFI() &&
956 MI->getOperand(2).isImm() &&
957 MI->getOperand(2).getImm() == 0) {
958 FrameIndex = MI->getOperand(1).getIndex();
959 return MI->getOperand(0).getReg();
960 }
961 break;
Jakob Stoklund Olesend64816a2010-09-15 17:27:09 +0000962 case ARM::VLD1q64Pseudo:
963 if (MI->getOperand(1).isFI() &&
964 MI->getOperand(0).getSubReg() == 0) {
965 FrameIndex = MI->getOperand(1).getIndex();
966 return MI->getOperand(0).getReg();
967 }
968 break;
Jakob Stoklund Olesen06f264e2010-09-15 21:40:11 +0000969 case ARM::VLDMQ:
970 if (MI->getOperand(1).isFI() &&
971 MI->getOperand(2).isImm() &&
972 MI->getOperand(2).getImm() == ARM_AM::getAM4ModeImm(ARM_AM::ia) &&
973 MI->getOperand(0).getSubReg() == 0) {
974 FrameIndex = MI->getOperand(1).getIndex();
975 return MI->getOperand(0).getReg();
976 }
977 break;
Jakob Stoklund Olesen34327852010-09-15 16:36:26 +0000978 }
979
980 return 0;
981}
982
Evan Cheng62b50652010-04-26 07:39:25 +0000983MachineInstr*
984ARMBaseInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF,
Evan Cheng8601a3d2010-04-29 01:13:30 +0000985 int FrameIx, uint64_t Offset,
Evan Cheng62b50652010-04-26 07:39:25 +0000986 const MDNode *MDPtr,
987 DebugLoc DL) const {
988 MachineInstrBuilder MIB = BuildMI(MF, DL, get(ARM::DBG_VALUE))
989 .addFrameIndex(FrameIx).addImm(0).addImm(Offset).addMetadata(MDPtr);
990 return &*MIB;
991}
992
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +0000993/// Create a copy of a const pool value. Update CPI to the new index and return
994/// the label UID.
995static unsigned duplicateCPV(MachineFunction &MF, unsigned &CPI) {
996 MachineConstantPool *MCP = MF.getConstantPool();
997 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
998
999 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI];
1000 assert(MCPE.isMachineConstantPoolEntry() &&
1001 "Expecting a machine constantpool entry!");
1002 ARMConstantPoolValue *ACPV =
1003 static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal);
1004
1005 unsigned PCLabelId = AFI->createConstPoolEntryUId();
1006 ARMConstantPoolValue *NewCPV = 0;
Jim Grosbach51f5b672010-09-10 21:38:22 +00001007 // FIXME: The below assumes PIC relocation model and that the function
1008 // is Thumb mode (t1 or t2). PCAdjustment would be 8 for ARM mode PIC, and
1009 // zero for non-PIC in ARM or Thumb. The callers are all of thumb LDR
1010 // instructions, so that's probably OK, but is PIC always correct when
1011 // we get here?
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +00001012 if (ACPV->isGlobalValue())
1013 NewCPV = new ARMConstantPoolValue(ACPV->getGV(), PCLabelId,
1014 ARMCP::CPValue, 4);
1015 else if (ACPV->isExtSymbol())
1016 NewCPV = new ARMConstantPoolValue(MF.getFunction()->getContext(),
1017 ACPV->getSymbol(), PCLabelId, 4);
1018 else if (ACPV->isBlockAddress())
1019 NewCPV = new ARMConstantPoolValue(ACPV->getBlockAddress(), PCLabelId,
1020 ARMCP::CPBlockAddress, 4);
Jim Grosbach51f5b672010-09-10 21:38:22 +00001021 else if (ACPV->isLSDA())
1022 NewCPV = new ARMConstantPoolValue(MF.getFunction(), PCLabelId,
1023 ARMCP::CPLSDA, 4);
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +00001024 else
1025 llvm_unreachable("Unexpected ARM constantpool value type!!");
1026 CPI = MCP->getConstantPoolIndex(NewCPV, MCPE.getAlignment());
1027 return PCLabelId;
1028}
1029
Evan Chengfdc83402009-11-08 00:15:23 +00001030void ARMBaseInstrInfo::
1031reMaterialize(MachineBasicBlock &MBB,
1032 MachineBasicBlock::iterator I,
1033 unsigned DestReg, unsigned SubIdx,
Evan Chengd57cdd52009-11-14 02:55:43 +00001034 const MachineInstr *Orig,
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +00001035 const TargetRegisterInfo &TRI) const {
Evan Chengfdc83402009-11-08 00:15:23 +00001036 unsigned Opcode = Orig->getOpcode();
1037 switch (Opcode) {
1038 default: {
1039 MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig);
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +00001040 MI->substituteRegister(Orig->getOperand(0).getReg(), DestReg, SubIdx, TRI);
Evan Chengfdc83402009-11-08 00:15:23 +00001041 MBB.insert(I, MI);
1042 break;
1043 }
1044 case ARM::tLDRpci_pic:
1045 case ARM::t2LDRpci_pic: {
1046 MachineFunction &MF = *MBB.getParent();
Evan Chengfdc83402009-11-08 00:15:23 +00001047 unsigned CPI = Orig->getOperand(1).getIndex();
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +00001048 unsigned PCLabelId = duplicateCPV(MF, CPI);
Evan Chengfdc83402009-11-08 00:15:23 +00001049 MachineInstrBuilder MIB = BuildMI(MBB, I, Orig->getDebugLoc(), get(Opcode),
1050 DestReg)
1051 .addConstantPoolIndex(CPI).addImm(PCLabelId);
1052 (*MIB).setMemRefs(Orig->memoperands_begin(), Orig->memoperands_end());
1053 break;
1054 }
1055 }
Evan Chengfdc83402009-11-08 00:15:23 +00001056}
1057
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +00001058MachineInstr *
1059ARMBaseInstrInfo::duplicate(MachineInstr *Orig, MachineFunction &MF) const {
1060 MachineInstr *MI = TargetInstrInfoImpl::duplicate(Orig, MF);
1061 switch(Orig->getOpcode()) {
1062 case ARM::tLDRpci_pic:
1063 case ARM::t2LDRpci_pic: {
1064 unsigned CPI = Orig->getOperand(1).getIndex();
1065 unsigned PCLabelId = duplicateCPV(MF, CPI);
1066 Orig->getOperand(1).setIndex(CPI);
1067 Orig->getOperand(2).setImm(PCLabelId);
1068 break;
1069 }
1070 }
1071 return MI;
1072}
1073
Evan Cheng506049f2010-03-03 01:44:33 +00001074bool ARMBaseInstrInfo::produceSameValue(const MachineInstr *MI0,
1075 const MachineInstr *MI1) const {
Evan Chengd457e6e2009-11-07 04:04:34 +00001076 int Opcode = MI0->getOpcode();
Evan Cheng9b824252009-11-20 02:10:27 +00001077 if (Opcode == ARM::t2LDRpci ||
1078 Opcode == ARM::t2LDRpci_pic ||
1079 Opcode == ARM::tLDRpci ||
1080 Opcode == ARM::tLDRpci_pic) {
Evan Chengd457e6e2009-11-07 04:04:34 +00001081 if (MI1->getOpcode() != Opcode)
1082 return false;
1083 if (MI0->getNumOperands() != MI1->getNumOperands())
1084 return false;
1085
1086 const MachineOperand &MO0 = MI0->getOperand(1);
1087 const MachineOperand &MO1 = MI1->getOperand(1);
1088 if (MO0.getOffset() != MO1.getOffset())
1089 return false;
1090
1091 const MachineFunction *MF = MI0->getParent()->getParent();
1092 const MachineConstantPool *MCP = MF->getConstantPool();
1093 int CPI0 = MO0.getIndex();
1094 int CPI1 = MO1.getIndex();
1095 const MachineConstantPoolEntry &MCPE0 = MCP->getConstants()[CPI0];
1096 const MachineConstantPoolEntry &MCPE1 = MCP->getConstants()[CPI1];
1097 ARMConstantPoolValue *ACPV0 =
1098 static_cast<ARMConstantPoolValue*>(MCPE0.Val.MachineCPVal);
1099 ARMConstantPoolValue *ACPV1 =
1100 static_cast<ARMConstantPoolValue*>(MCPE1.Val.MachineCPVal);
1101 return ACPV0->hasSameValue(ACPV1);
1102 }
1103
Evan Cheng506049f2010-03-03 01:44:33 +00001104 return MI0->isIdenticalTo(MI1, MachineInstr::IgnoreVRegDefs);
Evan Chengd457e6e2009-11-07 04:04:34 +00001105}
1106
Bill Wendling4b722102010-06-23 23:00:16 +00001107/// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
1108/// determine if two loads are loading from the same base address. It should
1109/// only return true if the base pointers are the same and the only differences
1110/// between the two addresses is the offset. It also returns the offsets by
1111/// reference.
1112bool ARMBaseInstrInfo::areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
1113 int64_t &Offset1,
1114 int64_t &Offset2) const {
1115 // Don't worry about Thumb: just ARM and Thumb2.
1116 if (Subtarget.isThumb1Only()) return false;
1117
1118 if (!Load1->isMachineOpcode() || !Load2->isMachineOpcode())
1119 return false;
1120
1121 switch (Load1->getMachineOpcode()) {
1122 default:
1123 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +00001124 case ARM::LDRi12:
Jim Grosbachc1d30212010-10-27 00:19:44 +00001125 case ARM::LDRBi12:
Bill Wendling4b722102010-06-23 23:00:16 +00001126 case ARM::LDRD:
1127 case ARM::LDRH:
1128 case ARM::LDRSB:
1129 case ARM::LDRSH:
1130 case ARM::VLDRD:
1131 case ARM::VLDRS:
1132 case ARM::t2LDRi8:
1133 case ARM::t2LDRDi8:
1134 case ARM::t2LDRSHi8:
1135 case ARM::t2LDRi12:
1136 case ARM::t2LDRSHi12:
1137 break;
1138 }
1139
1140 switch (Load2->getMachineOpcode()) {
1141 default:
1142 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +00001143 case ARM::LDRi12:
Jim Grosbachc1d30212010-10-27 00:19:44 +00001144 case ARM::LDRBi12:
Bill Wendling4b722102010-06-23 23:00:16 +00001145 case ARM::LDRD:
1146 case ARM::LDRH:
1147 case ARM::LDRSB:
1148 case ARM::LDRSH:
1149 case ARM::VLDRD:
1150 case ARM::VLDRS:
1151 case ARM::t2LDRi8:
1152 case ARM::t2LDRDi8:
1153 case ARM::t2LDRSHi8:
1154 case ARM::t2LDRi12:
1155 case ARM::t2LDRSHi12:
1156 break;
1157 }
1158
1159 // Check if base addresses and chain operands match.
1160 if (Load1->getOperand(0) != Load2->getOperand(0) ||
1161 Load1->getOperand(4) != Load2->getOperand(4))
1162 return false;
1163
1164 // Index should be Reg0.
1165 if (Load1->getOperand(3) != Load2->getOperand(3))
1166 return false;
1167
1168 // Determine the offsets.
1169 if (isa<ConstantSDNode>(Load1->getOperand(1)) &&
1170 isa<ConstantSDNode>(Load2->getOperand(1))) {
1171 Offset1 = cast<ConstantSDNode>(Load1->getOperand(1))->getSExtValue();
1172 Offset2 = cast<ConstantSDNode>(Load2->getOperand(1))->getSExtValue();
1173 return true;
1174 }
1175
1176 return false;
1177}
1178
1179/// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
1180/// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should
1181/// be scheduled togther. On some targets if two loads are loading from
1182/// addresses in the same cache line, it's better if they are scheduled
1183/// together. This function takes two integers that represent the load offsets
1184/// from the common base address. It returns true if it decides it's desirable
1185/// to schedule the two loads together. "NumLoads" is the number of loads that
1186/// have already been scheduled after Load1.
1187bool ARMBaseInstrInfo::shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
1188 int64_t Offset1, int64_t Offset2,
1189 unsigned NumLoads) const {
1190 // Don't worry about Thumb: just ARM and Thumb2.
1191 if (Subtarget.isThumb1Only()) return false;
1192
1193 assert(Offset2 > Offset1);
1194
1195 if ((Offset2 - Offset1) / 8 > 64)
1196 return false;
1197
1198 if (Load1->getMachineOpcode() != Load2->getMachineOpcode())
1199 return false; // FIXME: overly conservative?
1200
1201 // Four loads in a row should be sufficient.
1202 if (NumLoads >= 3)
1203 return false;
1204
1205 return true;
1206}
1207
Evan Cheng86050dc2010-06-18 23:09:54 +00001208bool ARMBaseInstrInfo::isSchedulingBoundary(const MachineInstr *MI,
1209 const MachineBasicBlock *MBB,
1210 const MachineFunction &MF) const {
Jim Grosbach57bb3942010-06-25 18:43:14 +00001211 // Debug info is never a scheduling boundary. It's necessary to be explicit
1212 // due to the special treatment of IT instructions below, otherwise a
1213 // dbg_value followed by an IT will result in the IT instruction being
1214 // considered a scheduling hazard, which is wrong. It should be the actual
1215 // instruction preceding the dbg_value instruction(s), just like it is
1216 // when debug info is not present.
1217 if (MI->isDebugValue())
1218 return false;
1219
Evan Cheng86050dc2010-06-18 23:09:54 +00001220 // Terminators and labels can't be scheduled around.
1221 if (MI->getDesc().isTerminator() || MI->isLabel())
1222 return true;
1223
1224 // Treat the start of the IT block as a scheduling boundary, but schedule
1225 // t2IT along with all instructions following it.
1226 // FIXME: This is a big hammer. But the alternative is to add all potential
1227 // true and anti dependencies to IT block instructions as implicit operands
1228 // to the t2IT instruction. The added compile time and complexity does not
1229 // seem worth it.
1230 MachineBasicBlock::const_iterator I = MI;
Jim Grosbach57bb3942010-06-25 18:43:14 +00001231 // Make sure to skip any dbg_value instructions
1232 while (++I != MBB->end() && I->isDebugValue())
1233 ;
1234 if (I != MBB->end() && I->getOpcode() == ARM::t2IT)
Evan Cheng86050dc2010-06-18 23:09:54 +00001235 return true;
1236
1237 // Don't attempt to schedule around any instruction that defines
1238 // a stack-oriented pointer, as it's unlikely to be profitable. This
1239 // saves compile time, because it doesn't require every single
1240 // stack slot reference to depend on the instruction that does the
1241 // modification.
1242 if (MI->definesRegister(ARM::SP))
1243 return true;
1244
1245 return false;
1246}
1247
Owen Andersonb20b8512010-09-28 18:32:13 +00001248bool ARMBaseInstrInfo::isProfitableToIfCvt(MachineBasicBlock &MBB,
Evan Cheng8239daf2010-11-03 00:45:17 +00001249 unsigned NumCyles,
1250 unsigned ExtraPredCycles,
Owen Andersone3cc84a2010-10-01 22:45:50 +00001251 float Probability,
1252 float Confidence) const {
Evan Cheng8239daf2010-11-03 00:45:17 +00001253 if (!NumCyles)
Evan Cheng13151432010-06-25 22:42:03 +00001254 return false;
Michael J. Spencer2bbb7692010-10-05 06:00:33 +00001255
Owen Andersonb20b8512010-09-28 18:32:13 +00001256 // Attempt to estimate the relative costs of predication versus branching.
Evan Cheng8239daf2010-11-03 00:45:17 +00001257 float UnpredCost = Probability * NumCyles;
Owen Anderson654d5442010-09-28 21:57:50 +00001258 UnpredCost += 1.0; // The branch itself
Owen Andersone3cc84a2010-10-01 22:45:50 +00001259 UnpredCost += (1.0 - Confidence) * Subtarget.getMispredictionPenalty();
Michael J. Spencer2bbb7692010-10-05 06:00:33 +00001260
Evan Cheng8239daf2010-11-03 00:45:17 +00001261 return (float)(NumCyles + ExtraPredCycles) < UnpredCost;
Evan Cheng13151432010-06-25 22:42:03 +00001262}
Michael J. Spencer2bbb7692010-10-05 06:00:33 +00001263
Evan Cheng13151432010-06-25 22:42:03 +00001264bool ARMBaseInstrInfo::
Evan Cheng8239daf2010-11-03 00:45:17 +00001265isProfitableToIfCvt(MachineBasicBlock &TMBB,
1266 unsigned TCycles, unsigned TExtra,
1267 MachineBasicBlock &FMBB,
1268 unsigned FCycles, unsigned FExtra,
Owen Andersone3cc84a2010-10-01 22:45:50 +00001269 float Probability, float Confidence) const {
Evan Cheng8239daf2010-11-03 00:45:17 +00001270 if (!TCycles || !FCycles)
Owen Andersonb20b8512010-09-28 18:32:13 +00001271 return false;
Michael J. Spencer2bbb7692010-10-05 06:00:33 +00001272
Owen Andersonb20b8512010-09-28 18:32:13 +00001273 // Attempt to estimate the relative costs of predication versus branching.
Evan Cheng8239daf2010-11-03 00:45:17 +00001274 float UnpredCost = Probability * TCycles + (1.0 - Probability) * FCycles;
Owen Anderson654d5442010-09-28 21:57:50 +00001275 UnpredCost += 1.0; // The branch itself
Owen Andersone3cc84a2010-10-01 22:45:50 +00001276 UnpredCost += (1.0 - Confidence) * Subtarget.getMispredictionPenalty();
Michael J. Spencer2bbb7692010-10-05 06:00:33 +00001277
Evan Cheng8239daf2010-11-03 00:45:17 +00001278 return (float)(TCycles + FCycles + TExtra + FExtra) < UnpredCost;
Evan Cheng13151432010-06-25 22:42:03 +00001279}
1280
Evan Cheng8fb90362009-08-08 03:20:32 +00001281/// getInstrPredicate - If instruction is predicated, returns its predicate
1282/// condition, otherwise returns AL. It also returns the condition code
1283/// register by reference.
Evan Cheng5adb66a2009-09-28 09:14:39 +00001284ARMCC::CondCodes
1285llvm::getInstrPredicate(const MachineInstr *MI, unsigned &PredReg) {
Evan Cheng8fb90362009-08-08 03:20:32 +00001286 int PIdx = MI->findFirstPredOperandIdx();
1287 if (PIdx == -1) {
1288 PredReg = 0;
1289 return ARMCC::AL;
1290 }
1291
1292 PredReg = MI->getOperand(PIdx+1).getReg();
1293 return (ARMCC::CondCodes)MI->getOperand(PIdx).getImm();
1294}
1295
1296
Evan Cheng6495f632009-07-28 05:48:47 +00001297int llvm::getMatchingCondBranchOpcode(int Opc) {
Evan Cheng5ca53a72009-07-27 18:20:05 +00001298 if (Opc == ARM::B)
1299 return ARM::Bcc;
1300 else if (Opc == ARM::tB)
1301 return ARM::tBcc;
1302 else if (Opc == ARM::t2B)
1303 return ARM::t2Bcc;
1304
1305 llvm_unreachable("Unknown unconditional branch opcode!");
1306 return 0;
1307}
1308
Evan Cheng6495f632009-07-28 05:48:47 +00001309
1310void llvm::emitARMRegPlusImmediate(MachineBasicBlock &MBB,
1311 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
1312 unsigned DestReg, unsigned BaseReg, int NumBytes,
1313 ARMCC::CondCodes Pred, unsigned PredReg,
1314 const ARMBaseInstrInfo &TII) {
1315 bool isSub = NumBytes < 0;
1316 if (isSub) NumBytes = -NumBytes;
1317
1318 while (NumBytes) {
1319 unsigned RotAmt = ARM_AM::getSOImmValRotate(NumBytes);
1320 unsigned ThisVal = NumBytes & ARM_AM::rotr32(0xFF, RotAmt);
1321 assert(ThisVal && "Didn't extract field correctly");
1322
1323 // We will handle these bits from offset, clear them.
1324 NumBytes &= ~ThisVal;
1325
1326 assert(ARM_AM::getSOImmVal(ThisVal) != -1 && "Bit extraction didn't work?");
1327
1328 // Build the new ADD / SUB.
1329 unsigned Opc = isSub ? ARM::SUBri : ARM::ADDri;
1330 BuildMI(MBB, MBBI, dl, TII.get(Opc), DestReg)
1331 .addReg(BaseReg, RegState::Kill).addImm(ThisVal)
1332 .addImm((unsigned)Pred).addReg(PredReg).addReg(0);
1333 BaseReg = DestReg;
1334 }
1335}
1336
Evan Chengcdbb3f52009-08-27 01:23:50 +00001337bool llvm::rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
1338 unsigned FrameReg, int &Offset,
1339 const ARMBaseInstrInfo &TII) {
Evan Cheng6495f632009-07-28 05:48:47 +00001340 unsigned Opcode = MI.getOpcode();
1341 const TargetInstrDesc &Desc = MI.getDesc();
1342 unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask);
1343 bool isSub = false;
Jim Grosbach764ab522009-08-11 15:33:49 +00001344
Evan Cheng6495f632009-07-28 05:48:47 +00001345 // Memory operands in inline assembly always use AddrMode2.
1346 if (Opcode == ARM::INLINEASM)
1347 AddrMode = ARMII::AddrMode2;
Jim Grosbach764ab522009-08-11 15:33:49 +00001348
Evan Cheng6495f632009-07-28 05:48:47 +00001349 if (Opcode == ARM::ADDri) {
1350 Offset += MI.getOperand(FrameRegIdx+1).getImm();
1351 if (Offset == 0) {
1352 // Turn it into a move.
1353 MI.setDesc(TII.get(ARM::MOVr));
1354 MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false);
1355 MI.RemoveOperand(FrameRegIdx+1);
Evan Chengcdbb3f52009-08-27 01:23:50 +00001356 Offset = 0;
1357 return true;
Evan Cheng6495f632009-07-28 05:48:47 +00001358 } else if (Offset < 0) {
1359 Offset = -Offset;
1360 isSub = true;
1361 MI.setDesc(TII.get(ARM::SUBri));
1362 }
1363
1364 // Common case: small offset, fits into instruction.
1365 if (ARM_AM::getSOImmVal(Offset) != -1) {
1366 // Replace the FrameIndex with sp / fp
1367 MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false);
1368 MI.getOperand(FrameRegIdx+1).ChangeToImmediate(Offset);
Evan Chengcdbb3f52009-08-27 01:23:50 +00001369 Offset = 0;
1370 return true;
Evan Cheng6495f632009-07-28 05:48:47 +00001371 }
1372
1373 // Otherwise, pull as much of the immedidate into this ADDri/SUBri
1374 // as possible.
1375 unsigned RotAmt = ARM_AM::getSOImmValRotate(Offset);
1376 unsigned ThisImmVal = Offset & ARM_AM::rotr32(0xFF, RotAmt);
1377
1378 // We will handle these bits from offset, clear them.
1379 Offset &= ~ThisImmVal;
1380
1381 // Get the properly encoded SOImmVal field.
1382 assert(ARM_AM::getSOImmVal(ThisImmVal) != -1 &&
1383 "Bit extraction didn't work?");
1384 MI.getOperand(FrameRegIdx+1).ChangeToImmediate(ThisImmVal);
1385 } else {
1386 unsigned ImmIdx = 0;
1387 int InstrOffs = 0;
1388 unsigned NumBits = 0;
1389 unsigned Scale = 1;
1390 switch (AddrMode) {
Jim Grosbach3e556122010-10-26 22:37:02 +00001391 case ARMII::AddrMode_i12: {
1392 ImmIdx = FrameRegIdx + 1;
1393 InstrOffs = MI.getOperand(ImmIdx).getImm();
1394 NumBits = 12;
1395 break;
1396 }
Evan Cheng6495f632009-07-28 05:48:47 +00001397 case ARMII::AddrMode2: {
1398 ImmIdx = FrameRegIdx+2;
1399 InstrOffs = ARM_AM::getAM2Offset(MI.getOperand(ImmIdx).getImm());
1400 if (ARM_AM::getAM2Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub)
1401 InstrOffs *= -1;
1402 NumBits = 12;
1403 break;
1404 }
1405 case ARMII::AddrMode3: {
1406 ImmIdx = FrameRegIdx+2;
1407 InstrOffs = ARM_AM::getAM3Offset(MI.getOperand(ImmIdx).getImm());
1408 if (ARM_AM::getAM3Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub)
1409 InstrOffs *= -1;
1410 NumBits = 8;
1411 break;
1412 }
Anton Korobeynikovbaf31082009-08-08 13:35:48 +00001413 case ARMII::AddrMode4:
Jim Grosbacha4432172009-11-15 21:45:34 +00001414 case ARMII::AddrMode6:
Evan Chengcdbb3f52009-08-27 01:23:50 +00001415 // Can't fold any offset even if it's zero.
1416 return false;
Evan Cheng6495f632009-07-28 05:48:47 +00001417 case ARMII::AddrMode5: {
1418 ImmIdx = FrameRegIdx+1;
1419 InstrOffs = ARM_AM::getAM5Offset(MI.getOperand(ImmIdx).getImm());
1420 if (ARM_AM::getAM5Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub)
1421 InstrOffs *= -1;
1422 NumBits = 8;
1423 Scale = 4;
1424 break;
1425 }
1426 default:
1427 llvm_unreachable("Unsupported addressing mode!");
1428 break;
1429 }
1430
1431 Offset += InstrOffs * Scale;
1432 assert((Offset & (Scale-1)) == 0 && "Can't encode this offset!");
1433 if (Offset < 0) {
1434 Offset = -Offset;
1435 isSub = true;
1436 }
1437
1438 // Attempt to fold address comp. if opcode has offset bits
1439 if (NumBits > 0) {
1440 // Common case: small offset, fits into instruction.
1441 MachineOperand &ImmOp = MI.getOperand(ImmIdx);
1442 int ImmedOffset = Offset / Scale;
1443 unsigned Mask = (1 << NumBits) - 1;
1444 if ((unsigned)Offset <= Mask * Scale) {
1445 // Replace the FrameIndex with sp
1446 MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false);
Jim Grosbach77aee8e2010-10-27 01:19:41 +00001447 // FIXME: When addrmode2 goes away, this will simplify (like the
1448 // T2 version), as the LDR.i12 versions don't need the encoding
1449 // tricks for the offset value.
1450 if (isSub) {
1451 if (AddrMode == ARMII::AddrMode_i12)
1452 ImmedOffset = -ImmedOffset;
1453 else
1454 ImmedOffset |= 1 << NumBits;
1455 }
Evan Cheng6495f632009-07-28 05:48:47 +00001456 ImmOp.ChangeToImmediate(ImmedOffset);
Evan Chengcdbb3f52009-08-27 01:23:50 +00001457 Offset = 0;
1458 return true;
Evan Cheng6495f632009-07-28 05:48:47 +00001459 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001460
Evan Cheng6495f632009-07-28 05:48:47 +00001461 // Otherwise, it didn't fit. Pull in what we can to simplify the immed.
1462 ImmedOffset = ImmedOffset & Mask;
Jim Grosbach063efbf2010-10-27 16:50:31 +00001463 if (isSub) {
1464 if (AddrMode == ARMII::AddrMode_i12)
1465 ImmedOffset = -ImmedOffset;
1466 else
1467 ImmedOffset |= 1 << NumBits;
1468 }
Evan Cheng6495f632009-07-28 05:48:47 +00001469 ImmOp.ChangeToImmediate(ImmedOffset);
1470 Offset &= ~(Mask*Scale);
1471 }
1472 }
1473
Evan Chengcdbb3f52009-08-27 01:23:50 +00001474 Offset = (isSub) ? -Offset : Offset;
1475 return Offset == 0;
Evan Cheng6495f632009-07-28 05:48:47 +00001476}
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001477
1478bool ARMBaseInstrInfo::
Eric Christophera99c3e92010-09-28 04:18:29 +00001479AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg, int &CmpMask,
1480 int &CmpValue) const {
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001481 switch (MI->getOpcode()) {
1482 default: break;
Bill Wendling38ae9972010-08-11 00:23:00 +00001483 case ARM::CMPri:
1484 case ARM::CMPzri:
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001485 case ARM::t2CMPri:
1486 case ARM::t2CMPzri:
1487 SrcReg = MI->getOperand(0).getReg();
Gabor Greif04ac81d2010-09-21 12:01:15 +00001488 CmpMask = ~0;
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001489 CmpValue = MI->getOperand(1).getImm();
1490 return true;
Gabor Greif04ac81d2010-09-21 12:01:15 +00001491 case ARM::TSTri:
1492 case ARM::t2TSTri:
1493 SrcReg = MI->getOperand(0).getReg();
1494 CmpMask = MI->getOperand(1).getImm();
1495 CmpValue = 0;
1496 return true;
1497 }
1498
1499 return false;
1500}
1501
Gabor Greif05642a32010-09-29 10:12:08 +00001502/// isSuitableForMask - Identify a suitable 'and' instruction that
1503/// operates on the given source register and applies the same mask
1504/// as a 'tst' instruction. Provide a limited look-through for copies.
1505/// When successful, MI will hold the found instruction.
1506static bool isSuitableForMask(MachineInstr *&MI, unsigned SrcReg,
Gabor Greif8ff9bb12010-09-21 13:30:57 +00001507 int CmpMask, bool CommonUse) {
Gabor Greif05642a32010-09-29 10:12:08 +00001508 switch (MI->getOpcode()) {
Gabor Greif04ac81d2010-09-21 12:01:15 +00001509 case ARM::ANDri:
1510 case ARM::t2ANDri:
Gabor Greif05642a32010-09-29 10:12:08 +00001511 if (CmpMask != MI->getOperand(2).getImm())
Gabor Greif8ff9bb12010-09-21 13:30:57 +00001512 return false;
Gabor Greif05642a32010-09-29 10:12:08 +00001513 if (SrcReg == MI->getOperand(CommonUse ? 1 : 0).getReg())
Gabor Greif04ac81d2010-09-21 12:01:15 +00001514 return true;
1515 break;
Gabor Greif05642a32010-09-29 10:12:08 +00001516 case ARM::COPY: {
1517 // Walk down one instruction which is potentially an 'and'.
1518 const MachineInstr &Copy = *MI;
Michael J. Spencerf000a7a2010-10-05 06:00:43 +00001519 MachineBasicBlock::iterator AND(
1520 llvm::next(MachineBasicBlock::iterator(MI)));
Gabor Greif05642a32010-09-29 10:12:08 +00001521 if (AND == MI->getParent()->end()) return false;
1522 MI = AND;
1523 return isSuitableForMask(MI, Copy.getOperand(0).getReg(),
1524 CmpMask, true);
1525 }
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001526 }
1527
1528 return false;
1529}
1530
Bill Wendlinga6556862010-09-11 00:13:50 +00001531/// OptimizeCompareInstr - Convert the instruction supplying the argument to the
Bill Wendling92ad57f2010-09-10 23:34:19 +00001532/// comparison into one that sets the zero bit in the flags register. Update the
1533/// iterator *only* if a transformation took place.
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001534bool ARMBaseInstrInfo::
Gabor Greif04ac81d2010-09-21 12:01:15 +00001535OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask,
Bill Wendlingb41ee962010-10-18 21:22:31 +00001536 int CmpValue, const MachineRegisterInfo *MRI,
1537 MachineBasicBlock::iterator &MII) const {
Bill Wendling36656612010-09-10 23:46:12 +00001538 if (CmpValue != 0)
Bill Wendling92ad57f2010-09-10 23:34:19 +00001539 return false;
1540
Bill Wendlingb41ee962010-10-18 21:22:31 +00001541 MachineRegisterInfo::def_iterator DI = MRI->def_begin(SrcReg);
1542 if (llvm::next(DI) != MRI->def_end())
Bill Wendling92ad57f2010-09-10 23:34:19 +00001543 // Only support one definition.
1544 return false;
1545
1546 MachineInstr *MI = &*DI;
1547
Gabor Greif04ac81d2010-09-21 12:01:15 +00001548 // Masked compares sometimes use the same register as the corresponding 'and'.
1549 if (CmpMask != ~0) {
Gabor Greif05642a32010-09-29 10:12:08 +00001550 if (!isSuitableForMask(MI, SrcReg, CmpMask, false)) {
Gabor Greif04ac81d2010-09-21 12:01:15 +00001551 MI = 0;
Bill Wendlingb41ee962010-10-18 21:22:31 +00001552 for (MachineRegisterInfo::use_iterator UI = MRI->use_begin(SrcReg),
1553 UE = MRI->use_end(); UI != UE; ++UI) {
Gabor Greif04ac81d2010-09-21 12:01:15 +00001554 if (UI->getParent() != CmpInstr->getParent()) continue;
Gabor Greif05642a32010-09-29 10:12:08 +00001555 MachineInstr *PotentialAND = &*UI;
Gabor Greif8ff9bb12010-09-21 13:30:57 +00001556 if (!isSuitableForMask(PotentialAND, SrcReg, CmpMask, true))
Gabor Greif04ac81d2010-09-21 12:01:15 +00001557 continue;
Gabor Greif05642a32010-09-29 10:12:08 +00001558 MI = PotentialAND;
Gabor Greif04ac81d2010-09-21 12:01:15 +00001559 break;
1560 }
1561 if (!MI) return false;
1562 }
1563 }
1564
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001565 // Conservatively refuse to convert an instruction which isn't in the same BB
1566 // as the comparison.
1567 if (MI->getParent() != CmpInstr->getParent())
1568 return false;
1569
1570 // Check that CPSR isn't set between the comparison instruction and the one we
1571 // want to change.
Evan Cheng691e64a2010-09-21 23:49:07 +00001572 MachineBasicBlock::const_iterator I = CmpInstr, E = MI,
1573 B = MI->getParent()->begin();
Bill Wendling0aa38b92010-10-09 00:03:48 +00001574
1575 // Early exit if CmpInstr is at the beginning of the BB.
1576 if (I == B) return false;
1577
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001578 --I;
1579 for (; I != E; --I) {
1580 const MachineInstr &Instr = *I;
1581
1582 for (unsigned IO = 0, EO = Instr.getNumOperands(); IO != EO; ++IO) {
1583 const MachineOperand &MO = Instr.getOperand(IO);
Bill Wendling40a5eb12010-11-01 20:41:43 +00001584 if (!MO.isReg()) continue;
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001585
Bill Wendling40a5eb12010-11-01 20:41:43 +00001586 // This instruction modifies or uses CPSR after the one we want to
1587 // change. We can't do this transformation.
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001588 if (MO.getReg() == ARM::CPSR)
1589 return false;
1590 }
Evan Cheng691e64a2010-09-21 23:49:07 +00001591
1592 if (I == B)
1593 // The 'and' is below the comparison instruction.
1594 return false;
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001595 }
1596
1597 // Set the "zero" bit in CPSR.
1598 switch (MI->getOpcode()) {
1599 default: break;
Bill Wendling38ae9972010-08-11 00:23:00 +00001600 case ARM::ADDri:
Bob Wilson3a951822010-09-15 17:12:08 +00001601 case ARM::ANDri:
1602 case ARM::t2ANDri:
Bill Wendling38ae9972010-08-11 00:23:00 +00001603 case ARM::SUBri:
1604 case ARM::t2ADDri:
Bill Wendlingad422712010-08-18 21:32:07 +00001605 case ARM::t2SUBri:
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001606 MI->RemoveOperand(5);
Bill Wendlingad422712010-08-18 21:32:07 +00001607 MachineInstrBuilder(MI)
1608 .addReg(ARM::CPSR, RegState::Define | RegState::Implicit);
Bill Wendling220e2402010-09-10 21:55:43 +00001609 MII = llvm::next(MachineBasicBlock::iterator(CmpInstr));
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001610 CmpInstr->eraseFromParent();
1611 return true;
1612 }
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +00001613
1614 return false;
1615}
Evan Cheng5f54ce32010-09-09 18:18:55 +00001616
1617unsigned
Evan Cheng8239daf2010-11-03 00:45:17 +00001618ARMBaseInstrInfo::getNumMicroOps(const InstrItineraryData *ItinData,
1619 const MachineInstr *MI) const {
Evan Cheng3ef1c872010-09-10 01:29:16 +00001620 if (!ItinData || ItinData->isEmpty())
Evan Cheng5f54ce32010-09-09 18:18:55 +00001621 return 1;
1622
1623 const TargetInstrDesc &Desc = MI->getDesc();
1624 unsigned Class = Desc.getSchedClass();
Bob Wilson064312d2010-09-15 16:28:21 +00001625 unsigned UOps = ItinData->Itineraries[Class].NumMicroOps;
Evan Cheng5f54ce32010-09-09 18:18:55 +00001626 if (UOps)
1627 return UOps;
1628
1629 unsigned Opc = MI->getOpcode();
1630 switch (Opc) {
1631 default:
1632 llvm_unreachable("Unexpected multi-uops instruction!");
1633 break;
Evan Cheng3ef1c872010-09-10 01:29:16 +00001634 case ARM::VLDMQ:
Evan Cheng5f54ce32010-09-09 18:18:55 +00001635 case ARM::VSTMQ:
1636 return 2;
1637
1638 // The number of uOps for load / store multiple are determined by the number
1639 // registers.
Evan Cheng3ef1c872010-09-10 01:29:16 +00001640 // On Cortex-A8, each pair of register loads / stores can be scheduled on the
1641 // same cycle. The scheduling for the first load / store must be done
1642 // separately by assuming the the address is not 64-bit aligned.
1643 // On Cortex-A9, the formula is simply (#reg / 2) + (#reg % 2). If the address
1644 // is not 64-bit aligned, then AGU would take an extra cycle.
1645 // For VFP / NEON load / store multiple, the formula is
Evan Cheng5f54ce32010-09-09 18:18:55 +00001646 // (#reg / 2) + (#reg % 2) + 1.
Evan Cheng5f54ce32010-09-09 18:18:55 +00001647 case ARM::VLDMD:
1648 case ARM::VLDMS:
1649 case ARM::VLDMD_UPD:
1650 case ARM::VLDMS_UPD:
1651 case ARM::VSTMD:
1652 case ARM::VSTMS:
1653 case ARM::VSTMD_UPD:
1654 case ARM::VSTMS_UPD: {
1655 unsigned NumRegs = MI->getNumOperands() - Desc.getNumOperands();
1656 return (NumRegs / 2) + (NumRegs % 2) + 1;
1657 }
1658 case ARM::LDM_RET:
1659 case ARM::LDM:
1660 case ARM::LDM_UPD:
1661 case ARM::STM:
1662 case ARM::STM_UPD:
1663 case ARM::tLDM:
1664 case ARM::tLDM_UPD:
1665 case ARM::tSTM_UPD:
1666 case ARM::tPOP_RET:
1667 case ARM::tPOP:
1668 case ARM::tPUSH:
1669 case ARM::t2LDM_RET:
1670 case ARM::t2LDM:
1671 case ARM::t2LDM_UPD:
1672 case ARM::t2STM:
1673 case ARM::t2STM_UPD: {
Evan Cheng3ef1c872010-09-10 01:29:16 +00001674 unsigned NumRegs = MI->getNumOperands() - Desc.getNumOperands() + 1;
1675 if (Subtarget.isCortexA8()) {
Evan Cheng8239daf2010-11-03 00:45:17 +00001676 if (NumRegs < 4)
1677 return 2;
1678 // 4 registers would be issued: 2, 2.
1679 // 5 registers would be issued: 2, 2, 1.
1680 UOps = (NumRegs / 2);
1681 if (NumRegs % 2)
1682 ++UOps;
1683 return UOps;
Evan Cheng3ef1c872010-09-10 01:29:16 +00001684 } else if (Subtarget.isCortexA9()) {
1685 UOps = (NumRegs / 2);
1686 // If there are odd number of registers or if it's not 64-bit aligned,
1687 // then it takes an extra AGU (Address Generation Unit) cycle.
1688 if ((NumRegs % 2) ||
1689 !MI->hasOneMemOperand() ||
1690 (*MI->memoperands_begin())->getAlignment() < 8)
1691 ++UOps;
1692 return UOps;
1693 } else {
1694 // Assume the worst.
1695 return NumRegs;
Michael J. Spencer2bbb7692010-10-05 06:00:33 +00001696 }
Evan Cheng5f54ce32010-09-09 18:18:55 +00001697 }
1698 }
1699}
Evan Chenga0792de2010-10-06 06:27:31 +00001700
1701int
Evan Cheng344d9db2010-10-07 23:12:15 +00001702ARMBaseInstrInfo::getVLDMDefCycle(const InstrItineraryData *ItinData,
1703 const TargetInstrDesc &DefTID,
1704 unsigned DefClass,
1705 unsigned DefIdx, unsigned DefAlign) const {
1706 int RegNo = (int)(DefIdx+1) - DefTID.getNumOperands() + 1;
1707 if (RegNo <= 0)
1708 // Def is the address writeback.
1709 return ItinData->getOperandCycle(DefClass, DefIdx);
1710
1711 int DefCycle;
1712 if (Subtarget.isCortexA8()) {
1713 // (regno / 2) + (regno % 2) + 1
1714 DefCycle = RegNo / 2 + 1;
1715 if (RegNo % 2)
1716 ++DefCycle;
1717 } else if (Subtarget.isCortexA9()) {
1718 DefCycle = RegNo;
1719 bool isSLoad = false;
1720 switch (DefTID.getOpcode()) {
1721 default: break;
1722 case ARM::VLDMS:
1723 case ARM::VLDMS_UPD:
1724 isSLoad = true;
1725 break;
1726 }
1727 // If there are odd number of 'S' registers or if it's not 64-bit aligned,
1728 // then it takes an extra cycle.
1729 if ((isSLoad && (RegNo % 2)) || DefAlign < 8)
1730 ++DefCycle;
1731 } else {
1732 // Assume the worst.
1733 DefCycle = RegNo + 2;
1734 }
1735
1736 return DefCycle;
1737}
1738
1739int
1740ARMBaseInstrInfo::getLDMDefCycle(const InstrItineraryData *ItinData,
1741 const TargetInstrDesc &DefTID,
1742 unsigned DefClass,
1743 unsigned DefIdx, unsigned DefAlign) const {
1744 int RegNo = (int)(DefIdx+1) - DefTID.getNumOperands() + 1;
1745 if (RegNo <= 0)
1746 // Def is the address writeback.
1747 return ItinData->getOperandCycle(DefClass, DefIdx);
1748
1749 int DefCycle;
1750 if (Subtarget.isCortexA8()) {
1751 // 4 registers would be issued: 1, 2, 1.
1752 // 5 registers would be issued: 1, 2, 2.
1753 DefCycle = RegNo / 2;
1754 if (DefCycle < 1)
1755 DefCycle = 1;
1756 // Result latency is issue cycle + 2: E2.
1757 DefCycle += 2;
1758 } else if (Subtarget.isCortexA9()) {
1759 DefCycle = (RegNo / 2);
1760 // If there are odd number of registers or if it's not 64-bit aligned,
1761 // then it takes an extra AGU (Address Generation Unit) cycle.
1762 if ((RegNo % 2) || DefAlign < 8)
1763 ++DefCycle;
1764 // Result latency is AGU cycles + 2.
1765 DefCycle += 2;
1766 } else {
1767 // Assume the worst.
1768 DefCycle = RegNo + 2;
1769 }
1770
1771 return DefCycle;
1772}
1773
1774int
1775ARMBaseInstrInfo::getVSTMUseCycle(const InstrItineraryData *ItinData,
1776 const TargetInstrDesc &UseTID,
1777 unsigned UseClass,
1778 unsigned UseIdx, unsigned UseAlign) const {
1779 int RegNo = (int)(UseIdx+1) - UseTID.getNumOperands() + 1;
1780 if (RegNo <= 0)
1781 return ItinData->getOperandCycle(UseClass, UseIdx);
1782
1783 int UseCycle;
1784 if (Subtarget.isCortexA8()) {
1785 // (regno / 2) + (regno % 2) + 1
1786 UseCycle = RegNo / 2 + 1;
1787 if (RegNo % 2)
1788 ++UseCycle;
1789 } else if (Subtarget.isCortexA9()) {
1790 UseCycle = RegNo;
1791 bool isSStore = false;
1792 switch (UseTID.getOpcode()) {
1793 default: break;
1794 case ARM::VSTMS:
1795 case ARM::VSTMS_UPD:
1796 isSStore = true;
1797 break;
1798 }
1799 // If there are odd number of 'S' registers or if it's not 64-bit aligned,
1800 // then it takes an extra cycle.
1801 if ((isSStore && (RegNo % 2)) || UseAlign < 8)
1802 ++UseCycle;
1803 } else {
1804 // Assume the worst.
1805 UseCycle = RegNo + 2;
1806 }
1807
1808 return UseCycle;
1809}
1810
1811int
1812ARMBaseInstrInfo::getSTMUseCycle(const InstrItineraryData *ItinData,
1813 const TargetInstrDesc &UseTID,
1814 unsigned UseClass,
1815 unsigned UseIdx, unsigned UseAlign) const {
1816 int RegNo = (int)(UseIdx+1) - UseTID.getNumOperands() + 1;
1817 if (RegNo <= 0)
1818 return ItinData->getOperandCycle(UseClass, UseIdx);
1819
1820 int UseCycle;
1821 if (Subtarget.isCortexA8()) {
1822 UseCycle = RegNo / 2;
1823 if (UseCycle < 2)
1824 UseCycle = 2;
1825 // Read in E3.
1826 UseCycle += 2;
1827 } else if (Subtarget.isCortexA9()) {
1828 UseCycle = (RegNo / 2);
1829 // If there are odd number of registers or if it's not 64-bit aligned,
1830 // then it takes an extra AGU (Address Generation Unit) cycle.
1831 if ((RegNo % 2) || UseAlign < 8)
1832 ++UseCycle;
1833 } else {
1834 // Assume the worst.
1835 UseCycle = 1;
1836 }
1837 return UseCycle;
1838}
1839
1840int
Evan Chenga0792de2010-10-06 06:27:31 +00001841ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
1842 const TargetInstrDesc &DefTID,
1843 unsigned DefIdx, unsigned DefAlign,
1844 const TargetInstrDesc &UseTID,
1845 unsigned UseIdx, unsigned UseAlign) const {
1846 unsigned DefClass = DefTID.getSchedClass();
1847 unsigned UseClass = UseTID.getSchedClass();
1848
1849 if (DefIdx < DefTID.getNumDefs() && UseIdx < UseTID.getNumOperands())
1850 return ItinData->getOperandLatency(DefClass, DefIdx, UseClass, UseIdx);
1851
1852 // This may be a def / use of a variable_ops instruction, the operand
1853 // latency might be determinable dynamically. Let the target try to
1854 // figure it out.
Evan Cheng9e08ee52010-10-28 02:00:25 +00001855 int DefCycle = -1;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001856 bool LdmBypass = false;
Evan Chenga0792de2010-10-06 06:27:31 +00001857 switch (DefTID.getOpcode()) {
1858 default:
1859 DefCycle = ItinData->getOperandCycle(DefClass, DefIdx);
1860 break;
Evan Cheng5a50cee2010-10-07 01:50:48 +00001861 case ARM::VLDMD:
1862 case ARM::VLDMS:
1863 case ARM::VLDMD_UPD:
1864 case ARM::VLDMS_UPD: {
Evan Cheng344d9db2010-10-07 23:12:15 +00001865 DefCycle = getVLDMDefCycle(ItinData, DefTID, DefClass, DefIdx, DefAlign);
Evan Cheng5a50cee2010-10-07 01:50:48 +00001866 break;
1867 }
Evan Chenga0792de2010-10-06 06:27:31 +00001868 case ARM::LDM_RET:
1869 case ARM::LDM:
1870 case ARM::LDM_UPD:
1871 case ARM::tLDM:
1872 case ARM::tLDM_UPD:
1873 case ARM::tPUSH:
1874 case ARM::t2LDM_RET:
1875 case ARM::t2LDM:
1876 case ARM::t2LDM_UPD: {
1877 LdmBypass = 1;
Evan Cheng344d9db2010-10-07 23:12:15 +00001878 DefCycle = getLDMDefCycle(ItinData, DefTID, DefClass, DefIdx, DefAlign);
1879 break;
Evan Chenga0792de2010-10-06 06:27:31 +00001880 }
1881 }
1882
1883 if (DefCycle == -1)
1884 // We can't seem to determine the result latency of the def, assume it's 2.
1885 DefCycle = 2;
1886
1887 int UseCycle = -1;
1888 switch (UseTID.getOpcode()) {
1889 default:
1890 UseCycle = ItinData->getOperandCycle(UseClass, UseIdx);
1891 break;
Evan Cheng5a50cee2010-10-07 01:50:48 +00001892 case ARM::VSTMD:
1893 case ARM::VSTMS:
1894 case ARM::VSTMD_UPD:
1895 case ARM::VSTMS_UPD: {
Evan Cheng344d9db2010-10-07 23:12:15 +00001896 UseCycle = getVSTMUseCycle(ItinData, UseTID, UseClass, UseIdx, UseAlign);
Evan Cheng5a50cee2010-10-07 01:50:48 +00001897 break;
1898 }
Evan Chenga0792de2010-10-06 06:27:31 +00001899 case ARM::STM:
1900 case ARM::STM_UPD:
1901 case ARM::tSTM_UPD:
1902 case ARM::tPOP_RET:
1903 case ARM::tPOP:
1904 case ARM::t2STM:
1905 case ARM::t2STM_UPD: {
Evan Cheng344d9db2010-10-07 23:12:15 +00001906 UseCycle = getSTMUseCycle(ItinData, UseTID, UseClass, UseIdx, UseAlign);
Evan Cheng5a50cee2010-10-07 01:50:48 +00001907 break;
Evan Chenga0792de2010-10-06 06:27:31 +00001908 }
1909 }
1910
1911 if (UseCycle == -1)
1912 // Assume it's read in the first stage.
1913 UseCycle = 1;
1914
1915 UseCycle = DefCycle - UseCycle + 1;
1916 if (UseCycle > 0) {
1917 if (LdmBypass) {
1918 // It's a variable_ops instruction so we can't use DefIdx here. Just use
1919 // first def operand.
1920 if (ItinData->hasPipelineForwarding(DefClass, DefTID.getNumOperands()-1,
1921 UseClass, UseIdx))
1922 --UseCycle;
1923 } else if (ItinData->hasPipelineForwarding(DefClass, DefIdx,
1924 UseClass, UseIdx))
1925 --UseCycle;
1926 }
1927
1928 return UseCycle;
1929}
1930
1931int
1932ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
1933 const MachineInstr *DefMI, unsigned DefIdx,
1934 const MachineInstr *UseMI, unsigned UseIdx) const {
1935 if (DefMI->isCopyLike() || DefMI->isInsertSubreg() ||
1936 DefMI->isRegSequence() || DefMI->isImplicitDef())
1937 return 1;
1938
1939 const TargetInstrDesc &DefTID = DefMI->getDesc();
1940 if (!ItinData || ItinData->isEmpty())
1941 return DefTID.mayLoad() ? 3 : 1;
1942
Evan Chengdd9dd6f2010-10-23 02:04:38 +00001943
Evan Chenga0792de2010-10-06 06:27:31 +00001944 const TargetInstrDesc &UseTID = UseMI->getDesc();
Evan Chengdd9dd6f2010-10-23 02:04:38 +00001945 const MachineOperand &DefMO = DefMI->getOperand(DefIdx);
Evan Chenge09206d2010-10-29 23:16:55 +00001946 if (DefMO.getReg() == ARM::CPSR) {
1947 if (DefMI->getOpcode() == ARM::FMSTAT) {
1948 // fpscr -> cpsr stalls over 20 cycles on A8 (and earlier?)
1949 return Subtarget.isCortexA9() ? 1 : 20;
1950 }
1951
Evan Chengdd9dd6f2010-10-23 02:04:38 +00001952 // CPSR set and branch can be paired in the same cycle.
Evan Chenge09206d2010-10-29 23:16:55 +00001953 if (UseTID.isBranch())
1954 return 0;
1955 }
Evan Chengdd9dd6f2010-10-23 02:04:38 +00001956
Evan Chenga0792de2010-10-06 06:27:31 +00001957 unsigned DefAlign = DefMI->hasOneMemOperand()
1958 ? (*DefMI->memoperands_begin())->getAlignment() : 0;
1959 unsigned UseAlign = UseMI->hasOneMemOperand()
1960 ? (*UseMI->memoperands_begin())->getAlignment() : 0;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001961 int Latency = getOperandLatency(ItinData, DefTID, DefIdx, DefAlign,
1962 UseTID, UseIdx, UseAlign);
1963
1964 if (Latency > 1 &&
1965 (Subtarget.isCortexA8() || Subtarget.isCortexA9())) {
1966 // FIXME: Shifter op hack: no shift (i.e. [r +/- r]) or [r + r << 2]
1967 // variants are one cycle cheaper.
1968 switch (DefTID.getOpcode()) {
1969 default: break;
1970 case ARM::LDRrs:
1971 case ARM::LDRBrs: {
1972 unsigned ShOpVal = DefMI->getOperand(3).getImm();
1973 unsigned ShImm = ARM_AM::getAM2Offset(ShOpVal);
1974 if (ShImm == 0 ||
1975 (ShImm == 2 && ARM_AM::getAM2ShiftOpc(ShOpVal) == ARM_AM::lsl))
1976 --Latency;
1977 break;
1978 }
1979 case ARM::t2LDRs:
1980 case ARM::t2LDRBs:
1981 case ARM::t2LDRHs:
1982 case ARM::t2LDRSHs: {
1983 // Thumb2 mode: lsl only.
1984 unsigned ShAmt = DefMI->getOperand(3).getImm();
1985 if (ShAmt == 0 || ShAmt == 2)
1986 --Latency;
1987 break;
1988 }
1989 }
1990 }
1991
1992 return Latency;
Evan Chenga0792de2010-10-06 06:27:31 +00001993}
1994
1995int
1996ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
1997 SDNode *DefNode, unsigned DefIdx,
1998 SDNode *UseNode, unsigned UseIdx) const {
1999 if (!DefNode->isMachineOpcode())
2000 return 1;
2001
2002 const TargetInstrDesc &DefTID = get(DefNode->getMachineOpcode());
2003 if (!ItinData || ItinData->isEmpty())
2004 return DefTID.mayLoad() ? 3 : 1;
2005
Evan Cheng08975152010-10-29 18:09:28 +00002006 if (!UseNode->isMachineOpcode()) {
2007 int Latency = ItinData->getOperandCycle(DefTID.getSchedClass(), DefIdx);
2008 if (Subtarget.isCortexA9())
2009 return Latency <= 2 ? 1 : Latency - 1;
2010 else
2011 return Latency <= 3 ? 1 : Latency - 2;
2012 }
Evan Chenga0792de2010-10-06 06:27:31 +00002013
2014 const TargetInstrDesc &UseTID = get(UseNode->getMachineOpcode());
2015 const MachineSDNode *DefMN = dyn_cast<MachineSDNode>(DefNode);
2016 unsigned DefAlign = !DefMN->memoperands_empty()
2017 ? (*DefMN->memoperands_begin())->getAlignment() : 0;
2018 const MachineSDNode *UseMN = dyn_cast<MachineSDNode>(UseNode);
2019 unsigned UseAlign = !UseMN->memoperands_empty()
2020 ? (*UseMN->memoperands_begin())->getAlignment() : 0;
Evan Cheng7e2fe912010-10-28 06:47:08 +00002021 int Latency = getOperandLatency(ItinData, DefTID, DefIdx, DefAlign,
2022 UseTID, UseIdx, UseAlign);
2023
2024 if (Latency > 1 &&
2025 (Subtarget.isCortexA8() || Subtarget.isCortexA9())) {
2026 // FIXME: Shifter op hack: no shift (i.e. [r +/- r]) or [r + r << 2]
2027 // variants are one cycle cheaper.
2028 switch (DefTID.getOpcode()) {
2029 default: break;
2030 case ARM::LDRrs:
2031 case ARM::LDRBrs: {
2032 unsigned ShOpVal =
2033 cast<ConstantSDNode>(DefNode->getOperand(2))->getZExtValue();
2034 unsigned ShImm = ARM_AM::getAM2Offset(ShOpVal);
2035 if (ShImm == 0 ||
2036 (ShImm == 2 && ARM_AM::getAM2ShiftOpc(ShOpVal) == ARM_AM::lsl))
2037 --Latency;
2038 break;
2039 }
2040 case ARM::t2LDRs:
2041 case ARM::t2LDRBs:
2042 case ARM::t2LDRHs:
2043 case ARM::t2LDRSHs: {
2044 // Thumb2 mode: lsl only.
2045 unsigned ShAmt =
2046 cast<ConstantSDNode>(DefNode->getOperand(2))->getZExtValue();
2047 if (ShAmt == 0 || ShAmt == 2)
2048 --Latency;
2049 break;
2050 }
2051 }
2052 }
2053
2054 return Latency;
Evan Chenga0792de2010-10-06 06:27:31 +00002055}
Evan Cheng23128422010-10-19 18:58:51 +00002056
Evan Cheng8239daf2010-11-03 00:45:17 +00002057int ARMBaseInstrInfo::getInstrLatency(const InstrItineraryData *ItinData,
2058 const MachineInstr *MI,
2059 unsigned *PredCost) const {
2060 if (MI->isCopyLike() || MI->isInsertSubreg() ||
2061 MI->isRegSequence() || MI->isImplicitDef())
2062 return 1;
2063
2064 if (!ItinData || ItinData->isEmpty())
2065 return 1;
2066
2067 const TargetInstrDesc &TID = MI->getDesc();
2068 unsigned Class = TID.getSchedClass();
2069 unsigned UOps = ItinData->Itineraries[Class].NumMicroOps;
2070 if (PredCost && TID.hasImplicitDefOfPhysReg(ARM::CPSR))
2071 // When predicated, CPSR is an additional source operand for CPSR updating
2072 // instructions, this apparently increases their latencies.
2073 *PredCost = 1;
2074 if (UOps)
2075 return ItinData->getStageLatency(Class);
2076 return getNumMicroOps(ItinData, MI);
2077}
2078
2079int ARMBaseInstrInfo::getInstrLatency(const InstrItineraryData *ItinData,
2080 SDNode *Node) const {
2081 if (!Node->isMachineOpcode())
2082 return 1;
2083
2084 if (!ItinData || ItinData->isEmpty())
2085 return 1;
2086
2087 unsigned Opcode = Node->getMachineOpcode();
2088 switch (Opcode) {
2089 default:
2090 return ItinData->getStageLatency(get(Opcode).getSchedClass());
2091 case ARM::VLDMQ:
2092 case ARM::VSTMQ:
2093 return 2;
Eric Christopher391f2282010-11-11 19:26:03 +00002094 }
Evan Cheng8239daf2010-11-03 00:45:17 +00002095}
2096
Evan Cheng23128422010-10-19 18:58:51 +00002097bool ARMBaseInstrInfo::
2098hasHighOperandLatency(const InstrItineraryData *ItinData,
2099 const MachineRegisterInfo *MRI,
2100 const MachineInstr *DefMI, unsigned DefIdx,
2101 const MachineInstr *UseMI, unsigned UseIdx) const {
2102 unsigned DDomain = DefMI->getDesc().TSFlags & ARMII::DomainMask;
2103 unsigned UDomain = UseMI->getDesc().TSFlags & ARMII::DomainMask;
2104 if (Subtarget.isCortexA8() &&
2105 (DDomain == ARMII::DomainVFP || UDomain == ARMII::DomainVFP))
2106 // CortexA8 VFP instructions are not pipelined.
2107 return true;
2108
2109 // Hoist VFP / NEON instructions with 4 or higher latency.
2110 int Latency = getOperandLatency(ItinData, DefMI, DefIdx, UseMI, UseIdx);
2111 if (Latency <= 3)
2112 return false;
2113 return DDomain == ARMII::DomainVFP || DDomain == ARMII::DomainNEON ||
2114 UDomain == ARMII::DomainVFP || UDomain == ARMII::DomainNEON;
2115}
Evan Chengc8141df2010-10-26 02:08:50 +00002116
2117bool ARMBaseInstrInfo::
2118hasLowDefLatency(const InstrItineraryData *ItinData,
2119 const MachineInstr *DefMI, unsigned DefIdx) const {
2120 if (!ItinData || ItinData->isEmpty())
2121 return false;
2122
2123 unsigned DDomain = DefMI->getDesc().TSFlags & ARMII::DomainMask;
2124 if (DDomain == ARMII::DomainGeneral) {
2125 unsigned DefClass = DefMI->getDesc().getSchedClass();
2126 int DefCycle = ItinData->getOperandCycle(DefClass, DefIdx);
2127 return (DefCycle != -1 && DefCycle <= 2);
2128 }
2129 return false;
2130}