LLVM 18.0.0git
AArch64InstrInfo.h
Go to the documentation of this file.
1//===- AArch64InstrInfo.h - AArch64 Instruction Information -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the AArch64 implementation of the TargetInstrInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64INSTRINFO_H
14#define LLVM_LIB_TARGET_AARCH64_AARCH64INSTRINFO_H
15
16#include "AArch64.h"
17#include "AArch64RegisterInfo.h"
20#include <optional>
21
22#define GET_INSTRINFO_HEADER
23#include "AArch64GenInstrInfo.inc"
24
25namespace llvm {
26
27class AArch64Subtarget;
28
33
34#define FALKOR_STRIDED_ACCESS_MD "falkor.strided.access"
35
37 const AArch64RegisterInfo RI;
38 const AArch64Subtarget &Subtarget;
39
40public:
41 explicit AArch64InstrInfo(const AArch64Subtarget &STI);
42
43 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
44 /// such, whenever a client has an instance of instruction info, it should
45 /// always be able to get register info as well (through this method).
46 const AArch64RegisterInfo &getRegisterInfo() const { return RI; }
47
48 unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
49
50 bool isAsCheapAsAMove(const MachineInstr &MI) const override;
51
52 bool isCoalescableExtInstr(const MachineInstr &MI, Register &SrcReg,
53 Register &DstReg, unsigned &SubIdx) const override;
54
55 bool
57 const MachineInstr &MIb) const override;
58
59 unsigned isLoadFromStackSlot(const MachineInstr &MI,
60 int &FrameIndex) const override;
61 unsigned isStoreToStackSlot(const MachineInstr &MI,
62 int &FrameIndex) const override;
63
64 /// Does this instruction set its full destination register to zero?
65 static bool isGPRZero(const MachineInstr &MI);
66
67 /// Does this instruction rename a GPR without modifying bits?
68 static bool isGPRCopy(const MachineInstr &MI);
69
70 /// Does this instruction rename an FPR without modifying bits?
71 static bool isFPRCopy(const MachineInstr &MI);
72
73 /// Return true if pairing the given load or store is hinted to be
74 /// unprofitable.
75 static bool isLdStPairSuppressed(const MachineInstr &MI);
76
77 /// Return true if the given load or store is a strided memory access.
78 static bool isStridedAccess(const MachineInstr &MI);
79
80 /// Return true if it has an unscaled load/store offset.
81 static bool hasUnscaledLdStOffset(unsigned Opc);
83 return hasUnscaledLdStOffset(MI.getOpcode());
84 }
85
86 /// Returns the unscaled load/store for the scaled load/store opcode,
87 /// if there is a corresponding unscaled variant available.
88 static std::optional<unsigned> getUnscaledLdSt(unsigned Opc);
89
90 /// Scaling factor for (scaled or unscaled) load or store.
91 static int getMemScale(unsigned Opc);
92 static int getMemScale(const MachineInstr &MI) {
93 return getMemScale(MI.getOpcode());
94 }
95
96 /// Returns whether the instruction is a pre-indexed load.
97 static bool isPreLd(const MachineInstr &MI);
98
99 /// Returns whether the instruction is a pre-indexed store.
100 static bool isPreSt(const MachineInstr &MI);
101
102 /// Returns whether the instruction is a pre-indexed load/store.
103 static bool isPreLdSt(const MachineInstr &MI);
104
105 /// Returns whether the instruction is a paired load/store.
106 static bool isPairedLdSt(const MachineInstr &MI);
107
108 /// Returns the base register operator of a load/store.
109 static const MachineOperand &getLdStBaseOp(const MachineInstr &MI);
110
111 /// Returns the immediate offset operator of a load/store.
112 static const MachineOperand &getLdStOffsetOp(const MachineInstr &MI);
113
114 /// Returns whether the instruction is FP or NEON.
115 static bool isFpOrNEON(const MachineInstr &MI);
116
117 /// Returns whether the instruction is in H form (16 bit operands)
118 static bool isHForm(const MachineInstr &MI);
119
120 /// Returns whether the instruction is in Q form (128 bit operands)
121 static bool isQForm(const MachineInstr &MI);
122
123 /// Returns the index for the immediate for a given instruction.
124 static unsigned getLoadStoreImmIdx(unsigned Opc);
125
126 /// Return true if pairing the given load or store may be paired with another.
127 static bool isPairableLdStInst(const MachineInstr &MI);
128
129 /// Return the opcode that set flags when possible. The caller is
130 /// responsible for ensuring the opc has a flag setting equivalent.
131 static unsigned convertToFlagSettingOpc(unsigned Opc);
132
133 /// Return true if this is a load/store that can be potentially paired/merged.
134 bool isCandidateToMergeOrPair(const MachineInstr &MI) const;
135
136 /// Hint that pairing the given load or store is unprofitable.
137 static void suppressLdStPair(MachineInstr &MI);
138
139 std::optional<ExtAddrMode>
141 const TargetRegisterInfo *TRI) const override;
142
145 int64_t &Offset, bool &OffsetIsScalable, unsigned &Width,
146 const TargetRegisterInfo *TRI) const override;
147
148 /// If \p OffsetIsScalable is set to 'true', the offset is scaled by `vscale`.
149 /// This is true for some SVE instructions like ldr/str that have a
150 /// 'reg + imm' addressing mode where the immediate is an index to the
151 /// scalable vector located at 'reg + imm * vscale x #bytes'.
153 const MachineOperand *&BaseOp,
154 int64_t &Offset, bool &OffsetIsScalable,
155 unsigned &Width,
156 const TargetRegisterInfo *TRI) const;
157
158 /// Return the immediate offset of the base register in a load/store \p LdSt.
160
161 /// Returns true if opcode \p Opc is a memory operation. If it is, set
162 /// \p Scale, \p Width, \p MinOffset, and \p MaxOffset accordingly.
163 ///
164 /// For unscaled instructions, \p Scale is set to 1.
165 static bool getMemOpInfo(unsigned Opcode, TypeSize &Scale, unsigned &Width,
166 int64_t &MinOffset, int64_t &MaxOffset);
167
170 unsigned NumLoads, unsigned NumBytes) const override;
171
173 const DebugLoc &DL, MCRegister DestReg,
174 MCRegister SrcReg, bool KillSrc, unsigned Opcode,
175 llvm::ArrayRef<unsigned> Indices) const;
177 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
178 bool KillSrc, unsigned Opcode, unsigned ZeroReg,
179 llvm::ArrayRef<unsigned> Indices) const;
181 const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg,
182 bool KillSrc) const override;
183
186 bool isKill, int FrameIndex,
187 const TargetRegisterClass *RC,
188 const TargetRegisterInfo *TRI,
189 Register VReg) const override;
190
193 int FrameIndex, const TargetRegisterClass *RC,
194 const TargetRegisterInfo *TRI,
195 Register VReg) const override;
196
197 // This tells target independent code that it is okay to pass instructions
198 // with subreg operands to foldMemoryOperandImpl.
199 bool isSubregFoldable() const override { return true; }
200
205 MachineBasicBlock::iterator InsertPt, int FrameIndex,
206 LiveIntervals *LIS = nullptr,
207 VirtRegMap *VRM = nullptr) const override;
208
209 /// \returns true if a branch from an instruction with opcode \p BranchOpc
210 /// bytes is capable of jumping to a position \p BrOffset bytes away.
211 bool isBranchOffsetInRange(unsigned BranchOpc,
212 int64_t BrOffset) const override;
213
214 MachineBasicBlock *getBranchDestBlock(const MachineInstr &MI) const override;
215
217 MachineBasicBlock &NewDestBB,
218 MachineBasicBlock &RestoreBB, const DebugLoc &DL,
219 int64_t BrOffset, RegScavenger *RS) const override;
220
222 MachineBasicBlock *&FBB,
224 bool AllowModify = false) const override;
226 MachineBranchPredicate &MBP,
227 bool AllowModify) const override;
229 int *BytesRemoved = nullptr) const override;
232 const DebugLoc &DL,
233 int *BytesAdded = nullptr) const override;
234 bool
237 Register, Register, Register, int &, int &,
238 int &) const override;
240 const DebugLoc &DL, Register DstReg,
242 Register FalseReg) const override;
243
245 MachineBasicBlock::iterator MI) const override;
246
247 MCInst getNop() const override;
248
250 const MachineBasicBlock *MBB,
251 const MachineFunction &MF) const override;
252
253 /// analyzeCompare - For a comparison instruction, return the source registers
254 /// in SrcReg and SrcReg2, and the value it compares against in CmpValue.
255 /// Return true if the comparison instruction can be analyzed.
256 bool analyzeCompare(const MachineInstr &MI, Register &SrcReg,
257 Register &SrcReg2, int64_t &CmpMask,
258 int64_t &CmpValue) const override;
259 /// optimizeCompareInstr - Convert the instruction supplying the argument to
260 /// the comparison into one that sets the zero bit in the flags register.
261 bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
262 Register SrcReg2, int64_t CmpMask, int64_t CmpValue,
263 const MachineRegisterInfo *MRI) const override;
264 bool optimizeCondBranch(MachineInstr &MI) const override;
265
266 /// Return true when a code sequence can improve throughput. It
267 /// should be called only for instructions in loops.
268 /// \param Pattern - combiner pattern
270 /// Return true when there is potentially a faster code sequence
271 /// for an instruction chain ending in ``Root``. All potential patterns are
272 /// listed in the ``Patterns`` array.
273 bool
276 bool DoRegPressureReduce) const override;
277 /// Return true when Inst is associative and commutative so that it can be
278 /// reassociated. If Invert is true, then the inverse of Inst operation must
279 /// be checked.
281 bool Invert) const override;
282 /// When getMachineCombinerPatterns() finds patterns, this function generates
283 /// the instructions that could replace the original code sequence
288 DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const override;
289 /// AArch64 supports MachineCombiner.
290 bool useMachineCombiner() const override;
291
292 bool expandPostRAPseudo(MachineInstr &MI) const override;
293
294 std::pair<unsigned, unsigned>
295 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
302
304 bool OutlineFromLinkOnceODRs) const override;
305 std::optional<outliner::OutlinedFunction> getOutliningCandidateInfo(
306 std::vector<outliner::Candidate> &RepeatedSequenceLocs) const override;
308 Function &F, std::vector<outliner::Candidate> &Candidates) const override;
310 getOutliningTypeImpl(MachineBasicBlock::iterator &MIT, unsigned Flags) const override;
312 std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>>
313 getOutlinableRanges(MachineBasicBlock &MBB, unsigned &Flags) const override;
315 const outliner::OutlinedFunction &OF) const override;
319 outliner::Candidate &C) const override;
321
324 DebugLoc &DL) const override;
325
326 /// Returns the vector element size (B, H, S or D) of an SVE opcode.
327 uint64_t getElementSizeForOpcode(unsigned Opc) const;
328 /// Returns true if the opcode is for an SVE instruction that sets the
329 /// condition codes as if it's results had been fed to a PTEST instruction
330 /// along with the same general predicate.
331 bool isPTestLikeOpcode(unsigned Opc) const;
332 /// Returns true if the opcode is for an SVE WHILE## instruction.
333 bool isWhileOpcode(unsigned Opc) const;
334 /// Returns true if the instruction has a shift by immediate that can be
335 /// executed in one cycle less.
336 static bool isFalkorShiftExtFast(const MachineInstr &MI);
337 /// Return true if the instructions is a SEH instruciton used for unwinding
338 /// on Windows.
339 static bool isSEHInstruction(const MachineInstr &MI);
340
341 std::optional<RegImmPair> isAddImmediate(const MachineInstr &MI,
342 Register Reg) const override;
343
344 bool isFunctionSafeToSplit(const MachineFunction &MF) const override;
345
346 bool isMBBSafeToSplitToCold(const MachineBasicBlock &MBB) const override;
347
348 std::optional<ParamLoadedValue>
349 describeLoadedValue(const MachineInstr &MI, Register Reg) const override;
350
351 unsigned int getTailDuplicateSize(CodeGenOptLevel OptLevel) const override;
352
354 MachineRegisterInfo &MRI) const override;
355
357 int64_t &NumBytes,
358 int64_t &NumPredicateVectors,
359 int64_t &NumDataVectors);
361 int64_t &ByteSized,
362 int64_t &VGSized);
363
364 bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
365#define GET_INSTRINFO_HELPER_DECLS
366#include "AArch64GenInstrInfo.inc"
367
368protected:
369 /// If the specific machine instruction is an instruction that moves/copies
370 /// value from one register to another register return destination and source
371 /// registers as machine operands.
372 std::optional<DestSourcePair>
373 isCopyInstrImpl(const MachineInstr &MI) const override;
374
375private:
376 unsigned getInstBundleLength(const MachineInstr &MI) const;
377
378 /// Sets the offsets on outlined instructions in \p MBB which use SP
379 /// so that they will be valid post-outlining.
380 ///
381 /// \param MBB A \p MachineBasicBlock in an outlined function.
382 void fixupPostOutline(MachineBasicBlock &MBB) const;
383
384 void instantiateCondBranch(MachineBasicBlock &MBB, const DebugLoc &DL,
385 MachineBasicBlock *TBB,
386 ArrayRef<MachineOperand> Cond) const;
387 bool substituteCmpToZero(MachineInstr &CmpInstr, unsigned SrcReg,
388 const MachineRegisterInfo &MRI) const;
389 bool removeCmpToZeroOrOne(MachineInstr &CmpInstr, unsigned SrcReg,
390 int CmpValue, const MachineRegisterInfo &MRI) const;
391
392 /// Returns an unused general-purpose register which can be used for
393 /// constructing an outlined call if one exists. Returns 0 otherwise.
394 Register findRegisterToSaveLRTo(outliner::Candidate &C) const;
395
396 /// Remove a ptest of a predicate-generating operation that already sets, or
397 /// can be made to set, the condition codes in an identical manner
398 bool optimizePTestInstr(MachineInstr *PTest, unsigned MaskReg,
399 unsigned PredReg,
400 const MachineRegisterInfo *MRI) const;
401};
402
403struct UsedNZCV {
404 bool N = false;
405 bool Z = false;
406 bool C = false;
407 bool V = false;
408
409 UsedNZCV() = default;
410
411 UsedNZCV &operator|=(const UsedNZCV &UsedFlags) {
412 this->N |= UsedFlags.N;
413 this->Z |= UsedFlags.Z;
414 this->C |= UsedFlags.C;
415 this->V |= UsedFlags.V;
416 return *this;
417 }
418};
419
420/// \returns Conditions flags used after \p CmpInstr in its MachineBB if NZCV
421/// flags are not alive in successors of the same \p CmpInstr and \p MI parent.
422/// \returns std::nullopt otherwise.
423///
424/// Collect instructions using that flags in \p CCUseInstrs if provided.
425std::optional<UsedNZCV>
426examineCFlagsUse(MachineInstr &MI, MachineInstr &CmpInstr,
427 const TargetRegisterInfo &TRI,
428 SmallVectorImpl<MachineInstr *> *CCUseInstrs = nullptr);
429
430/// Return true if there is an instruction /after/ \p DefMI and before \p UseMI
431/// which either reads or clobbers NZCV.
432bool isNZCVTouchedInInstructionRange(const MachineInstr &DefMI,
433 const MachineInstr &UseMI,
434 const TargetRegisterInfo *TRI);
435
436MCCFIInstruction createDefCFA(const TargetRegisterInfo &TRI, unsigned FrameReg,
437 unsigned Reg, const StackOffset &Offset,
438 bool LastAdjustmentWasScalable = true);
439MCCFIInstruction createCFAOffset(const TargetRegisterInfo &MRI, unsigned Reg,
440 const StackOffset &OffsetFromDefCFA);
441
442/// emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg
443/// plus Offset. This is intended to be used from within the prolog/epilog
444/// insertion (PEI) pass, where a virtual scratch register may be allocated
445/// if necessary, to be replaced by the scavenger at the end of PEI.
446void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
447 const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
448 StackOffset Offset, const TargetInstrInfo *TII,
450 bool SetNZCV = false, bool NeedsWinCFI = false,
451 bool *HasWinCFI = nullptr, bool EmitCFAOffset = false,
452 StackOffset InitialOffset = {},
453 unsigned FrameReg = AArch64::SP);
454
455/// rewriteAArch64FrameIndex - Rewrite MI to access 'Offset' bytes from the
456/// FP. Return false if the offset could not be handled directly in MI, and
457/// return the left-over portion by reference.
458bool rewriteAArch64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
459 unsigned FrameReg, StackOffset &Offset,
460 const AArch64InstrInfo *TII);
461
462/// Use to report the frame offset status in isAArch64FrameOffsetLegal.
464 AArch64FrameOffsetCannotUpdate = 0x0, ///< Offset cannot apply.
465 AArch64FrameOffsetIsLegal = 0x1, ///< Offset is legal.
466 AArch64FrameOffsetCanUpdate = 0x2 ///< Offset can apply, at least partly.
468
469/// Check if the @p Offset is a valid frame offset for @p MI.
470/// The returned value reports the validity of the frame offset for @p MI.
471/// It uses the values defined by AArch64FrameOffsetStatus for that.
472/// If result == AArch64FrameOffsetCannotUpdate, @p MI cannot be updated to
473/// use an offset.eq
474/// If result & AArch64FrameOffsetIsLegal, @p Offset can completely be
475/// rewritten in @p MI.
476/// If result & AArch64FrameOffsetCanUpdate, @p Offset contains the
477/// amount that is off the limit of the legal offset.
478/// If set, @p OutUseUnscaledOp will contain the whether @p MI should be
479/// turned into an unscaled operator, which opcode is in @p OutUnscaledOp.
480/// If set, @p EmittableOffset contains the amount that can be set in @p MI
481/// (possibly with @p OutUnscaledOp if OutUseUnscaledOp is true) and that
482/// is a legal offset.
483int isAArch64FrameOffsetLegal(const MachineInstr &MI, StackOffset &Offset,
484 bool *OutUseUnscaledOp = nullptr,
485 unsigned *OutUnscaledOp = nullptr,
486 int64_t *EmittableOffset = nullptr);
487
488static inline bool isUncondBranchOpcode(int Opc) { return Opc == AArch64::B; }
489
490static inline bool isCondBranchOpcode(int Opc) {
491 switch (Opc) {
492 case AArch64::Bcc:
493 case AArch64::CBZW:
494 case AArch64::CBZX:
495 case AArch64::CBNZW:
496 case AArch64::CBNZX:
497 case AArch64::TBZW:
498 case AArch64::TBZX:
499 case AArch64::TBNZW:
500 case AArch64::TBNZX:
501 return true;
502 default:
503 return false;
504 }
505}
506
507static inline bool isIndirectBranchOpcode(int Opc) {
508 switch (Opc) {
509 case AArch64::BR:
510 case AArch64::BRAA:
511 case AArch64::BRAB:
512 case AArch64::BRAAZ:
513 case AArch64::BRABZ:
514 return true;
515 }
516 return false;
517}
518
519static inline bool isPTrueOpcode(unsigned Opc) {
520 switch (Opc) {
521 case AArch64::PTRUE_B:
522 case AArch64::PTRUE_H:
523 case AArch64::PTRUE_S:
524 case AArch64::PTRUE_D:
525 return true;
526 default:
527 return false;
528 }
529}
530
531/// Return opcode to be used for indirect calls.
532unsigned getBLRCallOpcode(const MachineFunction &MF);
533
534/// Return XPAC opcode to be used for a ptrauth strip using the given key.
535static inline unsigned getXPACOpcodeForKey(AArch64PACKey::ID K) {
536 using namespace AArch64PACKey;
537 switch (K) {
538 case IA: case IB: return AArch64::XPACI;
539 case DA: case DB: return AArch64::XPACD;
540 }
541 llvm_unreachable("Unhandled AArch64PACKey::ID enum");
542}
543
544/// Return AUT opcode to be used for a ptrauth auth using the given key, or its
545/// AUT*Z variant that doesn't take a discriminator operand, using zero instead.
546static inline unsigned getAUTOpcodeForKey(AArch64PACKey::ID K, bool Zero) {
547 using namespace AArch64PACKey;
548 switch (K) {
549 case IA: return Zero ? AArch64::AUTIZA : AArch64::AUTIA;
550 case IB: return Zero ? AArch64::AUTIZB : AArch64::AUTIB;
551 case DA: return Zero ? AArch64::AUTDZA : AArch64::AUTDA;
552 case DB: return Zero ? AArch64::AUTDZB : AArch64::AUTDB;
553 }
554}
555
556/// Return PAC opcode to be used for a ptrauth sign using the given key, or its
557/// PAC*Z variant that doesn't take a discriminator operand, using zero instead.
558static inline unsigned getPACOpcodeForKey(AArch64PACKey::ID K, bool Zero) {
559 using namespace AArch64PACKey;
560 switch (K) {
561 case IA: return Zero ? AArch64::PACIZA : AArch64::PACIA;
562 case IB: return Zero ? AArch64::PACIZB : AArch64::PACIB;
563 case DA: return Zero ? AArch64::PACDZA : AArch64::PACDA;
564 case DB: return Zero ? AArch64::PACDZB : AArch64::PACDB;
565 }
566}
567
568// struct TSFlags {
569#define TSFLAG_ELEMENT_SIZE_TYPE(X) (X) // 3-bits
570#define TSFLAG_DESTRUCTIVE_INST_TYPE(X) ((X) << 3) // 4-bits
571#define TSFLAG_FALSE_LANE_TYPE(X) ((X) << 7) // 2-bits
572#define TSFLAG_INSTR_FLAGS(X) ((X) << 9) // 2-bits
573#define TSFLAG_SME_MATRIX_TYPE(X) ((X) << 11) // 3-bits
574// }
575
576namespace AArch64 {
577
585};
586
599};
600
605};
606
607// NOTE: This is a bit field.
610
620};
621
622#undef TSFLAG_ELEMENT_SIZE_TYPE
623#undef TSFLAG_DESTRUCTIVE_INST_TYPE
624#undef TSFLAG_FALSE_LANE_TYPE
625#undef TSFLAG_INSTR_FLAGS
626#undef TSFLAG_SME_MATRIX_TYPE
627
631
633}
634
635} // end namespace llvm
636
637#endif
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
#define TSFLAG_DESTRUCTIVE_INST_TYPE(X)
#define TSFLAG_SME_MATRIX_TYPE(X)
#define TSFLAG_FALSE_LANE_TYPE(X)
#define TSFLAG_INSTR_FLAGS(X)
#define TSFLAG_ELEMENT_SIZE_TYPE(X)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
unsigned Reg
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
static bool isHForm(const MachineInstr &MI)
Returns whether the instruction is in H form (16 bit operands)
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, Register DstReg, ArrayRef< MachineOperand > Cond, Register TrueReg, Register FalseReg) const override
void buildClearRegister(Register Reg, MachineBasicBlock &MBB, MachineBasicBlock::iterator Iter, DebugLoc &DL) const override
static bool isQForm(const MachineInstr &MI)
Returns whether the instruction is in Q form (128 bit operands)
static void decomposeStackOffsetForFrameOffsets(const StackOffset &Offset, int64_t &NumBytes, int64_t &NumPredicateVectors, int64_t &NumDataVectors)
Returns the offset in parts to which this frame offset can be decomposed for the purpose of describin...
static bool isFPRCopy(const MachineInstr &MI)
Does this instruction rename an FPR without modifying bits?
bool isThroughputPattern(MachineCombinerPattern Pattern) const override
Return true when a code sequence can improve throughput.
std::optional< DestSourcePair > isCopyInstrImpl(const MachineInstr &MI) const override
If the specific machine instruction is an instruction that moves/copies value from one register to an...
static int getMemScale(const MachineInstr &MI)
MachineBasicBlock * getBranchDestBlock(const MachineInstr &MI) const override
std::optional< RegImmPair > isAddImmediate(const MachineInstr &MI, Register Reg) const override
bool isSubregFoldable() const override
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
GetInstSize - Return the number of bytes of code the specified instruction may be.
bool shouldClusterMemOps(ArrayRef< const MachineOperand * > BaseOps1, ArrayRef< const MachineOperand * > BaseOps2, unsigned NumLoads, unsigned NumBytes) const override
Detect opportunities for ldp/stp formation.
bool getMemOperandWithOffsetWidth(const MachineInstr &MI, const MachineOperand *&BaseOp, int64_t &Offset, bool &OffsetIsScalable, unsigned &Width, const TargetRegisterInfo *TRI) const
If OffsetIsScalable is set to 'true', the offset is scaled by vscale.
uint64_t getElementSizeForOpcode(unsigned Opc) const
Returns the vector element size (B, H, S or D) of an SVE opcode.
outliner::InstrType getOutliningTypeImpl(MachineBasicBlock::iterator &MIT, unsigned Flags) const override
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, bool KillSrc) const override
static bool isGPRCopy(const MachineInstr &MI)
Does this instruction rename a GPR without modifying bits?
static unsigned convertToFlagSettingOpc(unsigned Opc)
Return the opcode that set flags when possible.
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const override
bool canInsertSelect(const MachineBasicBlock &, ArrayRef< MachineOperand > Cond, Register, Register, Register, int &, int &, int &) const override
static const MachineOperand & getLdStOffsetOp(const MachineInstr &MI)
Returns the immediate offset operator of a load/store.
bool isCoalescableExtInstr(const MachineInstr &MI, Register &SrcReg, Register &DstReg, unsigned &SubIdx) const override
bool isWhileOpcode(unsigned Opc) const
Returns true if the opcode is for an SVE WHILE## instruction.
static std::optional< unsigned > getUnscaledLdSt(unsigned Opc)
Returns the unscaled load/store for the scaled load/store opcode, if there is a corresponding unscale...
static bool hasUnscaledLdStOffset(unsigned Opc)
Return true if it has an unscaled load/store offset.
static bool hasUnscaledLdStOffset(MachineInstr &MI)
static bool isPreLdSt(const MachineInstr &MI)
Returns whether the instruction is a pre-indexed load/store.
MachineBasicBlock::iterator insertOutlinedCall(Module &M, MachineBasicBlock &MBB, MachineBasicBlock::iterator &It, MachineFunction &MF, outliner::Candidate &C) const override
std::optional< ExtAddrMode > getAddrModeFromMemoryOp(const MachineInstr &MemI, const TargetRegisterInfo *TRI) const override
bool analyzeBranchPredicate(MachineBasicBlock &MBB, MachineBranchPredicate &MBP, bool AllowModify) const override
static bool isSEHInstruction(const MachineInstr &MI)
Return true if the instructions is a SEH instruciton used for unwinding on Windows.
void insertIndirectBranch(MachineBasicBlock &MBB, MachineBasicBlock &NewDestBB, MachineBasicBlock &RestoreBB, const DebugLoc &DL, int64_t BrOffset, RegScavenger *RS) const override
SmallVector< std::pair< MachineBasicBlock::iterator, MachineBasicBlock::iterator > > getOutlinableRanges(MachineBasicBlock &MBB, unsigned &Flags) const override
static bool isPairableLdStInst(const MachineInstr &MI)
Return true if pairing the given load or store may be paired with another.
const AArch64RegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
static bool isPreSt(const MachineInstr &MI)
Returns whether the instruction is a pre-indexed store.
MachineInstr * foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, ArrayRef< unsigned > Ops, MachineBasicBlock::iterator InsertPt, int FrameIndex, LiveIntervals *LIS=nullptr, VirtRegMap *VRM=nullptr) const override
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
static bool isPairedLdSt(const MachineInstr &MI)
Returns whether the instruction is a paired load/store.
bool useMachineCombiner() const override
AArch64 supports MachineCombiner.
ArrayRef< std::pair< MachineMemOperand::Flags, const char * > > getSerializableMachineMemOperandTargetFlags() const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
bool isExtendLikelyToBeFolded(MachineInstr &ExtMI, MachineRegisterInfo &MRI) const override
static bool isFalkorShiftExtFast(const MachineInstr &MI)
Returns true if the instruction has a shift by immediate that can be executed in one cycle less.
std::optional< ParamLoadedValue > describeLoadedValue(const MachineInstr &MI, Register Reg) const override
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override
static bool isStridedAccess(const MachineInstr &MI)
Return true if the given load or store is a strided memory access.
void genAlternativeCodeSequence(MachineInstr &Root, MachineCombinerPattern Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs, SmallVectorImpl< MachineInstr * > &DelInstrs, DenseMap< unsigned, unsigned > &InstrIdxForVirtReg) const override
When getMachineCombinerPatterns() finds patterns, this function generates the instructions that could...
bool expandPostRAPseudo(MachineInstr &MI) const override
unsigned int getTailDuplicateSize(CodeGenOptLevel OptLevel) const override
bool isFunctionSafeToOutlineFrom(MachineFunction &MF, bool OutlineFromLinkOnceODRs) const override
bool getMemOperandsWithOffsetWidth(const MachineInstr &MI, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, unsigned &Width, const TargetRegisterInfo *TRI) const override
static bool isFpOrNEON(const MachineInstr &MI)
Returns whether the instruction is FP or NEON.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
bool shouldOutlineFromFunctionByDefault(MachineFunction &MF) const override
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
void copyGPRRegTuple(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, DebugLoc DL, unsigned DestReg, unsigned SrcReg, bool KillSrc, unsigned Opcode, unsigned ZeroReg, llvm::ArrayRef< unsigned > Indices) const
void buildOutlinedFrame(MachineBasicBlock &MBB, MachineFunction &MF, const outliner::OutlinedFunction &OF) const override
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
MachineOperand & getMemOpBaseRegImmOfsOffsetOperand(MachineInstr &LdSt) const
Return the immediate offset of the base register in a load/store LdSt.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify=false) const override
static bool isLdStPairSuppressed(const MachineInstr &MI)
Return true if pairing the given load or store is hinted to be unprofitable.
static bool getMemOpInfo(unsigned Opcode, TypeSize &Scale, unsigned &Width, int64_t &MinOffset, int64_t &MaxOffset)
Returns true if opcode Opc is a memory operation.
bool isFunctionSafeToSplit(const MachineFunction &MF) const override
bool isAssociativeAndCommutative(const MachineInstr &Inst, bool Invert) const override
Return true when Inst is associative and commutative so that it can be reassociated.
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t CmpMask, int64_t CmpValue, const MachineRegisterInfo *MRI) const override
optimizeCompareInstr - Convert the instruction supplying the argument to the comparison into one that...
std::optional< outliner::OutlinedFunction > getOutliningCandidateInfo(std::vector< outliner::Candidate > &RepeatedSequenceLocs) const override
bool getMachineCombinerPatterns(MachineInstr &Root, SmallVectorImpl< MachineCombinerPattern > &Patterns, bool DoRegPressureReduce) const override
Return true when there is potentially a faster code sequence for an instruction chain ending in Root.
static unsigned getLoadStoreImmIdx(unsigned Opc)
Returns the index for the immediate for a given instruction.
static bool isGPRZero(const MachineInstr &MI)
Does this instruction set its full destination register to zero?
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &CmpMask, int64_t &CmpValue) const override
analyzeCompare - For a comparison instruction, return the source registers in SrcReg and SrcReg2,...
bool isMBBSafeToSplitToCold(const MachineBasicBlock &MBB) const override
bool isAsCheapAsAMove(const MachineInstr &MI) const override
static void suppressLdStPair(MachineInstr &MI)
Hint that pairing the given load or store is unprofitable.
static bool isPreLd(const MachineInstr &MI)
Returns whether the instruction is a pre-indexed load.
ArrayRef< std::pair< unsigned, const char * > > getSerializableBitmaskMachineOperandTargetFlags() const override
void copyPhysRegTuple(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, bool KillSrc, unsigned Opcode, llvm::ArrayRef< unsigned > Indices) const
bool optimizeCondBranch(MachineInstr &MI) const override
Replace csincr-branch sequence by simple conditional branch.
static int getMemScale(unsigned Opc)
Scaling factor for (scaled or unscaled) load or store.
bool isCandidateToMergeOrPair(const MachineInstr &MI) const
Return true if this is a load/store that can be potentially paired/merged.
MCInst getNop() const override
static const MachineOperand & getLdStBaseOp(const MachineInstr &MI)
Returns the base register operator of a load/store.
bool isPTestLikeOpcode(unsigned Opc) const
Returns true if the opcode is for an SVE instruction that sets the condition codes as if it's results...
void mergeOutliningCandidateAttributes(Function &F, std::vector< outliner::Candidate > &Candidates) const override
static void decomposeStackOffsetForDwarfOffsets(const StackOffset &Offset, int64_t &ByteSized, int64_t &VGSized)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A debug info location.
Definition: DebugLoc.h:33
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
Definition: MachineInstr.h:68
Flags
Flags values. These may be or'd together.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StackOffset holds a fixed and a scalable offset in bytes.
Definition: TypeSize.h:36
virtual MachineInstr * foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, ArrayRef< unsigned > Ops, MachineBasicBlock::iterator InsertPt, int FrameIndex, LiveIntervals *LIS=nullptr, VirtRegMap *VRM=nullptr) const
Target-dependent implementation for foldMemoryOperand.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
int getSVERevInstr(uint16_t Opcode)
int getSMEPseudoMap(uint16_t Opcode)
static const uint64_t InstrFlagIsWhile
static const uint64_t InstrFlagIsPTestLike
int getSVEPseudoMap(uint16_t Opcode)
int getSVENonRevInstr(uint16_t Opcode)
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
InstrType
Represents how an instruction should be mapped by the outliner.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440
static bool isCondBranchOpcode(int Opc)
MCCFIInstruction createDefCFA(const TargetRegisterInfo &TRI, unsigned FrameReg, unsigned Reg, const StackOffset &Offset, bool LastAdjustmentWasScalable=true)
static bool isPTrueOpcode(unsigned Opc)
int isAArch64FrameOffsetLegal(const MachineInstr &MI, StackOffset &Offset, bool *OutUseUnscaledOp=nullptr, unsigned *OutUnscaledOp=nullptr, int64_t *EmittableOffset=nullptr)
Check if the Offset is a valid frame offset for MI.
static bool isIndirectBranchOpcode(int Opc)
static unsigned getXPACOpcodeForKey(AArch64PACKey::ID K)
Return XPAC opcode to be used for a ptrauth strip using the given key.
MCCFIInstruction createCFAOffset(const TargetRegisterInfo &MRI, unsigned Reg, const StackOffset &OffsetFromDefCFA)
unsigned getBLRCallOpcode(const MachineFunction &MF)
Return opcode to be used for indirect calls.
AArch64FrameOffsetStatus
Use to report the frame offset status in isAArch64FrameOffsetLegal.
@ AArch64FrameOffsetIsLegal
Offset is legal.
@ AArch64FrameOffsetCanUpdate
Offset can apply, at least partly.
@ AArch64FrameOffsetCannotUpdate
Offset cannot apply.
void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, StackOffset Offset, const TargetInstrInfo *TII, MachineInstr::MIFlag=MachineInstr::NoFlags, bool SetNZCV=false, bool NeedsWinCFI=false, bool *HasWinCFI=nullptr, bool EmitCFAOffset=false, StackOffset InitialOffset={}, unsigned FrameReg=AArch64::SP)
emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg plus Offset.
MachineCombinerPattern
These are instruction patterns matched by the machine combiner pass.
std::optional< UsedNZCV > examineCFlagsUse(MachineInstr &MI, MachineInstr &CmpInstr, const TargetRegisterInfo &TRI, SmallVectorImpl< MachineInstr * > *CCUseInstrs=nullptr)
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
static bool isUncondBranchOpcode(int Opc)
static unsigned getPACOpcodeForKey(AArch64PACKey::ID K, bool Zero)
Return PAC opcode to be used for a ptrauth sign using the given key, or its PAC*Z variant that doesn'...
bool rewriteAArch64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx, unsigned FrameReg, StackOffset &Offset, const AArch64InstrInfo *TII)
rewriteAArch64FrameIndex - Rewrite MI to access 'Offset' bytes from the FP.
static const MachineMemOperand::Flags MOSuppressPair
bool isNZCVTouchedInInstructionRange(const MachineInstr &DefMI, const MachineInstr &UseMI, const TargetRegisterInfo *TRI)
Return true if there is an instruction /after/ DefMI and before UseMI which either reads or clobbers ...
static const MachineMemOperand::Flags MOStridedAccess
static unsigned getAUTOpcodeForKey(AArch64PACKey::ID K, bool Zero)
Return AUT opcode to be used for a ptrauth auth using the given key, or its AUT*Z variant that doesn'...
UsedNZCV & operator|=(const UsedNZCV &UsedFlags)
UsedNZCV()=default
An individual sequence of instructions to be replaced with a call to an outlined function.
The information necessary to create an outlined function for some class of candidate.