Refine the definition of convergent to only disallow the addition of new control...
[oota-llvm.git] / include / llvm / MC / MCInstrDesc.h
index c74d1c3fd86df6c4f67d66b0cb9e0c9b84e2d15c..1baf82ee5c453babb8fabc6fd6098990752ce993 100644 (file)
 #ifndef LLVM_MC_MCINSTRDESC_H
 #define LLVM_MC_MCINSTRDESC_H
 
-#include "llvm/MC/MCInst.h"
-#include "llvm/MC/MCRegisterInfo.h"
-#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/Support/DataTypes.h"
+#include <string>
 
 namespace llvm {
+  class MCInst;
+  class MCRegisterInfo;
+  class MCSubtargetInfo;
+  class FeatureBitset;
 
 //===----------------------------------------------------------------------===//
 // Machine Operand Flags and Description
@@ -123,7 +125,8 @@ enum Flag {
   ExtraDefRegAllocReq,
   RegSequence,
   ExtractSubreg,
-  InsertSubreg
+  InsertSubreg,
+  Convergent
 };
 }
 
@@ -136,19 +139,23 @@ class MCInstrDesc {
 public:
   unsigned short Opcode;        // The opcode number
   unsigned short NumOperands;   // Num of args (may be more if variable_ops)
-  unsigned short NumDefs;       // Num of args that are definitions
+  unsigned char NumDefs;        // Num of args that are definitions
+  unsigned char Size;           // Number of bytes in encoding.
   unsigned short SchedClass;    // enum identifying instr sched class
-  unsigned short Size;          // Number of bytes in encoding.
-  unsigned Flags;               // Flags identifying machine instr class
+  uint64_t Flags;               // Flags identifying machine instr class
   uint64_t TSFlags;             // Target Specific Flag values
   const uint16_t *ImplicitUses; // Registers implicitly read by this instr
   const uint16_t *ImplicitDefs; // Registers implicitly defined by this instr
   const MCOperandInfo *OpInfo;  // 'NumOperands' entries about operands
-  uint64_t
-      DeprecatedFeatureMask; // Feature bits that this is deprecated on, if any
+  // Subtarget feature that this is deprecated on, if any
+  // -1 implies this is not deprecated by any single feature. It may still be 
+  // deprecated due to a "complex" reason, below.
+  int64_t DeprecatedFeature;
+
   // A complex method to determine is a certain is deprecated or not, and return
   // the reason for deprecation.
-  bool (*ComplexDeprecationInfo)(MCInst &, MCSubtargetInfo &, std::string &);
+  bool (*ComplexDeprecationInfo)(MCInst &, const MCSubtargetInfo &,
+                                 std::string &);
 
   /// \brief Returns the value of the specific constraint if
   /// it is set. Returns -1 if it is not set.
@@ -164,17 +171,8 @@ public:
 
   /// \brief Returns true if a certain instruction is deprecated and if so
   /// returns the reason in \p Info.
-  bool getDeprecatedInfo(MCInst &MI, MCSubtargetInfo &STI,
-                         std::string &Info) const {
-    if (ComplexDeprecationInfo)
-      return ComplexDeprecationInfo(MI, STI, Info);
-    if ((DeprecatedFeatureMask & STI.getFeatureBits()) != 0) {
-      // FIXME: it would be nice to include the subtarget feature here.
-      Info = "deprecated";
-      return true;
-    }
-    return false;
-  }
+  bool getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI,
+                         std::string &Info) const;
 
   /// \brief Return the opcode number for this descriptor.
   unsigned getOpcode() const { return Opcode; }
@@ -257,25 +255,7 @@ public:
   /// \brief Return true if this is a branch or an instruction which directly
   /// writes to the program counter. Considered 'may' affect rather than
   /// 'does' affect as things like predication are not taken into account.
-  bool mayAffectControlFlow(const MCInst &MI, const MCRegisterInfo &RI) const {
-    if (isBranch() || isCall() || isReturn() || isIndirectBranch())
-      return true;
-    unsigned PC = RI.getProgramCounter();
-    if (PC == 0)
-      return false;
-    if (hasDefOfPhysReg(MI, PC, RI))
-      return true;
-    // A variadic instruction may define PC in the variable operand list.
-    // There's currently no indication of which entries in a variable
-    // list are defs and which are uses. While that's the case, this function
-    // needs to assume they're defs in order to be conservatively correct.
-    for (int i = NumOperands, e = MI.getNumOperands(); i != e; ++i) {
-      if (MI.getOperand(i).isReg() &&
-          RI.isSubRegisterEq(PC, MI.getOperand(i).getReg()))
-        return true;
-    }
-    return false;
-  }
+  bool mayAffectControlFlow(const MCInst &MI, const MCRegisterInfo &RI) const;
 
   /// \brief Return true if this instruction has a predicate operand
   /// that controls execution. It may be set to 'always', or may be set to other
@@ -353,6 +333,13 @@ public:
   /// override accordingly.
   bool isInsertSubregLike() const { return Flags & (1 << MCID::InsertSubreg); }
 
+
+  /// \brief Return true if this instruction is convergent.
+  ///
+  /// Convergent instructions may not be made control-dependent on any
+  /// additional values.
+  bool isConvergent() const { return Flags & (1 << MCID::Convergent); }
+
   //===--------------------------------------------------------------------===//
   // Side Effect Analysis
   //===--------------------------------------------------------------------===//
@@ -532,24 +519,7 @@ public:
   /// \brief Return true if this instruction implicitly
   /// defines the specified physical register.
   bool hasImplicitDefOfPhysReg(unsigned Reg,
-                               const MCRegisterInfo *MRI = nullptr) const {
-    if (const uint16_t *ImpDefs = ImplicitDefs)
-      for (; *ImpDefs; ++ImpDefs)
-        if (*ImpDefs == Reg || (MRI && MRI->isSubRegister(Reg, *ImpDefs)))
-          return true;
-    return false;
-  }
-
-  /// \brief Return true if this instruction defines the specified physical
-  /// register, either explicitly or implicitly.
-  bool hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
-                       const MCRegisterInfo &RI) const {
-    for (int i = 0, e = NumDefs; i != e; ++i)
-      if (MI.getOperand(i).isReg() &&
-          RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
-        return true;
-    return hasImplicitDefOfPhysReg(Reg, &RI);
-  }
+                               const MCRegisterInfo *MRI = nullptr) const;
 
   /// \brief Return the scheduling class for this instruction.  The
   /// scheduling class is an index into the InstrItineraryData table.  This
@@ -572,6 +542,13 @@ public:
     }
     return -1;
   }
+
+private:
+
+  /// \brief Return true if this instruction defines the specified physical
+  /// register, either explicitly or implicitly.
+  bool hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
+                       const MCRegisterInfo &RI) const;
 };
 
 } // end namespace llvm