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