LLVM 23.0.0git
MachineInstr.h
Go to the documentation of this file.
1//===- llvm/CodeGen/MachineInstr.h - MachineInstr class ---------*- 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 declaration of the MachineInstr class, which is the
10// basic representation for all target dependent machine instructions used by
11// the back end.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_MACHINEINSTR_H
16#define LLVM_CODEGEN_MACHINEINSTR_H
17
18#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/ilist.h"
22#include "llvm/ADT/ilist_node.h"
29#include "llvm/IR/DebugLoc.h"
30#include "llvm/IR/InlineAsm.h"
31#include "llvm/MC/MCInstrDesc.h"
32#include "llvm/MC/MCSymbol.h"
37#include <algorithm>
38#include <cassert>
39#include <cstdint>
40#include <utility>
41
42namespace llvm {
43
44class DILabel;
45class Instruction;
46class MDNode;
47class AAResults;
48class BatchAAResults;
49class DIExpression;
50class DILocalVariable;
51class LiveRegUnits;
53class MachineFunction;
56class raw_ostream;
57template <typename T> class SmallVectorImpl;
58class SmallBitVector;
59class StringRef;
60class TargetInstrInfo;
61class MCRegisterClass;
64
65//===----------------------------------------------------------------------===//
66/// Representation of each machine instruction.
67///
68/// This class isn't a POD type, but it must have a trivial destructor. When a
69/// MachineFunction is deleted, all the contained MachineInstrs are deallocated
70/// without having their destructor called.
71///
72class MachineInstr
73 : public ilist_node_with_parent<MachineInstr, MachineBasicBlock,
74 ilist_sentinel_tracking<true>> {
75public:
77
79
80 /// Flags to specify different kinds of comments to output in
81 /// assembly code. These flags carry semantic information not
82 /// otherwise easily derivable from the IR text.
84 ReloadReuse = 0x1, // higher bits are reserved for target dep comments.
86 TAsmComments = 0x4 // Target Asm comments should start from this value.
87 };
88
89 enum MIFlag {
91 FrameSetup = 1 << 0, // Instruction is used as a part of
92 // function frame setup code.
93 FrameDestroy = 1 << 1, // Instruction is used as a part of
94 // function frame destruction code.
95 BundledPred = 1 << 2, // Instruction has bundled predecessors.
96 BundledSucc = 1 << 3, // Instruction has bundled successors.
97 FmNoNans = 1 << 4, // Instruction does not support Fast
98 // math nan values.
99 FmNoInfs = 1 << 5, // Instruction does not support Fast
100 // math infinity values.
101 FmNsz = 1 << 6, // Instruction is not required to retain
102 // signed zero values.
103 FmArcp = 1 << 7, // Instruction supports Fast math
104 // reciprocal approximations.
105 FmContract = 1 << 8, // Instruction supports Fast math
106 // contraction operations like fma.
107 FmAfn = 1 << 9, // Instruction may map to Fast math
108 // intrinsic approximation.
109 FmReassoc = 1 << 10, // Instruction supports Fast math
110 // reassociation of operand order.
111 NoUWrap = 1 << 11, // Instruction supports binary operator
112 // no unsigned wrap.
113 NoSWrap = 1 << 12, // Instruction supports binary operator
114 // no signed wrap.
115 IsExact = 1 << 13, // Instruction supports division is
116 // known to be exact.
117 NoFPExcept = 1 << 14, // Instruction does not raise
118 // floatint-point exceptions.
119 NoMerge = 1 << 15, // Passes that drop source location info
120 // (e.g. branch folding) should skip
121 // this instruction.
122 Unpredictable = 1 << 16, // Instruction with unpredictable condition.
123 NoConvergent = 1 << 17, // Call does not require convergence guarantees.
124 NonNeg = 1 << 18, // The operand is non-negative.
125 Disjoint = 1 << 19, // Each bit is zero in at least one of the inputs.
126 NoUSWrap = 1 << 20, // Instruction supports geps
127 // no unsigned signed wrap.
128 SameSign = 1 << 21, // Both operands have the same sign.
129 InBounds = 1 << 22, // Pointer arithmetic remains inbounds.
130 // Implies NoUSWrap.
131 LRSplit = 1 << 23 // Instruction for live range split.
132 };
133
134private:
135 const MCInstrDesc *MCID; // Instruction descriptor.
136 MachineBasicBlock *Parent = nullptr; // Pointer to the owning basic block.
137
138 // Operands are allocated by an ArrayRecycler.
139 MachineOperand *Operands = nullptr; // Pointer to the first operand.
140
141#define LLVM_MI_NUMOPERANDS_BITS 24
142#define LLVM_MI_FLAGS_BITS 32
143#define LLVM_MI_ASMPRINTERFLAGS_BITS 8
144
145 /// Number of operands on instruction.
147
148 // OperandCapacity has uint8_t size, so it should be next to NumOperands
149 // to properly pack.
150 using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
151 OperandCapacity CapOperands; // Capacity of the Operands array.
152
153 /// Various bits of additional information about the machine instruction.
154 uint32_t Flags;
155
156 /// Various bits of information used by the AsmPrinter to emit helpful
157 /// comments. This is *not* semantic information. Do not use this for
158 /// anything other than to convey comment information to AsmPrinter.
159 AsmPrinterFlagTy AsmPrinterFlags;
160
161 /// Cached opcode from MCID.
162 uint32_t Opcode;
163
164 /// Unique instruction number. Used by DBG_INSTR_REFs to refer to the values
165 /// defined by this instruction.
166 unsigned DebugInstrNum;
167
168 /// Internal implementation detail class that provides out-of-line storage for
169 /// extra info used by the machine instruction when this info cannot be stored
170 /// in-line within the instruction itself.
171 ///
172 /// This has to be defined eagerly due to the implementation constraints of
173 /// `PointerSumType` where it is used.
174 class ExtraInfo final
175 : TrailingObjects<ExtraInfo, MachineMemOperand *, MCSymbol *, MDNode *,
176 uint32_t, Value *> {
177 public:
178 static ExtraInfo *create(BumpPtrAllocator &Allocator,
180 MCSymbol *PreInstrSymbol = nullptr,
181 MCSymbol *PostInstrSymbol = nullptr,
182 MDNode *HeapAllocMarker = nullptr,
183 MDNode *PCSections = nullptr, uint32_t CFIType = 0,
184 MDNode *MMRAs = nullptr, Value *DS = nullptr) {
185 bool HasPreInstrSymbol = PreInstrSymbol != nullptr;
186 bool HasPostInstrSymbol = PostInstrSymbol != nullptr;
187 bool HasHeapAllocMarker = HeapAllocMarker != nullptr;
188 bool HasMMRAs = MMRAs != nullptr;
189 bool HasCFIType = CFIType != 0;
190 bool HasPCSections = PCSections != nullptr;
191 bool HasDS = DS != nullptr;
192 auto *Result = new (Allocator.Allocate(
193 totalSizeToAlloc<MachineMemOperand *, MCSymbol *, MDNode *, uint32_t,
194 Value *>(
195 MMOs.size(), HasPreInstrSymbol + HasPostInstrSymbol,
196 HasHeapAllocMarker + HasPCSections + HasMMRAs, HasCFIType, HasDS),
197 alignof(ExtraInfo)))
198 ExtraInfo(MMOs.size(), HasPreInstrSymbol, HasPostInstrSymbol,
199 HasHeapAllocMarker, HasPCSections, HasCFIType, HasMMRAs,
200 HasDS);
201
202 // Copy the actual data into the trailing objects.
203 llvm::copy(MMOs, Result->getTrailingObjects<MachineMemOperand *>());
204
205 unsigned MDNodeIdx = 0;
206
207 if (HasPreInstrSymbol)
208 Result->getTrailingObjects<MCSymbol *>()[0] = PreInstrSymbol;
209 if (HasPostInstrSymbol)
210 Result->getTrailingObjects<MCSymbol *>()[HasPreInstrSymbol] =
211 PostInstrSymbol;
212 if (HasHeapAllocMarker)
213 Result->getTrailingObjects<MDNode *>()[MDNodeIdx++] = HeapAllocMarker;
214 if (HasPCSections)
215 Result->getTrailingObjects<MDNode *>()[MDNodeIdx++] = PCSections;
216 if (HasCFIType)
217 Result->getTrailingObjects<uint32_t>()[0] = CFIType;
218 if (HasMMRAs)
219 Result->getTrailingObjects<MDNode *>()[MDNodeIdx++] = MMRAs;
220 if (HasDS)
221 Result->getTrailingObjects<Value *>()[0] = DS;
222
223 return Result;
224 }
225
226 ArrayRef<MachineMemOperand *> getMMOs() const {
228 }
229
230 MCSymbol *getPreInstrSymbol() const {
231 return HasPreInstrSymbol ? getTrailingObjects<MCSymbol *>()[0] : nullptr;
232 }
233
234 MCSymbol *getPostInstrSymbol() const {
235 return HasPostInstrSymbol
236 ? getTrailingObjects<MCSymbol *>()[HasPreInstrSymbol]
237 : nullptr;
238 }
239
240 MDNode *getHeapAllocMarker() const {
241 return HasHeapAllocMarker ? getTrailingObjects<MDNode *>()[0] : nullptr;
242 }
243
244 MDNode *getPCSections() const {
245 return HasPCSections
246 ? getTrailingObjects<MDNode *>()[HasHeapAllocMarker]
247 : nullptr;
248 }
249
250 uint32_t getCFIType() const {
251 return HasCFIType ? getTrailingObjects<uint32_t>()[0] : 0;
252 }
253
254 MDNode *getMMRAMetadata() const {
255 return HasMMRAs ? getTrailingObjects<MDNode *>()[HasHeapAllocMarker +
256 HasPCSections]
257 : nullptr;
258 }
259
260 Value *getDeactivationSymbol() const {
261 return HasDS ? getTrailingObjects<Value *>()[0] : 0;
262 }
263
264 private:
265 friend TrailingObjects;
266
267 // Description of the extra info, used to interpret the actual optional
268 // data appended.
269 //
270 // Note that this is not terribly space optimized. This leaves a great deal
271 // of flexibility to fit more in here later.
272 const int NumMMOs;
273 const bool HasPreInstrSymbol;
274 const bool HasPostInstrSymbol;
275 const bool HasHeapAllocMarker;
276 const bool HasPCSections;
277 const bool HasCFIType;
278 const bool HasMMRAs;
279 const bool HasDS;
280
281 // Implement the `TrailingObjects` internal API.
282 size_t numTrailingObjects(OverloadToken<MachineMemOperand *>) const {
283 return NumMMOs;
284 }
285 size_t numTrailingObjects(OverloadToken<MCSymbol *>) const {
286 return HasPreInstrSymbol + HasPostInstrSymbol;
287 }
288 size_t numTrailingObjects(OverloadToken<MDNode *>) const {
289 return HasHeapAllocMarker + HasPCSections;
290 }
291 size_t numTrailingObjects(OverloadToken<uint32_t>) const {
292 return HasCFIType;
293 }
294 size_t numTrailingObjects(OverloadToken<Value *>) const { return HasDS; }
295
296 // Just a boring constructor to allow us to initialize the sizes. Always use
297 // the `create` routine above.
298 ExtraInfo(int NumMMOs, bool HasPreInstrSymbol, bool HasPostInstrSymbol,
299 bool HasHeapAllocMarker, bool HasPCSections, bool HasCFIType,
300 bool HasMMRAs, bool HasDS)
301 : NumMMOs(NumMMOs), HasPreInstrSymbol(HasPreInstrSymbol),
302 HasPostInstrSymbol(HasPostInstrSymbol),
303 HasHeapAllocMarker(HasHeapAllocMarker), HasPCSections(HasPCSections),
304 HasCFIType(HasCFIType), HasMMRAs(HasMMRAs), HasDS(HasDS) {}
305 };
306
307 /// Enumeration of the kinds of inline extra info available. It is important
308 /// that the `MachineMemOperand` inline kind has a tag value of zero to make
309 /// it accessible as an `ArrayRef`.
310 enum ExtraInfoInlineKinds {
311 EIIK_MMO = 0,
312 EIIK_PreInstrSymbol,
313 EIIK_PostInstrSymbol,
314 EIIK_OutOfLine
315 };
316
317 // We store extra information about the instruction here. The common case is
318 // expected to be nothing or a single pointer (typically a MMO or a symbol).
319 // We work to optimize this common case by storing it inline here rather than
320 // requiring a separate allocation, but we fall back to an allocation when
321 // multiple pointers are needed.
322 PointerSumType<ExtraInfoInlineKinds,
323 PointerSumTypeMember<EIIK_MMO, MachineMemOperand *>,
324 PointerSumTypeMember<EIIK_PreInstrSymbol, MCSymbol *>,
325 PointerSumTypeMember<EIIK_PostInstrSymbol, MCSymbol *>,
326 PointerSumTypeMember<EIIK_OutOfLine, ExtraInfo *>>
327 Info;
328
329 DebugLoc DbgLoc; // Source line information.
330
331 // Intrusive list support
332 friend struct ilist_traits<MachineInstr>;
334 void setParent(MachineBasicBlock *P) { Parent = P; }
335
336 /// This constructor creates a copy of the given
337 /// MachineInstr in the given MachineFunction.
339
340 /// This constructor create a MachineInstr and add the implicit operands.
341 /// It reserves space for number of operands specified by
342 /// MCInstrDesc. An explicit DebugLoc is supplied.
344 bool NoImp = false);
345
346 // MachineInstrs are pool-allocated and owned by MachineFunction.
347 friend class MachineFunction;
348
349 void
350 dumprImpl(const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth,
351 SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const;
352
353 static bool opIsRegDef(const MachineOperand &Op) {
354 return Op.isReg() && Op.isDef();
355 }
356
357 static bool opIsRegUse(const MachineOperand &Op) {
358 return Op.isReg() && Op.isUse();
359 }
360
361 MutableArrayRef<MachineOperand> operands_impl() {
362 return {Operands, NumOperands};
363 }
364 ArrayRef<MachineOperand> operands_impl() const {
365 return {Operands, NumOperands};
366 }
367
368public:
369 MachineInstr(const MachineInstr &) = delete;
370 MachineInstr &operator=(const MachineInstr &) = delete;
371 // Use MachineFunction::DeleteMachineInstr() instead.
372 ~MachineInstr() = delete;
373
374 const MachineBasicBlock* getParent() const { return Parent; }
375 MachineBasicBlock* getParent() { return Parent; }
376
377 /// Move the instruction before \p MovePos.
378 LLVM_ABI void moveBefore(MachineInstr *MovePos);
379
380 /// Return the function that contains the basic block that this instruction
381 /// belongs to.
382 ///
383 /// Note: this is undefined behaviour if the instruction does not have a
384 /// parent.
385 LLVM_ABI const MachineFunction *getMF() const;
387 return const_cast<MachineFunction *>(
388 static_cast<const MachineInstr *>(this)->getMF());
389 }
390
391 /// Return the asm printer flags bitvector.
392 AsmPrinterFlagTy getAsmPrinterFlags() const { return AsmPrinterFlags; }
393
394 /// Clear the AsmPrinter bitvector.
395 void clearAsmPrinterFlags() { AsmPrinterFlags = 0; }
396
397 /// Return whether an AsmPrinter flag is set.
400 "Flag is out of range for the AsmPrinterFlags field");
401 return AsmPrinterFlags & Flag;
402 }
403
404 /// Set a flag for the AsmPrinter.
407 "Flag is out of range for the AsmPrinterFlags field");
408 AsmPrinterFlags |= Flag;
409 }
410
411 /// Clear specific AsmPrinter flags.
414 "Flag is out of range for the AsmPrinterFlags field");
415 AsmPrinterFlags &= ~Flag;
416 }
417
418 /// Return the MI flags bitvector.
420 return Flags;
421 }
422
423 /// Return whether an MI flag is set.
424 bool getFlag(MIFlag Flag) const {
425 assert(isUInt<LLVM_MI_FLAGS_BITS>(unsigned(Flag)) &&
426 "Flag is out of range for the Flags field");
427 return Flags & Flag;
428 }
429
430 /// Set a MI flag.
431 void setFlag(MIFlag Flag) {
432 assert(isUInt<LLVM_MI_FLAGS_BITS>(unsigned(Flag)) &&
433 "Flag is out of range for the Flags field");
434 Flags |= (uint32_t)Flag;
435 }
436
437 void setFlags(unsigned flags) {
439 "flags to be set are out of range for the Flags field");
440 // Filter out the automatically maintained flags.
441 unsigned Mask = BundledPred | BundledSucc;
442 Flags = (Flags & Mask) | (flags & ~Mask);
443 }
444
445 /// clearFlag - Clear a MI flag.
446 void clearFlag(MIFlag Flag) {
447 assert(isUInt<LLVM_MI_FLAGS_BITS>(unsigned(Flag)) &&
448 "Flag to clear is out of range for the Flags field");
449 Flags &= ~((uint32_t)Flag);
450 }
451
452 void clearFlags(unsigned flags) {
454 "flags to be cleared are out of range for the Flags field");
455 Flags &= ~flags;
456 }
457
458 /// Return true if MI is in a bundle (but not the first MI in a bundle).
459 ///
460 /// A bundle looks like this before it's finalized:
461 /// ----------------
462 /// | MI |
463 /// ----------------
464 /// |
465 /// ----------------
466 /// | MI * |
467 /// ----------------
468 /// |
469 /// ----------------
470 /// | MI * |
471 /// ----------------
472 /// In this case, the first MI starts a bundle but is not inside a bundle, the
473 /// next 2 MIs are considered "inside" the bundle.
474 ///
475 /// After a bundle is finalized, it looks like this:
476 /// ----------------
477 /// | Bundle |
478 /// ----------------
479 /// |
480 /// ----------------
481 /// | MI * |
482 /// ----------------
483 /// |
484 /// ----------------
485 /// | MI * |
486 /// ----------------
487 /// |
488 /// ----------------
489 /// | MI * |
490 /// ----------------
491 /// The first instruction has the special opcode "BUNDLE". It's not "inside"
492 /// a bundle, but the next three MIs are.
493 bool isInsideBundle() const {
494 return getFlag(BundledPred);
495 }
496
497 /// Return true if this instruction part of a bundle. This is true
498 /// if either itself or its following instruction is marked "InsideBundle".
499 bool isBundled() const {
501 }
502
503 /// Return true if this instruction is part of a bundle, and it is not the
504 /// first instruction in the bundle.
505 bool isBundledWithPred() const { return getFlag(BundledPred); }
506
507 /// Return true if this instruction is part of a bundle, and it is not the
508 /// last instruction in the bundle.
509 bool isBundledWithSucc() const { return getFlag(BundledSucc); }
510
511 /// Bundle this instruction with its predecessor. This can be an unbundled
512 /// instruction, or it can be the first instruction in a bundle.
514
515 /// Bundle this instruction with its successor. This can be an unbundled
516 /// instruction, or it can be the last instruction in a bundle.
518
519 /// Break bundle above this instruction.
521
522 /// Break bundle below this instruction.
524
525 /// Returns the debug location id of this MachineInstr.
526 const DebugLoc &getDebugLoc() const { return DbgLoc; }
527
528 /// Return the operand containing the offset to be used if this DBG_VALUE
529 /// instruction is indirect; will be an invalid register if this value is
530 /// not indirect, and an immediate with value 0 otherwise.
532 assert(isNonListDebugValue() && "not a DBG_VALUE");
533 return getOperand(1);
534 }
536 assert(isNonListDebugValue() && "not a DBG_VALUE");
537 return getOperand(1);
538 }
539
540 /// Return the operand for the debug variable referenced by
541 /// this DBG_VALUE instruction.
544
545 /// Return the debug variable referenced by
546 /// this DBG_VALUE instruction.
548
549 /// Return the operand for the complex address expression referenced by
550 /// this DBG_VALUE instruction.
553
554 /// Return the complex address expression referenced by
555 /// this DBG_VALUE instruction.
557
558 /// Return the debug label referenced by
559 /// this DBG_LABEL instruction.
560 LLVM_ABI const DILabel *getDebugLabel() const;
561
562 /// Fetch the instruction number of this MachineInstr. If it does not have
563 /// one already, a new and unique number will be assigned.
564 LLVM_ABI unsigned getDebugInstrNum();
565
566 /// Fetch instruction number of this MachineInstr -- but before it's inserted
567 /// into \p MF. Needed for transformations that create an instruction but
568 /// don't immediately insert them.
570
571 /// Examine the instruction number of this MachineInstr. May be zero if
572 /// it hasn't been assigned a number yet.
573 unsigned peekDebugInstrNum() const { return DebugInstrNum; }
574
575 /// Set instruction number of this MachineInstr. Avoid using unless you're
576 /// deserializing this information.
577 void setDebugInstrNum(unsigned Num) { DebugInstrNum = Num; }
578
579 /// Drop any variable location debugging information associated with this
580 /// instruction. Use when an instruction is modified in such a way that it no
581 /// longer defines the value it used to. Variable locations using that value
582 /// will be dropped.
583 void dropDebugNumber() { DebugInstrNum = 0; }
584
585 /// For inline asm, get the !srcloc metadata node if we have it, and decode
586 /// the loc cookie from it.
587 LLVM_ABI const MDNode *getLocCookieMD() const;
588
589 /// Emit an error referring to the source location of this instruction. This
590 /// should only be used for inline assembly that is somehow impossible to
591 /// compile. Other errors should have been handled much earlier.
592 LLVM_ABI void emitInlineAsmError(const Twine &ErrMsg) const;
593
594 // Emit an error in the LLVMContext referring to the source location of this
595 // instruction, if available.
596 LLVM_ABI void emitGenericError(const Twine &ErrMsg) const;
597
598 /// Returns the target instruction descriptor of this MachineInstr.
599 const MCInstrDesc &getDesc() const { return *MCID; }
600
601 /// Returns the opcode of this MachineInstr.
602 unsigned getOpcode() const { return Opcode; }
603
604 /// Retuns the total number of operands.
605 unsigned getNumOperands() const { return NumOperands; }
606
607 /// Returns the total number of operands which are debug locations.
608 unsigned getNumDebugOperands() const { return size(debug_operands()); }
609
610 const MachineOperand &getOperand(unsigned i) const {
611 return operands_impl()[i];
612 }
613 MachineOperand &getOperand(unsigned i) { return operands_impl()[i]; }
614
616 assert(Index < getNumDebugOperands() && "getDebugOperand() out of range!");
617 return *(debug_operands().begin() + Index);
618 }
619 const MachineOperand &getDebugOperand(unsigned Index) const {
620 assert(Index < getNumDebugOperands() && "getDebugOperand() out of range!");
621 return *(debug_operands().begin() + Index);
622 }
623
624 /// Returns whether this debug value has at least one debug operand with the
625 /// register \p Reg.
627 return any_of(debug_operands(), [Reg](const MachineOperand &Op) {
628 return Op.isReg() && Op.getReg() == Reg;
629 });
630 }
631
632 /// Returns a range of all of the operands that correspond to a debug use of
633 /// \p Reg.
635 const MachineOperand *, std::function<bool(const MachineOperand &Op)>>>
639 std::function<bool(MachineOperand &Op)>>>
641
642 bool isDebugOperand(const MachineOperand *Op) const {
643 return Op >= adl_begin(debug_operands()) && Op <= adl_end(debug_operands());
644 }
645
646 unsigned getDebugOperandIndex(const MachineOperand *Op) const {
647 assert(isDebugOperand(Op) && "Expected a debug operand.");
648 return std::distance(adl_begin(debug_operands()), Op);
649 }
650
651 /// Returns the total number of definitions.
652 unsigned getNumDefs() const {
653 return getNumExplicitDefs() + MCID->implicit_defs().size();
654 }
655
656 /// Returns true if the instruction has implicit definition.
657 bool hasImplicitDef() const {
658 for (const MachineOperand &MO : implicit_operands())
659 if (MO.isDef())
660 return true;
661 return false;
662 }
663
664 /// Returns the implicit operands number.
665 unsigned getNumImplicitOperands() const {
667 }
668
669 /// Return true if operand \p OpIdx is a subregister index.
670 bool isOperandSubregIdx(unsigned OpIdx) const {
671 assert(getOperand(OpIdx).isImm() && "Expected MO_Immediate operand type.");
672 if (isExtractSubreg() && OpIdx == 2)
673 return true;
674 if (isInsertSubreg() && OpIdx == 3)
675 return true;
676 if (isRegSequence() && OpIdx > 1 && (OpIdx % 2) == 0)
677 return true;
678 if (isSubregToReg() && OpIdx == 2)
679 return true;
680 return false;
681 }
682
683 /// Returns the number of non-implicit operands.
684 LLVM_ABI unsigned getNumExplicitOperands() const;
685
686 /// Returns the number of non-implicit definitions.
687 LLVM_ABI unsigned getNumExplicitDefs() const;
688
689 /// iterator/begin/end - Iterate over all operands of a machine instruction.
690
691 // The operands must always be in the following order:
692 // - explicit reg defs,
693 // - other explicit operands (reg uses, immediates, etc.),
694 // - implicit reg defs
695 // - implicit reg uses
698
701
702 mop_iterator operands_begin() { return Operands; }
703 mop_iterator operands_end() { return Operands + NumOperands; }
704
705 const_mop_iterator operands_begin() const { return Operands; }
706 const_mop_iterator operands_end() const { return Operands + NumOperands; }
707
708 mop_range operands() { return operands_impl(); }
709 const_mop_range operands() const { return operands_impl(); }
710
712 return operands_impl().take_front(getNumExplicitOperands());
713 }
715 return operands_impl().take_front(getNumExplicitOperands());
716 }
718 return operands_impl().drop_front(getNumExplicitOperands());
719 }
721 return operands_impl().drop_front(getNumExplicitOperands());
722 }
723
724 /// Returns all operands that are used to determine the variable
725 /// location for this DBG_VALUE instruction.
727 assert(isDebugValueLike() && "Must be a debug value instruction.");
728 return isNonListDebugValue() ? operands_impl().take_front(1)
729 : operands_impl().drop_front(2);
730 }
731 /// \copydoc debug_operands()
733 assert(isDebugValueLike() && "Must be a debug value instruction.");
734 return isNonListDebugValue() ? operands_impl().take_front(1)
735 : operands_impl().drop_front(2);
736 }
737 /// Returns all explicit operands that are register definitions.
738 /// Implicit definition are not included!
739 mop_range defs() { return operands_impl().take_front(getNumExplicitDefs()); }
740 /// \copydoc defs()
742 return operands_impl().take_front(getNumExplicitDefs());
743 }
744 /// Returns all operands which may be register uses.
745 /// This may include unrelated operands which are not register uses.
746 mop_range uses() { return operands_impl().drop_front(getNumExplicitDefs()); }
747 /// \copydoc uses()
749 return operands_impl().drop_front(getNumExplicitDefs());
750 }
752 return operands_impl()
753 .take_front(getNumExplicitOperands())
754 .drop_front(getNumExplicitDefs());
755 }
757 return operands_impl()
758 .take_front(getNumExplicitOperands())
759 .drop_front(getNumExplicitDefs());
760 }
761
766
767 /// Returns an iterator range over all operands that are (explicit or
768 /// implicit) register defs.
770 return make_filter_range(operands(), opIsRegDef);
771 }
772 /// \copydoc all_defs()
774 return make_filter_range(operands(), opIsRegDef);
775 }
776
777 /// Returns an iterator range over all operands that are (explicit or
778 /// implicit) register uses.
780 return make_filter_range(uses(), opIsRegUse);
781 }
782 /// \copydoc all_uses()
784 return make_filter_range(uses(), opIsRegUse);
785 }
786
787 /// Returns the number of the operand iterator \p I points to.
789 return I - operands_begin();
790 }
791
792 /// Access to memory operands of the instruction. If there are none, that does
793 /// not imply anything about whether the function accesses memory. Instead,
794 /// the caller must behave conservatively.
796 if (!Info)
797 return {};
798
799 if (Info.is<EIIK_MMO>())
800 return ArrayRef(Info.getAddrOfZeroTagPointer(), 1);
801
802 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
803 return EI->getMMOs();
804
805 return {};
806 }
807
808 /// Access to memory operands of the instruction.
809 ///
810 /// If `memoperands_begin() == memoperands_end()`, that does not imply
811 /// anything about whether the function accesses memory. Instead, the caller
812 /// must behave conservatively.
813 mmo_iterator memoperands_begin() const { return memoperands().begin(); }
814
815 /// Access to memory operands of the instruction.
816 ///
817 /// If `memoperands_begin() == memoperands_end()`, that does not imply
818 /// anything about whether the function accesses memory. Instead, the caller
819 /// must behave conservatively.
820 mmo_iterator memoperands_end() const { return memoperands().end(); }
821
822 /// Return true if we don't have any memory operands which described the
823 /// memory access done by this instruction. If this is true, calling code
824 /// must be conservative.
825 bool memoperands_empty() const { return memoperands().empty(); }
826
827 /// Return true if this instruction has exactly one MachineMemOperand.
828 bool hasOneMemOperand() const { return memoperands().size() == 1; }
829
830 /// Return the number of memory operands.
831 unsigned getNumMemOperands() const { return memoperands().size(); }
832
833 /// Helper to extract a pre-instruction symbol if one has been added.
835 if (!Info)
836 return nullptr;
837 if (MCSymbol *S = Info.get<EIIK_PreInstrSymbol>())
838 return S;
839 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
840 return EI->getPreInstrSymbol();
841
842 return nullptr;
843 }
844
845 /// Helper to extract a post-instruction symbol if one has been added.
847 if (!Info)
848 return nullptr;
849 if (MCSymbol *S = Info.get<EIIK_PostInstrSymbol>())
850 return S;
851 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
852 return EI->getPostInstrSymbol();
853
854 return nullptr;
855 }
856
857 /// Helper to extract a heap alloc marker if one has been added.
859 if (!Info)
860 return nullptr;
861 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
862 return EI->getHeapAllocMarker();
863
864 return nullptr;
865 }
866
867 /// Helper to extract PCSections metadata target sections.
869 if (!Info)
870 return nullptr;
871 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
872 return EI->getPCSections();
873
874 return nullptr;
875 }
876
877 /// Helper to extract mmra.op metadata.
879 if (!Info)
880 return nullptr;
881 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
882 return EI->getMMRAMetadata();
883 return nullptr;
884 }
885
887 if (!Info)
888 return nullptr;
889 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
890 return EI->getDeactivationSymbol();
891 return nullptr;
892 }
893
894 /// Helper to extract a CFI type hash if one has been added.
896 if (!Info)
897 return 0;
898 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
899 return EI->getCFIType();
900
901 return 0;
902 }
903
904 /// API for querying MachineInstr properties. They are the same as MCInstrDesc
905 /// queries but they are bundle aware.
906
908 IgnoreBundle, // Ignore bundles
909 AnyInBundle, // Return true if any instruction in bundle has property
910 AllInBundle // Return true if all instructions in bundle have property
911 };
912
913 /// Return true if the instruction (or in the case of a bundle,
914 /// the instructions inside the bundle) has the specified property.
915 /// The first argument is the property being queried.
916 /// The second argument indicates whether the query should look inside
917 /// instruction bundles.
918 bool hasProperty(unsigned MCFlag, QueryType Type = AnyInBundle) const {
919 assert(MCFlag < 64 &&
920 "MCFlag out of range for bit mask in getFlags/hasPropertyInBundle.");
921 // Inline the fast path for unbundled or bundle-internal instructions.
923 return getDesc().getFlags() & (1ULL << MCFlag);
924
925 // If this is the first instruction in a bundle, take the slow path.
926 return hasPropertyInBundle(1ULL << MCFlag, Type);
927 }
928
929 /// Return true if this is an instruction that should go through the usual
930 /// legalization steps.
934
935 /// Return true if this instruction can have a variable number of operands.
936 /// In this case, the variable operands will be after the normal
937 /// operands but before the implicit definitions and uses (if any are
938 /// present).
942
943 /// Set if this instruction has an optional definition, e.g.
944 /// ARM instructions which can set condition code if 's' bit is set.
948
949 /// Return true if this is a pseudo instruction that doesn't
950 /// correspond to a real machine instruction.
953 }
954
955 /// Return true if this instruction doesn't produce any output in the form of
956 /// executable instructions.
960
963 }
964
965 /// Return true if this is an instruction that marks the end of an EH scope,
966 /// i.e., a catchpad or a cleanuppad instruction.
970
972 return hasProperty(MCID::Call, Type);
973 }
974
975 /// Return true if this is a call instruction that may have an additional
976 /// information associated with it.
977 LLVM_ABI bool
979
980 /// Return true if copying, moving, or erasing this instruction requires
981 /// updating additional call info (see \ref copyCallInfo, \ref moveCallInfo,
982 /// \ref eraseCallInfo).
984
985 /// Returns true if the specified instruction stops control flow
986 /// from executing the instruction immediately following it. Examples include
987 /// unconditional branches and return instructions.
990 }
991
992 /// Returns true if this instruction part of the terminator for a basic block.
993 /// Typically this is things like return and branch instructions.
994 ///
995 /// Various passes use this to insert code into the bottom of a basic block,
996 /// but before control flow occurs.
1000
1001 /// Returns true if this is a conditional, unconditional, or indirect branch.
1002 /// Predicates below can be used to discriminate between
1003 /// these cases, and the TargetInstrInfo::analyzeBranch method can be used to
1004 /// get more information.
1006 return hasProperty(MCID::Branch, Type);
1007 }
1008
1009 /// Return true if this is an indirect branch, such as a
1010 /// branch through a register.
1014
1015 /// Return true if this is a branch which may fall
1016 /// through to the next instruction or may transfer control flow to some other
1017 /// block. The TargetInstrInfo::analyzeBranch method can be used to get more
1018 /// information about this branch.
1022
1023 /// Return true if this is a branch which always
1024 /// transfers control flow to some other block. The
1025 /// TargetInstrInfo::analyzeBranch method can be used to get more information
1026 /// about this branch.
1030
1031 /// Return true if this instruction has a predicate operand that
1032 /// controls execution. It may be set to 'always', or may be set to other
1033 /// values. There are various methods in TargetInstrInfo that can be used to
1034 /// control and modify the predicate in this instruction.
1036 // If it's a bundle than all bundled instructions must be predicable for this
1037 // to return true.
1039 }
1040
1041 /// Return true if this instruction is a comparison.
1044 }
1045
1046 /// Return true if this instruction is a move immediate
1047 /// (including conditional moves) instruction.
1051
1052 /// Return true if this instruction is a register move.
1053 /// (including moving values from subreg to reg)
1056 }
1057
1058 /// Return true if this instruction is a bitcast instruction.
1061 }
1062
1063 /// Return true if this instruction is a select instruction.
1065 return hasProperty(MCID::Select, Type);
1066 }
1067
1068 /// Return true if this instruction cannot be safely duplicated.
1069 /// For example, if the instruction has a unique labels attached
1070 /// to it, duplicating it would cause multiple definition errors.
1073 return true;
1075 }
1076
1077 /// Return true if this instruction is convergent.
1078 /// Convergent instructions can not be made control-dependent on any
1079 /// additional values.
1081 if (isInlineAsm()) {
1082 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
1083 if (ExtraInfo & InlineAsm::Extra_IsConvergent)
1084 return true;
1085 }
1086 if (getFlag(NoConvergent))
1087 return false;
1089 }
1090
1091 /// Returns true if the specified instruction has a delay slot
1092 /// which must be filled by the code generator.
1096
1097 /// Return true for instructions that can be folded as
1098 /// memory operands in other instructions. The most common use for this
1099 /// is instructions that are simple loads from memory that don't modify
1100 /// the loaded value in any way, but it can also be used for instructions
1101 /// that can be expressed as constant-pool loads, such as V_SETALLONES
1102 /// on x86, to allow them to be folded when it is beneficial.
1103 /// This should only be set on instructions that return a value in their
1104 /// only virtual register definition.
1108
1109 /// Return true if this instruction behaves
1110 /// the same way as the generic REG_SEQUENCE instructions.
1111 /// E.g., on ARM,
1112 /// dX VMOVDRR rY, rZ
1113 /// is equivalent to
1114 /// dX = REG_SEQUENCE rY, ssub_0, rZ, ssub_1.
1115 ///
1116 /// Note that for the optimizers to be able to take advantage of
1117 /// this property, TargetInstrInfo::getRegSequenceLikeInputs has to be
1118 /// override accordingly.
1122
1123 /// Return true if this instruction behaves
1124 /// the same way as the generic EXTRACT_SUBREG instructions.
1125 /// E.g., on ARM,
1126 /// rX, rY VMOVRRD dZ
1127 /// is equivalent to two EXTRACT_SUBREG:
1128 /// rX = EXTRACT_SUBREG dZ, ssub_0
1129 /// rY = EXTRACT_SUBREG dZ, ssub_1
1130 ///
1131 /// Note that for the optimizers to be able to take advantage of
1132 /// this property, TargetInstrInfo::getExtractSubregLikeInputs has to be
1133 /// override accordingly.
1137
1138 /// Return true if this instruction behaves
1139 /// the same way as the generic INSERT_SUBREG instructions.
1140 /// E.g., on ARM,
1141 /// dX = VSETLNi32 dY, rZ, Imm
1142 /// is equivalent to a INSERT_SUBREG:
1143 /// dX = INSERT_SUBREG dY, rZ, translateImmToSubIdx(Imm)
1144 ///
1145 /// Note that for the optimizers to be able to take advantage of
1146 /// this property, TargetInstrInfo::getInsertSubregLikeInputs has to be
1147 /// override accordingly.
1151
1152 //===--------------------------------------------------------------------===//
1153 // Side Effect Analysis
1154 //===--------------------------------------------------------------------===//
1155
1156 /// Return true if this instruction could possibly read memory.
1157 /// Instructions with this flag set are not necessarily simple load
1158 /// instructions, they may load a value and modify it, for example.
1160 if (isInlineAsm()) {
1161 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
1162 if (ExtraInfo & InlineAsm::Extra_MayLoad)
1163 return true;
1164 }
1166 }
1167
1168 /// Return true if this instruction could possibly modify memory.
1169 /// Instructions with this flag set are not necessarily simple store
1170 /// instructions, they may store a modified value based on their operands, or
1171 /// may not actually modify anything, for example.
1173 if (isInlineAsm()) {
1174 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
1175 if (ExtraInfo & InlineAsm::Extra_MayStore)
1176 return true;
1177 }
1179 }
1180
1181 /// Return true if this instruction could possibly read or modify memory.
1183 return mayLoad(Type) || mayStore(Type);
1184 }
1185
1186 /// Return true if this instruction could possibly raise a floating-point
1187 /// exception. This is the case if the instruction is a floating-point
1188 /// instruction that can in principle raise an exception, as indicated
1189 /// by the MCID::MayRaiseFPException property, *and* at the same time,
1190 /// the instruction is used in a context where we expect floating-point
1191 /// exceptions are not disabled, as indicated by the NoFPExcept MI flag.
1196
1197 //===--------------------------------------------------------------------===//
1198 // Flags that indicate whether an instruction can be modified by a method.
1199 //===--------------------------------------------------------------------===//
1200
1201 /// Return true if this may be a 2- or 3-address
1202 /// instruction (of the form "X = op Y, Z, ..."), which produces the same
1203 /// result if Y and Z are exchanged. If this flag is set, then the
1204 /// TargetInstrInfo::commuteInstruction method may be used to hack on the
1205 /// instruction.
1206 ///
1207 /// Note that this flag may be set on instructions that are only commutable
1208 /// sometimes. In these cases, the call to commuteInstruction will fail.
1209 /// Also note that some instructions require non-trivial modification to
1210 /// commute them.
1214
1215 /// Return true if this is a 2-address instruction
1216 /// which can be changed into a 3-address instruction if needed. Doing this
1217 /// transformation can be profitable in the register allocator, because it
1218 /// means that the instruction can use a 2-address form if possible, but
1219 /// degrade into a less efficient form if the source and dest register cannot
1220 /// be assigned to the same register. For example, this allows the x86
1221 /// backend to turn a "shl reg, 3" instruction into an LEA instruction, which
1222 /// is the same speed as the shift but has bigger code size.
1223 ///
1224 /// If this returns true, then the target must implement the
1225 /// TargetInstrInfo::convertToThreeAddress method for this instruction, which
1226 /// is allowed to fail if the transformation isn't valid for this specific
1227 /// instruction (e.g. shl reg, 4 on x86).
1228 ///
1232
1233 /// Return true if this instruction requires
1234 /// custom insertion support when the DAG scheduler is inserting it into a
1235 /// machine basic block. If this is true for the instruction, it basically
1236 /// means that it is a pseudo instruction used at SelectionDAG time that is
1237 /// expanded out into magic code by the target when MachineInstrs are formed.
1238 ///
1239 /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method
1240 /// is used to insert this into the MachineBasicBlock.
1244
1245 /// Return true if this instruction requires *adjustment*
1246 /// after instruction selection by calling a target hook. For example, this
1247 /// can be used to fill in ARM 's' optional operand depending on whether
1248 /// the conditional flag register is used.
1252
1253 /// Returns true if this instruction is a candidate for remat.
1254 /// This flag is deprecated, please don't use it anymore. If this
1255 /// flag is set, the isReMaterializableImpl() method is called to
1256 /// verify the instruction is really rematerializable.
1258 // It's only possible to re-mat a bundle if all bundled instructions are
1259 // re-materializable.
1261 }
1262
1263 /// Returns true if this instruction has the same cost (or less) than a move
1264 /// instruction. This is useful during certain types of optimizations
1265 /// (e.g., remat during two-address conversion or machine licm)
1266 /// where we would like to remat or hoist the instruction, but not if it costs
1267 /// more than moving the instruction into the appropriate register. Note, we
1268 /// are not marking copies from and to the same register class with this flag.
1270 // Only returns true for a bundle if all bundled instructions are cheap.
1272 }
1273
1274 /// Returns true if this instruction source operands
1275 /// have special register allocation requirements that are not captured by the
1276 /// operand register classes. e.g. ARM::STRD's two source registers must be an
1277 /// even / odd pair, ARM::STM registers have to be in ascending order.
1278 /// Post-register allocation passes should not attempt to change allocations
1279 /// for sources of instructions with this flag.
1283
1284 /// Returns true if this instruction def operands
1285 /// have special register allocation requirements that are not captured by the
1286 /// operand register classes. e.g. ARM::LDRD's two def registers must be an
1287 /// even / odd pair, ARM::LDM registers have to be in ascending order.
1288 /// Post-register allocation passes should not attempt to change allocations
1289 /// for definitions of instructions with this flag.
1293
1295 CheckDefs, // Check all operands for equality
1296 CheckKillDead, // Check all operands including kill / dead markers
1297 IgnoreDefs, // Ignore all definitions
1298 IgnoreVRegDefs // Ignore virtual register definitions
1299 };
1300
1301 /// Return true if this instruction is identical to \p Other.
1302 /// Two instructions are identical if they have the same opcode and all their
1303 /// operands are identical (with respect to MachineOperand::isIdenticalTo()).
1304 /// Note that this means liveness related flags (dead, undef, kill) do not
1305 /// affect the notion of identical.
1307 MICheckType Check = CheckDefs) const;
1308
1309 /// Returns true if this instruction is a debug instruction that represents an
1310 /// identical debug value to \p Other.
1311 /// This function considers these debug instructions equivalent if they have
1312 /// identical variables, debug locations, and debug operands, and if the
1313 /// DIExpressions combined with the directness flags are equivalent.
1315
1316 /// Unlink 'this' from the containing basic block, and return it without
1317 /// deleting it.
1318 ///
1319 /// This function can not be used on bundled instructions, use
1320 /// removeFromBundle() to remove individual instructions from a bundle.
1322
1323 /// Unlink this instruction from its basic block and return it without
1324 /// deleting it.
1325 ///
1326 /// If the instruction is part of a bundle, the other instructions in the
1327 /// bundle remain bundled.
1329
1330 /// Unlink 'this' from the containing basic block and delete it.
1331 ///
1332 /// If this instruction is the header of a bundle, the whole bundle is erased.
1333 /// This function can not be used for instructions inside a bundle, use
1334 /// eraseFromBundle() to erase individual bundled instructions.
1335 /// \returns the iterator following the erased instruction. If this is the
1336 /// header of a bundle it returns the iterator following the erased bundle
1337 /// iterator.
1339
1340 /// Unlink 'this' from its basic block and delete it.
1341 ///
1342 /// If the instruction is part of a bundle, the other instructions in the
1343 /// bundle remain bundled.
1345
1346 bool isEHLabel() const { return getOpcode() == TargetOpcode::EH_LABEL; }
1347 bool isGCLabel() const { return getOpcode() == TargetOpcode::GC_LABEL; }
1348 bool isAnnotationLabel() const {
1349 return getOpcode() == TargetOpcode::ANNOTATION_LABEL;
1350 }
1351
1352 bool isLifetimeMarker() const {
1353 return getOpcode() == TargetOpcode::LIFETIME_START ||
1354 getOpcode() == TargetOpcode::LIFETIME_END;
1355 }
1356
1357 /// Returns true if the MachineInstr represents a label.
1358 bool isLabel() const {
1359 return isEHLabel() || isGCLabel() || isAnnotationLabel();
1360 }
1361
1362 bool isCFIInstruction() const {
1363 return getOpcode() == TargetOpcode::CFI_INSTRUCTION;
1364 }
1365
1366 bool isPseudoProbe() const {
1367 return getOpcode() == TargetOpcode::PSEUDO_PROBE;
1368 }
1369
1370 // True if the instruction represents a position in the function.
1371 bool isPosition() const { return isLabel() || isCFIInstruction(); }
1372
1373 bool isNonListDebugValue() const {
1374 return getOpcode() == TargetOpcode::DBG_VALUE;
1375 }
1376 bool isDebugValueList() const {
1377 return getOpcode() == TargetOpcode::DBG_VALUE_LIST;
1378 }
1379 bool isDebugValue() const {
1381 }
1382 bool isDebugLabel() const { return getOpcode() == TargetOpcode::DBG_LABEL; }
1383 bool isDebugRef() const { return getOpcode() == TargetOpcode::DBG_INSTR_REF; }
1384 bool isDebugValueLike() const { return isDebugValue() || isDebugRef(); }
1385 bool isDebugPHI() const { return getOpcode() == TargetOpcode::DBG_PHI; }
1386 bool isDebugInstr() const {
1387 return isDebugValue() || isDebugLabel() || isDebugRef() || isDebugPHI();
1388 }
1390 return isDebugInstr() || isPseudoProbe();
1391 }
1392
1393 bool isDebugOffsetImm() const {
1395 }
1396
1397 /// A DBG_VALUE is indirect iff the location operand is a register and
1398 /// the offset operand is an immediate.
1400 return isDebugOffsetImm() && getDebugOperand(0).isReg();
1401 }
1402
1403 /// A DBG_VALUE is an entry value iff its debug expression contains the
1404 /// DW_OP_LLVM_entry_value operation.
1405 LLVM_ABI bool isDebugEntryValue() const;
1406
1407 /// Return true if the instruction is a debug value which describes a part of
1408 /// a variable as unavailable.
1409 bool isUndefDebugValue() const {
1410 if (!isDebugValue())
1411 return false;
1412 // If any $noreg locations are given, this DV is undef.
1413 for (const MachineOperand &Op : debug_operands())
1414 if (Op.isReg() && !Op.getReg().isValid())
1415 return true;
1416 return false;
1417 }
1418
1420 return getOpcode() == TargetOpcode::JUMP_TABLE_DEBUG_INFO;
1421 }
1422
1423 bool isPHI() const {
1424 return getOpcode() == TargetOpcode::PHI ||
1425 getOpcode() == TargetOpcode::G_PHI;
1426 }
1427 bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
1428 bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; }
1429 bool isInlineAsm() const {
1430 return getOpcode() == TargetOpcode::INLINEASM ||
1431 getOpcode() == TargetOpcode::INLINEASM_BR;
1432 }
1433 /// Returns true if the register operand can be folded with a load or store
1434 /// into a frame index. Does so by checking the InlineAsm::Flag immediate
1435 /// operand at OpId - 1.
1436 LLVM_ABI bool mayFoldInlineAsmRegOp(unsigned OpId) const;
1437
1440
1441 bool isInsertSubreg() const {
1442 return getOpcode() == TargetOpcode::INSERT_SUBREG;
1443 }
1444
1445 bool isSubregToReg() const {
1446 return getOpcode() == TargetOpcode::SUBREG_TO_REG;
1447 }
1448
1449 bool isRegSequence() const {
1450 return getOpcode() == TargetOpcode::REG_SEQUENCE;
1451 }
1452
1453 bool isBundle() const {
1454 return getOpcode() == TargetOpcode::BUNDLE;
1455 }
1456
1457 bool isCopy() const {
1458 return getOpcode() == TargetOpcode::COPY;
1459 }
1460
1461 bool isCopyLaneMask() const {
1462 return getOpcode() == TargetOpcode::COPY_LANEMASK;
1463 }
1464
1465 bool isFullCopy() const {
1466 return isCopy() && !getOperand(0).getSubReg() && !getOperand(1).getSubReg();
1467 }
1468
1469 bool isExtractSubreg() const {
1470 return getOpcode() == TargetOpcode::EXTRACT_SUBREG;
1471 }
1472
1473 bool isFakeUse() const { return getOpcode() == TargetOpcode::FAKE_USE; }
1474
1475 /// Return true if the instruction behaves like a copy.
1476 /// This does not include native copy instructions.
1477 bool isCopyLike() const {
1478 return isCopy() || isSubregToReg();
1479 }
1480
1481 /// Return true is the instruction is an identity copy.
1482 bool isIdentityCopy() const {
1483 return isCopy() && getOperand(0).getReg() == getOperand(1).getReg() &&
1485 }
1486
1487 /// Return true if this is a transient instruction that is either very likely
1488 /// to be eliminated during register allocation (such as copy-like
1489 /// instructions), or if this instruction doesn't have an execution-time cost.
1490 bool isTransient() const {
1491 switch (getOpcode()) {
1492 default:
1493 return isMetaInstruction();
1494 // Copy-like instructions are usually eliminated during register allocation.
1495 case TargetOpcode::PHI:
1496 case TargetOpcode::G_PHI:
1497 case TargetOpcode::COPY:
1498 case TargetOpcode::COPY_LANEMASK:
1499 case TargetOpcode::INSERT_SUBREG:
1500 case TargetOpcode::SUBREG_TO_REG:
1501 case TargetOpcode::REG_SEQUENCE:
1502 return true;
1503 }
1504 }
1505
1506 /// Return the number of instructions inside the MI bundle, excluding the
1507 /// bundle header.
1508 ///
1509 /// This is the number of instructions that MachineBasicBlock::iterator
1510 /// skips, 0 for unbundled instructions.
1511 LLVM_ABI unsigned getBundleSize() const;
1512
1513 /// Return true if the MachineInstr reads the specified register.
1514 /// If TargetRegisterInfo is non-null, then it also checks if there
1515 /// is a read of a super-register.
1516 /// This does not count partial redefines of virtual registers as reads:
1517 /// %reg1024:6 = OP.
1519 return findRegisterUseOperandIdx(Reg, TRI, false) != -1;
1520 }
1521
1522 /// Return true if the MachineInstr reads the specified virtual register.
1523 /// Take into account that a partial define is a
1524 /// read-modify-write operation.
1526 return readsWritesVirtualRegister(Reg).first;
1527 }
1528
1529 /// Return a pair of bools (reads, writes) indicating if this instruction
1530 /// reads or writes Reg. This also considers partial defines.
1531 /// If Ops is not null, all operand indices for Reg are added.
1532 LLVM_ABI std::pair<bool, bool>
1534 SmallVectorImpl<unsigned> *Ops = nullptr) const;
1535
1536 /// Return true if the MachineInstr kills the specified register.
1537 /// If TargetRegisterInfo is non-null, then it also checks if there is
1538 /// a kill of a super-register.
1540 return findRegisterUseOperandIdx(Reg, TRI, true) != -1;
1541 }
1542
1543 /// Return true if the MachineInstr fully defines the specified register.
1544 /// If TargetRegisterInfo is non-null, then it also checks
1545 /// if there is a def of a super-register.
1546 /// NOTE: It's ignoring subreg indices on virtual registers.
1548 return findRegisterDefOperandIdx(Reg, TRI, false, false) != -1;
1549 }
1550
1551 /// Return true if the MachineInstr modifies (fully define or partially
1552 /// define) the specified register.
1553 /// NOTE: It's ignoring subreg indices on virtual registers.
1555 return findRegisterDefOperandIdx(Reg, TRI, false, true) != -1;
1556 }
1557
1558 /// Returns true if the register is dead in this machine instruction.
1559 /// If TargetRegisterInfo is non-null, then it also checks
1560 /// if there is a dead def of a super-register.
1562 return findRegisterDefOperandIdx(Reg, TRI, true, false) != -1;
1563 }
1564
1565 /// Returns true if the MachineInstr has an implicit-use operand of exactly
1566 /// the given register (not considering sub/super-registers).
1568
1569 /// Returns the operand index that is a use of the specific register or -1
1570 /// if it is not found. It further tightens the search criteria to a use
1571 /// that kills the register if isKill is true.
1573 const TargetRegisterInfo *TRI,
1574 bool isKill = false) const;
1575
1576 /// Wrapper for findRegisterUseOperandIdx, it returns
1577 /// a pointer to the MachineOperand rather than an index.
1579 const TargetRegisterInfo *TRI,
1580 bool isKill = false) {
1582 return (Idx == -1) ? nullptr : &getOperand(Idx);
1583 }
1584
1586 const TargetRegisterInfo *TRI,
1587 bool isKill = false) const {
1588 return const_cast<MachineInstr *>(this)->findRegisterUseOperand(Reg, TRI,
1589 isKill);
1590 }
1591
1592 /// Returns the operand index that is a def of the specified register or
1593 /// -1 if it is not found. If isDead is true, defs that are not dead are
1594 /// skipped. If Overlap is true, then it also looks for defs that merely
1595 /// overlap the specified register. If TargetRegisterInfo is non-null,
1596 /// then it also checks if there is a def of a super-register.
1597 /// This may also return a register mask operand when Overlap is true.
1599 const TargetRegisterInfo *TRI,
1600 bool isDead = false,
1601 bool Overlap = false) const;
1602
1603 /// Wrapper for findRegisterDefOperandIdx, it returns
1604 /// a pointer to the MachineOperand rather than an index.
1606 const TargetRegisterInfo *TRI,
1607 bool isDead = false,
1608 bool Overlap = false) {
1609 int Idx = findRegisterDefOperandIdx(Reg, TRI, isDead, Overlap);
1610 return (Idx == -1) ? nullptr : &getOperand(Idx);
1611 }
1612
1614 const TargetRegisterInfo *TRI,
1615 bool isDead = false,
1616 bool Overlap = false) const {
1617 return const_cast<MachineInstr *>(this)->findRegisterDefOperand(
1618 Reg, TRI, isDead, Overlap);
1619 }
1620
1621 /// Find the index of the first operand in the
1622 /// operand list that is used to represent the predicate. It returns -1 if
1623 /// none is found.
1625
1626 /// Find the index of the flag word operand that
1627 /// corresponds to operand OpIdx on an inline asm instruction. Returns -1 if
1628 /// getOperand(OpIdx) does not belong to an inline asm operand group.
1629 ///
1630 /// If GroupNo is not NULL, it will receive the number of the operand group
1631 /// containing OpIdx.
1632 LLVM_ABI int findInlineAsmFlagIdx(unsigned OpIdx,
1633 unsigned *GroupNo = nullptr) const;
1634
1635 /// Compute the static register class constraint for operand OpIdx.
1636 /// For normal instructions, this is derived from the MCInstrDesc.
1637 /// For inline assembly it is derived from the flag words.
1638 ///
1639 /// Returns NULL if the static register class constraint cannot be
1640 /// determined.
1643 const TargetRegisterInfo *TRI) const;
1644
1645 /// Applies the constraints (def/use) implied by this MI on \p Reg to
1646 /// the given \p CurRC.
1647 /// If \p ExploreBundle is set and MI is part of a bundle, all the
1648 /// instructions inside the bundle will be taken into account. In other words,
1649 /// this method accumulates all the constraints of the operand of this MI and
1650 /// the related bundle if MI is a bundle or inside a bundle.
1651 ///
1652 /// Returns the register class that satisfies both \p CurRC and the
1653 /// constraints set by MI. Returns NULL if such a register class does not
1654 /// exist.
1655 ///
1656 /// \pre CurRC must not be NULL.
1658 Register Reg, const TargetRegisterClass *CurRC,
1660 bool ExploreBundle = false) const;
1661
1662 /// Applies the constraints (def/use) implied by the \p OpIdx operand
1663 /// to the given \p CurRC.
1664 ///
1665 /// Returns the register class that satisfies both \p CurRC and the
1666 /// constraints set by \p OpIdx MI. Returns NULL if such a register class
1667 /// does not exist.
1668 ///
1669 /// \pre CurRC must not be NULL.
1670 /// \pre The operand at \p OpIdx must be a register.
1673 const TargetInstrInfo *TII,
1674 const TargetRegisterInfo *TRI) const;
1675
1676 /// Add a tie between the register operands at DefIdx and UseIdx.
1677 /// The tie will cause the register allocator to ensure that the two
1678 /// operands are assigned the same physical register.
1679 ///
1680 /// Tied operands are managed automatically for explicit operands in the
1681 /// MCInstrDesc. This method is for exceptional cases like inline asm.
1682 LLVM_ABI void tieOperands(unsigned DefIdx, unsigned UseIdx);
1683
1684 /// Given the index of a tied register operand, find the
1685 /// operand it is tied to. Defs are tied to uses and vice versa. Returns the
1686 /// index of the tied operand which must exist.
1687 LLVM_ABI unsigned findTiedOperandIdx(unsigned OpIdx) const;
1688
1689 /// Given the index of a register def operand,
1690 /// check if the register def is tied to a source operand, due to either
1691 /// two-address elimination or inline assembly constraints. Returns the
1692 /// first tied use operand index by reference if UseOpIdx is not null.
1693 bool isRegTiedToUseOperand(unsigned DefOpIdx,
1694 unsigned *UseOpIdx = nullptr) const {
1695 const MachineOperand &MO = getOperand(DefOpIdx);
1696 if (!MO.isReg() || !MO.isDef() || !MO.isTied())
1697 return false;
1698 if (UseOpIdx)
1699 *UseOpIdx = findTiedOperandIdx(DefOpIdx);
1700 return true;
1701 }
1702
1703 /// Return true if the use operand of the specified index is tied to a def
1704 /// operand. It also returns the def operand index by reference if DefOpIdx
1705 /// is not null.
1706 bool isRegTiedToDefOperand(unsigned UseOpIdx,
1707 unsigned *DefOpIdx = nullptr) const {
1708 const MachineOperand &MO = getOperand(UseOpIdx);
1709 if (!MO.isReg() || !MO.isUse() || !MO.isTied())
1710 return false;
1711 if (DefOpIdx)
1712 *DefOpIdx = findTiedOperandIdx(UseOpIdx);
1713 return true;
1714 }
1715
1716 /// Clears kill flags on all operands.
1717 LLVM_ABI void clearKillInfo();
1718
1719 /// Replace all occurrences of FromReg with ToReg:SubIdx,
1720 /// properly composing subreg indices where necessary.
1721 LLVM_ABI void substituteRegister(Register FromReg, Register ToReg,
1722 unsigned SubIdx,
1724
1725 /// We have determined MI kills a register. Look for the
1726 /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
1727 /// add a implicit operand if it's not found. Returns true if the operand
1728 /// exists / is added.
1729 LLVM_ABI bool addRegisterKilled(Register IncomingReg,
1731 bool AddIfNotFound = false);
1732
1733 /// Clear all kill flags affecting Reg. If RegInfo is provided, this includes
1734 /// all aliasing registers.
1737
1738 /// We have determined MI defined a register without a use.
1739 /// Look for the operand that defines it and mark it as IsDead. If
1740 /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
1741 /// true if the operand exists / is added.
1743 bool AddIfNotFound = false);
1744
1745 /// Clear all dead flags on operands defining register @p Reg.
1747
1748 /// Mark all subregister defs of register @p Reg with the undef flag.
1749 /// This function is used when we determined to have a subregister def in an
1750 /// otherwise undefined super register.
1751 LLVM_ABI void setRegisterDefReadUndef(Register Reg, bool IsUndef = true);
1752
1753 /// We have determined MI defines a register. Make sure there is an operand
1754 /// defining Reg.
1756 const TargetRegisterInfo *RegInfo = nullptr);
1757
1758 /// Mark every physreg used by this instruction as
1759 /// dead except those in the UsedRegs list.
1760 ///
1761 /// On instructions with register mask operands, also add implicit-def
1762 /// operands for all registers in UsedRegs.
1764 const TargetRegisterInfo &TRI);
1765
1766 /// Return true if it is safe to move this instruction. If
1767 /// SawStore is set to true, it means that there is a store (or call) between
1768 /// the instruction's location and its intended destination.
1769 LLVM_ABI bool isSafeToMove(bool &SawStore) const;
1770
1771 /// Return true if this instruction would be trivially dead if all of its
1772 /// defined registers were dead.
1773 LLVM_ABI bool wouldBeTriviallyDead() const;
1774
1775 /// Check whether an MI is dead. If \p LivePhysRegs is provided, it is assumed
1776 /// to be at the position of MI and will be used to check the Liveness of
1777 /// physical register defs. If \p LivePhysRegs is not provided, this will
1778 /// pessimistically assume any PhysReg def is live.
1779 /// For trivially dead instructions (i.e. those without hard to model effects
1780 /// / wouldBeTriviallyDead), this checks deadness by analyzing defs of the
1781 /// MachineInstr. If the instruction wouldBeTriviallyDead, and all the defs
1782 /// either have dead flags or have no uses, then the instruction is said to be
1783 /// dead.
1784 LLVM_ABI bool isDead(const MachineRegisterInfo &MRI,
1785 LiveRegUnits *LivePhysRegs = nullptr) const;
1786
1787 /// Returns true if this instruction's memory access aliases the memory
1788 /// access of Other.
1789 //
1790 /// Assumes any physical registers used to compute addresses
1791 /// have the same value for both instructions. Returns false if neither
1792 /// instruction writes to memory.
1793 ///
1794 /// @param AA Optional alias analysis, used to compare memory operands.
1795 /// @param Other MachineInstr to check aliasing against.
1796 /// @param UseTBAA Whether to pass TBAA information to alias analysis.
1798 bool UseTBAA) const;
1800 bool UseTBAA) const;
1801
1802 /// Return true if this instruction may have an ordered
1803 /// or volatile memory reference, or if the information describing the memory
1804 /// reference is not available. Return false if it is known to have no
1805 /// ordered or volatile memory references.
1806 LLVM_ABI bool hasOrderedMemoryRef() const;
1807
1808 /// Return true if this load instruction never traps and points to a memory
1809 /// location whose value doesn't change during the execution of this function.
1810 ///
1811 /// Examples include loading a value from the constant pool or from the
1812 /// argument area of a function (if it does not change). If the instruction
1813 /// does multiple loads, this returns true only if all of the loads are
1814 /// dereferenceable and invariant.
1816
1817 /// If the specified instruction is a PHI that always merges together the
1818 /// same virtual register, return the register, otherwise return Register().
1820
1821 /// Return true if this instruction has side effects that are not modeled
1822 /// by mayLoad / mayStore, etc.
1823 /// For all instructions, the property is encoded in MCInstrDesc::Flags
1824 /// (see MCInstrDesc::hasUnmodeledSideEffects(). The only exception is
1825 /// INLINEASM instruction, in which case the side effect property is encoded
1826 /// in one of its operands (see InlineAsm::Extra_HasSideEffect).
1827 ///
1828 LLVM_ABI bool hasUnmodeledSideEffects() const;
1829
1830 /// Returns true if it is illegal to fold a load across this instruction.
1831 LLVM_ABI bool isLoadFoldBarrier() const;
1832
1833 /// Return true if all the defs of this instruction are dead.
1834 LLVM_ABI bool allDefsAreDead() const;
1835
1836 /// Return true if all the implicit defs of this instruction are dead.
1837 LLVM_ABI bool allImplicitDefsAreDead() const;
1838
1839 /// Return a valid size if the instruction is a spill instruction.
1840 LLVM_ABI std::optional<LocationSize>
1841 getSpillSize(const TargetInstrInfo *TII) const;
1842
1843 /// Return a valid size if the instruction is a folded spill instruction.
1844 LLVM_ABI std::optional<LocationSize>
1846
1847 /// Return a valid size if the instruction is a restore instruction.
1848 LLVM_ABI std::optional<LocationSize>
1849 getRestoreSize(const TargetInstrInfo *TII) const;
1850
1851 /// Return a valid size if the instruction is a folded restore instruction.
1852 LLVM_ABI std::optional<LocationSize>
1854
1855 /// Copy implicit register operands from specified
1856 /// instruction to this instruction.
1858
1859 /// Debugging support
1860 /// @{
1861 /// Determine the generic type to be printed (if needed) on uses and defs.
1862 LLVM_ABI LLT getTypeToPrint(unsigned OpIdx, SmallBitVector &PrintedTypes,
1863 const MachineRegisterInfo &MRI) const;
1864
1865 /// Return true when an instruction has tied register that can't be determined
1866 /// by the instruction's descriptor. This is useful for MIR printing, to
1867 /// determine whether we need to print the ties or not.
1868 LLVM_ABI bool hasComplexRegisterTies() const;
1869
1870 /// Print this MI to \p OS.
1871 /// Don't print information that can be inferred from other instructions if
1872 /// \p IsStandalone is false. It is usually true when only a fragment of the
1873 /// function is printed.
1874 /// Only print the defs and the opcode if \p SkipOpers is true.
1875 /// Otherwise, also print operands if \p SkipDebugLoc is true.
1876 /// Otherwise, also print the debug loc, with a terminating newline.
1877 /// \p TII is used to print the opcode name. If it's not present, but the
1878 /// MI is in a function, the opcode will be printed using the function's TII.
1879 LLVM_ABI void print(raw_ostream &OS, bool IsStandalone = true,
1880 bool SkipOpers = false, bool SkipDebugLoc = false,
1881 bool AddNewLine = true,
1882 const TargetInstrInfo *TII = nullptr) const;
1884 bool IsStandalone = true, bool SkipOpers = false,
1885 bool SkipDebugLoc = false, bool AddNewLine = true,
1886 const TargetInstrInfo *TII = nullptr) const;
1887 LLVM_ABI void dump() const;
1888 /// Print on dbgs() the current instruction and the instructions defining its
1889 /// operands and so on until we reach \p MaxDepth.
1890 LLVM_ABI void dumpr(const MachineRegisterInfo &MRI,
1891 unsigned MaxDepth = UINT_MAX) const;
1892 /// @}
1893
1894 //===--------------------------------------------------------------------===//
1895 // Accessors used to build up machine instructions.
1896
1897 /// Add the specified operand to the instruction. If it is an implicit
1898 /// operand, it is added to the end of the operand list. If it is an
1899 /// explicit operand it is added at the end of the explicit operand list
1900 /// (before the first implicit operand).
1901 ///
1902 /// MF must be the machine function that was used to allocate this
1903 /// instruction.
1904 ///
1905 /// MachineInstrBuilder provides a more convenient interface for creating
1906 /// instructions and adding operands.
1908
1909 /// Add an operand without providing an MF reference. This only works for
1910 /// instructions that are inserted in a basic block.
1911 ///
1912 /// MachineInstrBuilder and the two-argument addOperand(MF, MO) should be
1913 /// preferred.
1914 LLVM_ABI void addOperand(const MachineOperand &Op);
1915
1916 /// Inserts Ops BEFORE It. Can untie/retie tied operands.
1918
1919 /// Replace the instruction descriptor (thus opcode) of
1920 /// the current instruction with a new one.
1921 LLVM_ABI void setDesc(const MCInstrDesc &TID);
1922
1923 /// Replace current source information with new such.
1924 /// Avoid using this, the constructor argument is preferable.
1925 void setDebugLoc(DebugLoc DL) { DbgLoc = std::move(DL); }
1926
1927 /// Erase an operand from an instruction, leaving it with one
1928 /// fewer operand than it started with.
1929 LLVM_ABI void removeOperand(unsigned OpNo);
1930
1931 /// Clear this MachineInstr's memory reference descriptor list. This resets
1932 /// the memrefs to their most conservative state. This should be used only
1933 /// as a last resort since it greatly pessimizes our knowledge of the memory
1934 /// access performed by the instruction.
1936
1937 /// Assign this MachineInstr's memory reference descriptor list.
1938 ///
1939 /// Unlike other methods, this *will* allocate them into a new array
1940 /// associated with the provided `MachineFunction`.
1943
1944 /// Add a MachineMemOperand to the machine instruction.
1945 /// This function should be used only occasionally. The setMemRefs function
1946 /// is the primary method for setting up a MachineInstr's MemRefs list.
1948
1949 /// Clone another MachineInstr's memory reference descriptor list and replace
1950 /// ours with it.
1951 ///
1952 /// Note that `*this` may be the incoming MI!
1953 ///
1954 /// Prefer this API whenever possible as it can avoid allocations in common
1955 /// cases.
1957
1958 /// Clone the merge of multiple MachineInstrs' memory reference descriptors
1959 /// list and replace ours with it.
1960 ///
1961 /// Note that `*this` may be one of the incoming MIs!
1962 ///
1963 /// Prefer this API whenever possible as it can avoid allocations in common
1964 /// cases.
1967
1968 /// Set a symbol that will be emitted just prior to the instruction itself.
1969 ///
1970 /// Setting this to a null pointer will remove any such symbol.
1971 ///
1972 /// FIXME: This is not fully implemented yet.
1974
1975 /// Set a symbol that will be emitted just after the instruction itself.
1976 ///
1977 /// Setting this to a null pointer will remove any such symbol.
1978 ///
1979 /// FIXME: This is not fully implemented yet.
1981
1982 /// Clone another MachineInstr's pre- and post- instruction symbols and
1983 /// replace ours with it.
1985
1986 /// Set a marker on instructions that denotes where we should create and emit
1987 /// heap alloc site labels. This waits until after instruction selection and
1988 /// optimizations to create the label, so it should still work if the
1989 /// instruction is removed or duplicated.
1991
1992 // Set metadata on instructions that say which sections to emit instruction
1993 // addresses into.
1995
1997
1998 /// Set the CFI type for the instruction.
2000
2002
2003 /// Return the MIFlags which represent both MachineInstrs. This
2004 /// should be used when merging two MachineInstrs into one. This routine does
2005 /// not modify the MIFlags of this MachineInstr.
2007
2009
2010 /// Copy all flags to MachineInst MIFlags
2011 LLVM_ABI void copyIRFlags(const Instruction &I);
2012
2013 /// Break any tie involving OpIdx.
2014 void untieRegOperand(unsigned OpIdx) {
2016 if (MO.isReg() && MO.isTied()) {
2017 getOperand(findTiedOperandIdx(OpIdx)).TiedTo = 0;
2018 MO.TiedTo = 0;
2019 }
2020 }
2021
2022 /// Add all implicit def and use operands to this instruction.
2024
2025 /// Scan instructions immediately following MI and collect any matching
2026 /// DBG_VALUEs.
2028
2029 /// Find all DBG_VALUEs that point to the register def in this instruction
2030 /// and point them to \p Reg instead.
2032
2033 /// Remove all incoming values of Phi instruction for the given block.
2034 ///
2035 /// Return deleted operands count.
2036 ///
2037 /// Method does not erase PHI instruction even if it has single income or does
2038 /// not have incoming values at all. It is a caller responsibility to make
2039 /// decision how to process PHI instruction after incoming values removed.
2041
2042 /// Sets all register debug operands in this debug value instruction to be
2043 /// undef.
2045 assert(isDebugValue() && "Must be a debug value instruction.");
2046 for (MachineOperand &MO : debug_operands()) {
2047 if (MO.isReg()) {
2048 MO.setReg(0);
2049 MO.setSubReg(0);
2050 }
2051 }
2052 }
2053
2054 std::tuple<Register, Register> getFirst2Regs() const {
2055 return std::tuple(getOperand(0).getReg(), getOperand(1).getReg());
2056 }
2057
2058 std::tuple<Register, Register, Register> getFirst3Regs() const {
2059 return std::tuple(getOperand(0).getReg(), getOperand(1).getReg(),
2060 getOperand(2).getReg());
2061 }
2062
2063 std::tuple<Register, Register, Register, Register> getFirst4Regs() const {
2064 return std::tuple(getOperand(0).getReg(), getOperand(1).getReg(),
2065 getOperand(2).getReg(), getOperand(3).getReg());
2066 }
2067
2068 std::tuple<Register, Register, Register, Register, Register>
2070 return std::tuple(getOperand(0).getReg(), getOperand(1).getReg(),
2072 getOperand(4).getReg());
2073 }
2074
2075 LLVM_ABI std::tuple<LLT, LLT> getFirst2LLTs() const;
2076 LLVM_ABI std::tuple<LLT, LLT, LLT> getFirst3LLTs() const;
2077 LLVM_ABI std::tuple<LLT, LLT, LLT, LLT> getFirst4LLTs() const;
2078 LLVM_ABI std::tuple<LLT, LLT, LLT, LLT, LLT> getFirst5LLTs() const;
2079
2080 LLVM_ABI std::tuple<Register, LLT, Register, LLT> getFirst2RegLLTs() const;
2081 LLVM_ABI std::tuple<Register, LLT, Register, LLT, Register, LLT>
2082 getFirst3RegLLTs() const;
2083 LLVM_ABI
2084 std::tuple<Register, LLT, Register, LLT, Register, LLT, Register, LLT>
2085 getFirst4RegLLTs() const;
2087 LLT, Register, LLT>
2088 getFirst5RegLLTs() const;
2089
2090private:
2091 /// If this instruction is embedded into a MachineFunction, return the
2092 /// MachineRegisterInfo object for the current function, otherwise
2093 /// return null.
2094 MachineRegisterInfo *getRegInfo();
2095 const MachineRegisterInfo *getRegInfo() const;
2096
2097 /// Unlink all of the register operands in this instruction from their
2098 /// respective use lists. This requires that the operands already be on their
2099 /// use lists.
2100 void removeRegOperandsFromUseLists(MachineRegisterInfo&);
2101
2102 /// Add all of the register operands in this instruction from their
2103 /// respective use lists. This requires that the operands not be on their
2104 /// use lists yet.
2105 void addRegOperandsToUseLists(MachineRegisterInfo&);
2106
2107 /// Slow path for hasProperty when we're dealing with a bundle.
2108 LLVM_ABI bool hasPropertyInBundle(uint64_t Mask, QueryType Type) const;
2109
2110 /// Implements the logic of getRegClassConstraintEffectForVReg for the
2111 /// this MI and the given operand index \p OpIdx.
2112 /// If the related operand does not constrained Reg, this returns CurRC.
2113 const TargetRegisterClass *getRegClassConstraintEffectForVRegImpl(
2114 unsigned OpIdx, Register Reg, const TargetRegisterClass *CurRC,
2115 const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const;
2116
2117 /// Stores extra instruction information inline or allocates as ExtraInfo
2118 /// based on the number of pointers.
2119 void setExtraInfo(MachineFunction &MF, ArrayRef<MachineMemOperand *> MMOs,
2120 MCSymbol *PreInstrSymbol, MCSymbol *PostInstrSymbol,
2121 MDNode *HeapAllocMarker, MDNode *PCSections,
2122 uint32_t CFIType, MDNode *MMRAs, Value *DS);
2123};
2124
2125/// Special DenseMapInfo traits to compare MachineInstr* by *value* of the
2126/// instruction rather than by pointer value.
2127/// The hashing and equality testing functions ignore definitions so this is
2128/// useful for CSE, etc.
2130 LLVM_ABI static unsigned getHashValue(const MachineInstr *const &MI);
2131
2132 static bool isEqual(const MachineInstr *const &LHS,
2133 const MachineInstr *const &RHS) {
2134 return LHS->isIdenticalTo(*RHS, MachineInstr::IgnoreVRegDefs);
2135 }
2136};
2137
2138//===----------------------------------------------------------------------===//
2139// Debugging Support
2140
2142 MI.print(OS);
2143 return OS;
2144}
2145
2146} // end namespace llvm
2147
2148#endif // LLVM_CODEGEN_MACHINEINSTR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:215
This file defines DenseMapInfo traits for DenseMap.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define I(x, y, z)
Definition MD5.cpp:57
#define LLVM_MI_NUMOPERANDS_BITS
Register Reg
Register const TargetRegisterInfo * TRI
This file provides utility analysis objects describing memory locations.
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
MachineInstr unsigned OpIdx
#define P(N)
Basic Register Allocator
bool isDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
static cl::opt< bool > UseTBAA("use-tbaa-in-sched-mi", cl::Hidden, cl::init(true), cl::desc("Enable use of TBAA during MI DAG construction"))
This header defines support for implementing classes that have some trailing object (or arrays of obj...
Value * RHS
Value * LHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
const_pointer iterator
Definition ArrayRef.h:47
This class is a wrapper over an AAResults, and it is intended to be used only when there are no IR ch...
DWARF expression.
A debug info location.
Definition DebugLoc.h:126
A set of physical registers with utility functions to track liveness when walking backward/forward th...
A set of register units used to track register liveness.
Describe properties that are true of each instruction in the target description file.
uint64_t getFlags() const
Return flags of this instruction.
MCRegisterClass - Base class of TargetRegisterClass.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Metadata node.
Definition Metadata.h:1069
MachineBasicBlock iterator that automatically skips over MIs that are inside bundles (i....
Representation of each machine instruction.
mop_iterator operands_begin()
bool mayRaiseFPException() const
Return true if this instruction could possibly raise a floating-point exception.
ArrayRef< MachineMemOperand * >::iterator mmo_iterator
std::tuple< Register, Register, Register, Register, Register > getFirst5Regs() const
mop_range defs()
Returns all explicit operands that are register definitions.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
unsigned getNumImplicitOperands() const
Returns the implicit operands number.
bool isReturn(QueryType Type=AnyInBundle) const
LLVM_ABI void setRegisterDefReadUndef(Register Reg, bool IsUndef=true)
Mark all subregister defs of register Reg with the undef flag.
bool hasDebugOperandForReg(Register Reg) const
Returns whether this debug value has at least one debug operand with the register Reg.
bool isDebugValueList() const
LLVM_ABI void bundleWithPred()
Bundle this instruction with its predecessor.
bool isPosition() const
void setDebugValueUndef()
Sets all register debug operands in this debug value instruction to be undef.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
iterator_range< filter_iterator< const_mop_iterator, bool(*)(const MachineOperand &)> > filtered_const_mop_range
bool hasExtraDefRegAllocReq(QueryType Type=AnyInBundle) const
Returns true if this instruction def operands have special register allocation requirements that are ...
std::tuple< Register, Register, Register, Register > getFirst4Regs() const
bool isImplicitDef() const
LLVM_ABI std::tuple< Register, LLT, Register, LLT, Register, LLT, Register, LLT, Register, LLT > getFirst5RegLLTs() const
iterator_range< const_mop_iterator > const_mop_range
void clearAsmPrinterFlag(AsmPrinterFlagTy Flag)
Clear specific AsmPrinter flags.
LLVM_ABI iterator_range< filter_iterator< const MachineOperand *, std::function< bool(const MachineOperand &Op)> > > getDebugOperandsForReg(Register Reg) const
Returns a range of all of the operands that correspond to a debug use of Reg.
mop_range debug_operands()
Returns all operands that are used to determine the variable location for this DBG_VALUE instruction.
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
LLVM_ABI void setCFIType(MachineFunction &MF, uint32_t Type)
Set the CFI type for the instruction.
bool isCopy() const
const_mop_range debug_operands() const
Returns all operands that are used to determine the variable location for this DBG_VALUE instruction.
LLVM_ABI MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it.
filtered_const_mop_range all_uses() const
Returns an iterator range over all operands that are (explicit or implicit) register uses.
void clearAsmPrinterFlags()
Clear the AsmPrinter bitvector.
const MachineBasicBlock * getParent() const
bool isCopyLike() const
Return true if the instruction behaves like a copy.
void dropDebugNumber()
Drop any variable location debugging information associated with this instruction.
MDNode * getMMRAMetadata() const
Helper to extract mmra.op metadata.
LLVM_ABI void bundleWithSucc()
Bundle this instruction with its successor.
uint32_t getCFIType() const
Helper to extract a CFI type hash if one has been added.
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr reads the specified register.
bool isDebugLabel() const
LLVM_ABI void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just prior to the instruction itself.
bool isDebugOffsetImm() const
bool hasProperty(unsigned MCFlag, QueryType Type=AnyInBundle) const
Return true if the instruction (or in the case of a bundle, the instructions inside the bundle) has t...
LLVM_ABI bool isDereferenceableInvariantLoad() const
Return true if this load instruction never traps and points to a memory location whose value doesn't ...
void setFlags(unsigned flags)
MachineFunction * getMF()
QueryType
API for querying MachineInstr properties.
bool isPredicable(QueryType Type=AllInBundle) const
Return true if this instruction has a predicate operand that controls execution.
LLVM_ABI void addImplicitDefUseOperands(MachineFunction &MF)
Add all implicit def and use operands to this instruction.
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
filtered_mop_range all_defs()
Returns an iterator range over all operands that are (explicit or implicit) register defs.
LLVM_ABI std::tuple< LLT, LLT, LLT, LLT, LLT > getFirst5LLTs() const
MachineBasicBlock * getParent()
bool isSelect(QueryType Type=IgnoreBundle) const
Return true if this instruction is a select instruction.
bool isCall(QueryType Type=AnyInBundle) const
LLVM_ABI std::tuple< Register, LLT, Register, LLT, Register, LLT > getFirst3RegLLTs() const
bool usesCustomInsertionHook(QueryType Type=IgnoreBundle) const
Return true if this instruction requires custom insertion support when the DAG scheduler is inserting...
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
AsmPrinterFlagTy getAsmPrinterFlags() const
Return the asm printer flags bitvector.
LLVM_ABI uint32_t mergeFlagsWith(const MachineInstr &Other) const
Return the MIFlags which represent both MachineInstrs.
LLVM_ABI const MachineOperand & getDebugExpressionOp() const
Return the operand for the complex address expression referenced by this DBG_VALUE instruction.
LLVM_ABI std::pair< bool, bool > readsWritesVirtualRegister(Register Reg, SmallVectorImpl< unsigned > *Ops=nullptr) const
Return a pair of bools (reads, writes) indicating if this instruction reads or writes Reg.
const_mop_range implicit_operands() const
LLVM_ABI Register isConstantValuePHI() const
If the specified instruction is a PHI that always merges together the same virtual register,...
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
LLVM_ABI bool allImplicitDefsAreDead() const
Return true if all the implicit defs of this instruction are dead.
LLVM_ABI void cloneMemRefs(MachineFunction &MF, const MachineInstr &MI)
Clone another MachineInstr's memory reference descriptor list and replace ours with it.
LLVM_ABI const TargetRegisterClass * getRegClassConstraintEffectForVReg(Register Reg, const TargetRegisterClass *CurRC, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ExploreBundle=false) const
Applies the constraints (def/use) implied by this MI on Reg to the given CurRC.
LLVM_ABI bool isSafeToMove(bool &SawStore) const
Return true if it is safe to move this instruction.
LLVM_ABI bool mayAlias(BatchAAResults *AA, const MachineInstr &Other, bool UseTBAA) const
Returns true if this instruction's memory access aliases the memory access of Other.
bool isBundle() const
bool isDebugInstr() const
unsigned getNumDebugOperands() const
Returns the total number of operands which are debug locations.
unsigned getNumOperands() const
Retuns the total number of operands.
void setDebugInstrNum(unsigned Num)
Set instruction number of this MachineInstr.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
LLVM_ABI MachineInstr * removeFromBundle()
Unlink this instruction from its basic block and return it without deleting it.
const MachineOperand * const_mop_iterator
LLVM_ABI void dumpr(const MachineRegisterInfo &MRI, unsigned MaxDepth=UINT_MAX) const
Print on dbgs() the current instruction and the instructions defining its operands and so on until we...
LLVM_ABI void copyIRFlags(const Instruction &I)
Copy all flags to MachineInst MIFlags.
bool getAsmPrinterFlag(AsmPrinterFlagTy Flag) const
Return whether an AsmPrinter flag is set.
bool isDebugValueLike() const
bool isInlineAsm() const
bool memoperands_empty() const
Return true if we don't have any memory operands which described the memory access done by this instr...
const_mop_range uses() const
Returns all operands which may be register uses.
mmo_iterator memoperands_end() const
Access to memory operands of the instruction.
bool isDebugRef() const
bool isAnnotationLabel() const
LLVM_ABI void collectDebugValues(SmallVectorImpl< MachineInstr * > &DbgValues)
Scan instructions immediately following MI and collect any matching DBG_VALUEs.
MachineOperand & getDebugOffset()
unsigned peekDebugInstrNum() const
Examine the instruction number of this MachineInstr.
LLVM_ABI std::optional< LocationSize > getRestoreSize(const TargetInstrInfo *TII) const
Return a valid size if the instruction is a restore instruction.
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
LLVM_ABI unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
mop_range implicit_operands()
bool isSubregToReg() const
bool isCompare(QueryType Type=IgnoreBundle) const
Return true if this instruction is a comparison.
bool hasImplicitDef() const
Returns true if the instruction has implicit definition.
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
LLVM_ABI void setMemRefs(MachineFunction &MF, ArrayRef< MachineMemOperand * > MemRefs)
Assign this MachineInstr's memory reference descriptor list.
LLVM_ABI bool wouldBeTriviallyDead() const
Return true if this instruction would be trivially dead if all of its defined registers were dead.
bool isBundledWithPred() const
Return true if this instruction is part of a bundle, and it is not the first instruction in the bundl...
bool isDebugPHI() const
MachineOperand & getOperand(unsigned i)
LLVM_ABI std::tuple< LLT, LLT > getFirst2LLTs() const
LLVM_ABI std::optional< LocationSize > getFoldedSpillSize(const TargetInstrInfo *TII) const
Return a valid size if the instruction is a folded spill instruction.
const_mop_iterator operands_end() const
bool modifiesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register.
bool isCopyLaneMask() const
LLVM_ABI void unbundleFromPred()
Break bundle above this instruction.
LLVM_ABI void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction.
bool hasPostISelHook(QueryType Type=IgnoreBundle) const
Return true if this instruction requires adjustment after instruction selection by calling a target h...
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
bool isDebugOrPseudoInstr() const
LLVM_ABI bool isStackAligningInlineAsm() const
bool isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx=nullptr) const
Given the index of a register def operand, check if the register def is tied to a source operand,...
LLVM_ABI void dropMemRefs(MachineFunction &MF)
Clear this MachineInstr's memory reference descriptor list.
mop_iterator operands_end()
bool isFullCopy() const
LLVM_ABI int findRegisterUseOperandIdx(Register Reg, const TargetRegisterInfo *TRI, bool isKill=false) const
Returns the operand index that is a use of the specific register or -1 if it is not found.
MDNode * getPCSections() const
Helper to extract PCSections metadata target sections.
bool isCFIInstruction() const
LLVM_ABI int findFirstPredOperandIdx() const
Find the index of the first operand in the operand list that is used to represent the predicate.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
LLVM_ABI unsigned getBundleSize() const
Return the number of instructions inside the MI bundle, excluding the bundle header.
void setAsmPrinterFlag(AsmPrinterFlagTy Flag)
Set a flag for the AsmPrinter.
void clearFlags(unsigned flags)
bool hasExtraSrcRegAllocReq(QueryType Type=AnyInBundle) const
Returns true if this instruction source operands have special register allocation requirements that a...
bool isCommutable(QueryType Type=IgnoreBundle) const
Return true if this may be a 2- or 3-address instruction (of the form "X = op Y, Z,...
MachineInstr & operator=(const MachineInstr &)=delete
LLVM_ABI void cloneMergedMemRefs(MachineFunction &MF, ArrayRef< const MachineInstr * > MIs)
Clone the merge of multiple MachineInstrs' memory reference descriptors list and replace ours with it...
mop_range operands()
bool isConditionalBranch(QueryType Type=AnyInBundle) const
Return true if this is a branch which may fall through to the next instruction or may transfer contro...
bool isNotDuplicable(QueryType Type=AnyInBundle) const
Return true if this instruction cannot be safely duplicated.
LLVM_ABI bool isCandidateForAdditionalCallInfo(QueryType Type=IgnoreBundle) const
Return true if this is a call instruction that may have an additional information associated with it.
LLVM_ABI std::tuple< Register, LLT, Register, LLT, Register, LLT, Register, LLT > getFirst4RegLLTs() const
bool killsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr kills the specified register.
LLVM_ABI std::tuple< Register, LLT, Register, LLT > getFirst2RegLLTs() const
unsigned getNumMemOperands() const
Return the number of memory operands.
mop_range explicit_uses()
void clearFlag(MIFlag Flag)
clearFlag - Clear a MI flag.
bool isGCLabel() const
LLVM_ABI std::optional< LocationSize > getFoldedRestoreSize(const TargetInstrInfo *TII) const
Return a valid size if the instruction is a folded restore instruction.
LLVM_ABI const TargetRegisterClass * getRegClassConstraintEffect(unsigned OpIdx, const TargetRegisterClass *CurRC, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const
Applies the constraints (def/use) implied by the OpIdx operand to the given CurRC.
bool isOperandSubregIdx(unsigned OpIdx) const
Return true if operand OpIdx is a subregister index.
LLVM_ABI InlineAsm::AsmDialect getInlineAsmDialect() const
LLVM_ABI bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore,...
LLVM_ABI bool isEquivalentDbgInstr(const MachineInstr &Other) const
Returns true if this instruction is a debug instruction that represents an identical debug value to O...
bool isRegSequence() const
bool isExtractSubregLike(QueryType Type=IgnoreBundle) const
Return true if this instruction behaves the same way as the generic EXTRACT_SUBREG instructions.
LLVM_ABI const DILabel * getDebugLabel() const
Return the debug label referenced by this DBG_LABEL instruction.
void untieRegOperand(unsigned OpIdx)
Break any tie involving OpIdx.
bool registerDefIsDead(Register Reg, const TargetRegisterInfo *TRI) const
Returns true if the register is dead in this machine instruction.
const_mop_iterator operands_begin() const
static LLVM_ABI uint32_t copyFlagsFromInstruction(const Instruction &I)
bool definesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr fully defines the specified register.
LLVM_ABI unsigned removePHIIncomingValueFor(const MachineBasicBlock &MBB)
Remove all incoming values of Phi instruction for the given block.
LLVM_ABI void insert(mop_iterator InsertBefore, ArrayRef< MachineOperand > Ops)
Inserts Ops BEFORE It. Can untie/retie tied operands.
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
bool isUnconditionalBranch(QueryType Type=AnyInBundle) const
Return true if this is a branch which always transfers control flow to some other block.
const MachineOperand * findRegisterUseOperand(Register Reg, const TargetRegisterInfo *TRI, bool isKill=false) const
bool isJumpTableDebugInfo() const
std::tuple< Register, Register, Register > getFirst3Regs() const
LLVM_ABI unsigned getNumExplicitDefs() const
Returns the number of non-implicit definitions.
LLVM_ABI void eraseFromBundle()
Unlink 'this' from its basic block and delete it.
bool hasDelaySlot(QueryType Type=AnyInBundle) const
Returns true if the specified instruction has a delay slot which must be filled by the code generator...
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
LLVM_ABI void setHeapAllocMarker(MachineFunction &MF, MDNode *MD)
Set a marker on instructions that denotes where we should create and emit heap alloc site labels.
bool isMoveReg(QueryType Type=IgnoreBundle) const
Return true if this instruction is a register move.
const_mop_range explicit_uses() const
LLVM_ABI const DILocalVariable * getDebugVariable() const
Return the debug variable referenced by this DBG_VALUE instruction.
LLVM_ABI bool hasComplexRegisterTies() const
Return true when an instruction has tied register that can't be determined by the instruction's descr...
LLVM_ABI LLT getTypeToPrint(unsigned OpIdx, SmallBitVector &PrintedTypes, const MachineRegisterInfo &MRI) const
Debugging supportDetermine the generic type to be printed (if needed) on uses and defs.
bool isInsertSubreg() const
bool isLifetimeMarker() const
LLVM_ABI void substituteRegister(Register FromReg, Register ToReg, unsigned SubIdx, const TargetRegisterInfo &RegInfo)
Replace all occurrences of FromReg with ToReg:SubIdx, properly composing subreg indices where necessa...
mop_range explicit_operands()
LLVM_ABI unsigned findTiedOperandIdx(unsigned OpIdx) const
Given the index of a tied register operand, find the operand it is tied to.
LLVM_ABI void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.
bool isConvertibleTo3Addr(QueryType Type=IgnoreBundle) const
Return true if this is a 2-address instruction which can be changed into a 3-address instruction if n...
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
LLVM_ABI void cloneInstrSymbols(MachineFunction &MF, const MachineInstr &MI)
Clone another MachineInstr's pre- and post- instruction symbols and replace ours with it.
bool isInsideBundle() const
Return true if MI is in a bundle (but not the first MI in a bundle).
LLVM_ABI void changeDebugValuesDefReg(Register Reg)
Find all DBG_VALUEs that point to the register def in this instruction and point them to Reg instead.
LLVM_ABI bool isIdenticalTo(const MachineInstr &Other, MICheckType Check=CheckDefs) const
Return true if this instruction is identical to Other.
LLVM_ABI bool hasOrderedMemoryRef() const
Return true if this instruction may have an ordered or volatile memory reference, or if the informati...
mop_range uses()
Returns all operands which may be register uses.
LLVM_ABI void emitGenericError(const Twine &ErrMsg) const
const_mop_range explicit_operands() const
bool isConvergent(QueryType Type=AnyInBundle) const
Return true if this instruction is convergent.
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
const_mop_range defs() const
Returns all explicit operands that are register definitions.
LLVM_ABI const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
bool isLabel() const
Returns true if the MachineInstr represents a label.
LLVM_ABI void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
bool isExtractSubreg() const
bool isNonListDebugValue() const
CommentFlag
Flags to specify different kinds of comments to output in assembly code.
MachineOperand * mop_iterator
iterator/begin/end - Iterate over all operands of a machine instruction.
MachineOperand * findRegisterUseOperand(Register Reg, const TargetRegisterInfo *TRI, bool isKill=false)
Wrapper for findRegisterUseOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
LLVM_ABI bool isLoadFoldBarrier() const
Returns true if it is illegal to fold a load across this instruction.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
void setFlag(MIFlag Flag)
Set a MI flag.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI bool isDead(const MachineRegisterInfo &MRI, LiveRegUnits *LivePhysRegs=nullptr) const
Check whether an MI is dead.
LLVM_ABI std::tuple< LLT, LLT, LLT > getFirst3LLTs() const
bool isMoveImmediate(QueryType Type=IgnoreBundle) const
Return true if this instruction is a move immediate (including conditional moves) instruction.
bool isPreISelOpcode(QueryType Type=IgnoreBundle) const
Return true if this is an instruction that should go through the usual legalization steps.
bool isEHScopeReturn(QueryType Type=AnyInBundle) const
Return true if this is an instruction that marks the end of an EH scope, i.e., a catchpad or a cleanu...
bool isPseudo(QueryType Type=IgnoreBundle) const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction.
LLVM_ABI const MachineOperand & getDebugVariableOp() const
Return the operand for the debug variable referenced by this DBG_VALUE instruction.
LLVM_ABI void setPhysRegsDeadExcept(ArrayRef< Register > UsedRegs, const TargetRegisterInfo &TRI)
Mark every physreg used by this instruction as dead except those in the UsedRegs list.
LLVM_ABI void removeOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with.
friend class MachineFunction
filtered_mop_range all_uses()
Returns an iterator range over all operands that are (explicit or implicit) register uses.
MCSymbol * getPreInstrSymbol() const
Helper to extract a pre-instruction symbol if one has been added.
LLVM_ABI bool addRegisterKilled(Register IncomingReg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI kills a register.
bool readsVirtualRegister(Register Reg) const
Return true if the MachineInstr reads the specified virtual register.
LLVM_ABI void setPostInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just after the instruction itself.
bool isBitcast(QueryType Type=IgnoreBundle) const
Return true if this instruction is a bitcast instruction.
bool hasOptionalDef(QueryType Type=IgnoreBundle) const
Set if this instruction has an optional definition, e.g.
bool isTransient() const
Return true if this is a transient instruction that is either very likely to be eliminated during reg...
bool isDebugValue() const
LLVM_ABI void dump() const
unsigned getDebugOperandIndex(const MachineOperand *Op) const
const MachineOperand & getDebugOffset() const
Return the operand containing the offset to be used if this DBG_VALUE instruction is indirect; will b...
MachineOperand & getDebugOperand(unsigned Index)
LLVM_ABI std::optional< LocationSize > getSpillSize(const TargetInstrInfo *TII) const
Return a valid size if the instruction is a spill instruction.
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
LLVM_ABI void addRegisterDefined(Register Reg, const TargetRegisterInfo *RegInfo=nullptr)
We have determined MI defines a register.
MDNode * getHeapAllocMarker() const
Helper to extract a heap alloc marker if one has been added.
bool isInsertSubregLike(QueryType Type=IgnoreBundle) const
Return true if this instruction behaves the same way as the generic INSERT_SUBREG instructions.
LLVM_ABI unsigned getDebugInstrNum()
Fetch the instruction number of this MachineInstr.
bool isDebugOperand(const MachineOperand *Op) const
LLVM_ABI std::tuple< LLT, LLT, LLT, LLT > getFirst4LLTs() const
LLVM_ABI void clearRegisterDeads(Register Reg)
Clear all dead flags on operands defining register Reg.
LLVM_ABI void clearRegisterKills(Register Reg, const TargetRegisterInfo *RegInfo)
Clear all kill flags affecting Reg.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI void emitInlineAsmError(const Twine &ErrMsg) const
Emit an error referring to the source location of this instruction.
uint32_t getFlags() const
Return the MI flags bitvector.
bool isEHLabel() const
bool isPseudoProbe() const
LLVM_ABI bool hasRegisterImplicitUseOperand(Register Reg) const
Returns true if the MachineInstr has an implicit-use operand of exactly the given register (not consi...
LLVM_ABI bool shouldUpdateAdditionalCallInfo() const
Return true if copying, moving, or erasing this instruction requires updating additional call info (s...
LLVM_ABI void setDeactivationSymbol(MachineFunction &MF, Value *DS)
bool isUndefDebugValue() const
Return true if the instruction is a debug value which describes a part of a variable as unavailable.
Value * getDeactivationSymbol() const
bool isIdentityCopy() const
Return true is the instruction is an identity copy.
MCSymbol * getPostInstrSymbol() const
Helper to extract a post-instruction symbol if one has been added.
LLVM_ABI void unbundleFromSucc()
Break bundle below this instruction.
const MachineOperand & getDebugOperand(unsigned Index) const
iterator_range< filter_iterator< mop_iterator, bool(*)(const MachineOperand &)> > filtered_mop_range
LLVM_ABI void clearKillInfo()
Clears kill flags on all operands.
LLVM_ABI bool isDebugEntryValue() const
A DBG_VALUE is an entry value iff its debug expression contains the DW_OP_LLVM_entry_value operation.
bool isIndirectDebugValue() const
A DBG_VALUE is indirect iff the location operand is a register and the offset operand is an immediate...
unsigned getNumDefs() const
Returns the total number of definitions.
LLVM_ABI void setPCSections(MachineFunction &MF, MDNode *MD)
MachineInstr(const MachineInstr &)=delete
bool isKill() const
LLVM_ABI const MDNode * getLocCookieMD() const
For inline asm, get the !srcloc metadata node if we have it, and decode the loc cookie from it.
const MachineOperand * findRegisterDefOperand(Register Reg, const TargetRegisterInfo *TRI, bool isDead=false, bool Overlap=false) const
LLVM_ABI int findRegisterDefOperandIdx(Register Reg, const TargetRegisterInfo *TRI, bool isDead=false, bool Overlap=false) const
Returns the operand index that is a def of the specified register or -1 if it is not found.
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
iterator_range< mop_iterator > mop_range
bool isMetaInstruction(QueryType Type=IgnoreBundle) const
Return true if this instruction doesn't produce any output in the form of executable instructions.
bool canFoldAsLoad(QueryType Type=IgnoreBundle) const
Return true for instructions that can be folded as memory operands in other instructions.
void setDebugLoc(DebugLoc DL)
Replace current source information with new such.
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
bool isFakeUse() const
filtered_const_mop_range all_defs() const
Returns an iterator range over all operands that are (explicit or implicit) register defs.
bool isVariadic(QueryType Type=IgnoreBundle) const
Return true if this instruction can have a variable number of operands.
LLVM_ABI int findInlineAsmFlagIdx(unsigned OpIdx, unsigned *GroupNo=nullptr) const
Find the index of the flag word operand that corresponds to operand OpIdx on an inline asm instructio...
LLVM_ABI bool allDefsAreDead() const
Return true if all the defs of this instruction are dead.
LLVM_ABI void setMMRAMetadata(MachineFunction &MF, MDNode *MMRAs)
bool isRegSequenceLike(QueryType Type=IgnoreBundle) const
Return true if this instruction behaves the same way as the generic REG_SEQUENCE instructions.
LLVM_ABI const TargetRegisterClass * getRegClassConstraint(unsigned OpIdx, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const
Compute the static register class constraint for operand OpIdx.
bool isAsCheapAsAMove(QueryType Type=AllInBundle) const
Returns true if this instruction has the same cost (or less) than a move instruction.
const_mop_range operands() const
LLVM_ABI void moveBefore(MachineInstr *MovePos)
Move the instruction before MovePos.
MachineOperand * findRegisterDefOperand(Register Reg, const TargetRegisterInfo *TRI, bool isDead=false, bool Overlap=false)
Wrapper for findRegisterDefOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
LLVM_ABI void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
bool isBundled() const
Return true if this instruction part of a bundle.
bool isRematerializable(QueryType Type=AllInBundle) const
Returns true if this instruction is a candidate for remat.
LLVM_ABI bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
LLVM_ABI bool mayFoldInlineAsmRegOp(unsigned OpId) const
Returns true if the register operand can be folded with a load or store into a frame index.
std::tuple< Register, Register > getFirst2Regs() const
~MachineInstr()=delete
A description of a memory reference used in the backend.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Manage lifetime of a slot tracker for printing IR.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static constexpr std::enable_if_t< std::is_same_v< Foo< TrailingTys... >, Foo< Tys... > >, size_t > totalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType< TrailingTys, size_t >::type... Counts)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
A range adaptor for a pair of iterators.
IteratorT begin() const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This file defines classes to implement an intrusive doubly linked list class (i.e.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
Abstract Attribute helper functions.
Definition Attributor.h:165
@ ExtraDefRegAllocReq
@ MayRaiseFPException
@ ExtraSrcRegAllocReq
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1669
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
Definition ADL.h:78
constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))
Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...
Definition ADL.h:86
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:189
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:551
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
@ Other
Any other memory.
Definition ModRef.h:68
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1885
filter_iterator_impl< WrappedIteratorT, PredicateT, detail::fwd_or_bidi_tag< WrappedIteratorT > > filter_iterator
Defines filter_iterator to a suitable specialization of filter_iterator_impl, based on the underlying...
Definition STLExtras.h:538
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
An information struct used to provide DenseMap with the various necessary components for a given valu...
Special DenseMapInfo traits to compare MachineInstr* by value of the instruction rather than by point...
static LLVM_ABI unsigned getHashValue(const MachineInstr *const &MI)
static bool isEqual(const MachineInstr *const &LHS, const MachineInstr *const &RHS)
Callbacks do nothing by default in iplist and ilist.
Definition ilist.h:65
Template traits for intrusive list.
Definition ilist.h:90