1 //===- llvm/CodeGen/MachineInstr.h - MachineInstr class ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the declaration of the MachineInstr class, which is the
10 // basic representation for all target dependent machine instructions used by
11 // the back end.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_MACHINEINSTR_H
16 #define LLVM_CODEGEN_MACHINEINSTR_H
17 
18 #include "llvm/ADT/DenseMapInfo.h"
19 #include "llvm/ADT/PointerSumType.h"
20 #include "llvm/ADT/ilist.h"
21 #include "llvm/ADT/ilist_node.h"
22 #include "llvm/ADT/iterator_range.h"
23 #include "llvm/CodeGen/MachineMemOperand.h"
24 #include "llvm/CodeGen/MachineOperand.h"
25 #include "llvm/CodeGen/TargetOpcodes.h"
26 #include "llvm/IR/DebugLoc.h"
27 #include "llvm/IR/InlineAsm.h"
28 #include "llvm/MC/MCInstrDesc.h"
29 #include "llvm/MC/MCSymbol.h"
30 #include "llvm/Support/ArrayRecycler.h"
31 #include "llvm/Support/TrailingObjects.h"
32 #include <algorithm>
33 #include <cassert>
34 #include <cstdint>
35 #include <utility>
36 
37 namespace llvm {
38 
39 class AAResults;
40 template <typename T> class ArrayRef;
41 class DIExpression;
42 class DILocalVariable;
43 class MachineBasicBlock;
44 class MachineFunction;
45 class MachineMemOperand;
46 class MachineRegisterInfo;
47 class ModuleSlotTracker;
48 class raw_ostream;
49 template <typename T> class SmallVectorImpl;
50 class SmallBitVector;
51 class StringRef;
52 class TargetInstrInfo;
53 class TargetRegisterClass;
54 class TargetRegisterInfo;
55 
56 //===----------------------------------------------------------------------===//
57 /// Representation of each machine instruction.
58 ///
59 /// This class isn't a POD type, but it must have a trivial destructor. When a
60 /// MachineFunction is deleted, all the contained MachineInstrs are deallocated
61 /// without having their destructor called.
62 ///
63 class MachineInstr
64     : public ilist_node_with_parent<MachineInstr, MachineBasicBlock,
65                                     ilist_sentinel_tracking<true>> {
66 public:
67   using mmo_iterator = ArrayRef<MachineMemOperand *>::iterator;
68 
69   /// Flags to specify different kinds of comments to output in
70   /// assembly code.  These flags carry semantic information not
71   /// otherwise easily derivable from the IR text.
72   ///
73   enum CommentFlag {
74     ReloadReuse = 0x1,    // higher bits are reserved for target dep comments.
75     NoSchedComment = 0x2,
76     TAsmComments = 0x4    // Target Asm comments should start from this value.
77   };
78 
79   enum MIFlag {
80     NoFlags      = 0,
81     FrameSetup   = 1 << 0,              // Instruction is used as a part of
82                                         // function frame setup code.
83     FrameDestroy = 1 << 1,              // Instruction is used as a part of
84                                         // function frame destruction code.
85     BundledPred  = 1 << 2,              // Instruction has bundled predecessors.
86     BundledSucc  = 1 << 3,              // Instruction has bundled successors.
87     FmNoNans     = 1 << 4,              // Instruction does not support Fast
88                                         // math nan values.
89     FmNoInfs     = 1 << 5,              // Instruction does not support Fast
90                                         // math infinity values.
91     FmNsz        = 1 << 6,              // Instruction is not required to retain
92                                         // signed zero values.
93     FmArcp       = 1 << 7,              // Instruction supports Fast math
94                                         // reciprocal approximations.
95     FmContract   = 1 << 8,              // Instruction supports Fast math
96                                         // contraction operations like fma.
97     FmAfn        = 1 << 9,              // Instruction may map to Fast math
98                                         // instrinsic approximation.
99     FmReassoc    = 1 << 10,             // Instruction supports Fast math
100                                         // reassociation of operand order.
101     NoUWrap      = 1 << 11,             // Instruction supports binary operator
102                                         // no unsigned wrap.
103     NoSWrap      = 1 << 12,             // Instruction supports binary operator
104                                         // no signed wrap.
105     IsExact      = 1 << 13,             // Instruction supports division is
106                                         // known to be exact.
107     NoFPExcept   = 1 << 14,             // Instruction does not raise
108                                         // floatint-point exceptions.
109   };
110 
111 private:
112   const MCInstrDesc *MCID;              // Instruction descriptor.
113   MachineBasicBlock *Parent = nullptr;  // Pointer to the owning basic block.
114 
115   // Operands are allocated by an ArrayRecycler.
116   MachineOperand *Operands = nullptr;   // Pointer to the first operand.
117   unsigned NumOperands = 0;             // Number of operands on instruction.
118   using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
119   OperandCapacity CapOperands;          // Capacity of the Operands array.
120 
121   uint16_t Flags = 0;                   // Various bits of additional
122                                         // information about machine
123                                         // instruction.
124 
125   uint8_t AsmPrinterFlags = 0;          // Various bits of information used by
126                                         // the AsmPrinter to emit helpful
127                                         // comments.  This is *not* semantic
128                                         // information.  Do not use this for
129                                         // anything other than to convey comment
130                                         // information to AsmPrinter.
131 
132   /// Internal implementation detail class that provides out-of-line storage for
133   /// extra info used by the machine instruction when this info cannot be stored
134   /// in-line within the instruction itself.
135   ///
136   /// This has to be defined eagerly due to the implementation constraints of
137   /// `PointerSumType` where it is used.
138   class ExtraInfo final
139       : TrailingObjects<ExtraInfo, MachineMemOperand *, MCSymbol *, MDNode *> {
140   public:
141     static ExtraInfo *create(BumpPtrAllocator &Allocator,
142                              ArrayRef<MachineMemOperand *> MMOs,
143                              MCSymbol *PreInstrSymbol = nullptr,
144                              MCSymbol *PostInstrSymbol = nullptr,
145                              MDNode *HeapAllocMarker = nullptr) {
146       bool HasPreInstrSymbol = PreInstrSymbol != nullptr;
147       bool HasPostInstrSymbol = PostInstrSymbol != nullptr;
148       bool HasHeapAllocMarker = HeapAllocMarker != nullptr;
149       auto *Result = new (Allocator.Allocate(
150           totalSizeToAlloc<MachineMemOperand *, MCSymbol *, MDNode *>(
151               MMOs.size(), HasPreInstrSymbol + HasPostInstrSymbol,
152               HasHeapAllocMarker),
153           alignof(ExtraInfo)))
154           ExtraInfo(MMOs.size(), HasPreInstrSymbol, HasPostInstrSymbol,
155                     HasHeapAllocMarker);
156 
157       // Copy the actual data into the trailing objects.
158       std::copy(MMOs.begin(), MMOs.end(),
159                 Result->getTrailingObjects<MachineMemOperand *>());
160 
161       if (HasPreInstrSymbol)
162         Result->getTrailingObjects<MCSymbol *>()[0] = PreInstrSymbol;
163       if (HasPostInstrSymbol)
164         Result->getTrailingObjects<MCSymbol *>()[HasPreInstrSymbol] =
165             PostInstrSymbol;
166       if (HasHeapAllocMarker)
167         Result->getTrailingObjects<MDNode *>()[0] = HeapAllocMarker;
168 
169       return Result;
170     }
171 
getMMOs()172     ArrayRef<MachineMemOperand *> getMMOs() const {
173       return makeArrayRef(getTrailingObjects<MachineMemOperand *>(), NumMMOs);
174     }
175 
getPreInstrSymbol()176     MCSymbol *getPreInstrSymbol() const {
177       return HasPreInstrSymbol ? getTrailingObjects<MCSymbol *>()[0] : nullptr;
178     }
179 
getPostInstrSymbol()180     MCSymbol *getPostInstrSymbol() const {
181       return HasPostInstrSymbol
182                  ? getTrailingObjects<MCSymbol *>()[HasPreInstrSymbol]
183                  : nullptr;
184     }
185 
getHeapAllocMarker()186     MDNode *getHeapAllocMarker() const {
187       return HasHeapAllocMarker ? getTrailingObjects<MDNode *>()[0] : nullptr;
188     }
189 
190   private:
191     friend TrailingObjects;
192 
193     // Description of the extra info, used to interpret the actual optional
194     // data appended.
195     //
196     // Note that this is not terribly space optimized. This leaves a great deal
197     // of flexibility to fit more in here later.
198     const int NumMMOs;
199     const bool HasPreInstrSymbol;
200     const bool HasPostInstrSymbol;
201     const bool HasHeapAllocMarker;
202 
203     // Implement the `TrailingObjects` internal API.
numTrailingObjects(OverloadToken<MachineMemOperand * >)204     size_t numTrailingObjects(OverloadToken<MachineMemOperand *>) const {
205       return NumMMOs;
206     }
numTrailingObjects(OverloadToken<MCSymbol * >)207     size_t numTrailingObjects(OverloadToken<MCSymbol *>) const {
208       return HasPreInstrSymbol + HasPostInstrSymbol;
209     }
numTrailingObjects(OverloadToken<MDNode * >)210     size_t numTrailingObjects(OverloadToken<MDNode *>) const {
211       return HasHeapAllocMarker;
212     }
213 
214     // Just a boring constructor to allow us to initialize the sizes. Always use
215     // the `create` routine above.
ExtraInfo(int NumMMOs,bool HasPreInstrSymbol,bool HasPostInstrSymbol,bool HasHeapAllocMarker)216     ExtraInfo(int NumMMOs, bool HasPreInstrSymbol, bool HasPostInstrSymbol,
217               bool HasHeapAllocMarker)
218         : NumMMOs(NumMMOs), HasPreInstrSymbol(HasPreInstrSymbol),
219           HasPostInstrSymbol(HasPostInstrSymbol),
220           HasHeapAllocMarker(HasHeapAllocMarker) {}
221   };
222 
223   /// Enumeration of the kinds of inline extra info available. It is important
224   /// that the `MachineMemOperand` inline kind has a tag value of zero to make
225   /// it accessible as an `ArrayRef`.
226   enum ExtraInfoInlineKinds {
227     EIIK_MMO = 0,
228     EIIK_PreInstrSymbol,
229     EIIK_PostInstrSymbol,
230     EIIK_OutOfLine
231   };
232 
233   // We store extra information about the instruction here. The common case is
234   // expected to be nothing or a single pointer (typically a MMO or a symbol).
235   // We work to optimize this common case by storing it inline here rather than
236   // requiring a separate allocation, but we fall back to an allocation when
237   // multiple pointers are needed.
238   PointerSumType<ExtraInfoInlineKinds,
239                  PointerSumTypeMember<EIIK_MMO, MachineMemOperand *>,
240                  PointerSumTypeMember<EIIK_PreInstrSymbol, MCSymbol *>,
241                  PointerSumTypeMember<EIIK_PostInstrSymbol, MCSymbol *>,
242                  PointerSumTypeMember<EIIK_OutOfLine, ExtraInfo *>>
243       Info;
244 
245   DebugLoc debugLoc;                    // Source line information.
246 
247   // Intrusive list support
248   friend struct ilist_traits<MachineInstr>;
249   friend struct ilist_callback_traits<MachineBasicBlock>;
250   void setParent(MachineBasicBlock *P) { Parent = P; }
251 
252   /// This constructor creates a copy of the given
253   /// MachineInstr in the given MachineFunction.
254   MachineInstr(MachineFunction &, const MachineInstr &);
255 
256   /// This constructor create a MachineInstr and add the implicit operands.
257   /// It reserves space for number of operands specified by
258   /// MCInstrDesc.  An explicit DebugLoc is supplied.
259   MachineInstr(MachineFunction &, const MCInstrDesc &tid, DebugLoc dl,
260                bool NoImp = false);
261 
262   // MachineInstrs are pool-allocated and owned by MachineFunction.
263   friend class MachineFunction;
264 
265 public:
266   MachineInstr(const MachineInstr &) = delete;
267   MachineInstr &operator=(const MachineInstr &) = delete;
268   // Use MachineFunction::DeleteMachineInstr() instead.
269   ~MachineInstr() = delete;
270 
271   const MachineBasicBlock* getParent() const { return Parent; }
272   MachineBasicBlock* getParent() { return Parent; }
273 
274   /// Return the function that contains the basic block that this instruction
275   /// belongs to.
276   ///
277   /// Note: this is undefined behaviour if the instruction does not have a
278   /// parent.
279   const MachineFunction *getMF() const;
280   MachineFunction *getMF() {
281     return const_cast<MachineFunction *>(
282         static_cast<const MachineInstr *>(this)->getMF());
283   }
284 
285   /// Return the asm printer flags bitvector.
286   uint8_t getAsmPrinterFlags() const { return AsmPrinterFlags; }
287 
288   /// Clear the AsmPrinter bitvector.
289   void clearAsmPrinterFlags() { AsmPrinterFlags = 0; }
290 
291   /// Return whether an AsmPrinter flag is set.
292   bool getAsmPrinterFlag(CommentFlag Flag) const {
293     return AsmPrinterFlags & Flag;
294   }
295 
296   /// Set a flag for the AsmPrinter.
297   void setAsmPrinterFlag(uint8_t Flag) {
298     AsmPrinterFlags |= Flag;
299   }
300 
301   /// Clear specific AsmPrinter flags.
302   void clearAsmPrinterFlag(CommentFlag Flag) {
303     AsmPrinterFlags &= ~Flag;
304   }
305 
306   /// Return the MI flags bitvector.
307   uint16_t getFlags() const {
308     return Flags;
309   }
310 
311   /// Return whether an MI flag is set.
312   bool getFlag(MIFlag Flag) const {
313     return Flags & Flag;
314   }
315 
316   /// Set a MI flag.
317   void setFlag(MIFlag Flag) {
318     Flags |= (uint16_t)Flag;
319   }
320 
321   void setFlags(unsigned flags) {
322     // Filter out the automatically maintained flags.
323     unsigned Mask = BundledPred | BundledSucc;
324     Flags = (Flags & Mask) | (flags & ~Mask);
325   }
326 
327   /// clearFlag - Clear a MI flag.
328   void clearFlag(MIFlag Flag) {
329     Flags &= ~((uint16_t)Flag);
330   }
331 
332   /// Return true if MI is in a bundle (but not the first MI in a bundle).
333   ///
334   /// A bundle looks like this before it's finalized:
335   ///   ----------------
336   ///   |      MI      |
337   ///   ----------------
338   ///          |
339   ///   ----------------
340   ///   |      MI    * |
341   ///   ----------------
342   ///          |
343   ///   ----------------
344   ///   |      MI    * |
345   ///   ----------------
346   /// In this case, the first MI starts a bundle but is not inside a bundle, the
347   /// next 2 MIs are considered "inside" the bundle.
348   ///
349   /// After a bundle is finalized, it looks like this:
350   ///   ----------------
351   ///   |    Bundle    |
352   ///   ----------------
353   ///          |
354   ///   ----------------
355   ///   |      MI    * |
356   ///   ----------------
357   ///          |
358   ///   ----------------
359   ///   |      MI    * |
360   ///   ----------------
361   ///          |
362   ///   ----------------
363   ///   |      MI    * |
364   ///   ----------------
365   /// The first instruction has the special opcode "BUNDLE". It's not "inside"
366   /// a bundle, but the next three MIs are.
367   bool isInsideBundle() const {
368     return getFlag(BundledPred);
369   }
370 
371   /// Return true if this instruction part of a bundle. This is true
372   /// if either itself or its following instruction is marked "InsideBundle".
373   bool isBundled() const {
374     return isBundledWithPred() || isBundledWithSucc();
375   }
376 
377   /// Return true if this instruction is part of a bundle, and it is not the
378   /// first instruction in the bundle.
379   bool isBundledWithPred() const { return getFlag(BundledPred); }
380 
381   /// Return true if this instruction is part of a bundle, and it is not the
382   /// last instruction in the bundle.
383   bool isBundledWithSucc() const { return getFlag(BundledSucc); }
384 
385   /// Bundle this instruction with its predecessor. This can be an unbundled
386   /// instruction, or it can be the first instruction in a bundle.
387   void bundleWithPred();
388 
389   /// Bundle this instruction with its successor. This can be an unbundled
390   /// instruction, or it can be the last instruction in a bundle.
391   void bundleWithSucc();
392 
393   /// Break bundle above this instruction.
394   void unbundleFromPred();
395 
396   /// Break bundle below this instruction.
397   void unbundleFromSucc();
398 
399   /// Returns the debug location id of this MachineInstr.
400   const DebugLoc &getDebugLoc() const { return debugLoc; }
401 
402   /// Return the debug variable referenced by
403   /// this DBG_VALUE instruction.
404   const DILocalVariable *getDebugVariable() const;
405 
406   /// Return the complex address expression referenced by
407   /// this DBG_VALUE instruction.
408   const DIExpression *getDebugExpression() const;
409 
410   /// Return the debug label referenced by
411   /// this DBG_LABEL instruction.
412   const DILabel *getDebugLabel() const;
413 
414   /// Emit an error referring to the source location of this instruction.
415   /// This should only be used for inline assembly that is somehow
416   /// impossible to compile. Other errors should have been handled much
417   /// earlier.
418   ///
419   /// If this method returns, the caller should try to recover from the error.
420   void emitError(StringRef Msg) const;
421 
422   /// Returns the target instruction descriptor of this MachineInstr.
423   const MCInstrDesc &getDesc() const { return *MCID; }
424 
425   /// Returns the opcode of this MachineInstr.
426   unsigned getOpcode() const { return MCID->Opcode; }
427 
428   /// Retuns the total number of operands.
429   unsigned getNumOperands() const { return NumOperands; }
430 
431   const MachineOperand& getOperand(unsigned i) const {
432     assert(i < getNumOperands() && "getOperand() out of range!");
433     return Operands[i];
434   }
435   MachineOperand& getOperand(unsigned i) {
436     assert(i < getNumOperands() && "getOperand() out of range!");
437     return Operands[i];
438   }
439 
440   /// Returns the total number of definitions.
441   unsigned getNumDefs() const {
442     return getNumExplicitDefs() + MCID->getNumImplicitDefs();
443   }
444 
445   /// Returns true if the instruction has implicit definition.
446   bool hasImplicitDef() const {
447     for (unsigned I = getNumExplicitOperands(), E = getNumOperands();
448       I != E; ++I) {
449       const MachineOperand &MO = getOperand(I);
450       if (MO.isDef() && MO.isImplicit())
451         return true;
452     }
453     return false;
454   }
455 
456   /// Returns the implicit operands number.
457   unsigned getNumImplicitOperands() const {
458     return getNumOperands() - getNumExplicitOperands();
459   }
460 
461   /// Return true if operand \p OpIdx is a subregister index.
462   bool isOperandSubregIdx(unsigned OpIdx) const {
463     assert(getOperand(OpIdx).getType() == MachineOperand::MO_Immediate &&
464            "Expected MO_Immediate operand type.");
465     if (isExtractSubreg() && OpIdx == 2)
466       return true;
467     if (isInsertSubreg() && OpIdx == 3)
468       return true;
469     if (isRegSequence() && OpIdx > 1 && (OpIdx % 2) == 0)
470       return true;
471     if (isSubregToReg() && OpIdx == 3)
472       return true;
473     return false;
474   }
475 
476   /// Returns the number of non-implicit operands.
477   unsigned getNumExplicitOperands() const;
478 
479   /// Returns the number of non-implicit definitions.
480   unsigned getNumExplicitDefs() const;
481 
482   /// iterator/begin/end - Iterate over all operands of a machine instruction.
483   using mop_iterator = MachineOperand *;
484   using const_mop_iterator = const MachineOperand *;
485 
486   mop_iterator operands_begin() { return Operands; }
487   mop_iterator operands_end() { return Operands + NumOperands; }
488 
489   const_mop_iterator operands_begin() const { return Operands; }
490   const_mop_iterator operands_end() const { return Operands + NumOperands; }
491 
492   iterator_range<mop_iterator> operands() {
493     return make_range(operands_begin(), operands_end());
494   }
495   iterator_range<const_mop_iterator> operands() const {
496     return make_range(operands_begin(), operands_end());
497   }
498   iterator_range<mop_iterator> explicit_operands() {
499     return make_range(operands_begin(),
500                       operands_begin() + getNumExplicitOperands());
501   }
502   iterator_range<const_mop_iterator> explicit_operands() const {
503     return make_range(operands_begin(),
504                       operands_begin() + getNumExplicitOperands());
505   }
506   iterator_range<mop_iterator> implicit_operands() {
507     return make_range(explicit_operands().end(), operands_end());
508   }
509   iterator_range<const_mop_iterator> implicit_operands() const {
510     return make_range(explicit_operands().end(), operands_end());
511   }
512   /// Returns a range over all explicit operands that are register definitions.
513   /// Implicit definition are not included!
514   iterator_range<mop_iterator> defs() {
515     return make_range(operands_begin(),
516                       operands_begin() + getNumExplicitDefs());
517   }
518   /// \copydoc defs()
519   iterator_range<const_mop_iterator> defs() const {
520     return make_range(operands_begin(),
521                       operands_begin() + getNumExplicitDefs());
522   }
523   /// Returns a range that includes all operands that are register uses.
524   /// This may include unrelated operands which are not register uses.
525   iterator_range<mop_iterator> uses() {
526     return make_range(operands_begin() + getNumExplicitDefs(), operands_end());
527   }
528   /// \copydoc uses()
529   iterator_range<const_mop_iterator> uses() const {
530     return make_range(operands_begin() + getNumExplicitDefs(), operands_end());
531   }
532   iterator_range<mop_iterator> explicit_uses() {
533     return make_range(operands_begin() + getNumExplicitDefs(),
534                       operands_begin() + getNumExplicitOperands());
535   }
536   iterator_range<const_mop_iterator> explicit_uses() const {
537     return make_range(operands_begin() + getNumExplicitDefs(),
538                       operands_begin() + getNumExplicitOperands());
539   }
540 
541   /// Returns the number of the operand iterator \p I points to.
542   unsigned getOperandNo(const_mop_iterator I) const {
543     return I - operands_begin();
544   }
545 
546   /// Access to memory operands of the instruction. If there are none, that does
547   /// not imply anything about whether the function accesses memory. Instead,
548   /// the caller must behave conservatively.
549   ArrayRef<MachineMemOperand *> memoperands() const {
550     if (!Info)
551       return {};
552 
553     if (Info.is<EIIK_MMO>())
554       return makeArrayRef(Info.getAddrOfZeroTagPointer(), 1);
555 
556     if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
557       return EI->getMMOs();
558 
559     return {};
560   }
561 
562   /// Access to memory operands of the instruction.
563   ///
564   /// If `memoperands_begin() == memoperands_end()`, that does not imply
565   /// anything about whether the function accesses memory. Instead, the caller
566   /// must behave conservatively.
567   mmo_iterator memoperands_begin() const { return memoperands().begin(); }
568 
569   /// Access to memory operands of the instruction.
570   ///
571   /// If `memoperands_begin() == memoperands_end()`, that does not imply
572   /// anything about whether the function accesses memory. Instead, the caller
573   /// must behave conservatively.
574   mmo_iterator memoperands_end() const { return memoperands().end(); }
575 
576   /// Return true if we don't have any memory operands which described the
577   /// memory access done by this instruction.  If this is true, calling code
578   /// must be conservative.
579   bool memoperands_empty() const { return memoperands().empty(); }
580 
581   /// Return true if this instruction has exactly one MachineMemOperand.
582   bool hasOneMemOperand() const { return memoperands().size() == 1; }
583 
584   /// Return the number of memory operands.
585   unsigned getNumMemOperands() const { return memoperands().size(); }
586 
587   /// Helper to extract a pre-instruction symbol if one has been added.
588   MCSymbol *getPreInstrSymbol() const {
589     if (!Info)
590       return nullptr;
591     if (MCSymbol *S = Info.get<EIIK_PreInstrSymbol>())
592       return S;
593     if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
594       return EI->getPreInstrSymbol();
595 
596     return nullptr;
597   }
598 
599   /// Helper to extract a post-instruction symbol if one has been added.
600   MCSymbol *getPostInstrSymbol() const {
601     if (!Info)
602       return nullptr;
603     if (MCSymbol *S = Info.get<EIIK_PostInstrSymbol>())
604       return S;
605     if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
606       return EI->getPostInstrSymbol();
607 
608     return nullptr;
609   }
610 
611   /// Helper to extract a heap alloc marker if one has been added.
612   MDNode *getHeapAllocMarker() const {
613     if (!Info)
614       return nullptr;
615     if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>())
616       return EI->getHeapAllocMarker();
617 
618     return nullptr;
619   }
620 
621   /// API for querying MachineInstr properties. They are the same as MCInstrDesc
622   /// queries but they are bundle aware.
623 
624   enum QueryType {
625     IgnoreBundle,    // Ignore bundles
626     AnyInBundle,     // Return true if any instruction in bundle has property
627     AllInBundle      // Return true if all instructions in bundle have property
628   };
629 
630   /// Return true if the instruction (or in the case of a bundle,
631   /// the instructions inside the bundle) has the specified property.
632   /// The first argument is the property being queried.
633   /// The second argument indicates whether the query should look inside
634   /// instruction bundles.
635   bool hasProperty(unsigned MCFlag, QueryType Type = AnyInBundle) const {
636     assert(MCFlag < 64 &&
637            "MCFlag out of range for bit mask in getFlags/hasPropertyInBundle.");
638     // Inline the fast path for unbundled or bundle-internal instructions.
639     if (Type == IgnoreBundle || !isBundled() || isBundledWithPred())
640       return getDesc().getFlags() & (1ULL << MCFlag);
641 
642     // If this is the first instruction in a bundle, take the slow path.
643     return hasPropertyInBundle(1ULL << MCFlag, Type);
644   }
645 
646   /// Return true if this is an instruction that should go through the usual
647   /// legalization steps.
648   bool isPreISelOpcode(QueryType Type = IgnoreBundle) const {
649     return hasProperty(MCID::PreISelOpcode, Type);
650   }
651 
652   /// Return true if this instruction can have a variable number of operands.
653   /// In this case, the variable operands will be after the normal
654   /// operands but before the implicit definitions and uses (if any are
655   /// present).
656   bool isVariadic(QueryType Type = IgnoreBundle) const {
657     return hasProperty(MCID::Variadic, Type);
658   }
659 
660   /// Set if this instruction has an optional definition, e.g.
661   /// ARM instructions which can set condition code if 's' bit is set.
662   bool hasOptionalDef(QueryType Type = IgnoreBundle) const {
663     return hasProperty(MCID::HasOptionalDef, Type);
664   }
665 
666   /// Return true if this is a pseudo instruction that doesn't
667   /// correspond to a real machine instruction.
668   bool isPseudo(QueryType Type = IgnoreBundle) const {
669     return hasProperty(MCID::Pseudo, Type);
670   }
671 
672   bool isReturn(QueryType Type = AnyInBundle) const {
673     return hasProperty(MCID::Return, Type);
674   }
675 
676   /// Return true if this is an instruction that marks the end of an EH scope,
677   /// i.e., a catchpad or a cleanuppad instruction.
678   bool isEHScopeReturn(QueryType Type = AnyInBundle) const {
679     return hasProperty(MCID::EHScopeReturn, Type);
680   }
681 
682   bool isCall(QueryType Type = AnyInBundle) const {
683     return hasProperty(MCID::Call, Type);
684   }
685 
686   /// Returns true if the specified instruction stops control flow
687   /// from executing the instruction immediately following it.  Examples include
688   /// unconditional branches and return instructions.
689   bool isBarrier(QueryType Type = AnyInBundle) const {
690     return hasProperty(MCID::Barrier, Type);
691   }
692 
693   /// Returns true if this instruction part of the terminator for a basic block.
694   /// Typically this is things like return and branch instructions.
695   ///
696   /// Various passes use this to insert code into the bottom of a basic block,
697   /// but before control flow occurs.
698   bool isTerminator(QueryType Type = AnyInBundle) const {
699     return hasProperty(MCID::Terminator, Type);
700   }
701 
702   /// Returns true if this is a conditional, unconditional, or indirect branch.
703   /// Predicates below can be used to discriminate between
704   /// these cases, and the TargetInstrInfo::AnalyzeBranch method can be used to
705   /// get more information.
706   bool isBranch(QueryType Type = AnyInBundle) const {
707     return hasProperty(MCID::Branch, Type);
708   }
709 
710   /// Return true if this is an indirect branch, such as a
711   /// branch through a register.
712   bool isIndirectBranch(QueryType Type = AnyInBundle) const {
713     return hasProperty(MCID::IndirectBranch, Type);
714   }
715 
716   /// Return true if this is a branch which may fall
717   /// through to the next instruction or may transfer control flow to some other
718   /// block.  The TargetInstrInfo::AnalyzeBranch method can be used to get more
719   /// information about this branch.
720   bool isConditionalBranch(QueryType Type = AnyInBundle) const {
721     return isBranch(Type) && !isBarrier(Type) && !isIndirectBranch(Type);
722   }
723 
724   /// Return true if this is a branch which always
725   /// transfers control flow to some other block.  The
726   /// TargetInstrInfo::AnalyzeBranch method can be used to get more information
727   /// about this branch.
728   bool isUnconditionalBranch(QueryType Type = AnyInBundle) const {
729     return isBranch(Type) && isBarrier(Type) && !isIndirectBranch(Type);
730   }
731 
732   /// Return true if this instruction has a predicate operand that
733   /// controls execution.  It may be set to 'always', or may be set to other
734   /// values.   There are various methods in TargetInstrInfo that can be used to
735   /// control and modify the predicate in this instruction.
736   bool isPredicable(QueryType Type = AllInBundle) const {
737     // If it's a bundle than all bundled instructions must be predicable for this
738     // to return true.
739     return hasProperty(MCID::Predicable, Type);
740   }
741 
742   /// Return true if this instruction is a comparison.
743   bool isCompare(QueryType Type = IgnoreBundle) const {
744     return hasProperty(MCID::Compare, Type);
745   }
746 
747   /// Return true if this instruction is a move immediate
748   /// (including conditional moves) instruction.
749   bool isMoveImmediate(QueryType Type = IgnoreBundle) const {
750     return hasProperty(MCID::MoveImm, Type);
751   }
752 
753   /// Return true if this instruction is a register move.
754   /// (including moving values from subreg to reg)
755   bool isMoveReg(QueryType Type = IgnoreBundle) const {
756     return hasProperty(MCID::MoveReg, Type);
757   }
758 
759   /// Return true if this instruction is a bitcast instruction.
760   bool isBitcast(QueryType Type = IgnoreBundle) const {
761     return hasProperty(MCID::Bitcast, Type);
762   }
763 
764   /// Return true if this instruction is a select instruction.
765   bool isSelect(QueryType Type = IgnoreBundle) const {
766     return hasProperty(MCID::Select, Type);
767   }
768 
769   /// Return true if this instruction cannot be safely duplicated.
770   /// For example, if the instruction has a unique labels attached
771   /// to it, duplicating it would cause multiple definition errors.
772   bool isNotDuplicable(QueryType Type = AnyInBundle) const {
773     return hasProperty(MCID::NotDuplicable, Type);
774   }
775 
776   /// Return true if this instruction is convergent.
777   /// Convergent instructions can not be made control-dependent on any
778   /// additional values.
779   bool isConvergent(QueryType Type = AnyInBundle) const {
780     if (isInlineAsm()) {
781       unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
782       if (ExtraInfo & InlineAsm::Extra_IsConvergent)
783         return true;
784     }
785     return hasProperty(MCID::Convergent, Type);
786   }
787 
788   /// Returns true if the specified instruction has a delay slot
789   /// which must be filled by the code generator.
790   bool hasDelaySlot(QueryType Type = AnyInBundle) const {
791     return hasProperty(MCID::DelaySlot, Type);
792   }
793 
794   /// Return true for instructions that can be folded as
795   /// memory operands in other instructions. The most common use for this
796   /// is instructions that are simple loads from memory that don't modify
797   /// the loaded value in any way, but it can also be used for instructions
798   /// that can be expressed as constant-pool loads, such as V_SETALLONES
799   /// on x86, to allow them to be folded when it is beneficial.
800   /// This should only be set on instructions that return a value in their
801   /// only virtual register definition.
802   bool canFoldAsLoad(QueryType Type = IgnoreBundle) const {
803     return hasProperty(MCID::FoldableAsLoad, Type);
804   }
805 
806   /// Return true if this instruction behaves
807   /// the same way as the generic REG_SEQUENCE instructions.
808   /// E.g., on ARM,
809   /// dX VMOVDRR rY, rZ
810   /// is equivalent to
811   /// dX = REG_SEQUENCE rY, ssub_0, rZ, ssub_1.
812   ///
813   /// Note that for the optimizers to be able to take advantage of
814   /// this property, TargetInstrInfo::getRegSequenceLikeInputs has to be
815   /// override accordingly.
816   bool isRegSequenceLike(QueryType Type = IgnoreBundle) const {
817     return hasProperty(MCID::RegSequence, Type);
818   }
819 
820   /// Return true if this instruction behaves
821   /// the same way as the generic EXTRACT_SUBREG instructions.
822   /// E.g., on ARM,
823   /// rX, rY VMOVRRD dZ
824   /// is equivalent to two EXTRACT_SUBREG:
825   /// rX = EXTRACT_SUBREG dZ, ssub_0
826   /// rY = EXTRACT_SUBREG dZ, ssub_1
827   ///
828   /// Note that for the optimizers to be able to take advantage of
829   /// this property, TargetInstrInfo::getExtractSubregLikeInputs has to be
830   /// override accordingly.
831   bool isExtractSubregLike(QueryType Type = IgnoreBundle) const {
832     return hasProperty(MCID::ExtractSubreg, Type);
833   }
834 
835   /// Return true if this instruction behaves
836   /// the same way as the generic INSERT_SUBREG instructions.
837   /// E.g., on ARM,
838   /// dX = VSETLNi32 dY, rZ, Imm
839   /// is equivalent to a INSERT_SUBREG:
840   /// dX = INSERT_SUBREG dY, rZ, translateImmToSubIdx(Imm)
841   ///
842   /// Note that for the optimizers to be able to take advantage of
843   /// this property, TargetInstrInfo::getInsertSubregLikeInputs has to be
844   /// override accordingly.
845   bool isInsertSubregLike(QueryType Type = IgnoreBundle) const {
846     return hasProperty(MCID::InsertSubreg, Type);
847   }
848 
849   //===--------------------------------------------------------------------===//
850   // Side Effect Analysis
851   //===--------------------------------------------------------------------===//
852 
853   /// Return true if this instruction could possibly read memory.
854   /// Instructions with this flag set are not necessarily simple load
855   /// instructions, they may load a value and modify it, for example.
856   bool mayLoad(QueryType Type = AnyInBundle) const {
857     if (isInlineAsm()) {
858       unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
859       if (ExtraInfo & InlineAsm::Extra_MayLoad)
860         return true;
861     }
862     return hasProperty(MCID::MayLoad, Type);
863   }
864 
865   /// Return true if this instruction could possibly modify memory.
866   /// Instructions with this flag set are not necessarily simple store
867   /// instructions, they may store a modified value based on their operands, or
868   /// may not actually modify anything, for example.
869   bool mayStore(QueryType Type = AnyInBundle) const {
870     if (isInlineAsm()) {
871       unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
872       if (ExtraInfo & InlineAsm::Extra_MayStore)
873         return true;
874     }
875     return hasProperty(MCID::MayStore, Type);
876   }
877 
878   /// Return true if this instruction could possibly read or modify memory.
879   bool mayLoadOrStore(QueryType Type = AnyInBundle) const {
880     return mayLoad(Type) || mayStore(Type);
881   }
882 
883   /// Return true if this instruction could possibly raise a floating-point
884   /// exception.  This is the case if the instruction is a floating-point
885   /// instruction that can in principle raise an exception, as indicated
886   /// by the MCID::MayRaiseFPException property, *and* at the same time,
887   /// the instruction is used in a context where we expect floating-point
888   /// exceptions are not disabled, as indicated by the NoFPExcept MI flag.
889   bool mayRaiseFPException() const {
890     return hasProperty(MCID::MayRaiseFPException) &&
891            !getFlag(MachineInstr::MIFlag::NoFPExcept);
892   }
893 
894   //===--------------------------------------------------------------------===//
895   // Flags that indicate whether an instruction can be modified by a method.
896   //===--------------------------------------------------------------------===//
897 
898   /// Return true if this may be a 2- or 3-address
899   /// instruction (of the form "X = op Y, Z, ..."), which produces the same
900   /// result if Y and Z are exchanged.  If this flag is set, then the
901   /// TargetInstrInfo::commuteInstruction method may be used to hack on the
902   /// instruction.
903   ///
904   /// Note that this flag may be set on instructions that are only commutable
905   /// sometimes.  In these cases, the call to commuteInstruction will fail.
906   /// Also note that some instructions require non-trivial modification to
907   /// commute them.
908   bool isCommutable(QueryType Type = IgnoreBundle) const {
909     return hasProperty(MCID::Commutable, Type);
910   }
911 
912   /// Return true if this is a 2-address instruction
913   /// which can be changed into a 3-address instruction if needed.  Doing this
914   /// transformation can be profitable in the register allocator, because it
915   /// means that the instruction can use a 2-address form if possible, but
916   /// degrade into a less efficient form if the source and dest register cannot
917   /// be assigned to the same register.  For example, this allows the x86
918   /// backend to turn a "shl reg, 3" instruction into an LEA instruction, which
919   /// is the same speed as the shift but has bigger code size.
920   ///
921   /// If this returns true, then the target must implement the
922   /// TargetInstrInfo::convertToThreeAddress method for this instruction, which
923   /// is allowed to fail if the transformation isn't valid for this specific
924   /// instruction (e.g. shl reg, 4 on x86).
925   ///
926   bool isConvertibleTo3Addr(QueryType Type = IgnoreBundle) const {
927     return hasProperty(MCID::ConvertibleTo3Addr, Type);
928   }
929 
930   /// Return true if this instruction requires
931   /// custom insertion support when the DAG scheduler is inserting it into a
932   /// machine basic block.  If this is true for the instruction, it basically
933   /// means that it is a pseudo instruction used at SelectionDAG time that is
934   /// expanded out into magic code by the target when MachineInstrs are formed.
935   ///
936   /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method
937   /// is used to insert this into the MachineBasicBlock.
938   bool usesCustomInsertionHook(QueryType Type = IgnoreBundle) const {
939     return hasProperty(MCID::UsesCustomInserter, Type);
940   }
941 
942   /// Return true if this instruction requires *adjustment*
943   /// after instruction selection by calling a target hook. For example, this
944   /// can be used to fill in ARM 's' optional operand depending on whether
945   /// the conditional flag register is used.
946   bool hasPostISelHook(QueryType Type = IgnoreBundle) const {
947     return hasProperty(MCID::HasPostISelHook, Type);
948   }
949 
950   /// Returns true if this instruction is a candidate for remat.
951   /// This flag is deprecated, please don't use it anymore.  If this
952   /// flag is set, the isReallyTriviallyReMaterializable() method is called to
953   /// verify the instruction is really rematable.
954   bool isRematerializable(QueryType Type = AllInBundle) const {
955     // It's only possible to re-mat a bundle if all bundled instructions are
956     // re-materializable.
957     return hasProperty(MCID::Rematerializable, Type);
958   }
959 
960   /// Returns true if this instruction has the same cost (or less) than a move
961   /// instruction. This is useful during certain types of optimizations
962   /// (e.g., remat during two-address conversion or machine licm)
963   /// where we would like to remat or hoist the instruction, but not if it costs
964   /// more than moving the instruction into the appropriate register. Note, we
965   /// are not marking copies from and to the same register class with this flag.
966   bool isAsCheapAsAMove(QueryType Type = AllInBundle) const {
967     // Only returns true for a bundle if all bundled instructions are cheap.
968     return hasProperty(MCID::CheapAsAMove, Type);
969   }
970 
971   /// Returns true if this instruction source operands
972   /// have special register allocation requirements that are not captured by the
973   /// operand register classes. e.g. ARM::STRD's two source registers must be an
974   /// even / odd pair, ARM::STM registers have to be in ascending order.
975   /// Post-register allocation passes should not attempt to change allocations
976   /// for sources of instructions with this flag.
977   bool hasExtraSrcRegAllocReq(QueryType Type = AnyInBundle) const {
978     return hasProperty(MCID::ExtraSrcRegAllocReq, Type);
979   }
980 
981   /// Returns true if this instruction def operands
982   /// have special register allocation requirements that are not captured by the
983   /// operand register classes. e.g. ARM::LDRD's two def registers must be an
984   /// even / odd pair, ARM::LDM registers have to be in ascending order.
985   /// Post-register allocation passes should not attempt to change allocations
986   /// for definitions of instructions with this flag.
987   bool hasExtraDefRegAllocReq(QueryType Type = AnyInBundle) const {
988     return hasProperty(MCID::ExtraDefRegAllocReq, Type);
989   }
990 
991   enum MICheckType {
992     CheckDefs,      // Check all operands for equality
993     CheckKillDead,  // Check all operands including kill / dead markers
994     IgnoreDefs,     // Ignore all definitions
995     IgnoreVRegDefs  // Ignore virtual register definitions
996   };
997 
998   /// Return true if this instruction is identical to \p Other.
999   /// Two instructions are identical if they have the same opcode and all their
1000   /// operands are identical (with respect to MachineOperand::isIdenticalTo()).
1001   /// Note that this means liveness related flags (dead, undef, kill) do not
1002   /// affect the notion of identical.
1003   bool isIdenticalTo(const MachineInstr &Other,
1004                      MICheckType Check = CheckDefs) const;
1005 
1006   /// Unlink 'this' from the containing basic block, and return it without
1007   /// deleting it.
1008   ///
1009   /// This function can not be used on bundled instructions, use
1010   /// removeFromBundle() to remove individual instructions from a bundle.
1011   MachineInstr *removeFromParent();
1012 
1013   /// Unlink this instruction from its basic block and return it without
1014   /// deleting it.
1015   ///
1016   /// If the instruction is part of a bundle, the other instructions in the
1017   /// bundle remain bundled.
1018   MachineInstr *removeFromBundle();
1019 
1020   /// Unlink 'this' from the containing basic block and delete it.
1021   ///
1022   /// If this instruction is the header of a bundle, the whole bundle is erased.
1023   /// This function can not be used for instructions inside a bundle, use
1024   /// eraseFromBundle() to erase individual bundled instructions.
1025   void eraseFromParent();
1026 
1027   /// Unlink 'this' from the containing basic block and delete it.
1028   ///
1029   /// For all definitions mark their uses in DBG_VALUE nodes
1030   /// as undefined. Otherwise like eraseFromParent().
1031   void eraseFromParentAndMarkDBGValuesForRemoval();
1032 
1033   /// Unlink 'this' form its basic block and delete it.
1034   ///
1035   /// If the instruction is part of a bundle, the other instructions in the
1036   /// bundle remain bundled.
1037   void eraseFromBundle();
1038 
1039   bool isEHLabel() const { return getOpcode() == TargetOpcode::EH_LABEL; }
1040   bool isGCLabel() const { return getOpcode() == TargetOpcode::GC_LABEL; }
1041   bool isAnnotationLabel() const {
1042     return getOpcode() == TargetOpcode::ANNOTATION_LABEL;
1043   }
1044 
1045   /// Returns true if the MachineInstr represents a label.
1046   bool isLabel() const {
1047     return isEHLabel() || isGCLabel() || isAnnotationLabel();
1048   }
1049 
1050   bool isCFIInstruction() const {
1051     return getOpcode() == TargetOpcode::CFI_INSTRUCTION;
1052   }
1053 
1054   // True if the instruction represents a position in the function.
1055   bool isPosition() const { return isLabel() || isCFIInstruction(); }
1056 
1057   bool isDebugValue() const { return getOpcode() == TargetOpcode::DBG_VALUE; }
1058   bool isDebugLabel() const { return getOpcode() == TargetOpcode::DBG_LABEL; }
1059   bool isDebugInstr() const { return isDebugValue() || isDebugLabel(); }
1060 
1061   /// A DBG_VALUE is indirect iff the first operand is a register and
1062   /// the second operand is an immediate.
1063   bool isIndirectDebugValue() const {
1064     return isDebugValue()
1065       && getOperand(0).isReg()
1066       && getOperand(1).isImm();
1067   }
1068 
1069   /// A DBG_VALUE is an entry value iff its debug expression contains the
1070   /// DW_OP_LLVM_entry_value operation.
1071   bool isDebugEntryValue() const;
1072 
1073   /// Return true if the instruction is a debug value which describes a part of
1074   /// a variable as unavailable.
1075   bool isUndefDebugValue() const {
1076     return isDebugValue() && getOperand(0).isReg() && !getOperand(0).getReg().isValid();
1077   }
1078 
1079   bool isPHI() const {
1080     return getOpcode() == TargetOpcode::PHI ||
1081            getOpcode() == TargetOpcode::G_PHI;
1082   }
1083   bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
1084   bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; }
1085   bool isInlineAsm() const {
1086     return getOpcode() == TargetOpcode::INLINEASM ||
1087            getOpcode() == TargetOpcode::INLINEASM_BR;
1088   }
1089 
1090   /// FIXME: Seems like a layering violation that the AsmDialect, which is X86
1091   /// specific, be attached to a generic MachineInstr.
1092   bool isMSInlineAsm() const {
1093     return isInlineAsm() && getInlineAsmDialect() == InlineAsm::AD_Intel;
1094   }
1095 
1096   bool isStackAligningInlineAsm() const;
1097   InlineAsm::AsmDialect getInlineAsmDialect() const;
1098 
1099   bool isInsertSubreg() const {
1100     return getOpcode() == TargetOpcode::INSERT_SUBREG;
1101   }
1102 
1103   bool isSubregToReg() const {
1104     return getOpcode() == TargetOpcode::SUBREG_TO_REG;
1105   }
1106 
1107   bool isRegSequence() const {
1108     return getOpcode() == TargetOpcode::REG_SEQUENCE;
1109   }
1110 
1111   bool isBundle() const {
1112     return getOpcode() == TargetOpcode::BUNDLE;
1113   }
1114 
1115   bool isCopy() const {
1116     return getOpcode() == TargetOpcode::COPY;
1117   }
1118 
1119   bool isFullCopy() const {
1120     return isCopy() && !getOperand(0).getSubReg() && !getOperand(1).getSubReg();
1121   }
1122 
1123   bool isExtractSubreg() const {
1124     return getOpcode() == TargetOpcode::EXTRACT_SUBREG;
1125   }
1126 
1127   /// Return true if the instruction behaves like a copy.
1128   /// This does not include native copy instructions.
1129   bool isCopyLike() const {
1130     return isCopy() || isSubregToReg();
1131   }
1132 
1133   /// Return true is the instruction is an identity copy.
1134   bool isIdentityCopy() const {
1135     return isCopy() && getOperand(0).getReg() == getOperand(1).getReg() &&
1136       getOperand(0).getSubReg() == getOperand(1).getSubReg();
1137   }
1138 
1139   /// Return true if this instruction doesn't produce any output in the form of
1140   /// executable instructions.
1141   bool isMetaInstruction() const {
1142     switch (getOpcode()) {
1143     default:
1144       return false;
1145     case TargetOpcode::IMPLICIT_DEF:
1146     case TargetOpcode::KILL:
1147     case TargetOpcode::CFI_INSTRUCTION:
1148     case TargetOpcode::EH_LABEL:
1149     case TargetOpcode::GC_LABEL:
1150     case TargetOpcode::DBG_VALUE:
1151     case TargetOpcode::DBG_LABEL:
1152     case TargetOpcode::LIFETIME_START:
1153     case TargetOpcode::LIFETIME_END:
1154       return true;
1155     }
1156   }
1157 
1158   /// Return true if this is a transient instruction that is either very likely
1159   /// to be eliminated during register allocation (such as copy-like
1160   /// instructions), or if this instruction doesn't have an execution-time cost.
1161   bool isTransient() const {
1162     switch (getOpcode()) {
1163     default:
1164       return isMetaInstruction();
1165     // Copy-like instructions are usually eliminated during register allocation.
1166     case TargetOpcode::PHI:
1167     case TargetOpcode::G_PHI:
1168     case TargetOpcode::COPY:
1169     case TargetOpcode::INSERT_SUBREG:
1170     case TargetOpcode::SUBREG_TO_REG:
1171     case TargetOpcode::REG_SEQUENCE:
1172       return true;
1173     }
1174   }
1175 
1176   /// Return the number of instructions inside the MI bundle, excluding the
1177   /// bundle header.
1178   ///
1179   /// This is the number of instructions that MachineBasicBlock::iterator
1180   /// skips, 0 for unbundled instructions.
1181   unsigned getBundleSize() const;
1182 
1183   /// Return true if the MachineInstr reads the specified register.
1184   /// If TargetRegisterInfo is passed, then it also checks if there
1185   /// is a read of a super-register.
1186   /// This does not count partial redefines of virtual registers as reads:
1187   ///   %reg1024:6 = OP.
1188   bool readsRegister(Register Reg,
1189                      const TargetRegisterInfo *TRI = nullptr) const {
1190     return findRegisterUseOperandIdx(Reg, false, TRI) != -1;
1191   }
1192 
1193   /// Return true if the MachineInstr reads the specified virtual register.
1194   /// Take into account that a partial define is a
1195   /// read-modify-write operation.
1196   bool readsVirtualRegister(Register Reg) const {
1197     return readsWritesVirtualRegister(Reg).first;
1198   }
1199 
1200   /// Return a pair of bools (reads, writes) indicating if this instruction
1201   /// reads or writes Reg. This also considers partial defines.
1202   /// If Ops is not null, all operand indices for Reg are added.
1203   std::pair<bool,bool> readsWritesVirtualRegister(Register Reg,
1204                                 SmallVectorImpl<unsigned> *Ops = nullptr) const;
1205 
1206   /// Return true if the MachineInstr kills the specified register.
1207   /// If TargetRegisterInfo is passed, then it also checks if there is
1208   /// a kill of a super-register.
1209   bool killsRegister(Register Reg,
1210                      const TargetRegisterInfo *TRI = nullptr) const {
1211     return findRegisterUseOperandIdx(Reg, true, TRI) != -1;
1212   }
1213 
1214   /// Return true if the MachineInstr fully defines the specified register.
1215   /// If TargetRegisterInfo is passed, then it also checks
1216   /// if there is a def of a super-register.
1217   /// NOTE: It's ignoring subreg indices on virtual registers.
1218   bool definesRegister(Register Reg,
1219                        const TargetRegisterInfo *TRI = nullptr) const {
1220     return findRegisterDefOperandIdx(Reg, false, false, TRI) != -1;
1221   }
1222 
1223   /// Return true if the MachineInstr modifies (fully define or partially
1224   /// define) the specified register.
1225   /// NOTE: It's ignoring subreg indices on virtual registers.
1226   bool modifiesRegister(Register Reg, const TargetRegisterInfo *TRI) const {
1227     return findRegisterDefOperandIdx(Reg, false, true, TRI) != -1;
1228   }
1229 
1230   /// Returns true if the register is dead in this machine instruction.
1231   /// If TargetRegisterInfo is passed, then it also checks
1232   /// if there is a dead def of a super-register.
1233   bool registerDefIsDead(Register Reg,
1234                          const TargetRegisterInfo *TRI = nullptr) const {
1235     return findRegisterDefOperandIdx(Reg, true, false, TRI) != -1;
1236   }
1237 
1238   /// Returns true if the MachineInstr has an implicit-use operand of exactly
1239   /// the given register (not considering sub/super-registers).
1240   bool hasRegisterImplicitUseOperand(Register Reg) const;
1241 
1242   /// Returns the operand index that is a use of the specific register or -1
1243   /// if it is not found. It further tightens the search criteria to a use
1244   /// that kills the register if isKill is true.
1245   int findRegisterUseOperandIdx(Register Reg, bool isKill = false,
1246                                 const TargetRegisterInfo *TRI = nullptr) const;
1247 
1248   /// Wrapper for findRegisterUseOperandIdx, it returns
1249   /// a pointer to the MachineOperand rather than an index.
1250   MachineOperand *findRegisterUseOperand(Register Reg, bool isKill = false,
1251                                       const TargetRegisterInfo *TRI = nullptr) {
1252     int Idx = findRegisterUseOperandIdx(Reg, isKill, TRI);
1253     return (Idx == -1) ? nullptr : &getOperand(Idx);
1254   }
1255 
1256   const MachineOperand *findRegisterUseOperand(
1257     Register Reg, bool isKill = false,
1258     const TargetRegisterInfo *TRI = nullptr) const {
1259     return const_cast<MachineInstr *>(this)->
1260       findRegisterUseOperand(Reg, isKill, TRI);
1261   }
1262 
1263   /// Returns the operand index that is a def of the specified register or
1264   /// -1 if it is not found. If isDead is true, defs that are not dead are
1265   /// skipped. If Overlap is true, then it also looks for defs that merely
1266   /// overlap the specified register. If TargetRegisterInfo is non-null,
1267   /// then it also checks if there is a def of a super-register.
1268   /// This may also return a register mask operand when Overlap is true.
1269   int findRegisterDefOperandIdx(Register Reg,
1270                                 bool isDead = false, bool Overlap = false,
1271                                 const TargetRegisterInfo *TRI = nullptr) const;
1272 
1273   /// Wrapper for findRegisterDefOperandIdx, it returns
1274   /// a pointer to the MachineOperand rather than an index.
1275   MachineOperand *
1276   findRegisterDefOperand(Register Reg, bool isDead = false,
1277                          bool Overlap = false,
1278                          const TargetRegisterInfo *TRI = nullptr) {
1279     int Idx = findRegisterDefOperandIdx(Reg, isDead, Overlap, TRI);
1280     return (Idx == -1) ? nullptr : &getOperand(Idx);
1281   }
1282 
1283   const MachineOperand *
1284   findRegisterDefOperand(Register Reg, bool isDead = false,
1285                          bool Overlap = false,
1286                          const TargetRegisterInfo *TRI = nullptr) const {
1287     return const_cast<MachineInstr *>(this)->findRegisterDefOperand(
1288         Reg, isDead, Overlap, TRI);
1289   }
1290 
1291   /// Find the index of the first operand in the
1292   /// operand list that is used to represent the predicate. It returns -1 if
1293   /// none is found.
1294   int findFirstPredOperandIdx() const;
1295 
1296   /// Find the index of the flag word operand that
1297   /// corresponds to operand OpIdx on an inline asm instruction.  Returns -1 if
1298   /// getOperand(OpIdx) does not belong to an inline asm operand group.
1299   ///
1300   /// If GroupNo is not NULL, it will receive the number of the operand group
1301   /// containing OpIdx.
1302   ///
1303   /// The flag operand is an immediate that can be decoded with methods like
1304   /// InlineAsm::hasRegClassConstraint().
1305   int findInlineAsmFlagIdx(unsigned OpIdx, unsigned *GroupNo = nullptr) const;
1306 
1307   /// Compute the static register class constraint for operand OpIdx.
1308   /// For normal instructions, this is derived from the MCInstrDesc.
1309   /// For inline assembly it is derived from the flag words.
1310   ///
1311   /// Returns NULL if the static register class constraint cannot be
1312   /// determined.
1313   const TargetRegisterClass*
1314   getRegClassConstraint(unsigned OpIdx,
1315                         const TargetInstrInfo *TII,
1316                         const TargetRegisterInfo *TRI) const;
1317 
1318   /// Applies the constraints (def/use) implied by this MI on \p Reg to
1319   /// the given \p CurRC.
1320   /// If \p ExploreBundle is set and MI is part of a bundle, all the
1321   /// instructions inside the bundle will be taken into account. In other words,
1322   /// this method accumulates all the constraints of the operand of this MI and
1323   /// the related bundle if MI is a bundle or inside a bundle.
1324   ///
1325   /// Returns the register class that satisfies both \p CurRC and the
1326   /// constraints set by MI. Returns NULL if such a register class does not
1327   /// exist.
1328   ///
1329   /// \pre CurRC must not be NULL.
1330   const TargetRegisterClass *getRegClassConstraintEffectForVReg(
1331       Register Reg, const TargetRegisterClass *CurRC,
1332       const TargetInstrInfo *TII, const TargetRegisterInfo *TRI,
1333       bool ExploreBundle = false) const;
1334 
1335   /// Applies the constraints (def/use) implied by the \p OpIdx operand
1336   /// to the given \p CurRC.
1337   ///
1338   /// Returns the register class that satisfies both \p CurRC and the
1339   /// constraints set by \p OpIdx MI. Returns NULL if such a register class
1340   /// does not exist.
1341   ///
1342   /// \pre CurRC must not be NULL.
1343   /// \pre The operand at \p OpIdx must be a register.
1344   const TargetRegisterClass *
1345   getRegClassConstraintEffect(unsigned OpIdx, const TargetRegisterClass *CurRC,
1346                               const TargetInstrInfo *TII,
1347                               const TargetRegisterInfo *TRI) const;
1348 
1349   /// Add a tie between the register operands at DefIdx and UseIdx.
1350   /// The tie will cause the register allocator to ensure that the two
1351   /// operands are assigned the same physical register.
1352   ///
1353   /// Tied operands are managed automatically for explicit operands in the
1354   /// MCInstrDesc. This method is for exceptional cases like inline asm.
1355   void tieOperands(unsigned DefIdx, unsigned UseIdx);
1356 
1357   /// Given the index of a tied register operand, find the
1358   /// operand it is tied to. Defs are tied to uses and vice versa. Returns the
1359   /// index of the tied operand which must exist.
1360   unsigned findTiedOperandIdx(unsigned OpIdx) const;
1361 
1362   /// Given the index of a register def operand,
1363   /// check if the register def is tied to a source operand, due to either
1364   /// two-address elimination or inline assembly constraints. Returns the
1365   /// first tied use operand index by reference if UseOpIdx is not null.
1366   bool isRegTiedToUseOperand(unsigned DefOpIdx,
1367                              unsigned *UseOpIdx = nullptr) const {
1368     const MachineOperand &MO = getOperand(DefOpIdx);
1369     if (!MO.isReg() || !MO.isDef() || !MO.isTied())
1370       return false;
1371     if (UseOpIdx)
1372       *UseOpIdx = findTiedOperandIdx(DefOpIdx);
1373     return true;
1374   }
1375 
1376   /// Return true if the use operand of the specified index is tied to a def
1377   /// operand. It also returns the def operand index by reference if DefOpIdx
1378   /// is not null.
1379   bool isRegTiedToDefOperand(unsigned UseOpIdx,
1380                              unsigned *DefOpIdx = nullptr) const {
1381     const MachineOperand &MO = getOperand(UseOpIdx);
1382     if (!MO.isReg() || !MO.isUse() || !MO.isTied())
1383       return false;
1384     if (DefOpIdx)
1385       *DefOpIdx = findTiedOperandIdx(UseOpIdx);
1386     return true;
1387   }
1388 
1389   /// Clears kill flags on all operands.
1390   void clearKillInfo();
1391 
1392   /// Replace all occurrences of FromReg with ToReg:SubIdx,
1393   /// properly composing subreg indices where necessary.
1394   void substituteRegister(Register FromReg, Register ToReg, unsigned SubIdx,
1395                           const TargetRegisterInfo &RegInfo);
1396 
1397   /// We have determined MI kills a register. Look for the
1398   /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
1399   /// add a implicit operand if it's not found. Returns true if the operand
1400   /// exists / is added.
1401   bool addRegisterKilled(Register IncomingReg,
1402                          const TargetRegisterInfo *RegInfo,
1403                          bool AddIfNotFound = false);
1404 
1405   /// Clear all kill flags affecting Reg.  If RegInfo is provided, this includes
1406   /// all aliasing registers.
1407   void clearRegisterKills(Register Reg, const TargetRegisterInfo *RegInfo);
1408 
1409   /// We have determined MI defined a register without a use.
1410   /// Look for the operand that defines it and mark it as IsDead. If
1411   /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
1412   /// true if the operand exists / is added.
1413   bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo,
1414                        bool AddIfNotFound = false);
1415 
1416   /// Clear all dead flags on operands defining register @p Reg.
1417   void clearRegisterDeads(Register Reg);
1418 
1419   /// Mark all subregister defs of register @p Reg with the undef flag.
1420   /// This function is used when we determined to have a subregister def in an
1421   /// otherwise undefined super register.
1422   void setRegisterDefReadUndef(Register Reg, bool IsUndef = true);
1423 
1424   /// We have determined MI defines a register. Make sure there is an operand
1425   /// defining Reg.
1426   void addRegisterDefined(Register Reg,
1427                           const TargetRegisterInfo *RegInfo = nullptr);
1428 
1429   /// Mark every physreg used by this instruction as
1430   /// dead except those in the UsedRegs list.
1431   ///
1432   /// On instructions with register mask operands, also add implicit-def
1433   /// operands for all registers in UsedRegs.
1434   void setPhysRegsDeadExcept(ArrayRef<Register> UsedRegs,
1435                              const TargetRegisterInfo &TRI);
1436 
1437   /// Return true if it is safe to move this instruction. If
1438   /// SawStore is set to true, it means that there is a store (or call) between
1439   /// the instruction's location and its intended destination.
1440   bool isSafeToMove(AAResults *AA, bool &SawStore) const;
1441 
1442   /// Returns true if this instruction's memory access aliases the memory
1443   /// access of Other.
1444   //
1445   /// Assumes any physical registers used to compute addresses
1446   /// have the same value for both instructions.  Returns false if neither
1447   /// instruction writes to memory.
1448   ///
1449   /// @param AA Optional alias analysis, used to compare memory operands.
1450   /// @param Other MachineInstr to check aliasing against.
1451   /// @param UseTBAA Whether to pass TBAA information to alias analysis.
1452   bool mayAlias(AAResults *AA, const MachineInstr &Other, bool UseTBAA) const;
1453 
1454   /// Return true if this instruction may have an ordered
1455   /// or volatile memory reference, or if the information describing the memory
1456   /// reference is not available. Return false if it is known to have no
1457   /// ordered or volatile memory references.
1458   bool hasOrderedMemoryRef() const;
1459 
1460   /// Return true if this load instruction never traps and points to a memory
1461   /// location whose value doesn't change during the execution of this function.
1462   ///
1463   /// Examples include loading a value from the constant pool or from the
1464   /// argument area of a function (if it does not change).  If the instruction
1465   /// does multiple loads, this returns true only if all of the loads are
1466   /// dereferenceable and invariant.
1467   bool isDereferenceableInvariantLoad(AAResults *AA) const;
1468 
1469   /// If the specified instruction is a PHI that always merges together the
1470   /// same virtual register, return the register, otherwise return 0.
1471   unsigned isConstantValuePHI() const;
1472 
1473   /// Return true if this instruction has side effects that are not modeled
1474   /// by mayLoad / mayStore, etc.
1475   /// For all instructions, the property is encoded in MCInstrDesc::Flags
1476   /// (see MCInstrDesc::hasUnmodeledSideEffects(). The only exception is
1477   /// INLINEASM instruction, in which case the side effect property is encoded
1478   /// in one of its operands (see InlineAsm::Extra_HasSideEffect).
1479   ///
1480   bool hasUnmodeledSideEffects() const;
1481 
1482   /// Returns true if it is illegal to fold a load across this instruction.
1483   bool isLoadFoldBarrier() const;
1484 
1485   /// Return true if all the defs of this instruction are dead.
1486   bool allDefsAreDead() const;
1487 
1488   /// Return a valid size if the instruction is a spill instruction.
1489   Optional<unsigned> getSpillSize(const TargetInstrInfo *TII) const;
1490 
1491   /// Return a valid size if the instruction is a folded spill instruction.
1492   Optional<unsigned> getFoldedSpillSize(const TargetInstrInfo *TII) const;
1493 
1494   /// Return a valid size if the instruction is a restore instruction.
1495   Optional<unsigned> getRestoreSize(const TargetInstrInfo *TII) const;
1496 
1497   /// Return a valid size if the instruction is a folded restore instruction.
1498   Optional<unsigned>
1499   getFoldedRestoreSize(const TargetInstrInfo *TII) const;
1500 
1501   /// Copy implicit register operands from specified
1502   /// instruction to this instruction.
1503   void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI);
1504 
1505   /// Debugging support
1506   /// @{
1507   /// Determine the generic type to be printed (if needed) on uses and defs.
1508   LLT getTypeToPrint(unsigned OpIdx, SmallBitVector &PrintedTypes,
1509                      const MachineRegisterInfo &MRI) const;
1510 
1511   /// Return true when an instruction has tied register that can't be determined
1512   /// by the instruction's descriptor. This is useful for MIR printing, to
1513   /// determine whether we need to print the ties or not.
1514   bool hasComplexRegisterTies() const;
1515 
1516   /// Print this MI to \p OS.
1517   /// Don't print information that can be inferred from other instructions if
1518   /// \p IsStandalone is false. It is usually true when only a fragment of the
1519   /// function is printed.
1520   /// Only print the defs and the opcode if \p SkipOpers is true.
1521   /// Otherwise, also print operands if \p SkipDebugLoc is true.
1522   /// Otherwise, also print the debug loc, with a terminating newline.
1523   /// \p TII is used to print the opcode name.  If it's not present, but the
1524   /// MI is in a function, the opcode will be printed using the function's TII.
1525   void print(raw_ostream &OS, bool IsStandalone = true, bool SkipOpers = false,
1526              bool SkipDebugLoc = false, bool AddNewLine = true,
1527              const TargetInstrInfo *TII = nullptr) const;
1528   void print(raw_ostream &OS, ModuleSlotTracker &MST, bool IsStandalone = true,
1529              bool SkipOpers = false, bool SkipDebugLoc = false,
1530              bool AddNewLine = true,
1531              const TargetInstrInfo *TII = nullptr) const;
1532   void dump() const;
1533   /// @}
1534 
1535   //===--------------------------------------------------------------------===//
1536   // Accessors used to build up machine instructions.
1537 
1538   /// Add the specified operand to the instruction.  If it is an implicit
1539   /// operand, it is added to the end of the operand list.  If it is an
1540   /// explicit operand it is added at the end of the explicit operand list
1541   /// (before the first implicit operand).
1542   ///
1543   /// MF must be the machine function that was used to allocate this
1544   /// instruction.
1545   ///
1546   /// MachineInstrBuilder provides a more convenient interface for creating
1547   /// instructions and adding operands.
1548   void addOperand(MachineFunction &MF, const MachineOperand &Op);
1549 
1550   /// Add an operand without providing an MF reference. This only works for
1551   /// instructions that are inserted in a basic block.
1552   ///
1553   /// MachineInstrBuilder and the two-argument addOperand(MF, MO) should be
1554   /// preferred.
1555   void addOperand(const MachineOperand &Op);
1556 
1557   /// Replace the instruction descriptor (thus opcode) of
1558   /// the current instruction with a new one.
1559   void setDesc(const MCInstrDesc &tid) { MCID = &tid; }
1560 
1561   /// Replace current source information with new such.
1562   /// Avoid using this, the constructor argument is preferable.
1563   void setDebugLoc(DebugLoc dl) {
1564     debugLoc = std::move(dl);
1565     assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
1566   }
1567 
1568   /// Erase an operand from an instruction, leaving it with one
1569   /// fewer operand than it started with.
1570   void RemoveOperand(unsigned OpNo);
1571 
1572   /// Clear this MachineInstr's memory reference descriptor list.  This resets
1573   /// the memrefs to their most conservative state.  This should be used only
1574   /// as a last resort since it greatly pessimizes our knowledge of the memory
1575   /// access performed by the instruction.
1576   void dropMemRefs(MachineFunction &MF);
1577 
1578   /// Assign this MachineInstr's memory reference descriptor list.
1579   ///
1580   /// Unlike other methods, this *will* allocate them into a new array
1581   /// associated with the provided `MachineFunction`.
1582   void setMemRefs(MachineFunction &MF, ArrayRef<MachineMemOperand *> MemRefs);
1583 
1584   /// Add a MachineMemOperand to the machine instruction.
1585   /// This function should be used only occasionally. The setMemRefs function
1586   /// is the primary method for setting up a MachineInstr's MemRefs list.
1587   void addMemOperand(MachineFunction &MF, MachineMemOperand *MO);
1588 
1589   /// Clone another MachineInstr's memory reference descriptor list and replace
1590   /// ours with it.
1591   ///
1592   /// Note that `*this` may be the incoming MI!
1593   ///
1594   /// Prefer this API whenever possible as it can avoid allocations in common
1595   /// cases.
1596   void cloneMemRefs(MachineFunction &MF, const MachineInstr &MI);
1597 
1598   /// Clone the merge of multiple MachineInstrs' memory reference descriptors
1599   /// list and replace ours with it.
1600   ///
1601   /// Note that `*this` may be one of the incoming MIs!
1602   ///
1603   /// Prefer this API whenever possible as it can avoid allocations in common
1604   /// cases.
1605   void cloneMergedMemRefs(MachineFunction &MF,
1606                           ArrayRef<const MachineInstr *> MIs);
1607 
1608   /// Set a symbol that will be emitted just prior to the instruction itself.
1609   ///
1610   /// Setting this to a null pointer will remove any such symbol.
1611   ///
1612   /// FIXME: This is not fully implemented yet.
1613   void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol);
1614 
1615   /// Set a symbol that will be emitted just after the instruction itself.
1616   ///
1617   /// Setting this to a null pointer will remove any such symbol.
1618   ///
1619   /// FIXME: This is not fully implemented yet.
1620   void setPostInstrSymbol(MachineFunction &MF, MCSymbol *Symbol);
1621 
1622   /// Clone another MachineInstr's pre- and post- instruction symbols and
1623   /// replace ours with it.
1624   void cloneInstrSymbols(MachineFunction &MF, const MachineInstr &MI);
1625 
1626   /// Set a marker on instructions that denotes where we should create and emit
1627   /// heap alloc site labels. This waits until after instruction selection and
1628   /// optimizations to create the label, so it should still work if the
1629   /// instruction is removed or duplicated.
1630   void setHeapAllocMarker(MachineFunction &MF, MDNode *MD);
1631 
1632   /// Return the MIFlags which represent both MachineInstrs. This
1633   /// should be used when merging two MachineInstrs into one. This routine does
1634   /// not modify the MIFlags of this MachineInstr.
1635   uint16_t mergeFlagsWith(const MachineInstr& Other) const;
1636 
1637   static uint16_t copyFlagsFromInstruction(const Instruction &I);
1638 
1639   /// Copy all flags to MachineInst MIFlags
1640   void copyIRFlags(const Instruction &I);
1641 
1642   /// Break any tie involving OpIdx.
1643   void untieRegOperand(unsigned OpIdx) {
1644     MachineOperand &MO = getOperand(OpIdx);
1645     if (MO.isReg() && MO.isTied()) {
1646       getOperand(findTiedOperandIdx(OpIdx)).TiedTo = 0;
1647       MO.TiedTo = 0;
1648     }
1649   }
1650 
1651   /// Add all implicit def and use operands to this instruction.
1652   void addImplicitDefUseOperands(MachineFunction &MF);
1653 
1654   /// Scan instructions immediately following MI and collect any matching
1655   /// DBG_VALUEs.
1656   void collectDebugValues(SmallVectorImpl<MachineInstr *> &DbgValues);
1657 
1658   /// Find all DBG_VALUEs that point to the register def in this instruction
1659   /// and point them to \p Reg instead.
1660   void changeDebugValuesDefReg(Register Reg);
1661 
1662   /// Returns the Intrinsic::ID for this instruction.
1663   /// \pre Must have an intrinsic ID operand.
1664   unsigned getIntrinsicID() const {
1665     return getOperand(getNumExplicitDefs()).getIntrinsicID();
1666   }
1667 
1668 private:
1669   /// If this instruction is embedded into a MachineFunction, return the
1670   /// MachineRegisterInfo object for the current function, otherwise
1671   /// return null.
1672   MachineRegisterInfo *getRegInfo();
1673 
1674   /// Unlink all of the register operands in this instruction from their
1675   /// respective use lists.  This requires that the operands already be on their
1676   /// use lists.
1677   void RemoveRegOperandsFromUseLists(MachineRegisterInfo&);
1678 
1679   /// Add all of the register operands in this instruction from their
1680   /// respective use lists.  This requires that the operands not be on their
1681   /// use lists yet.
1682   void AddRegOperandsToUseLists(MachineRegisterInfo&);
1683 
1684   /// Slow path for hasProperty when we're dealing with a bundle.
1685   bool hasPropertyInBundle(uint64_t Mask, QueryType Type) const;
1686 
1687   /// Implements the logic of getRegClassConstraintEffectForVReg for the
1688   /// this MI and the given operand index \p OpIdx.
1689   /// If the related operand does not constrained Reg, this returns CurRC.
1690   const TargetRegisterClass *getRegClassConstraintEffectForVRegImpl(
1691       unsigned OpIdx, Register Reg, const TargetRegisterClass *CurRC,
1692       const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const;
1693 
1694   /// Stores extra instruction information inline or allocates as ExtraInfo
1695   /// based on the number of pointers.
1696   void setExtraInfo(MachineFunction &MF, ArrayRef<MachineMemOperand *> MMOs,
1697                     MCSymbol *PreInstrSymbol, MCSymbol *PostInstrSymbol,
1698                     MDNode *HeapAllocMarker);
1699 };
1700 
1701 /// Special DenseMapInfo traits to compare MachineInstr* by *value* of the
1702 /// instruction rather than by pointer value.
1703 /// The hashing and equality testing functions ignore definitions so this is
1704 /// useful for CSE, etc.
1705 struct MachineInstrExpressionTrait : DenseMapInfo<MachineInstr*> {
1706   static inline MachineInstr *getEmptyKey() {
1707     return nullptr;
1708   }
1709 
1710   static inline MachineInstr *getTombstoneKey() {
1711     return reinterpret_cast<MachineInstr*>(-1);
1712   }
1713 
1714   static unsigned getHashValue(const MachineInstr* const &MI);
1715 
1716   static bool isEqual(const MachineInstr* const &LHS,
1717                       const MachineInstr* const &RHS) {
1718     if (RHS == getEmptyKey() || RHS == getTombstoneKey() ||
1719         LHS == getEmptyKey() || LHS == getTombstoneKey())
1720       return LHS == RHS;
1721     return LHS->isIdenticalTo(*RHS, MachineInstr::IgnoreVRegDefs);
1722   }
1723 };
1724 
1725 //===----------------------------------------------------------------------===//
1726 // Debugging Support
1727 
1728 inline raw_ostream& operator<<(raw_ostream &OS, const MachineInstr &MI) {
1729   MI.print(OS);
1730   return OS;
1731 }
1732 
1733 } // end namespace llvm
1734 
1735 #endif // LLVM_CODEGEN_MACHINEINSTR_H
1736