blob: de1f307083babc538e079d89f599850d6c58092f [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"
Eugene Zelenko342257e2017-01-31 00:56:17 +000020#include "llvm/CodeGen/MachineBasicBlock.h"
21#include "llvm/CodeGen/MachineInstr.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000022#include "llvm/CodeGen/MachineInstrBuilder.h"
Eugene Zelenko342257e2017-01-31 00:56:17 +000023#include "llvm/CodeGen/MachineOperand.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000024#include "llvm/CodeGen/TargetInstrInfo.h"
Eugene Zelenko342257e2017-01-31 00:56:17 +000025#include <array>
26#include <cstdint>
David Goodwinaf7451b2009-07-08 16:09:28 +000027
Evan Cheng703a0fb2011-07-01 17:57:27 +000028#define GET_INSTRINFO_HEADER
29#include "ARMGenInstrInfo.inc"
30
David Goodwinaf7451b2009-07-08 16:09:28 +000031namespace llvm {
Eugene Zelenko342257e2017-01-31 00:56:17 +000032
33class ARMBaseRegisterInfo;
34class ARMSubtarget;
David Goodwinaf7451b2009-07-08 16:09:28 +000035
Evan Cheng703a0fb2011-07-01 17:57:27 +000036class ARMBaseInstrInfo : public ARMGenInstrInfo {
Chris Lattnercbe98562010-07-20 21:17:29 +000037 const ARMSubtarget &Subtarget;
Evan Cheng62c7b5b2010-12-05 22:04:16 +000038
David Goodwinaf7451b2009-07-08 16:09:28 +000039protected:
40 // Can be only subclassed.
Anton Korobeynikov14635da2009-11-02 00:10:38 +000041 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
Evan Cheng62c7b5b2010-12-05 22:04:16 +000042
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +000043 void expandLoadStackGuardBase(MachineBasicBlock::iterator MI,
Rafael Espindola82f46312016-06-28 15:18:26 +000044 unsigned LoadImmOpc, unsigned LoadOpc) const;
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +000045
Quentin Colombetd358e842014-08-22 18:05:22 +000046 /// Build the equivalent inputs of a REG_SEQUENCE for the given \p MI
47 /// and \p DefIdx.
48 /// \p [out] InputRegs of the equivalent REG_SEQUENCE. Each element of
49 /// the list is modeled as <Reg:SubReg, SubIdx>.
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +000050 /// E.g., REG_SEQUENCE %1:sub1, sub0, %2, sub1 would produce
Quentin Colombetd358e842014-08-22 18:05:22 +000051 /// two elements:
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +000052 /// - %1:sub1, sub0
53 /// - %2<:0>, sub1
Quentin Colombetd358e842014-08-22 18:05:22 +000054 ///
55 /// \returns true if it is possible to build such an input sequence
56 /// with the pair \p MI, \p DefIdx. False otherwise.
57 ///
58 /// \pre MI.isRegSequenceLike().
59 bool getRegSequenceLikeInputs(
60 const MachineInstr &MI, unsigned DefIdx,
61 SmallVectorImpl<RegSubRegPairAndIdx> &InputRegs) const override;
62
63 /// Build the equivalent inputs of a EXTRACT_SUBREG for the given \p MI
64 /// and \p DefIdx.
65 /// \p [out] InputReg of the equivalent EXTRACT_SUBREG.
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +000066 /// E.g., EXTRACT_SUBREG %1:sub1, sub0, sub1 would produce:
67 /// - %1:sub1, sub0
Quentin Colombetd358e842014-08-22 18:05:22 +000068 ///
69 /// \returns true if it is possible to build such an input sequence
70 /// with the pair \p MI, \p DefIdx. False otherwise.
71 ///
72 /// \pre MI.isExtractSubregLike().
73 bool getExtractSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx,
74 RegSubRegPairAndIdx &InputReg) const override;
75
76 /// Build the equivalent inputs of a INSERT_SUBREG for the given \p MI
77 /// and \p DefIdx.
78 /// \p [out] BaseReg and \p [out] InsertedReg contain
79 /// the equivalent inputs of INSERT_SUBREG.
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +000080 /// E.g., INSERT_SUBREG %0:sub0, %1:sub1, sub3 would produce:
81 /// - BaseReg: %0:sub0
82 /// - InsertedReg: %1:sub1, sub3
Quentin Colombetd358e842014-08-22 18:05:22 +000083 ///
84 /// \returns true if it is possible to build such an input sequence
85 /// with the pair \p MI, \p DefIdx. False otherwise.
86 ///
87 /// \pre MI.isInsertSubregLike().
88 bool
89 getInsertSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx,
90 RegSubRegPair &BaseReg,
91 RegSubRegPairAndIdx &InsertedReg) const override;
92
Andrew Kaylor16c4da02015-09-28 20:33:22 +000093 /// Commutes the operands in the given instruction.
94 /// The commutable operands are specified by their indices OpIdx1 and OpIdx2.
95 ///
96 /// Do not call this method for a non-commutable instruction or for
97 /// non-commutable pair of operand indices OpIdx1 and OpIdx2.
98 /// Even though the instruction is commutable, the method may still
99 /// fail to commute the operands, null pointer is returned in such cases.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000100 MachineInstr *commuteInstructionImpl(MachineInstr &MI, bool NewMI,
Andrew Kaylor16c4da02015-09-28 20:33:22 +0000101 unsigned OpIdx1,
102 unsigned OpIdx2) const override;
103
Alexander Ivchenkoaf961122018-08-30 14:32:47 +0000104 /// If the specific machine instruction is a instruction that moves/copies
105 /// value from one register to another register return true along with
106 /// @Source machine operand and @Destination machine operand.
107 bool isCopyInstrImpl(const MachineInstr &MI, const MachineOperand *&Source,
108 const MachineOperand *&Destination) const override;
109
David Goodwinaf7451b2009-07-08 16:09:28 +0000110public:
Jim Grosbach617f84dd2012-02-28 23:53:30 +0000111 // Return whether the target has an explicit NOP encoding.
112 bool hasNOP() const;
113
David Goodwinaf7451b2009-07-08 16:09:28 +0000114 // Return the non-pre/post incrementing version of 'Opc'. Return 0
115 // if there is not such an opcode.
Eugene Zelenko342257e2017-01-31 00:56:17 +0000116 virtual unsigned getUnindexedOpcode(unsigned Opc) const = 0;
David Goodwinaf7451b2009-07-08 16:09:28 +0000117
Craig Topper6bc27bf2014-03-10 02:09:33 +0000118 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000119 MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000120 LiveVariables *LV) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000121
Bill Wendlingf95178e2013-06-07 05:54:19 +0000122 virtual const ARMBaseRegisterInfo &getRegisterInfo() const = 0;
Anton Korobeynikov14635da2009-11-02 00:10:38 +0000123 const ARMSubtarget &getSubtarget() const { return Subtarget; }
David Goodwinaf7451b2009-07-08 16:09:28 +0000124
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000125 ScheduleHazardRecognizer *
Eric Christopherf047bfd2014-06-13 22:38:52 +0000126 CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000127 const ScheduleDAG *DAG) const override;
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000128
129 ScheduleHazardRecognizer *
130 CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000131 const ScheduleDAG *DAG) const override;
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000132
David Goodwinaf7451b2009-07-08 16:09:28 +0000133 // Branch analysis.
Jacques Pienaar71c30a12016-07-15 14:41:04 +0000134 bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000135 MachineBasicBlock *&FBB,
136 SmallVectorImpl<MachineOperand> &Cond,
137 bool AllowModify = false) const override;
Matt Arsenault1b9fc8e2016-09-14 20:43:16 +0000138 unsigned removeBranch(MachineBasicBlock &MBB,
Matt Arsenaulta2b036e2016-09-14 17:23:48 +0000139 int *BytesRemoved = nullptr) const override;
Matt Arsenaulte8e0f5c2016-09-14 17:24:15 +0000140 unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000141 MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond,
Matt Arsenaulta2b036e2016-09-14 17:23:48 +0000142 const DebugLoc &DL,
143 int *BytesAdded = nullptr) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000144
Craig Topper6bc27bf2014-03-10 02:09:33 +0000145 bool
Matt Arsenault1b9fc8e2016-09-14 20:43:16 +0000146 reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000147
148 // Predication support.
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000149 bool isPredicated(const MachineInstr &MI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000150
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000151 ARMCC::CondCodes getPredicate(const MachineInstr &MI) const {
152 int PIdx = MI.findFirstPredOperandIdx();
153 return PIdx != -1 ? (ARMCC::CondCodes)MI.getOperand(PIdx).getImm()
David Goodwinaf7451b2009-07-08 16:09:28 +0000154 : ARMCC::AL;
155 }
156
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000157 bool PredicateInstruction(MachineInstr &MI,
158 ArrayRef<MachineOperand> Pred) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000159
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000160 bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
161 ArrayRef<MachineOperand> Pred2) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000162
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000163 bool DefinesPredicate(MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000164 std::vector<MachineOperand> &Pred) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000165
Krzysztof Parzyszekcc318712017-03-03 18:30:54 +0000166 bool isPredicable(const MachineInstr &MI) const override;
Evan Chenga33fc862009-11-21 06:21:52 +0000167
Javed Absar4ae7e8122017-06-02 08:53:19 +0000168 // CPSR defined in instruction
169 static bool isCPSRDefined(const MachineInstr &MI);
170 bool isAddrMode3OpImm(const MachineInstr &MI, unsigned Op) const;
171 bool isAddrMode3OpMinusReg(const MachineInstr &MI, unsigned Op) const;
172
173 // Load, scaled register offset
174 bool isLdstScaledReg(const MachineInstr &MI, unsigned Op) const;
175 // Load, scaled register offset, not plus LSL2
176 bool isLdstScaledRegNotPlusLsl2(const MachineInstr &MI, unsigned Op) const;
177 // Minus reg for ldstso addr mode
178 bool isLdstSoMinusReg(const MachineInstr &MI, unsigned Op) const;
179 // Scaled register offset in address mode 2
180 bool isAm2ScaledReg(const MachineInstr &MI, unsigned Op) const;
181 // Load multiple, base reg in list
182 bool isLDMBaseRegInList(const MachineInstr &MI) const;
183 // get LDM variable defs size
184 unsigned getLDMVariableDefsSize(const MachineInstr &MI) const;
185
David Goodwinaf7451b2009-07-08 16:09:28 +0000186 /// GetInstSize - Returns the size of the specified MachineInstr.
187 ///
Sjoerd Meijera3de1262016-07-29 09:57:37 +0000188 unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000189
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000190 unsigned isLoadFromStackSlot(const MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000191 int &FrameIndex) const override;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000192 unsigned isStoreToStackSlot(const MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000193 int &FrameIndex) const override;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000194 unsigned isLoadFromStackSlotPostFE(const MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000195 int &FrameIndex) const override;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000196 unsigned isStoreToStackSlotPostFE(const MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000197 int &FrameIndex) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000198
Tim Northover5d72c5d2014-10-01 19:21:03 +0000199 void copyToCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
200 unsigned SrcReg, bool KillSrc,
201 const ARMSubtarget &Subtarget) const;
202 void copyFromCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
203 unsigned DestReg, bool KillSrc,
204 const ARMSubtarget &Subtarget) const;
205
Craig Topper6bc27bf2014-03-10 02:09:33 +0000206 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000207 const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000208 bool KillSrc) const override;
Evan Chengc47e1092009-07-27 03:14:20 +0000209
Craig Topper6bc27bf2014-03-10 02:09:33 +0000210 void storeRegToStackSlot(MachineBasicBlock &MBB,
211 MachineBasicBlock::iterator MBBI,
212 unsigned SrcReg, bool isKill, int FrameIndex,
213 const TargetRegisterClass *RC,
214 const TargetRegisterInfo *TRI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000215
Craig Topper6bc27bf2014-03-10 02:09:33 +0000216 void loadRegFromStackSlot(MachineBasicBlock &MBB,
217 MachineBasicBlock::iterator MBBI,
218 unsigned DestReg, int FrameIndex,
219 const TargetRegisterClass *RC,
220 const TargetRegisterInfo *TRI) const override;
David Goodwinaf7451b2009-07-08 16:09:28 +0000221
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000222 bool expandPostRAPseudo(MachineInstr &MI) const override;
Jakob Stoklund Olesenda7c0f82011-10-11 00:59:06 +0000223
Joel Galensonfe7fa402018-01-17 19:19:05 +0000224 bool shouldSink(const MachineInstr &MI) const override;
225
Craig Topper6bc27bf2014-03-10 02:09:33 +0000226 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
227 unsigned DestReg, unsigned SubIdx,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000228 const MachineInstr &Orig,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000229 const TargetRegisterInfo &TRI) const override;
Evan Chengfe864422009-11-08 00:15:23 +0000230
Matthias Braun55bc9b32017-08-22 23:56:30 +0000231 MachineInstr &
232 duplicate(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore,
233 const MachineInstr &Orig) const override;
Jakob Stoklund Olesen29a64c92010-01-06 23:47:07 +0000234
Tim Northover798697d2013-04-21 11:57:07 +0000235 const MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, unsigned Reg,
236 unsigned SubIdx, unsigned State,
237 const TargetRegisterInfo *TRI) const;
238
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000239 bool produceSameValue(const MachineInstr &MI0, const MachineInstr &MI1,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000240 const MachineRegisterInfo *MRI) const override;
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000241
Bill Wendlingf4707472010-06-23 23:00:16 +0000242 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to
243 /// determine if two loads are loading from the same base address. It should
244 /// only return true if the base pointers are the same and the only
245 /// differences between the two addresses is the offset. It also returns the
246 /// offsets by reference.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000247 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1,
248 int64_t &Offset2) const override;
Bill Wendlingf4707472010-06-23 23:00:16 +0000249
250 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000251 /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads
252 /// should be scheduled togther. On some targets if two loads are loading from
Bill Wendlingf4707472010-06-23 23:00:16 +0000253 /// addresses in the same cache line, it's better if they are scheduled
254 /// together. This function takes two integers that represent the load offsets
255 /// from the common base address. It returns true if it decides it's desirable
256 /// to schedule the two loads together. "NumLoads" is the number of loads that
257 /// have already been scheduled after Load1.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000258 bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
259 int64_t Offset1, int64_t Offset2,
260 unsigned NumLoads) const override;
Bill Wendlingf4707472010-06-23 23:00:16 +0000261
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000262 bool isSchedulingBoundary(const MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000263 const MachineBasicBlock *MBB,
264 const MachineFunction &MF) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000265
Craig Topper6bc27bf2014-03-10 02:09:33 +0000266 bool isProfitableToIfCvt(MachineBasicBlock &MBB,
267 unsigned NumCycles, unsigned ExtraPredCycles,
Cong Houc536bd92015-09-10 23:10:42 +0000268 BranchProbability Probability) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000269
Craig Topper6bc27bf2014-03-10 02:09:33 +0000270 bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT,
271 unsigned ExtraT, MachineBasicBlock &FMBB,
272 unsigned NumF, unsigned ExtraF,
Cong Houc536bd92015-09-10 23:10:42 +0000273 BranchProbability Probability) const override;
Evan Cheng02b184d2010-06-25 22:42:03 +0000274
Craig Topper6bc27bf2014-03-10 02:09:33 +0000275 bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
Cong Houc536bd92015-09-10 23:10:42 +0000276 BranchProbability Probability) const override {
Cameron Zwarich80018502011-04-13 06:39:16 +0000277 return NumCycles == 1;
Evan Cheng02b184d2010-06-25 22:42:03 +0000278 }
Bill Wendling7de9d522010-08-06 01:32:48 +0000279
Craig Topper6bc27bf2014-03-10 02:09:33 +0000280 bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
281 MachineBasicBlock &FMBB) const override;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000282
Manman Ren6fa76dc2012-06-29 21:33:59 +0000283 /// analyzeCompare - For a comparison instruction, return the source registers
284 /// in SrcReg and SrcReg2 if having two register operands, and the value it
285 /// compares against in CmpValue. Return true if the comparison instruction
286 /// can be analyzed.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000287 bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000288 unsigned &SrcReg2, int &CmpMask,
289 int &CmpValue) const override;
Bill Wendling7de9d522010-08-06 01:32:48 +0000290
Manman Ren6fa76dc2012-06-29 21:33:59 +0000291 /// optimizeCompareInstr - Convert the instruction to set the zero flag so
292 /// that we can remove a "comparison with zero"; Remove a redundant CMP
293 /// instruction if the flags can be updated in the same way by an earlier
294 /// instruction such as SUB.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000295 bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000296 unsigned SrcReg2, int CmpMask, int CmpValue,
297 const MachineRegisterInfo *MRI) const override;
Evan Cheng367a5df2010-09-09 18:18:55 +0000298
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000299 bool analyzeSelect(const MachineInstr &MI,
300 SmallVectorImpl<MachineOperand> &Cond, unsigned &TrueOp,
301 unsigned &FalseOp, bool &Optimizable) const override;
Jakob Stoklund Olesenc19bf022012-08-16 23:14:20 +0000302
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000303 MachineInstr *optimizeSelect(MachineInstr &MI,
Mehdi Amini22e59742015-01-13 07:07:13 +0000304 SmallPtrSetImpl<MachineInstr *> &SeenMIs,
305 bool) const override;
Jakob Stoklund Olesenc19bf022012-08-16 23:14:20 +0000306
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000307 /// FoldImmediate - 'Reg' is known to be defined by a move immediate
308 /// instruction, try to fold the immediate into the use instruction.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000309 bool FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, unsigned Reg,
310 MachineRegisterInfo *MRI) const override;
Evan Cheng7f8ab6e2010-11-17 20:13:28 +0000311
Craig Topper6bc27bf2014-03-10 02:09:33 +0000312 unsigned getNumMicroOps(const InstrItineraryData *ItinData,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000313 const MachineInstr &MI) const override;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000314
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000315 int getOperandLatency(const InstrItineraryData *ItinData,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000316 const MachineInstr &DefMI, unsigned DefIdx,
317 const MachineInstr &UseMI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000318 unsigned UseIdx) const override;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000319 int getOperandLatency(const InstrItineraryData *ItinData,
320 SDNode *DefNode, unsigned DefIdx,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000321 SDNode *UseNode, unsigned UseIdx) const override;
Jakob Stoklund Olesenf9b71a22011-09-27 22:57:21 +0000322
323 /// VFP/NEON execution domains.
324 std::pair<uint16_t, uint16_t>
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000325 getExecutionDomain(const MachineInstr &MI) const override;
326 void setExecutionDomain(MachineInstr &MI, unsigned Domain) const override;
Jakob Stoklund Olesenf9b71a22011-09-27 22:57:21 +0000327
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000328 unsigned
329 getPartialRegUpdateClearance(const MachineInstr &, unsigned,
330 const TargetRegisterInfo *) const override;
331 void breakPartialRegDependency(MachineInstr &, unsigned,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000332 const TargetRegisterInfo *TRI) const override;
Tom Roeder44cb65f2014-06-05 19:29:43 +0000333
Andrew Trick2ac6f7d2012-09-14 18:48:46 +0000334 /// Get the number of addresses by LDM or VLDM or zero for unknown.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000335 unsigned getNumLDMAddresses(const MachineInstr &MI) const;
Andrew Trick2ac6f7d2012-09-14 18:48:46 +0000336
Martin Storsjod3b29222018-08-22 20:34:06 +0000337 std::pair<unsigned, unsigned>
338 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
339 ArrayRef<std::pair<unsigned, const char *>>
340 getSerializableDirectMachineOperandTargetFlags() const override;
341 ArrayRef<std::pair<unsigned, const char *>>
342 getSerializableBitmaskMachineOperandTargetFlags() const override;
343
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000344private:
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000345 unsigned getInstBundleLength(const MachineInstr &MI) const;
Evan Cheng7fae11b2011-12-14 02:11:42 +0000346
Evan Cheng412e37b2010-10-07 23:12:15 +0000347 int getVLDMDefCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000348 const MCInstrDesc &DefMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000349 unsigned DefClass,
350 unsigned DefIdx, unsigned DefAlign) const;
351 int getLDMDefCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000352 const MCInstrDesc &DefMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000353 unsigned DefClass,
354 unsigned DefIdx, unsigned DefAlign) const;
355 int getVSTMUseCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000356 const MCInstrDesc &UseMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000357 unsigned UseClass,
358 unsigned UseIdx, unsigned UseAlign) const;
359 int getSTMUseCycle(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000360 const MCInstrDesc &UseMCID,
Evan Cheng412e37b2010-10-07 23:12:15 +0000361 unsigned UseClass,
362 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000363 int getOperandLatency(const InstrItineraryData *ItinData,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000364 const MCInstrDesc &DefMCID,
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000365 unsigned DefIdx, unsigned DefAlign,
Evan Cheng6cc775f2011-06-28 19:10:37 +0000366 const MCInstrDesc &UseMCID,
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000367 unsigned UseIdx, unsigned UseAlign) const;
Evan Cheng63c76082010-10-19 18:58:51 +0000368
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000369 int getOperandLatencyImpl(const InstrItineraryData *ItinData,
370 const MachineInstr &DefMI, unsigned DefIdx,
371 const MCInstrDesc &DefMCID, unsigned DefAdj,
372 const MachineOperand &DefMO, unsigned Reg,
373 const MachineInstr &UseMI, unsigned UseIdx,
374 const MCInstrDesc &UseMCID, unsigned UseAdj) const;
375
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000376 unsigned getPredicationCost(const MachineInstr &MI) const override;
Arnold Schwaighoferd2f96b92013-09-30 15:28:56 +0000377
Andrew Trick45446062012-06-05 21:11:27 +0000378 unsigned getInstrLatency(const InstrItineraryData *ItinData,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000379 const MachineInstr &MI,
Craig Toppere73658d2014-04-28 04:05:08 +0000380 unsigned *PredCost = nullptr) const override;
Evan Chengdebf9c52010-11-03 00:45:17 +0000381
382 int getInstrLatency(const InstrItineraryData *ItinData,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000383 SDNode *Node) const override;
Evan Chengdebf9c52010-11-03 00:45:17 +0000384
Matthias Braun88e21312015-06-13 03:42:11 +0000385 bool hasHighOperandLatency(const TargetSchedModel &SchedModel,
Evan Cheng63c76082010-10-19 18:58:51 +0000386 const MachineRegisterInfo *MRI,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000387 const MachineInstr &DefMI, unsigned DefIdx,
388 const MachineInstr &UseMI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000389 unsigned UseIdx) const override;
Matthias Braun88e21312015-06-13 03:42:11 +0000390 bool hasLowDefLatency(const TargetSchedModel &SchedModel,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000391 const MachineInstr &DefMI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000392 unsigned DefIdx) const override;
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000393
Andrew Trick924123a2011-09-21 02:20:46 +0000394 /// verifyInstruction - Perform target specific instruction verification.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000395 bool verifyInstruction(const MachineInstr &MI,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000396 StringRef &ErrInfo) const override;
Andrew Trick924123a2011-09-21 02:20:46 +0000397
Rafael Espindola82f46312016-06-28 15:18:26 +0000398 virtual void expandLoadStackGuard(MachineBasicBlock::iterator MI) const = 0;
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000399
Scott Douglass953f9082015-10-05 14:49:54 +0000400 void expandMEMCPY(MachineBasicBlock::iterator) const;
401
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000402private:
403 /// Modeling special VFP / NEON fp MLA / MLS hazards.
404
405 /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal
406 /// MLx table.
407 DenseMap<unsigned, unsigned> MLxEntryMap;
408
409 /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause
410 /// stalls when scheduled together with fp MLA / MLS opcodes.
411 SmallSet<unsigned, 16> MLxHazardOpcodes;
412
413public:
414 /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS
415 /// instruction.
416 bool isFpMLxInstruction(unsigned Opcode) const {
417 return MLxEntryMap.count(Opcode);
418 }
419
420 /// isFpMLxInstruction - This version also returns the multiply opcode and the
421 /// addition / subtraction opcode to expand to. Return true for 'HasLane' for
422 /// the MLX instructions with an extra lane operand.
423 bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc,
424 unsigned &AddSubOpc, bool &NegAcc,
425 bool &HasLane) const;
426
427 /// canCauseFpMLxStall - Return true if an instruction of the specified opcode
428 /// will cause stalls when scheduled after (within 4-cycle window) a fp
429 /// MLA / MLS instruction.
430 bool canCauseFpMLxStall(unsigned Opcode) const {
431 return MLxHazardOpcodes.count(Opcode);
432 }
Arnold Schwaighofer5dde1f32013-04-05 04:42:00 +0000433
434 /// Returns true if the instruction has a shift by immediate that can be
435 /// executed in one cycle less.
436 bool isSwiftFastImmShift(const MachineInstr *MI) const;
Serge Pavlov5943a962017-04-19 03:12:05 +0000437
438 /// Returns predicate register associated with the given frame instruction.
439 unsigned getFramePred(const MachineInstr &MI) const {
440 assert(isFrameInstr(MI));
Serge Pavlovd526b132017-05-09 13:35:13 +0000441 // Operands of ADJCALLSTACKDOWN/ADJCALLSTACKUP:
442 // - argument declared in the pattern:
Serge Pavlov5943a962017-04-19 03:12:05 +0000443 // 0 - frame size
Serge Pavlovd526b132017-05-09 13:35:13 +0000444 // 1 - arg of CALLSEQ_START/CALLSEQ_END
445 // 2 - predicate code (like ARMCC::AL)
Serge Pavlov5943a962017-04-19 03:12:05 +0000446 // - added by predOps:
447 // 3 - predicate reg
448 return MI.getOperand(3).getReg();
449 }
David Goodwinaf7451b2009-07-08 16:09:28 +0000450};
Evan Cheng780748d2009-07-28 05:48:47 +0000451
Diana Picus4f8c3e12017-01-13 09:37:56 +0000452/// Get the operands corresponding to the given \p Pred value. By default, the
453/// predicate register is assumed to be 0 (no register), but you can pass in a
454/// \p PredReg if that is not the case.
455static inline std::array<MachineOperand, 2> predOps(ARMCC::CondCodes Pred,
456 unsigned PredReg = 0) {
457 return {{MachineOperand::CreateImm(static_cast<int64_t>(Pred)),
Eugene Zelenko342257e2017-01-31 00:56:17 +0000458 MachineOperand::CreateReg(PredReg, false)}};
David Goodwinaf7451b2009-07-08 16:09:28 +0000459}
460
Diana Picus8a73f552017-01-13 10:18:01 +0000461/// Get the operand corresponding to the conditional code result. By default,
462/// this is 0 (no register).
463static inline MachineOperand condCodeOp(unsigned CCReg = 0) {
Eugene Zelenko342257e2017-01-31 00:56:17 +0000464 return MachineOperand::CreateReg(CCReg, false);
Evan Cheng780748d2009-07-28 05:48:47 +0000465}
466
Diana Picusa2c59142017-01-13 10:37:37 +0000467/// Get the operand corresponding to the conditional code result for Thumb1.
468/// This operand will always refer to CPSR and it will have the Define flag set.
469/// You can optionally set the Dead flag by means of \p isDead.
470static inline MachineOperand t1CondCodeOp(bool isDead = false) {
471 return MachineOperand::CreateReg(ARM::CPSR,
472 /*Define*/ true, /*Implicit*/ false,
473 /*Kill*/ false, isDead);
Evan Cheng6ddd7bc2009-08-15 07:59:10 +0000474}
475
476static inline
Evan Cheng780748d2009-07-28 05:48:47 +0000477bool isUncondBranchOpcode(int Opc) {
478 return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
479}
480
481static inline
482bool isCondBranchOpcode(int Opc) {
483 return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
484}
485
Momchil Velikov4a91fb92017-11-15 12:02:55 +0000486static inline bool isJumpTableBranchOpcode(int Opc) {
487 return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm_i12 ||
488 Opc == ARM::BR_JTm_rs || Opc == ARM::BR_JTadd || Opc == ARM::tBR_JTr ||
489 Opc == ARM::t2BR_JT;
Evan Cheng780748d2009-07-28 05:48:47 +0000490}
491
Bob Wilson73789b82009-10-28 18:26:41 +0000492static inline
493bool isIndirectBranchOpcode(int Opc) {
Bill Wendling8294a302010-11-30 00:48:15 +0000494 return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND;
Bob Wilson73789b82009-10-28 18:26:41 +0000495}
496
Tim Northover93bcc662013-11-08 17:18:07 +0000497static inline bool isPopOpcode(int Opc) {
498 return Opc == ARM::tPOP_RET || Opc == ARM::LDMIA_RET ||
499 Opc == ARM::t2LDMIA_RET || Opc == ARM::tPOP || Opc == ARM::LDMIA_UPD ||
500 Opc == ARM::t2LDMIA_UPD || Opc == ARM::VLDMDIA_UPD;
501}
502
503static inline bool isPushOpcode(int Opc) {
504 return Opc == ARM::tPUSH || Opc == ARM::t2STMDB_UPD ||
505 Opc == ARM::STMDB_UPD || Opc == ARM::VSTMDDB_UPD;
506}
507
Evan Cheng2aa91cc2009-08-08 03:20:32 +0000508/// getInstrPredicate - If instruction is predicated, returns its predicate
509/// condition, otherwise returns AL. It also returns the condition code
510/// register by reference.
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000511ARMCC::CondCodes getInstrPredicate(const MachineInstr &MI, unsigned &PredReg);
Evan Cheng2aa91cc2009-08-08 03:20:32 +0000512
Matthias Braunfa3872e2015-05-18 20:27:55 +0000513unsigned getMatchingCondBranchOpcode(unsigned Opc);
Evan Cheng780748d2009-07-28 05:48:47 +0000514
Jakob Stoklund Olesen6cb96122012-08-15 22:16:39 +0000515/// Determine if MI can be folded into an ARM MOVCC instruction, and return the
516/// opcode of the SSA instruction representing the conditional MI.
517unsigned canFoldARMInstrIntoMOVCC(unsigned Reg,
518 MachineInstr *&MI,
519 const MachineRegisterInfo &MRI);
Andrew Trick924123a2011-09-21 02:20:46 +0000520
521/// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether
522/// the instruction is encoded with an 'S' bit is determined by the optional
523/// CPSR def operand.
524unsigned convertAddSubFlagsOpcode(unsigned OldOpc);
525
Evan Cheng780748d2009-07-28 05:48:47 +0000526/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
527/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
528/// code.
529void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000530 MachineBasicBlock::iterator &MBBI,
531 const DebugLoc &dl, unsigned DestReg,
532 unsigned BaseReg, int NumBytes,
Evan Cheng780748d2009-07-28 05:48:47 +0000533 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000534 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Evan Cheng780748d2009-07-28 05:48:47 +0000535
536void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000537 MachineBasicBlock::iterator &MBBI,
538 const DebugLoc &dl, unsigned DestReg,
539 unsigned BaseReg, int NumBytes,
Evan Cheng780748d2009-07-28 05:48:47 +0000540 ARMCC::CondCodes Pred, unsigned PredReg,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000541 const ARMBaseInstrInfo &TII, unsigned MIFlags = 0);
Jim Grosbachbbdc5d22010-10-19 23:27:08 +0000542void emitThumbRegPlusImmediate(MachineBasicBlock &MBB,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000543 MachineBasicBlock::iterator &MBBI,
544 const DebugLoc &dl, unsigned DestReg,
545 unsigned BaseReg, int NumBytes,
546 const TargetInstrInfo &TII,
547 const ARMBaseRegisterInfo &MRI,
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000548 unsigned MIFlags = 0);
Evan Cheng780748d2009-07-28 05:48:47 +0000549
Tim Northover93bcc662013-11-08 17:18:07 +0000550/// Tries to add registers to the reglist of a given base-updating
551/// push/pop instruction to adjust the stack by an additional
552/// NumBytes. This can save a few bytes per function in code-size, but
553/// obviously generates more memory traffic. As such, it only takes
554/// effect in functions being optimised for size.
Tim Northoverdee86042013-12-02 14:46:26 +0000555bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget,
556 MachineFunction &MF, MachineInstr *MI,
Tim Northover93bcc662013-11-08 17:18:07 +0000557 unsigned NumBytes);
Evan Cheng780748d2009-07-28 05:48:47 +0000558
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000559/// rewriteARMFrameIndex / rewriteT2FrameIndex -
Evan Cheng7a37b1a2009-08-27 01:23:50 +0000560/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
561/// offset could not be handled directly in MI, and return the left-over
562/// portion by reference.
563bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
564 unsigned FrameReg, int &Offset,
565 const ARMBaseInstrInfo &TII);
Evan Cheng780748d2009-07-28 05:48:47 +0000566
Evan Cheng7a37b1a2009-08-27 01:23:50 +0000567bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
568 unsigned FrameReg, int &Offset,
569 const ARMBaseInstrInfo &TII);
Evan Cheng780748d2009-07-28 05:48:47 +0000570
Eugene Zelenko342257e2017-01-31 00:56:17 +0000571} // end namespace llvm
Evan Cheng780748d2009-07-28 05:48:47 +0000572
Eugene Zelenko342257e2017-01-31 00:56:17 +0000573#endif // LLVM_LIB_TARGET_ARM_ARMBASEINSTRINFO_H