blob: 30095fe73566b0dc9c57fdf2ca190407f372a6f9 [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
23namespace llvm {
Chris Lattner4dbbe342010-07-20 21:17:29 +000024 class ARMSubtarget;
25 class ARMBaseRegisterInfo;
David Goodwin334c2642009-07-08 16:09:28 +000026
27/// ARMII - This namespace holds all of the target specific flags that
28/// instruction info tracks.
29///
30namespace ARMII {
31 enum {
32 //===------------------------------------------------------------------===//
33 // Instruction Flags.
34
35 //===------------------------------------------------------------------===//
36 // This four-bit field describes the addressing mode used.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +000037 AddrModeMask = 0x1f, // The AddrMode enums are declared in ARMBaseInfo.h
David Goodwin334c2642009-07-08 16:09:28 +000038
39 // Size* - Flags to keep track of the size of an instruction.
Jim Grosbachd86609f2010-10-05 18:14:55 +000040 SizeShift = 5,
David Goodwin334c2642009-07-08 16:09:28 +000041 SizeMask = 7 << SizeShift,
42 SizeSpecial = 1, // 0 byte pseudo or special case.
43 Size8Bytes = 2,
44 Size4Bytes = 3,
45 Size2Bytes = 4,
46
Bob Wilsonbffb5b32010-03-13 07:34:35 +000047 // IndexMode - Unindex, pre-indexed, or post-indexed are valid for load
48 // and store ops only. Generic "updating" flag is used for ld/st multiple.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +000049 // The index mode enums are declared in ARMBaseInfo.h
Jim Grosbachd86609f2010-10-05 18:14:55 +000050 IndexModeShift = 8,
David Goodwin334c2642009-07-08 16:09:28 +000051 IndexModeMask = 3 << IndexModeShift,
David Goodwin334c2642009-07-08 16:09:28 +000052
53 //===------------------------------------------------------------------===//
54 // Instruction encoding formats.
55 //
Jim Grosbachd86609f2010-10-05 18:14:55 +000056 FormShift = 10,
David Goodwin334c2642009-07-08 16:09:28 +000057 FormMask = 0x3f << FormShift,
58
59 // Pseudo instructions
60 Pseudo = 0 << FormShift,
61
62 // Multiply instructions
63 MulFrm = 1 << FormShift,
64
65 // Branch instructions
66 BrFrm = 2 << FormShift,
67 BrMiscFrm = 3 << FormShift,
68
69 // Data Processing instructions
70 DPFrm = 4 << FormShift,
71 DPSoRegFrm = 5 << FormShift,
72
73 // Load and Store
74 LdFrm = 6 << FormShift,
75 StFrm = 7 << FormShift,
76 LdMiscFrm = 8 << FormShift,
77 StMiscFrm = 9 << FormShift,
78 LdStMulFrm = 10 << FormShift,
79
Johnny Chen81f04d52010-03-19 17:39:00 +000080 LdStExFrm = 11 << FormShift,
Jim Grosbach5278eb82009-12-11 01:42:04 +000081
David Goodwin334c2642009-07-08 16:09:28 +000082 // Miscellaneous arithmetic instructions
Johnny Chen81f04d52010-03-19 17:39:00 +000083 ArithMiscFrm = 12 << FormShift,
Bob Wilson9a1c1892010-08-11 00:01:18 +000084 SatFrm = 13 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +000085
86 // Extend instructions
Bob Wilson9a1c1892010-08-11 00:01:18 +000087 ExtFrm = 14 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +000088
89 // VFP formats
Bob Wilson9a1c1892010-08-11 00:01:18 +000090 VFPUnaryFrm = 15 << FormShift,
91 VFPBinaryFrm = 16 << FormShift,
92 VFPConv1Frm = 17 << FormShift,
93 VFPConv2Frm = 18 << FormShift,
94 VFPConv3Frm = 19 << FormShift,
95 VFPConv4Frm = 20 << FormShift,
96 VFPConv5Frm = 21 << FormShift,
97 VFPLdStFrm = 22 << FormShift,
98 VFPLdStMulFrm = 23 << FormShift,
99 VFPMiscFrm = 24 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000100
101 // Thumb format
Bob Wilson9a1c1892010-08-11 00:01:18 +0000102 ThumbFrm = 25 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000103
Bob Wilson26532632010-06-25 23:45:37 +0000104 // Miscelleaneous format
Bob Wilson9a1c1892010-08-11 00:01:18 +0000105 MiscFrm = 26 << FormShift,
Bob Wilson26532632010-06-25 23:45:37 +0000106
Bob Wilson1a913ed2010-06-11 21:34:50 +0000107 // NEON formats
Bob Wilson9a1c1892010-08-11 00:01:18 +0000108 NGetLnFrm = 27 << FormShift,
109 NSetLnFrm = 28 << FormShift,
110 NDupFrm = 29 << FormShift,
111 NLdStFrm = 30 << FormShift,
112 N1RegModImmFrm= 31 << FormShift,
113 N2RegFrm = 32 << FormShift,
114 NVCVTFrm = 33 << FormShift,
115 NVDupLnFrm = 34 << FormShift,
116 N2RegVShLFrm = 35 << FormShift,
117 N2RegVShRFrm = 36 << FormShift,
118 N3RegFrm = 37 << FormShift,
119 N3RegVShFrm = 38 << FormShift,
120 NVExtFrm = 39 << FormShift,
121 NVMulSLFrm = 40 << FormShift,
122 NVTBLFrm = 41 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000123
124 //===------------------------------------------------------------------===//
125 // Misc flags.
126
127 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
128 // it doesn't have a Rn operand.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000129 UnaryDP = 1 << 16,
David Goodwin334c2642009-07-08 16:09:28 +0000130
131 // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
132 // a 16-bit Thumb instruction if certain conditions are met.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000133 Xform16Bit = 1 << 17,
David Goodwin334c2642009-07-08 16:09:28 +0000134
135 //===------------------------------------------------------------------===//
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000136 // Code domain.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000137 DomainShift = 18,
Evan Cheng6557bce2011-02-22 19:53:14 +0000138 DomainMask = 7 << DomainShift,
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000139 DomainGeneral = 0 << DomainShift,
140 DomainVFP = 1 << DomainShift,
141 DomainNEON = 2 << DomainShift,
Evan Cheng6557bce2011-02-22 19:53:14 +0000142 DomainNEONA8 = 4 << DomainShift,
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000143
144 //===------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +0000145 // Field shifts - such shifts are used to set field while generating
146 // machine instructions.
Jim Grosbach42fac8e2010-10-11 23:16:21 +0000147 //
148 // FIXME: This list will need adjusting/fixing as the MC code emitter
149 // takes shape and the ARMCodeEmitter.cpp bits go away.
150 ShiftTypeShift = 4,
151
David Goodwin334c2642009-07-08 16:09:28 +0000152 M_BitShift = 5,
153 ShiftImmShift = 5,
154 ShiftShift = 7,
155 N_BitShift = 7,
156 ImmHiShift = 8,
157 SoRotImmShift = 8,
158 RegRsShift = 8,
159 ExtRotImmShift = 10,
160 RegRdLoShift = 12,
161 RegRdShift = 12,
162 RegRdHiShift = 16,
163 RegRnShift = 16,
164 S_BitShift = 20,
165 W_BitShift = 21,
166 AM3_I_BitShift = 22,
167 D_BitShift = 22,
168 U_BitShift = 23,
169 P_BitShift = 24,
170 I_BitShift = 25,
171 CondShift = 28
172 };
Evan Chengb46aaa32009-07-19 19:16:46 +0000173}
174
David Goodwin334c2642009-07-08 16:09:28 +0000175class ARMBaseInstrInfo : public TargetInstrInfoImpl {
Chris Lattner4dbbe342010-07-20 21:17:29 +0000176 const ARMSubtarget &Subtarget;
Evan Cheng48575f62010-12-05 22:04:16 +0000177
David Goodwin334c2642009-07-08 16:09:28 +0000178protected:
179 // Can be only subclassed.
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000180 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
Evan Cheng48575f62010-12-05 22:04:16 +0000181
David Goodwin334c2642009-07-08 16:09:28 +0000182public:
183 // Return the non-pre/post incrementing version of 'Opc'. Return 0
184 // if there is not such an opcode.
185 virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
186
David Goodwin334c2642009-07-08 16:09:28 +0000187 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
188 MachineBasicBlock::iterator &MBBI,
189 LiveVariables *LV) const;
190
191 virtual const ARMBaseRegisterInfo &getRegisterInfo() const =0;
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000192 const ARMSubtarget &getSubtarget() const { return Subtarget; }
David Goodwin334c2642009-07-08 16:09:28 +0000193
Evan Cheng48575f62010-12-05 22:04:16 +0000194 ScheduleHazardRecognizer *
Andrew Trick2da8bc82010-12-24 05:03:26 +0000195 CreateTargetHazardRecognizer(const TargetMachine *TM,
196 const ScheduleDAG *DAG) const;
197
198 ScheduleHazardRecognizer *
199 CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
200 const ScheduleDAG *DAG) const;
Evan Cheng48575f62010-12-05 22:04:16 +0000201
David Goodwin334c2642009-07-08 16:09:28 +0000202 // Branch analysis.
203 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
204 MachineBasicBlock *&FBB,
205 SmallVectorImpl<MachineOperand> &Cond,
Chris Lattner20628752010-07-22 21:27:00 +0000206 bool AllowModify = false) const;
David Goodwin334c2642009-07-08 16:09:28 +0000207 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
208 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
209 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000210 const SmallVectorImpl<MachineOperand> &Cond,
211 DebugLoc DL) const;
David Goodwin334c2642009-07-08 16:09:28 +0000212
213 virtual
214 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
215
216 // Predication support.
Evan Chengab331502009-07-10 01:38:27 +0000217 bool isPredicated(const MachineInstr *MI) const {
218 int PIdx = MI->findFirstPredOperandIdx();
219 return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL;
220 }
David Goodwin334c2642009-07-08 16:09:28 +0000221
222 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
223 int PIdx = MI->findFirstPredOperandIdx();
224 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
225 : ARMCC::AL;
226 }
227
228 virtual
229 bool PredicateInstruction(MachineInstr *MI,
230 const SmallVectorImpl<MachineOperand> &Pred) const;
231
232 virtual
233 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
234 const SmallVectorImpl<MachineOperand> &Pred2) const;
235
236 virtual bool DefinesPredicate(MachineInstr *MI,
237 std::vector<MachineOperand> &Pred) const;
238
Evan Chengac0869d2009-11-21 06:21:52 +0000239 virtual bool isPredicable(MachineInstr *MI) const;
240
David Goodwin334c2642009-07-08 16:09:28 +0000241 /// GetInstSize - Returns the size of the specified MachineInstr.
242 ///
243 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
244
David Goodwin334c2642009-07-08 16:09:28 +0000245 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
246 int &FrameIndex) const;
247 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
248 int &FrameIndex) const;
249
Jakob Stoklund Olesenac273662010-07-11 06:33:54 +0000250 virtual void copyPhysReg(MachineBasicBlock &MBB,
251 MachineBasicBlock::iterator I, DebugLoc DL,
252 unsigned DestReg, unsigned SrcReg,
253 bool KillSrc) const;
Evan Cheng5732ca02009-07-27 03:14:20 +0000254
David Goodwin334c2642009-07-08 16:09:28 +0000255 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
256 MachineBasicBlock::iterator MBBI,
257 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000258 const TargetRegisterClass *RC,
259 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000260
David Goodwin334c2642009-07-08 16:09:28 +0000261 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
262 MachineBasicBlock::iterator MBBI,
263 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000264 const TargetRegisterClass *RC,
265 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000266
Evan Cheng62b50652010-04-26 07:39:25 +0000267 virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
Evan Cheng8601a3d2010-04-29 01:13:30 +0000268 int FrameIx,
Evan Cheng62b50652010-04-26 07:39:25 +0000269 uint64_t Offset,
270 const MDNode *MDPtr,
271 DebugLoc DL) const;
272
Evan Chengfdc83402009-11-08 00:15:23 +0000273 virtual void reMaterialize(MachineBasicBlock &MBB,
274 MachineBasicBlock::iterator MI,
275 unsigned DestReg, unsigned SubIdx,
Evan Chengd57cdd52009-11-14 02:55:43 +0000276 const MachineInstr *Orig,
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +0000277 const TargetRegisterInfo &TRI) const;
Evan Chengfdc83402009-11-08 00:15:23 +0000278
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +0000279 MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const;
280
Evan Cheng506049f2010-03-03 01:44:33 +0000281 virtual bool produceSameValue(const MachineInstr *MI0,
Evan Cheng9fe20092011-01-20 08:34:58 +0000282 const MachineInstr *MI1,
283 const MachineRegisterInfo *MRI) const;
Evan Cheng86050dc2010-06-18 23:09:54 +0000284
Bill Wendling4b722102010-06-23 23:00:16 +0000285 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
286 /// determine if two loads are loading from the same base address. It should
287 /// only return true if the base pointers are the same and the only
288 /// differences between the two addresses is the offset. It also returns the
289 /// offsets by reference.
290 virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
291 int64_t &Offset1, int64_t &Offset2)const;
292
293 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
294 /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should
295 /// be scheduled togther. On some targets if two loads are loading from
296 /// addresses in the same cache line, it's better if they are scheduled
297 /// together. This function takes two integers that represent the load offsets
298 /// from the common base address. It returns true if it decides it's desirable
299 /// to schedule the two loads together. "NumLoads" is the number of loads that
300 /// have already been scheduled after Load1.
301 virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
302 int64_t Offset1, int64_t Offset2,
303 unsigned NumLoads) const;
304
Evan Cheng86050dc2010-06-18 23:09:54 +0000305 virtual bool isSchedulingBoundary(const MachineInstr *MI,
306 const MachineBasicBlock *MBB,
307 const MachineFunction &MF) const;
Evan Cheng13151432010-06-25 22:42:03 +0000308
309 virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB,
Evan Cheng8239daf2010-11-03 00:45:17 +0000310 unsigned NumCyles, unsigned ExtraPredCycles,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000311 float Prob, float Confidence) const;
Evan Cheng13151432010-06-25 22:42:03 +0000312
Evan Cheng8239daf2010-11-03 00:45:17 +0000313 virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
314 unsigned NumT, unsigned ExtraT,
315 MachineBasicBlock &FMBB,
316 unsigned NumF, unsigned ExtraF,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000317 float Probability, float Confidence) const;
Evan Cheng13151432010-06-25 22:42:03 +0000318
319 virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
Evan Cheng8239daf2010-11-03 00:45:17 +0000320 unsigned NumCyles,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000321 float Probability,
322 float Confidence) const {
Evan Cheng8239daf2010-11-03 00:45:17 +0000323 return NumCyles == 1;
Evan Cheng13151432010-06-25 22:42:03 +0000324 }
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000325
Bill Wendlingc98af332010-08-08 05:04:59 +0000326 /// AnalyzeCompare - For a comparison instruction, return the source register
327 /// in SrcReg and the value it compares against in CmpValue. Return true if
328 /// the comparison instruction can be analyzed.
329 virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000330 int &CmpMask, int &CmpValue) const;
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000331
Bill Wendlinga6556862010-09-11 00:13:50 +0000332 /// OptimizeCompareInstr - Convert the instruction to set the zero flag so
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000333 /// that we can remove a "comparison with zero".
Bill Wendlinga6556862010-09-11 00:13:50 +0000334 virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000335 int CmpMask, int CmpValue,
Evan Chengeb96a2f2010-11-15 21:20:45 +0000336 const MachineRegisterInfo *MRI) const;
Evan Cheng5f54ce32010-09-09 18:18:55 +0000337
Evan Chengc4af4632010-11-17 20:13:28 +0000338 /// FoldImmediate - 'Reg' is known to be defined by a move immediate
339 /// instruction, try to fold the immediate into the use instruction.
340 virtual bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
341 unsigned Reg, MachineRegisterInfo *MRI) const;
342
Evan Cheng8239daf2010-11-03 00:45:17 +0000343 virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
344 const MachineInstr *MI) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000345
346 virtual
347 int getOperandLatency(const InstrItineraryData *ItinData,
348 const MachineInstr *DefMI, unsigned DefIdx,
349 const MachineInstr *UseMI, unsigned UseIdx) const;
350 virtual
351 int getOperandLatency(const InstrItineraryData *ItinData,
352 SDNode *DefNode, unsigned DefIdx,
353 SDNode *UseNode, unsigned UseIdx) const;
354private:
Evan Cheng344d9db2010-10-07 23:12:15 +0000355 int getVLDMDefCycle(const InstrItineraryData *ItinData,
356 const TargetInstrDesc &DefTID,
357 unsigned DefClass,
358 unsigned DefIdx, unsigned DefAlign) const;
359 int getLDMDefCycle(const InstrItineraryData *ItinData,
360 const TargetInstrDesc &DefTID,
361 unsigned DefClass,
362 unsigned DefIdx, unsigned DefAlign) const;
363 int getVSTMUseCycle(const InstrItineraryData *ItinData,
364 const TargetInstrDesc &UseTID,
365 unsigned UseClass,
366 unsigned UseIdx, unsigned UseAlign) const;
367 int getSTMUseCycle(const InstrItineraryData *ItinData,
368 const TargetInstrDesc &UseTID,
369 unsigned UseClass,
370 unsigned UseIdx, unsigned UseAlign) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000371 int getOperandLatency(const InstrItineraryData *ItinData,
372 const TargetInstrDesc &DefTID,
373 unsigned DefIdx, unsigned DefAlign,
374 const TargetInstrDesc &UseTID,
375 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng23128422010-10-19 18:58:51 +0000376
Evan Cheng8239daf2010-11-03 00:45:17 +0000377 int getInstrLatency(const InstrItineraryData *ItinData,
378 const MachineInstr *MI, unsigned *PredCost = 0) const;
379
380 int getInstrLatency(const InstrItineraryData *ItinData,
381 SDNode *Node) const;
382
Evan Cheng23128422010-10-19 18:58:51 +0000383 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
384 const MachineRegisterInfo *MRI,
385 const MachineInstr *DefMI, unsigned DefIdx,
386 const MachineInstr *UseMI, unsigned UseIdx) const;
Evan Chengc8141df2010-10-26 02:08:50 +0000387 bool hasLowDefLatency(const InstrItineraryData *ItinData,
388 const MachineInstr *DefMI, unsigned DefIdx) const;
Evan Cheng48575f62010-12-05 22:04:16 +0000389
390private:
391 /// Modeling special VFP / NEON fp MLA / MLS hazards.
392
393 /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal
394 /// MLx table.
395 DenseMap<unsigned, unsigned> MLxEntryMap;
396
397 /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause
398 /// stalls when scheduled together with fp MLA / MLS opcodes.
399 SmallSet<unsigned, 16> MLxHazardOpcodes;
400
401public:
402 /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS
403 /// instruction.
404 bool isFpMLxInstruction(unsigned Opcode) const {
405 return MLxEntryMap.count(Opcode);
406 }
407
408 /// isFpMLxInstruction - This version also returns the multiply opcode and the
409 /// addition / subtraction opcode to expand to. Return true for 'HasLane' for
410 /// the MLX instructions with an extra lane operand.
411 bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc,
412 unsigned &AddSubOpc, bool &NegAcc,
413 bool &HasLane) const;
414
415 /// canCauseFpMLxStall - Return true if an instruction of the specified opcode
416 /// will cause stalls when scheduled after (within 4-cycle window) a fp
417 /// MLA / MLS instruction.
418 bool canCauseFpMLxStall(unsigned Opcode) const {
419 return MLxHazardOpcodes.count(Opcode);
420 }
David Goodwin334c2642009-07-08 16:09:28 +0000421};
Evan Cheng6495f632009-07-28 05:48:47 +0000422
423static inline
424const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
425 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwin334c2642009-07-08 16:09:28 +0000426}
427
Evan Cheng6495f632009-07-28 05:48:47 +0000428static inline
429const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
430 return MIB.addReg(0);
431}
432
433static inline
Evan Chenge8af1f92009-08-10 02:37:24 +0000434const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
435 bool isDead = false) {
436 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng6495f632009-07-28 05:48:47 +0000437}
438
439static inline
Evan Chengbc9b7542009-08-15 07:59:10 +0000440const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
441 return MIB.addReg(0);
442}
443
444static inline
Evan Cheng6495f632009-07-28 05:48:47 +0000445bool isUncondBranchOpcode(int Opc) {
446 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
447}
448
449static inline
450bool isCondBranchOpcode(int Opc) {
451 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
452}
453
454static inline
455bool isJumpTableBranchOpcode(int Opc) {
456 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
457 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
458}
459
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000460static inline
461bool isIndirectBranchOpcode(int Opc) {
Bill Wendling6e46d842010-11-30 00:48:15 +0000462 return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000463}
464
Evan Cheng8fb90362009-08-08 03:20:32 +0000465/// getInstrPredicate - If instruction is predicated, returns its predicate
466/// condition, otherwise returns AL. It also returns the condition code
467/// register by reference.
Evan Cheng5adb66a2009-09-28 09:14:39 +0000468ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
Evan Cheng8fb90362009-08-08 03:20:32 +0000469
Evan Cheng6495f632009-07-28 05:48:47 +0000470int getMatchingCondBranchOpcode(int Opc);
471
472/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
473/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
474/// code.
475void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
476 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
477 unsigned DestReg, unsigned BaseReg, int NumBytes,
478 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikov57caad72011-03-05 18:43:32 +0000479 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Evan Cheng6495f632009-07-28 05:48:47 +0000480
481void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
482 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
483 unsigned DestReg, unsigned BaseReg, int NumBytes,
484 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikov57caad72011-03-05 18:43:32 +0000485 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Jim Grosbache4ad3872010-10-19 23:27:08 +0000486void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
Anton Korobeynikov57caad72011-03-05 18:43:32 +0000487 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
Jim Grosbache4ad3872010-10-19 23:27:08 +0000488 unsigned DestReg, unsigned BaseReg,
489 int NumBytes, const TargetInstrInfo &TII,
490 const ARMBaseRegisterInfo& MRI,
Anton Korobeynikov57caad72011-03-05 18:43:32 +0000491 unsigned MIFlags = 0);
Evan Cheng6495f632009-07-28 05:48:47 +0000492
493
Jim Grosbach764ab522009-08-11 15:33:49 +0000494/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Chengcdbb3f52009-08-27 01:23:50 +0000495/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
496/// offset could not be handled directly in MI, and return the left-over
497/// portion by reference.
498bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
499 unsigned FrameReg, int &Offset,
500 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000501
Evan Chengcdbb3f52009-08-27 01:23:50 +0000502bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
503 unsigned FrameReg, int &Offset,
504 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000505
506} // End llvm namespace
507
David Goodwin334c2642009-07-08 16:09:28 +0000508#endif