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