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