blob: 5e7156c9ce971495f54037a21f11c4753e090f24 [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
Eric Christopher8b3ca622010-11-18 19:40:05 +0000214 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
215 MachineBasicBlock::iterator MI,
216 const std::vector<CalleeSavedInfo> &CSI,
217 const TargetRegisterInfo *TRI) const;
218
219private:
220 void emitPopInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
221 const std::vector<CalleeSavedInfo> &CSI, unsigned Opc,
222 bool isVarArg, bool(*Func)(unsigned, bool)) const;
223 void emitPushInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
224 const std::vector<CalleeSavedInfo> &CSI, unsigned Opc,
225 bool(*Func)(unsigned, bool)) const;
226
227
228public:
David Goodwin334c2642009-07-08 16:09:28 +0000229 // Branch analysis.
230 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
231 MachineBasicBlock *&FBB,
232 SmallVectorImpl<MachineOperand> &Cond,
Chris Lattner20628752010-07-22 21:27:00 +0000233 bool AllowModify = false) const;
David Goodwin334c2642009-07-08 16:09:28 +0000234 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
235 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
236 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000237 const SmallVectorImpl<MachineOperand> &Cond,
238 DebugLoc DL) const;
David Goodwin334c2642009-07-08 16:09:28 +0000239
240 virtual
241 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
242
243 // Predication support.
Evan Chengab331502009-07-10 01:38:27 +0000244 bool isPredicated(const MachineInstr *MI) const {
245 int PIdx = MI->findFirstPredOperandIdx();
246 return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL;
247 }
David Goodwin334c2642009-07-08 16:09:28 +0000248
249 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
250 int PIdx = MI->findFirstPredOperandIdx();
251 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
252 : ARMCC::AL;
253 }
254
255 virtual
256 bool PredicateInstruction(MachineInstr *MI,
257 const SmallVectorImpl<MachineOperand> &Pred) const;
258
259 virtual
260 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
261 const SmallVectorImpl<MachineOperand> &Pred2) const;
262
263 virtual bool DefinesPredicate(MachineInstr *MI,
264 std::vector<MachineOperand> &Pred) const;
265
Evan Chengac0869d2009-11-21 06:21:52 +0000266 virtual bool isPredicable(MachineInstr *MI) const;
267
David Goodwin334c2642009-07-08 16:09:28 +0000268 /// GetInstSize - Returns the size of the specified MachineInstr.
269 ///
270 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
271
David Goodwin334c2642009-07-08 16:09:28 +0000272 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
273 int &FrameIndex) const;
274 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
275 int &FrameIndex) const;
276
Jakob Stoklund Olesenac273662010-07-11 06:33:54 +0000277 virtual void copyPhysReg(MachineBasicBlock &MBB,
278 MachineBasicBlock::iterator I, DebugLoc DL,
279 unsigned DestReg, unsigned SrcReg,
280 bool KillSrc) const;
Evan Cheng5732ca02009-07-27 03:14:20 +0000281
David Goodwin334c2642009-07-08 16:09:28 +0000282 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
283 MachineBasicBlock::iterator MBBI,
284 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000285 const TargetRegisterClass *RC,
286 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000287
David Goodwin334c2642009-07-08 16:09:28 +0000288 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
289 MachineBasicBlock::iterator MBBI,
290 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000291 const TargetRegisterClass *RC,
292 const TargetRegisterInfo *TRI) const;
David Goodwin334c2642009-07-08 16:09:28 +0000293
Evan Cheng62b50652010-04-26 07:39:25 +0000294 virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
Evan Cheng8601a3d2010-04-29 01:13:30 +0000295 int FrameIx,
Evan Cheng62b50652010-04-26 07:39:25 +0000296 uint64_t Offset,
297 const MDNode *MDPtr,
298 DebugLoc DL) const;
299
Evan Chengfdc83402009-11-08 00:15:23 +0000300 virtual void reMaterialize(MachineBasicBlock &MBB,
301 MachineBasicBlock::iterator MI,
302 unsigned DestReg, unsigned SubIdx,
Evan Chengd57cdd52009-11-14 02:55:43 +0000303 const MachineInstr *Orig,
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +0000304 const TargetRegisterInfo &TRI) const;
Evan Chengfdc83402009-11-08 00:15:23 +0000305
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +0000306 MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const;
307
Evan Cheng506049f2010-03-03 01:44:33 +0000308 virtual bool produceSameValue(const MachineInstr *MI0,
309 const MachineInstr *MI1) const;
Evan Cheng86050dc2010-06-18 23:09:54 +0000310
Bill Wendling4b722102010-06-23 23:00:16 +0000311 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
312 /// determine if two loads are loading from the same base address. It should
313 /// only return true if the base pointers are the same and the only
314 /// differences between the two addresses is the offset. It also returns the
315 /// offsets by reference.
316 virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
317 int64_t &Offset1, int64_t &Offset2)const;
318
319 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
320 /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should
321 /// be scheduled togther. On some targets if two loads are loading from
322 /// addresses in the same cache line, it's better if they are scheduled
323 /// together. This function takes two integers that represent the load offsets
324 /// from the common base address. It returns true if it decides it's desirable
325 /// to schedule the two loads together. "NumLoads" is the number of loads that
326 /// have already been scheduled after Load1.
327 virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
328 int64_t Offset1, int64_t Offset2,
329 unsigned NumLoads) const;
330
Evan Cheng86050dc2010-06-18 23:09:54 +0000331 virtual bool isSchedulingBoundary(const MachineInstr *MI,
332 const MachineBasicBlock *MBB,
333 const MachineFunction &MF) const;
Evan Cheng13151432010-06-25 22:42:03 +0000334
335 virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB,
Evan Cheng8239daf2010-11-03 00:45:17 +0000336 unsigned NumCyles, unsigned ExtraPredCycles,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000337 float Prob, float Confidence) const;
Evan Cheng13151432010-06-25 22:42:03 +0000338
Evan Cheng8239daf2010-11-03 00:45:17 +0000339 virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
340 unsigned NumT, unsigned ExtraT,
341 MachineBasicBlock &FMBB,
342 unsigned NumF, unsigned ExtraF,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000343 float Probability, float Confidence) const;
Evan Cheng13151432010-06-25 22:42:03 +0000344
345 virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
Evan Cheng8239daf2010-11-03 00:45:17 +0000346 unsigned NumCyles,
Owen Andersone3cc84a2010-10-01 22:45:50 +0000347 float Probability,
348 float Confidence) const {
Evan Cheng8239daf2010-11-03 00:45:17 +0000349 return NumCyles == 1;
Evan Cheng13151432010-06-25 22:42:03 +0000350 }
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000351
Bill Wendlingc98af332010-08-08 05:04:59 +0000352 /// AnalyzeCompare - For a comparison instruction, return the source register
353 /// in SrcReg and the value it compares against in CmpValue. Return true if
354 /// the comparison instruction can be analyzed.
355 virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000356 int &CmpMask, int &CmpValue) const;
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000357
Bill Wendlinga6556862010-09-11 00:13:50 +0000358 /// OptimizeCompareInstr - Convert the instruction to set the zero flag so
Bill Wendlinge4ddbdf2010-08-06 01:32:48 +0000359 /// that we can remove a "comparison with zero".
Bill Wendlinga6556862010-09-11 00:13:50 +0000360 virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
Gabor Greif04ac81d2010-09-21 12:01:15 +0000361 int CmpMask, int CmpValue,
Evan Chengeb96a2f2010-11-15 21:20:45 +0000362 const MachineRegisterInfo *MRI) const;
Evan Cheng5f54ce32010-09-09 18:18:55 +0000363
Evan Chengc4af4632010-11-17 20:13:28 +0000364 /// FoldImmediate - 'Reg' is known to be defined by a move immediate
365 /// instruction, try to fold the immediate into the use instruction.
366 virtual bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
367 unsigned Reg, MachineRegisterInfo *MRI) const;
368
Evan Cheng8239daf2010-11-03 00:45:17 +0000369 virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
370 const MachineInstr *MI) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000371
372 virtual
373 int getOperandLatency(const InstrItineraryData *ItinData,
374 const MachineInstr *DefMI, unsigned DefIdx,
375 const MachineInstr *UseMI, unsigned UseIdx) const;
376 virtual
377 int getOperandLatency(const InstrItineraryData *ItinData,
378 SDNode *DefNode, unsigned DefIdx,
379 SDNode *UseNode, unsigned UseIdx) const;
380private:
Evan Cheng344d9db2010-10-07 23:12:15 +0000381 int getVLDMDefCycle(const InstrItineraryData *ItinData,
382 const TargetInstrDesc &DefTID,
383 unsigned DefClass,
384 unsigned DefIdx, unsigned DefAlign) const;
385 int getLDMDefCycle(const InstrItineraryData *ItinData,
386 const TargetInstrDesc &DefTID,
387 unsigned DefClass,
388 unsigned DefIdx, unsigned DefAlign) const;
389 int getVSTMUseCycle(const InstrItineraryData *ItinData,
390 const TargetInstrDesc &UseTID,
391 unsigned UseClass,
392 unsigned UseIdx, unsigned UseAlign) const;
393 int getSTMUseCycle(const InstrItineraryData *ItinData,
394 const TargetInstrDesc &UseTID,
395 unsigned UseClass,
396 unsigned UseIdx, unsigned UseAlign) const;
Evan Chenga0792de2010-10-06 06:27:31 +0000397 int getOperandLatency(const InstrItineraryData *ItinData,
398 const TargetInstrDesc &DefTID,
399 unsigned DefIdx, unsigned DefAlign,
400 const TargetInstrDesc &UseTID,
401 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng23128422010-10-19 18:58:51 +0000402
Evan Cheng8239daf2010-11-03 00:45:17 +0000403 int getInstrLatency(const InstrItineraryData *ItinData,
404 const MachineInstr *MI, unsigned *PredCost = 0) const;
405
406 int getInstrLatency(const InstrItineraryData *ItinData,
407 SDNode *Node) const;
408
Evan Cheng23128422010-10-19 18:58:51 +0000409 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
410 const MachineRegisterInfo *MRI,
411 const MachineInstr *DefMI, unsigned DefIdx,
412 const MachineInstr *UseMI, unsigned UseIdx) const;
Evan Chengc8141df2010-10-26 02:08:50 +0000413 bool hasLowDefLatency(const InstrItineraryData *ItinData,
414 const MachineInstr *DefMI, unsigned DefIdx) const;
David Goodwin334c2642009-07-08 16:09:28 +0000415};
Evan Cheng6495f632009-07-28 05:48:47 +0000416
417static inline
418const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
419 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwin334c2642009-07-08 16:09:28 +0000420}
421
Evan Cheng6495f632009-07-28 05:48:47 +0000422static inline
423const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
424 return MIB.addReg(0);
425}
426
427static inline
Evan Chenge8af1f92009-08-10 02:37:24 +0000428const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
429 bool isDead = false) {
430 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng6495f632009-07-28 05:48:47 +0000431}
432
433static inline
Evan Chengbc9b7542009-08-15 07:59:10 +0000434const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
435 return MIB.addReg(0);
436}
437
438static inline
Evan Cheng6495f632009-07-28 05:48:47 +0000439bool isUncondBranchOpcode(int Opc) {
440 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
441}
442
443static inline
444bool isCondBranchOpcode(int Opc) {
445 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
446}
447
448static inline
449bool isJumpTableBranchOpcode(int Opc) {
450 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
451 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
452}
453
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000454static inline
455bool isIndirectBranchOpcode(int Opc) {
Anton Korobeynikovce7bf1c2010-03-06 19:39:36 +0000456 return Opc == ARM::BRIND || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000457}
458
Evan Cheng8fb90362009-08-08 03:20:32 +0000459/// getInstrPredicate - If instruction is predicated, returns its predicate
460/// condition, otherwise returns AL. It also returns the condition code
461/// register by reference.
Evan Cheng5adb66a2009-09-28 09:14:39 +0000462ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
Evan Cheng8fb90362009-08-08 03:20:32 +0000463
Evan Cheng6495f632009-07-28 05:48:47 +0000464int getMatchingCondBranchOpcode(int Opc);
465
466/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
467/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
468/// code.
469void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
470 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
471 unsigned DestReg, unsigned BaseReg, int NumBytes,
472 ARMCC::CondCodes Pred, unsigned PredReg,
473 const ARMBaseInstrInfo &TII);
474
475void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
476 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
477 unsigned DestReg, unsigned BaseReg, int NumBytes,
478 ARMCC::CondCodes Pred, unsigned PredReg,
479 const ARMBaseInstrInfo &TII);
Jim Grosbache4ad3872010-10-19 23:27:08 +0000480void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
481 MachineBasicBlock::iterator &MBBI,
482 unsigned DestReg, unsigned BaseReg,
483 int NumBytes, const TargetInstrInfo &TII,
484 const ARMBaseRegisterInfo& MRI,
485 DebugLoc dl);
Evan Cheng6495f632009-07-28 05:48:47 +0000486
487
Jim Grosbach764ab522009-08-11 15:33:49 +0000488/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Chengcdbb3f52009-08-27 01:23:50 +0000489/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
490/// offset could not be handled directly in MI, and return the left-over
491/// portion by reference.
492bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
493 unsigned FrameReg, int &Offset,
494 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000495
Evan Chengcdbb3f52009-08-27 01:23:50 +0000496bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
497 unsigned FrameReg, int &Offset,
498 const ARMBaseInstrInfo &TII);
Evan Cheng6495f632009-07-28 05:48:47 +0000499
500} // End llvm namespace
501
David Goodwin334c2642009-07-08 16:09:28 +0000502#endif