119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//===-- llvm/Mc/McInstrDesc.h - Instruction Descriptors -*- C++ -*-===//
219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//
319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//                     The LLVM Compiler Infrastructure
419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//
519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman// This file is distributed under the University of Illinois Open Source
619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman// License. See LICENSE.TXT for details.
719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//
819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//===----------------------------------------------------------------------===//
919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//
1019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman// This file defines the MCOperandInfo and MCInstrDesc classes, which
1119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman// are used to describe target instructions and their operands.
1219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//
1319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//===----------------------------------------------------------------------===//
1419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
1519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#ifndef LLVM_MC_MCINSTRDESC_H
1619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#define LLVM_MC_MCINSTRDESC_H
1719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
1819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "llvm/Support/DataTypes.h"
1919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
2019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumannamespace llvm {
2119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
2219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//===----------------------------------------------------------------------===//
2319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman// Machine Operand Flags and Description
2419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//===----------------------------------------------------------------------===//
2519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
2619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumannamespace MCOI {
2719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  // Operand constraints
2819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  enum OperandConstraint {
2919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    TIED_TO = 0,    // Must be allocated the same register as.
3019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    EARLY_CLOBBER   // Operand is an early clobber register operand
3119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  };
3219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
3319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// OperandFlags - These are flags set on operands, but should be considered
3419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// private, all access should go through the MCOperandInfo accessors.
3519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// See the accessors for a description of what these are.
3619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  enum OperandFlags {
3719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LookupPtrRegClass = 0,
3819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Predicate,
3919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    OptionalDef
4019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  };
4119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
4219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Operand Type - Operands are tagged with one of the values of this enum.
4319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  enum OperandType {
4419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    OPERAND_UNKNOWN,
4519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    OPERAND_IMMEDIATE,
4619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    OPERAND_REGISTER,
4719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    OPERAND_MEMORY,
4819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    OPERAND_PCREL
4919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  };
5019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman}
5119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
5219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// MCOperandInfo - This holds information about one operand of a machine
5319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// instruction, indicating the register class for register operands, etc.
5419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman///
5519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass MCOperandInfo {
5619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanpublic:
5719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// RegClass - This specifies the register class enumeration of the operand
5819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// if the operand is a register.  If isLookupPtrRegClass is set, then this is
5919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// an index that is passed to TargetRegisterInfo::getPointerRegClass(x) to
6019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// get a dynamic register class.
6119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  short RegClass;
6219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
6319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Flags - These are flags from the MCOI::OperandFlags enum.
6419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned short Flags;
6519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Lower 16 bits are used to specify which constraints are set. The higher 16
6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// bits are used to specify the value of constraints (4 bits each).
6819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned Constraints;
6919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
7019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// OperandType - Information about the type of the operand.
7119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  MCOI::OperandType OperandType;
7219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Currently no other information.
7319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
7419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isLookupPtrRegClass - Set if this operand is a pointer value and it
7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// requires a callback to look up its register class.
7619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isLookupPtrRegClass() const {return Flags&(1 <<MCOI::LookupPtrRegClass);}
7719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
7819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isPredicate - Set if this is one of the operands that made up of
7919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// the predicate operand that controls an isPredicable() instruction.
8019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isPredicate() const { return Flags & (1 << MCOI::Predicate); }
8119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
8219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isOptionalDef - Set if this operand is a optional def.
8319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
8419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isOptionalDef() const { return Flags & (1 << MCOI::OptionalDef); }
8519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman};
8619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
8719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//===----------------------------------------------------------------------===//
8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman// Machine Instruction Flags and Description
9019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman//===----------------------------------------------------------------------===//
9119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
9219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// MCInstrDesc flags - These should be considered private to the
9319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// implementation of the MCInstrDesc class.  Clients should use the predicate
9419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// methods on MCInstrDesc, not use these directly.  These all correspond to
9519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// bitfields in the MCInstrDesc::Flags field.
9619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumannamespace MCID {
9719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  enum {
9819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Variadic = 0,
9919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    HasOptionalDef,
10019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Pseudo,
10119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Return,
10219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Call,
10319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Barrier,
10419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Terminator,
10519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Branch,
10619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    IndirectBranch,
10719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Compare,
10819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    MoveImm,
10919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Bitcast,
11019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    DelaySlot,
11119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    FoldableAsLoad,
11219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    MayLoad,
11319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    MayStore,
11419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Predicable,
11519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    NotDuplicable,
11619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    UnmodeledSideEffects,
11719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Commutable,
11819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    ConvertibleTo3Addr,
11919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    UsesCustomInserter,
12019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    HasPostISelHook,
12119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Rematerializable,
12219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    CheapAsAMove,
12319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    ExtraSrcRegAllocReq,
12419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    ExtraDefRegAllocReq
12519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  };
12619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman}
12719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
12819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// MCInstrDesc - Describe properties that are true of each instruction in the
12919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// target description file.  This captures information about side effects,
13019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// register use and many other things.  There is one instance of this struct
13119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// for each target instruction class, and the MachineInstr class points to
13219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/// this struct directly to describe itself.
13319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass MCInstrDesc {
13419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanpublic:
13519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned short  Opcode;        // The opcode number
13619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned short  NumOperands;   // Num of args (may be more if variable_ops)
13719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned short  NumDefs;       // Num of args that are definitions
13819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned short  SchedClass;    // enum identifying instr sched class
13919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned short  Size;          // Number of bytes in encoding.
14019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const char *    Name;          // Name of the instruction record in td file
14119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned        Flags;         // Flags identifying machine instr class
14219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  uint64_t        TSFlags;       // Target Specific Flag values
14319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const unsigned *ImplicitUses;  // Registers implicitly read by this instr
14419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const unsigned *ImplicitDefs;  // Registers implicitly defined by this instr
14519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const MCOperandInfo *OpInfo;   // 'NumOperands' entries about operands
14619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
14719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getOperandConstraint - Returns the value of the specific constraint if
14819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// it is set. Returns -1 if it is not set.
14919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  int getOperandConstraint(unsigned OpNum,
15019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                           MCOI::OperandConstraint Constraint) const {
15119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    if (OpNum < NumOperands &&
15219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        (OpInfo[OpNum].Constraints & (1 << Constraint))) {
15319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      unsigned Pos = 16 + Constraint * 4;
15419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return (int)(OpInfo[OpNum].Constraints >> Pos) & 0xf;
15519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    }
15619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return -1;
15719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
15819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
15919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getOpcode - Return the opcode number for this descriptor.
16019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned getOpcode() const {
16119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Opcode;
16219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
16319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
16419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getName - Return the name of the record in the .td file for this
16519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instruction, for example "ADD8ri".
16619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const char *getName() const {
16719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Name;
16819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
16919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
17019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getNumOperands - Return the number of declared MachineOperands for this
17119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// MachineInstruction.  Note that variadic (isVariadic() returns true)
17219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instructions may have additional operands at the end of the list, and note
17319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// that the machine instruction may include implicit register def/uses as
17419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// well.
17519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned getNumOperands() const {
17619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return NumOperands;
17719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
17819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
17919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getNumDefs - Return the number of MachineOperands that are register
18019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// definitions.  Register definitions always occur at the start of the
18119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// machine operand list.  This is the number of "outs" in the .td file,
18219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// and does not include implicit defs.
18319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned getNumDefs() const {
18419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return NumDefs;
18519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
18619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
18719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isVariadic - Return true if this instruction can have a variable number of
18819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// operands.  In this case, the variable operands will be after the normal
18919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// operands but before the implicit definitions and uses (if any are
19019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// present).
19119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isVariadic() const {
19219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Variadic);
19319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
19419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
19519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// hasOptionalDef - Set if this instruction has an optional definition, e.g.
19619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// ARM instructions which can set condition code if 's' bit is set.
19719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool hasOptionalDef() const {
19819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::HasOptionalDef);
19919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
20019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
20119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getImplicitUses - Return a list of registers that are potentially
20219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// read by any instance of this machine instruction.  For example, on X86,
20319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// the "adc" instruction adds two register operands and adds the carry bit in
20419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// from the flags register.  In this case, the instruction is marked as
20519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// implicitly reading the flags.  Likewise, the variable shift instruction on
20619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// X86 is marked as implicitly reading the 'CL' register, which it always
20719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// does.
20819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
20919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// This method returns null if the instruction has no implicit uses.
21019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const unsigned *getImplicitUses() const {
21119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return ImplicitUses;
21219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
21319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
21419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getNumImplicitUses - Return the number of implicit uses this instruction
21519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// has.
21619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned getNumImplicitUses() const {
21719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    if (ImplicitUses == 0) return 0;
21819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    unsigned i = 0;
21919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    for (; ImplicitUses[i]; ++i) /*empty*/;
22019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return i;
22119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
22219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
22319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getImplicitDefs - Return a list of registers that are potentially
22419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// written by any instance of this machine instruction.  For example, on X86,
22519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// many instructions implicitly set the flags register.  In this case, they
22619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// are marked as setting the FLAGS.  Likewise, many instructions always
22719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// deposit their result in a physical register.  For example, the X86 divide
22819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instruction always deposits the quotient and remainder in the EAX/EDX
22919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// registers.  For that instruction, this will return a list containing the
23019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// EAX/EDX/EFLAGS registers.
23119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
23219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// This method returns null if the instruction has no implicit defs.
23319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const unsigned *getImplicitDefs() const {
23419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return ImplicitDefs;
23519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
23619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
23719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getNumImplicitDefs - Return the number of implicit defs this instruction
23819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// has.
23919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned getNumImplicitDefs() const {
24019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    if (ImplicitDefs == 0) return 0;
24119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    unsigned i = 0;
24219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    for (; ImplicitDefs[i]; ++i) /*empty*/;
24319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return i;
24419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
24519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
24619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// hasImplicitUseOfPhysReg - Return true if this instruction implicitly
24719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// uses the specified physical register.
24819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool hasImplicitUseOfPhysReg(unsigned Reg) const {
24919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    if (const unsigned *ImpUses = ImplicitUses)
25019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      for (; *ImpUses; ++ImpUses)
25119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        if (*ImpUses == Reg) return true;
25219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return false;
25319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
25419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
25519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// hasImplicitDefOfPhysReg - Return true if this instruction implicitly
25619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// defines the specified physical register.
25719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool hasImplicitDefOfPhysReg(unsigned Reg) const {
25819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    if (const unsigned *ImpDefs = ImplicitDefs)
25919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      for (; *ImpDefs; ++ImpDefs)
26019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        if (*ImpDefs == Reg) return true;
26119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return false;
26219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
26319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
26419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getSchedClass - Return the scheduling class for this instruction.  The
26519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// scheduling class is an index into the InstrItineraryData table.  This
26619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// returns zero if there is no known scheduling information for the
26719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instruction.
26819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
26919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned getSchedClass() const {
27019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return SchedClass;
27119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
27219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
27319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getSize - Return the number of bytes in the encoding of this instruction,
27419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// or zero if the encoding size cannot be known from the opcode.
27519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  unsigned getSize() const {
27619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Size;
27719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
27819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
27919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isPseudo - Return true if this is a pseudo instruction that doesn't
28019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// correspond to a real machine instruction.
28119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
28219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isPseudo() const {
28319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Pseudo);
28419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
28519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
28619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isReturn() const {
28719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Return);
28819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
28919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
29019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isCall() const {
29119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Call);
29219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
29319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
29419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isBarrier - Returns true if the specified instruction stops control flow
29519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// from executing the instruction immediately following it.  Examples include
29619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// unconditional branches and return instructions.
29719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isBarrier() const {
29819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Barrier);
29919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
30019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
30119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// findFirstPredOperandIdx() - Find the index of the first operand in the
30219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// operand list that is used to represent the predicate. It returns -1 if
30319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// none is found.
30419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  int findFirstPredOperandIdx() const {
30519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    if (isPredicable()) {
30619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
30719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        if (OpInfo[i].isPredicate())
30819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman          return i;
30919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    }
31019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return -1;
31119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
31219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
31319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isTerminator - Returns true if this instruction part of the terminator for
31419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// a basic block.  Typically this is things like return and branch
31519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instructions.
31619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
31719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Various passes use this to insert code into the bottom of a basic block,
31819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// but before control flow occurs.
31919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isTerminator() const {
32019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Terminator);
32119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
32219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
32319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isBranch - Returns true if this is a conditional, unconditional, or
32419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// indirect branch.  Predicates below can be used to discriminate between
32519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// these cases, and the TargetInstrInfo::AnalyzeBranch method can be used to
32619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// get more information.
32719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isBranch() const {
32819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Branch);
32919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
33019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
33119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isIndirectBranch - Return true if this is an indirect branch, such as a
33219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// branch through a register.
33319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isIndirectBranch() const {
33419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::IndirectBranch);
33519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
33619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
33719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isConditionalBranch - Return true if this is a branch which may fall
33819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// through to the next instruction or may transfer control flow to some other
33919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// block.  The TargetInstrInfo::AnalyzeBranch method can be used to get more
34019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// information about this branch.
34119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isConditionalBranch() const {
34219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return isBranch() & !isBarrier() & !isIndirectBranch();
34319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
34419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
34519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isUnconditionalBranch - Return true if this is a branch which always
34619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// transfers control flow to some other block.  The
34719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// TargetInstrInfo::AnalyzeBranch method can be used to get more information
34819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// about this branch.
34919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isUnconditionalBranch() const {
35019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return isBranch() & isBarrier() & !isIndirectBranch();
35119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
35219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
35319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  // isPredicable - Return true if this instruction has a predicate operand that
35419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  // controls execution.  It may be set to 'always', or may be set to other
35519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// values.   There are various methods in TargetInstrInfo that can be used to
35619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// control and modify the predicate in this instruction.
35719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isPredicable() const {
35819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Predicable);
35919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
36019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
36119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isCompare - Return true if this instruction is a comparison.
36219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isCompare() const {
36319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Compare);
36419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
36519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
36619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isMoveImmediate - Return true if this instruction is a move immediate
36719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// (including conditional moves) instruction.
36819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isMoveImmediate() const {
36919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::MoveImm);
37019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
37119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
37219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isBitcast - Return true if this instruction is a bitcast instruction.
37319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
37419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isBitcast() const {
37519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Bitcast);
37619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
37719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
37819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isNotDuplicable - Return true if this instruction cannot be safely
37919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// duplicated.  For example, if the instruction has a unique labels attached
38019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// to it, duplicating it would cause multiple definition errors.
38119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isNotDuplicable() const {
38219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::NotDuplicable);
38319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
38419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
38519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// hasDelaySlot - Returns true if the specified instruction has a delay slot
38619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// which must be filled by the code generator.
38719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool hasDelaySlot() const {
38819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::DelaySlot);
38919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
39019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
39119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// canFoldAsLoad - Return true for instructions that can be folded as
39219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// memory operands in other instructions. The most common use for this
39319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// is instructions that are simple loads from memory that don't modify
39419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// the loaded value in any way, but it can also be used for instructions
39519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// that can be expressed as constant-pool loads, such as V_SETALLONES
39619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// on x86, to allow them to be folded when it is beneficial.
39719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// This should only be set on instructions that return a value in their
39819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// only virtual register definition.
39919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool canFoldAsLoad() const {
40019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::FoldableAsLoad);
40119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
40219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
40319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  //===--------------------------------------------------------------------===//
40419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  // Side Effect Analysis
40519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  //===--------------------------------------------------------------------===//
40619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
40719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// mayLoad - Return true if this instruction could possibly read memory.
40819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Instructions with this flag set are not necessarily simple load
40919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instructions, they may load a value and modify it, for example.
41019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool mayLoad() const {
41119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::MayLoad);
41219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
41319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
41419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
41519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// mayStore - Return true if this instruction could possibly modify memory.
41619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Instructions with this flag set are not necessarily simple store
41719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instructions, they may store a modified value based on their operands, or
41819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// may not actually modify anything, for example.
41919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool mayStore() const {
42019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::MayStore);
42119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
42219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
42319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// hasUnmodeledSideEffects - Return true if this instruction has side
42419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// effects that are not modeled by other flags.  This does not return true
42519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// for instructions whose effects are captured by:
42619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
42719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///  1. Their operand list and implicit definition/use list.  Register use/def
42819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///     info is explicit for instructions.
42919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///  2. Memory accesses.  Use mayLoad/mayStore.
43019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///  3. Calling, branching, returning: use isCall/isReturn/isBranch.
43119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
43219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Examples of side effects would be modifying 'invisible' machine state like
43319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// a control register, flushing a cache, modifying a register invisible to
43419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// LLVM, etc.
43519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
43619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool hasUnmodeledSideEffects() const {
43719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::UnmodeledSideEffects);
43819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
43919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
44019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  //===--------------------------------------------------------------------===//
44119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  // Flags that indicate whether an instruction can be modified by a method.
44219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  //===--------------------------------------------------------------------===//
44319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
44419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isCommutable - Return true if this may be a 2- or 3-address
44519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instruction (of the form "X = op Y, Z, ..."), which produces the same
44619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// result if Y and Z are exchanged.  If this flag is set, then the
44719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// TargetInstrInfo::commuteInstruction method may be used to hack on the
44819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instruction.
44919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
45019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Note that this flag may be set on instructions that are only commutable
45119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// sometimes.  In these cases, the call to commuteInstruction will fail.
45219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Also note that some instructions require non-trivial modification to
45319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// commute them.
45419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isCommutable() const {
45519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Commutable);
45619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
45719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
45819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isConvertibleTo3Addr - Return true if this is a 2-address instruction
45919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// which can be changed into a 3-address instruction if needed.  Doing this
46019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// transformation can be profitable in the register allocator, because it
46119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// means that the instruction can use a 2-address form if possible, but
46219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// degrade into a less efficient form if the source and dest register cannot
46319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// be assigned to the same register.  For example, this allows the x86
46419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// backend to turn a "shl reg, 3" instruction into an LEA instruction, which
46519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// is the same speed as the shift but has bigger code size.
46619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
46719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// If this returns true, then the target must implement the
46819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// TargetInstrInfo::convertToThreeAddress method for this instruction, which
46919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// is allowed to fail if the transformation isn't valid for this specific
47019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// instruction (e.g. shl reg, 4 on x86).
47119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
47219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isConvertibleTo3Addr() const {
47319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::ConvertibleTo3Addr);
47419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
47519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
47619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// usesCustomInsertionHook - Return true if this instruction requires
47719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// custom insertion support when the DAG scheduler is inserting it into a
47819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// machine basic block.  If this is true for the instruction, it basically
47919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// means that it is a pseudo instruction used at SelectionDAG time that is
48019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// expanded out into magic code by the target when MachineInstrs are formed.
48119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
48219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method
48319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// is used to insert this into the MachineBasicBlock.
48419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool usesCustomInsertionHook() const {
48519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::UsesCustomInserter);
48619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
48719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
48819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// hasPostISelHook - Return true if this instruction requires *adjustment*
48919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// after instruction selection by calling a target hook. For example, this
49019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// can be used to fill in ARM 's' optional operand depending on whether
49119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// the conditional flag register is used.
49219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool hasPostISelHook() const {
49319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::HasPostISelHook);
49419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
49519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
49619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isRematerializable - Returns true if this instruction is a candidate for
49719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// remat.  This flag is deprecated, please don't use it anymore.  If this
49819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// flag is set, the isReallyTriviallyReMaterializable() method is called to
49919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// verify the instruction is really rematable.
50019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isRematerializable() const {
50119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::Rematerializable);
50219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
50319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
50419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isAsCheapAsAMove - Returns true if this instruction has the same cost (or
50519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// less) than a move instruction. This is useful during certain types of
50619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// optimizations (e.g., remat during two-address conversion or machine licm)
50719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// where we would like to remat or hoist the instruction, but not if it costs
50819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// more than moving the instruction into the appropriate register. Note, we
50919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// are not marking copies from and to the same register class with this flag.
51019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isAsCheapAsAMove() const {
51119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::CheapAsAMove);
51219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
51319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
51419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// hasExtraSrcRegAllocReq - Returns true if this instruction source operands
51519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// have special register allocation requirements that are not captured by the
51619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// operand register classes. e.g. ARM::STRD's two source registers must be an
51719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// even / odd pair, ARM::STM registers have to be in ascending order.
51819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Post-register allocation passes should not attempt to change allocations
51919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// for sources of instructions with this flag.
52019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool hasExtraSrcRegAllocReq() const {
52119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::ExtraSrcRegAllocReq);
52219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
52319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
52419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// hasExtraDefRegAllocReq - Returns true if this instruction def operands
52519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// have special register allocation requirements that are not captured by the
52619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// operand register classes. e.g. ARM::LDRD's two def registers must be an
52719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// even / odd pair, ARM::LDM registers have to be in ascending order.
52819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Post-register allocation passes should not attempt to change allocations
52919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// for definitions of instructions with this flag.
53019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool hasExtraDefRegAllocReq() const {
53119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Flags & (1 << MCID::ExtraDefRegAllocReq);
53219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
53319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman};
53419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
53519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman} // end namespace llvm
53619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
53719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#endif
538