blob: f607f267c68deba2c55a2850f662d58656ea75ef [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"
David Goodwin334c2642009-07-08 16:09:28 +000020
21namespace llvm {
Chris Lattner4dbbe342010-07-20 21:17:29 +000022 class ARMSubtarget;
23 class ARMBaseRegisterInfo;
David Goodwin334c2642009-07-08 16:09:28 +000024
25/// ARMII - This namespace holds all of the target specific flags that
26/// instruction info tracks.
27///
28namespace ARMII {
29 enum {
30 //===------------------------------------------------------------------===//
31 // Instruction Flags.
32
33 //===------------------------------------------------------------------===//
34 // This four-bit field describes the addressing mode used.
35
Jim Grosbachd86609f2010-10-05 18:14:55 +000036 AddrModeMask = 0x1f,
David Goodwin334c2642009-07-08 16:09:28 +000037 AddrModeNone = 0,
38 AddrMode1 = 1,
39 AddrMode2 = 2,
40 AddrMode3 = 3,
41 AddrMode4 = 4,
42 AddrMode5 = 5,
43 AddrMode6 = 6,
44 AddrModeT1_1 = 7,
45 AddrModeT1_2 = 8,
46 AddrModeT1_4 = 9,
47 AddrModeT1_s = 10, // i8 * 4 for pc and sp relative data
48 AddrModeT2_i12 = 11,
49 AddrModeT2_i8 = 12,
50 AddrModeT2_so = 13,
51 AddrModeT2_pc = 14, // +/- i12 for pc relative data
52 AddrModeT2_i8s4 = 15, // i8 * 4
53
54 // Size* - Flags to keep track of the size of an instruction.
Jim Grosbachd86609f2010-10-05 18:14:55 +000055 SizeShift = 5,
David Goodwin334c2642009-07-08 16:09:28 +000056 SizeMask = 7 << SizeShift,
57 SizeSpecial = 1, // 0 byte pseudo or special case.
58 Size8Bytes = 2,
59 Size4Bytes = 3,
60 Size2Bytes = 4,
61
Bob Wilsonbffb5b32010-03-13 07:34:35 +000062 // IndexMode - Unindex, pre-indexed, or post-indexed are valid for load
63 // and store ops only. Generic "updating" flag is used for ld/st multiple.
Jim Grosbachd86609f2010-10-05 18:14:55 +000064 IndexModeShift = 8,
David Goodwin334c2642009-07-08 16:09:28 +000065 IndexModeMask = 3 << IndexModeShift,
66 IndexModePre = 1,
67 IndexModePost = 2,
Bob Wilsonbffb5b32010-03-13 07:34:35 +000068 IndexModeUpd = 3,
David Goodwin334c2642009-07-08 16:09:28 +000069
70 //===------------------------------------------------------------------===//
71 // Instruction encoding formats.
72 //
Jim Grosbachd86609f2010-10-05 18:14:55 +000073 FormShift = 10,
David Goodwin334c2642009-07-08 16:09:28 +000074 FormMask = 0x3f << FormShift,
75
76 // Pseudo instructions
77 Pseudo = 0 << FormShift,
78
79 // Multiply instructions
80 MulFrm = 1 << FormShift,
81
82 // Branch instructions
83 BrFrm = 2 << FormShift,
84 BrMiscFrm = 3 << FormShift,
85
86 // Data Processing instructions
87 DPFrm = 4 << FormShift,
88 DPSoRegFrm = 5 << FormShift,
89
90 // Load and Store
91 LdFrm = 6 << FormShift,
92 StFrm = 7 << FormShift,
93 LdMiscFrm = 8 << FormShift,
94 StMiscFrm = 9 << FormShift,
95 LdStMulFrm = 10 << FormShift,
96
Johnny Chen81f04d52010-03-19 17:39:00 +000097 LdStExFrm = 11 << FormShift,
Jim Grosbach5278eb82009-12-11 01:42:04 +000098
David Goodwin334c2642009-07-08 16:09:28 +000099 // Miscellaneous arithmetic instructions
Johnny Chen81f04d52010-03-19 17:39:00 +0000100 ArithMiscFrm = 12 << FormShift,
Bob Wilson9a1c1892010-08-11 00:01:18 +0000101 SatFrm = 13 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000102
103 // Extend instructions
Bob Wilson9a1c1892010-08-11 00:01:18 +0000104 ExtFrm = 14 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000105
106 // VFP formats
Bob Wilson9a1c1892010-08-11 00:01:18 +0000107 VFPUnaryFrm = 15 << FormShift,
108 VFPBinaryFrm = 16 << FormShift,
109 VFPConv1Frm = 17 << FormShift,
110 VFPConv2Frm = 18 << FormShift,
111 VFPConv3Frm = 19 << FormShift,
112 VFPConv4Frm = 20 << FormShift,
113 VFPConv5Frm = 21 << FormShift,
114 VFPLdStFrm = 22 << FormShift,
115 VFPLdStMulFrm = 23 << FormShift,
116 VFPMiscFrm = 24 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000117
118 // Thumb format
Bob Wilson9a1c1892010-08-11 00:01:18 +0000119 ThumbFrm = 25 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000120
Bob Wilson26532632010-06-25 23:45:37 +0000121 // Miscelleaneous format
Bob Wilson9a1c1892010-08-11 00:01:18 +0000122 MiscFrm = 26 << FormShift,
Bob Wilson26532632010-06-25 23:45:37 +0000123
Bob Wilson1a913ed2010-06-11 21:34:50 +0000124 // NEON formats
Bob Wilson9a1c1892010-08-11 00:01:18 +0000125 NGetLnFrm = 27 << FormShift,
126 NSetLnFrm = 28 << FormShift,
127 NDupFrm = 29 << FormShift,
128 NLdStFrm = 30 << FormShift,
129 N1RegModImmFrm= 31 << FormShift,
130 N2RegFrm = 32 << FormShift,
131 NVCVTFrm = 33 << FormShift,
132 NVDupLnFrm = 34 << FormShift,
133 N2RegVShLFrm = 35 << FormShift,
134 N2RegVShRFrm = 36 << FormShift,
135 N3RegFrm = 37 << FormShift,
136 N3RegVShFrm = 38 << FormShift,
137 NVExtFrm = 39 << FormShift,
138 NVMulSLFrm = 40 << FormShift,
139 NVTBLFrm = 41 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000140
141 //===------------------------------------------------------------------===//
142 // Misc flags.
143
144 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
145 // it doesn't have a Rn operand.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000146 UnaryDP = 1 << 16,
David Goodwin334c2642009-07-08 16:09:28 +0000147
148 // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
149 // a 16-bit Thumb instruction if certain conditions are met.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000150 Xform16Bit = 1 << 17,
David Goodwin334c2642009-07-08 16:09:28 +0000151
152 //===------------------------------------------------------------------===//
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000153 // Code domain.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000154 DomainShift = 18,
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000155 DomainMask = 3 << DomainShift,
156 DomainGeneral = 0 << DomainShift,
157 DomainVFP = 1 << DomainShift,
158 DomainNEON = 2 << DomainShift,
159
160 //===------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +0000161 // Field shifts - such shifts are used to set field while generating
162 // machine instructions.
Jim Grosbach42fac8e2010-10-11 23:16:21 +0000163 //
164 // FIXME: This list will need adjusting/fixing as the MC code emitter
165 // takes shape and the ARMCodeEmitter.cpp bits go away.
166 ShiftTypeShift = 4,
167
David Goodwin334c2642009-07-08 16:09:28 +0000168 M_BitShift = 5,
169 ShiftImmShift = 5,
170 ShiftShift = 7,
171 N_BitShift = 7,
172 ImmHiShift = 8,
173 SoRotImmShift = 8,
174 RegRsShift = 8,
175 ExtRotImmShift = 10,
176 RegRdLoShift = 12,
177 RegRdShift = 12,
178 RegRdHiShift = 16,
179 RegRnShift = 16,
180 S_BitShift = 20,
181 W_BitShift = 21,
182 AM3_I_BitShift = 22,
183 D_BitShift = 22,
184 U_BitShift = 23,
185 P_BitShift = 24,
186 I_BitShift = 25,
187 CondShift = 28
188 };
Evan Chengb46aaa32009-07-19 19:16:46 +0000189}
190
David Goodwin334c2642009-07-08 16:09:28 +0000191class ARMBaseInstrInfo : public TargetInstrInfoImpl {
Chris Lattner4dbbe342010-07-20 21:17:29 +0000192 const ARMSubtarget &Subtarget;
David Goodwin334c2642009-07-08 16:09:28 +0000193protected:
194 // Can be only subclassed.
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000195 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
David Goodwin334c2642009-07-08 16:09:28 +0000196public:
197 // Return the non-pre/post incrementing version of 'Opc'. Return 0
198 // if there is not such an opcode.
199 virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
200
David Goodwin334c2642009-07-08 16:09:28 +0000201 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
202 MachineBasicBlock::iterator &MBBI,
203 LiveVariables *LV) const;
204
205 virtual const ARMBaseRegisterInfo &getRegisterInfo() const =0;
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000206 const ARMSubtarget &getSubtarget() const { return Subtarget; }
David Goodwin334c2642009-07-08 16:09:28 +0000207
Evan Cheng2457f2c2010-05-22 01:47:14 +0000208 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
209 MachineBasicBlock::iterator MI,
210 const std::vector<CalleeSavedInfo> &CSI,
211 const TargetRegisterInfo *TRI) const;
212
David Goodwin334c2642009-07-08 16:09:28 +0000213 // Branch analysis.
214 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
215 MachineBasicBlock *&FBB,
216 SmallVectorImpl<MachineOperand> &Cond,
Chris Lattner20628752010-07-22 21:27:00 +0000217 bool AllowModify = false) const;
David Goodwin334c2642009-07-08 16:09:28 +0000218 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
219 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
220 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000221 const SmallVectorImpl<MachineOperand> &Cond,
222 DebugLoc DL) const;
David Goodwin334c2642009-07-08 16:09:28 +0000223
224 virtual
225 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
226
227 // Predication support.
Evan Chengab331502009-07-10 01:38:27 +0000228 bool isPredicated(const MachineInstr *MI) const {
229 int PIdx = MI->findFirstPredOperandIdx();
230 return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL;
231 }
David Goodwin334c2642009-07-08 16:09:28 +0000232
233 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
234 int PIdx = MI->findFirstPredOperandIdx();
235 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
236 : ARMCC::AL;
237 }
238
239 virtual
240 bool PredicateInstruction(MachineInstr *MI,
241 const SmallVectorImpl<MachineOperand> &Pred) const;
242
243 virtual
244 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
245 const SmallVectorImpl<MachineOperand> &Pred2) const;
246
247 virtual bool DefinesPredicate(MachineInstr *MI,
248 std::vector<MachineOperand> &Pred) const;
249
Evan Chengac0869d2009-11-21 06:21:52 +0000250 virtual bool isPredicable(MachineInstr *MI) const;
251
David Goodwin334c2642009-07-08 16:09:28 +0000252 /// GetInstSize - Returns the size of the specified MachineInstr.
253 ///
254 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
255
David Goodwin334c2642009-07-08 16:09:28 +0000256 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
257 int &FrameIndex) const;
258 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
259 int &FrameIndex) const;
260
Jakob Stoklund Olesenac273662010-07-11 06:33:54 +0000261 virtual void copyPhysReg(MachineBasicBlock &MBB,
262 MachineBasicBlock::iterator I, DebugLoc DL,
263 unsigned DestReg, unsigned SrcReg,
264 bool KillSrc) const;
Evan Cheng5732ca02009-07-27 03:14:20 +0000265
David Goodwin334c2642009-07-08 16:09:28 +0000266 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
267 MachineBasicBlock::iterator MBBI,
268 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000269 const TargetRegisterClass *RC,
270 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000271
David Goodwin334c2642009-07-08 16:09:28 +0000272 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
273 MachineBasicBlock::iterator MBBI,
274 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000275 const TargetRegisterClass *RC,
276 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000277
Evan Cheng62b50652010-04-26 07:39:25 +0000278 virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
Evan Cheng8601a3d2010-04-29 01:13:30 +0000279 int FrameIx,
Evan Cheng62b50652010-04-26 07:39:25 +0000280 uint64_t Offset,
281 const MDNode *MDPtr,
282 DebugLoc DL) const;
283
Evan Chengfdc83402009-11-08 00:15:23 +0000284 virtual void reMaterialize(MachineBasicBlock &MBB,
285 MachineBasicBlock::iterator MI,
286 unsigned DestReg, unsigned SubIdx,
Evan Chengd57cdd52009-11-14 02:55:43 +0000287 const MachineInstr *Orig,
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +0000288 const TargetRegisterInfo &TRI) const;
Evan Chengfdc83402009-11-08 00:15:23 +0000289
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +0000290 MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const;
291
Evan Cheng506049f2010-03-03 01:44:33 +0000292 virtual bool produceSameValue(const MachineInstr *MI0,
293 const MachineInstr *MI1) const;
Evan Cheng86050dc2010-06-18 23:09:54 +0000294
Bill Wendling4b722102010-06-23 23:00:16 +0000295 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
296 /// determine if two loads are loading from the same base address. It should
297 /// only return true if the base pointers are the same and the only
298 /// differences between the two addresses is the offset. It also returns the
299 /// offsets by reference.
300 virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
301 int64_t &Offset1, int64_t &Offset2)const;
302
303 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
304 /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should
305 /// be scheduled togther. On some targets if two loads are loading from
306 /// addresses in the same cache line, it's better if they are scheduled
307 /// together. This function takes two integers that represent the load offsets
308 /// from the common base address. It returns true if it decides it's desirable
309 /// to schedule the two loads together. "NumLoads" is the number of loads that
310 /// have already been scheduled after Load1.
311 virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
312 int64_t Offset1, int64_t Offset2,
313 unsigned NumLoads) const;
314
Evan Cheng86050dc2010-06-18 23:09:54 +0000315 virtual bool isSchedulingBoundary(const MachineInstr *MI,
316 const MachineBasicBlock *MBB,
317 const MachineFunction &MF) const;
Evan Cheng13151432010-06-25 22:42:03 +0000318
319 virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000320 unsigned NumInstrs,
321 float Prob, float Confidence) const;
Evan Cheng13151432010-06-25 22:42:03 +0000322
323 virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB,unsigned NumT,
Owen Andersonb20b8512010-09-28 18:32:13 +0000324 MachineBasicBlock &FMBB,unsigned NumF,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000325 float Probability, float Confidence) const;
Evan Cheng13151432010-06-25 22:42:03 +0000326
327 virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
Owen Andersonb20b8512010-09-28 18:32:13 +0000328 unsigned NumInstrs,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000329 float Probability,
330 float Confidence) const {
Bob Wilsonb3a68172010-10-26 00:02:19 +0000331 return NumInstrs == 1;
Evan Cheng13151432010-06-25 22:42:03 +0000332 }
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000333
Bill Wendlingc98af332010-08-08 05:04:59 +0000334 /// AnalyzeCompare - For a comparison instruction, return the source register
335 /// in SrcReg and the value it compares against in CmpValue. Return true if
336 /// the comparison instruction can be analyzed.
337 virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000338 int &CmpMask, int &CmpValue) const;
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000339
Bill Wendlinga6556862010-09-11 00:13:50 +0000340 /// OptimizeCompareInstr - Convert the instruction to set the zero flag so
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000341 /// that we can remove a "comparison with zero".
Bill Wendlinga6556862010-09-11 00:13:50 +0000342 virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000343 int CmpMask, int CmpValue,
Bill Wendlingb41ee962010-10-18 21:22:31 +0000344 const MachineRegisterInfo *MRI,
Bill Wendling220e2402010-09-10 21:55:43 +0000345 MachineBasicBlock::iterator &MII) const;
Evan Cheng5f54ce32010-09-09 18:18:55 +0000346
347 virtual unsigned getNumMicroOps(const MachineInstr *MI,
Evan Cheng3ef1c872010-09-10 01:29:16 +0000348 const InstrItineraryData *ItinData) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000349
350 virtual
351 int getOperandLatency(const InstrItineraryData *ItinData,
352 const MachineInstr *DefMI, unsigned DefIdx,
353 const MachineInstr *UseMI, unsigned UseIdx) const;
354 virtual
355 int getOperandLatency(const InstrItineraryData *ItinData,
356 SDNode *DefNode, unsigned DefIdx,
357 SDNode *UseNode, unsigned UseIdx) const;
358private:
Evan Cheng344d9db2010-10-07 23:12:15 +0000359 int getVLDMDefCycle(const InstrItineraryData *ItinData,
360 const TargetInstrDesc &DefTID,
361 unsigned DefClass,
362 unsigned DefIdx, unsigned DefAlign) const;
363 int getLDMDefCycle(const InstrItineraryData *ItinData,
364 const TargetInstrDesc &DefTID,
365 unsigned DefClass,
366 unsigned DefIdx, unsigned DefAlign) const;
367 int getVSTMUseCycle(const InstrItineraryData *ItinData,
368 const TargetInstrDesc &UseTID,
369 unsigned UseClass,
370 unsigned UseIdx, unsigned UseAlign) const;
371 int getSTMUseCycle(const InstrItineraryData *ItinData,
372 const TargetInstrDesc &UseTID,
373 unsigned UseClass,
374 unsigned UseIdx, unsigned UseAlign) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000375 int getOperandLatency(const InstrItineraryData *ItinData,
376 const TargetInstrDesc &DefTID,
377 unsigned DefIdx, unsigned DefAlign,
378 const TargetInstrDesc &UseTID,
379 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng23128422010-10-19 18:58:51 +0000380
381 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
382 const MachineRegisterInfo *MRI,
383 const MachineInstr *DefMI, unsigned DefIdx,
384 const MachineInstr *UseMI, unsigned UseIdx) const;
Evan Chengc8141df2010-10-26 02:08:50 +0000385 bool hasLowDefLatency(const InstrItineraryData *ItinData,
386 const MachineInstr *DefMI, unsigned DefIdx) const;
David Goodwin334c2642009-07-08 16:09:28 +0000387};
Evan Cheng6495f632009-07-28 05:48:47 +0000388
389static inline
390const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
391 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwin334c2642009-07-08 16:09:28 +0000392}
393
Evan Cheng6495f632009-07-28 05:48:47 +0000394static inline
395const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
396 return MIB.addReg(0);
397}
398
399static inline
Evan Chenge8af1f92009-08-10 02:37:24 +0000400const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
401 bool isDead = false) {
402 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng6495f632009-07-28 05:48:47 +0000403}
404
405static inline
Evan Chengbc9b7542009-08-15 07:59:10 +0000406const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
407 return MIB.addReg(0);
408}
409
410static inline
Evan Cheng6495f632009-07-28 05:48:47 +0000411bool isUncondBranchOpcode(int Opc) {
412 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
413}
414
415static inline
416bool isCondBranchOpcode(int Opc) {
417 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
418}
419
420static inline
421bool isJumpTableBranchOpcode(int Opc) {
422 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
423 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
424}
425
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000426static inline
427bool isIndirectBranchOpcode(int Opc) {
Anton Korobeynikovce7bf1c2010-03-06 19:39:36 +0000428 return Opc == ARM::BRIND || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000429}
430
Evan Cheng8fb90362009-08-08 03:20:32 +0000431/// getInstrPredicate - If instruction is predicated, returns its predicate
432/// condition, otherwise returns AL. It also returns the condition code
433/// register by reference.
Evan Cheng5adb66a2009-09-28 09:14:39 +0000434ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
Evan Cheng8fb90362009-08-08 03:20:32 +0000435
Evan Cheng6495f632009-07-28 05:48:47 +0000436int getMatchingCondBranchOpcode(int Opc);
437
438/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
439/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
440/// code.
441void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
442 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
443 unsigned DestReg, unsigned BaseReg, int NumBytes,
444 ARMCC::CondCodes Pred, unsigned PredReg,
445 const ARMBaseInstrInfo &TII);
446
447void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
448 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
449 unsigned DestReg, unsigned BaseReg, int NumBytes,
450 ARMCC::CondCodes Pred, unsigned PredReg,
451 const ARMBaseInstrInfo &TII);
Jim Grosbache4ad3872010-10-19 23:27:08 +0000452void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
453 MachineBasicBlock::iterator &MBBI,
454 unsigned DestReg, unsigned BaseReg,
455 int NumBytes, const TargetInstrInfo &TII,
456 const ARMBaseRegisterInfo& MRI,
457 DebugLoc dl);
Evan Cheng6495f632009-07-28 05:48:47 +0000458
459
Jim Grosbach764ab522009-08-11 15:33:49 +0000460/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Chengcdbb3f52009-08-27 01:23:50 +0000461/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
462/// offset could not be handled directly in MI, and return the left-over
463/// portion by reference.
464bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
465 unsigned FrameReg, int &Offset,
466 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000467
Evan Chengcdbb3f52009-08-27 01:23:50 +0000468bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
469 unsigned FrameReg, int &Offset,
470 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000471
472} // End llvm namespace
473
David Goodwin334c2642009-07-08 16:09:28 +0000474#endif