blob: ab5dc661faf35f0422924385e7c9b6ae53f80941 [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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_ARM_ARMBASEINSTRINFO_H
15#define LLVM_LIB_TARGET_ARM_ARMBASEINSTRINFO_H
David Goodwinaf7451b2009-07-08 16:09:28 +000016
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"
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +000021#include "llvm/Support/CodeGen.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000022#include "llvm/Target/TargetInstrInfo.h"
David Goodwinaf7451b2009-07-08 16:09:28 +000023
Evan Cheng703a0fb2011-07-01 17:57:27 +000024#define GET_INSTRINFO_HEADER
25#include "ARMGenInstrInfo.inc"
26
David Goodwinaf7451b2009-07-08 16:09:28 +000027namespace llvm {
Chris Lattnercbe98562010-07-20 21:17:29 +000028 class ARMSubtarget;
29 class ARMBaseRegisterInfo;
David Goodwinaf7451b2009-07-08 16:09:28 +000030
Evan Cheng703a0fb2011-07-01 17:57:27 +000031class ARMBaseInstrInfo : public ARMGenInstrInfo {
Chris Lattnercbe98562010-07-20 21:17:29 +000032 const ARMSubtarget &Subtarget;
Evan Cheng62c7b5b2010-12-05 22:04:16 +000033
David Goodwinaf7451b2009-07-08 16:09:28 +000034protected:
35 // Can be only subclassed.
Anton Korobeynikov14635da2009-11-02 00:10:38 +000036 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
Evan Cheng62c7b5b2010-12-05 22:04:16 +000037
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +000038 void expandLoadStackGuardBase(MachineBasicBlock::iterator MI,
39 unsigned LoadImmOpc, unsigned LoadOpc,
40 Reloc::Model RM) const;
41
Quentin Colombetd358e842014-08-22 18:05:22 +000042 /// Build the equivalent inputs of a REG_SEQUENCE for the given \p MI
43 /// and \p DefIdx.
44 /// \p [out] InputRegs of the equivalent REG_SEQUENCE. Each element of
45 /// the list is modeled as <Reg:SubReg, SubIdx>.
46 /// E.g., REG_SEQUENCE vreg1:sub1, sub0, vreg2, sub1 would produce
47 /// two elements:
48 /// - vreg1:sub1, sub0
49 /// - vreg2<:0>, sub1
50 ///
51 /// \returns true if it is possible to build such an input sequence
52 /// with the pair \p MI, \p DefIdx. False otherwise.
53 ///
54 /// \pre MI.isRegSequenceLike().
55 bool getRegSequenceLikeInputs(
56 const MachineInstr &MI, unsigned DefIdx,
57 SmallVectorImpl<RegSubRegPairAndIdx> &InputRegs) const override;
58
59 /// Build the equivalent inputs of a EXTRACT_SUBREG for the given \p MI
60 /// and \p DefIdx.
61 /// \p [out] InputReg of the equivalent EXTRACT_SUBREG.
62 /// E.g., EXTRACT_SUBREG vreg1:sub1, sub0, sub1 would produce:
63 /// - vreg1:sub1, sub0
64 ///
65 /// \returns true if it is possible to build such an input sequence
66 /// with the pair \p MI, \p DefIdx. False otherwise.
67 ///
68 /// \pre MI.isExtractSubregLike().
69 bool getExtractSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx,
70 RegSubRegPairAndIdx &InputReg) const override;
71
72 /// Build the equivalent inputs of a INSERT_SUBREG for the given \p MI
73 /// and \p DefIdx.
74 /// \p [out] BaseReg and \p [out] InsertedReg contain
75 /// the equivalent inputs of INSERT_SUBREG.
76 /// E.g., INSERT_SUBREG vreg0:sub0, vreg1:sub1, sub3 would produce:
77 /// - BaseReg: vreg0:sub0
78 /// - InsertedReg: vreg1:sub1, sub3
79 ///
80 /// \returns true if it is possible to build such an input sequence
81 /// with the pair \p MI, \p DefIdx. False otherwise.
82 ///
83 /// \pre MI.isInsertSubregLike().
84 bool
85 getInsertSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx,
86 RegSubRegPair &BaseReg,
87 RegSubRegPairAndIdx &InsertedReg) const override;
88
David Goodwinaf7451b2009-07-08 16:09:28 +000089public:
Jim Grosbach617f84dd2012-02-28 23:53:30 +000090 // Return whether the target has an explicit NOP encoding.
91 bool hasNOP() const;
92
David Goodwinaf7451b2009-07-08 16:09:28 +000093 // Return the non-pre/post incrementing version of 'Opc'. Return 0
94 // if there is not such an opcode.
95 virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
96
Craig Topper6bc27bf2014-03-10 02:09:33 +000097 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
98 MachineBasicBlock::iterator &MBBI,
99 LiveVariables *LV) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000100
Bill Wendlingf95178e2013-06-07 05:54:19 +0000101 virtual const ARMBaseRegisterInfo &getRegisterInfo() const = 0;
Anton Korobeynikov14635da2009-11-02 00:10:38 +0000102 const ARMSubtarget &getSubtarget() const { return Subtarget; }
David Goodwinaf7451b2009-07-08 16:09:28 +0000103
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000104 ScheduleHazardRecognizer *
Eric Christopherf047bfd2014-06-13 22:38:52 +0000105 CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000106 const ScheduleDAG *DAG) const override;
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000107
108 ScheduleHazardRecognizer *
109 CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000110 const ScheduleDAG *DAG) const override;
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000111
David Goodwinaf7451b2009-07-08 16:09:28 +0000112 // Branch analysis.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000113 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
114 MachineBasicBlock *&FBB,
115 SmallVectorImpl<MachineOperand> &Cond,
116 bool AllowModify = false) const override;
117 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
118 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
119 MachineBasicBlock *FBB,
120 const SmallVectorImpl<MachineOperand> &Cond,
121 DebugLoc DL) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000122
Craig Topper6bc27bf2014-03-10 02:09:33 +0000123 bool
124 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000125
126 // Predication support.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000127 bool isPredicated(const MachineInstr *MI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000128
129 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
130 int PIdx = MI->findFirstPredOperandIdx();
131 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
132 : ARMCC::AL;
133 }
134
David Goodwinaf7451b2009-07-08 16:09:28 +0000135 bool PredicateInstruction(MachineInstr *MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000136 const SmallVectorImpl<MachineOperand> &Pred) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000137
David Goodwinaf7451b2009-07-08 16:09:28 +0000138 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000139 const SmallVectorImpl<MachineOperand> &Pred2) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000140
Craig Topper6bc27bf2014-03-10 02:09:33 +0000141 bool DefinesPredicate(MachineInstr *MI,
142 std::vector<MachineOperand> &Pred) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000143
Craig Topper6bc27bf2014-03-10 02:09:33 +0000144 bool isPredicable(MachineInstr *MI) const override;
Evan Chenga33fc862009-11-21 06:21:52 +0000145
David Goodwinaf7451b2009-07-08 16:09:28 +0000146 /// GetInstSize - Returns the size of the specified MachineInstr.
147 ///
148 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
149
Craig Topper6bc27bf2014-03-10 02:09:33 +0000150 unsigned isLoadFromStackSlot(const MachineInstr *MI,
151 int &FrameIndex) const override;
152 unsigned isStoreToStackSlot(const MachineInstr *MI,
153 int &FrameIndex) const override;
154 unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
155 int &FrameIndex) const override;
156 unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
157 int &FrameIndex) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000158
Tim Northover5d72c5d2014-10-01 19:21:03 +0000159 void copyToCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
160 unsigned SrcReg, bool KillSrc,
161 const ARMSubtarget &Subtarget) const;
162 void copyFromCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
163 unsigned DestReg, bool KillSrc,
164 const ARMSubtarget &Subtarget) const;
165
Craig Topper6bc27bf2014-03-10 02:09:33 +0000166 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
167 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
168 bool KillSrc) const override;
Evan Chengc47e1092009-07-27 03:14:20 +0000169
Craig Topper6bc27bf2014-03-10 02:09:33 +0000170 void storeRegToStackSlot(MachineBasicBlock &MBB,
171 MachineBasicBlock::iterator MBBI,
172 unsigned SrcReg, bool isKill, int FrameIndex,
173 const TargetRegisterClass *RC,
174 const TargetRegisterInfo *TRI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000175
Craig Topper6bc27bf2014-03-10 02:09:33 +0000176 void loadRegFromStackSlot(MachineBasicBlock &MBB,
177 MachineBasicBlock::iterator MBBI,
178 unsigned DestReg, int FrameIndex,
179 const TargetRegisterClass *RC,
180 const TargetRegisterInfo *TRI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000181
Craig Topper6bc27bf2014-03-10 02:09:33 +0000182 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Jakob Stoklund Olesenda7c0f82011-10-11 00:59:06 +0000183
Craig Topper6bc27bf2014-03-10 02:09:33 +0000184 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
185 unsigned DestReg, unsigned SubIdx,
186 const MachineInstr *Orig,
187 const TargetRegisterInfo &TRI) const override;
Evan Chengfe864422009-11-08 00:15:23 +0000188
Craig Topper6bc27bf2014-03-10 02:09:33 +0000189 MachineInstr *duplicate(MachineInstr *Orig,
190 MachineFunction &MF) const override;
Jakob Stoklund Olesen29a64c92010-01-06 23:47:07 +0000191
Craig Topper6bc27bf2014-03-10 02:09:33 +0000192 MachineInstr *commuteInstruction(MachineInstr*,
193 bool=false) const override;
Jakob Stoklund Olesen0a5b72f2012-04-04 18:23:42 +0000194
Tim Northover798697d2013-04-21 11:57:07 +0000195 const MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, unsigned Reg,
196 unsigned SubIdx, unsigned State,
197 const TargetRegisterInfo *TRI) const;
198
Craig Topper6bc27bf2014-03-10 02:09:33 +0000199 bool produceSameValue(const MachineInstr *MI0, const MachineInstr *MI1,
200 const MachineRegisterInfo *MRI) const override;
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000201
Bill Wendlingf4707472010-06-23 23:00:16 +0000202 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
203 /// determine if two loads are loading from the same base address. It should
204 /// only return true if the base pointers are the same and the only
205 /// differences between the two addresses is the offset. It also returns the
206 /// offsets by reference.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000207 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1,
208 int64_t &Offset2) const override;
Bill Wendlingf4707472010-06-23 23:00:16 +0000209
210 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000211 /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads
212 /// should be scheduled togther. On some targets if two loads are loading from
Bill Wendlingf4707472010-06-23 23:00:16 +0000213 /// addresses in the same cache line, it's better if they are scheduled
214 /// together. This function takes two integers that represent the load offsets
215 /// from the common base address. It returns true if it decides it's desirable
216 /// to schedule the two loads together. "NumLoads" is the number of loads that
217 /// have already been scheduled after Load1.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000218 bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
219 int64_t Offset1, int64_t Offset2,
220 unsigned NumLoads) const override;
Bill Wendlingf4707472010-06-23 23:00:16 +0000221
Craig Topper6bc27bf2014-03-10 02:09:33 +0000222 bool isSchedulingBoundary(const MachineInstr *MI,
223 const MachineBasicBlock *MBB,
224 const MachineFunction &MF) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000225
Craig Topper6bc27bf2014-03-10 02:09:33 +0000226 bool isProfitableToIfCvt(MachineBasicBlock &MBB,
227 unsigned NumCycles, unsigned ExtraPredCycles,
228 const BranchProbability &Probability) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000229
Craig Topper6bc27bf2014-03-10 02:09:33 +0000230 bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT,
231 unsigned ExtraT, MachineBasicBlock &FMBB,
232 unsigned NumF, unsigned ExtraF,
233 const BranchProbability &Probability) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000234
Craig Topper6bc27bf2014-03-10 02:09:33 +0000235 bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
236 const BranchProbability &Probability) const override {
Cameron Zwarich80018502011-04-13 06:39:16 +0000237 return NumCycles == 1;
Evan Cheng02b184d2010-06-25 22:42:03 +0000238 }
Bill Wendling7de9d522010-08-06 01:32:48 +0000239
Craig Topper6bc27bf2014-03-10 02:09:33 +0000240 bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
241 MachineBasicBlock &FMBB) const override;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000242
Manman Ren6fa76dc2012-06-29 21:33:59 +0000243 /// analyzeCompare - For a comparison instruction, return the source registers
244 /// in SrcReg and SrcReg2 if having two register operands, and the value it
245 /// compares against in CmpValue. Return true if the comparison instruction
246 /// can be analyzed.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000247 bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
248 unsigned &SrcReg2, int &CmpMask,
249 int &CmpValue) const override;
Bill Wendling7de9d522010-08-06 01:32:48 +0000250
Manman Ren6fa76dc2012-06-29 21:33:59 +0000251 /// optimizeCompareInstr - Convert the instruction to set the zero flag so
252 /// that we can remove a "comparison with zero"; Remove a redundant CMP
253 /// instruction if the flags can be updated in the same way by an earlier
254 /// instruction such as SUB.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000255 bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
256 unsigned SrcReg2, int CmpMask, int CmpValue,
257 const MachineRegisterInfo *MRI) const override;
Evan Cheng367a5df2010-09-09 18:18:55 +0000258
Craig Topper6bc27bf2014-03-10 02:09:33 +0000259 bool analyzeSelect(const MachineInstr *MI,
260 SmallVectorImpl<MachineOperand> &Cond,
261 unsigned &TrueOp, unsigned &FalseOp,
262 bool &Optimizable) const override;
Jakob Stoklund Olesenc19bf022012-08-16 23:14:20 +0000263
Craig Topper6bc27bf2014-03-10 02:09:33 +0000264 MachineInstr *optimizeSelect(MachineInstr *MI, bool) const override;
Jakob Stoklund Olesenc19bf022012-08-16 23:14:20 +0000265
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000266 /// FoldImmediate - 'Reg' is known to be defined by a move immediate
267 /// instruction, try to fold the immediate into the use instruction.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000268 bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
269 unsigned Reg, MachineRegisterInfo *MRI) const override;
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000270
Craig Topper6bc27bf2014-03-10 02:09:33 +0000271 unsigned getNumMicroOps(const InstrItineraryData *ItinData,
272 const MachineInstr *MI) const override;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000273
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000274 int getOperandLatency(const InstrItineraryData *ItinData,
275 const MachineInstr *DefMI, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000276 const MachineInstr *UseMI,
277 unsigned UseIdx) const override;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000278 int getOperandLatency(const InstrItineraryData *ItinData,
279 SDNode *DefNode, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000280 SDNode *UseNode, unsigned UseIdx) const override;
Jakob Stoklund Olesenf9b71a22011-09-27 22:57:21 +0000281
282 /// VFP/NEON execution domains.
283 std::pair<uint16_t, uint16_t>
Craig Topper6bc27bf2014-03-10 02:09:33 +0000284 getExecutionDomain(const MachineInstr *MI) const override;
285 void setExecutionDomain(MachineInstr *MI, unsigned Domain) const override;
Jakob Stoklund Olesenf9b71a22011-09-27 22:57:21 +0000286
Bob Wilsone8a549c2012-09-29 21:43:49 +0000287 unsigned getPartialRegUpdateClearance(const MachineInstr*, unsigned,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000288 const TargetRegisterInfo*) const override;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000289 void breakPartialRegDependency(MachineBasicBlock::iterator, unsigned,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000290 const TargetRegisterInfo *TRI) const override;
Tom Roeder44cb65f2014-06-05 19:29:43 +0000291
292 void
293 getUnconditionalBranch(MCInst &Branch,
294 const MCSymbolRefExpr *BranchTarget) const override;
295
296 void getTrap(MCInst &MI) const override;
297
Andrew Trick2ac6f7d2012-09-14 18:48:46 +0000298 /// Get the number of addresses by LDM or VLDM or zero for unknown.
299 unsigned getNumLDMAddresses(const MachineInstr *MI) const;
300
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000301private:
Evan Cheng7fae11b2011-12-14 02:11:42 +0000302 unsigned getInstBundleLength(const MachineInstr *MI) const;
303
Evan Cheng412e37b2010-10-07 23:12:15 +0000304 int getVLDMDefCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000305 const MCInstrDesc &DefMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000306 unsigned DefClass,
307 unsigned DefIdx, unsigned DefAlign) const;
308 int getLDMDefCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000309 const MCInstrDesc &DefMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000310 unsigned DefClass,
311 unsigned DefIdx, unsigned DefAlign) const;
312 int getVSTMUseCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000313 const MCInstrDesc &UseMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000314 unsigned UseClass,
315 unsigned UseIdx, unsigned UseAlign) const;
316 int getSTMUseCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000317 const MCInstrDesc &UseMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000318 unsigned UseClass,
319 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000320 int getOperandLatency(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000321 const MCInstrDesc &DefMCID,
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000322 unsigned DefIdx, unsigned DefAlign,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000323 const MCInstrDesc &UseMCID,
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000324 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng63c76082010-10-19 18:58:51 +0000325
Craig Topper6bc27bf2014-03-10 02:09:33 +0000326 unsigned getPredicationCost(const MachineInstr *MI) const override;
Arnold Schwaighoferd2f96b92013-09-30 15:28:56 +0000327
Andrew Trick45446062012-06-05 21:11:27 +0000328 unsigned getInstrLatency(const InstrItineraryData *ItinData,
329 const MachineInstr *MI,
Craig Toppere73658d2014-04-28 04:05:08 +0000330 unsigned *PredCost = nullptr) const override;
Evan Chengdebf9c52010-11-03 00:45:17 +0000331
332 int getInstrLatency(const InstrItineraryData *ItinData,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000333 SDNode *Node) const override;
Evan Chengdebf9c52010-11-03 00:45:17 +0000334
Evan Cheng63c76082010-10-19 18:58:51 +0000335 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
336 const MachineRegisterInfo *MRI,
337 const MachineInstr *DefMI, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000338 const MachineInstr *UseMI,
339 unsigned UseIdx) const override;
Evan Chenge96b8d72010-10-26 02:08:50 +0000340 bool hasLowDefLatency(const InstrItineraryData *ItinData,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000341 const MachineInstr *DefMI,
342 unsigned DefIdx) const override;
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000343
Andrew Trick924123a2011-09-21 02:20:46 +0000344 /// verifyInstruction - Perform target specific instruction verification.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000345 bool verifyInstruction(const MachineInstr *MI,
346 StringRef &ErrInfo) const override;
Andrew Trick924123a2011-09-21 02:20:46 +0000347
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000348 virtual void expandLoadStackGuard(MachineBasicBlock::iterator MI,
349 Reloc::Model RM) const = 0;
350
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000351private:
352 /// Modeling special VFP / NEON fp MLA / MLS hazards.
353
354 /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal
355 /// MLx table.
356 DenseMap<unsigned, unsigned> MLxEntryMap;
357
358 /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause
359 /// stalls when scheduled together with fp MLA / MLS opcodes.
360 SmallSet<unsigned, 16> MLxHazardOpcodes;
361
362public:
363 /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS
364 /// instruction.
365 bool isFpMLxInstruction(unsigned Opcode) const {
366 return MLxEntryMap.count(Opcode);
367 }
368
369 /// isFpMLxInstruction - This version also returns the multiply opcode and the
370 /// addition / subtraction opcode to expand to. Return true for 'HasLane' for
371 /// the MLX instructions with an extra lane operand.
372 bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc,
373 unsigned &AddSubOpc, bool &NegAcc,
374 bool &HasLane) const;
375
376 /// canCauseFpMLxStall - Return true if an instruction of the specified opcode
377 /// will cause stalls when scheduled after (within 4-cycle window) a fp
378 /// MLA / MLS instruction.
379 bool canCauseFpMLxStall(unsigned Opcode) const {
380 return MLxHazardOpcodes.count(Opcode);
381 }
Arnold Schwaighofer5dde1f32013-04-05 04:42:00 +0000382
383 /// Returns true if the instruction has a shift by immediate that can be
384 /// executed in one cycle less.
385 bool isSwiftFastImmShift(const MachineInstr *MI) const;
David Goodwinaf7451b2009-07-08 16:09:28 +0000386};
Evan Cheng780748d2009-07-28 05:48:47 +0000387
388static inline
389const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
390 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwinaf7451b2009-07-08 16:09:28 +0000391}
392
Evan Cheng780748d2009-07-28 05:48:47 +0000393static inline
394const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
395 return MIB.addReg(0);
396}
397
398static inline
Evan Cheng51cbd2d2009-08-10 02:37:24 +0000399const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
400 bool isDead = false) {
401 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng780748d2009-07-28 05:48:47 +0000402}
403
404static inline
Evan Cheng6ddd7bc2009-08-15 07:59:10 +0000405const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
406 return MIB.addReg(0);
407}
408
409static inline
Evan Cheng780748d2009-07-28 05:48:47 +0000410bool isUncondBranchOpcode(int Opc) {
411 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
412}
413
414static inline
415bool isCondBranchOpcode(int Opc) {
416 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
417}
418
419static inline
420bool isJumpTableBranchOpcode(int Opc) {
421 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
422 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
423}
424
Bob Wilson73789b82009-10-28 18:26:41 +0000425static inline
426bool isIndirectBranchOpcode(int Opc) {
Bill Wendling8294a302010-11-30 00:48:15 +0000427 return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson73789b82009-10-28 18:26:41 +0000428}
429
Tim Northover93bcc662013-11-08 17:18:07 +0000430static inline bool isPopOpcode(int Opc) {
431 return Opc == ARM::tPOP_RET || Opc == ARM::LDMIA_RET ||
432 Opc == ARM::t2LDMIA_RET || Opc == ARM::tPOP || Opc == ARM::LDMIA_UPD ||
433 Opc == ARM::t2LDMIA_UPD || Opc == ARM::VLDMDIA_UPD;
434}
435
436static inline bool isPushOpcode(int Opc) {
437 return Opc == ARM::tPUSH || Opc == ARM::t2STMDB_UPD ||
438 Opc == ARM::STMDB_UPD || Opc == ARM::VSTMDDB_UPD;
439}
440
Evan Cheng2aa91cc2009-08-08 03:20:32 +0000441/// getInstrPredicate - If instruction is predicated, returns its predicate
442/// condition, otherwise returns AL. It also returns the condition code
443/// register by reference.
Evan Cheng83e0d482009-09-28 09:14:39 +0000444ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
Evan Cheng2aa91cc2009-08-08 03:20:32 +0000445
Evan Cheng780748d2009-07-28 05:48:47 +0000446int getMatchingCondBranchOpcode(int Opc);
447
Jakob Stoklund Olesen6cb96122012-08-15 22:16:39 +0000448/// Determine if MI can be folded into an ARM MOVCC instruction, and return the
449/// opcode of the SSA instruction representing the conditional MI.
450unsigned canFoldARMInstrIntoMOVCC(unsigned Reg,
451 MachineInstr *&MI,
452 const MachineRegisterInfo &MRI);
Andrew Trick924123a2011-09-21 02:20:46 +0000453
454/// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether
455/// the instruction is encoded with an 'S' bit is determined by the optional
456/// CPSR def operand.
457unsigned convertAddSubFlagsOpcode(unsigned OldOpc);
458
Evan Cheng780748d2009-07-28 05:48:47 +0000459/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
460/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
461/// code.
462void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
463 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
464 unsigned DestReg, unsigned BaseReg, int NumBytes,
465 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000466 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Evan Cheng780748d2009-07-28 05:48:47 +0000467
468void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
469 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
470 unsigned DestReg, unsigned BaseReg, int NumBytes,
471 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000472 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Jim Grosbachbbdc5d22010-10-19 23:27:08 +0000473void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000474 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
Jim Grosbachbbdc5d22010-10-19 23:27:08 +0000475 unsigned DestReg, unsigned BaseReg,
476 int NumBytes, const TargetInstrInfo &TII,
477 const ARMBaseRegisterInfo& MRI,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000478 unsigned MIFlags = 0);
Evan Cheng780748d2009-07-28 05:48:47 +0000479
Tim Northover93bcc662013-11-08 17:18:07 +0000480/// Tries to add registers to the reglist of a given base-updating
481/// push/pop instruction to adjust the stack by an additional
482/// NumBytes. This can save a few bytes per function in code-size, but
483/// obviously generates more memory traffic. As such, it only takes
484/// effect in functions being optimised for size.
Tim Northoverdee86042013-12-02 14:46:26 +0000485bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget,
486 MachineFunction &MF, MachineInstr *MI,
Tim Northover93bcc662013-11-08 17:18:07 +0000487 unsigned NumBytes);
Evan Cheng780748d2009-07-28 05:48:47 +0000488
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000489/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Cheng7a37b1a2009-08-27 01:23:50 +0000490/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
491/// offset could not be handled directly in MI, and return the left-over
492/// portion by reference.
493bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
494 unsigned FrameReg, int &Offset,
495 const ARMBaseInstrInfo &TII);
Evan Cheng780748d2009-07-28 05:48:47 +0000496
Evan Cheng7a37b1a2009-08-27 01:23:50 +0000497bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
498 unsigned FrameReg, int &Offset,
499 const ARMBaseInstrInfo &TII);
Evan Cheng780748d2009-07-28 05:48:47 +0000500
501} // End llvm namespace
502
David Goodwinaf7451b2009-07-08 16:09:28 +0000503#endif