blob: 0ae4773a96e2011b1d0b37d5bd71134e40be9459 [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
Andrew Kaylor16c4da02015-09-28 20:33:22 +000089 /// Commutes the operands in the given instruction.
90 /// The commutable operands are specified by their indices OpIdx1 and OpIdx2.
91 ///
92 /// Do not call this method for a non-commutable instruction or for
93 /// non-commutable pair of operand indices OpIdx1 and OpIdx2.
94 /// Even though the instruction is commutable, the method may still
95 /// fail to commute the operands, null pointer is returned in such cases.
96 MachineInstr *commuteInstructionImpl(MachineInstr *MI,
97 bool NewMI,
98 unsigned OpIdx1,
99 unsigned OpIdx2) const override;
100
David Goodwinaf7451b2009-07-08 16:09:28 +0000101public:
Jim Grosbach617f84dd2012-02-28 23:53:30 +0000102 // Return whether the target has an explicit NOP encoding.
103 bool hasNOP() const;
104
David Goodwinaf7451b2009-07-08 16:09:28 +0000105 // Return the non-pre/post incrementing version of 'Opc'. Return 0
106 // if there is not such an opcode.
107 virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
108
Craig Topper6bc27bf2014-03-10 02:09:33 +0000109 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
110 MachineBasicBlock::iterator &MBBI,
111 LiveVariables *LV) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000112
Bill Wendlingf95178e2013-06-07 05:54:19 +0000113 virtual const ARMBaseRegisterInfo &getRegisterInfo() const = 0;
Anton Korobeynikov14635da2009-11-02 00:10:38 +0000114 const ARMSubtarget &getSubtarget() const { return Subtarget; }
David Goodwinaf7451b2009-07-08 16:09:28 +0000115
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000116 ScheduleHazardRecognizer *
Eric Christopherf047bfd2014-06-13 22:38:52 +0000117 CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000118 const ScheduleDAG *DAG) const override;
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000119
120 ScheduleHazardRecognizer *
121 CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000122 const ScheduleDAG *DAG) const override;
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000123
David Goodwinaf7451b2009-07-08 16:09:28 +0000124 // Branch analysis.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000125 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
126 MachineBasicBlock *&FBB,
127 SmallVectorImpl<MachineOperand> &Cond,
128 bool AllowModify = false) const override;
129 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
130 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000131 MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000132 DebugLoc DL) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000133
Craig Topper6bc27bf2014-03-10 02:09:33 +0000134 bool
135 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000136
137 // Predication support.
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000138 bool isPredicated(const MachineInstr &MI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000139
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000140 ARMCC::CondCodes getPredicate(const MachineInstr &MI) const {
141 int PIdx = MI.findFirstPredOperandIdx();
142 return PIdx != -1 ? (ARMCC::CondCodes)MI.getOperand(PIdx).getImm()
David Goodwinaf7451b2009-07-08 16:09:28 +0000143 : ARMCC::AL;
144 }
145
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000146 bool PredicateInstruction(MachineInstr &MI,
147 ArrayRef<MachineOperand> Pred) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000148
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000149 bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
150 ArrayRef<MachineOperand> Pred2) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000151
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000152 bool DefinesPredicate(MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000153 std::vector<MachineOperand> &Pred) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000154
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000155 bool isPredicable(MachineInstr &MI) const override;
Evan Chenga33fc862009-11-21 06:21:52 +0000156
David Goodwinaf7451b2009-07-08 16:09:28 +0000157 /// GetInstSize - Returns the size of the specified MachineInstr.
158 ///
159 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
160
Craig Topper6bc27bf2014-03-10 02:09:33 +0000161 unsigned isLoadFromStackSlot(const MachineInstr *MI,
162 int &FrameIndex) const override;
163 unsigned isStoreToStackSlot(const MachineInstr *MI,
164 int &FrameIndex) const override;
165 unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
166 int &FrameIndex) const override;
167 unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
168 int &FrameIndex) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000169
Tim Northover5d72c5d2014-10-01 19:21:03 +0000170 void copyToCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
171 unsigned SrcReg, bool KillSrc,
172 const ARMSubtarget &Subtarget) const;
173 void copyFromCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
174 unsigned DestReg, bool KillSrc,
175 const ARMSubtarget &Subtarget) const;
176
Craig Topper6bc27bf2014-03-10 02:09:33 +0000177 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
178 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
179 bool KillSrc) const override;
Evan Chengc47e1092009-07-27 03:14:20 +0000180
Craig Topper6bc27bf2014-03-10 02:09:33 +0000181 void storeRegToStackSlot(MachineBasicBlock &MBB,
182 MachineBasicBlock::iterator MBBI,
183 unsigned SrcReg, bool isKill, int FrameIndex,
184 const TargetRegisterClass *RC,
185 const TargetRegisterInfo *TRI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000186
Craig Topper6bc27bf2014-03-10 02:09:33 +0000187 void loadRegFromStackSlot(MachineBasicBlock &MBB,
188 MachineBasicBlock::iterator MBBI,
189 unsigned DestReg, int FrameIndex,
190 const TargetRegisterClass *RC,
191 const TargetRegisterInfo *TRI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000192
Craig Topper6bc27bf2014-03-10 02:09:33 +0000193 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Jakob Stoklund Olesenda7c0f82011-10-11 00:59:06 +0000194
Craig Topper6bc27bf2014-03-10 02:09:33 +0000195 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
196 unsigned DestReg, unsigned SubIdx,
197 const MachineInstr *Orig,
198 const TargetRegisterInfo &TRI) const override;
Evan Chengfe864422009-11-08 00:15:23 +0000199
Craig Topper6bc27bf2014-03-10 02:09:33 +0000200 MachineInstr *duplicate(MachineInstr *Orig,
201 MachineFunction &MF) const override;
Jakob Stoklund Olesen29a64c92010-01-06 23:47:07 +0000202
Tim Northover798697d2013-04-21 11:57:07 +0000203 const MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, unsigned Reg,
204 unsigned SubIdx, unsigned State,
205 const TargetRegisterInfo *TRI) const;
206
Craig Topper6bc27bf2014-03-10 02:09:33 +0000207 bool produceSameValue(const MachineInstr *MI0, const MachineInstr *MI1,
208 const MachineRegisterInfo *MRI) const override;
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000209
Bill Wendlingf4707472010-06-23 23:00:16 +0000210 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
211 /// determine if two loads are loading from the same base address. It should
212 /// only return true if the base pointers are the same and the only
213 /// differences between the two addresses is the offset. It also returns the
214 /// offsets by reference.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000215 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1,
216 int64_t &Offset2) const override;
Bill Wendlingf4707472010-06-23 23:00:16 +0000217
218 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000219 /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads
220 /// should be scheduled togther. On some targets if two loads are loading from
Bill Wendlingf4707472010-06-23 23:00:16 +0000221 /// addresses in the same cache line, it's better if they are scheduled
222 /// together. This function takes two integers that represent the load offsets
223 /// from the common base address. It returns true if it decides it's desirable
224 /// to schedule the two loads together. "NumLoads" is the number of loads that
225 /// have already been scheduled after Load1.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000226 bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
227 int64_t Offset1, int64_t Offset2,
228 unsigned NumLoads) const override;
Bill Wendlingf4707472010-06-23 23:00:16 +0000229
Craig Topper6bc27bf2014-03-10 02:09:33 +0000230 bool isSchedulingBoundary(const MachineInstr *MI,
231 const MachineBasicBlock *MBB,
232 const MachineFunction &MF) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000233
Craig Topper6bc27bf2014-03-10 02:09:33 +0000234 bool isProfitableToIfCvt(MachineBasicBlock &MBB,
235 unsigned NumCycles, unsigned ExtraPredCycles,
Cong Houc536bd92015-09-10 23:10:42 +0000236 BranchProbability Probability) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000237
Craig Topper6bc27bf2014-03-10 02:09:33 +0000238 bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT,
239 unsigned ExtraT, MachineBasicBlock &FMBB,
240 unsigned NumF, unsigned ExtraF,
Cong Houc536bd92015-09-10 23:10:42 +0000241 BranchProbability Probability) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000242
Craig Topper6bc27bf2014-03-10 02:09:33 +0000243 bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
Cong Houc536bd92015-09-10 23:10:42 +0000244 BranchProbability Probability) const override {
Cameron Zwarich80018502011-04-13 06:39:16 +0000245 return NumCycles == 1;
Evan Cheng02b184d2010-06-25 22:42:03 +0000246 }
Bill Wendling7de9d522010-08-06 01:32:48 +0000247
Craig Topper6bc27bf2014-03-10 02:09:33 +0000248 bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
249 MachineBasicBlock &FMBB) const override;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000250
Manman Ren6fa76dc2012-06-29 21:33:59 +0000251 /// analyzeCompare - For a comparison instruction, return the source registers
252 /// in SrcReg and SrcReg2 if having two register operands, and the value it
253 /// compares against in CmpValue. Return true if the comparison instruction
254 /// can be analyzed.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000255 bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
256 unsigned &SrcReg2, int &CmpMask,
257 int &CmpValue) const override;
Bill Wendling7de9d522010-08-06 01:32:48 +0000258
Manman Ren6fa76dc2012-06-29 21:33:59 +0000259 /// optimizeCompareInstr - Convert the instruction to set the zero flag so
260 /// that we can remove a "comparison with zero"; Remove a redundant CMP
261 /// instruction if the flags can be updated in the same way by an earlier
262 /// instruction such as SUB.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000263 bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
264 unsigned SrcReg2, int CmpMask, int CmpValue,
265 const MachineRegisterInfo *MRI) const override;
Evan Cheng367a5df2010-09-09 18:18:55 +0000266
Craig Topper6bc27bf2014-03-10 02:09:33 +0000267 bool analyzeSelect(const MachineInstr *MI,
268 SmallVectorImpl<MachineOperand> &Cond,
269 unsigned &TrueOp, unsigned &FalseOp,
270 bool &Optimizable) const override;
Jakob Stoklund Olesenc19bf022012-08-16 23:14:20 +0000271
Mehdi Amini22e59742015-01-13 07:07:13 +0000272 MachineInstr *optimizeSelect(MachineInstr *MI,
273 SmallPtrSetImpl<MachineInstr *> &SeenMIs,
274 bool) const override;
Jakob Stoklund Olesenc19bf022012-08-16 23:14:20 +0000275
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000276 /// FoldImmediate - 'Reg' is known to be defined by a move immediate
277 /// instruction, try to fold the immediate into the use instruction.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000278 bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
279 unsigned Reg, MachineRegisterInfo *MRI) const override;
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000280
Craig Topper6bc27bf2014-03-10 02:09:33 +0000281 unsigned getNumMicroOps(const InstrItineraryData *ItinData,
282 const MachineInstr *MI) const override;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000283
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000284 int getOperandLatency(const InstrItineraryData *ItinData,
285 const MachineInstr *DefMI, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000286 const MachineInstr *UseMI,
287 unsigned UseIdx) const override;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000288 int getOperandLatency(const InstrItineraryData *ItinData,
289 SDNode *DefNode, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000290 SDNode *UseNode, unsigned UseIdx) const override;
Jakob Stoklund Olesenf9b71a22011-09-27 22:57:21 +0000291
292 /// VFP/NEON execution domains.
293 std::pair<uint16_t, uint16_t>
Craig Topper6bc27bf2014-03-10 02:09:33 +0000294 getExecutionDomain(const MachineInstr *MI) const override;
295 void setExecutionDomain(MachineInstr *MI, unsigned Domain) const override;
Jakob Stoklund Olesenf9b71a22011-09-27 22:57:21 +0000296
Bob Wilsone8a549c2012-09-29 21:43:49 +0000297 unsigned getPartialRegUpdateClearance(const MachineInstr*, unsigned,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000298 const TargetRegisterInfo*) const override;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000299 void breakPartialRegDependency(MachineBasicBlock::iterator, unsigned,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000300 const TargetRegisterInfo *TRI) const override;
Tom Roeder44cb65f2014-06-05 19:29:43 +0000301
Andrew Trick2ac6f7d2012-09-14 18:48:46 +0000302 /// Get the number of addresses by LDM or VLDM or zero for unknown.
303 unsigned getNumLDMAddresses(const MachineInstr *MI) const;
304
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000305private:
Evan Cheng7fae11b2011-12-14 02:11:42 +0000306 unsigned getInstBundleLength(const MachineInstr *MI) const;
307
Evan Cheng412e37b2010-10-07 23:12:15 +0000308 int getVLDMDefCycle(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 getLDMDefCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000313 const MCInstrDesc &DefMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000314 unsigned DefClass,
315 unsigned DefIdx, unsigned DefAlign) const;
316 int getVSTMUseCycle(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;
320 int getSTMUseCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000321 const MCInstrDesc &UseMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000322 unsigned UseClass,
323 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000324 int getOperandLatency(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000325 const MCInstrDesc &DefMCID,
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000326 unsigned DefIdx, unsigned DefAlign,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000327 const MCInstrDesc &UseMCID,
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000328 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng63c76082010-10-19 18:58:51 +0000329
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000330 unsigned getPredicationCost(const MachineInstr &MI) const override;
Arnold Schwaighoferd2f96b92013-09-30 15:28:56 +0000331
Andrew Trick45446062012-06-05 21:11:27 +0000332 unsigned getInstrLatency(const InstrItineraryData *ItinData,
333 const MachineInstr *MI,
Craig Toppere73658d2014-04-28 04:05:08 +0000334 unsigned *PredCost = nullptr) const override;
Evan Chengdebf9c52010-11-03 00:45:17 +0000335
336 int getInstrLatency(const InstrItineraryData *ItinData,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000337 SDNode *Node) const override;
Evan Chengdebf9c52010-11-03 00:45:17 +0000338
Matthias Braun88e21312015-06-13 03:42:11 +0000339 bool hasHighOperandLatency(const TargetSchedModel &SchedModel,
Evan Cheng63c76082010-10-19 18:58:51 +0000340 const MachineRegisterInfo *MRI,
341 const MachineInstr *DefMI, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000342 const MachineInstr *UseMI,
343 unsigned UseIdx) const override;
Matthias Braun88e21312015-06-13 03:42:11 +0000344 bool hasLowDefLatency(const TargetSchedModel &SchedModel,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000345 const MachineInstr *DefMI,
346 unsigned DefIdx) const override;
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000347
Andrew Trick924123a2011-09-21 02:20:46 +0000348 /// verifyInstruction - Perform target specific instruction verification.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000349 bool verifyInstruction(const MachineInstr *MI,
350 StringRef &ErrInfo) const override;
Andrew Trick924123a2011-09-21 02:20:46 +0000351
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000352 virtual void expandLoadStackGuard(MachineBasicBlock::iterator MI,
353 Reloc::Model RM) const = 0;
354
Scott Douglass953f9082015-10-05 14:49:54 +0000355 void expandMEMCPY(MachineBasicBlock::iterator) const;
356
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000357private:
358 /// Modeling special VFP / NEON fp MLA / MLS hazards.
359
360 /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal
361 /// MLx table.
362 DenseMap<unsigned, unsigned> MLxEntryMap;
363
364 /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause
365 /// stalls when scheduled together with fp MLA / MLS opcodes.
366 SmallSet<unsigned, 16> MLxHazardOpcodes;
367
368public:
369 /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS
370 /// instruction.
371 bool isFpMLxInstruction(unsigned Opcode) const {
372 return MLxEntryMap.count(Opcode);
373 }
374
375 /// isFpMLxInstruction - This version also returns the multiply opcode and the
376 /// addition / subtraction opcode to expand to. Return true for 'HasLane' for
377 /// the MLX instructions with an extra lane operand.
378 bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc,
379 unsigned &AddSubOpc, bool &NegAcc,
380 bool &HasLane) const;
381
382 /// canCauseFpMLxStall - Return true if an instruction of the specified opcode
383 /// will cause stalls when scheduled after (within 4-cycle window) a fp
384 /// MLA / MLS instruction.
385 bool canCauseFpMLxStall(unsigned Opcode) const {
386 return MLxHazardOpcodes.count(Opcode);
387 }
Arnold Schwaighofer5dde1f32013-04-05 04:42:00 +0000388
389 /// Returns true if the instruction has a shift by immediate that can be
390 /// executed in one cycle less.
391 bool isSwiftFastImmShift(const MachineInstr *MI) const;
David Goodwinaf7451b2009-07-08 16:09:28 +0000392};
Evan Cheng780748d2009-07-28 05:48:47 +0000393
394static inline
395const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
396 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
David Goodwinaf7451b2009-07-08 16:09:28 +0000397}
398
Evan Cheng780748d2009-07-28 05:48:47 +0000399static inline
400const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
401 return MIB.addReg(0);
402}
403
404static inline
Evan Cheng51cbd2d2009-08-10 02:37:24 +0000405const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
406 bool isDead = false) {
407 return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
Evan Cheng780748d2009-07-28 05:48:47 +0000408}
409
410static inline
Evan Cheng6ddd7bc2009-08-15 07:59:10 +0000411const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
412 return MIB.addReg(0);
413}
414
415static inline
Evan Cheng780748d2009-07-28 05:48:47 +0000416bool isUncondBranchOpcode(int Opc) {
417 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
418}
419
420static inline
421bool isCondBranchOpcode(int Opc) {
422 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
423}
424
425static inline
426bool isJumpTableBranchOpcode(int Opc) {
427 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
428 Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
429}
430
Bob Wilson73789b82009-10-28 18:26:41 +0000431static inline
432bool isIndirectBranchOpcode(int Opc) {
Bill Wendling8294a302010-11-30 00:48:15 +0000433 return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson73789b82009-10-28 18:26:41 +0000434}
435
Tim Northover93bcc662013-11-08 17:18:07 +0000436static inline bool isPopOpcode(int Opc) {
437 return Opc == ARM::tPOP_RET || Opc == ARM::LDMIA_RET ||
438 Opc == ARM::t2LDMIA_RET || Opc == ARM::tPOP || Opc == ARM::LDMIA_UPD ||
439 Opc == ARM::t2LDMIA_UPD || Opc == ARM::VLDMDIA_UPD;
440}
441
442static inline bool isPushOpcode(int Opc) {
443 return Opc == ARM::tPUSH || Opc == ARM::t2STMDB_UPD ||
444 Opc == ARM::STMDB_UPD || Opc == ARM::VSTMDDB_UPD;
445}
446
Evan Cheng2aa91cc2009-08-08 03:20:32 +0000447/// getInstrPredicate - If instruction is predicated, returns its predicate
448/// condition, otherwise returns AL. It also returns the condition code
449/// register by reference.
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000450ARMCC::CondCodes getInstrPredicate(const MachineInstr &MI, unsigned &PredReg);
Evan Cheng2aa91cc2009-08-08 03:20:32 +0000451
Matthias Braunfa3872e2015-05-18 20:27:55 +0000452unsigned getMatchingCondBranchOpcode(unsigned Opc);
Evan Cheng780748d2009-07-28 05:48:47 +0000453
Jakob Stoklund Olesen6cb96122012-08-15 22:16:39 +0000454/// Determine if MI can be folded into an ARM MOVCC instruction, and return the
455/// opcode of the SSA instruction representing the conditional MI.
456unsigned canFoldARMInstrIntoMOVCC(unsigned Reg,
457 MachineInstr *&MI,
458 const MachineRegisterInfo &MRI);
Andrew Trick924123a2011-09-21 02:20:46 +0000459
460/// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether
461/// the instruction is encoded with an 'S' bit is determined by the optional
462/// CPSR def operand.
463unsigned convertAddSubFlagsOpcode(unsigned OldOpc);
464
Evan Cheng780748d2009-07-28 05:48:47 +0000465/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
466/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
467/// code.
468void emitARMRegPlusImmediate(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);
Evan Cheng780748d2009-07-28 05:48:47 +0000473
474void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
475 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
476 unsigned DestReg, unsigned BaseReg, int NumBytes,
477 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000478 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Jim Grosbachbbdc5d22010-10-19 23:27:08 +0000479void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000480 MachineBasicBlock::iterator &MBBI, DebugLoc dl,
Jim Grosbachbbdc5d22010-10-19 23:27:08 +0000481 unsigned DestReg, unsigned BaseReg,
482 int NumBytes, const TargetInstrInfo &TII,
483 const ARMBaseRegisterInfo& MRI,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000484 unsigned MIFlags = 0);
Evan Cheng780748d2009-07-28 05:48:47 +0000485
Tim Northover93bcc662013-11-08 17:18:07 +0000486/// Tries to add registers to the reglist of a given base-updating
487/// push/pop instruction to adjust the stack by an additional
488/// NumBytes. This can save a few bytes per function in code-size, but
489/// obviously generates more memory traffic. As such, it only takes
490/// effect in functions being optimised for size.
Tim Northoverdee86042013-12-02 14:46:26 +0000491bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget,
492 MachineFunction &MF, MachineInstr *MI,
Tim Northover93bcc662013-11-08 17:18:07 +0000493 unsigned NumBytes);
Evan Cheng780748d2009-07-28 05:48:47 +0000494
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000495/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Cheng7a37b1a2009-08-27 01:23:50 +0000496/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
497/// offset could not be handled directly in MI, and return the left-over
498/// portion by reference.
499bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
500 unsigned FrameReg, int &Offset,
501 const ARMBaseInstrInfo &TII);
Evan Cheng780748d2009-07-28 05:48:47 +0000502
Evan Cheng7a37b1a2009-08-27 01:23:50 +0000503bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
504 unsigned FrameReg, int &Offset,
505 const ARMBaseInstrInfo &TII);
Evan Cheng780748d2009-07-28 05:48:47 +0000506
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000507} // End llvm namespace
Evan Cheng780748d2009-07-28 05:48:47 +0000508
David Goodwinaf7451b2009-07-08 16:09:28 +0000509#endif