LLVM 24.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 NonNull = 1 << 24 // Address space cast source is not the null
133 // value of the source address space.
134 };
135
137 return NoUWrap | NoSWrap | NoUSWrap | IsExact | Disjoint | NonNeg |
139 }
140
141private:
142 const MCInstrDesc *MCID; // Instruction descriptor.
143 MachineBasicBlock *Parent = nullptr; // Pointer to the owning basic block.
144
145 // Operands are allocated by an ArrayRecycler.
146 MachineOperand *Operands = nullptr; // Pointer to the first operand.
147
148#define LLVM_MI_NUMOPERANDS_BITS 24
149#define LLVM_MI_FLAGS_BITS 32
150#define LLVM_MI_ASMPRINTERFLAGS_BITS 8
151
152 /// Number of operands on instruction.
154
155 // OperandCapacity has uint8_t size, so it should be next to NumOperands
156 // to properly pack.
157 using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
158 OperandCapacity CapOperands; // Capacity of the Operands array.
159
160 /// Various bits of additional information about the machine instruction.
161 uint32_t Flags;
162
163 /// Various bits of information used by the AsmPrinter to emit helpful
164 /// comments. This is *not* semantic information. Do not use this for
165 /// anything other than to convey comment information to AsmPrinter.
166 AsmPrinterFlagTy AsmPrinterFlags;
167
168 /// Cached opcode from MCID.
169 uint32_t Opcode;
170
171 /// Unique instruction number. Used by DBG_INSTR_REFs to refer to the values
172 /// defined by this instruction.
173 unsigned DebugInstrNum;
174
175 /// One-based handle into the instruction table of the SlotIndexes analysis
176 /// numbering this function. 0 if the instruction is not indexed.
177 unsigned SlotIndexHandle = 0;
178
179 /// Internal implementation detail class that provides out-of-line storage for
180 /// extra info used by the machine instruction when this info cannot be stored
181 /// in-line within the instruction itself.
182 ///
183 /// This has to be defined eagerly due to the implementation constraints of
184 /// `PointerSumType` where it is used.
185 class ExtraInfo final
186 : TrailingObjects<ExtraInfo, MachineMemOperand *, MCSymbol *, MDNode *,
187 uint32_t, Value *> {
188 public:
189 static ExtraInfo *create(BumpPtrAllocator &Allocator,
191 MCSymbol *PreInstrSymbol = nullptr,
192 MCSymbol *PostInstrSymbol = nullptr,
193 MDNode *HeapAllocMarker = nullptr,
194 MDNode *PCSections = nullptr, uint32_t CFIType = 0,
195 MDNode *MMRAs = nullptr, Value *DS = nullptr) {
196 bool HasPreInstrSymbol = PreInstrSymbol != nullptr;
197 bool HasPostInstrSymbol = PostInstrSymbol != nullptr;
198 bool HasHeapAllocMarker = HeapAllocMarker != nullptr;
199 bool HasMMRAs = MMRAs != nullptr;
200 bool HasCFIType = CFIType != 0;
201 bool HasPCSections = PCSections != nullptr;
202 bool HasDS = DS != nullptr;
203 auto *Result = new (Allocator.Allocate(
204 totalSizeToAlloc<MachineMemOperand *, MCSymbol *, MDNode *, uint32_t,
205 Value *>(
206 MMOs.size(), HasPreInstrSymbol + HasPostInstrSymbol,
207 HasHeapAllocMarker + HasPCSections + HasMMRAs, HasCFIType, HasDS),
208 alignof(ExtraInfo)))
209 ExtraInfo(MMOs.size(), HasPreInstrSymbol, HasPostInstrSymbol,
210 HasHeapAllocMarker, HasPCSections, HasCFIType, HasMMRAs,
211 HasDS);
212
213 // Copy the actual data into the trailing objects.
214 llvm::copy(MMOs, Result->getTrailingObjects<MachineMemOperand *>());
215
216 unsigned MDNodeIdx = 0;
217
218 if (HasPreInstrSymbol)
219 Result->getTrailingObjects<MCSymbol *>()[0] = PreInstrSymbol;
220 if (HasPostInstrSymbol)
221 Result->getTrailingObjects<MCSymbol *>()[HasPreInstrSymbol] =
222 PostInstrSymbol;
223 if (HasHeapAllocMarker)
224 Result->getTrailingObjects<MDNode *>()[MDNodeIdx++] = HeapAllocMarker;
225 if (HasPCSections)
226 Result->getTrailingObjects<MDNode *>()[MDNodeIdx++] = PCSections;
227 if (HasCFIType)
228 Result->getTrailingObjects<uint32_t>()[0] = CFIType;
229 if (HasMMRAs)
230 Result->getTrailingObjects<MDNode *>()[MDNodeIdx++] = MMRAs;
231 if (HasDS)
232 Result->getTrailingObjects<Value *>()[0] = DS;
233
234 return Result;
235 }
236
237 ArrayRef<MachineMemOperand *> getMMOs() const {
239 }
240
241 MCSymbol *getPreInstrSymbol() const {
242 return HasPreInstrSymbol ? getTrailingObjects<MCSymbol *>()[0] : nullptr;
243 }
244
245 MCSymbol *getPostInstrSymbol() const {
246 return HasPostInstrSymbol
247 ? getTrailingObjects<MCSymbol *>()[HasPreInstrSymbol]
248 : nullptr;
249 }
250
251 MDNode *getHeapAllocMarker() const {
252 return HasHeapAllocMarker ? getTrailingObjects<MDNode *>()[0] : nullptr;
253 }
254
255 MDNode *getPCSections() const {
256 return HasPCSections
257 ? getTrailingObjects<MDNode *>()[HasHeapAllocMarker]
258 : nullptr;
259 }
260
261 uint32_t getCFIType() const {
262 return HasCFIType ? getTrailingObjects<uint32_t>()[0] : 0;
263 }
264
265 MDNode *getMMRAMetadata() const {
266 return HasMMRAs ? getTrailingObjects<MDNode *>()[HasHeapAllocMarker +
267 HasPCSections]
268 : nullptr;
269 }
270
271 Value *getDeactivationSymbol() const {
272 return HasDS ? getTrailingObjects<Value *>()[0] : 0;
273 }
274
275 private:
276 friend TrailingObjects;
277
278 // Description of the extra info, used to interpret the actual optional
279 // data appended.
280 //
281 // Note that this is not terribly space optimized. This leaves a great deal
282 // of flexibility to fit more in here later.
283 const int NumMMOs;
284 const bool HasPreInstrSymbol;
285 const bool HasPostInstrSymbol;
286 const bool HasHeapAllocMarker;
287 const bool HasPCSections;
288 const bool HasCFIType;
289 const bool HasMMRAs;
290 const bool HasDS;
291
292 // Implement the `TrailingObjects` internal API.
293 size_t numTrailingObjects(OverloadToken<MachineMemOperand *>) const {
294 return NumMMOs;
295 }
296 size_t numTrailingObjects(OverloadToken<MCSymbol *>) const {
297 return HasPreInstrSymbol + HasPostInstrSymbol;
298 }
299 size_t numTrailingObjects(OverloadToken<MDNode *>) const {
300 return HasHeapAllocMarker + HasPCSections;
301 }
302 size_t numTrailingObjects(OverloadToken<uint32_t>) const {
303 return HasCFIType;
304 }
305 size_t numTrailingObjects(OverloadToken<Value *>) const { return HasDS; }
306
307 // Just a boring constructor to allow us to initialize the sizes. Always use
308 // the `create` routine above.
309 ExtraInfo(int NumMMOs, bool HasPreInstrSymbol, bool HasPostInstrSymbol,
310 bool HasHeapAllocMarker, bool HasPCSections, bool HasCFIType,
311 bool HasMMRAs, bool HasDS)
312 : NumMMOs(NumMMOs), HasPreInstrSymbol(HasPreInstrSymbol),
313 HasPostInstrSymbol(HasPostInstrSymbol),
314 HasHeapAllocMarker(HasHeapAllocMarker), HasPCSections(HasPCSections),
315 HasCFIType(HasCFIType), HasMMRAs(HasMMRAs), HasDS(HasDS) {}
316 };
317
318 /// Enumeration of the kinds of inline extra info available. It is important
319 /// that the `MachineMemOperand` inline kind has a tag value of zero to make
320 /// it accessible as an `ArrayRef`.
321 enum ExtraInfoInlineKinds {
322 EIIK_MMO = 0,
323 EIIK_PreInstrSymbol,
324 EIIK_PostInstrSymbol,
325 EIIK_OutOfLine
326 };
327
328 // We store extra information about the instruction here. The common case is
329 // expected to be nothing or a single pointer (typically a MMO or a symbol).
330 // We work to optimize this common case by storing it inline here rather than
331 // requiring a separate allocation, but we fall back to an allocation when
332 // multiple pointers are needed.
333 PointerSumType<ExtraInfoInlineKinds,
334 PointerSumTypeMember<EIIK_MMO, MachineMemOperand *>,
335 PointerSumTypeMember<EIIK_PreInstrSymbol, MCSymbol *>,
336 PointerSumTypeMember<EIIK_PostInstrSymbol, MCSymbol *>,
337 PointerSumTypeMember<EIIK_OutOfLine, ExtraInfo *>>
338 Info;
339
340 DebugLoc DbgLoc; // Source line information.
341
342 // Intrusive list support
343 friend struct ilist_traits<MachineInstr>;
345 void setParent(MachineBasicBlock *P) { Parent = P; }
346
347 /// This constructor creates a copy of the given
348 /// MachineInstr in the given MachineFunction.
350
351 /// This constructor create a MachineInstr and add the implicit operands.
352 /// It reserves space for number of operands specified by
353 /// MCInstrDesc. An explicit DebugLoc is supplied.
355 bool NoImp = false);
356
357 // MachineInstrs are pool-allocated and owned by MachineFunction.
358 friend class MachineFunction;
359
360 friend class SlotIndexes;
361
362 void
363 dumprImpl(const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth,
364 SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const;
365
366 static bool opIsRegDef(const MachineOperand &Op) {
367 return Op.isReg() && Op.isDef();
368 }
369
370 static bool opIsRegUse(const MachineOperand &Op) {
371 return Op.isReg() && Op.isUse();
372 }
373
374 MutableArrayRef<MachineOperand> operands_impl() {
375 return {Operands, NumOperands};
376 }
377 ArrayRef<MachineOperand> operands_impl() const {
378 return {Operands, NumOperands};
379 }
380
381public:
382 MachineInstr(const MachineInstr &) = delete;
383 MachineInstr &operator=(const MachineInstr &) = delete;
384 // Use MachineFunction::DeleteMachineInstr() instead.
385 ~MachineInstr() = delete;
386
387 const MachineBasicBlock* getParent() const { return Parent; }
388 MachineBasicBlock* getParent() { return Parent; }
389
390 /// Move the instruction before \p MovePos.
391 LLVM_ABI void moveBefore(MachineInstr *MovePos);
392
393 /// Return the function that contains the basic block that this instruction
394 /// belongs to.
395 ///
396 /// Note: this is undefined behaviour if the instruction does not have a
397 /// parent.
398 LLVM_ABI const MachineFunction *getMF() const;
400 return const_cast<MachineFunction *>(
401 static_cast<const MachineInstr *>(this)->getMF());
402 }
403
404 /// Return the asm printer flags bitvector.
405 AsmPrinterFlagTy getAsmPrinterFlags() const { return AsmPrinterFlags; }
406
407 /// Clear the AsmPrinter bitvector.
408 void clearAsmPrinterFlags() { AsmPrinterFlags = 0; }
409
410 /// Return whether an AsmPrinter flag is set.
413 "Flag is out of range for the AsmPrinterFlags field");
414 return AsmPrinterFlags & Flag;
415 }
416
417 /// Set a flag for the AsmPrinter.
420 "Flag is out of range for the AsmPrinterFlags field");
421 AsmPrinterFlags |= Flag;
422 }
423
424 /// Clear specific AsmPrinter flags.
427 "Flag is out of range for the AsmPrinterFlags field");
428 AsmPrinterFlags &= ~Flag;
429 }
430
431 /// Return the MI flags bitvector.
433 return Flags;
434 }
435
436 /// Return whether an MI flag is set.
437 bool getFlag(MIFlag Flag) const {
438 assert(isUInt<LLVM_MI_FLAGS_BITS>(unsigned(Flag)) &&
439 "Flag is out of range for the Flags field");
440 return Flags & Flag;
441 }
442
443 /// Set a MI flag.
444 void setFlag(MIFlag Flag) {
445 assert(isUInt<LLVM_MI_FLAGS_BITS>(unsigned(Flag)) &&
446 "Flag is out of range for the Flags field");
447 Flags |= (uint32_t)Flag;
448 }
449
450 void setFlags(unsigned flags) {
452 "flags to be set are out of range for the Flags field");
453 // Filter out the automatically maintained flags.
454 unsigned Mask = BundledPred | BundledSucc;
455 Flags = (Flags & Mask) | (flags & ~Mask);
456 }
457
458 /// clearFlag - Clear a MI flag.
459 void clearFlag(MIFlag Flag) {
460 assert(isUInt<LLVM_MI_FLAGS_BITS>(unsigned(Flag)) &&
461 "Flag to clear is out of range for the Flags field");
462 Flags &= ~((uint32_t)Flag);
463 }
464
465 void clearFlags(unsigned flags) {
467 "flags to be cleared are out of range for the Flags field");
468 Flags &= ~flags;
469 }
470
471 /// Return true if MI is in a bundle (but not the first MI in a bundle).
472 ///
473 /// A bundle looks like this before it's finalized:
474 /// ----------------
475 /// | MI |
476 /// ----------------
477 /// |
478 /// ----------------
479 /// | MI * |
480 /// ----------------
481 /// |
482 /// ----------------
483 /// | MI * |
484 /// ----------------
485 /// In this case, the first MI starts a bundle but is not inside a bundle, the
486 /// next 2 MIs are considered "inside" the bundle.
487 ///
488 /// After a bundle is finalized, it looks like this:
489 /// ----------------
490 /// | Bundle |
491 /// ----------------
492 /// |
493 /// ----------------
494 /// | MI * |
495 /// ----------------
496 /// |
497 /// ----------------
498 /// | MI * |
499 /// ----------------
500 /// |
501 /// ----------------
502 /// | MI * |
503 /// ----------------
504 /// The first instruction has the special opcode "BUNDLE". It's not "inside"
505 /// a bundle, but the next three MIs are.
506 bool isInsideBundle() const {
507 return getFlag(BundledPred);
508 }
509
510 /// Return true if this instruction part of a bundle. This is true
511 /// if either itself or its following instruction is marked "InsideBundle".
512 bool isBundled() const {
514 }
515
516 /// Return true if this instruction is part of a bundle, and it is not the
517 /// first instruction in the bundle.
518 bool isBundledWithPred() const { return getFlag(BundledPred); }
519
520 /// Return true if this instruction is part of a bundle, and it is not the
521 /// last instruction in the bundle.
522 bool isBundledWithSucc() const { return getFlag(BundledSucc); }
523
524 /// Bundle this instruction with its predecessor. This can be an unbundled
525 /// instruction, or it can be the first instruction in a bundle.
527
528 /// Bundle this instruction with its successor. This can be an unbundled
529 /// instruction, or it can be the last instruction in a bundle.
531
532 /// Break bundle above this instruction.
534
535 /// Break bundle below this instruction.
537
538 /// Returns the debug location id of this MachineInstr.
539 const DebugLoc &getDebugLoc() const { return DbgLoc; }
540
541 /// Return the operand containing the offset to be used if this DBG_VALUE
542 /// instruction is indirect; will be an invalid register if this value is
543 /// not indirect, and an immediate with value 0 otherwise.
545 assert(isNonListDebugValue() && "not a DBG_VALUE");
546 return getOperand(1);
547 }
549 assert(isNonListDebugValue() && "not a DBG_VALUE");
550 return getOperand(1);
551 }
552
553 /// Return the operand for the debug variable referenced by
554 /// this DBG_VALUE instruction.
557
558 /// Return the debug variable referenced by
559 /// this DBG_VALUE instruction.
561
562 /// Return the operand for the complex address expression referenced by
563 /// this DBG_VALUE instruction.
566
567 /// Return the complex address expression referenced by
568 /// this DBG_VALUE instruction.
570
571 /// Return the debug label referenced by
572 /// this DBG_LABEL instruction.
573 LLVM_ABI const DILabel *getDebugLabel() const;
574
575 /// Fetch the instruction number of this MachineInstr. If it does not have
576 /// one already, a new and unique number will be assigned.
577 LLVM_ABI unsigned getDebugInstrNum();
578
579 /// Fetch instruction number of this MachineInstr -- but before it's inserted
580 /// into \p MF. Needed for transformations that create an instruction but
581 /// don't immediately insert them.
583
584 /// Examine the instruction number of this MachineInstr. May be zero if
585 /// it hasn't been assigned a number yet.
586 unsigned peekDebugInstrNum() const { return DebugInstrNum; }
587
588 /// Set instruction number of this MachineInstr. Avoid using unless you're
589 /// deserializing this information.
590 void setDebugInstrNum(unsigned Num) { DebugInstrNum = Num; }
591
592 /// Drop any variable location debugging information associated with this
593 /// instruction. Use when an instruction is modified in such a way that it no
594 /// longer defines the value it used to. Variable locations using that value
595 /// will be dropped.
596 void dropDebugNumber() { DebugInstrNum = 0; }
597
598 /// For inline asm, get the !srcloc metadata node if we have it, and decode
599 /// the loc cookie from it.
600 LLVM_ABI const MDNode *getLocCookieMD() const;
601
602 /// Emit an error referring to the source location of this instruction. This
603 /// should only be used for inline assembly that is somehow impossible to
604 /// compile. Other errors should have been handled much earlier.
605 LLVM_ABI void emitInlineAsmError(const Twine &ErrMsg) const;
606
607 // Emit an error in the LLVMContext referring to the source location of this
608 // instruction, if available.
609 LLVM_ABI void emitGenericError(const Twine &ErrMsg) const;
610
611 /// Returns the target instruction descriptor of this MachineInstr.
612 const MCInstrDesc &getDesc() const { return *MCID; }
613
614 /// Returns the opcode of this MachineInstr.
615 unsigned getOpcode() const { return Opcode; }
616
617 /// Retuns the total number of operands.
618 unsigned getNumOperands() const { return NumOperands; }
619
620 /// Returns the total number of operands which are debug locations.
621 unsigned getNumDebugOperands() const { return size(debug_operands()); }
622
623 const MachineOperand &getOperand(unsigned i) const {
624 return operands_impl()[i];
625 }
626 MachineOperand &getOperand(unsigned i) { return operands_impl()[i]; }
627
629 assert(Index < getNumDebugOperands() && "getDebugOperand() out of range!");
630 return *(debug_operands().begin() + Index);
631 }
632 const MachineOperand &getDebugOperand(unsigned Index) const {
633 assert(Index < getNumDebugOperands() && "getDebugOperand() out of range!");
634 return *(debug_operands().begin() + Index);
635 }
636
637 /// Returns whether this debug value has at least one debug operand with the
638 /// register \p Reg.
640 return any_of(debug_operands(), [Reg](const MachineOperand &Op) {
641 return Op.isReg() && Op.getReg() == Reg;
642 });
643 }
644
645 /// Returns a range of all of the operands that correspond to a debug use of
646 /// \p Reg.
648 const MachineOperand *, std::function<bool(const MachineOperand &Op)>>>
652 std::function<bool(MachineOperand &Op)>>>
654
655 bool isDebugOperand(const MachineOperand *Op) const {
656 return Op >= adl_begin(debug_operands()) && Op <= adl_end(debug_operands());
657 }
658
659 unsigned getDebugOperandIndex(const MachineOperand *Op) const {
660 assert(isDebugOperand(Op) && "Expected a debug operand.");
661 return std::distance(adl_begin(debug_operands()), Op);
662 }
663
664 /// Returns the total number of definitions.
665 unsigned getNumDefs() const {
666 return getNumExplicitDefs() + MCID->implicit_defs().size();
667 }
668
669 /// Returns true if the instruction has implicit definition.
670 bool hasImplicitDef() const {
671 for (const MachineOperand &MO : implicit_operands())
672 if (MO.isDef())
673 return true;
674 return false;
675 }
676
677 /// Returns the implicit operands number.
678 unsigned getNumImplicitOperands() const {
680 }
681
682 /// Return true if operand \p OpIdx is a subregister index.
683 bool isOperandSubregIdx(unsigned OpIdx) const {
684 assert(getOperand(OpIdx).isImm() && "Expected MO_Immediate operand type.");
685 if (isExtractSubreg() && OpIdx == 2)
686 return true;
687 if (isInsertSubreg() && OpIdx == 3)
688 return true;
689 if (isRegSequence() && OpIdx > 1 && (OpIdx % 2) == 0)
690 return true;
691 if (isSubregToReg() && OpIdx == 2)
692 return true;
693 return false;
694 }
695
696 /// Returns the number of non-implicit operands.
697 LLVM_ABI unsigned getNumExplicitOperands() const;
698
699 /// Returns the number of non-implicit definitions.
700 LLVM_ABI unsigned getNumExplicitDefs() const;
701
702 /// iterator/begin/end - Iterate over all operands of a machine instruction.
703
704 // The operands must always be in the following order:
705 // - explicit reg defs,
706 // - other explicit operands (reg uses, immediates, etc.),
707 // - implicit reg defs
708 // - implicit reg uses
711
714
715 mop_iterator operands_begin() { return Operands; }
716 mop_iterator operands_end() { return Operands + NumOperands; }
717
718 const_mop_iterator operands_begin() const { return Operands; }
719 const_mop_iterator operands_end() const { return Operands + NumOperands; }
720
721 mop_range operands() { return operands_impl(); }
722 const_mop_range operands() const { return operands_impl(); }
723
725 return operands_impl().take_front(getNumExplicitOperands());
726 }
728 return operands_impl().take_front(getNumExplicitOperands());
729 }
731 return operands_impl().drop_front(getNumExplicitOperands());
732 }
734 return operands_impl().drop_front(getNumExplicitOperands());
735 }
736
737 /// Returns all operands that are used to determine the variable
738 /// location for this DBG_VALUE instruction.
740 assert(isDebugValueLike() && "Must be a debug value instruction.");
741 return isNonListDebugValue() ? operands_impl().take_front(1)
742 : operands_impl().drop_front(2);
743 }
744 /// \copydoc debug_operands()
746 assert(isDebugValueLike() && "Must be a debug value instruction.");
747 return isNonListDebugValue() ? operands_impl().take_front(1)
748 : operands_impl().drop_front(2);
749 }
750 /// Returns all explicit operands that are register definitions.
751 /// Implicit definition are not included!
752 mop_range defs() { return operands_impl().take_front(getNumExplicitDefs()); }
753 /// \copydoc defs()
755 return operands_impl().take_front(getNumExplicitDefs());
756 }
757 /// Returns all operands which may be register uses.
758 /// This may include unrelated operands which are not register uses.
759 mop_range uses() { return operands_impl().drop_front(getNumExplicitDefs()); }
760 /// \copydoc uses()
762 return operands_impl().drop_front(getNumExplicitDefs());
763 }
765 return operands_impl()
766 .take_front(getNumExplicitOperands())
767 .drop_front(getNumExplicitDefs());
768 }
770 return operands_impl()
771 .take_front(getNumExplicitOperands())
772 .drop_front(getNumExplicitDefs());
773 }
774
779
780 /// Returns an iterator range over all operands that are (explicit or
781 /// implicit) register defs.
783 return make_filter_range(operands(), opIsRegDef);
784 }
785 /// \copydoc all_defs()
787 return make_filter_range(operands(), opIsRegDef);
788 }
789
790 /// Returns an iterator range over all operands that are (explicit or
791 /// implicit) register uses.
793 return make_filter_range(uses(), opIsRegUse);
794 }
795 /// \copydoc all_uses()
797 return make_filter_range(uses(), opIsRegUse);
798 }
799
800 /// Returns the number of the operand iterator \p I points to.
802 return I - operands_begin();
803 }
804
805 /// Access to memory operands of the instruction. If there are none, that does
806 /// not imply anything about whether the function accesses memory. Instead,
807 /// the caller must behave conservatively.
809 if (!Info)
810 return {};
811
812 if (Info.is<EIIK_MMO>())
813 return ArrayRef(Info.getAddrOfZeroTagPointer(), 1);
814
815 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
816 return EI->getMMOs();
817
818 return {};
819 }
820
821 /// Access to memory operands of the instruction.
822 ///
823 /// If `memoperands_begin() == memoperands_end()`, that does not imply
824 /// anything about whether the function accesses memory. Instead, the caller
825 /// must behave conservatively.
826 mmo_iterator memoperands_begin() const { return memoperands().begin(); }
827
828 /// Access to memory operands of the instruction.
829 ///
830 /// If `memoperands_begin() == memoperands_end()`, that does not imply
831 /// anything about whether the function accesses memory. Instead, the caller
832 /// must behave conservatively.
833 mmo_iterator memoperands_end() const { return memoperands().end(); }
834
835 /// Return true if we don't have any memory operands which described the
836 /// memory access done by this instruction. If this is true, calling code
837 /// must be conservative.
838 bool memoperands_empty() const { return memoperands().empty(); }
839
840 /// Return true if this instruction has exactly one MachineMemOperand.
841 bool hasOneMemOperand() const { return memoperands().size() == 1; }
842
843 /// Return the number of memory operands.
844 unsigned getNumMemOperands() const { return memoperands().size(); }
845
846 /// Helper to extract a pre-instruction symbol if one has been added.
848 if (!Info)
849 return nullptr;
850 if (MCSymbol *S = Info.get<EIIK_PreInstrSymbol>())
851 return S;
852 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
853 return EI->getPreInstrSymbol();
854
855 return nullptr;
856 }
857
858 /// Helper to extract a post-instruction symbol if one has been added.
860 if (!Info)
861 return nullptr;
862 if (MCSymbol *S = Info.get<EIIK_PostInstrSymbol>())
863 return S;
864 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
865 return EI->getPostInstrSymbol();
866
867 return nullptr;
868 }
869
870 /// Helper to extract a heap alloc marker if one has been added.
872 if (!Info)
873 return nullptr;
874 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
875 return EI->getHeapAllocMarker();
876
877 return nullptr;
878 }
879
880 /// Helper to extract PCSections metadata target sections.
882 if (!Info)
883 return nullptr;
884 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
885 return EI->getPCSections();
886
887 return nullptr;
888 }
889
890 /// Helper to extract mmra.op metadata.
892 if (!Info)
893 return nullptr;
894 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
895 return EI->getMMRAMetadata();
896 return nullptr;
897 }
898
900 if (!Info)
901 return nullptr;
902 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
903 return EI->getDeactivationSymbol();
904 return nullptr;
905 }
906
907 /// Helper to extract a CFI type hash if one has been added.
909 if (!Info)
910 return 0;
911 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
912 return EI->getCFIType();
913
914 return 0;
915 }
916
917 /// API for querying MachineInstr properties. They are the same as MCInstrDesc
918 /// queries but they are bundle aware.
919
921 IgnoreBundle, // Ignore bundles
922 AnyInBundle, // Return true if any instruction in bundle has property
923 AllInBundle // Return true if all instructions in bundle have property
924 };
925
926 /// Return true if the instruction (or in the case of a bundle,
927 /// the instructions inside the bundle) has the specified property.
928 /// The first argument is the property being queried.
929 /// The second argument indicates whether the query should look inside
930 /// instruction bundles.
931 bool hasProperty(unsigned MCFlag, QueryType Type = AnyInBundle) const {
932 assert(MCFlag < 64 &&
933 "MCFlag out of range for bit mask in getFlags/hasPropertyInBundle.");
934 // Inline the fast path for unbundled or bundle-internal instructions.
936 return getDesc().getFlags() & (1ULL << MCFlag);
937
938 // If this is the first instruction in a bundle, take the slow path.
939 return hasPropertyInBundle(1ULL << MCFlag, Type);
940 }
941
942 /// Return true if this is an instruction that should go through the usual
943 /// legalization steps.
947
948 /// Return true if this instruction can have a variable number of operands.
949 /// In this case, the variable operands will be after the normal
950 /// operands but before the implicit definitions and uses (if any are
951 /// present).
955
956 /// Set if this instruction has an optional definition, e.g.
957 /// ARM instructions which can set condition code if 's' bit is set.
961
962 /// Return true if this is a pseudo instruction that doesn't
963 /// correspond to a real machine instruction.
966 }
967
968 /// Return true if this instruction doesn't produce any output in the form of
969 /// executable instructions.
973
976 }
977
978 /// Return true if this is an instruction that marks the end of an EH scope,
979 /// i.e., a catchpad or a cleanuppad instruction.
983
985 return hasProperty(MCID::Call, Type);
986 }
987
988 /// Return true if this is a call instruction that may have an additional
989 /// information associated with it.
990 LLVM_ABI bool
992
993 /// Return true if copying, moving, or erasing this instruction requires
994 /// updating additional call info (see \ref copyCallInfo, \ref moveCallInfo,
995 /// \ref eraseCallInfo).
997
998 /// Returns true if the specified instruction stops control flow
999 /// from executing the instruction immediately following it. Examples include
1000 /// unconditional branches and return instructions.
1003 }
1004
1005 /// Returns true if this instruction part of the terminator for a basic block.
1006 /// Typically this is things like return and branch instructions.
1007 ///
1008 /// Various passes use this to insert code into the bottom of a basic block,
1009 /// but before control flow occurs.
1013
1014 /// Returns true if this is a conditional, unconditional, or indirect branch.
1015 /// Predicates below can be used to discriminate between
1016 /// these cases, and the TargetInstrInfo::analyzeBranch method can be used to
1017 /// get more information.
1019 return hasProperty(MCID::Branch, Type);
1020 }
1021
1022 /// Return true if this is an indirect branch, such as a
1023 /// branch through a register.
1027
1028 /// Return true if this is a branch which may fall
1029 /// through to the next instruction or may transfer control flow to some other
1030 /// block. The TargetInstrInfo::analyzeBranch method can be used to get more
1031 /// information about this branch.
1035
1036 /// Return true if this is a branch which always
1037 /// transfers control flow to some other block. The
1038 /// TargetInstrInfo::analyzeBranch method can be used to get more information
1039 /// about this branch.
1043
1044 /// Return true if this instruction has a predicate operand that
1045 /// controls execution. It may be set to 'always', or may be set to other
1046 /// values. There are various methods in TargetInstrInfo that can be used to
1047 /// control and modify the predicate in this instruction.
1049 // If it's a bundle than all bundled instructions must be predicable for this
1050 // to return true.
1052 }
1053
1054 /// Return true if this instruction is a comparison.
1057 }
1058
1059 /// Return true if this instruction is a move immediate
1060 /// (including conditional moves) instruction.
1064
1065 /// Return true if this instruction is a register move.
1066 /// (including moving values from subreg to reg)
1069 }
1070
1071 /// Return true if this instruction is a bitcast instruction.
1074 }
1075
1076 /// Return true if this instruction is a select instruction.
1078 return hasProperty(MCID::Select, Type);
1079 }
1080
1081 /// Return true if this instruction cannot be safely duplicated.
1082 /// For example, if the instruction has a unique labels attached
1083 /// to it, duplicating it would cause multiple definition errors.
1086 return true;
1088 }
1089
1090 /// Return true if this instruction is convergent.
1091 /// Convergent instructions can not be made control-dependent on any
1092 /// additional values.
1094 if (isInlineAsm()) {
1095 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
1096 if (ExtraInfo & InlineAsm::Extra_IsConvergent)
1097 return true;
1098 }
1099 if (getFlag(NoConvergent))
1100 return false;
1102 }
1103
1104 /// Returns true if the specified instruction has a delay slot
1105 /// which must be filled by the code generator.
1109
1110 /// Return true for instructions that can be folded as
1111 /// memory operands in other instructions. The most common use for this
1112 /// is instructions that are simple loads from memory that don't modify
1113 /// the loaded value in any way, but it can also be used for instructions
1114 /// that can be expressed as constant-pool loads, such as V_SETALLONES
1115 /// on x86, to allow them to be folded when it is beneficial.
1116 /// This should only be set on instructions that return a value in their
1117 /// only virtual register definition.
1121
1122 /// Return true if this instruction behaves
1123 /// the same way as the generic REG_SEQUENCE instructions.
1124 /// E.g., on ARM,
1125 /// dX VMOVDRR rY, rZ
1126 /// is equivalent to
1127 /// dX = REG_SEQUENCE rY, ssub_0, rZ, ssub_1.
1128 ///
1129 /// Note that for the optimizers to be able to take advantage of
1130 /// this property, TargetInstrInfo::getRegSequenceLikeInputs has to be
1131 /// override accordingly.
1135
1136 /// Return true if this instruction behaves
1137 /// the same way as the generic EXTRACT_SUBREG instructions.
1138 /// E.g., on ARM,
1139 /// rX, rY VMOVRRD dZ
1140 /// is equivalent to two EXTRACT_SUBREG:
1141 /// rX = EXTRACT_SUBREG dZ, ssub_0
1142 /// rY = EXTRACT_SUBREG dZ, ssub_1
1143 ///
1144 /// Note that for the optimizers to be able to take advantage of
1145 /// this property, TargetInstrInfo::getExtractSubregLikeInputs has to be
1146 /// override accordingly.
1150
1151 /// Return true if this instruction behaves
1152 /// the same way as the generic INSERT_SUBREG instructions.
1153 /// E.g., on ARM,
1154 /// dX = VSETLNi32 dY, rZ, Imm
1155 /// is equivalent to a INSERT_SUBREG:
1156 /// dX = INSERT_SUBREG dY, rZ, translateImmToSubIdx(Imm)
1157 ///
1158 /// Note that for the optimizers to be able to take advantage of
1159 /// this property, TargetInstrInfo::getInsertSubregLikeInputs has to be
1160 /// override accordingly.
1164
1165 //===--------------------------------------------------------------------===//
1166 // Side Effect Analysis
1167 //===--------------------------------------------------------------------===//
1168
1169 /// Return true if this instruction could possibly read memory.
1170 /// Instructions with this flag set are not necessarily simple load
1171 /// instructions, they may load a value and modify it, for example.
1173 if (isInlineAsm()) {
1174 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
1175 if (ExtraInfo & InlineAsm::Extra_MayLoad)
1176 return true;
1177 }
1179 }
1180
1181 /// Return true if this instruction could possibly modify memory.
1182 /// Instructions with this flag set are not necessarily simple store
1183 /// instructions, they may store a modified value based on their operands, or
1184 /// may not actually modify anything, for example.
1186 if (isInlineAsm()) {
1187 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
1188 if (ExtraInfo & InlineAsm::Extra_MayStore)
1189 return true;
1190 }
1192 }
1193
1194 /// Return true if this instruction could possibly read or modify memory.
1196 return mayLoad(Type) || mayStore(Type);
1197 }
1198
1199 /// Return true if this instruction could possibly raise a floating-point
1200 /// exception. This is the case if the instruction is a floating-point
1201 /// instruction that can in principle raise an exception, as indicated
1202 /// by the MCID::MayRaiseFPException property, *and* at the same time,
1203 /// the instruction is used in a context where we expect floating-point
1204 /// exceptions are not disabled, as indicated by the NoFPExcept MI flag.
1209
1210 //===--------------------------------------------------------------------===//
1211 // Flags that indicate whether an instruction can be modified by a method.
1212 //===--------------------------------------------------------------------===//
1213
1214 /// Return true if this may be a 2- or 3-address
1215 /// instruction (of the form "X = op Y, Z, ..."), which produces the same
1216 /// result if Y and Z are exchanged. If this flag is set, then the
1217 /// TargetInstrInfo::commuteInstruction method may be used to hack on the
1218 /// instruction.
1219 ///
1220 /// Note that this flag may be set on instructions that are only commutable
1221 /// sometimes. In these cases, the call to commuteInstruction will fail.
1222 /// Also note that some instructions require non-trivial modification to
1223 /// commute them.
1227
1228 /// Return true if this is a 2-address instruction
1229 /// which can be changed into a 3-address instruction if needed. Doing this
1230 /// transformation can be profitable in the register allocator, because it
1231 /// means that the instruction can use a 2-address form if possible, but
1232 /// degrade into a less efficient form if the source and dest register cannot
1233 /// be assigned to the same register. For example, this allows the x86
1234 /// backend to turn a "shl reg, 3" instruction into an LEA instruction, which
1235 /// is the same speed as the shift but has bigger code size.
1236 ///
1237 /// If this returns true, then the target must implement the
1238 /// TargetInstrInfo::convertToThreeAddress method for this instruction, which
1239 /// is allowed to fail if the transformation isn't valid for this specific
1240 /// instruction (e.g. shl reg, 4 on x86).
1241 ///
1245
1246 /// Return true if this instruction requires
1247 /// custom insertion support when the DAG scheduler is inserting it into a
1248 /// machine basic block. If this is true for the instruction, it basically
1249 /// means that it is a pseudo instruction used at SelectionDAG time that is
1250 /// expanded out into magic code by the target when MachineInstrs are formed.
1251 ///
1252 /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method
1253 /// is used to insert this into the MachineBasicBlock.
1257
1258 /// Return true if this instruction requires *adjustment*
1259 /// after instruction selection by calling a target hook. For example, this
1260 /// can be used to fill in ARM 's' optional operand depending on whether
1261 /// the conditional flag register is used.
1265
1266 /// Returns true if this instruction is a candidate for remat.
1267 /// This flag is deprecated, please don't use it anymore. If this
1268 /// flag is set, the isReMaterializableImpl() method is called to
1269 /// verify the instruction is really rematerializable.
1271 // It's only possible to re-mat a bundle if all bundled instructions are
1272 // re-materializable.
1274 }
1275
1276 /// Returns true if this instruction has the same cost (or less) than a move
1277 /// instruction. This is useful during certain types of optimizations
1278 /// (e.g., remat during two-address conversion or machine licm)
1279 /// where we would like to remat or hoist the instruction, but not if it costs
1280 /// more than moving the instruction into the appropriate register. Note, we
1281 /// are not marking copies from and to the same register class with this flag.
1283 // Only returns true for a bundle if all bundled instructions are cheap.
1285 }
1286
1287 /// Returns true if this instruction source operands
1288 /// have special register allocation requirements that are not captured by the
1289 /// operand register classes. e.g. ARM::STRD's two source registers must be an
1290 /// even / odd pair, ARM::STM registers have to be in ascending order.
1291 /// Post-register allocation passes should not attempt to change allocations
1292 /// for sources of instructions with this flag.
1296
1297 /// Returns true if this instruction def operands
1298 /// have special register allocation requirements that are not captured by the
1299 /// operand register classes. e.g. ARM::LDRD's two def registers must be an
1300 /// even / odd pair, ARM::LDM registers have to be in ascending order.
1301 /// Post-register allocation passes should not attempt to change allocations
1302 /// for definitions of instructions with this flag.
1306
1308 CheckDefs, // Check all operands for equality
1309 CheckKillDead, // Check all operands including kill / dead markers
1310 IgnoreDefs, // Ignore all definitions
1311 IgnoreVRegDefs // Ignore virtual register definitions
1312 };
1313
1314 /// Return true if this instruction is identical to \p Other.
1315 /// Two instructions are identical if they have the same opcode and all their
1316 /// operands are identical (with respect to MachineOperand::isIdenticalTo()).
1317 /// Note that this means liveness related flags (dead, undef, kill) do not
1318 /// affect the notion of identical.
1320 MICheckType Check = CheckDefs) const;
1321
1322 /// Returns true if this instruction is a debug instruction that represents an
1323 /// identical debug value to \p Other.
1324 /// This function considers these debug instructions equivalent if they have
1325 /// identical variables, debug locations, and debug operands, and if the
1326 /// DIExpressions combined with the directness flags are equivalent.
1328
1329 /// Unlink 'this' from the containing basic block, and return it without
1330 /// deleting it.
1331 ///
1332 /// This function can not be used on bundled instructions, use
1333 /// removeFromBundle() to remove individual instructions from a bundle.
1335
1336 /// Unlink this instruction from its basic block and return it without
1337 /// deleting it.
1338 ///
1339 /// If the instruction is part of a bundle, the other instructions in the
1340 /// bundle remain bundled.
1342
1343 /// Unlink 'this' from the containing basic block and delete it.
1344 ///
1345 /// If this instruction is the header of a bundle, the whole bundle is erased.
1346 /// This function can not be used for instructions inside a bundle, use
1347 /// eraseFromBundle() to erase individual bundled instructions.
1348 /// \returns the iterator following the erased instruction. If this is the
1349 /// header of a bundle it returns the iterator following the erased bundle
1350 /// iterator.
1352
1353 /// Unlink 'this' from its basic block and delete it.
1354 ///
1355 /// If the instruction is part of a bundle, the other instructions in the
1356 /// bundle remain bundled.
1358
1359 bool isEHLabel() const { return getOpcode() == TargetOpcode::EH_LABEL; }
1360 bool isGCLabel() const { return getOpcode() == TargetOpcode::GC_LABEL; }
1361 bool isAnnotationLabel() const {
1362 return getOpcode() == TargetOpcode::ANNOTATION_LABEL;
1363 }
1364
1365 bool isLifetimeMarker() const {
1366 return getOpcode() == TargetOpcode::LIFETIME_START ||
1367 getOpcode() == TargetOpcode::LIFETIME_END;
1368 }
1369
1370 /// Returns true if the MachineInstr represents a label.
1371 bool isLabel() const {
1372 return isEHLabel() || isGCLabel() || isAnnotationLabel();
1373 }
1374
1375 bool isCFIInstruction() const {
1376 return getOpcode() == TargetOpcode::CFI_INSTRUCTION;
1377 }
1378
1379 bool isPseudoProbe() const {
1380 return getOpcode() == TargetOpcode::PSEUDO_PROBE;
1381 }
1382
1383 // True if the instruction represents a position in the function.
1384 // FIXME: Why are LIFETIME markers not considered in MachineInstr::isPosition?
1385 bool isPosition() const { return isLabel() || isCFIInstruction(); }
1386
1387 bool isNonListDebugValue() const {
1388 return getOpcode() == TargetOpcode::DBG_VALUE;
1389 }
1390 bool isDebugValueList() const {
1391 return getOpcode() == TargetOpcode::DBG_VALUE_LIST;
1392 }
1393 bool isDebugValue() const {
1395 }
1396 bool isDebugLabel() const { return getOpcode() == TargetOpcode::DBG_LABEL; }
1397 bool isDebugRef() const { return getOpcode() == TargetOpcode::DBG_INSTR_REF; }
1398 bool isDebugValueLike() const { return isDebugValue() || isDebugRef(); }
1399 bool isDebugPHI() const { return getOpcode() == TargetOpcode::DBG_PHI; }
1400 bool isDebugInstr() const {
1401 return isDebugValue() || isDebugLabel() || isDebugRef() || isDebugPHI();
1402 }
1404 return isDebugInstr() || isPseudoProbe();
1405 }
1406
1407 bool isDebugOffsetImm() const {
1409 }
1410
1411 /// A DBG_VALUE is indirect iff the location operand is a register and
1412 /// the offset operand is an immediate.
1414 return isDebugOffsetImm() && getDebugOperand(0).isReg();
1415 }
1416
1417 /// A DBG_VALUE is an entry value iff its debug expression contains the
1418 /// DW_OP_LLVM_entry_value operation.
1419 LLVM_ABI bool isDebugEntryValue() const;
1420
1421 /// Return true if the instruction is a debug value which describes a part of
1422 /// a variable as unavailable.
1423 bool isUndefDebugValue() const {
1424 if (!isDebugValue())
1425 return false;
1426 // If any $noreg locations are given, this DV is undef.
1427 for (const MachineOperand &Op : debug_operands())
1428 if (Op.isReg() && !Op.getReg().isValid())
1429 return true;
1430 return false;
1431 }
1432
1434 return getOpcode() == TargetOpcode::JUMP_TABLE_DEBUG_INFO;
1435 }
1436
1437 bool isPHI() const {
1438 return getOpcode() == TargetOpcode::PHI ||
1439 getOpcode() == TargetOpcode::G_PHI;
1440 }
1441 bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
1442 bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; }
1443 bool isInlineAsm() const {
1444 return getOpcode() == TargetOpcode::INLINEASM ||
1445 getOpcode() == TargetOpcode::INLINEASM_BR;
1446 }
1447 /// Returns true if the register operand can be folded with a load or store
1448 /// into a frame index. Does so by checking the InlineAsm::Flag immediate
1449 /// operand at OpId - 1.
1450 LLVM_ABI bool mayFoldInlineAsmRegOp(unsigned OpId) const;
1451
1454
1455 bool isInsertSubreg() const {
1456 return getOpcode() == TargetOpcode::INSERT_SUBREG;
1457 }
1458
1459 bool isSubregToReg() const {
1460 return getOpcode() == TargetOpcode::SUBREG_TO_REG;
1461 }
1462
1463 bool isRegSequence() const {
1464 return getOpcode() == TargetOpcode::REG_SEQUENCE;
1465 }
1466
1467 bool isBundle() const {
1468 return getOpcode() == TargetOpcode::BUNDLE;
1469 }
1470
1471 bool isCopy() const {
1472 return getOpcode() == TargetOpcode::COPY;
1473 }
1474
1475 bool isCopyLaneMask() const {
1476 return getOpcode() == TargetOpcode::COPY_LANEMASK;
1477 }
1478
1479 bool isFullCopy() const {
1480 return isCopy() && !getOperand(0).getSubReg() && !getOperand(1).getSubReg();
1481 }
1482
1483 bool isExtractSubreg() const {
1484 return getOpcode() == TargetOpcode::EXTRACT_SUBREG;
1485 }
1486
1487 bool isFakeUse() const { return getOpcode() == TargetOpcode::FAKE_USE; }
1488
1489 /// Return true if the instruction behaves like a copy.
1490 /// This does not include native copy instructions.
1491 bool isCopyLike() const {
1492 return isCopy() || isSubregToReg();
1493 }
1494
1495 /// Return true is the instruction is an identity copy.
1496 bool isIdentityCopy() const {
1497 return isCopy() && getOperand(0).getReg() == getOperand(1).getReg() &&
1499 }
1500
1501 /// Return true if this is a transient instruction that is either very likely
1502 /// to be eliminated during register allocation (such as copy-like
1503 /// instructions), or if this instruction doesn't have an execution-time cost.
1504 bool isTransient() const {
1505 switch (getOpcode()) {
1506 default:
1507 return isMetaInstruction();
1508 // Copy-like instructions are usually eliminated during register allocation.
1509 case TargetOpcode::PHI:
1510 case TargetOpcode::G_PHI:
1511 case TargetOpcode::COPY:
1512 case TargetOpcode::COPY_LANEMASK:
1513 case TargetOpcode::INSERT_SUBREG:
1514 case TargetOpcode::SUBREG_TO_REG:
1515 case TargetOpcode::REG_SEQUENCE:
1516 return true;
1517 }
1518 }
1519
1520 /// Return the number of instructions inside the MI bundle, excluding the
1521 /// bundle header.
1522 ///
1523 /// This is the number of instructions that MachineBasicBlock::iterator
1524 /// skips, 0 for unbundled instructions.
1525 LLVM_ABI unsigned getBundleSize() const;
1526
1527 /// Return true if the MachineInstr reads the specified register.
1528 /// If TargetRegisterInfo is non-null, then it also checks if there
1529 /// is a read of a super-register.
1530 /// This does not count partial redefines of virtual registers as reads:
1531 /// %reg1024:6 = OP.
1533 return findRegisterUseOperandIdx(Reg, TRI, false) != -1;
1534 }
1535
1536 /// Return true if two operands read (Reg, SubReg) and one is tied to a def of
1537 /// another register. Such reads may not be marked undef: rewriting the tie
1538 /// would separate them.
1539 LLVM_ABI bool hasTiedAndOtherReadOf(Register Reg, unsigned SubReg) const;
1540
1541 /// Return true if the MachineInstr reads the specified virtual register.
1542 /// Take into account that a partial define is a
1543 /// read-modify-write operation.
1545 return readsWritesVirtualRegister(Reg).first;
1546 }
1547
1548 /// Return a pair of bools (reads, writes) indicating if this instruction
1549 /// reads or writes Reg. This also considers partial defines.
1550 /// If Ops is not null, all operand indices for Reg are added.
1551 LLVM_ABI std::pair<bool, bool>
1553 SmallVectorImpl<unsigned> *Ops = nullptr) const;
1554
1555 /// Return true if the MachineInstr kills the specified register.
1556 /// If TargetRegisterInfo is non-null, then it also checks if there is
1557 /// a kill of a super-register.
1559 return findRegisterUseOperandIdx(Reg, TRI, true) != -1;
1560 }
1561
1562 /// Return true if the MachineInstr fully defines the specified register.
1563 /// If TargetRegisterInfo is non-null, then it also checks
1564 /// if there is a def of a super-register.
1565 /// NOTE: It's ignoring subreg indices on virtual registers.
1567 return findRegisterDefOperandIdx(Reg, TRI, false, false) != -1;
1568 }
1569
1570 /// Return true if the MachineInstr modifies (fully define or partially
1571 /// define) the specified register.
1572 /// NOTE: It's ignoring subreg indices on virtual registers.
1574 return findRegisterDefOperandIdx(Reg, TRI, false, true) != -1;
1575 }
1576
1577 /// Returns true if the register is dead in this machine instruction.
1578 /// If TargetRegisterInfo is non-null, then it also checks
1579 /// if there is a dead def of a super-register.
1581 return findRegisterDefOperandIdx(Reg, TRI, true, false) != -1;
1582 }
1583
1584 /// Returns true if the MachineInstr has an implicit-use operand of exactly
1585 /// the given register (not considering sub/super-registers).
1587
1588 /// Returns the operand index that is a use of the specific register or -1
1589 /// if it is not found. It further tightens the search criteria to a use
1590 /// that kills the register if isKill is true.
1592 const TargetRegisterInfo *TRI,
1593 bool isKill = false) const;
1594
1595 /// Wrapper for findRegisterUseOperandIdx, it returns
1596 /// a pointer to the MachineOperand rather than an index.
1598 const TargetRegisterInfo *TRI,
1599 bool isKill = false) {
1601 return (Idx == -1) ? nullptr : &getOperand(Idx);
1602 }
1603
1605 const TargetRegisterInfo *TRI,
1606 bool isKill = false) const {
1607 return const_cast<MachineInstr *>(this)->findRegisterUseOperand(Reg, TRI,
1608 isKill);
1609 }
1610
1611 /// Returns the operand index that is a def of the specified register or
1612 /// -1 if it is not found. If isDead is true, defs that are not dead are
1613 /// skipped. If Overlap is true, then it also looks for defs that merely
1614 /// overlap the specified register. If TargetRegisterInfo is non-null,
1615 /// then it also checks if there is a def of a super-register.
1616 /// This may also return a register mask operand when Overlap is true.
1618 const TargetRegisterInfo *TRI,
1619 bool isDead = false,
1620 bool Overlap = false) const;
1621
1622 /// Wrapper for findRegisterDefOperandIdx, it returns
1623 /// a pointer to the MachineOperand rather than an index.
1625 const TargetRegisterInfo *TRI,
1626 bool isDead = false,
1627 bool Overlap = false) {
1628 int Idx = findRegisterDefOperandIdx(Reg, TRI, isDead, Overlap);
1629 return (Idx == -1) ? nullptr : &getOperand(Idx);
1630 }
1631
1633 const TargetRegisterInfo *TRI,
1634 bool isDead = false,
1635 bool Overlap = false) const {
1636 return const_cast<MachineInstr *>(this)->findRegisterDefOperand(
1637 Reg, TRI, isDead, Overlap);
1638 }
1639
1640 /// Find the index of the first operand in the
1641 /// operand list that is used to represent the predicate. It returns -1 if
1642 /// none is found.
1644
1645 /// Find the index of the flag word operand that
1646 /// corresponds to operand OpIdx on an inline asm instruction. Returns -1 if
1647 /// getOperand(OpIdx) does not belong to an inline asm operand group.
1648 ///
1649 /// If GroupNo is not NULL, it will receive the number of the operand group
1650 /// containing OpIdx.
1651 LLVM_ABI int findInlineAsmFlagIdx(unsigned OpIdx,
1652 unsigned *GroupNo = nullptr) const;
1653
1654 /// Compute the static register class constraint for operand OpIdx.
1655 /// For normal instructions, this is derived from the MCInstrDesc.
1656 /// For inline assembly it is derived from the flag words.
1657 ///
1658 /// Returns NULL if the static register class constraint cannot be
1659 /// determined.
1661 getRegClassConstraint(unsigned OpIdx, const TargetInstrInfo *TII,
1662 const TargetRegisterInfo *TRI) const;
1663
1664 /// Applies the constraints (def/use) implied by this MI on \p Reg to
1665 /// the given \p CurRC.
1666 /// If \p ExploreBundle is set and MI is part of a bundle, all the
1667 /// instructions inside the bundle will be taken into account. In other words,
1668 /// this method accumulates all the constraints of the operand of this MI and
1669 /// the related bundle if MI is a bundle or inside a bundle.
1670 ///
1671 /// Returns the register class that satisfies both \p CurRC and the
1672 /// constraints set by MI. Returns NULL if such a register class does not
1673 /// exist.
1674 ///
1675 /// \pre CurRC must not be NULL.
1677 Register Reg, const TargetRegisterClass *CurRC,
1679 bool ExploreBundle = false) const;
1680
1681 /// Applies the constraints (def/use) implied by the \p OpIdx operand
1682 /// to the given \p CurRC.
1683 ///
1684 /// Returns the register class that satisfies both \p CurRC and the
1685 /// constraints set by \p OpIdx MI. Returns NULL if such a register class
1686 /// does not exist.
1687 ///
1688 /// \pre CurRC must not be NULL.
1689 /// \pre The operand at \p OpIdx must be a register.
1691 getRegClassConstraintEffect(unsigned OpIdx, const TargetRegisterClass *CurRC,
1692 const TargetInstrInfo *TII,
1693 const TargetRegisterInfo *TRI) const;
1694
1695 /// Add a tie between the register operands at DefIdx and UseIdx.
1696 /// The tie will cause the register allocator to ensure that the two
1697 /// operands are assigned the same physical register.
1698 ///
1699 /// Tied operands are managed automatically for explicit operands in the
1700 /// MCInstrDesc. This method is for exceptional cases like inline asm.
1701 LLVM_ABI void tieOperands(unsigned DefIdx, unsigned UseIdx);
1702
1703 /// Given the index of a tied register operand, find the
1704 /// operand it is tied to. Defs are tied to uses and vice versa. Returns the
1705 /// index of the tied operand which must exist.
1706 LLVM_ABI unsigned findTiedOperandIdx(unsigned OpIdx) const;
1707
1708 /// Given the index of a register def operand,
1709 /// check if the register def is tied to a source operand, due to either
1710 /// two-address elimination or inline assembly constraints. Returns the
1711 /// first tied use operand index by reference if UseOpIdx is not null.
1712 bool isRegTiedToUseOperand(unsigned DefOpIdx,
1713 unsigned *UseOpIdx = nullptr) const {
1714 const MachineOperand &MO = getOperand(DefOpIdx);
1715 if (!MO.isReg() || !MO.isDef() || !MO.isTied())
1716 return false;
1717 if (UseOpIdx)
1718 *UseOpIdx = findTiedOperandIdx(DefOpIdx);
1719 return true;
1720 }
1721
1722 /// Return true if the use operand of the specified index is tied to a def
1723 /// operand. It also returns the def operand index by reference if DefOpIdx
1724 /// is not null.
1725 bool isRegTiedToDefOperand(unsigned UseOpIdx,
1726 unsigned *DefOpIdx = nullptr) const {
1727 const MachineOperand &MO = getOperand(UseOpIdx);
1728 if (!MO.isReg() || !MO.isUse() || !MO.isTied())
1729 return false;
1730 if (DefOpIdx)
1731 *DefOpIdx = findTiedOperandIdx(UseOpIdx);
1732 return true;
1733 }
1734
1735 /// Clears kill flags on all operands.
1736 LLVM_ABI void clearKillInfo();
1737
1738 /// Replace all occurrences of FromReg with ToReg:SubIdx,
1739 /// properly composing subreg indices where necessary.
1740 LLVM_ABI void substituteRegister(Register FromReg, Register ToReg,
1741 unsigned SubIdx,
1743
1744 /// We have determined MI kills a register. Look for the
1745 /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
1746 /// add a implicit operand if it's not found. Returns true if the operand
1747 /// exists / is added.
1748 LLVM_ABI bool addRegisterKilled(Register IncomingReg,
1750 bool AddIfNotFound = false);
1751
1752 /// Clear all kill flags affecting Reg. If RegInfo is provided, this includes
1753 /// all aliasing registers.
1756
1757 /// We have determined MI defined a register without a use.
1758 /// Look for the operand that defines it and mark it as IsDead. If
1759 /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
1760 /// true if the operand exists / is added.
1762 bool AddIfNotFound = false);
1763
1764 /// Clear all dead flags on operands defining register @p Reg.
1766
1767 /// Mark all subregister defs of register @p Reg with the undef flag.
1768 /// This function is used when we determined to have a subregister def in an
1769 /// otherwise undefined super register.
1770 LLVM_ABI void setRegisterDefReadUndef(Register Reg, bool IsUndef = true);
1771
1772 /// We have determined MI defines a register. Make sure there is an operand
1773 /// defining Reg.
1775 const TargetRegisterInfo *RegInfo = nullptr);
1776
1777 /// Mark every physreg used by this instruction as
1778 /// dead except those in the UsedRegs list.
1779 ///
1780 /// On instructions with register mask operands, also add implicit-def
1781 /// operands for all registers in UsedRegs.
1783 const TargetRegisterInfo &TRI);
1784
1785 /// Mark the implicit physreg defs named by the instruction description as
1786 /// dead.
1788 unsigned Idx = getNumExplicitOperands();
1789 for (unsigned E = Idx + MCID->implicit_defs().size(); Idx != E; ++Idx)
1790 getOperand(Idx).setIsDead();
1791 }
1792
1793 /// Return true if it is safe to move this instruction. If
1794 /// SawStore is set to true, it means that there is a store (or call) between
1795 /// the instruction's location and its intended destination.
1796 LLVM_ABI bool isSafeToMove(bool &SawStore) const;
1797
1798 /// Return true if this instruction would be trivially dead if all of its
1799 /// defined registers were dead.
1800 LLVM_ABI bool wouldBeTriviallyDead() const;
1801
1802 /// Check whether an MI is dead. If \p LivePhysRegs is provided, it is assumed
1803 /// to be at the position of MI and will be used to check the Liveness of
1804 /// physical register defs. If \p LivePhysRegs is not provided, this will
1805 /// pessimistically assume any PhysReg def is live.
1806 /// For trivially dead instructions (i.e. those without hard to model effects
1807 /// / wouldBeTriviallyDead), this checks deadness by analyzing defs of the
1808 /// MachineInstr. If the instruction wouldBeTriviallyDead, and all the defs
1809 /// either have dead flags or have no uses, then the instruction is said to be
1810 /// dead.
1812 LiveRegUnits *LivePhysRegs = nullptr) const;
1813
1814 /// Returns true if this instruction's memory access aliases the memory
1815 /// access of Other.
1816 //
1817 /// Assumes any physical registers used to compute addresses
1818 /// have the same value for both instructions. Returns false if neither
1819 /// instruction writes to memory.
1820 ///
1821 /// @param AA Optional alias analysis, used to compare memory operands.
1822 /// @param Other MachineInstr to check aliasing against.
1823 /// @param UseTBAA Whether to pass TBAA information to alias analysis.
1825 bool UseTBAA) const;
1827 bool UseTBAA) const;
1828
1829 /// Return true if this instruction may have an ordered
1830 /// or volatile memory reference, or if the information describing the memory
1831 /// reference is not available. Return false if it is known to have no
1832 /// ordered or volatile memory references.
1833 LLVM_ABI bool hasOrderedMemoryRef() const;
1834
1835 /// Return true if this load instruction never traps and points to a memory
1836 /// location whose value doesn't change during the execution of this function.
1837 ///
1838 /// Examples include loading a value from the constant pool or from the
1839 /// argument area of a function (if it does not change). If the instruction
1840 /// does multiple loads, this returns true only if all of the loads are
1841 /// dereferenceable and invariant.
1843
1844 /// If the specified instruction is a PHI that always merges together the
1845 /// same virtual register, return the register, otherwise return Register().
1847
1848 /// Return true if this instruction has side effects that are not modeled
1849 /// by mayLoad / mayStore, etc.
1850 /// For all instructions, the property is encoded in MCInstrDesc::Flags
1851 /// (see MCInstrDesc::hasUnmodeledSideEffects(). The only exception is
1852 /// INLINEASM instruction, in which case the side effect property is encoded
1853 /// in one of its operands (see InlineAsm::Extra_HasSideEffect).
1854 ///
1855 LLVM_ABI bool hasUnmodeledSideEffects() const;
1856
1857 /// Returns true if it is illegal to fold a load across this instruction.
1858 LLVM_ABI bool isLoadFoldBarrier() const;
1859
1860 /// Return true if all the defs of this instruction are dead.
1861 LLVM_ABI bool allDefsAreDead() const;
1862
1863 /// Return true if all the implicit defs of this instruction are dead.
1864 LLVM_ABI bool allImplicitDefsAreDead() const;
1865
1866 /// Return a valid size if the instruction is a spill instruction.
1867 LLVM_ABI std::optional<LocationSize>
1868 getSpillSize(const TargetInstrInfo *TII) const;
1869
1870 /// Return a valid size if the instruction is a folded spill instruction.
1871 LLVM_ABI std::optional<LocationSize>
1873
1874 /// Return a valid size if the instruction is a restore instruction.
1875 LLVM_ABI std::optional<LocationSize>
1876 getRestoreSize(const TargetInstrInfo *TII) const;
1877
1878 /// Return a valid size if the instruction is a folded restore instruction.
1879 LLVM_ABI std::optional<LocationSize>
1881
1882 /// Copy implicit register operands from specified
1883 /// instruction to this instruction.
1885
1886 /// Debugging support
1887 /// @{
1888 /// Determine the generic type to be printed (if needed) on uses and defs.
1889 LLVM_ABI LLT getTypeToPrint(unsigned OpIdx, SmallBitVector &PrintedTypes,
1890 const MachineRegisterInfo &MRI) const;
1891
1892 /// Return true when an instruction has tied register that can't be determined
1893 /// by the instruction's descriptor. This is useful for MIR printing, to
1894 /// determine whether we need to print the ties or not.
1895 LLVM_ABI bool hasComplexRegisterTies() const;
1896
1897 /// Print this MI to \p OS.
1898 /// Don't print information that can be inferred from other instructions if
1899 /// \p IsStandalone is false. It is usually true when only a fragment of the
1900 /// function is printed.
1901 /// Only print the defs and the opcode if \p SkipOpers is true.
1902 /// Otherwise, also print operands if \p SkipDebugLoc is true.
1903 /// Otherwise, also print the debug loc, with a terminating newline.
1904 /// \p TII is used to print the opcode name. If it's not present, but the
1905 /// MI is in a function, the opcode will be printed using the function's TII.
1906 LLVM_ABI void print(raw_ostream &OS, bool IsStandalone = true,
1907 bool SkipOpers = false, bool SkipDebugLoc = false,
1908 bool AddNewLine = true,
1909 const TargetInstrInfo *TII = nullptr) const;
1911 bool IsStandalone = true, bool SkipOpers = false,
1912 bool SkipDebugLoc = false, bool AddNewLine = true,
1913 const TargetInstrInfo *TII = nullptr) const;
1914 LLVM_ABI void dump() const;
1915 /// Print on dbgs() the current instruction and the instructions defining its
1916 /// operands and so on until we reach \p MaxDepth.
1918 unsigned MaxDepth = UINT_MAX) const;
1919 /// @}
1920
1921 //===--------------------------------------------------------------------===//
1922 // Accessors used to build up machine instructions.
1923
1924 /// Add the specified operand to the instruction. If it is an implicit
1925 /// operand, it is added to the end of the operand list. If it is an
1926 /// explicit operand it is added at the end of the explicit operand list
1927 /// (before the first implicit operand).
1928 ///
1929 /// MF must be the machine function that was used to allocate this
1930 /// instruction.
1931 ///
1932 /// MachineInstrBuilder provides a more convenient interface for creating
1933 /// instructions and adding operands.
1935
1936 /// Add an operand without providing an MF reference. This only works for
1937 /// instructions that are inserted in a basic block.
1938 ///
1939 /// MachineInstrBuilder and the two-argument addOperand(MF, MO) should be
1940 /// preferred.
1941 LLVM_ABI void addOperand(const MachineOperand &Op);
1942
1943 /// Inserts Ops BEFORE It. Can untie/retie tied operands.
1945
1946 /// Replace the instruction descriptor (thus opcode) of
1947 /// the current instruction with a new one.
1948 LLVM_ABI void setDesc(const MCInstrDesc &TID);
1949
1950 /// Replace current source information with new such.
1951 /// Avoid using this, the constructor argument is preferable.
1952 void setDebugLoc(DebugLoc DL) { DbgLoc = std::move(DL); }
1953
1954 /// Erase an operand from an instruction, leaving it with one
1955 /// fewer operand than it started with.
1956 LLVM_ABI void removeOperand(unsigned OpNo);
1957
1958 /// Clear this MachineInstr's memory reference descriptor list. This resets
1959 /// the memrefs to their most conservative state. This should be used only
1960 /// as a last resort since it greatly pessimizes our knowledge of the memory
1961 /// access performed by the instruction.
1963
1964 /// Assign this MachineInstr's memory reference descriptor list.
1965 ///
1966 /// Unlike other methods, this *will* allocate them into a new array
1967 /// associated with the provided `MachineFunction`.
1970
1971 /// Add a MachineMemOperand to the machine instruction.
1972 /// This function should be used only occasionally. The setMemRefs function
1973 /// is the primary method for setting up a MachineInstr's MemRefs list.
1975
1976 /// Clone another MachineInstr's memory reference descriptor list and replace
1977 /// ours with it.
1978 ///
1979 /// Note that `*this` may be the incoming MI!
1980 ///
1981 /// Prefer this API whenever possible as it can avoid allocations in common
1982 /// cases.
1984
1985 /// Clone the merge of multiple MachineInstrs' memory reference descriptors
1986 /// list and replace ours with it.
1987 ///
1988 /// Note that `*this` may be one of the incoming MIs!
1989 ///
1990 /// Prefer this API whenever possible as it can avoid allocations in common
1991 /// cases.
1994
1995 /// Set a symbol that will be emitted just prior to the instruction itself.
1996 ///
1997 /// Setting this to a null pointer will remove any such symbol.
1998 ///
1999 /// FIXME: This is not fully implemented yet.
2001
2002 /// Set a symbol that will be emitted just after the instruction itself.
2003 ///
2004 /// Setting this to a null pointer will remove any such symbol.
2005 ///
2006 /// FIXME: This is not fully implemented yet.
2008
2009 /// Clone another MachineInstr's pre- and post- instruction symbols and
2010 /// replace ours with it.
2012
2013 /// Set a marker on instructions that denotes where we should create and emit
2014 /// heap alloc site labels. This waits until after instruction selection and
2015 /// optimizations to create the label, so it should still work if the
2016 /// instruction is removed or duplicated.
2018
2019 // Set metadata on instructions that say which sections to emit instruction
2020 // addresses into.
2022
2024
2025 /// Set the CFI type for the instruction.
2027
2029
2030 /// Return the MIFlags which represent both MachineInstrs. This
2031 /// should be used when merging two MachineInstrs into one. This routine does
2032 /// not modify the MIFlags of this MachineInstr.
2034
2036
2037 /// Copy all flags to MachineInst MIFlags
2038 LLVM_ABI void copyIRFlags(const Instruction &I);
2039
2040 /// Break any tie involving OpIdx.
2041 void untieRegOperand(unsigned OpIdx) {
2042 MachineOperand &MO = getOperand(OpIdx);
2043 if (MO.isReg() && MO.isTied()) {
2044 getOperand(findTiedOperandIdx(OpIdx)).TiedTo = 0;
2045 MO.TiedTo = 0;
2046 }
2047 }
2048
2049 /// Add all implicit def and use operands to this instruction.
2051
2052 /// Scan instructions immediately following MI and collect any matching
2053 /// DBG_VALUEs.
2055
2056 /// Find all DBG_VALUEs that point to the register def in this instruction
2057 /// and point them to \p Reg instead.
2059
2060 /// Remove all incoming values of Phi instruction for the given block.
2061 ///
2062 /// Return deleted operands count.
2063 ///
2064 /// Method does not erase PHI instruction even if it has single income or does
2065 /// not have incoming values at all. It is a caller responsibility to make
2066 /// decision how to process PHI instruction after incoming values removed.
2068
2069 /// Sets all register debug operands in this debug value instruction to be
2070 /// undef.
2072 assert(isDebugValue() && "Must be a debug value instruction.");
2073 for (MachineOperand &MO : debug_operands()) {
2074 if (MO.isReg()) {
2075 MO.setReg(0);
2076 MO.setSubReg(0);
2077 }
2078 }
2079 }
2080
2081 std::tuple<Register, Register> getFirst2Regs() const {
2082 return std::tuple(getOperand(0).getReg(), getOperand(1).getReg());
2083 }
2084
2085 std::tuple<Register, Register, Register> getFirst3Regs() const {
2086 return std::tuple(getOperand(0).getReg(), getOperand(1).getReg(),
2087 getOperand(2).getReg());
2088 }
2089
2090 std::tuple<Register, Register, Register, Register> getFirst4Regs() const {
2091 return std::tuple(getOperand(0).getReg(), getOperand(1).getReg(),
2092 getOperand(2).getReg(), getOperand(3).getReg());
2093 }
2094
2095 std::tuple<Register, Register, Register, Register, Register>
2097 return std::tuple(getOperand(0).getReg(), getOperand(1).getReg(),
2099 getOperand(4).getReg());
2100 }
2101
2102 LLVM_ABI std::tuple<LLT, LLT> getFirst2LLTs() const;
2103 LLVM_ABI std::tuple<LLT, LLT, LLT> getFirst3LLTs() const;
2104 LLVM_ABI std::tuple<LLT, LLT, LLT, LLT> getFirst4LLTs() const;
2105 LLVM_ABI std::tuple<LLT, LLT, LLT, LLT, LLT> getFirst5LLTs() const;
2106
2107 LLVM_ABI std::tuple<Register, LLT, Register, LLT> getFirst2RegLLTs() const;
2108 LLVM_ABI std::tuple<Register, LLT, Register, LLT, Register, LLT>
2109 getFirst3RegLLTs() const;
2110 LLVM_ABI
2111 std::tuple<Register, LLT, Register, LLT, Register, LLT, Register, LLT>
2112 getFirst4RegLLTs() const;
2114 LLT, Register, LLT>
2115 getFirst5RegLLTs() const;
2116
2117private:
2118 /// If this instruction is embedded into a MachineFunction, return the
2119 /// MachineRegisterInfo object for the current function, otherwise
2120 /// return null.
2121 MachineRegisterInfo *getRegInfo();
2122 const MachineRegisterInfo *getRegInfo() const;
2123
2124 /// Unlink all of the register operands in this instruction from their
2125 /// respective use lists. This requires that the operands already be on their
2126 /// use lists.
2127 void removeRegOperandsFromUseLists(MachineRegisterInfo&);
2128
2129 /// Add all of the register operands in this instruction from their
2130 /// respective use lists. This requires that the operands not be on their
2131 /// use lists yet.
2132 void addRegOperandsToUseLists(MachineRegisterInfo&);
2133
2134 /// Slow path for hasProperty when we're dealing with a bundle.
2135 LLVM_ABI bool hasPropertyInBundle(uint64_t Mask, QueryType Type) const;
2136
2137 /// Implements the logic of getRegClassConstraintEffectForVReg for the
2138 /// this MI and the given operand index \p OpIdx.
2139 /// If the related operand does not constrained Reg, this returns CurRC.
2140 const TargetRegisterClass *getRegClassConstraintEffectForVRegImpl(
2141 unsigned OpIdx, Register Reg, const TargetRegisterClass *CurRC,
2142 const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const;
2143
2144 /// Stores extra instruction information inline or allocates as ExtraInfo
2145 /// based on the number of pointers.
2146 void setExtraInfo(MachineFunction &MF, ArrayRef<MachineMemOperand *> MMOs,
2147 MCSymbol *PreInstrSymbol, MCSymbol *PostInstrSymbol,
2148 MDNode *HeapAllocMarker, MDNode *PCSections,
2149 uint32_t CFIType, MDNode *MMRAs, Value *DS);
2150};
2151
2152/// Special DenseMapInfo traits to compare MachineInstr* by *value* of the
2153/// instruction rather than by pointer value.
2154/// The hashing and equality testing functions ignore definitions so this is
2155/// useful for CSE, etc.
2157 LLVM_ABI static unsigned getHashValue(const MachineInstr *const &MI);
2158
2159 static bool isEqual(const MachineInstr *const &LHS,
2160 const MachineInstr *const &RHS) {
2161 return LHS->isIdenticalTo(*RHS, MachineInstr::IgnoreVRegDefs);
2162 }
2163};
2164
2165//===----------------------------------------------------------------------===//
2166// Debugging Support
2167
2169 MI.print(OS);
2170 return OS;
2171}
2172
2173} // end namespace llvm
2174
2175#endif // LLVM_CODEGEN_MACHINEINSTR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
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)
#define P(N)
MachineRegisterInfo & MRI
Basic Register Allocator
SI Fold Operands
bool isDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
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:1087
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...
static constexpr uint32_t getPoisonGeneratingFlags()
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
void setImplicitPhysRegDefsDead()
Mark the implicit physreg defs named by the instruction description as dead.
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.
friend class SlotIndexes
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 bool hasTiedAndOtherReadOf(Register Reg, unsigned SubReg) const
Return true if two operands read (Reg, SubReg) and one is tied to a def of another register.
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.
void setIsDead(bool Val=true)
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:166
@ 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:1685
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:1762
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
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:552
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:1901
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:539
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391
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