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