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