blob: c929fce9e7b0fd2a05649a4cc9b4b15d6d9df1d7 [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
Jim Grosbach3e556122010-10-26 22:37:02 +000053 AddrMode_i12 = 16,
David Goodwin334c2642009-07-08 16:09:28 +000054
55 // Size* - Flags to keep track of the size of an instruction.
Jim Grosbachd86609f2010-10-05 18:14:55 +000056 SizeShift = 5,
David Goodwin334c2642009-07-08 16:09:28 +000057 SizeMask = 7 << SizeShift,
58 SizeSpecial = 1, // 0 byte pseudo or special case.
59 Size8Bytes = 2,
60 Size4Bytes = 3,
61 Size2Bytes = 4,
62
Bob Wilsonbffb5b32010-03-13 07:34:35 +000063 // IndexMode - Unindex, pre-indexed, or post-indexed are valid for load
64 // and store ops only. Generic "updating" flag is used for ld/st multiple.
Jim Grosbachd86609f2010-10-05 18:14:55 +000065 IndexModeShift = 8,
David Goodwin334c2642009-07-08 16:09:28 +000066 IndexModeMask = 3 << IndexModeShift,
67 IndexModePre = 1,
68 IndexModePost = 2,
Bob Wilsonbffb5b32010-03-13 07:34:35 +000069 IndexModeUpd = 3,
David Goodwin334c2642009-07-08 16:09:28 +000070
71 //===------------------------------------------------------------------===//
72 // Instruction encoding formats.
73 //
Jim Grosbachd86609f2010-10-05 18:14:55 +000074 FormShift = 10,
David Goodwin334c2642009-07-08 16:09:28 +000075 FormMask = 0x3f << FormShift,
76
77 // Pseudo instructions
78 Pseudo = 0 << FormShift,
79
80 // Multiply instructions
81 MulFrm = 1 << FormShift,
82
83 // Branch instructions
84 BrFrm = 2 << FormShift,
85 BrMiscFrm = 3 << FormShift,
86
87 // Data Processing instructions
88 DPFrm = 4 << FormShift,
89 DPSoRegFrm = 5 << FormShift,
90
91 // Load and Store
92 LdFrm = 6 << FormShift,
93 StFrm = 7 << FormShift,
94 LdMiscFrm = 8 << FormShift,
95 StMiscFrm = 9 << FormShift,
96 LdStMulFrm = 10 << FormShift,
97
Johnny Chen81f04d52010-03-19 17:39:00 +000098 LdStExFrm = 11 << FormShift,
Jim Grosbach5278eb82009-12-11 01:42:04 +000099
David Goodwin334c2642009-07-08 16:09:28 +0000100 // Miscellaneous arithmetic instructions
Johnny Chen81f04d52010-03-19 17:39:00 +0000101 ArithMiscFrm = 12 << FormShift,
Bob Wilson9a1c1892010-08-11 00:01:18 +0000102 SatFrm = 13 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000103
104 // Extend instructions
Bob Wilson9a1c1892010-08-11 00:01:18 +0000105 ExtFrm = 14 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000106
107 // VFP formats
Bob Wilson9a1c1892010-08-11 00:01:18 +0000108 VFPUnaryFrm = 15 << FormShift,
109 VFPBinaryFrm = 16 << FormShift,
110 VFPConv1Frm = 17 << FormShift,
111 VFPConv2Frm = 18 << FormShift,
112 VFPConv3Frm = 19 << FormShift,
113 VFPConv4Frm = 20 << FormShift,
114 VFPConv5Frm = 21 << FormShift,
115 VFPLdStFrm = 22 << FormShift,
116 VFPLdStMulFrm = 23 << FormShift,
117 VFPMiscFrm = 24 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000118
119 // Thumb format
Bob Wilson9a1c1892010-08-11 00:01:18 +0000120 ThumbFrm = 25 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000121
Bob Wilson26532632010-06-25 23:45:37 +0000122 // Miscelleaneous format
Bob Wilson9a1c1892010-08-11 00:01:18 +0000123 MiscFrm = 26 << FormShift,
Bob Wilson26532632010-06-25 23:45:37 +0000124
Bob Wilson1a913ed2010-06-11 21:34:50 +0000125 // NEON formats
Bob Wilson9a1c1892010-08-11 00:01:18 +0000126 NGetLnFrm = 27 << FormShift,
127 NSetLnFrm = 28 << FormShift,
128 NDupFrm = 29 << FormShift,
129 NLdStFrm = 30 << FormShift,
130 N1RegModImmFrm= 31 << FormShift,
131 N2RegFrm = 32 << FormShift,
132 NVCVTFrm = 33 << FormShift,
133 NVDupLnFrm = 34 << FormShift,
134 N2RegVShLFrm = 35 << FormShift,
135 N2RegVShRFrm = 36 << FormShift,
136 N3RegFrm = 37 << FormShift,
137 N3RegVShFrm = 38 << FormShift,
138 NVExtFrm = 39 << FormShift,
139 NVMulSLFrm = 40 << FormShift,
140 NVTBLFrm = 41 << FormShift,
David Goodwin334c2642009-07-08 16:09:28 +0000141
142 //===------------------------------------------------------------------===//
143 // Misc flags.
144
145 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
146 // it doesn't have a Rn operand.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000147 UnaryDP = 1 << 16,
David Goodwin334c2642009-07-08 16:09:28 +0000148
149 // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
150 // a 16-bit Thumb instruction if certain conditions are met.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000151 Xform16Bit = 1 << 17,
David Goodwin334c2642009-07-08 16:09:28 +0000152
153 //===------------------------------------------------------------------===//
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000154 // Code domain.
Jim Grosbachd86609f2010-10-05 18:14:55 +0000155 DomainShift = 18,
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000156 DomainMask = 3 << DomainShift,
157 DomainGeneral = 0 << DomainShift,
158 DomainVFP = 1 << DomainShift,
159 DomainNEON = 2 << DomainShift,
160
161 //===------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +0000162 // Field shifts - such shifts are used to set field while generating
163 // machine instructions.
Jim Grosbach42fac8e2010-10-11 23:16:21 +0000164 //
165 // FIXME: This list will need adjusting/fixing as the MC code emitter
166 // takes shape and the ARMCodeEmitter.cpp bits go away.
167 ShiftTypeShift = 4,
168
David Goodwin334c2642009-07-08 16:09:28 +0000169 M_BitShift = 5,
170 ShiftImmShift = 5,
171 ShiftShift = 7,
172 N_BitShift = 7,
173 ImmHiShift = 8,
174 SoRotImmShift = 8,
175 RegRsShift = 8,
176 ExtRotImmShift = 10,
177 RegRdLoShift = 12,
178 RegRdShift = 12,
179 RegRdHiShift = 16,
180 RegRnShift = 16,
181 S_BitShift = 20,
182 W_BitShift = 21,
183 AM3_I_BitShift = 22,
184 D_BitShift = 22,
185 U_BitShift = 23,
186 P_BitShift = 24,
187 I_BitShift = 25,
188 CondShift = 28
189 };
Evan Chengb46aaa32009-07-19 19:16:46 +0000190}
191
David Goodwin334c2642009-07-08 16:09:28 +0000192class ARMBaseInstrInfo : public TargetInstrInfoImpl {
Chris Lattner4dbbe342010-07-20 21:17:29 +0000193 const ARMSubtarget &Subtarget;
David Goodwin334c2642009-07-08 16:09:28 +0000194protected:
195 // Can be only subclassed.
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000196 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
David Goodwin334c2642009-07-08 16:09:28 +0000197public:
198 // Return the non-pre/post incrementing version of 'Opc'. Return 0
199 // if there is not such an opcode.
200 virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
201
David Goodwin334c2642009-07-08 16:09:28 +0000202 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
203 MachineBasicBlock::iterator &MBBI,
204 LiveVariables *LV) const;
205
206 virtual const ARMBaseRegisterInfo &getRegisterInfo() const =0;
Anton Korobeynikovf95215f2009-11-02 00:10:38 +0000207 const ARMSubtarget &getSubtarget() const { return Subtarget; }
David Goodwin334c2642009-07-08 16:09:28 +0000208
Evan Cheng2457f2c2010-05-22 01:47:14 +0000209 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
210 MachineBasicBlock::iterator MI,
211 const std::vector<CalleeSavedInfo> &CSI,
212 const TargetRegisterInfo *TRI) const;
213
David Goodwin334c2642009-07-08 16:09:28 +0000214 // Branch analysis.
215 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
216 MachineBasicBlock *&FBB,
217 SmallVectorImpl<MachineOperand> &Cond,
Chris Lattner20628752010-07-22 21:27:00 +0000218 bool AllowModify = false) const;
David Goodwin334c2642009-07-08 16:09:28 +0000219 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
220 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
221 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000222 const SmallVectorImpl<MachineOperand> &Cond,
223 DebugLoc DL) const;
David Goodwin334c2642009-07-08 16:09:28 +0000224
225 virtual
226 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
227
228 // Predication support.
Evan Chengab331502009-07-10 01:38:27 +0000229 bool isPredicated(const MachineInstr *MI) const {
230 int PIdx = MI->findFirstPredOperandIdx();
231 return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL;
232 }
David Goodwin334c2642009-07-08 16:09:28 +0000233
234 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
235 int PIdx = MI->findFirstPredOperandIdx();
236 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
237 : ARMCC::AL;
238 }
239
240 virtual
241 bool PredicateInstruction(MachineInstr *MI,
242 const SmallVectorImpl<MachineOperand> &Pred) const;
243
244 virtual
245 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
246 const SmallVectorImpl<MachineOperand> &Pred2) const;
247
248 virtual bool DefinesPredicate(MachineInstr *MI,
249 std::vector<MachineOperand> &Pred) const;
250
Evan Chengac0869d2009-11-21 06:21:52 +0000251 virtual bool isPredicable(MachineInstr *MI) const;
252
David Goodwin334c2642009-07-08 16:09:28 +0000253 /// GetInstSize - Returns the size of the specified MachineInstr.
254 ///
255 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
256
David Goodwin334c2642009-07-08 16:09:28 +0000257 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
258 int &FrameIndex) const;
259 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
260 int &FrameIndex) const;
261
Jakob Stoklund Olesenac273662010-07-11 06:33:54 +0000262 virtual void copyPhysReg(MachineBasicBlock &MBB,
263 MachineBasicBlock::iterator I, DebugLoc DL,
264 unsigned DestReg, unsigned SrcReg,
265 bool KillSrc) const;
Evan Cheng5732ca02009-07-27 03:14:20 +0000266
David Goodwin334c2642009-07-08 16:09:28 +0000267 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
268 MachineBasicBlock::iterator MBBI,
269 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000270 const TargetRegisterClass *RC,
271 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000272
David Goodwin334c2642009-07-08 16:09:28 +0000273 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
274 MachineBasicBlock::iterator MBBI,
275 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000276 const TargetRegisterClass *RC,
277 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000278
Evan Cheng62b50652010-04-26 07:39:25 +0000279 virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
Evan Cheng8601a3d2010-04-29 01:13:30 +0000280 int FrameIx,
Evan Cheng62b50652010-04-26 07:39:25 +0000281 uint64_t Offset,
282 const MDNode *MDPtr,
283 DebugLoc DL) const;
284
Evan Chengfdc83402009-11-08 00:15:23 +0000285 virtual void reMaterialize(MachineBasicBlock &MBB,
286 MachineBasicBlock::iterator MI,
287 unsigned DestReg, unsigned SubIdx,
Evan Chengd57cdd52009-11-14 02:55:43 +0000288 const MachineInstr *Orig,
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +0000289 const TargetRegisterInfo &TRI) const;
Evan Chengfdc83402009-11-08 00:15:23 +0000290
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +0000291 MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const;
292
Evan Cheng506049f2010-03-03 01:44:33 +0000293 virtual bool produceSameValue(const MachineInstr *MI0,
294 const MachineInstr *MI1) const;
Evan Cheng86050dc2010-06-18 23:09:54 +0000295
Bill Wendling4b722102010-06-23 23:00:16 +0000296 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
297 /// determine if two loads are loading from the same base address. It should
298 /// only return true if the base pointers are the same and the only
299 /// differences between the two addresses is the offset. It also returns the
300 /// offsets by reference.
301 virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
302 int64_t &Offset1, int64_t &Offset2)const;
303
304 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
305 /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should
306 /// be scheduled togther. On some targets if two loads are loading from
307 /// addresses in the same cache line, it's better if they are scheduled
308 /// together. This function takes two integers that represent the load offsets
309 /// from the common base address. It returns true if it decides it's desirable
310 /// to schedule the two loads together. "NumLoads" is the number of loads that
311 /// have already been scheduled after Load1.
312 virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
313 int64_t Offset1, int64_t Offset2,
314 unsigned NumLoads) const;
315
Evan Cheng86050dc2010-06-18 23:09:54 +0000316 virtual bool isSchedulingBoundary(const MachineInstr *MI,
317 const MachineBasicBlock *MBB,
318 const MachineFunction &MF) const;
Evan Cheng13151432010-06-25 22:42:03 +0000319
320 virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB,
Evan Cheng8239daf2010-11-03 00:45:17 +0000321 unsigned NumCyles, unsigned ExtraPredCycles,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000322 float Prob, float Confidence) const;
Evan Cheng13151432010-06-25 22:42:03 +0000323
Evan Cheng8239daf2010-11-03 00:45:17 +0000324 virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
325 unsigned NumT, unsigned ExtraT,
326 MachineBasicBlock &FMBB,
327 unsigned NumF, unsigned ExtraF,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000328 float Probability, float Confidence) const;
Evan Cheng13151432010-06-25 22:42:03 +0000329
330 virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
Evan Cheng8239daf2010-11-03 00:45:17 +0000331 unsigned NumCyles,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000332 float Probability,
333 float Confidence) const {
Evan Cheng8239daf2010-11-03 00:45:17 +0000334 return NumCyles == 1;
Evan Cheng13151432010-06-25 22:42:03 +0000335 }
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000336
Bill Wendlingc98af332010-08-08 05:04:59 +0000337 /// AnalyzeCompare - For a comparison instruction, return the source register
338 /// in SrcReg and the value it compares against in CmpValue. Return true if
339 /// the comparison instruction can be analyzed.
340 virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000341 int &CmpMask, int &CmpValue) const;
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000342
Bill Wendlinga6556862010-09-11 00:13:50 +0000343 /// OptimizeCompareInstr - Convert the instruction to set the zero flag so
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000344 /// that we can remove a "comparison with zero".
Bill Wendlinga6556862010-09-11 00:13:50 +0000345 virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000346 int CmpMask, int CmpValue,
Evan Chengeb96a2f2010-11-15 21:20:45 +0000347 const MachineRegisterInfo *MRI) const;
Evan Cheng5f54ce32010-09-09 18:18:55 +0000348
Evan Cheng8239daf2010-11-03 00:45:17 +0000349 virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
350 const MachineInstr *MI) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000351
352 virtual
353 int getOperandLatency(const InstrItineraryData *ItinData,
354 const MachineInstr *DefMI, unsigned DefIdx,
355 const MachineInstr *UseMI, unsigned UseIdx) const;
356 virtual
357 int getOperandLatency(const InstrItineraryData *ItinData,
358 SDNode *DefNode, unsigned DefIdx,
359 SDNode *UseNode, unsigned UseIdx) const;
360private:
Evan Cheng344d9db2010-10-07 23:12:15 +0000361 int getVLDMDefCycle(const InstrItineraryData *ItinData,
362 const TargetInstrDesc &DefTID,
363 unsigned DefClass,
364 unsigned DefIdx, unsigned DefAlign) const;
365 int getLDMDefCycle(const InstrItineraryData *ItinData,
366 const TargetInstrDesc &DefTID,
367 unsigned DefClass,
368 unsigned DefIdx, unsigned DefAlign) const;
369 int getVSTMUseCycle(const InstrItineraryData *ItinData,
370 const TargetInstrDesc &UseTID,
371 unsigned UseClass,
372 unsigned UseIdx, unsigned UseAlign) const;
373 int getSTMUseCycle(const InstrItineraryData *ItinData,
374 const TargetInstrDesc &UseTID,
375 unsigned UseClass,
376 unsigned UseIdx, unsigned UseAlign) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000377 int getOperandLatency(const InstrItineraryData *ItinData,
378 const TargetInstrDesc &DefTID,
379 unsigned DefIdx, unsigned DefAlign,
380 const TargetInstrDesc &UseTID,
381 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng23128422010-10-19 18:58:51 +0000382
Evan Cheng8239daf2010-11-03 00:45:17 +0000383 int getInstrLatency(const InstrItineraryData *ItinData,
384 const MachineInstr *MI, unsigned *PredCost = 0) const;
385
386 int getInstrLatency(const InstrItineraryData *ItinData,
387 SDNode *Node) const;
388
Evan Cheng23128422010-10-19 18:58:51 +0000389 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
390 const MachineRegisterInfo *MRI,
391 const MachineInstr *DefMI, unsigned DefIdx,
392 const MachineInstr *UseMI, unsigned UseIdx) const;
Evan Chengc8141df2010-10-26 02:08:50 +0000393 bool hasLowDefLatency(const InstrItineraryData *ItinData,
394 const MachineInstr *DefMI, unsigned DefIdx) const;
David Goodwin334c2642009-07-08 16:09:28 +0000395};
Evan Cheng6495f632009-07-28 05:48:47 +0000396
397static inline
398const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
399 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwin334c2642009-07-08 16:09:28 +0000400}
401
Evan Cheng6495f632009-07-28 05:48:47 +0000402static inline
403const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
404 return MIB.addReg(0);
405}
406
407static inline
Evan Chenge8af1f92009-08-10 02:37:24 +0000408const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
409 bool isDead = false) {
410 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng6495f632009-07-28 05:48:47 +0000411}
412
413static inline
Evan Chengbc9b7542009-08-15 07:59:10 +0000414const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
415 return MIB.addReg(0);
416}
417
418static inline
Evan Cheng6495f632009-07-28 05:48:47 +0000419bool isUncondBranchOpcode(int Opc) {
420 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
421}
422
423static inline
424bool isCondBranchOpcode(int Opc) {
425 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
426}
427
428static inline
429bool isJumpTableBranchOpcode(int Opc) {
430 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
431 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
432}
433
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000434static inline
435bool isIndirectBranchOpcode(int Opc) {
Anton Korobeynikovce7bf1c2010-03-06 19:39:36 +0000436 return Opc == ARM::BRIND || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000437}
438
Evan Cheng8fb90362009-08-08 03:20:32 +0000439/// getInstrPredicate - If instruction is predicated, returns its predicate
440/// condition, otherwise returns AL. It also returns the condition code
441/// register by reference.
Evan Cheng5adb66a2009-09-28 09:14:39 +0000442ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
Evan Cheng8fb90362009-08-08 03:20:32 +0000443
Evan Cheng6495f632009-07-28 05:48:47 +0000444int getMatchingCondBranchOpcode(int Opc);
445
446/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
447/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
448/// code.
449void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
450 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
451 unsigned DestReg, unsigned BaseReg, int NumBytes,
452 ARMCC::CondCodes Pred, unsigned PredReg,
453 const ARMBaseInstrInfo &TII);
454
455void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
456 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
457 unsigned DestReg, unsigned BaseReg, int NumBytes,
458 ARMCC::CondCodes Pred, unsigned PredReg,
459 const ARMBaseInstrInfo &TII);
Jim Grosbache4ad3872010-10-19 23:27:08 +0000460void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
461 MachineBasicBlock::iterator &MBBI,
462 unsigned DestReg, unsigned BaseReg,
463 int NumBytes, const TargetInstrInfo &TII,
464 const ARMBaseRegisterInfo& MRI,
465 DebugLoc dl);
Evan Cheng6495f632009-07-28 05:48:47 +0000466
467
Jim Grosbach764ab522009-08-11 15:33:49 +0000468/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Chengcdbb3f52009-08-27 01:23:50 +0000469/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
470/// offset could not be handled directly in MI, and return the left-over
471/// portion by reference.
472bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
473 unsigned FrameReg, int &Offset,
474 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000475
Evan Chengcdbb3f52009-08-27 01:23:50 +0000476bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
477 unsigned FrameReg, int &Offset,
478 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000479
480} // End llvm namespace
481
David Goodwin334c2642009-07-08 16:09:28 +0000482#endif