MachineInstr: introduce explicit_operands and implicit_operands ranges
[oota-llvm.git] / include / llvm / CodeGen / MachineInstr.h
1 //===-- llvm/CodeGen/MachineInstr.h - MachineInstr class --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the MachineInstr class, which is the
11 // basic representation for all target dependent machine instructions used by
12 // the back end.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_MACHINEINSTR_H
17 #define LLVM_CODEGEN_MACHINEINSTR_H
18
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/DenseMapInfo.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/ilist.h"
24 #include "llvm/ADT/ilist_node.h"
25 #include "llvm/ADT/iterator_range.h"
26 #include "llvm/CodeGen/MachineOperand.h"
27 #include "llvm/IR/DebugLoc.h"
28 #include "llvm/IR/InlineAsm.h"
29 #include "llvm/MC/MCInstrDesc.h"
30 #include "llvm/Support/ArrayRecycler.h"
31 #include "llvm/Target/TargetOpcodes.h"
32
33 namespace llvm {
34
35 template <typename T> class SmallVectorImpl;
36 class AliasAnalysis;
37 class TargetInstrInfo;
38 class TargetRegisterClass;
39 class TargetRegisterInfo;
40 class MachineFunction;
41 class MachineMemOperand;
42
43 //===----------------------------------------------------------------------===//
44 /// MachineInstr - Representation of each machine instruction.
45 ///
46 /// This class isn't a POD type, but it must have a trivial destructor. When a
47 /// MachineFunction is deleted, all the contained MachineInstrs are deallocated
48 /// without having their destructor called.
49 ///
50 class MachineInstr : public ilist_node<MachineInstr> {
51 public:
52   typedef MachineMemOperand **mmo_iterator;
53
54   /// Flags to specify different kinds of comments to output in
55   /// assembly code.  These flags carry semantic information not
56   /// otherwise easily derivable from the IR text.
57   ///
58   enum CommentFlag {
59     ReloadReuse = 0x1
60   };
61
62   enum MIFlag {
63     NoFlags      = 0,
64     FrameSetup   = 1 << 0,              // Instruction is used as a part of
65                                         // function frame setup code.
66     BundledPred  = 1 << 1,              // Instruction has bundled predecessors.
67     BundledSucc  = 1 << 2               // Instruction has bundled successors.
68   };
69 private:
70   const MCInstrDesc *MCID;              // Instruction descriptor.
71   MachineBasicBlock *Parent;            // Pointer to the owning basic block.
72
73   // Operands are allocated by an ArrayRecycler.
74   MachineOperand *Operands;             // Pointer to the first operand.
75   unsigned NumOperands;                 // Number of operands on instruction.
76   typedef ArrayRecycler<MachineOperand>::Capacity OperandCapacity;
77   OperandCapacity CapOperands;          // Capacity of the Operands array.
78
79   uint8_t Flags;                        // Various bits of additional
80                                         // information about machine
81                                         // instruction.
82
83   uint8_t AsmPrinterFlags;              // Various bits of information used by
84                                         // the AsmPrinter to emit helpful
85                                         // comments.  This is *not* semantic
86                                         // information.  Do not use this for
87                                         // anything other than to convey comment
88                                         // information to AsmPrinter.
89
90   uint8_t NumMemRefs;                   // Information on memory references.
91   mmo_iterator MemRefs;
92
93   DebugLoc debugLoc;                    // Source line information.
94
95   MachineInstr(const MachineInstr&) LLVM_DELETED_FUNCTION;
96   void operator=(const MachineInstr&) LLVM_DELETED_FUNCTION;
97   // Use MachineFunction::DeleteMachineInstr() instead.
98   ~MachineInstr() LLVM_DELETED_FUNCTION;
99
100   // Intrusive list support
101   friend struct ilist_traits<MachineInstr>;
102   friend struct ilist_traits<MachineBasicBlock>;
103   void setParent(MachineBasicBlock *P) { Parent = P; }
104
105   /// MachineInstr ctor - This constructor creates a copy of the given
106   /// MachineInstr in the given MachineFunction.
107   MachineInstr(MachineFunction &, const MachineInstr &);
108
109   /// MachineInstr ctor - This constructor create a MachineInstr and add the
110   /// implicit operands.  It reserves space for number of operands specified by
111   /// MCInstrDesc.  An explicit DebugLoc is supplied.
112   MachineInstr(MachineFunction&, const MCInstrDesc &MCID,
113                const DebugLoc dl, bool NoImp = false);
114
115   // MachineInstrs are pool-allocated and owned by MachineFunction.
116   friend class MachineFunction;
117
118 public:
119   const MachineBasicBlock* getParent() const { return Parent; }
120   MachineBasicBlock* getParent() { return Parent; }
121
122   /// getAsmPrinterFlags - Return the asm printer flags bitvector.
123   ///
124   uint8_t getAsmPrinterFlags() const { return AsmPrinterFlags; }
125
126   /// clearAsmPrinterFlags - clear the AsmPrinter bitvector
127   ///
128   void clearAsmPrinterFlags() { AsmPrinterFlags = 0; }
129
130   /// getAsmPrinterFlag - Return whether an AsmPrinter flag is set.
131   ///
132   bool getAsmPrinterFlag(CommentFlag Flag) const {
133     return AsmPrinterFlags & Flag;
134   }
135
136   /// setAsmPrinterFlag - Set a flag for the AsmPrinter.
137   ///
138   void setAsmPrinterFlag(CommentFlag Flag) {
139     AsmPrinterFlags |= (uint8_t)Flag;
140   }
141
142   /// clearAsmPrinterFlag - clear specific AsmPrinter flags
143   ///
144   void clearAsmPrinterFlag(CommentFlag Flag) {
145     AsmPrinterFlags &= ~Flag;
146   }
147
148   /// getFlags - Return the MI flags bitvector.
149   uint8_t getFlags() const {
150     return Flags;
151   }
152
153   /// getFlag - Return whether an MI flag is set.
154   bool getFlag(MIFlag Flag) const {
155     return Flags & Flag;
156   }
157
158   /// setFlag - Set a MI flag.
159   void setFlag(MIFlag Flag) {
160     Flags |= (uint8_t)Flag;
161   }
162
163   void setFlags(unsigned flags) {
164     // Filter out the automatically maintained flags.
165     unsigned Mask = BundledPred | BundledSucc;
166     Flags = (Flags & Mask) | (flags & ~Mask);
167   }
168
169   /// clearFlag - Clear a MI flag.
170   void clearFlag(MIFlag Flag) {
171     Flags &= ~((uint8_t)Flag);
172   }
173
174   /// isInsideBundle - Return true if MI is in a bundle (but not the first MI
175   /// in a bundle).
176   ///
177   /// A bundle looks like this before it's finalized:
178   ///   ----------------
179   ///   |      MI      |
180   ///   ----------------
181   ///          |
182   ///   ----------------
183   ///   |      MI    * |
184   ///   ----------------
185   ///          |
186   ///   ----------------
187   ///   |      MI    * |
188   ///   ----------------
189   /// In this case, the first MI starts a bundle but is not inside a bundle, the
190   /// next 2 MIs are considered "inside" the bundle.
191   ///
192   /// After a bundle is finalized, it looks like this:
193   ///   ----------------
194   ///   |    Bundle    |
195   ///   ----------------
196   ///          |
197   ///   ----------------
198   ///   |      MI    * |
199   ///   ----------------
200   ///          |
201   ///   ----------------
202   ///   |      MI    * |
203   ///   ----------------
204   ///          |
205   ///   ----------------
206   ///   |      MI    * |
207   ///   ----------------
208   /// The first instruction has the special opcode "BUNDLE". It's not "inside"
209   /// a bundle, but the next three MIs are.
210   bool isInsideBundle() const {
211     return getFlag(BundledPred);
212   }
213
214   /// isBundled - Return true if this instruction part of a bundle. This is true
215   /// if either itself or its following instruction is marked "InsideBundle".
216   bool isBundled() const {
217     return isBundledWithPred() || isBundledWithSucc();
218   }
219
220   /// Return true if this instruction is part of a bundle, and it is not the
221   /// first instruction in the bundle.
222   bool isBundledWithPred() const { return getFlag(BundledPred); }
223
224   /// Return true if this instruction is part of a bundle, and it is not the
225   /// last instruction in the bundle.
226   bool isBundledWithSucc() const { return getFlag(BundledSucc); }
227
228   /// Bundle this instruction with its predecessor. This can be an unbundled
229   /// instruction, or it can be the first instruction in a bundle.
230   void bundleWithPred();
231
232   /// Bundle this instruction with its successor. This can be an unbundled
233   /// instruction, or it can be the last instruction in a bundle.
234   void bundleWithSucc();
235
236   /// Break bundle above this instruction.
237   void unbundleFromPred();
238
239   /// Break bundle below this instruction.
240   void unbundleFromSucc();
241
242   /// getDebugLoc - Returns the debug location id of this MachineInstr.
243   ///
244   DebugLoc getDebugLoc() const { return debugLoc; }
245
246   /// emitError - Emit an error referring to the source location of this
247   /// instruction. This should only be used for inline assembly that is somehow
248   /// impossible to compile. Other errors should have been handled much
249   /// earlier.
250   ///
251   /// If this method returns, the caller should try to recover from the error.
252   ///
253   void emitError(StringRef Msg) const;
254
255   /// getDesc - Returns the target instruction descriptor of this
256   /// MachineInstr.
257   const MCInstrDesc &getDesc() const { return *MCID; }
258
259   /// getOpcode - Returns the opcode of this MachineInstr.
260   ///
261   int getOpcode() const { return MCID->Opcode; }
262
263   /// Access to explicit operands of the instruction.
264   ///
265   unsigned getNumOperands() const { return NumOperands; }
266
267   const MachineOperand& getOperand(unsigned i) const {
268     assert(i < getNumOperands() && "getOperand() out of range!");
269     return Operands[i];
270   }
271   MachineOperand& getOperand(unsigned i) {
272     assert(i < getNumOperands() && "getOperand() out of range!");
273     return Operands[i];
274   }
275
276   /// getNumExplicitOperands - Returns the number of non-implicit operands.
277   ///
278   unsigned getNumExplicitOperands() const;
279
280   /// iterator/begin/end - Iterate over all operands of a machine instruction.
281   typedef MachineOperand *mop_iterator;
282   typedef const MachineOperand *const_mop_iterator;
283
284   mop_iterator operands_begin() { return Operands; }
285   mop_iterator operands_end() { return Operands + NumOperands; }
286
287   const_mop_iterator operands_begin() const { return Operands; }
288   const_mop_iterator operands_end() const { return Operands + NumOperands; }
289
290   iterator_range<mop_iterator> operands() {
291     return iterator_range<mop_iterator>(operands_begin(), operands_end());
292   }
293   iterator_range<const_mop_iterator> operands() const {
294     return iterator_range<const_mop_iterator>(operands_begin(), operands_end());
295   }
296   iterator_range<mop_iterator> explicit_operands() {
297     return iterator_range<mop_iterator>(
298         operands_begin(), operands_begin() + getNumExplicitOperands());
299   }
300   iterator_range<const_mop_iterator> explicit_operands() const {
301     return iterator_range<const_mop_iterator>(
302         operands_begin(), operands_begin() + getNumExplicitOperands());
303   }
304   iterator_range<mop_iterator> implicit_operands() {
305     return iterator_range<mop_iterator>(explicit_operands().end(),
306                                         operands_end());
307   }
308   iterator_range<const_mop_iterator> implicit_operands() const {
309     return iterator_range<const_mop_iterator>(explicit_operands().end(),
310                                               operands_end());
311   }
312
313   /// Access to memory operands of the instruction
314   mmo_iterator memoperands_begin() const { return MemRefs; }
315   mmo_iterator memoperands_end() const { return MemRefs + NumMemRefs; }
316   bool memoperands_empty() const { return NumMemRefs == 0; }
317
318   iterator_range<mmo_iterator>  memoperands() {
319     return iterator_range<mmo_iterator>(memoperands_begin(), memoperands_end());
320   }
321   iterator_range<mmo_iterator> memoperands() const {
322     return iterator_range<mmo_iterator>(memoperands_begin(), memoperands_end());
323   }
324
325   /// hasOneMemOperand - Return true if this instruction has exactly one
326   /// MachineMemOperand.
327   bool hasOneMemOperand() const {
328     return NumMemRefs == 1;
329   }
330
331   /// API for querying MachineInstr properties. They are the same as MCInstrDesc
332   /// queries but they are bundle aware.
333
334   enum QueryType {
335     IgnoreBundle,    // Ignore bundles
336     AnyInBundle,     // Return true if any instruction in bundle has property
337     AllInBundle      // Return true if all instructions in bundle have property
338   };
339
340   /// hasProperty - Return true if the instruction (or in the case of a bundle,
341   /// the instructions inside the bundle) has the specified property.
342   /// The first argument is the property being queried.
343   /// The second argument indicates whether the query should look inside
344   /// instruction bundles.
345   bool hasProperty(unsigned MCFlag, QueryType Type = AnyInBundle) const {
346     // Inline the fast path for unbundled or bundle-internal instructions.
347     if (Type == IgnoreBundle || !isBundled() || isBundledWithPred())
348       return getDesc().getFlags() & (1 << MCFlag);
349
350     // If this is the first instruction in a bundle, take the slow path.
351     return hasPropertyInBundle(1 << MCFlag, Type);
352   }
353
354   /// isVariadic - Return true if this instruction can have a variable number of
355   /// operands.  In this case, the variable operands will be after the normal
356   /// operands but before the implicit definitions and uses (if any are
357   /// present).
358   bool isVariadic(QueryType Type = IgnoreBundle) const {
359     return hasProperty(MCID::Variadic, Type);
360   }
361
362   /// hasOptionalDef - Set if this instruction has an optional definition, e.g.
363   /// ARM instructions which can set condition code if 's' bit is set.
364   bool hasOptionalDef(QueryType Type = IgnoreBundle) const {
365     return hasProperty(MCID::HasOptionalDef, Type);
366   }
367
368   /// isPseudo - Return true if this is a pseudo instruction that doesn't
369   /// correspond to a real machine instruction.
370   ///
371   bool isPseudo(QueryType Type = IgnoreBundle) const {
372     return hasProperty(MCID::Pseudo, Type);
373   }
374
375   bool isReturn(QueryType Type = AnyInBundle) const {
376     return hasProperty(MCID::Return, Type);
377   }
378
379   bool isCall(QueryType Type = AnyInBundle) const {
380     return hasProperty(MCID::Call, Type);
381   }
382
383   /// isBarrier - Returns true if the specified instruction stops control flow
384   /// from executing the instruction immediately following it.  Examples include
385   /// unconditional branches and return instructions.
386   bool isBarrier(QueryType Type = AnyInBundle) const {
387     return hasProperty(MCID::Barrier, Type);
388   }
389
390   /// isTerminator - Returns true if this instruction part of the terminator for
391   /// a basic block.  Typically this is things like return and branch
392   /// instructions.
393   ///
394   /// Various passes use this to insert code into the bottom of a basic block,
395   /// but before control flow occurs.
396   bool isTerminator(QueryType Type = AnyInBundle) const {
397     return hasProperty(MCID::Terminator, Type);
398   }
399
400   /// isBranch - Returns true if this is a conditional, unconditional, or
401   /// indirect branch.  Predicates below can be used to discriminate between
402   /// these cases, and the TargetInstrInfo::AnalyzeBranch method can be used to
403   /// get more information.
404   bool isBranch(QueryType Type = AnyInBundle) const {
405     return hasProperty(MCID::Branch, Type);
406   }
407
408   /// isIndirectBranch - Return true if this is an indirect branch, such as a
409   /// branch through a register.
410   bool isIndirectBranch(QueryType Type = AnyInBundle) const {
411     return hasProperty(MCID::IndirectBranch, Type);
412   }
413
414   /// isConditionalBranch - Return true if this is a branch which may fall
415   /// through to the next instruction or may transfer control flow to some other
416   /// block.  The TargetInstrInfo::AnalyzeBranch method can be used to get more
417   /// information about this branch.
418   bool isConditionalBranch(QueryType Type = AnyInBundle) const {
419     return isBranch(Type) & !isBarrier(Type) & !isIndirectBranch(Type);
420   }
421
422   /// isUnconditionalBranch - Return true if this is a branch which always
423   /// transfers control flow to some other block.  The
424   /// TargetInstrInfo::AnalyzeBranch method can be used to get more information
425   /// about this branch.
426   bool isUnconditionalBranch(QueryType Type = AnyInBundle) const {
427     return isBranch(Type) & isBarrier(Type) & !isIndirectBranch(Type);
428   }
429
430   /// Return true if this instruction has a predicate operand that
431   /// controls execution.  It may be set to 'always', or may be set to other
432   /// values.   There are various methods in TargetInstrInfo that can be used to
433   /// control and modify the predicate in this instruction.
434   bool isPredicable(QueryType Type = AllInBundle) const {
435     // If it's a bundle than all bundled instructions must be predicable for this
436     // to return true.
437     return hasProperty(MCID::Predicable, Type);
438   }
439
440   /// isCompare - Return true if this instruction is a comparison.
441   bool isCompare(QueryType Type = IgnoreBundle) const {
442     return hasProperty(MCID::Compare, Type);
443   }
444
445   /// isMoveImmediate - Return true if this instruction is a move immediate
446   /// (including conditional moves) instruction.
447   bool isMoveImmediate(QueryType Type = IgnoreBundle) const {
448     return hasProperty(MCID::MoveImm, Type);
449   }
450
451   /// isBitcast - Return true if this instruction is a bitcast instruction.
452   ///
453   bool isBitcast(QueryType Type = IgnoreBundle) const {
454     return hasProperty(MCID::Bitcast, Type);
455   }
456
457   /// isSelect - Return true if this instruction is a select instruction.
458   ///
459   bool isSelect(QueryType Type = IgnoreBundle) const {
460     return hasProperty(MCID::Select, Type);
461   }
462
463   /// isNotDuplicable - Return true if this instruction cannot be safely
464   /// duplicated.  For example, if the instruction has a unique labels attached
465   /// to it, duplicating it would cause multiple definition errors.
466   bool isNotDuplicable(QueryType Type = AnyInBundle) const {
467     return hasProperty(MCID::NotDuplicable, Type);
468   }
469
470   /// hasDelaySlot - Returns true if the specified instruction has a delay slot
471   /// which must be filled by the code generator.
472   bool hasDelaySlot(QueryType Type = AnyInBundle) const {
473     return hasProperty(MCID::DelaySlot, Type);
474   }
475
476   /// canFoldAsLoad - Return true for instructions that can be folded as
477   /// memory operands in other instructions. The most common use for this
478   /// is instructions that are simple loads from memory that don't modify
479   /// the loaded value in any way, but it can also be used for instructions
480   /// that can be expressed as constant-pool loads, such as V_SETALLONES
481   /// on x86, to allow them to be folded when it is beneficial.
482   /// This should only be set on instructions that return a value in their
483   /// only virtual register definition.
484   bool canFoldAsLoad(QueryType Type = IgnoreBundle) const {
485     return hasProperty(MCID::FoldableAsLoad, Type);
486   }
487
488   //===--------------------------------------------------------------------===//
489   // Side Effect Analysis
490   //===--------------------------------------------------------------------===//
491
492   /// mayLoad - Return true if this instruction could possibly read memory.
493   /// Instructions with this flag set are not necessarily simple load
494   /// instructions, they may load a value and modify it, for example.
495   bool mayLoad(QueryType Type = AnyInBundle) const {
496     if (isInlineAsm()) {
497       unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
498       if (ExtraInfo & InlineAsm::Extra_MayLoad)
499         return true;
500     }
501     return hasProperty(MCID::MayLoad, Type);
502   }
503
504
505   /// mayStore - Return true if this instruction could possibly modify memory.
506   /// Instructions with this flag set are not necessarily simple store
507   /// instructions, they may store a modified value based on their operands, or
508   /// may not actually modify anything, for example.
509   bool mayStore(QueryType Type = AnyInBundle) const {
510     if (isInlineAsm()) {
511       unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
512       if (ExtraInfo & InlineAsm::Extra_MayStore)
513         return true;
514     }
515     return hasProperty(MCID::MayStore, Type);
516   }
517
518   //===--------------------------------------------------------------------===//
519   // Flags that indicate whether an instruction can be modified by a method.
520   //===--------------------------------------------------------------------===//
521
522   /// isCommutable - Return true if this may be a 2- or 3-address
523   /// instruction (of the form "X = op Y, Z, ..."), which produces the same
524   /// result if Y and Z are exchanged.  If this flag is set, then the
525   /// TargetInstrInfo::commuteInstruction method may be used to hack on the
526   /// instruction.
527   ///
528   /// Note that this flag may be set on instructions that are only commutable
529   /// sometimes.  In these cases, the call to commuteInstruction will fail.
530   /// Also note that some instructions require non-trivial modification to
531   /// commute them.
532   bool isCommutable(QueryType Type = IgnoreBundle) const {
533     return hasProperty(MCID::Commutable, Type);
534   }
535
536   /// isConvertibleTo3Addr - Return true if this is a 2-address instruction
537   /// which can be changed into a 3-address instruction if needed.  Doing this
538   /// transformation can be profitable in the register allocator, because it
539   /// means that the instruction can use a 2-address form if possible, but
540   /// degrade into a less efficient form if the source and dest register cannot
541   /// be assigned to the same register.  For example, this allows the x86
542   /// backend to turn a "shl reg, 3" instruction into an LEA instruction, which
543   /// is the same speed as the shift but has bigger code size.
544   ///
545   /// If this returns true, then the target must implement the
546   /// TargetInstrInfo::convertToThreeAddress method for this instruction, which
547   /// is allowed to fail if the transformation isn't valid for this specific
548   /// instruction (e.g. shl reg, 4 on x86).
549   ///
550   bool isConvertibleTo3Addr(QueryType Type = IgnoreBundle) const {
551     return hasProperty(MCID::ConvertibleTo3Addr, Type);
552   }
553
554   /// usesCustomInsertionHook - Return true if this instruction requires
555   /// custom insertion support when the DAG scheduler is inserting it into a
556   /// machine basic block.  If this is true for the instruction, it basically
557   /// means that it is a pseudo instruction used at SelectionDAG time that is
558   /// expanded out into magic code by the target when MachineInstrs are formed.
559   ///
560   /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method
561   /// is used to insert this into the MachineBasicBlock.
562   bool usesCustomInsertionHook(QueryType Type = IgnoreBundle) const {
563     return hasProperty(MCID::UsesCustomInserter, Type);
564   }
565
566   /// hasPostISelHook - Return true if this instruction requires *adjustment*
567   /// after instruction selection by calling a target hook. For example, this
568   /// can be used to fill in ARM 's' optional operand depending on whether
569   /// the conditional flag register is used.
570   bool hasPostISelHook(QueryType Type = IgnoreBundle) const {
571     return hasProperty(MCID::HasPostISelHook, Type);
572   }
573
574   /// isRematerializable - Returns true if this instruction is a candidate for
575   /// remat.  This flag is deprecated, please don't use it anymore.  If this
576   /// flag is set, the isReallyTriviallyReMaterializable() method is called to
577   /// verify the instruction is really rematable.
578   bool isRematerializable(QueryType Type = AllInBundle) const {
579     // It's only possible to re-mat a bundle if all bundled instructions are
580     // re-materializable.
581     return hasProperty(MCID::Rematerializable, Type);
582   }
583
584   /// isAsCheapAsAMove - Returns true if this instruction has the same cost (or
585   /// less) than a move instruction. This is useful during certain types of
586   /// optimizations (e.g., remat during two-address conversion or machine licm)
587   /// where we would like to remat or hoist the instruction, but not if it costs
588   /// more than moving the instruction into the appropriate register. Note, we
589   /// are not marking copies from and to the same register class with this flag.
590   bool isAsCheapAsAMove(QueryType Type = AllInBundle) const {
591     // Only returns true for a bundle if all bundled instructions are cheap.
592     // FIXME: This probably requires a target hook.
593     return hasProperty(MCID::CheapAsAMove, Type);
594   }
595
596   /// hasExtraSrcRegAllocReq - Returns true if this instruction source operands
597   /// have special register allocation requirements that are not captured by the
598   /// operand register classes. e.g. ARM::STRD's two source registers must be an
599   /// even / odd pair, ARM::STM registers have to be in ascending order.
600   /// Post-register allocation passes should not attempt to change allocations
601   /// for sources of instructions with this flag.
602   bool hasExtraSrcRegAllocReq(QueryType Type = AnyInBundle) const {
603     return hasProperty(MCID::ExtraSrcRegAllocReq, Type);
604   }
605
606   /// hasExtraDefRegAllocReq - Returns true if this instruction def operands
607   /// have special register allocation requirements that are not captured by the
608   /// operand register classes. e.g. ARM::LDRD's two def registers must be an
609   /// even / odd pair, ARM::LDM registers have to be in ascending order.
610   /// Post-register allocation passes should not attempt to change allocations
611   /// for definitions of instructions with this flag.
612   bool hasExtraDefRegAllocReq(QueryType Type = AnyInBundle) const {
613     return hasProperty(MCID::ExtraDefRegAllocReq, Type);
614   }
615
616
617   enum MICheckType {
618     CheckDefs,      // Check all operands for equality
619     CheckKillDead,  // Check all operands including kill / dead markers
620     IgnoreDefs,     // Ignore all definitions
621     IgnoreVRegDefs  // Ignore virtual register definitions
622   };
623
624   /// isIdenticalTo - Return true if this instruction is identical to (same
625   /// opcode and same operands as) the specified instruction.
626   bool isIdenticalTo(const MachineInstr *Other,
627                      MICheckType Check = CheckDefs) const;
628
629   /// Unlink 'this' from the containing basic block, and return it without
630   /// deleting it.
631   ///
632   /// This function can not be used on bundled instructions, use
633   /// removeFromBundle() to remove individual instructions from a bundle.
634   MachineInstr *removeFromParent();
635
636   /// Unlink this instruction from its basic block and return it without
637   /// deleting it.
638   ///
639   /// If the instruction is part of a bundle, the other instructions in the
640   /// bundle remain bundled.
641   MachineInstr *removeFromBundle();
642
643   /// Unlink 'this' from the containing basic block and delete it.
644   ///
645   /// If this instruction is the header of a bundle, the whole bundle is erased.
646   /// This function can not be used for instructions inside a bundle, use
647   /// eraseFromBundle() to erase individual bundled instructions.
648   void eraseFromParent();
649
650   /// Unlink 'this' form its basic block and delete it.
651   ///
652   /// If the instruction is part of a bundle, the other instructions in the
653   /// bundle remain bundled.
654   void eraseFromBundle();
655
656   bool isEHLabel() const { return getOpcode() == TargetOpcode::EH_LABEL; }
657   bool isGCLabel() const { return getOpcode() == TargetOpcode::GC_LABEL; }
658
659   /// isLabel - Returns true if the MachineInstr represents a label.
660   ///
661   bool isLabel() const { return isEHLabel() || isGCLabel(); }
662   bool isCFIInstruction() const {
663     return getOpcode() == TargetOpcode::CFI_INSTRUCTION;
664   }
665
666   // True if the instruction represents a position in the function.
667   bool isPosition() const { return isLabel() || isCFIInstruction(); }
668
669   bool isDebugValue() const { return getOpcode() == TargetOpcode::DBG_VALUE; }
670   /// A DBG_VALUE is indirect iff the first operand is a register and
671   /// the second operand is an immediate.
672   bool isIndirectDebugValue() const {
673     return isDebugValue()
674       && getOperand(0).isReg()
675       && getOperand(1).isImm();
676   }
677
678   bool isPHI() const { return getOpcode() == TargetOpcode::PHI; }
679   bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
680   bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; }
681   bool isInlineAsm() const { return getOpcode() == TargetOpcode::INLINEASM; }
682   bool isMSInlineAsm() const { 
683     return getOpcode() == TargetOpcode::INLINEASM && getInlineAsmDialect();
684   }
685   bool isStackAligningInlineAsm() const;
686   InlineAsm::AsmDialect getInlineAsmDialect() const;
687   bool isInsertSubreg() const {
688     return getOpcode() == TargetOpcode::INSERT_SUBREG;
689   }
690   bool isSubregToReg() const {
691     return getOpcode() == TargetOpcode::SUBREG_TO_REG;
692   }
693   bool isRegSequence() const {
694     return getOpcode() == TargetOpcode::REG_SEQUENCE;
695   }
696   bool isBundle() const {
697     return getOpcode() == TargetOpcode::BUNDLE;
698   }
699   bool isCopy() const {
700     return getOpcode() == TargetOpcode::COPY;
701   }
702   bool isFullCopy() const {
703     return isCopy() && !getOperand(0).getSubReg() && !getOperand(1).getSubReg();
704   }
705
706   /// isCopyLike - Return true if the instruction behaves like a copy.
707   /// This does not include native copy instructions.
708   bool isCopyLike() const {
709     return isCopy() || isSubregToReg();
710   }
711
712   /// isIdentityCopy - Return true is the instruction is an identity copy.
713   bool isIdentityCopy() const {
714     return isCopy() && getOperand(0).getReg() == getOperand(1).getReg() &&
715       getOperand(0).getSubReg() == getOperand(1).getSubReg();
716   }
717
718   /// isTransient - Return true if this is a transient instruction that is
719   /// either very likely to be eliminated during register allocation (such as
720   /// copy-like instructions), or if this instruction doesn't have an
721   /// execution-time cost.
722   bool isTransient() const {
723     switch(getOpcode()) {
724     default: return false;
725     // Copy-like instructions are usually eliminated during register allocation.
726     case TargetOpcode::PHI:
727     case TargetOpcode::COPY:
728     case TargetOpcode::INSERT_SUBREG:
729     case TargetOpcode::SUBREG_TO_REG:
730     case TargetOpcode::REG_SEQUENCE:
731     // Pseudo-instructions that don't produce any real output.
732     case TargetOpcode::IMPLICIT_DEF:
733     case TargetOpcode::KILL:
734     case TargetOpcode::CFI_INSTRUCTION:
735     case TargetOpcode::EH_LABEL:
736     case TargetOpcode::GC_LABEL:
737     case TargetOpcode::DBG_VALUE:
738       return true;
739     }
740   }
741
742   /// Return the number of instructions inside the MI bundle, excluding the
743   /// bundle header.
744   ///
745   /// This is the number of instructions that MachineBasicBlock::iterator
746   /// skips, 0 for unbundled instructions.
747   unsigned getBundleSize() const;
748
749   /// readsRegister - Return true if the MachineInstr reads the specified
750   /// register. If TargetRegisterInfo is passed, then it also checks if there
751   /// is a read of a super-register.
752   /// This does not count partial redefines of virtual registers as reads:
753   ///   %reg1024:6 = OP.
754   bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
755     return findRegisterUseOperandIdx(Reg, false, TRI) != -1;
756   }
757
758   /// readsVirtualRegister - Return true if the MachineInstr reads the specified
759   /// virtual register. Take into account that a partial define is a
760   /// read-modify-write operation.
761   bool readsVirtualRegister(unsigned Reg) const {
762     return readsWritesVirtualRegister(Reg).first;
763   }
764
765   /// readsWritesVirtualRegister - Return a pair of bools (reads, writes)
766   /// indicating if this instruction reads or writes Reg. This also considers
767   /// partial defines.
768   /// If Ops is not null, all operand indices for Reg are added.
769   std::pair<bool,bool> readsWritesVirtualRegister(unsigned Reg,
770                                       SmallVectorImpl<unsigned> *Ops = 0) const;
771
772   /// killsRegister - Return true if the MachineInstr kills the specified
773   /// register. If TargetRegisterInfo is passed, then it also checks if there is
774   /// a kill of a super-register.
775   bool killsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
776     return findRegisterUseOperandIdx(Reg, true, TRI) != -1;
777   }
778
779   /// definesRegister - Return true if the MachineInstr fully defines the
780   /// specified register. If TargetRegisterInfo is passed, then it also checks
781   /// if there is a def of a super-register.
782   /// NOTE: It's ignoring subreg indices on virtual registers.
783   bool definesRegister(unsigned Reg, const TargetRegisterInfo *TRI=NULL) const {
784     return findRegisterDefOperandIdx(Reg, false, false, TRI) != -1;
785   }
786
787   /// modifiesRegister - Return true if the MachineInstr modifies (fully define
788   /// or partially define) the specified register.
789   /// NOTE: It's ignoring subreg indices on virtual registers.
790   bool modifiesRegister(unsigned Reg, const TargetRegisterInfo *TRI) const {
791     return findRegisterDefOperandIdx(Reg, false, true, TRI) != -1;
792   }
793
794   /// registerDefIsDead - Returns true if the register is dead in this machine
795   /// instruction. If TargetRegisterInfo is passed, then it also checks
796   /// if there is a dead def of a super-register.
797   bool registerDefIsDead(unsigned Reg,
798                          const TargetRegisterInfo *TRI = NULL) const {
799     return findRegisterDefOperandIdx(Reg, true, false, TRI) != -1;
800   }
801
802   /// findRegisterUseOperandIdx() - Returns the operand index that is a use of
803   /// the specific register or -1 if it is not found. It further tightens
804   /// the search criteria to a use that kills the register if isKill is true.
805   int findRegisterUseOperandIdx(unsigned Reg, bool isKill = false,
806                                 const TargetRegisterInfo *TRI = NULL) const;
807
808   /// findRegisterUseOperand - Wrapper for findRegisterUseOperandIdx, it returns
809   /// a pointer to the MachineOperand rather than an index.
810   MachineOperand *findRegisterUseOperand(unsigned Reg, bool isKill = false,
811                                          const TargetRegisterInfo *TRI = NULL) {
812     int Idx = findRegisterUseOperandIdx(Reg, isKill, TRI);
813     return (Idx == -1) ? NULL : &getOperand(Idx);
814   }
815
816   /// findRegisterDefOperandIdx() - Returns the operand index that is a def of
817   /// the specified register or -1 if it is not found. If isDead is true, defs
818   /// that are not dead are skipped. If Overlap is true, then it also looks for
819   /// defs that merely overlap the specified register. If TargetRegisterInfo is
820   /// non-null, then it also checks if there is a def of a super-register.
821   /// This may also return a register mask operand when Overlap is true.
822   int findRegisterDefOperandIdx(unsigned Reg,
823                                 bool isDead = false, bool Overlap = false,
824                                 const TargetRegisterInfo *TRI = NULL) const;
825
826   /// findRegisterDefOperand - Wrapper for findRegisterDefOperandIdx, it returns
827   /// a pointer to the MachineOperand rather than an index.
828   MachineOperand *findRegisterDefOperand(unsigned Reg, bool isDead = false,
829                                          const TargetRegisterInfo *TRI = NULL) {
830     int Idx = findRegisterDefOperandIdx(Reg, isDead, false, TRI);
831     return (Idx == -1) ? NULL : &getOperand(Idx);
832   }
833
834   /// findFirstPredOperandIdx() - Find the index of the first operand in the
835   /// operand list that is used to represent the predicate. It returns -1 if
836   /// none is found.
837   int findFirstPredOperandIdx() const;
838
839   /// findInlineAsmFlagIdx() - Find the index of the flag word operand that
840   /// corresponds to operand OpIdx on an inline asm instruction.  Returns -1 if
841   /// getOperand(OpIdx) does not belong to an inline asm operand group.
842   ///
843   /// If GroupNo is not NULL, it will receive the number of the operand group
844   /// containing OpIdx.
845   ///
846   /// The flag operand is an immediate that can be decoded with methods like
847   /// InlineAsm::hasRegClassConstraint().
848   ///
849   int findInlineAsmFlagIdx(unsigned OpIdx, unsigned *GroupNo = 0) const;
850
851   /// getRegClassConstraint - Compute the static register class constraint for
852   /// operand OpIdx.  For normal instructions, this is derived from the
853   /// MCInstrDesc.  For inline assembly it is derived from the flag words.
854   ///
855   /// Returns NULL if the static register classs constraint cannot be
856   /// determined.
857   ///
858   const TargetRegisterClass*
859   getRegClassConstraint(unsigned OpIdx,
860                         const TargetInstrInfo *TII,
861                         const TargetRegisterInfo *TRI) const;
862
863   /// \brief Applies the constraints (def/use) implied by this MI on \p Reg to
864   /// the given \p CurRC.
865   /// If \p ExploreBundle is set and MI is part of a bundle, all the
866   /// instructions inside the bundle will be taken into account. In other words,
867   /// this method accumulates all the constrains of the operand of this MI and
868   /// the related bundle if MI is a bundle or inside a bundle.
869   ///
870   /// Returns the register class that statisfies both \p CurRC and the
871   /// constraints set by MI. Returns NULL if such a register class does not
872   /// exist.
873   ///
874   /// \pre CurRC must not be NULL.
875   const TargetRegisterClass *getRegClassConstraintEffectForVReg(
876       unsigned Reg, const TargetRegisterClass *CurRC,
877       const TargetInstrInfo *TII, const TargetRegisterInfo *TRI,
878       bool ExploreBundle = false) const;
879
880   /// \brief Applies the constraints (def/use) implied by the \p OpIdx operand
881   /// to the given \p CurRC.
882   ///
883   /// Returns the register class that statisfies both \p CurRC and the
884   /// constraints set by \p OpIdx MI. Returns NULL if such a register class
885   /// does not exist.
886   ///
887   /// \pre CurRC must not be NULL.
888   /// \pre The operand at \p OpIdx must be a register.
889   const TargetRegisterClass *
890   getRegClassConstraintEffect(unsigned OpIdx, const TargetRegisterClass *CurRC,
891                               const TargetInstrInfo *TII,
892                               const TargetRegisterInfo *TRI) const;
893
894   /// tieOperands - Add a tie between the register operands at DefIdx and
895   /// UseIdx. The tie will cause the register allocator to ensure that the two
896   /// operands are assigned the same physical register.
897   ///
898   /// Tied operands are managed automatically for explicit operands in the
899   /// MCInstrDesc. This method is for exceptional cases like inline asm.
900   void tieOperands(unsigned DefIdx, unsigned UseIdx);
901
902   /// findTiedOperandIdx - Given the index of a tied register operand, find the
903   /// operand it is tied to. Defs are tied to uses and vice versa. Returns the
904   /// index of the tied operand which must exist.
905   unsigned findTiedOperandIdx(unsigned OpIdx) const;
906
907   /// isRegTiedToUseOperand - Given the index of a register def operand,
908   /// check if the register def is tied to a source operand, due to either
909   /// two-address elimination or inline assembly constraints. Returns the
910   /// first tied use operand index by reference if UseOpIdx is not null.
911   bool isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx = 0) const {
912     const MachineOperand &MO = getOperand(DefOpIdx);
913     if (!MO.isReg() || !MO.isDef() || !MO.isTied())
914       return false;
915     if (UseOpIdx)
916       *UseOpIdx = findTiedOperandIdx(DefOpIdx);
917     return true;
918   }
919
920   /// isRegTiedToDefOperand - Return true if the use operand of the specified
921   /// index is tied to an def operand. It also returns the def operand index by
922   /// reference if DefOpIdx is not null.
923   bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx = 0) const {
924     const MachineOperand &MO = getOperand(UseOpIdx);
925     if (!MO.isReg() || !MO.isUse() || !MO.isTied())
926       return false;
927     if (DefOpIdx)
928       *DefOpIdx = findTiedOperandIdx(UseOpIdx);
929     return true;
930   }
931
932   /// clearKillInfo - Clears kill flags on all operands.
933   ///
934   void clearKillInfo();
935
936   /// substituteRegister - Replace all occurrences of FromReg with ToReg:SubIdx,
937   /// properly composing subreg indices where necessary.
938   void substituteRegister(unsigned FromReg, unsigned ToReg, unsigned SubIdx,
939                           const TargetRegisterInfo &RegInfo);
940
941   /// addRegisterKilled - We have determined MI kills a register. Look for the
942   /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
943   /// add a implicit operand if it's not found. Returns true if the operand
944   /// exists / is added.
945   bool addRegisterKilled(unsigned IncomingReg,
946                          const TargetRegisterInfo *RegInfo,
947                          bool AddIfNotFound = false);
948
949   /// clearRegisterKills - Clear all kill flags affecting Reg.  If RegInfo is
950   /// provided, this includes super-register kills.
951   void clearRegisterKills(unsigned Reg, const TargetRegisterInfo *RegInfo);
952
953   /// addRegisterDead - We have determined MI defined a register without a use.
954   /// Look for the operand that defines it and mark it as IsDead. If
955   /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
956   /// true if the operand exists / is added.
957   bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo,
958                        bool AddIfNotFound = false);
959
960   /// addRegisterDefined - We have determined MI defines a register. Make sure
961   /// there is an operand defining Reg.
962   void addRegisterDefined(unsigned Reg, const TargetRegisterInfo *RegInfo = 0);
963
964   /// setPhysRegsDeadExcept - Mark every physreg used by this instruction as
965   /// dead except those in the UsedRegs list.
966   ///
967   /// On instructions with register mask operands, also add implicit-def
968   /// operands for all registers in UsedRegs.
969   void setPhysRegsDeadExcept(ArrayRef<unsigned> UsedRegs,
970                              const TargetRegisterInfo &TRI);
971
972   /// isSafeToMove - Return true if it is safe to move this instruction. If
973   /// SawStore is set to true, it means that there is a store (or call) between
974   /// the instruction's location and its intended destination.
975   bool isSafeToMove(const TargetInstrInfo *TII, AliasAnalysis *AA,
976                     bool &SawStore) const;
977
978   /// hasOrderedMemoryRef - Return true if this instruction may have an ordered
979   /// or volatile memory reference, or if the information describing the memory
980   /// reference is not available. Return false if it is known to have no
981   /// ordered or volatile memory references.
982   bool hasOrderedMemoryRef() const;
983
984   /// isInvariantLoad - Return true if this instruction is loading from a
985   /// location whose value is invariant across the function.  For example,
986   /// loading a value from the constant pool or from the argument area of
987   /// a function if it does not change.  This should only return true of *all*
988   /// loads the instruction does are invariant (if it does multiple loads).
989   bool isInvariantLoad(AliasAnalysis *AA) const;
990
991   /// isConstantValuePHI - If the specified instruction is a PHI that always
992   /// merges together the same virtual register, return the register, otherwise
993   /// return 0.
994   unsigned isConstantValuePHI() const;
995
996   /// hasUnmodeledSideEffects - Return true if this instruction has side
997   /// effects that are not modeled by mayLoad / mayStore, etc.
998   /// For all instructions, the property is encoded in MCInstrDesc::Flags
999   /// (see MCInstrDesc::hasUnmodeledSideEffects(). The only exception is
1000   /// INLINEASM instruction, in which case the side effect property is encoded
1001   /// in one of its operands (see InlineAsm::Extra_HasSideEffect).
1002   ///
1003   bool hasUnmodeledSideEffects() const;
1004
1005   /// allDefsAreDead - Return true if all the defs of this instruction are dead.
1006   ///
1007   bool allDefsAreDead() const;
1008
1009   /// copyImplicitOps - Copy implicit register operands from specified
1010   /// instruction to this instruction.
1011   void copyImplicitOps(MachineFunction &MF, const MachineInstr *MI);
1012
1013   //
1014   // Debugging support
1015   //
1016   void print(raw_ostream &OS, const TargetMachine *TM = 0,
1017              bool SkipOpers = false) const;
1018   void dump() const;
1019
1020   //===--------------------------------------------------------------------===//
1021   // Accessors used to build up machine instructions.
1022
1023   /// Add the specified operand to the instruction.  If it is an implicit
1024   /// operand, it is added to the end of the operand list.  If it is an
1025   /// explicit operand it is added at the end of the explicit operand list
1026   /// (before the first implicit operand).
1027   ///
1028   /// MF must be the machine function that was used to allocate this
1029   /// instruction.
1030   ///
1031   /// MachineInstrBuilder provides a more convenient interface for creating
1032   /// instructions and adding operands.
1033   void addOperand(MachineFunction &MF, const MachineOperand &Op);
1034
1035   /// Add an operand without providing an MF reference. This only works for
1036   /// instructions that are inserted in a basic block.
1037   ///
1038   /// MachineInstrBuilder and the two-argument addOperand(MF, MO) should be
1039   /// preferred.
1040   void addOperand(const MachineOperand &Op);
1041
1042   /// setDesc - Replace the instruction descriptor (thus opcode) of
1043   /// the current instruction with a new one.
1044   ///
1045   void setDesc(const MCInstrDesc &tid) { MCID = &tid; }
1046
1047   /// setDebugLoc - Replace current source information with new such.
1048   /// Avoid using this, the constructor argument is preferable.
1049   ///
1050   void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
1051
1052   /// RemoveOperand - Erase an operand  from an instruction, leaving it with one
1053   /// fewer operand than it started with.
1054   ///
1055   void RemoveOperand(unsigned i);
1056
1057   /// addMemOperand - Add a MachineMemOperand to the machine instruction.
1058   /// This function should be used only occasionally. The setMemRefs function
1059   /// is the primary method for setting up a MachineInstr's MemRefs list.
1060   void addMemOperand(MachineFunction &MF, MachineMemOperand *MO);
1061
1062   /// setMemRefs - Assign this MachineInstr's memory reference descriptor
1063   /// list. This does not transfer ownership.
1064   void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
1065     MemRefs = NewMemRefs;
1066     NumMemRefs = uint8_t(NewMemRefsEnd - NewMemRefs);
1067     assert(NumMemRefs == NewMemRefsEnd - NewMemRefs && "Too many memrefs");
1068   }
1069
1070 private:
1071   /// getRegInfo - If this instruction is embedded into a MachineFunction,
1072   /// return the MachineRegisterInfo object for the current function, otherwise
1073   /// return null.
1074   MachineRegisterInfo *getRegInfo();
1075
1076   /// untieRegOperand - Break any tie involving OpIdx.
1077   void untieRegOperand(unsigned OpIdx) {
1078     MachineOperand &MO = getOperand(OpIdx);
1079     if (MO.isReg() && MO.isTied()) {
1080       getOperand(findTiedOperandIdx(OpIdx)).TiedTo = 0;
1081       MO.TiedTo = 0;
1082     }
1083   }
1084
1085   /// addImplicitDefUseOperands - Add all implicit def and use operands to
1086   /// this instruction.
1087   void addImplicitDefUseOperands(MachineFunction &MF);
1088
1089   /// RemoveRegOperandsFromUseLists - Unlink all of the register operands in
1090   /// this instruction from their respective use lists.  This requires that the
1091   /// operands already be on their use lists.
1092   void RemoveRegOperandsFromUseLists(MachineRegisterInfo&);
1093
1094   /// AddRegOperandsToUseLists - Add all of the register operands in
1095   /// this instruction from their respective use lists.  This requires that the
1096   /// operands not be on their use lists yet.
1097   void AddRegOperandsToUseLists(MachineRegisterInfo&);
1098
1099   /// hasPropertyInBundle - Slow path for hasProperty when we're dealing with a
1100   /// bundle.
1101   bool hasPropertyInBundle(unsigned Mask, QueryType Type) const;
1102
1103   /// \brief Implements the logic of getRegClassConstraintEffectForVReg for the
1104   /// this MI and the given operand index \p OpIdx.
1105   /// If the related operand does not constrained Reg, this returns CurRC.
1106   const TargetRegisterClass *getRegClassConstraintEffectForVRegImpl(
1107       unsigned OpIdx, unsigned Reg, const TargetRegisterClass *CurRC,
1108       const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const;
1109 };
1110
1111 /// MachineInstrExpressionTrait - Special DenseMapInfo traits to compare
1112 /// MachineInstr* by *value* of the instruction rather than by pointer value.
1113 /// The hashing and equality testing functions ignore definitions so this is
1114 /// useful for CSE, etc.
1115 struct MachineInstrExpressionTrait : DenseMapInfo<MachineInstr*> {
1116   static inline MachineInstr *getEmptyKey() {
1117     return 0;
1118   }
1119
1120   static inline MachineInstr *getTombstoneKey() {
1121     return reinterpret_cast<MachineInstr*>(-1);
1122   }
1123
1124   static unsigned getHashValue(const MachineInstr* const &MI);
1125
1126   static bool isEqual(const MachineInstr* const &LHS,
1127                       const MachineInstr* const &RHS) {
1128     if (RHS == getEmptyKey() || RHS == getTombstoneKey() ||
1129         LHS == getEmptyKey() || LHS == getTombstoneKey())
1130       return LHS == RHS;
1131     return LHS->isIdenticalTo(RHS, MachineInstr::IgnoreVRegDefs);
1132   }
1133 };
1134
1135 //===----------------------------------------------------------------------===//
1136 // Debugging Support
1137
1138 inline raw_ostream& operator<<(raw_ostream &OS, const MachineInstr &MI) {
1139   MI.print(OS);
1140   return OS;
1141 }
1142
1143 } // End llvm namespace
1144
1145 #endif