blob: 1d8799fd6684aff401dbef4604a027f982090925 [file] [log] [blame]
Jim Grosbach31c24bf2009-11-07 22:00:39 +00001//===- ARMBaseInstrInfo.h - ARM Base 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#ifndef ARMBASEINSTRUCTIONINFO_H
15#define ARMBASEINSTRUCTIONINFO_H
16
David Goodwin334c2642009-07-08 16:09:28 +000017#include "ARM.h"
Anton Korobeynikovb8e9ac82009-07-16 23:26:06 +000018#include "llvm/CodeGen/MachineInstrBuilder.h"
19#include "llvm/Target/TargetInstrInfo.h"
Evan Cheng48575f62010-12-05 22:04:16 +000020#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/SmallSet.h"
David Goodwin334c2642009-07-08 16:09:28 +000022
Evan Cheng4db3cff2011-07-01 17:57:27 +000023#define GET_INSTRINFO_HEADER
24#include "ARMGenInstrInfo.inc"
25
David Goodwin334c2642009-07-08 16:09:28 +000026namespace llvm {
Chris Lattner4dbbe342010-07-20 21:17:29 +000027 class ARMSubtarget;
28 class ARMBaseRegisterInfo;
David Goodwin334c2642009-07-08 16:09:28 +000029
30/// ARMII - This namespace holds all of the target specific flags that
31/// instruction info tracks.
32///
33namespace ARMII {
34 enum {
35 //===------------------------------------------------------------------===//
36 // Instruction Flags.
37
38 //===------------------------------------------------------------------===//
39 // This four-bit field describes the addressing mode used.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +000040 AddrModeMask = 0x1f, // The AddrMode enums are declared in ARMBaseInfo.h
David Goodwin334c2642009-07-08 16:09:28 +000041
42 // Size* - Flags to keep track of the size of an instruction.
Jim Grosbachd86609f2010-10-05 18:14:55 +000043 SizeShift = 5,
David Goodwin334c2642009-07-08 16:09:28 +000044 SizeMask = 7 << SizeShift,
45 SizeSpecial = 1, // 0 byte pseudo or special case.
46 Size8Bytes = 2,
47 Size4Bytes = 3,
48 Size2Bytes = 4,
49
Bob Wilsonbffb5b32010-03-13 07:34:35 +000050 // IndexMode - Unindex, pre-indexed, or post-indexed are valid for load
51 // and store ops only. Generic "updating" flag is used for ld/st multiple.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +000052 // The index mode enums are declared in ARMBaseInfo.h
Jim Grosbachd86609f2010-10-05 18:14:55 +000053 IndexModeShift = 8,
David Goodwin334c2642009-07-08 16:09:28 +000054 IndexModeMask = 3 << IndexModeShift,
David Goodwin334c2642009-07-08 16:09:28 +000055
56 //===------------------------------------------------------------------===//
57 // Instruction encoding formats.
58 //
Jim Grosbachd86609f2010-10-05 18:14:55 +000059 FormShift = 10,
David Goodwin334c2642009-07-08 16:09:28 +000060 FormMask = 0x3f << FormShift,
61
62 // Pseudo instructions
63 Pseudo = 0 << FormShift,
64
65 // Multiply instructions
66 MulFrm = 1 << FormShift,
67
68 // Branch instructions
69 BrFrm = 2 << FormShift,
70 BrMiscFrm = 3 << FormShift,
71
72 // Data Processing instructions
73 DPFrm = 4 << FormShift,
74 DPSoRegFrm = 5 << FormShift,
75
76 // Load and Store
77 LdFrm = 6 << FormShift,
78 StFrm = 7 << FormShift,
79 LdMiscFrm = 8 << FormShift,
80 StMiscFrm = 9 << FormShift,
81 LdStMulFrm = 10 << FormShift,
82
Johnny Chen81f04d52010-03-19 17:39:00 +000083 LdStExFrm = 11 << FormShift,
Jim Grosbach5278eb82009-12-11 01:42:04 +000084
David Goodwin334c2642009-07-08 16:09:28 +000085 // Miscellaneous arithmetic instructions
Johnny Chen81f04d52010-03-19 17:39:00 +000086 ArithMiscFrm = 12 << FormShift,
Bob Wilson9a1c1892010-08-11 00:01:18 +000087 SatFrm = 13 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +000088
89 // Extend instructions
Bob Wilson9a1c1892010-08-11 00:01:18 +000090 ExtFrm = 14 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +000091
92 // VFP formats
Bob Wilson9a1c1892010-08-11 00:01:18 +000093 VFPUnaryFrm = 15 << FormShift,
94 VFPBinaryFrm = 16 << FormShift,
95 VFPConv1Frm = 17 << FormShift,
96 VFPConv2Frm = 18 << FormShift,
97 VFPConv3Frm = 19 << FormShift,
98 VFPConv4Frm = 20 << FormShift,
99 VFPConv5Frm = 21 << FormShift,
100 VFPLdStFrm = 22 << FormShift,
101 VFPLdStMulFrm = 23 << FormShift,
102 VFPMiscFrm = 24 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000103
104 // Thumb format
Bob Wilson9a1c1892010-08-11 00:01:18 +0000105 ThumbFrm = 25 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000106
Bob Wilson26532632010-06-25 23:45:37 +0000107 // Miscelleaneous format
Bob Wilson9a1c1892010-08-11 00:01:18 +0000108 MiscFrm = 26 << FormShift,
Bob Wilson26532632010-06-25 23:45:37 +0000109
Bob Wilson1a913ed2010-06-11 21:34:50 +0000110 // NEON formats
Bob Wilson9a1c1892010-08-11 00:01:18 +0000111 NGetLnFrm = 27 << FormShift,
112 NSetLnFrm = 28 << FormShift,
113 NDupFrm = 29 << FormShift,
114 NLdStFrm = 30 << FormShift,
115 N1RegModImmFrm= 31 << FormShift,
116 N2RegFrm = 32 << FormShift,
117 NVCVTFrm = 33 << FormShift,
118 NVDupLnFrm = 34 << FormShift,
119 N2RegVShLFrm = 35 << FormShift,
120 N2RegVShRFrm = 36 << FormShift,
121 N3RegFrm = 37 << FormShift,
122 N3RegVShFrm = 38 << FormShift,
123 NVExtFrm = 39 << FormShift,
124 NVMulSLFrm = 40 << FormShift,
125 NVTBLFrm = 41 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000126
127 //===------------------------------------------------------------------===//
128 // Misc flags.
129
130 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
131 // it doesn't have a Rn operand.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000132 UnaryDP = 1 << 16,
David Goodwin334c2642009-07-08 16:09:28 +0000133
134 // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
135 // a 16-bit Thumb instruction if certain conditions are met.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000136 Xform16Bit = 1 << 17,
David Goodwin334c2642009-07-08 16:09:28 +0000137
138 //===------------------------------------------------------------------===//
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000139 // Code domain.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000140 DomainShift = 18,
Evan Cheng6557bce2011-02-22 19:53:14 +0000141 DomainMask = 7 << DomainShift,
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000142 DomainGeneral = 0 << DomainShift,
143 DomainVFP = 1 << DomainShift,
144 DomainNEON = 2 << DomainShift,
Evan Cheng6557bce2011-02-22 19:53:14 +0000145 DomainNEONA8 = 4 << DomainShift,
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000146
147 //===------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +0000148 // Field shifts - such shifts are used to set field while generating
149 // machine instructions.
Jim Grosbach42fac8e2010-10-11 23:16:21 +0000150 //
151 // FIXME: This list will need adjusting/fixing as the MC code emitter
152 // takes shape and the ARMCodeEmitter.cpp bits go away.
153 ShiftTypeShift = 4,
154
David Goodwin334c2642009-07-08 16:09:28 +0000155 M_BitShift = 5,
156 ShiftImmShift = 5,
157 ShiftShift = 7,
158 N_BitShift = 7,
159 ImmHiShift = 8,
160 SoRotImmShift = 8,
161 RegRsShift = 8,
162 ExtRotImmShift = 10,
163 RegRdLoShift = 12,
164 RegRdShift = 12,
165 RegRdHiShift = 16,
166 RegRnShift = 16,
167 S_BitShift = 20,
168 W_BitShift = 21,
169 AM3_I_BitShift = 22,
170 D_BitShift = 22,
171 U_BitShift = 23,
172 P_BitShift = 24,
173 I_BitShift = 25,
174 CondShift = 28
175 };
Evan Chengb46aaa32009-07-19 19:16:46 +0000176}
177
Evan Cheng4db3cff2011-07-01 17:57:27 +0000178class ARMBaseInstrInfo : public ARMGenInstrInfo {
Chris Lattner4dbbe342010-07-20 21:17:29 +0000179 const ARMSubtarget &Subtarget;
Evan Cheng48575f62010-12-05 22:04:16 +0000180
David Goodwin334c2642009-07-08 16:09:28 +0000181protected:
182 // Can be only subclassed.
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000183 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
Evan Cheng48575f62010-12-05 22:04:16 +0000184
David Goodwin334c2642009-07-08 16:09:28 +0000185public:
186 // Return the non-pre/post incrementing version of 'Opc'. Return 0
187 // if there is not such an opcode.
188 virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
189
David Goodwin334c2642009-07-08 16:09:28 +0000190 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
191 MachineBasicBlock::iterator &MBBI,
192 LiveVariables *LV) const;
193
194 virtual const ARMBaseRegisterInfo &getRegisterInfo() const =0;
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000195 const ARMSubtarget &getSubtarget() const { return Subtarget; }
David Goodwin334c2642009-07-08 16:09:28 +0000196
Evan Cheng48575f62010-12-05 22:04:16 +0000197 ScheduleHazardRecognizer *
Andrew Trick2da8bc82010-12-24 05:03:26 +0000198 CreateTargetHazardRecognizer(const TargetMachine *TM,
199 const ScheduleDAG *DAG) const;
200
201 ScheduleHazardRecognizer *
202 CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
203 const ScheduleDAG *DAG) const;
Evan Cheng48575f62010-12-05 22:04:16 +0000204
David Goodwin334c2642009-07-08 16:09:28 +0000205 // Branch analysis.
206 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
207 MachineBasicBlock *&FBB,
208 SmallVectorImpl<MachineOperand> &Cond,
Chris Lattner20628752010-07-22 21:27:00 +0000209 bool AllowModify = false) const;
David Goodwin334c2642009-07-08 16:09:28 +0000210 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
211 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
212 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000213 const SmallVectorImpl<MachineOperand> &Cond,
214 DebugLoc DL) const;
David Goodwin334c2642009-07-08 16:09:28 +0000215
216 virtual
217 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
218
219 // Predication support.
Evan Chengab331502009-07-10 01:38:27 +0000220 bool isPredicated(const MachineInstr *MI) const {
221 int PIdx = MI->findFirstPredOperandIdx();
222 return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL;
223 }
David Goodwin334c2642009-07-08 16:09:28 +0000224
225 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
226 int PIdx = MI->findFirstPredOperandIdx();
227 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
228 : ARMCC::AL;
229 }
230
231 virtual
232 bool PredicateInstruction(MachineInstr *MI,
233 const SmallVectorImpl<MachineOperand> &Pred) const;
234
235 virtual
236 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
237 const SmallVectorImpl<MachineOperand> &Pred2) const;
238
239 virtual bool DefinesPredicate(MachineInstr *MI,
240 std::vector<MachineOperand> &Pred) const;
241
Evan Chengac0869d2009-11-21 06:21:52 +0000242 virtual bool isPredicable(MachineInstr *MI) const;
243
David Goodwin334c2642009-07-08 16:09:28 +0000244 /// GetInstSize - Returns the size of the specified MachineInstr.
245 ///
246 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
247
David Goodwin334c2642009-07-08 16:09:28 +0000248 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
249 int &FrameIndex) const;
250 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
251 int &FrameIndex) const;
252
Jakob Stoklund Olesenac273662010-07-11 06:33:54 +0000253 virtual void copyPhysReg(MachineBasicBlock &MBB,
254 MachineBasicBlock::iterator I, DebugLoc DL,
255 unsigned DestReg, unsigned SrcReg,
256 bool KillSrc) const;
Evan Cheng5732ca02009-07-27 03:14:20 +0000257
David Goodwin334c2642009-07-08 16:09:28 +0000258 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
259 MachineBasicBlock::iterator MBBI,
260 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000261 const TargetRegisterClass *RC,
262 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000263
David Goodwin334c2642009-07-08 16:09:28 +0000264 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
265 MachineBasicBlock::iterator MBBI,
266 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000267 const TargetRegisterClass *RC,
268 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000269
Evan Cheng62b50652010-04-26 07:39:25 +0000270 virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
Evan Cheng8601a3d2010-04-29 01:13:30 +0000271 int FrameIx,
Evan Cheng62b50652010-04-26 07:39:25 +0000272 uint64_t Offset,
273 const MDNode *MDPtr,
274 DebugLoc DL) const;
275
Evan Chengfdc83402009-11-08 00:15:23 +0000276 virtual void reMaterialize(MachineBasicBlock &MBB,
277 MachineBasicBlock::iterator MI,
278 unsigned DestReg, unsigned SubIdx,
Evan Chengd57cdd52009-11-14 02:55:43 +0000279 const MachineInstr *Orig,
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +0000280 const TargetRegisterInfo &TRI) const;
Evan Chengfdc83402009-11-08 00:15:23 +0000281
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +0000282 MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const;
283
Evan Cheng506049f2010-03-03 01:44:33 +0000284 virtual bool produceSameValue(const MachineInstr *MI0,
Evan Cheng9fe20092011-01-20 08:34:58 +0000285 const MachineInstr *MI1,
286 const MachineRegisterInfo *MRI) const;
Evan Cheng86050dc2010-06-18 23:09:54 +0000287
Bill Wendling4b722102010-06-23 23:00:16 +0000288 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
289 /// determine if two loads are loading from the same base address. It should
290 /// only return true if the base pointers are the same and the only
291 /// differences between the two addresses is the offset. It also returns the
292 /// offsets by reference.
293 virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
294 int64_t &Offset1, int64_t &Offset2)const;
295
296 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000297 /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads
298 /// should be scheduled togther. On some targets if two loads are loading from
Bill Wendling4b722102010-06-23 23:00:16 +0000299 /// addresses in the same cache line, it's better if they are scheduled
300 /// together. This function takes two integers that represent the load offsets
301 /// from the common base address. It returns true if it decides it's desirable
302 /// to schedule the two loads together. "NumLoads" is the number of loads that
303 /// have already been scheduled after Load1.
304 virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
305 int64_t Offset1, int64_t Offset2,
306 unsigned NumLoads) const;
307
Evan Cheng86050dc2010-06-18 23:09:54 +0000308 virtual bool isSchedulingBoundary(const MachineInstr *MI,
309 const MachineBasicBlock *MBB,
310 const MachineFunction &MF) const;
Evan Cheng13151432010-06-25 22:42:03 +0000311
312 virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB,
Cameron Zwarich5876db72011-04-13 06:39:16 +0000313 unsigned NumCycles, unsigned ExtraPredCycles,
Jakub Staszakf81b7f62011-07-10 02:58:07 +0000314 const BranchProbability &Probability) const;
Evan Cheng13151432010-06-25 22:42:03 +0000315
Evan Cheng8239daf2010-11-03 00:45:17 +0000316 virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
317 unsigned NumT, unsigned ExtraT,
318 MachineBasicBlock &FMBB,
319 unsigned NumF, unsigned ExtraF,
Jakub Staszakf81b7f62011-07-10 02:58:07 +0000320 const BranchProbability &Probability) const;
Evan Cheng13151432010-06-25 22:42:03 +0000321
322 virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
Cameron Zwarich5876db72011-04-13 06:39:16 +0000323 unsigned NumCycles,
Jakub Staszakf81b7f62011-07-10 02:58:07 +0000324 const BranchProbability
325 &Probability) const {
Cameron Zwarich5876db72011-04-13 06:39:16 +0000326 return NumCycles == 1;
Evan Cheng13151432010-06-25 22:42:03 +0000327 }
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000328
Bill Wendlingc98af332010-08-08 05:04:59 +0000329 /// AnalyzeCompare - For a comparison instruction, return the source register
330 /// in SrcReg and the value it compares against in CmpValue. Return true if
331 /// the comparison instruction can be analyzed.
332 virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000333 int &CmpMask, int &CmpValue) const;
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000334
Bill Wendlinga6556862010-09-11 00:13:50 +0000335 /// OptimizeCompareInstr - Convert the instruction to set the zero flag so
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000336 /// that we can remove a "comparison with zero".
Bill Wendlinga6556862010-09-11 00:13:50 +0000337 virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000338 int CmpMask, int CmpValue,
Evan Chengeb96a2f2010-11-15 21:20:45 +0000339 const MachineRegisterInfo *MRI) const;
Evan Cheng5f54ce32010-09-09 18:18:55 +0000340
Evan Chengc4af4632010-11-17 20:13:28 +0000341 /// FoldImmediate - 'Reg' is known to be defined by a move immediate
342 /// instruction, try to fold the immediate into the use instruction.
343 virtual bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
344 unsigned Reg, MachineRegisterInfo *MRI) const;
345
Evan Cheng8239daf2010-11-03 00:45:17 +0000346 virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
347 const MachineInstr *MI) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000348
349 virtual
350 int getOperandLatency(const InstrItineraryData *ItinData,
351 const MachineInstr *DefMI, unsigned DefIdx,
352 const MachineInstr *UseMI, unsigned UseIdx) const;
353 virtual
354 int getOperandLatency(const InstrItineraryData *ItinData,
355 SDNode *DefNode, unsigned DefIdx,
356 SDNode *UseNode, unsigned UseIdx) const;
357private:
Evan Cheng344d9db2010-10-07 23:12:15 +0000358 int getVLDMDefCycle(const InstrItineraryData *ItinData,
Evan Chenge837dea2011-06-28 19:10:37 +0000359 const MCInstrDesc &DefMCID,
Evan Cheng344d9db2010-10-07 23:12:15 +0000360 unsigned DefClass,
361 unsigned DefIdx, unsigned DefAlign) const;
362 int getLDMDefCycle(const InstrItineraryData *ItinData,
Evan Chenge837dea2011-06-28 19:10:37 +0000363 const MCInstrDesc &DefMCID,
Evan Cheng344d9db2010-10-07 23:12:15 +0000364 unsigned DefClass,
365 unsigned DefIdx, unsigned DefAlign) const;
366 int getVSTMUseCycle(const InstrItineraryData *ItinData,
Evan Chenge837dea2011-06-28 19:10:37 +0000367 const MCInstrDesc &UseMCID,
Evan Cheng344d9db2010-10-07 23:12:15 +0000368 unsigned UseClass,
369 unsigned UseIdx, unsigned UseAlign) const;
370 int getSTMUseCycle(const InstrItineraryData *ItinData,
Evan Chenge837dea2011-06-28 19:10:37 +0000371 const MCInstrDesc &UseMCID,
Evan Cheng344d9db2010-10-07 23:12:15 +0000372 unsigned UseClass,
373 unsigned UseIdx, unsigned UseAlign) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000374 int getOperandLatency(const InstrItineraryData *ItinData,
Evan Chenge837dea2011-06-28 19:10:37 +0000375 const MCInstrDesc &DefMCID,
Evan Chenga0792de2010-10-06 06:27:31 +0000376 unsigned DefIdx, unsigned DefAlign,
Evan Chenge837dea2011-06-28 19:10:37 +0000377 const MCInstrDesc &UseMCID,
Evan Chenga0792de2010-10-06 06:27:31 +0000378 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng23128422010-10-19 18:58:51 +0000379
Evan Cheng8239daf2010-11-03 00:45:17 +0000380 int getInstrLatency(const InstrItineraryData *ItinData,
381 const MachineInstr *MI, unsigned *PredCost = 0) const;
382
383 int getInstrLatency(const InstrItineraryData *ItinData,
384 SDNode *Node) const;
385
Evan Cheng23128422010-10-19 18:58:51 +0000386 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
387 const MachineRegisterInfo *MRI,
388 const MachineInstr *DefMI, unsigned DefIdx,
389 const MachineInstr *UseMI, unsigned UseIdx) const;
Evan Chengc8141df2010-10-26 02:08:50 +0000390 bool hasLowDefLatency(const InstrItineraryData *ItinData,
391 const MachineInstr *DefMI, unsigned DefIdx) const;
Evan Cheng48575f62010-12-05 22:04:16 +0000392
393private:
394 /// Modeling special VFP / NEON fp MLA / MLS hazards.
395
396 /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal
397 /// MLx table.
398 DenseMap<unsigned, unsigned> MLxEntryMap;
399
400 /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause
401 /// stalls when scheduled together with fp MLA / MLS opcodes.
402 SmallSet<unsigned, 16> MLxHazardOpcodes;
403
404public:
405 /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS
406 /// instruction.
407 bool isFpMLxInstruction(unsigned Opcode) const {
408 return MLxEntryMap.count(Opcode);
409 }
410
411 /// isFpMLxInstruction - This version also returns the multiply opcode and the
412 /// addition / subtraction opcode to expand to. Return true for 'HasLane' for
413 /// the MLX instructions with an extra lane operand.
414 bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc,
415 unsigned &AddSubOpc, bool &NegAcc,
416 bool &HasLane) const;
417
418 /// canCauseFpMLxStall - Return true if an instruction of the specified opcode
419 /// will cause stalls when scheduled after (within 4-cycle window) a fp
420 /// MLA / MLS instruction.
421 bool canCauseFpMLxStall(unsigned Opcode) const {
422 return MLxHazardOpcodes.count(Opcode);
423 }
David Goodwin334c2642009-07-08 16:09:28 +0000424};
Evan Cheng6495f632009-07-28 05:48:47 +0000425
426static inline
427const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
428 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwin334c2642009-07-08 16:09:28 +0000429}
430
Evan Cheng6495f632009-07-28 05:48:47 +0000431static inline
432const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
433 return MIB.addReg(0);
434}
435
436static inline
Evan Chenge8af1f92009-08-10 02:37:24 +0000437const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
438 bool isDead = false) {
439 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng6495f632009-07-28 05:48:47 +0000440}
441
442static inline
Evan Chengbc9b7542009-08-15 07:59:10 +0000443const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
444 return MIB.addReg(0);
445}
446
447static inline
Evan Cheng6495f632009-07-28 05:48:47 +0000448bool isUncondBranchOpcode(int Opc) {
449 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
450}
451
452static inline
453bool isCondBranchOpcode(int Opc) {
454 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
455}
456
457static inline
458bool isJumpTableBranchOpcode(int Opc) {
459 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
460 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
461}
462
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000463static inline
464bool isIndirectBranchOpcode(int Opc) {
Bill Wendling6e46d842010-11-30 00:48:15 +0000465 return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000466}
467
Evan Cheng8fb90362009-08-08 03:20:32 +0000468/// getInstrPredicate - If instruction is predicated, returns its predicate
469/// condition, otherwise returns AL. It also returns the condition code
470/// register by reference.
Evan Cheng5adb66a2009-09-28 09:14:39 +0000471ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
Evan Cheng8fb90362009-08-08 03:20:32 +0000472
Evan Cheng6495f632009-07-28 05:48:47 +0000473int getMatchingCondBranchOpcode(int Opc);
474
475/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
476/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
477/// code.
478void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
479 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
480 unsigned DestReg, unsigned BaseReg, int NumBytes,
481 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikov57caad72011-03-05 18:43:32 +0000482 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Evan Cheng6495f632009-07-28 05:48:47 +0000483
484void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
485 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
486 unsigned DestReg, unsigned BaseReg, int NumBytes,
487 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikov57caad72011-03-05 18:43:32 +0000488 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Jim Grosbache4ad3872010-10-19 23:27:08 +0000489void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
Anton Korobeynikov57caad72011-03-05 18:43:32 +0000490 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
Jim Grosbache4ad3872010-10-19 23:27:08 +0000491 unsigned DestReg, unsigned BaseReg,
492 int NumBytes, const TargetInstrInfo &TII,
493 const ARMBaseRegisterInfo& MRI,
Anton Korobeynikov57caad72011-03-05 18:43:32 +0000494 unsigned MIFlags = 0);
Evan Cheng6495f632009-07-28 05:48:47 +0000495
496
Jim Grosbach764ab522009-08-11 15:33:49 +0000497/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Chengcdbb3f52009-08-27 01:23:50 +0000498/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
499/// offset could not be handled directly in MI, and return the left-over
500/// portion by reference.
501bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
502 unsigned FrameReg, int &Offset,
503 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000504
Evan Chengcdbb3f52009-08-27 01:23:50 +0000505bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
506 unsigned FrameReg, int &Offset,
507 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000508
509} // End llvm namespace
510
David Goodwin334c2642009-07-08 16:09:28 +0000511#endif