blob: b8d675806b25a94a9f9839df37e1e4b0c79ec6f9 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- ARMBaseInstrInfo.h - ARM Base Instruction Information ---*- C++ -*-===//
David Goodwinaf7451b2009-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
Craig Toppera9253262014-03-22 23:51:00 +000017#include "MCTargetDesc/ARMBaseInfo.h"
Evan Cheng62c7b5b2010-12-05 22:04:16 +000018#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/SmallSet.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000020#include "llvm/CodeGen/MachineInstrBuilder.h"
21#include "llvm/Target/TargetInstrInfo.h"
David Goodwinaf7451b2009-07-08 16:09:28 +000022
Evan Cheng703a0fb2011-07-01 17:57:27 +000023#define GET_INSTRINFO_HEADER
24#include "ARMGenInstrInfo.inc"
25
David Goodwinaf7451b2009-07-08 16:09:28 +000026namespace llvm {
Chris Lattnercbe98562010-07-20 21:17:29 +000027 class ARMSubtarget;
28 class ARMBaseRegisterInfo;
David Goodwinaf7451b2009-07-08 16:09:28 +000029
Evan Cheng703a0fb2011-07-01 17:57:27 +000030class ARMBaseInstrInfo : public ARMGenInstrInfo {
Chris Lattnercbe98562010-07-20 21:17:29 +000031 const ARMSubtarget &Subtarget;
Evan Cheng62c7b5b2010-12-05 22:04:16 +000032
David Goodwinaf7451b2009-07-08 16:09:28 +000033protected:
34 // Can be only subclassed.
Anton Korobeynikov14635da2009-11-02 00:10:38 +000035 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
Evan Cheng62c7b5b2010-12-05 22:04:16 +000036
David Goodwinaf7451b2009-07-08 16:09:28 +000037public:
Jim Grosbach617f84dd2012-02-28 23:53:30 +000038 // Return whether the target has an explicit NOP encoding.
39 bool hasNOP() const;
40
David Goodwinaf7451b2009-07-08 16:09:28 +000041 // Return the non-pre/post incrementing version of 'Opc'. Return 0
42 // if there is not such an opcode.
43 virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
44
Craig Topper6bc27bf2014-03-10 02:09:33 +000045 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
46 MachineBasicBlock::iterator &MBBI,
47 LiveVariables *LV) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +000048
Bill Wendlingf95178e2013-06-07 05:54:19 +000049 virtual const ARMBaseRegisterInfo &getRegisterInfo() const = 0;
Anton Korobeynikov14635da2009-11-02 00:10:38 +000050 const ARMSubtarget &getSubtarget() const { return Subtarget; }
David Goodwinaf7451b2009-07-08 16:09:28 +000051
Evan Cheng62c7b5b2010-12-05 22:04:16 +000052 ScheduleHazardRecognizer *
Eric Christopherf047bfd2014-06-13 22:38:52 +000053 CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,
Craig Topper6bc27bf2014-03-10 02:09:33 +000054 const ScheduleDAG *DAG) const override;
Andrew Trick10ffc2b2010-12-24 05:03:26 +000055
56 ScheduleHazardRecognizer *
57 CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
Craig Topper6bc27bf2014-03-10 02:09:33 +000058 const ScheduleDAG *DAG) const override;
Evan Cheng62c7b5b2010-12-05 22:04:16 +000059
David Goodwinaf7451b2009-07-08 16:09:28 +000060 // Branch analysis.
Craig Topper6bc27bf2014-03-10 02:09:33 +000061 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
62 MachineBasicBlock *&FBB,
63 SmallVectorImpl<MachineOperand> &Cond,
64 bool AllowModify = false) const override;
65 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
66 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
67 MachineBasicBlock *FBB,
68 const SmallVectorImpl<MachineOperand> &Cond,
69 DebugLoc DL) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +000070
Craig Topper6bc27bf2014-03-10 02:09:33 +000071 bool
72 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +000073
74 // Predication support.
Craig Topper6bc27bf2014-03-10 02:09:33 +000075 bool isPredicated(const MachineInstr *MI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +000076
77 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
78 int PIdx = MI->findFirstPredOperandIdx();
79 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
80 : ARMCC::AL;
81 }
82
David Goodwinaf7451b2009-07-08 16:09:28 +000083 bool PredicateInstruction(MachineInstr *MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +000084 const SmallVectorImpl<MachineOperand> &Pred) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +000085
David Goodwinaf7451b2009-07-08 16:09:28 +000086 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
Craig Topper6bc27bf2014-03-10 02:09:33 +000087 const SmallVectorImpl<MachineOperand> &Pred2) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +000088
Craig Topper6bc27bf2014-03-10 02:09:33 +000089 bool DefinesPredicate(MachineInstr *MI,
90 std::vector<MachineOperand> &Pred) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +000091
Craig Topper6bc27bf2014-03-10 02:09:33 +000092 bool isPredicable(MachineInstr *MI) const override;
Evan Chenga33fc862009-11-21 06:21:52 +000093
David Goodwinaf7451b2009-07-08 16:09:28 +000094 /// GetInstSize - Returns the size of the specified MachineInstr.
95 ///
96 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
97
Craig Topper6bc27bf2014-03-10 02:09:33 +000098 unsigned isLoadFromStackSlot(const MachineInstr *MI,
99 int &FrameIndex) const override;
100 unsigned isStoreToStackSlot(const MachineInstr *MI,
101 int &FrameIndex) const override;
102 unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
103 int &FrameIndex) const override;
104 unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
105 int &FrameIndex) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000106
Craig Topper6bc27bf2014-03-10 02:09:33 +0000107 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
108 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
109 bool KillSrc) const override;
Evan Chengc47e1092009-07-27 03:14:20 +0000110
Craig Topper6bc27bf2014-03-10 02:09:33 +0000111 void storeRegToStackSlot(MachineBasicBlock &MBB,
112 MachineBasicBlock::iterator MBBI,
113 unsigned SrcReg, bool isKill, int FrameIndex,
114 const TargetRegisterClass *RC,
115 const TargetRegisterInfo *TRI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000116
Craig Topper6bc27bf2014-03-10 02:09:33 +0000117 void loadRegFromStackSlot(MachineBasicBlock &MBB,
118 MachineBasicBlock::iterator MBBI,
119 unsigned DestReg, int FrameIndex,
120 const TargetRegisterClass *RC,
121 const TargetRegisterInfo *TRI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000122
Craig Topper6bc27bf2014-03-10 02:09:33 +0000123 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Jakob Stoklund Olesenda7c0f82011-10-11 00:59:06 +0000124
Craig Topper6bc27bf2014-03-10 02:09:33 +0000125 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
126 unsigned DestReg, unsigned SubIdx,
127 const MachineInstr *Orig,
128 const TargetRegisterInfo &TRI) const override;
Evan Chengfe864422009-11-08 00:15:23 +0000129
Craig Topper6bc27bf2014-03-10 02:09:33 +0000130 MachineInstr *duplicate(MachineInstr *Orig,
131 MachineFunction &MF) const override;
Jakob Stoklund Olesen29a64c92010-01-06 23:47:07 +0000132
Craig Topper6bc27bf2014-03-10 02:09:33 +0000133 MachineInstr *commuteInstruction(MachineInstr*,
134 bool=false) const override;
Jakob Stoklund Olesen0a5b72f2012-04-04 18:23:42 +0000135
Tim Northover798697d2013-04-21 11:57:07 +0000136 const MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, unsigned Reg,
137 unsigned SubIdx, unsigned State,
138 const TargetRegisterInfo *TRI) const;
139
Craig Topper6bc27bf2014-03-10 02:09:33 +0000140 bool produceSameValue(const MachineInstr *MI0, const MachineInstr *MI1,
141 const MachineRegisterInfo *MRI) const override;
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000142
Bill Wendlingf4707472010-06-23 23:00:16 +0000143 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
144 /// determine if two loads are loading from the same base address. It should
145 /// only return true if the base pointers are the same and the only
146 /// differences between the two addresses is the offset. It also returns the
147 /// offsets by reference.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000148 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1,
149 int64_t &Offset2) const override;
Bill Wendlingf4707472010-06-23 23:00:16 +0000150
151 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000152 /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads
153 /// should be scheduled togther. On some targets if two loads are loading from
Bill Wendlingf4707472010-06-23 23:00:16 +0000154 /// addresses in the same cache line, it's better if they are scheduled
155 /// together. This function takes two integers that represent the load offsets
156 /// from the common base address. It returns true if it decides it's desirable
157 /// to schedule the two loads together. "NumLoads" is the number of loads that
158 /// have already been scheduled after Load1.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000159 bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
160 int64_t Offset1, int64_t Offset2,
161 unsigned NumLoads) const override;
Bill Wendlingf4707472010-06-23 23:00:16 +0000162
Craig Topper6bc27bf2014-03-10 02:09:33 +0000163 bool isSchedulingBoundary(const MachineInstr *MI,
164 const MachineBasicBlock *MBB,
165 const MachineFunction &MF) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000166
Craig Topper6bc27bf2014-03-10 02:09:33 +0000167 bool isProfitableToIfCvt(MachineBasicBlock &MBB,
168 unsigned NumCycles, unsigned ExtraPredCycles,
169 const BranchProbability &Probability) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000170
Craig Topper6bc27bf2014-03-10 02:09:33 +0000171 bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT,
172 unsigned ExtraT, MachineBasicBlock &FMBB,
173 unsigned NumF, unsigned ExtraF,
174 const BranchProbability &Probability) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000175
Craig Topper6bc27bf2014-03-10 02:09:33 +0000176 bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
177 const BranchProbability &Probability) const override {
Cameron Zwarich80018502011-04-13 06:39:16 +0000178 return NumCycles == 1;
Evan Cheng02b184d2010-06-25 22:42:03 +0000179 }
Bill Wendling7de9d522010-08-06 01:32:48 +0000180
Craig Topper6bc27bf2014-03-10 02:09:33 +0000181 bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
182 MachineBasicBlock &FMBB) const override;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000183
Manman Ren6fa76dc2012-06-29 21:33:59 +0000184 /// analyzeCompare - For a comparison instruction, return the source registers
185 /// in SrcReg and SrcReg2 if having two register operands, and the value it
186 /// compares against in CmpValue. Return true if the comparison instruction
187 /// can be analyzed.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000188 bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
189 unsigned &SrcReg2, int &CmpMask,
190 int &CmpValue) const override;
Bill Wendling7de9d522010-08-06 01:32:48 +0000191
Manman Ren6fa76dc2012-06-29 21:33:59 +0000192 /// optimizeCompareInstr - Convert the instruction to set the zero flag so
193 /// that we can remove a "comparison with zero"; Remove a redundant CMP
194 /// instruction if the flags can be updated in the same way by an earlier
195 /// instruction such as SUB.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000196 bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
197 unsigned SrcReg2, int CmpMask, int CmpValue,
198 const MachineRegisterInfo *MRI) const override;
Evan Cheng367a5df2010-09-09 18:18:55 +0000199
Craig Topper6bc27bf2014-03-10 02:09:33 +0000200 bool analyzeSelect(const MachineInstr *MI,
201 SmallVectorImpl<MachineOperand> &Cond,
202 unsigned &TrueOp, unsigned &FalseOp,
203 bool &Optimizable) const override;
Jakob Stoklund Olesenc19bf022012-08-16 23:14:20 +0000204
Craig Topper6bc27bf2014-03-10 02:09:33 +0000205 MachineInstr *optimizeSelect(MachineInstr *MI, bool) const override;
Jakob Stoklund Olesenc19bf022012-08-16 23:14:20 +0000206
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000207 /// FoldImmediate - 'Reg' is known to be defined by a move immediate
208 /// instruction, try to fold the immediate into the use instruction.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000209 bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
210 unsigned Reg, MachineRegisterInfo *MRI) const override;
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000211
Craig Topper6bc27bf2014-03-10 02:09:33 +0000212 unsigned getNumMicroOps(const InstrItineraryData *ItinData,
213 const MachineInstr *MI) const override;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000214
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000215 int getOperandLatency(const InstrItineraryData *ItinData,
216 const MachineInstr *DefMI, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000217 const MachineInstr *UseMI,
218 unsigned UseIdx) const override;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000219 int getOperandLatency(const InstrItineraryData *ItinData,
220 SDNode *DefNode, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000221 SDNode *UseNode, unsigned UseIdx) const override;
Jakob Stoklund Olesenf9b71a22011-09-27 22:57:21 +0000222
223 /// VFP/NEON execution domains.
224 std::pair<uint16_t, uint16_t>
Craig Topper6bc27bf2014-03-10 02:09:33 +0000225 getExecutionDomain(const MachineInstr *MI) const override;
226 void setExecutionDomain(MachineInstr *MI, unsigned Domain) const override;
Jakob Stoklund Olesenf9b71a22011-09-27 22:57:21 +0000227
Bob Wilsone8a549c2012-09-29 21:43:49 +0000228 unsigned getPartialRegUpdateClearance(const MachineInstr*, unsigned,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000229 const TargetRegisterInfo*) const override;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000230 void breakPartialRegDependency(MachineBasicBlock::iterator, unsigned,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000231 const TargetRegisterInfo *TRI) const override;
Tom Roeder44cb65f2014-06-05 19:29:43 +0000232
233 void
234 getUnconditionalBranch(MCInst &Branch,
235 const MCSymbolRefExpr *BranchTarget) const override;
236
237 void getTrap(MCInst &MI) const override;
238
Andrew Trick2ac6f7d2012-09-14 18:48:46 +0000239 /// Get the number of addresses by LDM or VLDM or zero for unknown.
240 unsigned getNumLDMAddresses(const MachineInstr *MI) const;
241
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000242private:
Evan Cheng7fae11b2011-12-14 02:11:42 +0000243 unsigned getInstBundleLength(const MachineInstr *MI) const;
244
Evan Cheng412e37b2010-10-07 23:12:15 +0000245 int getVLDMDefCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000246 const MCInstrDesc &DefMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000247 unsigned DefClass,
248 unsigned DefIdx, unsigned DefAlign) const;
249 int getLDMDefCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000250 const MCInstrDesc &DefMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000251 unsigned DefClass,
252 unsigned DefIdx, unsigned DefAlign) const;
253 int getVSTMUseCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000254 const MCInstrDesc &UseMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000255 unsigned UseClass,
256 unsigned UseIdx, unsigned UseAlign) const;
257 int getSTMUseCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000258 const MCInstrDesc &UseMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000259 unsigned UseClass,
260 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000261 int getOperandLatency(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000262 const MCInstrDesc &DefMCID,
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000263 unsigned DefIdx, unsigned DefAlign,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000264 const MCInstrDesc &UseMCID,
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000265 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng63c76082010-10-19 18:58:51 +0000266
Craig Topper6bc27bf2014-03-10 02:09:33 +0000267 unsigned getPredicationCost(const MachineInstr *MI) const override;
Arnold Schwaighoferd2f96b92013-09-30 15:28:56 +0000268
Andrew Trick45446062012-06-05 21:11:27 +0000269 unsigned getInstrLatency(const InstrItineraryData *ItinData,
270 const MachineInstr *MI,
Craig Toppere73658d2014-04-28 04:05:08 +0000271 unsigned *PredCost = nullptr) const override;
Evan Chengdebf9c52010-11-03 00:45:17 +0000272
273 int getInstrLatency(const InstrItineraryData *ItinData,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000274 SDNode *Node) const override;
Evan Chengdebf9c52010-11-03 00:45:17 +0000275
Evan Cheng63c76082010-10-19 18:58:51 +0000276 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
277 const MachineRegisterInfo *MRI,
278 const MachineInstr *DefMI, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000279 const MachineInstr *UseMI,
280 unsigned UseIdx) const override;
Evan Chenge96b8d72010-10-26 02:08:50 +0000281 bool hasLowDefLatency(const InstrItineraryData *ItinData,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000282 const MachineInstr *DefMI,
283 unsigned DefIdx) const override;
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000284
Andrew Trick924123a2011-09-21 02:20:46 +0000285 /// verifyInstruction - Perform target specific instruction verification.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000286 bool verifyInstruction(const MachineInstr *MI,
287 StringRef &ErrInfo) const override;
Andrew Trick924123a2011-09-21 02:20:46 +0000288
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000289private:
290 /// Modeling special VFP / NEON fp MLA / MLS hazards.
291
292 /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal
293 /// MLx table.
294 DenseMap<unsigned, unsigned> MLxEntryMap;
295
296 /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause
297 /// stalls when scheduled together with fp MLA / MLS opcodes.
298 SmallSet<unsigned, 16> MLxHazardOpcodes;
299
300public:
301 /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS
302 /// instruction.
303 bool isFpMLxInstruction(unsigned Opcode) const {
304 return MLxEntryMap.count(Opcode);
305 }
306
307 /// isFpMLxInstruction - This version also returns the multiply opcode and the
308 /// addition / subtraction opcode to expand to. Return true for 'HasLane' for
309 /// the MLX instructions with an extra lane operand.
310 bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc,
311 unsigned &AddSubOpc, bool &NegAcc,
312 bool &HasLane) const;
313
314 /// canCauseFpMLxStall - Return true if an instruction of the specified opcode
315 /// will cause stalls when scheduled after (within 4-cycle window) a fp
316 /// MLA / MLS instruction.
317 bool canCauseFpMLxStall(unsigned Opcode) const {
318 return MLxHazardOpcodes.count(Opcode);
319 }
Arnold Schwaighofer5dde1f32013-04-05 04:42:00 +0000320
321 /// Returns true if the instruction has a shift by immediate that can be
322 /// executed in one cycle less.
323 bool isSwiftFastImmShift(const MachineInstr *MI) const;
David Goodwinaf7451b2009-07-08 16:09:28 +0000324};
Evan Cheng780748d2009-07-28 05:48:47 +0000325
326static inline
327const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
328 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwinaf7451b2009-07-08 16:09:28 +0000329}
330
Evan Cheng780748d2009-07-28 05:48:47 +0000331static inline
332const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
333 return MIB.addReg(0);
334}
335
336static inline
Evan Cheng51cbd2d2009-08-10 02:37:24 +0000337const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
338 bool isDead = false) {
339 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng780748d2009-07-28 05:48:47 +0000340}
341
342static inline
Evan Cheng6ddd7bc2009-08-15 07:59:10 +0000343const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
344 return MIB.addReg(0);
345}
346
347static inline
Evan Cheng780748d2009-07-28 05:48:47 +0000348bool isUncondBranchOpcode(int Opc) {
349 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
350}
351
352static inline
353bool isCondBranchOpcode(int Opc) {
354 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
355}
356
357static inline
358bool isJumpTableBranchOpcode(int Opc) {
359 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
360 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
361}
362
Bob Wilson73789b82009-10-28 18:26:41 +0000363static inline
364bool isIndirectBranchOpcode(int Opc) {
Bill Wendling8294a302010-11-30 00:48:15 +0000365 return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson73789b82009-10-28 18:26:41 +0000366}
367
Tim Northover93bcc662013-11-08 17:18:07 +0000368static inline bool isPopOpcode(int Opc) {
369 return Opc == ARM::tPOP_RET || Opc == ARM::LDMIA_RET ||
370 Opc == ARM::t2LDMIA_RET || Opc == ARM::tPOP || Opc == ARM::LDMIA_UPD ||
371 Opc == ARM::t2LDMIA_UPD || Opc == ARM::VLDMDIA_UPD;
372}
373
374static inline bool isPushOpcode(int Opc) {
375 return Opc == ARM::tPUSH || Opc == ARM::t2STMDB_UPD ||
376 Opc == ARM::STMDB_UPD || Opc == ARM::VSTMDDB_UPD;
377}
378
Evan Cheng2aa91cc2009-08-08 03:20:32 +0000379/// getInstrPredicate - If instruction is predicated, returns its predicate
380/// condition, otherwise returns AL. It also returns the condition code
381/// register by reference.
Evan Cheng83e0d482009-09-28 09:14:39 +0000382ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
Evan Cheng2aa91cc2009-08-08 03:20:32 +0000383
Evan Cheng780748d2009-07-28 05:48:47 +0000384int getMatchingCondBranchOpcode(int Opc);
385
Jakob Stoklund Olesen6cb96122012-08-15 22:16:39 +0000386/// Determine if MI can be folded into an ARM MOVCC instruction, and return the
387/// opcode of the SSA instruction representing the conditional MI.
388unsigned canFoldARMInstrIntoMOVCC(unsigned Reg,
389 MachineInstr *&MI,
390 const MachineRegisterInfo &MRI);
Andrew Trick924123a2011-09-21 02:20:46 +0000391
392/// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether
393/// the instruction is encoded with an 'S' bit is determined by the optional
394/// CPSR def operand.
395unsigned convertAddSubFlagsOpcode(unsigned OldOpc);
396
Evan Cheng780748d2009-07-28 05:48:47 +0000397/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
398/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
399/// code.
400void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
401 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
402 unsigned DestReg, unsigned BaseReg, int NumBytes,
403 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000404 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Evan Cheng780748d2009-07-28 05:48:47 +0000405
406void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
407 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
408 unsigned DestReg, unsigned BaseReg, int NumBytes,
409 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000410 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Jim Grosbachbbdc5d22010-10-19 23:27:08 +0000411void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000412 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
Jim Grosbachbbdc5d22010-10-19 23:27:08 +0000413 unsigned DestReg, unsigned BaseReg,
414 int NumBytes, const TargetInstrInfo &TII,
415 const ARMBaseRegisterInfo& MRI,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000416 unsigned MIFlags = 0);
Evan Cheng780748d2009-07-28 05:48:47 +0000417
Tim Northover93bcc662013-11-08 17:18:07 +0000418/// Tries to add registers to the reglist of a given base-updating
419/// push/pop instruction to adjust the stack by an additional
420/// NumBytes. This can save a few bytes per function in code-size, but
421/// obviously generates more memory traffic. As such, it only takes
422/// effect in functions being optimised for size.
Tim Northoverdee86042013-12-02 14:46:26 +0000423bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget,
424 MachineFunction &MF, MachineInstr *MI,
Tim Northover93bcc662013-11-08 17:18:07 +0000425 unsigned NumBytes);
Evan Cheng780748d2009-07-28 05:48:47 +0000426
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000427/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Cheng7a37b1a2009-08-27 01:23:50 +0000428/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
429/// offset could not be handled directly in MI, and return the left-over
430/// portion by reference.
431bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
432 unsigned FrameReg, int &Offset,
433 const ARMBaseInstrInfo &TII);
Evan Cheng780748d2009-07-28 05:48:47 +0000434
Evan Cheng7a37b1a2009-08-27 01:23:50 +0000435bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
436 unsigned FrameReg, int &Offset,
437 const ARMBaseInstrInfo &TII);
Evan Cheng780748d2009-07-28 05:48:47 +0000438
439} // End llvm namespace
440
David Goodwinaf7451b2009-07-08 16:09:28 +0000441#endif