blob: c11f02ccb109aa23def260c391900f1df5d73ae7 [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,
Bill Wendlingb41ee962010-10-18 21:22:31 +0000347 const MachineRegisterInfo *MRI,
Bill Wendling220e2402010-09-10 21:55:43 +0000348 MachineBasicBlock::iterator &MII) const;
Evan Cheng5f54ce32010-09-09 18:18:55 +0000349
Evan Cheng8239daf2010-11-03 00:45:17 +0000350 virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
351 const MachineInstr *MI) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000352
353 virtual
354 int getOperandLatency(const InstrItineraryData *ItinData,
355 const MachineInstr *DefMI, unsigned DefIdx,
356 const MachineInstr *UseMI, unsigned UseIdx) const;
357 virtual
358 int getOperandLatency(const InstrItineraryData *ItinData,
359 SDNode *DefNode, unsigned DefIdx,
360 SDNode *UseNode, unsigned UseIdx) const;
361private:
Evan Cheng344d9db2010-10-07 23:12:15 +0000362 int getVLDMDefCycle(const InstrItineraryData *ItinData,
363 const TargetInstrDesc &DefTID,
364 unsigned DefClass,
365 unsigned DefIdx, unsigned DefAlign) const;
366 int getLDMDefCycle(const InstrItineraryData *ItinData,
367 const TargetInstrDesc &DefTID,
368 unsigned DefClass,
369 unsigned DefIdx, unsigned DefAlign) const;
370 int getVSTMUseCycle(const InstrItineraryData *ItinData,
371 const TargetInstrDesc &UseTID,
372 unsigned UseClass,
373 unsigned UseIdx, unsigned UseAlign) const;
374 int getSTMUseCycle(const InstrItineraryData *ItinData,
375 const TargetInstrDesc &UseTID,
376 unsigned UseClass,
377 unsigned UseIdx, unsigned UseAlign) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000378 int getOperandLatency(const InstrItineraryData *ItinData,
379 const TargetInstrDesc &DefTID,
380 unsigned DefIdx, unsigned DefAlign,
381 const TargetInstrDesc &UseTID,
382 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng23128422010-10-19 18:58:51 +0000383
Evan Cheng8239daf2010-11-03 00:45:17 +0000384 int getInstrLatency(const InstrItineraryData *ItinData,
385 const MachineInstr *MI, unsigned *PredCost = 0) const;
386
387 int getInstrLatency(const InstrItineraryData *ItinData,
388 SDNode *Node) const;
389
Evan Cheng23128422010-10-19 18:58:51 +0000390 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
391 const MachineRegisterInfo *MRI,
392 const MachineInstr *DefMI, unsigned DefIdx,
393 const MachineInstr *UseMI, unsigned UseIdx) const;
Evan Chengc8141df2010-10-26 02:08:50 +0000394 bool hasLowDefLatency(const InstrItineraryData *ItinData,
395 const MachineInstr *DefMI, unsigned DefIdx) const;
David Goodwin334c2642009-07-08 16:09:28 +0000396};
Evan Cheng6495f632009-07-28 05:48:47 +0000397
398static inline
399const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
400 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwin334c2642009-07-08 16:09:28 +0000401}
402
Evan Cheng6495f632009-07-28 05:48:47 +0000403static inline
404const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
405 return MIB.addReg(0);
406}
407
408static inline
Evan Chenge8af1f92009-08-10 02:37:24 +0000409const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
410 bool isDead = false) {
411 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng6495f632009-07-28 05:48:47 +0000412}
413
414static inline
Evan Chengbc9b7542009-08-15 07:59:10 +0000415const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
416 return MIB.addReg(0);
417}
418
419static inline
Evan Cheng6495f632009-07-28 05:48:47 +0000420bool isUncondBranchOpcode(int Opc) {
421 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
422}
423
424static inline
425bool isCondBranchOpcode(int Opc) {
426 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
427}
428
429static inline
430bool isJumpTableBranchOpcode(int Opc) {
431 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
432 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
433}
434
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000435static inline
436bool isIndirectBranchOpcode(int Opc) {
Anton Korobeynikovce7bf1c2010-03-06 19:39:36 +0000437 return Opc == ARM::BRIND || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000438}
439
Evan Cheng8fb90362009-08-08 03:20:32 +0000440/// getInstrPredicate - If instruction is predicated, returns its predicate
441/// condition, otherwise returns AL. It also returns the condition code
442/// register by reference.
Evan Cheng5adb66a2009-09-28 09:14:39 +0000443ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
Evan Cheng8fb90362009-08-08 03:20:32 +0000444
Evan Cheng6495f632009-07-28 05:48:47 +0000445int getMatchingCondBranchOpcode(int Opc);
446
447/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
448/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
449/// code.
450void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
451 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
452 unsigned DestReg, unsigned BaseReg, int NumBytes,
453 ARMCC::CondCodes Pred, unsigned PredReg,
454 const ARMBaseInstrInfo &TII);
455
456void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
457 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
458 unsigned DestReg, unsigned BaseReg, int NumBytes,
459 ARMCC::CondCodes Pred, unsigned PredReg,
460 const ARMBaseInstrInfo &TII);
Jim Grosbache4ad3872010-10-19 23:27:08 +0000461void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
462 MachineBasicBlock::iterator &MBBI,
463 unsigned DestReg, unsigned BaseReg,
464 int NumBytes, const TargetInstrInfo &TII,
465 const ARMBaseRegisterInfo& MRI,
466 DebugLoc dl);
Evan Cheng6495f632009-07-28 05:48:47 +0000467
468
Jim Grosbach764ab522009-08-11 15:33:49 +0000469/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Chengcdbb3f52009-08-27 01:23:50 +0000470/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
471/// offset could not be handled directly in MI, and return the left-over
472/// portion by reference.
473bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
474 unsigned FrameReg, int &Offset,
475 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000476
Evan Chengcdbb3f52009-08-27 01:23:50 +0000477bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
478 unsigned FrameReg, int &Offset,
479 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000480
481} // End llvm namespace
482
David Goodwin334c2642009-07-08 16:09:28 +0000483#endif