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"
28576cd11ab8035d4240f7e6ea8d7c6c2e45154f86Chad Rosier#include "llvm/InlineAsm.h"
291e86a66b00b94adc4ad6977ef6b47c516ac62cecDevang Patel#include "llvm/Support/DebugLoc.h"
301baa88e3de8947b02d9ef4caa73e5860f048ec6eDan Gohman#include <vector>
31be583b914d8156b99d3da264d5adca37fee8dbc9John Criswell
32d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
33d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
3418b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesentemplate <typename T> class SmallVectorImpl;
35e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohmanclass AliasAnalysis;
36b27087f5aa574f875598f4a309b7dd687c64a455Evan Chengclass TargetInstrInfo;
37f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesenclass TargetRegisterClass;
386f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohmanclass TargetRegisterInfo;
398e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohmanclass MachineFunction;
40c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohmanclass MachineMemOperand;
41c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos
42b05497e0ca1ba2e7f57b792cc160e5d1c8579582Chris Lattner//===----------------------------------------------------------------------===//
438b915b4ed2c6e43413937ac71c0cbcf476ad1a98Chris Lattner/// MachineInstr - Representation of each machine instruction.
448b915b4ed2c6e43413937ac71c0cbcf476ad1a98Chris Lattner///
45fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineInstr : public ilist_node<MachineInstr> {
46c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohmanpublic:
47c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  typedef MachineMemOperand **mmo_iterator;
48c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman
4945282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  /// Flags to specify different kinds of comments to output in
5045282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  /// assembly code.  These flags carry semantic information not
5145282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  /// otherwise easily derivable from the IR text.
5245282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  ///
5345282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  enum CommentFlag {
5445282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner    ReloadReuse = 0x1
5545282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  };
566dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
576dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  enum MIFlag {
587c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    NoFlags      = 0,
597c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    FrameSetup   = 1 << 0,              // Instruction is used as a part of
606dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov                                        // function frame setup code.
617c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    InsideBundle = 1 << 1               // Instruction is inside a bundle (not
627c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng                                        // the first MI in a bundle)
636dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  };
64c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohmanprivate:
65e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  const MCInstrDesc *MCID;              // Instruction descriptor.
669a00279988612d0f960fb8d43e4ccfcab89e0e14Evan Cheng
676dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  uint8_t Flags;                        // Various bits of additional
686dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov                                        // information about machine
696dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov                                        // instruction.
706dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
716647b59c9263eb1decd7f7ff353c0c99ec09ae6cAnton Korobeynikov  uint8_t AsmPrinterFlags;              // Various bits of information used by
721251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // the AsmPrinter to emit helpful
731251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // comments.  This is *not* semantic
741251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // information.  Do not use this for
751251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // anything other than to convey comment
761251443929a256c833717e1030c368d3b6e4cb7cDavid Greene                                        // information to AsmPrinter.
771251443929a256c833717e1030c368d3b6e4cb7cDavid Greene
78861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer  uint16_t NumMemRefs;                  // information on memory references
79861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer  mmo_iterator MemRefs;
80861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer
81943b5e117fe9a087f9aa529a2632c2d32cc22374Chris Lattner  std::vector<MachineOperand> Operands; // the operands
82f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  MachineBasicBlock *Parent;            // Pointer to the owning basic block.
8306efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  DebugLoc debugLoc;                    // Source line information.
84c54839573cd9ffa6af33dc5190cc40d498534585Brian Gaeke
858e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineInstr(const MachineInstr&);   // DO NOT IMPLEMENT
869452b0797a80001920576d7e2ef4af05242cba69Chris Lattner  void operator=(const MachineInstr&); // DO NOT IMPLEMENT
87c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos
88c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos  // Intrusive list support
89fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  friend struct ilist_traits<MachineInstr>;
90fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  friend struct ilist_traits<MachineBasicBlock>;
91f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  void setParent(MachineBasicBlock *P) { Parent = P; }
928e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
938e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// MachineInstr ctor - This constructor creates a copy of the given
948e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// MachineInstr in the given MachineFunction.
958e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineInstr(MachineFunction &, const MachineInstr &);
968e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
97c0f64ffab93d11fb27a3b8a0707b77400918a20eEvan Cheng  /// MachineInstr ctor - This constructor creates a dummy MachineInstr with
98e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// MCID NULL and no operands.
99c0f64ffab93d11fb27a3b8a0707b77400918a20eEvan Cheng  MachineInstr();
100e8b57ef2603ed522083dc18e559ca4e20abf22aeVikram S. Adve
10106efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  // The next two constructors have DebugLoc and non-DebugLoc versions;
10206efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  // over time, the non-DebugLoc versions should be phased out and eventually
10306efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  // removed.
10406efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
105666f8cb9b7486a45f59fd9ba3202e4b67dbad58cBob Wilson  /// MachineInstr ctor - This constructor creates a MachineInstr and adds the
106666f8cb9b7486a45f59fd9ba3202e4b67dbad58cBob Wilson  /// implicit operands.  It reserves space for the number of operands specified
107e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// by the MCInstrDesc.  The version with a DebugLoc should be preferred.
108e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  explicit MachineInstr(const MCInstrDesc &MCID, bool NoImp = false);
109d7de496b23fca8145f777a56281457bf64e8bbadEvan Cheng
1107db458fb0768059f050d3a0f1a26818fa8e22712Chris Lattner  /// MachineInstr ctor - Work exactly the same as the ctor above, except that
1117db458fb0768059f050d3a0f1a26818fa8e22712Chris Lattner  /// the MachineInstr is created and added to the end of the specified basic
11206efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// block.  The version with a DebugLoc should be preferred.
113e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  MachineInstr(MachineBasicBlock *MBB, const MCInstrDesc &MCID);
114ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
11506efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// MachineInstr ctor - This constructor create a MachineInstr and add the
11606efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// implicit operands.  It reserves space for number of operands specified by
117e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// MCInstrDesc.  An explicit DebugLoc is supplied.
118e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  explicit MachineInstr(const MCInstrDesc &MCID, const DebugLoc dl,
11906efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen                        bool NoImp = false);
12006efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
12106efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// MachineInstr ctor - Work exactly the same as the ctor above, except that
12206efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// the MachineInstr is created and added to the end of the specified basic
12306efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// block.
124108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach  MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl,
125e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng               const MCInstrDesc &MCID);
12606efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
127aad5c0505183a5b7913f1a443a1f0650122551ccAlkis Evlogimenos  ~MachineInstr();
128aad5c0505183a5b7913f1a443a1f0650122551ccAlkis Evlogimenos
1298e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // MachineInstrs are pool-allocated and owned by MachineFunction.
1308e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  friend class MachineFunction;
1318e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
1328e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohmanpublic:
133f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  const MachineBasicBlock* getParent() const { return Parent; }
134f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  MachineBasicBlock* getParent() { return Parent; }
13506efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
1361251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  /// getAsmPrinterFlags - Return the asm printer flags bitvector.
1371251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  ///
1386647b59c9263eb1decd7f7ff353c0c99ec09ae6cAnton Korobeynikov  uint8_t getAsmPrinterFlags() const { return AsmPrinterFlags; }
1391251443929a256c833717e1030c368d3b6e4cb7cDavid Greene
140cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  /// clearAsmPrinterFlags - clear the AsmPrinter bitvector
141cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  ///
142cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  void clearAsmPrinterFlags() { AsmPrinterFlags = 0; }
143108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
1441251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  /// getAsmPrinterFlag - Return whether an AsmPrinter flag is set.
1451251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  ///
14645282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  bool getAsmPrinterFlag(CommentFlag Flag) const {
1471251443929a256c833717e1030c368d3b6e4cb7cDavid Greene    return AsmPrinterFlags & Flag;
1481251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  }
1491251443929a256c833717e1030c368d3b6e4cb7cDavid Greene
1501251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  /// setAsmPrinterFlag - Set a flag for the AsmPrinter.
1511251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  ///
15245282aedb9c5a33d20565502c6c8fc871fa84cbeChris Lattner  void setAsmPrinterFlag(CommentFlag Flag) {
1536dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    AsmPrinterFlags |= (uint8_t)Flag;
1546dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  }
1556dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
1567c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// clearAsmPrinterFlag - clear specific AsmPrinter flags
1577c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///
1587c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  void clearAsmPrinterFlag(CommentFlag Flag) {
1597c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    AsmPrinterFlags &= ~Flag;
1607c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  }
1617c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng
1626dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  /// getFlags - Return the MI flags bitvector.
1636dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  uint8_t getFlags() const {
1646dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    return Flags;
1656dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  }
1666dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
1676dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  /// getFlag - Return whether an MI flag is set.
1686dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  bool getFlag(MIFlag Flag) const {
1696dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    return Flags & Flag;
1706dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  }
1716dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
1726dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  /// setFlag - Set a MI flag.
1736dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  void setFlag(MIFlag Flag) {
1746dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    Flags |= (uint8_t)Flag;
1756dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  }
1766dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
1776dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov  void setFlags(unsigned flags) {
1786dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov    Flags = flags;
1791251443929a256c833717e1030c368d3b6e4cb7cDavid Greene  }
180108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
181ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  /// clearFlag - Clear a MI flag.
182ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  void clearFlag(MIFlag Flag) {
183ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng    Flags &= ~((uint8_t)Flag);
184ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  }
185ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng
1867c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// isInsideBundle - Return true if MI is in a bundle (but not the first MI
1877c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// in a bundle).
188cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  ///
1897c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// A bundle looks like this before it's finalized:
1907c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
1917c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   |      MI      |
1927c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
1937c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
1947c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
195b3aacdd358052ddd8d9fc9ac77f5e17a4048941aAndrew Trick  ///   |      MI    * |
1967c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
1977c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
1987c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
199b3aacdd358052ddd8d9fc9ac77f5e17a4048941aAndrew Trick  ///   |      MI    * |
2007c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2017c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// In this case, the first MI starts a bundle but is not inside a bundle, the
2027c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// next 2 MIs are considered "inside" the bundle.
2037c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///
2047c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// After a bundle is finalized, it looks like this:
2057c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2067c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   |    Bundle    |
2077c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2087c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
2097c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2107c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   |      MI    * |
2117c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2127c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
2137c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
214b3aacdd358052ddd8d9fc9ac77f5e17a4048941aAndrew Trick  ///   |      MI    * |
2157c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2167c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///          |
2177c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
218b3aacdd358052ddd8d9fc9ac77f5e17a4048941aAndrew Trick  ///   |      MI    * |
2197c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///   ----------------
2207c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// The first instruction has the special opcode "BUNDLE". It's not "inside"
2217c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  /// a bundle, but the next three MIs are.
2227c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  bool isInsideBundle() const {
2237c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng    return getFlag(InsideBundle);
224cbd323ad5259dc2bd3428a4ac26718b10adcd3cfChris Lattner  }
2251251443929a256c833717e1030c368d3b6e4cb7cDavid Greene
226ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  /// setIsInsideBundle - Set InsideBundle bit.
227ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  ///
228ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  void setIsInsideBundle(bool Val = true) {
229ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng    if (Val)
230ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng      setFlag(InsideBundle);
231ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng    else
232ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng      clearFlag(InsideBundle);
233ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  }
234ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng
23599a7a13f4aa5bf8f272c95f7b09ba997d2b30a35Andrew Trick  /// isBundled - Return true if this instruction part of a bundle. This is true
23699a7a13f4aa5bf8f272c95f7b09ba997d2b30a35Andrew Trick  /// if either itself or its following instruction is marked "InsideBundle".
23799a7a13f4aa5bf8f272c95f7b09ba997d2b30a35Andrew Trick  bool isBundled() const;
23899a7a13f4aa5bf8f272c95f7b09ba997d2b30a35Andrew Trick
23906efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// getDebugLoc - Returns the debug location id of this MachineInstr.
24006efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  ///
241d5fb7906130989a579d1bfe4490b414331e94feeChris Lattner  DebugLoc getDebugLoc() const { return debugLoc; }
2426dd97471c43805b3febf598d50498a09a02e93f4Anton Korobeynikov
243d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// emitError - Emit an error referring to the source location of this
244d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// instruction. This should only be used for inline assembly that is somehow
245d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// impossible to compile. Other errors should have been handled much
246d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// earlier.
247d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  ///
248d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  /// If this method returns, the caller should try to recover from the error.
249d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  ///
250d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen  void emitError(StringRef Msg) const;
251d519de082766bb71e13f6a516b305ff841c6b48cJakob Stoklund Olesen
25269244300b8a0112efb44b6273ecea4ca6264b8cfChris Lattner  /// getDesc - Returns the target instruction descriptor of this
25367f660cb080965ea93ed6d7265a67100f2fe38e4Evan Cheng  /// MachineInstr.
254e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  const MCInstrDesc &getDesc() const { return *MCID; }
255ab8672c8bb83e722b856eac67863542ea7e0cbb2Alkis Evlogimenos
256c54839573cd9ffa6af33dc5190cc40d498534585Brian Gaeke  /// getOpcode - Returns the opcode of this MachineInstr.
257cd0b3a90aa34bd42d75d8d86f74ca4972145781dBrian Gaeke  ///
258e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  int getOpcode() const { return MCID->Opcode; }
2599f495b54fa94dba4e0be59ba9736c7cf18d996d9Vikram S. Adve
260cd0b3a90aa34bd42d75d8d86f74ca4972145781dBrian Gaeke  /// Access to explicit operands of the instruction.
261cd0b3a90aa34bd42d75d8d86f74ca4972145781dBrian Gaeke  ///
26234cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  unsigned getNumOperands() const { return (unsigned)Operands.size(); }
263ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
264572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  const MachineOperand& getOperand(unsigned i) const {
265a2bae305fb5a870c4ef753ed290a7ddea73ec82bVikram S. Adve    assert(i < getNumOperands() && "getOperand() out of range!");
266943b5e117fe9a087f9aa529a2632c2d32cc22374Chris Lattner    return Operands[i];
267572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  }
268572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  MachineOperand& getOperand(unsigned i) {
269a2bae305fb5a870c4ef753ed290a7ddea73ec82bVikram S. Adve    assert(i < getNumOperands() && "getOperand() out of range!");
270943b5e117fe9a087f9aa529a2632c2d32cc22374Chris Lattner    return Operands[i];
271572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  }
2726d6c3f86186333037f2fd3fb001e8b2998c080d9Chris Lattner
27319e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  /// getNumExplicitOperands - Returns the number of non-implicit operands.
27419e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  ///
27519e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  unsigned getNumExplicitOperands() const;
276ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner
277ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  /// iterator/begin/end - Iterate over all operands of a machine instruction.
278ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  typedef std::vector<MachineOperand>::iterator mop_iterator;
279ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  typedef std::vector<MachineOperand>::const_iterator const_mop_iterator;
280ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner
281ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  mop_iterator operands_begin() { return Operands.begin(); }
282ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  mop_iterator operands_end() { return Operands.end(); }
283ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner
284ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  const_mop_iterator operands_begin() const { return Operands.begin(); }
285ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner  const_mop_iterator operands_end() const { return Operands.end(); }
286ccb5c677c66aea0a86878de69d5346ef802a6505Chris Lattner
28769de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  /// Access to memory operands of the instruction
288c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  mmo_iterator memoperands_begin() const { return MemRefs; }
289861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer  mmo_iterator memoperands_end() const { return MemRefs + NumMemRefs; }
290861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer  bool memoperands_empty() const { return NumMemRefs == 0; }
29169de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
292cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman  /// hasOneMemOperand - Return true if this instruction has exactly one
293cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman  /// MachineMemOperand.
294cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman  bool hasOneMemOperand() const {
295861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer    return NumMemRefs == 1;
296cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman  }
297cddc11e7570893233af8e84dfb8e7f0f9ab0090dDan Gohman
2985a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// API for querying MachineInstr properties. They are the same as MCInstrDesc
2995a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// queries but they are bundle aware.
3005a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
30143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  enum QueryType {
30243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    IgnoreBundle,    // Ignore bundles
30343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    AnyInBundle,     // Return true if any instruction in bundle has property
30443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    AllInBundle      // Return true if all instructions in bundle have property
30543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  };
30643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng
3075a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasProperty - Return true if the instruction (or in the case of a bundle,
3085a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// the instructions inside the bundle) has the specified property.
3095a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// The first argument is the property being queried.
3105a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// The second argument indicates whether the query should look inside
3115a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instruction bundles.
31285f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  bool hasProperty(unsigned MCFlag, QueryType Type = AnyInBundle) const {
31385f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer    // Inline the fast path.
31485f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer    if (Type == IgnoreBundle || !isBundle())
31585f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer      return getDesc().getFlags() & (1 << MCFlag);
31685f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer
31785f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer    // If we have a bundle, take the slow path.
31885f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer    return hasPropertyInBundle(1 << MCFlag, Type);
31985f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  }
3205a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3215a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isVariadic - Return true if this instruction can have a variable number of
3225a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// operands.  In this case, the variable operands will be after the normal
3235a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// operands but before the implicit definitions and uses (if any are
3245a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// present).
32543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isVariadic(QueryType Type = IgnoreBundle) const {
32643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Variadic, Type);
3275a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3285a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3295a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasOptionalDef - Set if this instruction has an optional definition, e.g.
3305a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// ARM instructions which can set condition code if 's' bit is set.
33143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasOptionalDef(QueryType Type = IgnoreBundle) const {
33243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::HasOptionalDef, Type);
3335a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3345a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3355a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isPseudo - Return true if this is a pseudo instruction that doesn't
3365a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// correspond to a real machine instruction.
3377c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  ///
33843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isPseudo(QueryType Type = IgnoreBundle) const {
33943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Pseudo, Type);
3405a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3415a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
34243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isReturn(QueryType Type = AnyInBundle) const {
34343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Return, Type);
3445a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3455a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
34643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isCall(QueryType Type = AnyInBundle) const {
34743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Call, Type);
3485a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3495a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3505a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isBarrier - Returns true if the specified instruction stops control flow
3515a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// from executing the instruction immediately following it.  Examples include
3525a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// unconditional branches and return instructions.
35343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isBarrier(QueryType Type = AnyInBundle) const {
35443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Barrier, Type);
3555a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3567c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng
3575a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isTerminator - Returns true if this instruction part of the terminator for
3585a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// a basic block.  Typically this is things like return and branch
3595a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instructions.
3605a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
3615a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Various passes use this to insert code into the bottom of a basic block,
3625a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// but before control flow occurs.
36343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isTerminator(QueryType Type = AnyInBundle) const {
36443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Terminator, Type);
3657c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng  }
3667c2a4a30e0e16762c75adacebd05ec9fcbccf16bEvan Cheng
3675a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isBranch - Returns true if this is a conditional, unconditional, or
3685a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// indirect branch.  Predicates below can be used to discriminate between
3695a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// these cases, and the TargetInstrInfo::AnalyzeBranch method can be used to
3705a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// get more information.
37143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isBranch(QueryType Type = AnyInBundle) const {
37243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Branch, Type);
3735a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3745a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3755a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isIndirectBranch - Return true if this is an indirect branch, such as a
3765a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// branch through a register.
37743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isIndirectBranch(QueryType Type = AnyInBundle) const {
37843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::IndirectBranch, Type);
3795a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3805a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3815a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isConditionalBranch - Return true if this is a branch which may fall
3825a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// through to the next instruction or may transfer control flow to some other
3835a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// block.  The TargetInstrInfo::AnalyzeBranch method can be used to get more
3845a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// information about this branch.
38543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isConditionalBranch(QueryType Type = AnyInBundle) const {
38643d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return isBranch(Type) & !isBarrier(Type) & !isIndirectBranch(Type);
3875a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3885a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3895a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isUnconditionalBranch - Return true if this is a branch which always
3905a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// transfers control flow to some other block.  The
3915a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// TargetInstrInfo::AnalyzeBranch method can be used to get more information
3925a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// about this branch.
39343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isUnconditionalBranch(QueryType Type = AnyInBundle) const {
39443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return isBranch(Type) & isBarrier(Type) & !isIndirectBranch(Type);
3955a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
3965a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
3975a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  // isPredicable - Return true if this instruction has a predicate operand that
3985a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  // controls execution.  It may be set to 'always', or may be set to other
3995a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// values.   There are various methods in TargetInstrInfo that can be used to
4005a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// control and modify the predicate in this instruction.
40143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isPredicable(QueryType Type = AllInBundle) const {
4025a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // If it's a bundle than all bundled instructions must be predicable for this
4035a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // to return true.
40443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Predicable, Type);
4055a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4065a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4075a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isCompare - Return true if this instruction is a comparison.
40843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isCompare(QueryType Type = IgnoreBundle) const {
40943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Compare, Type);
4105a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4115a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4125a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isMoveImmediate - Return true if this instruction is a move immediate
4135a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// (including conditional moves) instruction.
41443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isMoveImmediate(QueryType Type = IgnoreBundle) const {
41543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::MoveImm, Type);
4165a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4175a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4185a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isBitcast - Return true if this instruction is a bitcast instruction.
4195a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
42043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isBitcast(QueryType Type = IgnoreBundle) const {
42143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Bitcast, Type);
4225a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4235a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
424f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen  /// isSelect - Return true if this instruction is a select instruction.
425f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen  ///
426f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen  bool isSelect(QueryType Type = IgnoreBundle) const {
427f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen    return hasProperty(MCID::Select, Type);
428f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen  }
429f2c64ef519b38a4328809b27b4a3a8e0c26e9709Jakob Stoklund Olesen
4305a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isNotDuplicable - Return true if this instruction cannot be safely
4315a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// duplicated.  For example, if the instruction has a unique labels attached
4325a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// to it, duplicating it would cause multiple definition errors.
43343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isNotDuplicable(QueryType Type = AnyInBundle) const {
43443d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::NotDuplicable, Type);
4355a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4365a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4375a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasDelaySlot - Returns true if the specified instruction has a delay slot
4385a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// which must be filled by the code generator.
43943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasDelaySlot(QueryType Type = AnyInBundle) const {
44043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::DelaySlot, Type);
4415a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4425a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4435a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// canFoldAsLoad - Return true for instructions that can be folded as
4445a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// memory operands in other instructions. The most common use for this
4455a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// is instructions that are simple loads from memory that don't modify
4465a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// the loaded value in any way, but it can also be used for instructions
4475a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// that can be expressed as constant-pool loads, such as V_SETALLONES
4485a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// on x86, to allow them to be folded when it is beneficial.
4495a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// This should only be set on instructions that return a value in their
4505a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// only virtual register definition.
45143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool canFoldAsLoad(QueryType Type = IgnoreBundle) const {
45243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::FoldableAsLoad, Type);
4535a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4545a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4555a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  //===--------------------------------------------------------------------===//
4565a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  // Side Effect Analysis
4575a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  //===--------------------------------------------------------------------===//
4585a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4595a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// mayLoad - Return true if this instruction could possibly read memory.
4605a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Instructions with this flag set are not necessarily simple load
4615a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instructions, they may load a value and modify it, for example.
46243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool mayLoad(QueryType Type = AnyInBundle) const {
46343d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::MayLoad, Type);
4645a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4655a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4665a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4675a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// mayStore - Return true if this instruction could possibly modify memory.
4685a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Instructions with this flag set are not necessarily simple store
4695a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instructions, they may store a modified value based on their operands, or
4705a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// may not actually modify anything, for example.
47143d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool mayStore(QueryType Type = AnyInBundle) const {
47243d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::MayStore, Type);
4735a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4745a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4755a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  //===--------------------------------------------------------------------===//
4765a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  // Flags that indicate whether an instruction can be modified by a method.
4775a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  //===--------------------------------------------------------------------===//
4785a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4795a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isCommutable - Return true if this may be a 2- or 3-address
4805a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instruction (of the form "X = op Y, Z, ..."), which produces the same
4815a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// result if Y and Z are exchanged.  If this flag is set, then the
4825a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// TargetInstrInfo::commuteInstruction method may be used to hack on the
4835a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instruction.
4845a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
4855a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Note that this flag may be set on instructions that are only commutable
4865a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// sometimes.  In these cases, the call to commuteInstruction will fail.
4875a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Also note that some instructions require non-trivial modification to
4885a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// commute them.
48943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isCommutable(QueryType Type = IgnoreBundle) const {
49043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Commutable, Type);
4915a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
4925a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
4935a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isConvertibleTo3Addr - Return true if this is a 2-address instruction
4945a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// which can be changed into a 3-address instruction if needed.  Doing this
4955a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// transformation can be profitable in the register allocator, because it
4965a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// means that the instruction can use a 2-address form if possible, but
4975a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// degrade into a less efficient form if the source and dest register cannot
4985a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// be assigned to the same register.  For example, this allows the x86
4995a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// backend to turn a "shl reg, 3" instruction into an LEA instruction, which
5005a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// is the same speed as the shift but has bigger code size.
5015a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
5025a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// If this returns true, then the target must implement the
5035a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// TargetInstrInfo::convertToThreeAddress method for this instruction, which
5045a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// is allowed to fail if the transformation isn't valid for this specific
5055a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// instruction (e.g. shl reg, 4 on x86).
5065a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
50743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isConvertibleTo3Addr(QueryType Type = IgnoreBundle) const {
50843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::ConvertibleTo3Addr, Type);
5095a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5105a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5115a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// usesCustomInsertionHook - Return true if this instruction requires
5125a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// custom insertion support when the DAG scheduler is inserting it into a
5135a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// machine basic block.  If this is true for the instruction, it basically
5145a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// means that it is a pseudo instruction used at SelectionDAG time that is
5155a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// expanded out into magic code by the target when MachineInstrs are formed.
5165a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  ///
5175a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method
5185a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// is used to insert this into the MachineBasicBlock.
51943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool usesCustomInsertionHook(QueryType Type = IgnoreBundle) const {
52043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::UsesCustomInserter, Type);
5215a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5225a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5235a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasPostISelHook - Return true if this instruction requires *adjustment*
5245a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// after instruction selection by calling a target hook. For example, this
5255a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// can be used to fill in ARM 's' optional operand depending on whether
5265a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// the conditional flag register is used.
52743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasPostISelHook(QueryType Type = IgnoreBundle) const {
52843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::HasPostISelHook, Type);
5295a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5305a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5315a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isRematerializable - Returns true if this instruction is a candidate for
5325a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// remat.  This flag is deprecated, please don't use it anymore.  If this
5335a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// flag is set, the isReallyTriviallyReMaterializable() method is called to
5345a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// verify the instruction is really rematable.
53543d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isRematerializable(QueryType Type = AllInBundle) const {
5365a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // It's only possible to re-mat a bundle if all bundled instructions are
5375a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // re-materializable.
53843d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::Rematerializable, Type);
5395a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5405a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5415a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// isAsCheapAsAMove - Returns true if this instruction has the same cost (or
5425a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// less) than a move instruction. This is useful during certain types of
5435a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// optimizations (e.g., remat during two-address conversion or machine licm)
5445a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// where we would like to remat or hoist the instruction, but not if it costs
5455a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// more than moving the instruction into the appropriate register. Note, we
5465a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// are not marking copies from and to the same register class with this flag.
54743d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool isAsCheapAsAMove(QueryType Type = AllInBundle) const {
5485a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // Only returns true for a bundle if all bundled instructions are cheap.
5495a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng    // FIXME: This probably requires a target hook.
55043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::CheapAsAMove, Type);
5515a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5525a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5535a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasExtraSrcRegAllocReq - Returns true if this instruction source operands
5545a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// have special register allocation requirements that are not captured by the
5555a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// operand register classes. e.g. ARM::STRD's two source registers must be an
5565a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// even / odd pair, ARM::STM registers have to be in ascending order.
5575a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Post-register allocation passes should not attempt to change allocations
5585a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// for sources of instructions with this flag.
55943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasExtraSrcRegAllocReq(QueryType Type = AnyInBundle) const {
56043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::ExtraSrcRegAllocReq, Type);
5615a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5625a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5635a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// hasExtraDefRegAllocReq - Returns true if this instruction def operands
5645a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// have special register allocation requirements that are not captured by the
5655a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// operand register classes. e.g. ARM::LDRD's two def registers must be an
5665a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// even / odd pair, ARM::LDM registers have to be in ascending order.
5675a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// Post-register allocation passes should not attempt to change allocations
5685a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  /// for definitions of instructions with this flag.
56943d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng  bool hasExtraDefRegAllocReq(QueryType Type = AnyInBundle) const {
57043d5d4ca1c93529c43e78cc5aa03c4ee10a6b0d8Evan Cheng    return hasProperty(MCID::ExtraDefRegAllocReq, Type);
5715a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng  }
5725a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
5735a96b3dad2f634c9081c8b2b6c2575441dc5a2bdEvan Cheng
574506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng  enum MICheckType {
575506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng    CheckDefs,      // Check all operands for equality
576cbc988be22bc9411d95215c8b7251b5f85710674Evan Cheng    CheckKillDead,  // Check all operands including kill / dead markers
577506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng    IgnoreDefs,     // Ignore all definitions
578506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng    IgnoreVRegDefs  // Ignore virtual register definitions
579506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng  };
580506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng
581fcfcb6cb502fd4562b57425a5802dc52f358c451Chris Lattner  /// isIdenticalTo - Return true if this instruction is identical to (same
582fcfcb6cb502fd4562b57425a5802dc52f358c451Chris Lattner  /// opcode and same operands as) the specified instruction.
583506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng  bool isIdenticalTo(const MachineInstr *Other,
584506049f29f4f202a8e45feb916cc0264440a7f6dEvan Cheng                     MICheckType Check = CheckDefs) const;
585a2bae305fb5a870c4ef753ed290a7ddea73ec82bVikram S. Adve
5866b560918426182d2b46b899d609911d49f6739f7Chris Lattner  /// removeFromParent - This method unlinks 'this' from the containing basic
5876b560918426182d2b46b899d609911d49f6739f7Chris Lattner  /// block, and returns it, but does not delete it.
5886b560918426182d2b46b899d609911d49f6739f7Chris Lattner  MachineInstr *removeFromParent();
589108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
5906b560918426182d2b46b899d609911d49f6739f7Chris Lattner  /// eraseFromParent - This method unlinks 'this' from the containing basic
5916b560918426182d2b46b899d609911d49f6739f7Chris Lattner  /// block and deletes it.
5928e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void eraseFromParent();
593466b534a570f574ed485d875bbca8454f68dcb52Tanya Lattner
5944406604047423576e36657c7ede266ca42e79642Dan Gohman  /// isLabel - Returns true if the MachineInstr represents a label.
5954406604047423576e36657c7ede266ca42e79642Dan Gohman  ///
596518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isLabel() const {
5977431beaba2a01c3fe299c861b2ec85cbf1dc81c4Bill Wendling    return getOpcode() == TargetOpcode::PROLOG_LABEL ||
598518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner           getOpcode() == TargetOpcode::EH_LABEL ||
599518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner           getOpcode() == TargetOpcode::GC_LABEL;
600518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  }
601108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
6027431beaba2a01c3fe299c861b2ec85cbf1dc81c4Bill Wendling  bool isPrologLabel() const {
6037431beaba2a01c3fe299c861b2ec85cbf1dc81c4Bill Wendling    return getOpcode() == TargetOpcode::PROLOG_LABEL;
6047431beaba2a01c3fe299c861b2ec85cbf1dc81c4Bill Wendling  }
605518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isEHLabel() const { return getOpcode() == TargetOpcode::EH_LABEL; }
606518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isGCLabel() const { return getOpcode() == TargetOpcode::GC_LABEL; }
607518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isDebugValue() const { return getOpcode() == TargetOpcode::DBG_VALUE; }
608108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
609518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isPHI() const { return getOpcode() == TargetOpcode::PHI; }
610518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
611518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; }
612518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isInlineAsm() const { return getOpcode() == TargetOpcode::INLINEASM; }
613c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  bool isStackAligningInlineAsm() const;
614576cd11ab8035d4240f7e6ea8d7c6c2e45154f86Chad Rosier  InlineAsm::AsmDialect getInlineAsmDialect() const;
615518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isInsertSubreg() const {
616518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner    return getOpcode() == TargetOpcode::INSERT_SUBREG;
617518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  }
618518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  bool isSubregToReg() const {
619518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner    return getOpcode() == TargetOpcode::SUBREG_TO_REG;
620518bb53485df640d7b7e3f6b0544099020c42aa7Chris Lattner  }
6213d720fbc6ad40bc9287a420f824d244965d24631Evan Cheng  bool isRegSequence() const {
6223d720fbc6ad40bc9287a420f824d244965d24631Evan Cheng    return getOpcode() == TargetOpcode::REG_SEQUENCE;
6233d720fbc6ad40bc9287a420f824d244965d24631Evan Cheng  }
624ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  bool isBundle() const {
625ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng    return getOpcode() == TargetOpcode::BUNDLE;
626ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  }
627a4e1ba53ddedd08669886b2849926bb33facc198Jakob Stoklund Olesen  bool isCopy() const {
628a4e1ba53ddedd08669886b2849926bb33facc198Jakob Stoklund Olesen    return getOpcode() == TargetOpcode::COPY;
629a4e1ba53ddedd08669886b2849926bb33facc198Jakob Stoklund Olesen  }
630cfe5254cd34d9414d9f6b8aa02dc1239d71a703fRafael Espindola  bool isFullCopy() const {
631cfe5254cd34d9414d9f6b8aa02dc1239d71a703fRafael Espindola    return isCopy() && !getOperand(0).getSubReg() && !getOperand(1).getSubReg();
632cfe5254cd34d9414d9f6b8aa02dc1239d71a703fRafael Espindola  }
633a4e1ba53ddedd08669886b2849926bb33facc198Jakob Stoklund Olesen
634273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen  /// isCopyLike - Return true if the instruction behaves like a copy.
635273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen  /// This does not include native copy instructions.
636273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen  bool isCopyLike() const {
6370bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen    return isCopy() || isSubregToReg();
6380bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen  }
6390bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen
6400bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen  /// isIdentityCopy - Return true is the instruction is an identity copy.
6410bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen  bool isIdentityCopy() const {
6420bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen    return isCopy() && getOperand(0).getReg() == getOperand(1).getReg() &&
6430bc25f40402f48ba42fc45403f635b20d90fabb3Jakob Stoklund Olesen      getOperand(0).getSubReg() == getOperand(1).getSubReg();
644273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen  }
645273f7e42994a5bce0614d04d96dbfdf05fd652e5Jakob Stoklund Olesen
6463f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  /// isTransient - Return true if this is a transient instruction that is
6473f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  /// either very likely to be eliminated during register allocation (such as
6483f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  /// copy-like instructions), or if this instruction doesn't have an
6493f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  /// execution-time cost.
6503f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  bool isTransient() const {
6513f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    switch(getOpcode()) {
6523f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    default: return false;
6533f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    // Copy-like instructions are usually eliminated during register allocation.
6543f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::PHI:
6553f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::COPY:
6563f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::INSERT_SUBREG:
6573f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::SUBREG_TO_REG:
6583f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::REG_SEQUENCE:
6593f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    // Pseudo-instructions that don't produce any real output.
6603f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::IMPLICIT_DEF:
6613f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::KILL:
6623f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::PROLOG_LABEL:
6633f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::EH_LABEL:
6643f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::GC_LABEL:
6653f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    case TargetOpcode::DBG_VALUE:
6663f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen      return true;
6673f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen    }
6683f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen  }
6693f63a589788995a724bc4587d022fe15ea8576baJakob Stoklund Olesen
670ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  /// getBundleSize - Return the number of instructions inside the MI bundle.
671ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng  unsigned getBundleSize() const;
672ddfd1377d2e4154d44dc3ad217735adc15af2e3fEvan Cheng
6736130f66eaae89f8878590796977678afa8448926Evan Cheng  /// readsRegister - Return true if the MachineInstr reads the specified
6746130f66eaae89f8878590796977678afa8448926Evan Cheng  /// register. If TargetRegisterInfo is passed, then it also checks if there
6756130f66eaae89f8878590796977678afa8448926Evan Cheng  /// is a read of a super-register.
6767ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  /// This does not count partial redefines of virtual registers as reads:
6777ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  ///   %reg1024:6 = OP.
6786130f66eaae89f8878590796977678afa8448926Evan Cheng  bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
6796130f66eaae89f8878590796977678afa8448926Evan Cheng    return findRegisterUseOperandIdx(Reg, false, TRI) != -1;
6806130f66eaae89f8878590796977678afa8448926Evan Cheng  }
6816130f66eaae89f8878590796977678afa8448926Evan Cheng
6827ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  /// readsVirtualRegister - Return true if the MachineInstr reads the specified
6837ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  /// virtual register. Take into account that a partial define is a
6847ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen  /// read-modify-write operation.
68518b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  bool readsVirtualRegister(unsigned Reg) const {
68618b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen    return readsWritesVirtualRegister(Reg).first;
68718b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  }
68818b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen
68918b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  /// readsWritesVirtualRegister - Return a pair of bools (reads, writes)
69018b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  /// indicating if this instruction reads or writes Reg. This also considers
69118b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  /// partial defines.
69218b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  /// If Ops is not null, all operand indices for Reg are added.
69318b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen  std::pair<bool,bool> readsWritesVirtualRegister(unsigned Reg,
69418b2c9d3bf5a6633535eaad8388f0353b14cbfb8Jakob Stoklund Olesen                                      SmallVectorImpl<unsigned> *Ops = 0) const;
6957ebc4d63db05ac214d36bc01b4d60adadaf923e5Jakob Stoklund Olesen
6966130f66eaae89f8878590796977678afa8448926Evan Cheng  /// killsRegister - Return true if the MachineInstr kills the specified
6976130f66eaae89f8878590796977678afa8448926Evan Cheng  /// register. If TargetRegisterInfo is passed, then it also checks if there is
6986130f66eaae89f8878590796977678afa8448926Evan Cheng  /// a kill of a super-register.
6996130f66eaae89f8878590796977678afa8448926Evan Cheng  bool killsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
7006130f66eaae89f8878590796977678afa8448926Evan Cheng    return findRegisterUseOperandIdx(Reg, true, TRI) != -1;
7016130f66eaae89f8878590796977678afa8448926Evan Cheng  }
7026130f66eaae89f8878590796977678afa8448926Evan Cheng
7031015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// definesRegister - Return true if the MachineInstr fully defines the
7046130f66eaae89f8878590796977678afa8448926Evan Cheng  /// specified register. If TargetRegisterInfo is passed, then it also checks
7056130f66eaae89f8878590796977678afa8448926Evan Cheng  /// if there is a def of a super-register.
7061015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// NOTE: It's ignoring subreg indices on virtual registers.
7071015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  bool definesRegister(unsigned Reg, const TargetRegisterInfo *TRI=NULL) const {
7081015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng    return findRegisterDefOperandIdx(Reg, false, false, TRI) != -1;
7091015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  }
7101015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng
7111015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// modifiesRegister - Return true if the MachineInstr modifies (fully define
7121015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// or partially define) the specified register.
7131015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// NOTE: It's ignoring subreg indices on virtual registers.
7141015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  bool modifiesRegister(unsigned Reg, const TargetRegisterInfo *TRI) const {
7151015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng    return findRegisterDefOperandIdx(Reg, false, true, TRI) != -1;
7166130f66eaae89f8878590796977678afa8448926Evan Cheng  }
7176130f66eaae89f8878590796977678afa8448926Evan Cheng
7186130f66eaae89f8878590796977678afa8448926Evan Cheng  /// registerDefIsDead - Returns true if the register is dead in this machine
7196130f66eaae89f8878590796977678afa8448926Evan Cheng  /// instruction. If TargetRegisterInfo is passed, then it also checks
7206130f66eaae89f8878590796977678afa8448926Evan Cheng  /// if there is a dead def of a super-register.
7216130f66eaae89f8878590796977678afa8448926Evan Cheng  bool registerDefIsDead(unsigned Reg,
7226130f66eaae89f8878590796977678afa8448926Evan Cheng                         const TargetRegisterInfo *TRI = NULL) const {
7231015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng    return findRegisterDefOperandIdx(Reg, true, false, TRI) != -1;
7246130f66eaae89f8878590796977678afa8448926Evan Cheng  }
7256130f66eaae89f8878590796977678afa8448926Evan Cheng
726faa510726f4b40aa4495e60e4d341c6467e3fb01Evan Cheng  /// findRegisterUseOperandIdx() - Returns the operand index that is a use of
72710f9101c4c0df0837414976ad0ef0e86d6771059Jim Grosbach  /// the specific register or -1 if it is not found. It further tightens
72876d7e76c15c258ec4a71fd75a2a32bca3a5e5e27Evan Cheng  /// the search criteria to a use that kills the register if isKill is true.
7296130f66eaae89f8878590796977678afa8448926Evan Cheng  int findRegisterUseOperandIdx(unsigned Reg, bool isKill = false,
7306130f66eaae89f8878590796977678afa8448926Evan Cheng                                const TargetRegisterInfo *TRI = NULL) const;
7316130f66eaae89f8878590796977678afa8448926Evan Cheng
7326130f66eaae89f8878590796977678afa8448926Evan Cheng  /// findRegisterUseOperand - Wrapper for findRegisterUseOperandIdx, it returns
7336130f66eaae89f8878590796977678afa8448926Evan Cheng  /// a pointer to the MachineOperand rather than an index.
7349180c8e3cfd12abd21242768db05072a209ca6e7Evan Cheng  MachineOperand *findRegisterUseOperand(unsigned Reg, bool isKill = false,
7356130f66eaae89f8878590796977678afa8448926Evan Cheng                                         const TargetRegisterInfo *TRI = NULL) {
7366130f66eaae89f8878590796977678afa8448926Evan Cheng    int Idx = findRegisterUseOperandIdx(Reg, isKill, TRI);
7376130f66eaae89f8878590796977678afa8448926Evan Cheng    return (Idx == -1) ? NULL : &getOperand(Idx);
7386130f66eaae89f8878590796977678afa8448926Evan Cheng  }
739108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
7406130f66eaae89f8878590796977678afa8448926Evan Cheng  /// findRegisterDefOperandIdx() - Returns the operand index that is a def of
741703bfe69092e8da79fbef2fc5ca07b805ad9f753Dan Gohman  /// the specified register or -1 if it is not found. If isDead is true, defs
7421015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// that are not dead are skipped. If Overlap is true, then it also looks for
7431015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// defs that merely overlap the specified register. If TargetRegisterInfo is
7441015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  /// non-null, then it also checks if there is a def of a super-register.
7451cf8b0f2a5435d8444b6cc7d4a27eef424398273Jakob Stoklund Olesen  /// This may also return a register mask operand when Overlap is true.
7461015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng  int findRegisterDefOperandIdx(unsigned Reg,
7471015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng                                bool isDead = false, bool Overlap = false,
7486130f66eaae89f8878590796977678afa8448926Evan Cheng                                const TargetRegisterInfo *TRI = NULL) const;
7496130f66eaae89f8878590796977678afa8448926Evan Cheng
7506130f66eaae89f8878590796977678afa8448926Evan Cheng  /// findRegisterDefOperand - Wrapper for findRegisterDefOperandIdx, it returns
7516130f66eaae89f8878590796977678afa8448926Evan Cheng  /// a pointer to the MachineOperand rather than an index.
752631bd3cdf39eb099d5d5d279b17b08f119956538Evan Cheng  MachineOperand *findRegisterDefOperand(unsigned Reg, bool isDead = false,
7536130f66eaae89f8878590796977678afa8448926Evan Cheng                                         const TargetRegisterInfo *TRI = NULL) {
7541015ba7018c87f48cc7bb45a564eb4a27241e76aEvan Cheng    int Idx = findRegisterDefOperandIdx(Reg, isDead, false, TRI);
7556130f66eaae89f8878590796977678afa8448926Evan Cheng    return (Idx == -1) ? NULL : &getOperand(Idx);
7566130f66eaae89f8878590796977678afa8448926Evan Cheng  }
75719e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng
758f277ee4be7edabb759a7f78138b693d72d0c263fEvan Cheng  /// findFirstPredOperandIdx() - Find the index of the first operand in the
759f277ee4be7edabb759a7f78138b693d72d0c263fEvan Cheng  /// operand list that is used to represent the predicate. It returns -1 if
760f277ee4be7edabb759a7f78138b693d72d0c263fEvan Cheng  /// none is found.
761f277ee4be7edabb759a7f78138b693d72d0c263fEvan Cheng  int findFirstPredOperandIdx() const;
762108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
7639dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// findInlineAsmFlagIdx() - Find the index of the flag word operand that
7649dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// corresponds to operand OpIdx on an inline asm instruction.  Returns -1 if
7659dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// getOperand(OpIdx) does not belong to an inline asm operand group.
7669dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  ///
7679dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// If GroupNo is not NULL, it will receive the number of the operand group
7689dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// containing OpIdx.
7699dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  ///
7709dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// The flag operand is an immediate that can be decoded with methods like
7719dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  /// InlineAsm::hasRegClassConstraint().
7729dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  ///
7739dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen  int findInlineAsmFlagIdx(unsigned OpIdx, unsigned *GroupNo = 0) const;
7749dfaacb696d1ad850f9f5f49a94fdb81cf8ae018Jakob Stoklund Olesen
775f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// getRegClassConstraint - Compute the static register class constraint for
776f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// operand OpIdx.  For normal instructions, this is derived from the
777f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// MCInstrDesc.  For inline assembly it is derived from the flag words.
778f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  ///
779f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// Returns NULL if the static register classs constraint cannot be
780f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  /// determined.
781f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  ///
782f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  const TargetRegisterClass*
783f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen  getRegClassConstraint(unsigned OpIdx,
784f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen                        const TargetInstrInfo *TII,
785f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen                        const TargetRegisterInfo *TRI) const;
786f5916976e9057177100badee7b7388bd7ba76ac3Jakob Stoklund Olesen
78794083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen  /// tieOperands - Add a tie between the register operands at DefIdx and
78894083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen  /// UseIdx. The tie will cause the register allocator to ensure that the two
78994083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen  /// operands are assigned the same physical register.
79094083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen  ///
79194083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen  /// Tied operands are managed automatically for explicit operands in the
79294083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen  /// MCInstrDesc. This method is for exceptional cases like inline asm.
79394083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen  void tieOperands(unsigned DefIdx, unsigned UseIdx);
79494083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen
795699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  /// findTiedOperandIdx - Given the index of a tied register operand, find the
796699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  /// operand it is tied to. Defs are tied to uses and vice versa. Returns the
797699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  /// index of the tied operand which must exist.
798699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  unsigned findTiedOperandIdx(unsigned OpIdx) const;
799699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen
800d9df5017040489303acb57bdd8697ef0f8bafc08Bob Wilson  /// isRegTiedToUseOperand - Given the index of a register def operand,
801d9df5017040489303acb57bdd8697ef0f8bafc08Bob Wilson  /// check if the register def is tied to a source operand, due to either
802d9df5017040489303acb57bdd8697ef0f8bafc08Bob Wilson  /// two-address elimination or inline assembly constraints. Returns the
803a21bb20f5943f5f4c66d4727784c26007db2470cJim Grosbach  /// first tied use operand index by reference if UseOpIdx is not null.
80499c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen  bool isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx = 0) const {
80599c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen    const MachineOperand &MO = getOperand(DefOpIdx);
80699c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen    if (!MO.isReg() || !MO.isDef() || !MO.isTied())
80799c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen      return false;
80899c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen    if (UseOpIdx)
80999c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen      *UseOpIdx = findTiedOperandIdx(DefOpIdx);
81099c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen    return true;
81199c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen  }
81232dfbeada7292167bb488f36a71a5a6a519ddaffEvan Cheng
813a24752ff43dc1ad8c18c5d9e78549c45f62b980eEvan Cheng  /// isRegTiedToDefOperand - Return true if the use operand of the specified
814a24752ff43dc1ad8c18c5d9e78549c45f62b980eEvan Cheng  /// index is tied to an def operand. It also returns the def operand index by
815a24752ff43dc1ad8c18c5d9e78549c45f62b980eEvan Cheng  /// reference if DefOpIdx is not null.
81699c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen  bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx = 0) const {
81799c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen    const MachineOperand &MO = getOperand(UseOpIdx);
81899c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen    if (!MO.isReg() || !MO.isUse() || !MO.isTied())
81999c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen      return false;
82099c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen    if (DefOpIdx)
82199c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen      *DefOpIdx = findTiedOperandIdx(UseOpIdx);
82299c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen    return true;
82399c416c9f7e8a9d7d1038d03cafebec730280398Jakob Stoklund Olesen  }
824a24752ff43dc1ad8c18c5d9e78549c45f62b980eEvan Cheng
825e6cd757e6800b9b94a6459ec148c0624c4f2e3c1Dan Gohman  /// clearKillInfo - Clears kill flags on all operands.
826e6cd757e6800b9b94a6459ec148c0624c4f2e3c1Dan Gohman  ///
827e6cd757e6800b9b94a6459ec148c0624c4f2e3c1Dan Gohman  void clearKillInfo();
828e6cd757e6800b9b94a6459ec148c0624c4f2e3c1Dan Gohman
8299a00279988612d0f960fb8d43e4ccfcab89e0e14Evan Cheng  /// copyKillDeadInfo - Copies kill / dead operand properties from MI.
8309a00279988612d0f960fb8d43e4ccfcab89e0e14Evan Cheng  ///
831576d123e130a8291669dd2384a3735cc4933fd00Evan Cheng  void copyKillDeadInfo(const MachineInstr *MI);
8329a00279988612d0f960fb8d43e4ccfcab89e0e14Evan Cheng
83319e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  /// copyPredicates - Copies predicate operand(s) from MI.
83419e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng  void copyPredicates(const MachineInstr *MI);
83519e3f31f6acd9f5ce3cdd8372d4cb598ed921f95Evan Cheng
8369edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen  /// substituteRegister - Replace all occurrences of FromReg with ToReg:SubIdx,
8379edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen  /// properly composing subreg indices where necessary.
8389edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen  void substituteRegister(unsigned FromReg, unsigned ToReg, unsigned SubIdx,
8399edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen                          const TargetRegisterInfo &RegInfo);
8409edf7deb37f0f97664f279040fa15d89f32e23d9Jakob Stoklund Olesen
841b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// addRegisterKilled - We have determined MI kills a register. Look for the
842b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
843b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// add a implicit operand if it's not found. Returns true if the operand
844b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// exists / is added.
8456f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohman  bool addRegisterKilled(unsigned IncomingReg,
8466f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohman                         const TargetRegisterInfo *RegInfo,
847b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson                         bool AddIfNotFound = false);
8488efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen
8491a96c914315b0286d84c507d696484e2c95875a4Jakob Stoklund Olesen  /// clearRegisterKills - Clear all kill flags affecting Reg.  If RegInfo is
8501a96c914315b0286d84c507d696484e2c95875a4Jakob Stoklund Olesen  /// provided, this includes super-register kills.
8511a96c914315b0286d84c507d696484e2c95875a4Jakob Stoklund Olesen  void clearRegisterKills(unsigned Reg, const TargetRegisterInfo *RegInfo);
8521a96c914315b0286d84c507d696484e2c95875a4Jakob Stoklund Olesen
853b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// addRegisterDead - We have determined MI defined a register without a use.
854b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// Look for the operand that defines it and mark it as IsDead. If
855b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
856b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson  /// true if the operand exists / is added.
8576f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohman  bool addRegisterDead(unsigned IncomingReg, const TargetRegisterInfo *RegInfo,
858b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson                       bool AddIfNotFound = false);
859b487e7215c4f70f3d98f8fbc0a11eb119afc1f37Owen Anderson
8608efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen  /// addRegisterDefined - We have determined MI defines a register. Make sure
8618efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen  /// there is an operand defining Reg.
8628efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen  void addRegisterDefined(unsigned IncomingReg,
86363e6a488cb6c29983415221719d05fbf99e00193Jakob Stoklund Olesen                          const TargetRegisterInfo *RegInfo = 0);
8648efadf94b568c08de3ff8ce35fd904a935387406Jakob Stoklund Olesen
8652a09f878ef64f216268df3dbe2f51b949f18c145Jim Grosbach  /// setPhysRegsDeadExcept - Mark every physreg used by this instruction as
8662a09f878ef64f216268df3dbe2f51b949f18c145Jim Grosbach  /// dead except those in the UsedRegs list.
86777180e0b402fff318cffd89a2251e46b3dce4064Jakob Stoklund Olesen  ///
86877180e0b402fff318cffd89a2251e46b3dce4064Jakob Stoklund Olesen  /// On instructions with register mask operands, also add implicit-def
86977180e0b402fff318cffd89a2251e46b3dce4064Jakob Stoklund Olesen  /// operands for all registers in UsedRegs.
870a37818dbb119bda75273f16b8484732e742cdbb7Jakob Stoklund Olesen  void setPhysRegsDeadExcept(ArrayRef<unsigned> UsedRegs,
871db4971259ce94cea26e555e9ade82672a3581f5cDan Gohman                             const TargetRegisterInfo &TRI);
872db4971259ce94cea26e555e9ade82672a3581f5cDan Gohman
8739f1c8317a4676945b4961ddb9827ef2412551620Evan Cheng  /// isSafeToMove - Return true if it is safe to move this instruction. If
8749f1c8317a4676945b4961ddb9827ef2412551620Evan Cheng  /// SawStore is set to true, it means that there is a store (or call) between
8759f1c8317a4676945b4961ddb9827ef2412551620Evan Cheng  /// the instruction's location and its intended destination.
876ac1abde05b7e6956c01deb6557539bee8fea30f4Evan Cheng  bool isSafeToMove(const TargetInstrInfo *TII, AliasAnalysis *AA,
877ac1abde05b7e6956c01deb6557539bee8fea30f4Evan Cheng                    bool &SawStore) const;
878b27087f5aa574f875598f4a309b7dd687c64a455Evan Cheng
8793e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  /// isSafeToReMat - Return true if it's safe to rematerialize the specified
8803e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman  /// instruction which defined the specified register instead of copying it.
881ac1abde05b7e6956c01deb6557539bee8fea30f4Evan Cheng  bool isSafeToReMat(const TargetInstrInfo *TII, AliasAnalysis *AA,
882ac1abde05b7e6956c01deb6557539bee8fea30f4Evan Cheng                     unsigned DstReg) const;
883df3b99381f1c211071cc1daf0cc297666877bbcbEvan Cheng
884f036f7a1e79910bf5b5b6f37d2e512b4f01155a0Jakob Stoklund Olesen  /// hasOrderedMemoryRef - Return true if this instruction may have an ordered
885f036f7a1e79910bf5b5b6f37d2e512b4f01155a0Jakob Stoklund Olesen  /// or volatile memory reference, or if the information describing the memory
886f036f7a1e79910bf5b5b6f37d2e512b4f01155a0Jakob Stoklund Olesen  /// reference is not available. Return false if it is known to have no
887f036f7a1e79910bf5b5b6f37d2e512b4f01155a0Jakob Stoklund Olesen  /// ordered or volatile memory references.
888f036f7a1e79910bf5b5b6f37d2e512b4f01155a0Jakob Stoklund Olesen  bool hasOrderedMemoryRef() const;
8893e4fb70c6af53a2d00e057a7e4a8f93eb2ff2112Dan Gohman
890e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman  /// isInvariantLoad - Return true if this instruction is loading from a
891e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman  /// location whose value is invariant across the function.  For example,
892f451cb870efcf9e0302d25ed05f4cac6bb494e42Dan Gohman  /// loading a value from the constant pool or from the argument area of
893e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman  /// a function if it does not change.  This should only return true of *all*
894e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman  /// loads the instruction does are invariant (if it does multiple loads).
895a70dca156fa76d452f54829b5c5f962ddfd94ef2Dan Gohman  bool isInvariantLoad(AliasAnalysis *AA) const;
896e33f44cfc547359bc28526e4c5e1852b600b4448Dan Gohman
897229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng  /// isConstantValuePHI - If the specified instruction is a PHI that always
898229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng  /// merges together the same virtual register, return the register, otherwise
899229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng  /// return 0.
900229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng  unsigned isConstantValuePHI() const;
901229694f0ee630ceabe96a8bd48952f6740f928b2Evan Cheng
902c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  /// hasUnmodeledSideEffects - Return true if this instruction has side
903c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  /// effects that are not modeled by mayLoad / mayStore, etc.
904e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// For all instructions, the property is encoded in MCInstrDesc::Flags
905e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  /// (see MCInstrDesc::hasUnmodeledSideEffects(). The only exception is
906c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  /// INLINEASM instruction, in which case the side effect property is encoded
907c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  /// in one of its operands (see InlineAsm::Extra_HasSideEffect).
908c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  ///
909c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng  bool hasUnmodeledSideEffects() const;
910c36b7069b42bece963b7e6adf020353ce990ef76Evan Cheng
911a57fabe815ccf016eead526eb3ef475f116ab155Evan Cheng  /// allDefsAreDead - Return true if all the defs of this instruction are dead.
912a57fabe815ccf016eead526eb3ef475f116ab155Evan Cheng  ///
913a57fabe815ccf016eead526eb3ef475f116ab155Evan Cheng  bool allDefsAreDead() const;
914a57fabe815ccf016eead526eb3ef475f116ab155Evan Cheng
915b179b46cc558c720d23a066c768bad71f975eb93Evan Cheng  /// copyImplicitOps - Copy implicit register operands from specified
916b179b46cc558c720d23a066c768bad71f975eb93Evan Cheng  /// instruction to this instruction.
917b179b46cc558c720d23a066c768bad71f975eb93Evan Cheng  void copyImplicitOps(const MachineInstr *MI);
918b179b46cc558c720d23a066c768bad71f975eb93Evan Cheng
919a995e6086deca9cbd9aab9d6e1e94b36964b66daVikram S. Adve  //
920a995e6086deca9cbd9aab9d6e1e94b36964b66daVikram S. Adve  // Debugging support
921fa78fbf446b505767e838f9c188707183c57fc9cChris Lattner  //
922cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson  void print(raw_ostream &OS, const TargetMachine *TM = 0) const;
923572f5c8c0cf66cd6f53dda255cd8c4d8f27d8505Chris Lattner  void dump() const;
9242f898d207466bf233b55607e404baca302bc7b5eChris Lattner
925413746e9833d97a8b463ef6a788aa326cf3829a2Chris Lattner  //===--------------------------------------------------------------------===//
92662ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  // Accessors used to build up machine instructions.
9277ad6be7b01a902f532eebb607306f7b3f4627718Chris Lattner
92862ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// addOperand - Add the specified operand to the instruction.  If it is an
92962ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// implicit operand, it is added to the end of the operand list.  If it is
93062ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// an explicit operand it is added at the end of the explicit operand list
931108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach  /// (before the first implicit operand).
93262ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  void addOperand(const MachineOperand &Op);
933108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
9345080f4d9919d39b367891dc51e739c571a66036cChris Lattner  /// setDesc - Replace the instruction descriptor (thus opcode) of
93567f660cb080965ea93ed6d7265a67100f2fe38e4Evan Cheng  /// the current instruction with a new one.
9363c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner  ///
937e837dead3c8dc3445ef6a0e2322179c57e264a13Evan Cheng  void setDesc(const MCInstrDesc &tid) { MCID = &tid; }
9383c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner
93906efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  /// setDebugLoc - Replace current source information with new such.
940ab160cf371d6148d49b5401a903dd4ce381b2f8cDale Johannesen  /// Avoid using this, the constructor argument is preferable.
94106efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  ///
94206efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen  void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
94306efc02854a96a9f92edc3bf46b0451f488cf2e6Dale Johannesen
9443c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner  /// RemoveOperand - Erase an operand  from an instruction, leaving it with one
9453c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner  /// fewer operand than it started with.
9463c8cbe6567c94fdd24ec9b2b8b5c5cc1b01a8c58Chris Lattner  ///
94762ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  void RemoveOperand(unsigned i);
94862ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner
949c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// addMemOperand - Add a MachineMemOperand to the machine instruction.
950c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// This function should be used only occasionally. The setMemRefs function
951c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// is the primary method for setting up a MachineInstr's MemRefs list.
952c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  void addMemOperand(MachineFunction &MF, MachineMemOperand *MO);
9538e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
954c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// setMemRefs - Assign this MachineInstr's memory reference descriptor
955c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// list. This does not transfer ownership.
956c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
957c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman    MemRefs = NewMemRefs;
958861ea230a7841fe4ccc8a1cd5460354e59aeed3cBenjamin Kramer    NumMemRefs = NewMemRefsEnd - NewMemRefs;
959c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  }
96069de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
961943b5e117fe9a087f9aa529a2632c2d32cc22374Chris Lattnerprivate:
96262ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// getRegInfo - If this instruction is embedded into a MachineFunction,
96362ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// return the MachineRegisterInfo object for the current function, otherwise
96462ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// return null.
96562ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  MachineRegisterInfo *getRegInfo();
966d7de496b23fca8145f777a56281457bf64e8bbadEvan Cheng
967699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  /// untieRegOperand - Break any tie involving OpIdx.
968699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  void untieRegOperand(unsigned OpIdx) {
96994083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen    MachineOperand &MO = getOperand(OpIdx);
97094083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen    if (MO.isReg() && MO.isTied()) {
971c8ecb401caefc5fb97b20041544d8da5d8e2f830Jakob Stoklund Olesen      getOperand(findTiedOperandIdx(OpIdx)).TiedTo = 0;
972c8ecb401caefc5fb97b20041544d8da5d8e2f830Jakob Stoklund Olesen      MO.TiedTo = 0;
97394083149fd6891c8a72472cf1814fa6600a75979Jakob Stoklund Olesen    }
974699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen  }
975699ac049517285d978ed607b2735976c5ae97ac0Jakob Stoklund Olesen
976d7de496b23fca8145f777a56281457bf64e8bbadEvan Cheng  /// addImplicitDefUseOperands - Add all implicit def and use operands to
977d7de496b23fca8145f777a56281457bf64e8bbadEvan Cheng  /// this instruction.
97867f660cb080965ea93ed6d7265a67100f2fe38e4Evan Cheng  void addImplicitDefUseOperands();
979108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
98062ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// RemoveRegOperandsFromUseLists - Unlink all of the register operands in
98162ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// this instruction from their respective use lists.  This requires that the
98262ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// operands already be on their use lists.
983ff2b99afc8cbc6cfa73181072888e0f9f07deb7eJakob Stoklund Olesen  void RemoveRegOperandsFromUseLists(MachineRegisterInfo&);
984108e4dbecb690056e678da2f15c56ef7220f9ec9Jim Grosbach
98562ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// AddRegOperandsToUseLists - Add all of the register operands in
98662ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// this instruction from their respective use lists.  This requires that the
98762ed6b9ade63bf01717ce5274fa11e93e873d245Chris Lattner  /// operands not be on their use lists yet.
988ff2b99afc8cbc6cfa73181072888e0f9f07deb7eJakob Stoklund Olesen  void AddRegOperandsToUseLists(MachineRegisterInfo&);
98985f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer
99085f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  /// hasPropertyInBundle - Slow path for hasProperty when we're dealing with a
99185f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  /// bundle.
99285f9cef27e6b2605e67e94afc949f5b5f5b90668Benjamin Kramer  bool hasPropertyInBundle(unsigned Mask, QueryType Type) const;
993a995e6086deca9cbd9aab9d6e1e94b36964b66daVikram S. Adve};
99423ee550765232e22d0daf6407141ecef4c55c06fVikram S. Adve
99505bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng/// MachineInstrExpressionTrait - Special DenseMapInfo traits to compare
99605bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng/// MachineInstr* by *value* of the instruction rather than by pointer value.
99705bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng/// The hashing and equality testing functions ignore definitions so this is
99805bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng/// useful for CSE, etc.
99905bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Chengstruct MachineInstrExpressionTrait : DenseMapInfo<MachineInstr*> {
100005bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  static inline MachineInstr *getEmptyKey() {
100105bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng    return 0;
100205bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  }
100305bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng
100405bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  static inline MachineInstr *getTombstoneKey() {
100505bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng    return reinterpret_cast<MachineInstr*>(-1);
100605bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  }
100705bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng
100867eaa08f2b71aa8aec8cdf4c7d970db4cad58adaEvan Cheng  static unsigned getHashValue(const MachineInstr* const &MI);
100905bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng
101005bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  static bool isEqual(const MachineInstr* const &LHS,
101105bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng                      const MachineInstr* const &RHS) {
101205bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng    if (RHS == getEmptyKey() || RHS == getTombstoneKey() ||
101305bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng        LHS == getEmptyKey() || LHS == getTombstoneKey())
101405bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng      return LHS == RHS;
101505bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng    return LHS->isIdenticalTo(RHS, MachineInstr::IgnoreVRegDefs);
101605bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng  }
101705bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng};
101805bdcbb1ae48d1d1209173d137d11c35f46abff3Evan Cheng
1019b05497e0ca1ba2e7f57b792cc160e5d1c8579582Chris Lattner//===----------------------------------------------------------------------===//
1020593da4acc56d4c591ad688e6605b04d0825c867eVikram S. Adve// Debugging Support
1021593da4acc56d4c591ad688e6605b04d0825c867eVikram S. Adve
1022cb3718832375a581c5ea23f15918f3ea447a446cOwen Andersoninline raw_ostream& operator<<(raw_ostream &OS, const MachineInstr &MI) {
1023cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson  MI.print(OS);
1024cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson  return OS;
1025cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson}
1026cb3718832375a581c5ea23f15918f3ea447a446cOwen Anderson
1027d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
1028d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
102923ee550765232e22d0daf6407141ecef4c55c06fVikram S. Adve#endif
1030