X86InstrInfo.h revision beac75da3784929aee9f0357fc5cd76d49d6c3d7
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//===- X86InstrInfo.h - X86 Instruction Information ------------*- C++ -*- ===//
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//                     The LLVM Compiler Infrastructure
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// This file is distributed under the University of Illinois Open Source
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// License. See LICENSE.TXT for details.
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//===----------------------------------------------------------------------===//
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// This file contains the X86 implementation of the TargetInstrInfo class.
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//===----------------------------------------------------------------------===//
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef X86INSTRUCTIONINFO_H
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define X86INSTRUCTIONINFO_H
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/Target/TargetInstrInfo.h"
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "X86.h"
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "X86RegisterInfo.h"
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/ADT/DenseMap.h"
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace llvm {
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  class X86RegisterInfo;
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  class X86TargetMachine;
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace X86 {
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Enums for memory operand decoding.  Each memory operand is represented with
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // a 5 operand sequence in the form:
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  //   [BaseReg, ScaleAmt, IndexReg, Disp, Segment]
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // These enums help decode this.
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  enum {
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AddrBaseReg = 0,
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AddrScaleAmt = 1,
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AddrIndexReg = 2,
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AddrDisp = 3,
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// AddrSegmentReg - The operand # of the segment in the memory operand.
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AddrSegmentReg = 4,
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// AddrNumOperands - Total number of operands in a memory reference.
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AddrNumOperands = 5
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  };
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // X86 specific condition code. These correspond to X86_*_COND in
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // X86InstrInfo.td. They must be kept in synch.
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  enum CondCode {
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_A  = 0,
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_AE = 1,
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_B  = 2,
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_BE = 3,
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_E  = 4,
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_G  = 5,
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_GE = 6,
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_L  = 7,
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_LE = 8,
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_NE = 9,
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_NO = 10,
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_NP = 11,
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_NS = 12,
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_O  = 13,
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_P  = 14,
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_S  = 15,
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Artificial condition codes. These are used by AnalyzeBranch
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // to indicate a block terminated with two conditional branches to
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // the same location. This occurs in code using FCMP_OEQ or FCMP_UNE,
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // which can't be represented on x86 with a single condition. These
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // are never used in MachineInstrs.
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_NE_OR_P,
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_NP_OR_E,
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    COND_INVALID
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  };
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Turn condition code into conditional branch opcode.
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  unsigned GetCondBranchFromCond(CondCode CC);
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// GetOppositeBranchCondition - Return the inverse of the specified cond,
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// e.g. turning COND_E to COND_NE.
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  CondCode GetOppositeBranchCondition(X86::CondCode CC);
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// X86II - This namespace holds all of the target specific flags that
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// instruction info tracks.
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry///
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace X86II {
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// Target Operand Flag enum.
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  enum TOF {
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //===------------------------------------------------------------------===//
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // X86 Specific MachineOperand flags.
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_NO_FLAG,
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// relocation of:
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL + [. - PICBASELABEL]
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_GOT_ABSOLUTE_ADDRESS,
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// immediate should get the value of the symbol minus the PIC base label:
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL - PICBASELABEL
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_PIC_BASE_OFFSET,
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_GOT - On a symbol operand this indicates that the immediate is the
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// offset to the GOT entry for the symbol name from the base of the GOT.
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See the X86-64 ELF ABI supplement for more details.
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @GOT
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_GOT,
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_GOTOFF - On a symbol operand this indicates that the immediate is
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// the offset to the location of the symbol name from the base of the GOT.
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See the X86-64 ELF ABI supplement for more details.
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @GOTOFF
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_GOTOFF,
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_GOTPCREL - On a symbol operand this indicates that the immediate is
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// offset to the GOT entry for the symbol name from the current code
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// location.
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See the X86-64 ELF ABI supplement for more details.
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @GOTPCREL
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_GOTPCREL,
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_PLT - On a symbol operand this indicates that the immediate is
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// offset to the PLT entry of symbol name from the current code location.
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See the X86-64 ELF ABI supplement for more details.
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @PLT
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_PLT,
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_TLSGD - On a symbol operand this indicates that the immediate is
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// some TLS offset.
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See 'ELF Handling for Thread-Local Storage' for more details.
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @TLSGD
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_TLSGD,
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// some TLS offset.
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See 'ELF Handling for Thread-Local Storage' for more details.
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @GOTTPOFF
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_GOTTPOFF,
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_INDNTPOFF - On a symbol operand this indicates that the immediate is
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// some TLS offset.
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See 'ELF Handling for Thread-Local Storage' for more details.
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @INDNTPOFF
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_INDNTPOFF,
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_TPOFF - On a symbol operand this indicates that the immediate is
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// some TLS offset.
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See 'ELF Handling for Thread-Local Storage' for more details.
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @TPOFF
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_TPOFF,
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_NTPOFF - On a symbol operand this indicates that the immediate is
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// some TLS offset.
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// See 'ELF Handling for Thread-Local Storage' for more details.
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///    SYMBOL_LABEL @NTPOFF
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_NTPOFF,
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// reference is actually to the "__imp_FOO" symbol.  This is used for
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// dllimport linkage on windows.
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_DLLIMPORT,
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_DARWIN_STUB - On a symbol operand "FOO", this indicates that the
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// reference is actually to the "FOO$stub" symbol.  This is used for calls
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// and jumps to external functions on Tiger and before.
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_DARWIN_STUB,
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// reference is actually to the "FOO$non_lazy_ptr" symbol, which is a
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// non-PIC-base-relative reference to a non-hidden dyld lazy pointer stub.
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_DARWIN_NONLAZY,
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// that the reference is actually to "FOO$non_lazy_ptr - PICBASE", which is
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// a PIC-base-relative reference to a non-hidden dyld lazy pointer stub.
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_DARWIN_NONLAZY_PIC_BASE,
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// indicates that the reference is actually to "FOO$non_lazy_ptr -PICBASE",
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// which is a PIC-base-relative reference to a hidden dyld lazy pointer
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// stub.
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE,
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_TLVP - On a symbol operand this indicates that the immediate is
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// some TLS offset.
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// This is the TLS offset for the Darwin TLS mechanism.
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_TLVP,
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// is some TLS offset from the picbase.
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// This is the 32-bit TLS offset for Darwin TLS in PIC mode.
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MO_TLVP_PIC_BASE
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  };
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// isGlobalStubReference - Return true if the specified TargetFlag operand is
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// a reference to a stub for a global, not the global itself.
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline static bool isGlobalStubReference(unsigned char TargetFlag) {
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  switch (TargetFlag) {
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_DLLIMPORT: // dllimport stub.
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_GOTPCREL:  // rip-relative GOT reference.
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_GOT:       // normal GOT reference.
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_DARWIN_NONLAZY_PIC_BASE:        // Normal $non_lazy_ptr ref.
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_DARWIN_NONLAZY:                 // Normal $non_lazy_ptr ref.
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Hidden $non_lazy_ptr ref.
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    return true;
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  default:
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    return false;
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// isGlobalRelativeToPICBase - Return true if the specified global value
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg).  If this
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// is true, the addressing mode has the PIC base register added in (e.g. EBX).
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  switch (TargetFlag) {
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_GOTOFF:                         // isPICStyleGOT: local global.
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_GOT:                            // isPICStyleGOT: other global.
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_PIC_BASE_OFFSET:                // Darwin local global.
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_DARWIN_NONLAZY_PIC_BASE:        // Darwin/32 external global.
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Darwin/32 hidden global.
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  case X86II::MO_TLVP:                           // ??? Pretty sure..
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    return true;
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  default:
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    return false;
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// X86II - This namespace holds all of the target specific flags that
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// instruction info tracks.
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry///
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace X86II {
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  enum {
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //===------------------------------------------------------------------===//
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Instruction encodings.  These are the standard/most common forms for X86
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // instructions.
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // PseudoFrm - This represents an instruction that is a pseudo instruction
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // or one that has not been implemented yet.  It is illegal to code generate
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // it, but tolerated for intermediate implementation stages.
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Pseudo         = 0,
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// Raw - This form is for instructions that don't have any operands, so
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// they are just a fixed opcode value, like 'leave'.
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    RawFrm         = 1,
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// AddRegFrm - This form is used for instructions like 'push r32' that have
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// their one register operand added to their opcode.
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AddRegFrm      = 2,
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MRMDestReg - This form is used for instructions that use the Mod/RM byte
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// to specify a destination, which in this case is a register.
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRMDestReg     = 3,
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MRMDestMem - This form is used for instructions that use the Mod/RM byte
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// to specify a destination, which in this case is memory.
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRMDestMem     = 4,
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MRMSrcReg - This form is used for instructions that use the Mod/RM byte
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// to specify a source, which in this case is a register.
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRMSrcReg      = 5,
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MRMSrcMem - This form is used for instructions that use the Mod/RM byte
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// to specify a source, which in this case is memory.
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRMSrcMem      = 6,
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// MRM[0-7][rm] - These forms are used to represent instructions that use
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// a Mod/RM byte, and use the middle field to hold extended opcode
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// information.  In the intel manual these are represented as /0, /1, ...
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ///
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // First, instructions that operate on a register r/m operand...
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM0r = 16,  MRM1r = 17,  MRM2r = 18,  MRM3r = 19, // Format /0 /1 /2 /3
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM4r = 20,  MRM5r = 21,  MRM6r = 22,  MRM7r = 23, // Format /4 /5 /6 /7
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Next, instructions that operate on a memory r/m operand...
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM0m = 24,  MRM1m = 25,  MRM2m = 26,  MRM3m = 27, // Format /0 /1 /2 /3
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM4m = 28,  MRM5m = 29,  MRM6m = 30,  MRM7m = 31, // Format /4 /5 /6 /7
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // MRMInitReg - This form is used for instructions whose source and
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // destinations are the same register.
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRMInitReg = 32,
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //// MRM_C1 - A mod/rm byte of exactly 0xC1.
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_C1 = 33,
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_C2 = 34,
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_C3 = 35,
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_C4 = 36,
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_C8 = 37,
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_C9 = 38,
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_E8 = 39,
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_F0 = 40,
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_F8 = 41,
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MRM_F9 = 42,
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// RawFrmImm16 - This is used for CALL FAR instructions, which have two
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// immediates, the first of which is a 16 or 32-bit immediate (specified by
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// the imm encoding) and the second is a 16-bit fixed value.  In the AMD
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    /// manual, this operand is described as pntr16:32 and pntr16:16
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    RawFrmImm16 = 43,
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    FormMask       = 63,
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //===------------------------------------------------------------------===//
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Actual flags...
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // OpSize - Set if this instruction requires an operand size prefix (0x66),
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // which most often indicates that the instruction operates on 16 bit data
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // instead of 32 bit data.
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    OpSize      = 1 << 6,
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // AsSize - Set if this instruction requires an operand size prefix (0x67),
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // which most often indicates that the instruction address 16 bit address
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // instead of 32 bit address (or 32 bit address in 64 bit mode).
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AdSize      = 1 << 7,
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //===------------------------------------------------------------------===//
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Op0Mask - There are several prefix bytes that are used to form two byte
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // opcodes.  These are currently 0x0F, 0xF3, and 0xD8-0xDF.  This mask is
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // used to obtain the setting of this field.  If no bits in this field is
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // set, there is no prefix byte for obtaining a multibyte opcode.
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Op0Shift    = 8,
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Op0Mask     = 0xF << Op0Shift,
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // TB - TwoByte - Set if this instruction has a two byte opcode, which
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // starts with a 0x0F byte before the real opcode.
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    TB          = 1 << Op0Shift,
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // REP - The 0xF3 prefix byte indicating repetition of the following
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // instruction.
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    REP         = 2 << Op0Shift,
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // D8-DF - These escape opcodes are used by the floating point unit.  These
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // values must remain sequential.
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    D8 = 3 << Op0Shift,   D9 = 4 << Op0Shift,
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    DA = 5 << Op0Shift,   DB = 6 << Op0Shift,
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    DC = 7 << Op0Shift,   DD = 8 << Op0Shift,
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    DE = 9 << Op0Shift,   DF = 10 << Op0Shift,
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // XS, XD - These prefix codes are for single and double precision scalar
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // floating point operations performed in the SSE registers.
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    XD = 11 << Op0Shift,  XS = 12 << Op0Shift,
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // T8, TA - Prefix after the 0x0F prefix.
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    T8 = 13 << Op0Shift,  TA = 14 << Op0Shift,
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // TF - Prefix before and after 0x0F
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    TF = 15 << Op0Shift,
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //===------------------------------------------------------------------===//
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // REX_W - REX prefixes are instruction prefixes used in 64-bit mode.
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // They are used to specify GPRs and SSE registers, 64-bit operand size,
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // etc. We only cares about REX.W and REX.R bits and only the former is
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // statically determined.
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    REXShift    = 12,
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    REX_W       = 1 << REXShift,
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //===------------------------------------------------------------------===//
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // This three-bit field describes the size of an immediate operand.  Zero is
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // unused so that we can tell if we forgot to set a value.
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ImmShift = 13,
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ImmMask    = 7 << ImmShift,
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Imm8       = 1 << ImmShift,
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Imm8PCRel  = 2 << ImmShift,
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Imm16      = 3 << ImmShift,
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Imm16PCRel = 4 << ImmShift,
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Imm32      = 5 << ImmShift,
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Imm32PCRel = 6 << ImmShift,
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Imm64      = 7 << ImmShift,
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //===------------------------------------------------------------------===//
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // FP Instruction Classification...  Zero is non-fp instruction.
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // FPTypeMask - Mask for all of the FP types...
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    FPTypeShift = 16,
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    FPTypeMask  = 7 << FPTypeShift,
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // NotFP - The default, set for instructions that do not use FP registers.
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    NotFP      = 0 << FPTypeShift,
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // ZeroArgFP - 0 arg FP instruction which implicitly pushes ST(0), f.e. fld0
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    ZeroArgFP  = 1 << FPTypeShift,
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // OneArgFP - 1 arg FP instructions which implicitly read ST(0), such as fst
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    OneArgFP   = 2 << FPTypeShift,
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // OneArgFPRW - 1 arg FP instruction which implicitly read ST(0) and write a
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // result back to ST(0).  For example, fcos, fsqrt, etc.
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    OneArgFPRW = 3 << FPTypeShift,
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // TwoArgFP - 2 arg FP instructions which implicitly read ST(0), and an
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // explicit argument, storing the result to either ST(0) or the implicit
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // argument.  For example: fadd, fsub, fmul, etc...
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    TwoArgFP   = 4 << FPTypeShift,
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // CompareFP - 2 arg FP instructions which implicitly read ST(0) and an
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // explicit argument, but have no destination.  Example: fucom, fucomi, ...
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    CompareFP  = 5 << FPTypeShift,
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // CondMovFP - "2 operand" floating point conditional move instructions.
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    CondMovFP  = 6 << FPTypeShift,
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // SpecialFP - Special instruction forms.  Dispatch by opcode explicitly.
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    SpecialFP  = 7 << FPTypeShift,
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Lock prefix
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    LOCKShift = 19,
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    LOCK = 1 << LOCKShift,
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Segment override prefixes. Currently we just need ability to address
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // stuff in gs and fs segments.
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    SegOvrShift = 20,
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    SegOvrMask  = 3 << SegOvrShift,
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    FS          = 1 << SegOvrShift,
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    GS          = 2 << SegOvrShift,
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Execution domain for SSE instructions in bits 22, 23.
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // 0 in bits 22-23 means normal, non-SSE instruction.
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    SSEDomainShift = 22,
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    OpcodeShift   = 24,
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    OpcodeMask    = 0xFF << OpcodeShift,
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    //===------------------------------------------------------------------===//
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // VEX - The opcode prefix used by AVX instructions
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    VEX         = 1U << 0,
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // VEX_W - Has a opcode specific functionality, but is used in the same
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // way as REX_W is for regular SSE instructions.
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    VEX_W       = 1U << 1,
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // VEX_4V - Used to specify an additional AVX/SSE register. Several 2
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // address instructions in SSE are represented as 3 address ones in AVX
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // and the additional register is encoded in VEX_VVVV prefix.
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    VEX_4V      = 1U << 2,
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // VEX_I8IMM - Specifies that the last register used in a AVX instruction,
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // must be encoded in the i8 immediate field. This usually happens in
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // instructions with 4 operands.
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    VEX_I8IMM   = 1U << 3,
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // VEX_L - Stands for a bit in the VEX opcode prefix meaning the current
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // instruction uses 256-bit wide registers. This is usually auto detected if
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // a VR256 register is used, but some AVX instructions also have this field
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // marked when using a f256 memory references.
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    VEX_L       = 1U << 4
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  };
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // getBaseOpcodeFor - This function returns the "base" X86 opcode for the
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // specified machine instruction.
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  //
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static inline unsigned char getBaseOpcodeFor(uint64_t TSFlags) {
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    return TSFlags >> X86II::OpcodeShift;
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static inline bool hasImm(uint64_t TSFlags) {
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    return (TSFlags & X86II::ImmMask) != 0;
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// getSizeOfImm - Decode the "size of immediate" field from the TSFlags field
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// of the specified instruction.
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static inline unsigned getSizeOfImm(uint64_t TSFlags) {
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    switch (TSFlags & X86II::ImmMask) {
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    default: assert(0 && "Unknown immediate size");
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm8:
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm8PCRel:  return 1;
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm16:
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm16PCRel: return 2;
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm32:
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm32PCRel: return 4;
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm64:      return 8;
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    }
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// isImmPCRel - Return true if the immediate of the specified instruction's
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// TSFlags indicates that it is pc relative.
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static inline unsigned isImmPCRel(uint64_t TSFlags) {
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    switch (TSFlags & X86II::ImmMask) {
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    default: assert(0 && "Unknown immediate size");
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm8PCRel:
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm16PCRel:
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm32PCRel:
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      return true;
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm8:
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm16:
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm32:
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Imm64:
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      return false;
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    }
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// getMemoryOperandNo - The function returns the MCInst operand # for the
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// first field of the memory operand.  If the instruction doesn't have a
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// memory operand, this returns -1.
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// Note that this ignores tied operands.  If there is a tied register which
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// is duplicated in the MCInst (e.g. "EAX = addl EAX, [mem]") it is only
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// counted as one operand.
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static inline int getMemoryOperandNo(uint64_t TSFlags) {
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    switch (TSFlags & X86II::FormMask) {
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRMInitReg:  assert(0 && "FIXME: Remove this form");
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    default: assert(0 && "Unknown FormMask value in getMemoryOperandNo!");
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::Pseudo:
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::RawFrm:
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::AddRegFrm:
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRMDestReg:
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRMSrcReg:
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::RawFrmImm16:
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry       return -1;
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRMDestMem:
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      return 0;
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRMSrcMem: {
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      bool HasVEX_4V = (TSFlags >> 32) & X86II::VEX_4V;
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      unsigned FirstMemOp = 1;
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      if (HasVEX_4V)
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        ++FirstMemOp;// Skip the register source (which is encoded in VEX_VVVV).
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      // FIXME: Maybe lea should have its own form?  This is a horrible hack.
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      //if (Opcode == X86::LEA64r || Opcode == X86::LEA64_32r ||
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      //    Opcode == X86::LEA16r || Opcode == X86::LEA32r)
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      return FirstMemOp;
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    }
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM0r: case X86II::MRM1r:
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM2r: case X86II::MRM3r:
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM4r: case X86II::MRM5r:
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM6r: case X86II::MRM7r:
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      return -1;
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM0m: case X86II::MRM1m:
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM2m: case X86II::MRM3m:
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM4m: case X86II::MRM5m:
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM6m: case X86II::MRM7m:
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      return 0;
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_C1:
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_C2:
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_C3:
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_C4:
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_C8:
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_C9:
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_E8:
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_F0:
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_F8:
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    case X86II::MRM_F9:
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      return -1;
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    }
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline static bool isScale(const MachineOperand &MO) {
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  return MO.isImm() &&
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    (MO.getImm() == 1 || MO.getImm() == 2 ||
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry     MO.getImm() == 4 || MO.getImm() == 8);
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline static bool isLeaMem(const MachineInstr *MI, unsigned Op) {
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (MI->getOperand(Op).isFI()) return true;
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  return Op+4 <= MI->getNumOperands() &&
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MI->getOperand(Op  ).isReg() && isScale(MI->getOperand(Op+1)) &&
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MI->getOperand(Op+2).isReg() &&
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    (MI->getOperand(Op+3).isImm() ||
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry     MI->getOperand(Op+3).isGlobal() ||
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry     MI->getOperand(Op+3).isCPI() ||
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry     MI->getOperand(Op+3).isJTI());
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline static bool isMem(const MachineInstr *MI, unsigned Op) {
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (MI->getOperand(Op).isFI()) return true;
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  return Op+5 <= MI->getNumOperands() &&
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MI->getOperand(Op+4).isReg() &&
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    isLeaMem(MI, Op);
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass X86InstrInfo : public TargetInstrInfoImpl {
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  X86TargetMachine &TM;
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  const X86RegisterInfo RI;
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// RegOp2MemOpTable2Addr, RegOp2MemOpTable0, RegOp2MemOpTable1,
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// RegOp2MemOpTable2 - Load / store folding opcode maps.
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable2Addr;
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable0;
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable1;
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable2;
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// MemOp2RegOpTable - Load / store unfolding opcode map.
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  DenseMap<unsigned*, std::pair<unsigned, unsigned> > MemOp2RegOpTable;
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  explicit X86InstrInfo(X86TargetMachine &tm);
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// such, whenever a client has an instance of instruction info, it should
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// always be able to get register info as well (through this method).
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual const X86RegisterInfo &getRegisterInfo() const { return RI; }
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// extension instruction. That is, it's like a copy where it's legal for the
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// true, then it's expected the pre-extension value is available as a subreg
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// of the result register. This also returns the sub-register index in
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// SubIdx.
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool isCoalescableExtInstr(const MachineInstr &MI,
6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                     unsigned &SrcReg, unsigned &DstReg,
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                     unsigned &SubIdx) const;
6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  unsigned isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const;
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// stack locations as well.  This uses a heuristic so it isn't
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// reliable for correctness.
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                     int &FrameIndex) const;
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// hasLoadFromStackSlot - If the specified machine instruction has
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// a load from a stack slot, return true along with the FrameIndex
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// of the loaded stack slot and the machine mem operand containing
6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// the reference.  If not, return false.  Unlike
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// isLoadFromStackSlot, this returns true for any instructions that
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// loads from the stack.  This is a hint only and may not catch all
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// cases.
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  bool hasLoadFromStackSlot(const MachineInstr *MI,
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                            const MachineMemOperand *&MMO,
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                            int &FrameIndex) const;
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  unsigned isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const;
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// stack locations as well.  This uses a heuristic so it isn't
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// reliable for correctness.
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                    int &FrameIndex) const;
6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// hasStoreToStackSlot - If the specified machine instruction has a
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// store to a stack slot, return true along with the FrameIndex of
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// the loaded stack slot and the machine mem operand containing the
6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// reference.  If not, return false.  Unlike isStoreToStackSlot,
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// this returns true for any instructions that loads from the
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// stack.  This is a hint only and may not catch all cases.
6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  bool hasStoreToStackSlot(const MachineInstr *MI,
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                           const MachineMemOperand *&MMO,
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                           int &FrameIndex) const;
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                         AliasAnalysis *AA) const;
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                     unsigned DestReg, unsigned SubIdx,
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                     const MachineInstr *Orig,
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                     const TargetRegisterInfo &TRI) const;
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// convertToThreeAddress - This method must be implemented by targets that
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// may be able to convert a two-address instruction into a true
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// three-address instruction on demand.  This allows the X86 target (for
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// example) to convert ADD and SHL instructions into LEA instructions if they
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// would require register copies due to two-addressness.
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// This method returns a null pointer if the transformation cannot be
6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// performed, otherwise it returns the new instruction.
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              MachineBasicBlock::iterator &MBBI,
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              LiveVariables *LV) const;
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// commuteInstruction - We have a few instructions that must be hacked on to
6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// commute them.
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const;
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Branch analysis.
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool isUnpredicatedTerminator(const MachineInstr* MI) const;
6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                             MachineBasicBlock *&FBB,
6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                             SmallVectorImpl<MachineOperand> &Cond,
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                             bool AllowModify) const;
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                MachineBasicBlock *FBB,
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                const SmallVectorImpl<MachineOperand> &Cond,
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                DebugLoc DL) const;
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual void copyPhysReg(MachineBasicBlock &MBB,
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                           MachineBasicBlock::iterator MI, DebugLoc DL,
7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                           unsigned DestReg, unsigned SrcReg,
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                           bool KillSrc) const;
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                   MachineBasicBlock::iterator MI,
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                   unsigned SrcReg, bool isKill, int FrameIndex,
7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                   const TargetRegisterClass *RC,
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                   const TargetRegisterInfo *TRI) const;
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                              SmallVectorImpl<MachineOperand> &Addr,
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                              const TargetRegisterClass *RC,
7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                              MachineInstr::mmo_iterator MMOBegin,
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                              MachineInstr::mmo_iterator MMOEnd,
7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                              SmallVectorImpl<MachineInstr*> &NewMIs) const;
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                    MachineBasicBlock::iterator MI,
7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                    unsigned DestReg, int FrameIndex,
7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                    const TargetRegisterClass *RC,
7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                    const TargetRegisterInfo *TRI) const;
7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                               SmallVectorImpl<MachineOperand> &Addr,
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                               const TargetRegisterClass *RC,
7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                               MachineInstr::mmo_iterator MMOBegin,
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                               MachineInstr::mmo_iterator MMOEnd,
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                               SmallVectorImpl<MachineInstr*> &NewMIs) const;
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                         MachineBasicBlock::iterator MI,
7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                        const std::vector<CalleeSavedInfo> &CSI,
7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                         const TargetRegisterInfo *TRI) const;
7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                           MachineBasicBlock::iterator MI,
7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                        const std::vector<CalleeSavedInfo> &CSI,
7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                           const TargetRegisterInfo *TRI) const;
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual
7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                         int FrameIx, uint64_t Offset,
7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                         const MDNode *MDPtr,
7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                         DebugLoc DL) const;
7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// foldMemoryOperand - If this target supports it, fold a load or store of
7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// the specified stack slot into the specified machine instruction for the
7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// specified operand(s).  If this is possible, the target should perform the
7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// folding and return true, otherwise it should return false.  If it folds
7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// the instruction, it is likely that the MachineInstruction the iterator
7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// references has been changed.
7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              MachineInstr* MI,
7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                           const SmallVectorImpl<unsigned> &Ops,
7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              int FrameIndex) const;
7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// foldMemoryOperand - Same as the previous version except it allows folding
7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// of any load and store from / to any address, not just from a specific
7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// stack slot.
7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              MachineInstr* MI,
7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                           const SmallVectorImpl<unsigned> &Ops,
7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              MachineInstr* LoadMI) const;
7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// canFoldMemoryOperand - Returns true if the specified load / store is
7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// folding is possible.
7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool canFoldMemoryOperand(const MachineInstr*,
7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                    const SmallVectorImpl<unsigned> &) const;
7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// unfoldMemoryOperand - Separate a single instruction which folded a load or
7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// a store or a load and a store into two or more instruction. If this is
7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// possible, returns true as well as the new instructions by reference.
7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                           unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                           SmallVectorImpl<MachineInstr*> &NewMIs) const;
7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                           SmallVectorImpl<SDNode*> &NewNodes) const;
7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// instruction after load / store are unfolded from an instruction of the
7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// specified opcode. It returns zero if the specified unfolding is not
7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// possible. If LoadRegIndex is non-null, it is filled in with the operand
7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// index of the operand which will hold the register holding the loaded
7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// value.
7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                      bool UnfoldLoad, bool UnfoldStore,
7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                      unsigned *LoadRegIndex = 0) const;
7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler
7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// to determine if two loads are loading from the same base address. It
7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// should only return true if the base pointers are the same and the
7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// only differences between the two addresses are the offset. It also returns
7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// the offsets by reference.
7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                       int64_t &Offset1, int64_t &Offset2) const;
7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should
8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// be scheduled togther. On some targets if two loads are loading from
8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// addresses in the same cache line, it's better if they are scheduled
8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// together. This function takes two integers that represent the load offsets
8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// from the common base address. It returns true if it decides it's desirable
8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// to schedule the two loads together. "NumLoads" is the number of loads that
8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// have already been scheduled after Load1.
8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                       int64_t Offset1, int64_t Offset2,
8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                       unsigned NumLoads) const;
8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual void getNoopForMachoTarget(MCInst &NopInst) const;
8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual
8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// instruction that defines the specified register class.
8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const;
8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static bool isX86_64NonExtLowByteReg(unsigned reg) {
8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    return (reg == X86::SPL || reg == X86::BPL ||
8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry          reg == X86::SIL || reg == X86::DIL);
8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static bool isX86_64ExtendedReg(const MachineOperand &MO) {
8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    if (!MO.isReg()) return false;
8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    return isX86_64ExtendedReg(MO.getReg());
8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// isX86_64ExtendedReg - Is the MachineOperand a x86-64 extended (r8 or
8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// higher) register?  e.g. r8, xmm8, xmm13, etc.
8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static bool isX86_64ExtendedReg(unsigned RegNo);
8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// getGlobalBaseReg - Return a virtual register initialized with the
8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// the global base register value. Output instructions required to
8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// initialize the register in the function entry block, if necessary.
8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ///
8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  unsigned getGlobalBaseReg(MachineFunction *MF) const;
8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// GetSSEDomain - Return the SSE execution domain of MI as the first element,
8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// and a bitmask of possible arguments to SetSSEDomain ase the second.
8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  std::pair<uint16_t, uint16_t> GetSSEDomain(const MachineInstr *MI) const;
8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// SetSSEDomain - Set the SSEDomain of MI.
8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  void SetSSEDomain(MachineInstr *MI, unsigned Domain) const;
8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                      MachineInstr* MI,
8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                      unsigned OpNum,
8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                      const SmallVectorImpl<MachineOperand> &MOs,
8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                      unsigned Size, unsigned Alignment) const;
8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  MachineInstr * convertToThreeAddressWithLEA(unsigned MIOpc,
8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              MachineFunction::iterator &MFI,
8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              MachineBasicBlock::iterator &MBBI,
8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                                              LiveVariables *LV) const;
8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// isFrameOperand - Return true and the FrameIndex if the specified
8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  /// operand and follow operands form a reference to the stack frame.
8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  bool isFrameOperand(const MachineInstr *MI, unsigned int Op,
8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                      int &FrameIndex) const;
8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // End llvm namespace
8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry