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