MachineInstr.h revision 699ac049517285d978ed607b2735976c5ae97ac0
148486893f46d2e12e926682a3ecb908716bc66c4Chris Lattner//===-- llvm/CodeGen/MachineInstr.h - MachineInstr class --------*- C++ -*-===//
2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9a730c864227b287cdfad5f5f3d5d0808c9f422bbChris Lattner//
10a730c864227b287cdfad5f5f3d5d0808c9f422bbChris Lattner// This file contains the declaration of the MachineInstr class, which is the
11ef6a6a69ff1e1b709d0acb315b9f6c926c67a778Misha Brukman// basic representation for all target dependent machine instructions used by
12a730c864227b287cdfad5f5f3d5d0808c9f422bbChris Lattner// the back end.
13a730c864227b287cdfad5f5f3d5d0808c9f422bbChris Lattner//
14a730c864227b287cdfad5f5f3d5d0808c9f422bbChris Lattner//===----------------------------------------------------------------------===//
1523ee550765232e22d0daf6407141ecef4c55c06fVikram S. Adve
1623ee550765232e22d0daf6407141ecef4c55c06fVikram S. Adve#ifndef LLVM_CODEGEN_MACHINEINSTR_H
1723ee550765232e22d0daf6407141ecef4c55c06fVikram S. Adve#define LLVM_CODEGEN_MACHINEINSTR_H
1823ee550765232e22d0daf6407141ecef4c55c06fVikram S. Adve
19103a64318bb716d68a4248996466900411d789beChris Lattner#include "llvm/CodeGen/MachineOperand.h"
20e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng#include "llvm/MC/MCInstrDesc.h"
21518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner#include "llvm/Target/TargetOpcodes.h"
22a37818dbb119bda75273f16b8484732e742cdbb7Jakob Stoklund Olesen#include "llvm/ADT/ArrayRef.h"
2384e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner#include "llvm/ADT/ilist.h"
2484e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner#include "llvm/ADT/ilist_node.h"
2584e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner#include "llvm/ADT/STLExtras.h"
26d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen#include "llvm/ADT/StringRef.h"
2784e679beea11ac55ed7871eec4deaccdf393de3eChris Lattner#include "llvm/ADT/DenseMapInfo.h"
281e86a66b00b94adc4ad6977ef6b47c516ac62cecDevang Patel#include "llvm/Support/DebugLoc.h"
291baa88e3de8947b02d9ef4caa73e5860f048ec6eDan Gohman#include <vector>
30be583b914d8156b99d3da264d5adca37fee8dbc9John Criswell
31d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
32d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
3318b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesentemplate <typename T> class SmallVectorImpl;
34e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohmanclass AliasAnalysis;
35b27087f5aa574f875598f4a309b7dd687c64a455Evan Chengclass TargetInstrInfo;
36f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesenclass TargetRegisterClass;
376f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohmanclass TargetRegisterInfo;
388e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohmanclass MachineFunction;
39c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohmanclass MachineMemOperand;
40c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos
41b05497e0ca1ba2e7f57b792cc160e5d1c8579582Chris Lattner//===----------------------------------------------------------------------===//
428b915b4ed2c6e43413937ac71c0cbcf476ad1a98Chris Lattner/// MachineInstr - Representation of each machine instruction.
438b915b4ed2c6e43413937ac71c0cbcf476ad1a98Chris Lattner///
44fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineInstr : public ilist_node<MachineInstr> {
45c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohmanpublic:
46c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  typedef MachineMemOperand **mmo_iterator;
47c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman
4845282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  /// Flags to specify different kinds of comments to output in
4945282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  /// assembly code.  These flags carry semantic information not
5045282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  /// otherwise easily derivable from the IR text.
5145282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  ///
5245282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  enum CommentFlag {
5345282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner    ReloadReuse = 0x1
5445282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  };
556dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
566dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  enum MIFlag {
577c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    NoFlags      = 0,
587c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    FrameSetup   = 1 << 0,              // Instruction is used as a part of
596dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov                                        // function frame setup code.
607c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    InsideBundle = 1 << 1               // Instruction is inside a bundle (not
617c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng                                        // the first MI in a bundle)
626dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  };
63c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohmanprivate:
64e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  const MCInstrDesc *MCID;              // Instruction descriptor.
659a00279988612d0f960fb8d43e4ccfcab89e0e14Evan Cheng
666dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  uint8_t Flags;                        // Various bits of additional
676dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov                                        // information about machine
686dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov                                        // instruction.
696dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
706647b59c9263eb1decd7f7ff353c0c99ec09ae6cAnton Korobeynikov  uint8_t AsmPrinterFlags;              // Various bits of information used by
711251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // the AsmPrinter to emit helpful
721251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // comments.  This is *not* semantic
731251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // information.  Do not use this for
741251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // anything other than to convey comment
751251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // information to AsmPrinter.
761251443929a256c833717e1030c368d3b6e4cb7cDavid Greene
77861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer  uint16_t NumMemRefs;                  // information on memory references
78861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer  mmo_iterator MemRefs;
79861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer
80943b5e117fe9a087f9aa529a2632c2d32cc22374Chris Lattner  std::vector<MachineOperand> Operands; // the operands
81f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  MachineBasicBlock *Parent;            // Pointer to the owning basic block.
8206efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  DebugLoc debugLoc;                    // Source line information.
83c54839573cd9ffa6af33dc5190cc40d498534585Brian Gaeke
848e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineInstr(const MachineInstr&);   // DO NOT IMPLEMENT
859452b0797a80001920576d7e2ef4af05242cba69Chris Lattner  void operator=(const MachineInstr&); // DO NOT IMPLEMENT
86c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos
87c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos  // Intrusive list support
88fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  friend struct ilist_traits<MachineInstr>;
89fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  friend struct ilist_traits<MachineBasicBlock>;
90f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  void setParent(MachineBasicBlock *P) { Parent = P; }
918e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
928e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// MachineInstr ctor - This constructor creates a copy of the given
938e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// MachineInstr in the given MachineFunction.
948e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineInstr(MachineFunction &, const MachineInstr &);
958e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
96c0f64ffab93d11fb27a3b8a0707b77400918a20eEvan Cheng  /// MachineInstr ctor - This constructor creates a dummy MachineInstr with
97e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// MCID NULL and no operands.
98c0f64ffab93d11fb27a3b8a0707b77400918a20eEvan Cheng  MachineInstr();
99e8b57ef2603ed522083dc18e559ca4e20abf22aeVikram S. Adve
10006efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  // The next two constructors have DebugLoc and non-DebugLoc versions;
10106efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  // over time, the non-DebugLoc versions should be phased out and eventually
10206efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  // removed.
10306efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
104666f8cb9b7486a45f59fd9ba3202e4b67dbad58cBob Wilson  /// MachineInstr ctor - This constructor creates a MachineInstr and adds the
105666f8cb9b7486a45f59fd9ba3202e4b67dbad58cBob Wilson  /// implicit operands.  It reserves space for the number of operands specified
106e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// by the MCInstrDesc.  The version with a DebugLoc should be preferred.
107e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  explicit MachineInstr(const MCInstrDesc &MCID, bool NoImp = false);
108d7de496b23fca8145f777a56281457bf64e8bbadEvan Cheng
1097db458fb0768059f050d3a0f1a26818fa8e22712Chris Lattner  /// MachineInstr ctor - Work exactly the same as the ctor above, except that
1107db458fb0768059f050d3a0f1a26818fa8e22712Chris Lattner  /// the MachineInstr is created and added to the end of the specified basic
11106efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// block.  The version with a DebugLoc should be preferred.
112e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  MachineInstr(MachineBasicBlock *MBB, const MCInstrDesc &MCID);
113ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
11406efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// MachineInstr ctor - This constructor create a MachineInstr and add the
11506efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// implicit operands.  It reserves space for number of operands specified by
116e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// MCInstrDesc.  An explicit DebugLoc is supplied.
117e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  explicit MachineInstr(const MCInstrDesc &MCID, const DebugLoc dl,
11806efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen                        bool NoImp = false);
11906efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
12006efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// MachineInstr ctor - Work exactly the same as the ctor above, except that
12106efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// the MachineInstr is created and added to the end of the specified basic
12206efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// block.
123108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach  MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl,
124e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng               const MCInstrDesc &MCID);
12506efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
126aad5c0505183a5b7913f1a443a1f0650122551ccAlkis Evlogimenos  ~MachineInstr();
127aad5c0505183a5b7913f1a443a1f0650122551ccAlkis Evlogimenos
1288e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // MachineInstrs are pool-allocated and owned by MachineFunction.
1298e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  friend class MachineFunction;
1308e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
1318e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohmanpublic:
132f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  const MachineBasicBlock* getParent() const { return Parent; }
133f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  MachineBasicBlock* getParent() { return Parent; }
13406efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
1351251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  /// getAsmPrinterFlags - Return the asm printer flags bitvector.
1361251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  ///
1376647b59c9263eb1decd7f7ff353c0c99ec09ae6cAnton Korobeynikov  uint8_t getAsmPrinterFlags() const { return AsmPrinterFlags; }
1381251443929a256c833717e1030c368d3b6e4cb7cDavid Greene
139cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  /// clearAsmPrinterFlags - clear the AsmPrinter bitvector
140cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  ///
141cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  void clearAsmPrinterFlags() { AsmPrinterFlags = 0; }
142108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
1431251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  /// getAsmPrinterFlag - Return whether an AsmPrinter flag is set.
1441251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  ///
14545282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  bool getAsmPrinterFlag(CommentFlag Flag) const {
1461251443929a256c833717e1030c368d3b6e4cb7cDavid Greene    return AsmPrinterFlags & Flag;
1471251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  }
1481251443929a256c833717e1030c368d3b6e4cb7cDavid Greene
1491251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  /// setAsmPrinterFlag - Set a flag for the AsmPrinter.
1501251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  ///
15145282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  void setAsmPrinterFlag(CommentFlag Flag) {
1526dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    AsmPrinterFlags |= (uint8_t)Flag;
1536dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  }
1546dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
1557c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// clearAsmPrinterFlag - clear specific AsmPrinter flags
1567c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///
1577c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  void clearAsmPrinterFlag(CommentFlag Flag) {
1587c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    AsmPrinterFlags &= ~Flag;
1597c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  }
1607c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng
1616dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  /// getFlags - Return the MI flags bitvector.
1626dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  uint8_t getFlags() const {
1636dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    return Flags;
1646dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  }
1656dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
1666dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  /// getFlag - Return whether an MI flag is set.
1676dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  bool getFlag(MIFlag Flag) const {
1686dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    return Flags & Flag;
1696dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  }
1706dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
1716dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  /// setFlag - Set a MI flag.
1726dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  void setFlag(MIFlag Flag) {
1736dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    Flags |= (uint8_t)Flag;
1746dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  }
1756dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
1766dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  void setFlags(unsigned flags) {
1776dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    Flags = flags;
1781251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  }
179108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
180ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  /// clearFlag - Clear a MI flag.
181ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  void clearFlag(MIFlag Flag) {
182ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng    Flags &= ~((uint8_t)Flag);
183ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  }
184ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng
1857c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// isInsideBundle - Return true if MI is in a bundle (but not the first MI
1867c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// in a bundle).
187cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  ///
1887c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// A bundle looks like this before it's finalized:
1897c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
1907c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   |      MI      |
1917c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
1927c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
1937c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
194b3aacdd358052ddd8d9fc9ac77f5e17a4048941aAndrew Trick  ///   |      MI    * |
1957c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
1967c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
1977c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
198b3aacdd358052ddd8d9fc9ac77f5e17a4048941aAndrew Trick  ///   |      MI    * |
1997c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2007c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// In this case, the first MI starts a bundle but is not inside a bundle, the
2017c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// next 2 MIs are considered "inside" the bundle.
2027c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///
2037c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// After a bundle is finalized, it looks like this:
2047c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2057c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   |    Bundle    |
2067c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2077c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
2087c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2097c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   |      MI    * |
2107c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2117c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
2127c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
213b3aacdd358052ddd8d9fc9ac77f5e17a4048941aAndrew Trick  ///   |      MI    * |
2147c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2157c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
2167c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
217b3aacdd358052ddd8d9fc9ac77f5e17a4048941aAndrew Trick  ///   |      MI    * |
2187c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2197c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// The first instruction has the special opcode "BUNDLE". It's not "inside"
2207c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// a bundle, but the next three MIs are.
2217c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  bool isInsideBundle() const {
2227c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    return getFlag(InsideBundle);
223cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  }
2241251443929a256c833717e1030c368d3b6e4cb7cDavid Greene
225ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  /// setIsInsideBundle - Set InsideBundle bit.
226ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  ///
227ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  void setIsInsideBundle(bool Val = true) {
228ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng    if (Val)
229ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng      setFlag(InsideBundle);
230ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng    else
231ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng      clearFlag(InsideBundle);
232ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  }
233ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng
23499a7a13f4aa5bf8f272c95f7b09ba997d2b30a35Andrew Trick  /// isBundled - Return true if this instruction part of a bundle. This is true
23599a7a13f4aa5bf8f272c95f7b09ba997d2b30a35Andrew Trick  /// if either itself or its following instruction is marked "InsideBundle".
23699a7a13f4aa5bf8f272c95f7b09ba997d2b30a35Andrew Trick  bool isBundled() const;
23799a7a13f4aa5bf8f272c95f7b09ba997d2b30a35Andrew Trick
23806efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// getDebugLoc - Returns the debug location id of this MachineInstr.
23906efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  ///
240d5fb7906130989a579d1bfe4490b414331e94feeChris Lattner  DebugLoc getDebugLoc() const { return debugLoc; }
2416dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
242d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// emitError - Emit an error referring to the source location of this
243d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// instruction. This should only be used for inline assembly that is somehow
244d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// impossible to compile. Other errors should have been handled much
245d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// earlier.
246d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  ///
247d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// If this method returns, the caller should try to recover from the error.
248d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  ///
249d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  void emitError(StringRef Msg) const;
250d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen
25169244300b8a0112efb44b6273ecea4ca6264b8cfChris Lattner  /// getDesc - Returns the target instruction descriptor of this
25267f660cb080965ea93ed6d7265a67100f2fe38e4Evan Cheng  /// MachineInstr.
253e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  const MCInstrDesc &getDesc() const { return *MCID; }
254ab8672c8bb83e722b856eac67863542ea7e0cbb2Alkis Evlogimenos
255c54839573cd9ffa6af33dc5190cc40d498534585Brian Gaeke  /// getOpcode - Returns the opcode of this MachineInstr.
256cd0b3a90aa34bd42d75d8d86f74ca4972145781dBrian Gaeke  ///
257e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  int getOpcode() const { return MCID->Opcode; }
2589f495b54fa94dba4e0be59ba9736c7cf18d996d9Vikram S. Adve
259cd0b3a90aa34bd42d75d8d86f74ca4972145781dBrian Gaeke  /// Access to explicit operands of the instruction.
260cd0b3a90aa34bd42d75d8d86f74ca4972145781dBrian Gaeke  ///
26134cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  unsigned getNumOperands() const { return (unsigned)Operands.size(); }
262ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
263572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  const MachineOperand& getOperand(unsigned i) const {
264a2bae305fb5a870c4ef753ed290a7ddea73ec82bVikram S. Adve    assert(i < getNumOperands() && "getOperand() out of range!");
265943b5e117fe9a087f9aa529a2632c2d32cc22374Chris Lattner    return Operands[i];
266572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  }
267572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  MachineOperand& getOperand(unsigned i) {
268a2bae305fb5a870c4ef753ed290a7ddea73ec82bVikram S. Adve    assert(i < getNumOperands() && "getOperand() out of range!");
269943b5e117fe9a087f9aa529a2632c2d32cc22374Chris Lattner    return Operands[i];
270572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  }
2716d6c3f86186333037f2fd3fb001e8b2998c080d9Chris Lattner
27219e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  /// getNumExplicitOperands - Returns the number of non-implicit operands.
27319e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  ///
27419e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  unsigned getNumExplicitOperands() const;
275ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner
276ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  /// iterator/begin/end - Iterate over all operands of a machine instruction.
277ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  typedef std::vector<MachineOperand>::iterator mop_iterator;
278ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  typedef std::vector<MachineOperand>::const_iterator const_mop_iterator;
279ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner
280ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  mop_iterator operands_begin() { return Operands.begin(); }
281ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  mop_iterator operands_end() { return Operands.end(); }
282ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner
283ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  const_mop_iterator operands_begin() const { return Operands.begin(); }
284ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  const_mop_iterator operands_end() const { return Operands.end(); }
285ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner
28669de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  /// Access to memory operands of the instruction
287c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  mmo_iterator memoperands_begin() const { return MemRefs; }
288861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer  mmo_iterator memoperands_end() const { return MemRefs + NumMemRefs; }
289861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer  bool memoperands_empty() const { return NumMemRefs == 0; }
29069de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
291cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman  /// hasOneMemOperand - Return true if this instruction has exactly one
292cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman  /// MachineMemOperand.
293cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman  bool hasOneMemOperand() const {
294861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer    return NumMemRefs == 1;
295cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman  }
296cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman
2975a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// API for querying MachineInstr properties. They are the same as MCInstrDesc
2985a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// queries but they are bundle aware.
2995a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
30043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  enum QueryType {
30143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    IgnoreBundle,    // Ignore bundles
30243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    AnyInBundle,     // Return true if any instruction in bundle has property
30343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    AllInBundle      // Return true if all instructions in bundle have property
30443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  };
30543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng
3065a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasProperty - Return true if the instruction (or in the case of a bundle,
3075a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// the instructions inside the bundle) has the specified property.
3085a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// The first argument is the property being queried.
3095a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// The second argument indicates whether the query should look inside
3105a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instruction bundles.
31185f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  bool hasProperty(unsigned MCFlag, QueryType Type = AnyInBundle) const {
31285f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer    // Inline the fast path.
31385f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer    if (Type == IgnoreBundle || !isBundle())
31485f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer      return getDesc().getFlags() & (1 << MCFlag);
31585f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer
31685f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer    // If we have a bundle, take the slow path.
31785f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer    return hasPropertyInBundle(1 << MCFlag, Type);
31885f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  }
3195a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3205a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isVariadic - Return true if this instruction can have a variable number of
3215a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// operands.  In this case, the variable operands will be after the normal
3225a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// operands but before the implicit definitions and uses (if any are
3235a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// present).
32443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isVariadic(QueryType Type = IgnoreBundle) const {
32543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Variadic, Type);
3265a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3275a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3285a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasOptionalDef - Set if this instruction has an optional definition, e.g.
3295a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// ARM instructions which can set condition code if 's' bit is set.
33043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasOptionalDef(QueryType Type = IgnoreBundle) const {
33143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::HasOptionalDef, Type);
3325a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3335a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3345a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isPseudo - Return true if this is a pseudo instruction that doesn't
3355a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// correspond to a real machine instruction.
3367c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///
33743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isPseudo(QueryType Type = IgnoreBundle) const {
33843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Pseudo, Type);
3395a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3405a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
34143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isReturn(QueryType Type = AnyInBundle) const {
34243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Return, Type);
3435a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3445a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
34543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isCall(QueryType Type = AnyInBundle) const {
34643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Call, Type);
3475a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3485a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3495a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isBarrier - Returns true if the specified instruction stops control flow
3505a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// from executing the instruction immediately following it.  Examples include
3515a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// unconditional branches and return instructions.
35243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isBarrier(QueryType Type = AnyInBundle) const {
35343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Barrier, Type);
3545a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3557c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng
3565a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isTerminator - Returns true if this instruction part of the terminator for
3575a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// a basic block.  Typically this is things like return and branch
3585a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instructions.
3595a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
3605a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Various passes use this to insert code into the bottom of a basic block,
3615a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// but before control flow occurs.
36243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isTerminator(QueryType Type = AnyInBundle) const {
36343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Terminator, Type);
3647c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  }
3657c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng
3665a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isBranch - Returns true if this is a conditional, unconditional, or
3675a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// indirect branch.  Predicates below can be used to discriminate between
3685a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// these cases, and the TargetInstrInfo::AnalyzeBranch method can be used to
3695a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// get more information.
37043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isBranch(QueryType Type = AnyInBundle) const {
37143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Branch, Type);
3725a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3735a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3745a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isIndirectBranch - Return true if this is an indirect branch, such as a
3755a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// branch through a register.
37643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isIndirectBranch(QueryType Type = AnyInBundle) const {
37743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::IndirectBranch, Type);
3785a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3795a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3805a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isConditionalBranch - Return true if this is a branch which may fall
3815a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// through to the next instruction or may transfer control flow to some other
3825a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// block.  The TargetInstrInfo::AnalyzeBranch method can be used to get more
3835a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// information about this branch.
38443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isConditionalBranch(QueryType Type = AnyInBundle) const {
38543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return isBranch(Type) & !isBarrier(Type) & !isIndirectBranch(Type);
3865a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3875a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3885a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isUnconditionalBranch - Return true if this is a branch which always
3895a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// transfers control flow to some other block.  The
3905a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// TargetInstrInfo::AnalyzeBranch method can be used to get more information
3915a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// about this branch.
39243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isUnconditionalBranch(QueryType Type = AnyInBundle) const {
39343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return isBranch(Type) & isBarrier(Type) & !isIndirectBranch(Type);
3945a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3955a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3965a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  // isPredicable - Return true if this instruction has a predicate operand that
3975a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  // controls execution.  It may be set to 'always', or may be set to other
3985a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// values.   There are various methods in TargetInstrInfo that can be used to
3995a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// control and modify the predicate in this instruction.
40043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isPredicable(QueryType Type = AllInBundle) const {
4015a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // If it's a bundle than all bundled instructions must be predicable for this
4025a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // to return true.
40343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Predicable, Type);
4045a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4055a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4065a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isCompare - Return true if this instruction is a comparison.
40743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isCompare(QueryType Type = IgnoreBundle) const {
40843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Compare, Type);
4095a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4105a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4115a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isMoveImmediate - Return true if this instruction is a move immediate
4125a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// (including conditional moves) instruction.
41343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isMoveImmediate(QueryType Type = IgnoreBundle) const {
41443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::MoveImm, Type);
4155a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4165a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4175a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isBitcast - Return true if this instruction is a bitcast instruction.
4185a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
41943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isBitcast(QueryType Type = IgnoreBundle) const {
42043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Bitcast, Type);
4215a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4225a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
423f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen  /// isSelect - Return true if this instruction is a select instruction.
424f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen  ///
425f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen  bool isSelect(QueryType Type = IgnoreBundle) const {
426f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen    return hasProperty(MCID::Select, Type);
427f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen  }
428f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen
4295a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isNotDuplicable - Return true if this instruction cannot be safely
4305a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// duplicated.  For example, if the instruction has a unique labels attached
4315a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// to it, duplicating it would cause multiple definition errors.
43243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isNotDuplicable(QueryType Type = AnyInBundle) const {
43343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::NotDuplicable, Type);
4345a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4355a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4365a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasDelaySlot - Returns true if the specified instruction has a delay slot
4375a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// which must be filled by the code generator.
43843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasDelaySlot(QueryType Type = AnyInBundle) const {
43943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::DelaySlot, Type);
4405a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4415a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4425a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// canFoldAsLoad - Return true for instructions that can be folded as
4435a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// memory operands in other instructions. The most common use for this
4445a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// is instructions that are simple loads from memory that don't modify
4455a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// the loaded value in any way, but it can also be used for instructions
4465a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// that can be expressed as constant-pool loads, such as V_SETALLONES
4475a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// on x86, to allow them to be folded when it is beneficial.
4485a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// This should only be set on instructions that return a value in their
4495a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// only virtual register definition.
45043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool canFoldAsLoad(QueryType Type = IgnoreBundle) const {
45143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::FoldableAsLoad, Type);
4525a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4535a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4545a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  //===--------------------------------------------------------------------===//
4555a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  // Side Effect Analysis
4565a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  //===--------------------------------------------------------------------===//
4575a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4585a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// mayLoad - Return true if this instruction could possibly read memory.
4595a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Instructions with this flag set are not necessarily simple load
4605a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instructions, they may load a value and modify it, for example.
46143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool mayLoad(QueryType Type = AnyInBundle) const {
46243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::MayLoad, Type);
4635a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4645a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4655a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4665a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// mayStore - Return true if this instruction could possibly modify memory.
4675a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Instructions with this flag set are not necessarily simple store
4685a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instructions, they may store a modified value based on their operands, or
4695a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// may not actually modify anything, for example.
47043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool mayStore(QueryType Type = AnyInBundle) const {
47143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::MayStore, Type);
4725a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4735a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4745a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  //===--------------------------------------------------------------------===//
4755a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  // Flags that indicate whether an instruction can be modified by a method.
4765a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  //===--------------------------------------------------------------------===//
4775a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4785a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isCommutable - Return true if this may be a 2- or 3-address
4795a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instruction (of the form "X = op Y, Z, ..."), which produces the same
4805a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// result if Y and Z are exchanged.  If this flag is set, then the
4815a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// TargetInstrInfo::commuteInstruction method may be used to hack on the
4825a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instruction.
4835a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
4845a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Note that this flag may be set on instructions that are only commutable
4855a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// sometimes.  In these cases, the call to commuteInstruction will fail.
4865a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Also note that some instructions require non-trivial modification to
4875a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// commute them.
48843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isCommutable(QueryType Type = IgnoreBundle) const {
48943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Commutable, Type);
4905a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4915a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4925a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isConvertibleTo3Addr - Return true if this is a 2-address instruction
4935a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// which can be changed into a 3-address instruction if needed.  Doing this
4945a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// transformation can be profitable in the register allocator, because it
4955a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// means that the instruction can use a 2-address form if possible, but
4965a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// degrade into a less efficient form if the source and dest register cannot
4975a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// be assigned to the same register.  For example, this allows the x86
4985a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// backend to turn a "shl reg, 3" instruction into an LEA instruction, which
4995a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// is the same speed as the shift but has bigger code size.
5005a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
5015a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// If this returns true, then the target must implement the
5025a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// TargetInstrInfo::convertToThreeAddress method for this instruction, which
5035a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// is allowed to fail if the transformation isn't valid for this specific
5045a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instruction (e.g. shl reg, 4 on x86).
5055a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
50643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isConvertibleTo3Addr(QueryType Type = IgnoreBundle) const {
50743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::ConvertibleTo3Addr, Type);
5085a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5095a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5105a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// usesCustomInsertionHook - Return true if this instruction requires
5115a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// custom insertion support when the DAG scheduler is inserting it into a
5125a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// machine basic block.  If this is true for the instruction, it basically
5135a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// means that it is a pseudo instruction used at SelectionDAG time that is
5145a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// expanded out into magic code by the target when MachineInstrs are formed.
5155a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
5165a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method
5175a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// is used to insert this into the MachineBasicBlock.
51843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool usesCustomInsertionHook(QueryType Type = IgnoreBundle) const {
51943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::UsesCustomInserter, Type);
5205a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5215a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5225a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasPostISelHook - Return true if this instruction requires *adjustment*
5235a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// after instruction selection by calling a target hook. For example, this
5245a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// can be used to fill in ARM 's' optional operand depending on whether
5255a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// the conditional flag register is used.
52643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasPostISelHook(QueryType Type = IgnoreBundle) const {
52743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::HasPostISelHook, Type);
5285a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5295a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5305a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isRematerializable - Returns true if this instruction is a candidate for
5315a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// remat.  This flag is deprecated, please don't use it anymore.  If this
5325a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// flag is set, the isReallyTriviallyReMaterializable() method is called to
5335a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// verify the instruction is really rematable.
53443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isRematerializable(QueryType Type = AllInBundle) const {
5355a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // It's only possible to re-mat a bundle if all bundled instructions are
5365a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // re-materializable.
53743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Rematerializable, Type);
5385a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5395a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5405a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isAsCheapAsAMove - Returns true if this instruction has the same cost (or
5415a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// less) than a move instruction. This is useful during certain types of
5425a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// optimizations (e.g., remat during two-address conversion or machine licm)
5435a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// where we would like to remat or hoist the instruction, but not if it costs
5445a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// more than moving the instruction into the appropriate register. Note, we
5455a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// are not marking copies from and to the same register class with this flag.
54643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isAsCheapAsAMove(QueryType Type = AllInBundle) const {
5475a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // Only returns true for a bundle if all bundled instructions are cheap.
5485a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // FIXME: This probably requires a target hook.
54943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::CheapAsAMove, Type);
5505a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5515a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5525a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasExtraSrcRegAllocReq - Returns true if this instruction source operands
5535a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// have special register allocation requirements that are not captured by the
5545a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// operand register classes. e.g. ARM::STRD's two source registers must be an
5555a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// even / odd pair, ARM::STM registers have to be in ascending order.
5565a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Post-register allocation passes should not attempt to change allocations
5575a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// for sources of instructions with this flag.
55843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasExtraSrcRegAllocReq(QueryType Type = AnyInBundle) const {
55943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::ExtraSrcRegAllocReq, Type);
5605a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5615a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5625a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasExtraDefRegAllocReq - Returns true if this instruction def operands
5635a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// have special register allocation requirements that are not captured by the
5645a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// operand register classes. e.g. ARM::LDRD's two def registers must be an
5655a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// even / odd pair, ARM::LDM registers have to be in ascending order.
5665a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Post-register allocation passes should not attempt to change allocations
5675a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// for definitions of instructions with this flag.
56843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasExtraDefRegAllocReq(QueryType Type = AnyInBundle) const {
56943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::ExtraDefRegAllocReq, Type);
5705a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5715a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5725a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
573506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng  enum MICheckType {
574506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng    CheckDefs,      // Check all operands for equality
575cbc988be22bc9411d95215c8b7251b5f85710674Evan Cheng    CheckKillDead,  // Check all operands including kill / dead markers
576506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng    IgnoreDefs,     // Ignore all definitions
577506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng    IgnoreVRegDefs  // Ignore virtual register definitions
578506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng  };
579506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng
580fcfcb6cb502fd4562b57425a5802dc52f358c451Chris Lattner  /// isIdenticalTo - Return true if this instruction is identical to (same
581fcfcb6cb502fd4562b57425a5802dc52f358c451Chris Lattner  /// opcode and same operands as) the specified instruction.
582506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng  bool isIdenticalTo(const MachineInstr *Other,
583506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng                     MICheckType Check = CheckDefs) const;
584a2bae305fb5a870c4ef753ed290a7ddea73ec82bVikram S. Adve
5856b560918426182d2b46b899d609911d49f6739f7Chris Lattner  /// removeFromParent - This method unlinks 'this' from the containing basic
5866b560918426182d2b46b899d609911d49f6739f7Chris Lattner  /// block, and returns it, but does not delete it.
5876b560918426182d2b46b899d609911d49f6739f7Chris Lattner  MachineInstr *removeFromParent();
588108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
5896b560918426182d2b46b899d609911d49f6739f7Chris Lattner  /// eraseFromParent - This method unlinks 'this' from the containing basic
5906b560918426182d2b46b899d609911d49f6739f7Chris Lattner  /// block and deletes it.
5918e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void eraseFromParent();
592466b534a570f574ed485d875bbca8454f68dcb52Tanya Lattner
5934406604047423576e36657c7ede266ca42e79642Dan Gohman  /// isLabel - Returns true if the MachineInstr represents a label.
5944406604047423576e36657c7ede266ca42e79642Dan Gohman  ///
595518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isLabel() const {
5967431beaba2a01c3fe299c861b2ec85cbf1dc81c4Bill Wendling    return getOpcode() == TargetOpcode::PROLOG_LABEL ||
597518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner           getOpcode() == TargetOpcode::EH_LABEL ||
598518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner           getOpcode() == TargetOpcode::GC_LABEL;
599518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  }
600108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
6017431beaba2a01c3fe299c861b2ec85cbf1dc81c4Bill Wendling  bool isPrologLabel() const {
6027431beaba2a01c3fe299c861b2ec85cbf1dc81c4Bill Wendling    return getOpcode() == TargetOpcode::PROLOG_LABEL;
6037431beaba2a01c3fe299c861b2ec85cbf1dc81c4Bill Wendling  }
604518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isEHLabel() const { return getOpcode() == TargetOpcode::EH_LABEL; }
605518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isGCLabel() const { return getOpcode() == TargetOpcode::GC_LABEL; }
606518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isDebugValue() const { return getOpcode() == TargetOpcode::DBG_VALUE; }
607108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
608518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isPHI() const { return getOpcode() == TargetOpcode::PHI; }
609518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
610518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; }
611518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isInlineAsm() const { return getOpcode() == TargetOpcode::INLINEASM; }
612c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  bool isStackAligningInlineAsm() const;
613518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isInsertSubreg() const {
614518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner    return getOpcode() == TargetOpcode::INSERT_SUBREG;
615518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  }
616518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isSubregToReg() const {
617518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner    return getOpcode() == TargetOpcode::SUBREG_TO_REG;
618518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  }
6193d720fbc6ad40bc9287a420f824d244965d24631Evan Cheng  bool isRegSequence() const {
6203d720fbc6ad40bc9287a420f824d244965d24631Evan Cheng    return getOpcode() == TargetOpcode::REG_SEQUENCE;
6213d720fbc6ad40bc9287a420f824d244965d24631Evan Cheng  }
622ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  bool isBundle() const {
623ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng    return getOpcode() == TargetOpcode::BUNDLE;
624ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  }
625a4e1ba53ddedd08669886b2849926bb33facc198Jakob Stoklund Olesen  bool isCopy() const {
626a4e1ba53ddedd08669886b2849926bb33facc198Jakob Stoklund Olesen    return getOpcode() == TargetOpcode::COPY;
627a4e1ba53ddedd08669886b2849926bb33facc198Jakob Stoklund Olesen  }
628cfe5254cd34d9414d9f6b8aa02dc1239d71a703fRafael Espindola  bool isFullCopy() const {
629cfe5254cd34d9414d9f6b8aa02dc1239d71a703fRafael Espindola    return isCopy() && !getOperand(0).getSubReg() && !getOperand(1).getSubReg();
630cfe5254cd34d9414d9f6b8aa02dc1239d71a703fRafael Espindola  }
631a4e1ba53ddedd08669886b2849926bb33facc198Jakob Stoklund Olesen
632273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen  /// isCopyLike - Return true if the instruction behaves like a copy.
633273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen  /// This does not include native copy instructions.
634273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen  bool isCopyLike() const {
6350bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen    return isCopy() || isSubregToReg();
6360bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen  }
6370bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen
6380bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen  /// isIdentityCopy - Return true is the instruction is an identity copy.
6390bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen  bool isIdentityCopy() const {
6400bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen    return isCopy() && getOperand(0).getReg() == getOperand(1).getReg() &&
6410bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen      getOperand(0).getSubReg() == getOperand(1).getSubReg();
642273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen  }
643273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen
6443f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  /// isTransient - Return true if this is a transient instruction that is
6453f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  /// either very likely to be eliminated during register allocation (such as
6463f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  /// copy-like instructions), or if this instruction doesn't have an
6473f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  /// execution-time cost.
6483f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  bool isTransient() const {
6493f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    switch(getOpcode()) {
6503f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    default: return false;
6513f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    // Copy-like instructions are usually eliminated during register allocation.
6523f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::PHI:
6533f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::COPY:
6543f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::INSERT_SUBREG:
6553f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::SUBREG_TO_REG:
6563f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::REG_SEQUENCE:
6573f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    // Pseudo-instructions that don't produce any real output.
6583f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::IMPLICIT_DEF:
6593f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::KILL:
6603f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::PROLOG_LABEL:
6613f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::EH_LABEL:
6623f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::GC_LABEL:
6633f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::DBG_VALUE:
6643f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen      return true;
6653f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    }
6663f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  }
6673f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen
668ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  /// getBundleSize - Return the number of instructions inside the MI bundle.
669ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  unsigned getBundleSize() const;
670ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng
6716130f66eaae89f8878590796977678afa8448926Evan Cheng  /// readsRegister - Return true if the MachineInstr reads the specified
6726130f66eaae89f8878590796977678afa8448926Evan Cheng  /// register. If TargetRegisterInfo is passed, then it also checks if there
6736130f66eaae89f8878590796977678afa8448926Evan Cheng  /// is a read of a super-register.
6747ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  /// This does not count partial redefines of virtual registers as reads:
6757ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  ///   %reg1024:6 = OP.
6766130f66eaae89f8878590796977678afa8448926Evan Cheng  bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
6776130f66eaae89f8878590796977678afa8448926Evan Cheng    return findRegisterUseOperandIdx(Reg, false, TRI) != -1;
6786130f66eaae89f8878590796977678afa8448926Evan Cheng  }
6796130f66eaae89f8878590796977678afa8448926Evan Cheng
6807ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  /// readsVirtualRegister - Return true if the MachineInstr reads the specified
6817ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  /// virtual register. Take into account that a partial define is a
6827ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  /// read-modify-write operation.
68318b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  bool readsVirtualRegister(unsigned Reg) const {
68418b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen    return readsWritesVirtualRegister(Reg).first;
68518b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  }
68618b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen
68718b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  /// readsWritesVirtualRegister - Return a pair of bools (reads, writes)
68818b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  /// indicating if this instruction reads or writes Reg. This also considers
68918b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  /// partial defines.
69018b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  /// If Ops is not null, all operand indices for Reg are added.
69118b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  std::pair<bool,bool> readsWritesVirtualRegister(unsigned Reg,
69218b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen                                      SmallVectorImpl<unsigned> *Ops = 0) const;
6937ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen
6946130f66eaae89f8878590796977678afa8448926Evan Cheng  /// killsRegister - Return true if the MachineInstr kills the specified
6956130f66eaae89f8878590796977678afa8448926Evan Cheng  /// register. If TargetRegisterInfo is passed, then it also checks if there is
6966130f66eaae89f8878590796977678afa8448926Evan Cheng  /// a kill of a super-register.
6976130f66eaae89f8878590796977678afa8448926Evan Cheng  bool killsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
6986130f66eaae89f8878590796977678afa8448926Evan Cheng    return findRegisterUseOperandIdx(Reg, true, TRI) != -1;
6996130f66eaae89f8878590796977678afa8448926Evan Cheng  }
7006130f66eaae89f8878590796977678afa8448926Evan Cheng
7011015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// definesRegister - Return true if the MachineInstr fully defines the
7026130f66eaae89f8878590796977678afa8448926Evan Cheng  /// specified register. If TargetRegisterInfo is passed, then it also checks
7036130f66eaae89f8878590796977678afa8448926Evan Cheng  /// if there is a def of a super-register.
7041015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// NOTE: It's ignoring subreg indices on virtual registers.
7051015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  bool definesRegister(unsigned Reg, const TargetRegisterInfo *TRI=NULL) const {
7061015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng    return findRegisterDefOperandIdx(Reg, false, false, TRI) != -1;
7071015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  }
7081015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng
7091015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// modifiesRegister - Return true if the MachineInstr modifies (fully define
7101015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// or partially define) the specified register.
7111015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// NOTE: It's ignoring subreg indices on virtual registers.
7121015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  bool modifiesRegister(unsigned Reg, const TargetRegisterInfo *TRI) const {
7131015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng    return findRegisterDefOperandIdx(Reg, false, true, TRI) != -1;
7146130f66eaae89f8878590796977678afa8448926Evan Cheng  }
7156130f66eaae89f8878590796977678afa8448926Evan Cheng
7166130f66eaae89f8878590796977678afa8448926Evan Cheng  /// registerDefIsDead - Returns true if the register is dead in this machine
7176130f66eaae89f8878590796977678afa8448926Evan Cheng  /// instruction. If TargetRegisterInfo is passed, then it also checks
7186130f66eaae89f8878590796977678afa8448926Evan Cheng  /// if there is a dead def of a super-register.
7196130f66eaae89f8878590796977678afa8448926Evan Cheng  bool registerDefIsDead(unsigned Reg,
7206130f66eaae89f8878590796977678afa8448926Evan Cheng                         const TargetRegisterInfo *TRI = NULL) const {
7211015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng    return findRegisterDefOperandIdx(Reg, true, false, TRI) != -1;
7226130f66eaae89f8878590796977678afa8448926Evan Cheng  }
7236130f66eaae89f8878590796977678afa8448926Evan Cheng
724faa510726f4b40aa4495e60e4d341c6467e3fb01Evan Cheng  /// findRegisterUseOperandIdx() - Returns the operand index that is a use of
72510f9101c4c0df0837414976ad0ef0e86d6771059Jim Grosbach  /// the specific register or -1 if it is not found. It further tightens
72676d7e76c15c258ec4a71fd75a2a32bca3a5e5e27Evan Cheng  /// the search criteria to a use that kills the register if isKill is true.
7276130f66eaae89f8878590796977678afa8448926Evan Cheng  int findRegisterUseOperandIdx(unsigned Reg, bool isKill = false,
7286130f66eaae89f8878590796977678afa8448926Evan Cheng                                const TargetRegisterInfo *TRI = NULL) const;
7296130f66eaae89f8878590796977678afa8448926Evan Cheng
7306130f66eaae89f8878590796977678afa8448926Evan Cheng  /// findRegisterUseOperand - Wrapper for findRegisterUseOperandIdx, it returns
7316130f66eaae89f8878590796977678afa8448926Evan Cheng  /// a pointer to the MachineOperand rather than an index.
7329180c8e3cfd12abd21242768db05072a209ca6e7Evan Cheng  MachineOperand *findRegisterUseOperand(unsigned Reg, bool isKill = false,
7336130f66eaae89f8878590796977678afa8448926Evan Cheng                                         const TargetRegisterInfo *TRI = NULL) {
7346130f66eaae89f8878590796977678afa8448926Evan Cheng    int Idx = findRegisterUseOperandIdx(Reg, isKill, TRI);
7356130f66eaae89f8878590796977678afa8448926Evan Cheng    return (Idx == -1) ? NULL : &getOperand(Idx);
7366130f66eaae89f8878590796977678afa8448926Evan Cheng  }
737108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
7386130f66eaae89f8878590796977678afa8448926Evan Cheng  /// findRegisterDefOperandIdx() - Returns the operand index that is a def of
739703bfe69092e8da79fbef2fc5ca07b805ad9f753Dan Gohman  /// the specified register or -1 if it is not found. If isDead is true, defs
7401015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// that are not dead are skipped. If Overlap is true, then it also looks for
7411015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// defs that merely overlap the specified register. If TargetRegisterInfo is
7421015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// non-null, then it also checks if there is a def of a super-register.
7431cf8b0f2a5435d8444b6cc7d4a27eef424398273Jakob Stoklund Olesen  /// This may also return a register mask operand when Overlap is true.
7441015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  int findRegisterDefOperandIdx(unsigned Reg,
7451015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng                                bool isDead = false, bool Overlap = false,
7466130f66eaae89f8878590796977678afa8448926Evan Cheng                                const TargetRegisterInfo *TRI = NULL) const;
7476130f66eaae89f8878590796977678afa8448926Evan Cheng
7486130f66eaae89f8878590796977678afa8448926Evan Cheng  /// findRegisterDefOperand - Wrapper for findRegisterDefOperandIdx, it returns
7496130f66eaae89f8878590796977678afa8448926Evan Cheng  /// a pointer to the MachineOperand rather than an index.
750631bd3cdf39eb099d5d5d279b17b08f119956538Evan Cheng  MachineOperand *findRegisterDefOperand(unsigned Reg, bool isDead = false,
7516130f66eaae89f8878590796977678afa8448926Evan Cheng                                         const TargetRegisterInfo *TRI = NULL) {
7521015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng    int Idx = findRegisterDefOperandIdx(Reg, isDead, false, TRI);
7536130f66eaae89f8878590796977678afa8448926Evan Cheng    return (Idx == -1) ? NULL : &getOperand(Idx);
7546130f66eaae89f8878590796977678afa8448926Evan Cheng  }
75519e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng
756f277ee4be7edabb759a7f78138b693d72d0c263fEvan Cheng  /// findFirstPredOperandIdx() - Find the index of the first operand in the
757f277ee4be7edabb759a7f78138b693d72d0c263fEvan Cheng  /// operand list that is used to represent the predicate. It returns -1 if
758f277ee4be7edabb759a7f78138b693d72d0c263fEvan Cheng  /// none is found.
759f277ee4be7edabb759a7f78138b693d72d0c263fEvan Cheng  int findFirstPredOperandIdx() const;
760108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
7619dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// findInlineAsmFlagIdx() - Find the index of the flag word operand that
7629dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// corresponds to operand OpIdx on an inline asm instruction.  Returns -1 if
7639dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// getOperand(OpIdx) does not belong to an inline asm operand group.
7649dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  ///
7659dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// If GroupNo is not NULL, it will receive the number of the operand group
7669dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// containing OpIdx.
7679dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  ///
7689dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// The flag operand is an immediate that can be decoded with methods like
7699dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// InlineAsm::hasRegClassConstraint().
7709dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  ///
7719dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  int findInlineAsmFlagIdx(unsigned OpIdx, unsigned *GroupNo = 0) const;
7729dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen
773f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// getRegClassConstraint - Compute the static register class constraint for
774f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// operand OpIdx.  For normal instructions, this is derived from the
775f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// MCInstrDesc.  For inline assembly it is derived from the flag words.
776f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  ///
777f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// Returns NULL if the static register classs constraint cannot be
778f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// determined.
779f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  ///
780f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  const TargetRegisterClass*
781f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  getRegClassConstraint(unsigned OpIdx,
782f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen                        const TargetInstrInfo *TII,
783f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen                        const TargetRegisterInfo *TRI) const;
784f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen
785699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  /// findTiedOperandIdx - Given the index of a tied register operand, find the
786699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  /// operand it is tied to. Defs are tied to uses and vice versa. Returns the
787699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  /// index of the tied operand which must exist.
788699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  unsigned findTiedOperandIdx(unsigned OpIdx) const;
789699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen
790d9df5017040489303acb57bdd8697ef0f8bafc08Bob Wilson  /// isRegTiedToUseOperand - Given the index of a register def operand,
791d9df5017040489303acb57bdd8697ef0f8bafc08Bob Wilson  /// check if the register def is tied to a source operand, due to either
792d9df5017040489303acb57bdd8697ef0f8bafc08Bob Wilson  /// two-address elimination or inline assembly constraints. Returns the
793a21bb20f5943f5f4c66d4727784c26007db2470cJim Grosbach  /// first tied use operand index by reference if UseOpIdx is not null.
794ce9be2cf5dc84865f6b819bd3f9be16944426268Jakob Stoklund Olesen  bool isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx = 0) const;
79532dfbeada7292167bb488f36a71a5a6a519ddaffEvan Cheng
796a24752ff43dc1ad8c18c5d9e78549c45f62b980eEvan Cheng  /// isRegTiedToDefOperand - Return true if the use operand of the specified
797a24752ff43dc1ad8c18c5d9e78549c45f62b980eEvan Cheng  /// index is tied to an def operand. It also returns the def operand index by
798a24752ff43dc1ad8c18c5d9e78549c45f62b980eEvan Cheng  /// reference if DefOpIdx is not null.
799ce9be2cf5dc84865f6b819bd3f9be16944426268Jakob Stoklund Olesen  bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx = 0) const;
800a24752ff43dc1ad8c18c5d9e78549c45f62b980eEvan Cheng
801e6cd757e6800b9b94a6459ec148c0624c4f2e3c1Dan Gohman  /// clearKillInfo - Clears kill flags on all operands.
802e6cd757e6800b9b94a6459ec148c0624c4f2e3c1Dan Gohman  ///
803e6cd757e6800b9b94a6459ec148c0624c4f2e3c1Dan Gohman  void clearKillInfo();
804e6cd757e6800b9b94a6459ec148c0624c4f2e3c1Dan Gohman
8059a00279988612d0f960fb8d43e4ccfcab89e0e14Evan Cheng  /// copyKillDeadInfo - Copies kill / dead operand properties from MI.
8069a00279988612d0f960fb8d43e4ccfcab89e0e14Evan Cheng  ///
807576d123e130a8291669dd2384a3735cc4933fd00Evan Cheng  void copyKillDeadInfo(const MachineInstr *MI);
8089a00279988612d0f960fb8d43e4ccfcab89e0e14Evan Cheng
80919e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  /// copyPredicates - Copies predicate operand(s) from MI.
81019e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  void copyPredicates(const MachineInstr *MI);
81119e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng
8129edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen  /// substituteRegister - Replace all occurrences of FromReg with ToReg:SubIdx,
8139edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen  /// properly composing subreg indices where necessary.
8149edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen  void substituteRegister(unsigned FromReg, unsigned ToReg, unsigned SubIdx,
8159edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen                          const TargetRegisterInfo &RegInfo);
8169edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen
817b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// addRegisterKilled - We have determined MI kills a register. Look for the
818b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
819b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// add a implicit operand if it's not found. Returns true if the operand
820b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// exists / is added.
8216f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohman  bool addRegisterKilled(unsigned IncomingReg,
8226f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohman                         const TargetRegisterInfo *RegInfo,
823b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson                         bool AddIfNotFound = false);
8248efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen
8251a96c914315b0286d84c507d696484e2c95875a4Jakob Stoklund Olesen  /// clearRegisterKills - Clear all kill flags affecting Reg.  If RegInfo is
8261a96c914315b0286d84c507d696484e2c95875a4Jakob Stoklund Olesen  /// provided, this includes super-register kills.
8271a96c914315b0286d84c507d696484e2c95875a4Jakob Stoklund Olesen  void clearRegisterKills(unsigned Reg, const TargetRegisterInfo *RegInfo);
8281a96c914315b0286d84c507d696484e2c95875a4Jakob Stoklund Olesen
829b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// addRegisterDead - We have determined MI defined a register without a use.
830b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// Look for the operand that defines it and mark it as IsDead. If
831b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
832b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// true if the operand exists / is added.
8336f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohman  bool addRegisterDead(unsigned IncomingReg, const TargetRegisterInfo *RegInfo,
834b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson                       bool AddIfNotFound = false);
835b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson
8368efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen  /// addRegisterDefined - We have determined MI defines a register. Make sure
8378efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen  /// there is an operand defining Reg.
8388efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen  void addRegisterDefined(unsigned IncomingReg,
83963e6a488cb6c29983415221719d05fbf99e00193Jakob Stoklund Olesen                          const TargetRegisterInfo *RegInfo = 0);
8408efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen
8412a09f878ef64f216268df3dbe2f51b949f18c145Jim Grosbach  /// setPhysRegsDeadExcept - Mark every physreg used by this instruction as
8422a09f878ef64f216268df3dbe2f51b949f18c145Jim Grosbach  /// dead except those in the UsedRegs list.
84377180e0b402fff318cffd89a2251e46b3dce4064Jakob Stoklund Olesen  ///
84477180e0b402fff318cffd89a2251e46b3dce4064Jakob Stoklund Olesen  /// On instructions with register mask operands, also add implicit-def
84577180e0b402fff318cffd89a2251e46b3dce4064Jakob Stoklund Olesen  /// operands for all registers in UsedRegs.
846a37818dbb119bda75273f16b8484732e742cdbb7Jakob Stoklund Olesen  void setPhysRegsDeadExcept(ArrayRef<unsigned> UsedRegs,
847db4971259ce94cea26e555e9ade82672a3581f5cDan Gohman                             const TargetRegisterInfo &TRI);
848db4971259ce94cea26e555e9ade82672a3581f5cDan Gohman
8499f1c8317a4676945b4961ddb9827ef2412551620Evan Cheng  /// isSafeToMove - Return true if it is safe to move this instruction. If
8509f1c8317a4676945b4961ddb9827ef2412551620Evan Cheng  /// SawStore is set to true, it means that there is a store (or call) between
8519f1c8317a4676945b4961ddb9827ef2412551620Evan Cheng  /// the instruction's location and its intended destination.
852ac1abde05b7e6956c01deb6557539bee8fea30f4Evan Cheng  bool isSafeToMove(const TargetInstrInfo *TII, AliasAnalysis *AA,
853ac1abde05b7e6956c01deb6557539bee8fea30f4Evan Cheng                    bool &SawStore) const;
854b27087f5aa574f875598f4a309b7dd687c64a455Evan Cheng
8553e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  /// isSafeToReMat - Return true if it's safe to rematerialize the specified
8563e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  /// instruction which defined the specified register instead of copying it.
857ac1abde05b7e6956c01deb6557539bee8fea30f4Evan Cheng  bool isSafeToReMat(const TargetInstrInfo *TII, AliasAnalysis *AA,
858ac1abde05b7e6956c01deb6557539bee8fea30f4Evan Cheng                     unsigned DstReg) const;
859df3b99381f1c211071cc1daf0cc297666877bbcbEvan Cheng
8603e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  /// hasVolatileMemoryRef - Return true if this instruction may have a
8613e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  /// volatile memory reference, or if the information describing the
8623e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  /// memory reference is not available. Return false if it is known to
8633e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  /// have no volatile memory references.
8643e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  bool hasVolatileMemoryRef() const;
8653e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman
866e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman  /// isInvariantLoad - Return true if this instruction is loading from a
867e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman  /// location whose value is invariant across the function.  For example,
868f451cb870efcf9e0302d25ed05f4cac6bb494e42Dan Gohman  /// loading a value from the constant pool or from the argument area of
869e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman  /// a function if it does not change.  This should only return true of *all*
870e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman  /// loads the instruction does are invariant (if it does multiple loads).
871a70dca156fa76d452f54829b5c5f962ddfd94ef2Dan Gohman  bool isInvariantLoad(AliasAnalysis *AA) const;
872e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman
873229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng  /// isConstantValuePHI - If the specified instruction is a PHI that always
874229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng  /// merges together the same virtual register, return the register, otherwise
875229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng  /// return 0.
876229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng  unsigned isConstantValuePHI() const;
877229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng
878c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  /// hasUnmodeledSideEffects - Return true if this instruction has side
879c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  /// effects that are not modeled by mayLoad / mayStore, etc.
880e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// For all instructions, the property is encoded in MCInstrDesc::Flags
881e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// (see MCInstrDesc::hasUnmodeledSideEffects(). The only exception is
882c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  /// INLINEASM instruction, in which case the side effect property is encoded
883c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  /// in one of its operands (see InlineAsm::Extra_HasSideEffect).
884c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  ///
885c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  bool hasUnmodeledSideEffects() const;
886c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng
887a57fabe815ccf016eead526eb3ef475f116ab155Evan Cheng  /// allDefsAreDead - Return true if all the defs of this instruction are dead.
888a57fabe815ccf016eead526eb3ef475f116ab155Evan Cheng  ///
889a57fabe815ccf016eead526eb3ef475f116ab155Evan Cheng  bool allDefsAreDead() const;
890a57fabe815ccf016eead526eb3ef475f116ab155Evan Cheng
891b179b46cc558c720d23a066c768bad71f975eb93Evan Cheng  /// copyImplicitOps - Copy implicit register operands from specified
892b179b46cc558c720d23a066c768bad71f975eb93Evan Cheng  /// instruction to this instruction.
893b179b46cc558c720d23a066c768bad71f975eb93Evan Cheng  void copyImplicitOps(const MachineInstr *MI);
894b179b46cc558c720d23a066c768bad71f975eb93Evan Cheng
895a995e6086deca9cbd9aab9d6e1e94b36964b66daVikram S. Adve  //
896a995e6086deca9cbd9aab9d6e1e94b36964b66daVikram S. Adve  // Debugging support
897fa78fbf446b505767e838f9c188707183c57fc9cChris Lattner  //
898cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson  void print(raw_ostream &OS, const TargetMachine *TM = 0) const;
899572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  void dump() const;
9002f898d207466bf233b55607e404baca302bc7b5eChris Lattner
901413746e9833d97a8b463ef6a788aa326cf3829a2Chris Lattner  //===--------------------------------------------------------------------===//
90262ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  // Accessors used to build up machine instructions.
9037ad6be7b01a902f532eebb607306f7b3f4627718Chris Lattner
90462ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// addOperand - Add the specified operand to the instruction.  If it is an
90562ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// implicit operand, it is added to the end of the operand list.  If it is
90662ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// an explicit operand it is added at the end of the explicit operand list
907108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach  /// (before the first implicit operand).
90862ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  void addOperand(const MachineOperand &Op);
909108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
9105080f4d9919d39b367891dc51e739c571a66036cChris Lattner  /// setDesc - Replace the instruction descriptor (thus opcode) of
91167f660cb080965ea93ed6d7265a67100f2fe38e4Evan Cheng  /// the current instruction with a new one.
9123c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner  ///
913e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  void setDesc(const MCInstrDesc &tid) { MCID = &tid; }
9143c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner
91506efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// setDebugLoc - Replace current source information with new such.
916ab160cf371d6148d49b5401a903dd4ce381b2f8cDale Johannesen  /// Avoid using this, the constructor argument is preferable.
91706efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  ///
91806efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
91906efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
9203c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner  /// RemoveOperand - Erase an operand  from an instruction, leaving it with one
9213c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner  /// fewer operand than it started with.
9223c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner  ///
92362ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  void RemoveOperand(unsigned i);
92462ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner
925c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// addMemOperand - Add a MachineMemOperand to the machine instruction.
926c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// This function should be used only occasionally. The setMemRefs function
927c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// is the primary method for setting up a MachineInstr's MemRefs list.
928c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  void addMemOperand(MachineFunction &MF, MachineMemOperand *MO);
9298e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
930c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// setMemRefs - Assign this MachineInstr's memory reference descriptor
931c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// list. This does not transfer ownership.
932c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
933c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman    MemRefs = NewMemRefs;
934861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer    NumMemRefs = NewMemRefsEnd - NewMemRefs;
935c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  }
93669de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
937943b5e117fe9a087f9aa529a2632c2d32cc22374Chris Lattnerprivate:
93862ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// getRegInfo - If this instruction is embedded into a MachineFunction,
93962ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// return the MachineRegisterInfo object for the current function, otherwise
94062ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// return null.
94162ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  MachineRegisterInfo *getRegInfo();
942d7de496b23fca8145f777a56281457bf64e8bbadEvan Cheng
943699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  /// untieRegOperand - Break any tie involving OpIdx.
944699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  void untieRegOperand(unsigned OpIdx) {
945699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen    const MachineOperand &MO = getOperand(OpIdx);
946699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen    if (MO.isReg() && MO.isTied())
947699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen      getOperand(findTiedOperandIdx(OpIdx)).setIsTied(false);
948699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  }
949699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen
950d7de496b23fca8145f777a56281457bf64e8bbadEvan Cheng  /// addImplicitDefUseOperands - Add all implicit def and use operands to
951d7de496b23fca8145f777a56281457bf64e8bbadEvan Cheng  /// this instruction.
95267f660cb080965ea93ed6d7265a67100f2fe38e4Evan Cheng  void addImplicitDefUseOperands();
953108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
95462ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// RemoveRegOperandsFromUseLists - Unlink all of the register operands in
95562ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// this instruction from their respective use lists.  This requires that the
95662ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// operands already be on their use lists.
957ff2b99afc8cbc6cfa73181072888e0f9f07deb7eJakob Stoklund Olesen  void RemoveRegOperandsFromUseLists(MachineRegisterInfo&);
958108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
95962ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// AddRegOperandsToUseLists - Add all of the register operands in
96062ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// this instruction from their respective use lists.  This requires that the
96162ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// operands not be on their use lists yet.
962ff2b99afc8cbc6cfa73181072888e0f9f07deb7eJakob Stoklund Olesen  void AddRegOperandsToUseLists(MachineRegisterInfo&);
96385f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer
96485f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  /// hasPropertyInBundle - Slow path for hasProperty when we're dealing with a
96585f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  /// bundle.
96685f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  bool hasPropertyInBundle(unsigned Mask, QueryType Type) const;
967a995e6086deca9cbd9aab9d6e1e94b36964b66daVikram S. Adve};
96823ee550765232e22d0daf6407141ecef4c55c06fVikram S. Adve
96905bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng/// MachineInstrExpressionTrait - Special DenseMapInfo traits to compare
97005bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng/// MachineInstr* by *value* of the instruction rather than by pointer value.
97105bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng/// The hashing and equality testing functions ignore definitions so this is
97205bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng/// useful for CSE, etc.
97305bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Chengstruct MachineInstrExpressionTrait : DenseMapInfo<MachineInstr*> {
97405bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  static inline MachineInstr *getEmptyKey() {
97505bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng    return 0;
97605bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  }
97705bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng
97805bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  static inline MachineInstr *getTombstoneKey() {
97905bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng    return reinterpret_cast<MachineInstr*>(-1);
98005bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  }
98105bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng
98267eaa08f2b71aa8aec8cdf4c7d970db4cad58adaEvan Cheng  static unsigned getHashValue(const MachineInstr* const &MI);
98305bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng
98405bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  static bool isEqual(const MachineInstr* const &LHS,
98505bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng                      const MachineInstr* const &RHS) {
98605bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng    if (RHS == getEmptyKey() || RHS == getTombstoneKey() ||
98705bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng        LHS == getEmptyKey() || LHS == getTombstoneKey())
98805bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng      return LHS == RHS;
98905bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng    return LHS->isIdenticalTo(RHS, MachineInstr::IgnoreVRegDefs);
99005bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  }
99105bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng};
99205bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng
993b05497e0ca1ba2e7f57b792cc160e5d1c8579582Chris Lattner//===----------------------------------------------------------------------===//
994593da4acc56d4c591ad688e6605b04d0825c867eVikram S. Adve// Debugging Support
995593da4acc56d4c591ad688e6605b04d0825c867eVikram S. Adve
996cb3718832375a581c5ea23f15918f3ea447a446cOwen Andersoninline raw_ostream& operator<<(raw_ostream &OS, const MachineInstr &MI) {
997cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson  MI.print(OS);
998cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson  return OS;
999cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson}
1000cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson
1001d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
1002d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
100323ee550765232e22d0daf6407141ecef4c55c06fVikram S. Adve#endif
1004