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