Remove stray comma in enum to satisfy -Wpedantic.
[oota-llvm.git] / utils / TableGen / X86RecognizableInstr.cpp
index 6e36854137eb67caaafee5417ef644a30d75ac19..17fd0ec5c6efa617c6a941011eccef86e3e5c8cc 100644 (file)
@@ -80,7 +80,7 @@ namespace X86Local {
     XD = 11,  XS = 12,
     T8 = 13,  P_TA = 14,
     A6 = 15,  A7 = 16, T8XD = 17, T8XS = 18, TAXD = 19,
-    XOP8 = 20, XOP9 = 21, XOPA = 22
+    XOP8 = 20, XOP9 = 21, XOPA = 22, PD = 23, T8PD = 24, TAPD = 25
   };
 }
 
@@ -230,7 +230,6 @@ RecognizableInstr::RecognizableInstr(DisassemblerTables &tables,
   Prefix   = byteFromRec(Rec, "Prefix");
   Opcode   = byteFromRec(Rec, "Opcode");
   Form     = byteFromRec(Rec, "FormBits");
-  SegOvr   = byteFromRec(Rec, "SegOvrBits");
 
   HasOpSizePrefix  = Rec->getValueAsBit("hasOpSizePrefix");
   HasAdSizePrefix  = Rec->getValueAsBit("hasAdSizePrefix");
@@ -248,15 +247,17 @@ RecognizableInstr::RecognizableInstr(DisassemblerTables &tables,
   HasEVEX_B        = Rec->getValueAsBit("hasEVEX_B");
   HasLockPrefix    = Rec->getValueAsBit("hasLockPrefix");
   IsCodeGenOnly    = Rec->getValueAsBit("isCodeGenOnly");
+  ForceDisassemble = Rec->getValueAsBit("ForceDisassemble");
 
   Name      = Rec->getName();
   AsmString = Rec->getValueAsString("AsmString");
 
   Operands = &insn.Operands.OperandList;
 
-  IsSSE            = (HasOpSizePrefix && (Name.find("16") == Name.npos)) ||
+  IsSSE            = ((HasOpSizePrefix || Prefix == X86Local::PD ||
+                       Prefix == X86Local::T8PD || Prefix == X86Local::TAPD) &&
+                      (Name.find("16") == Name.npos)) ||
                      (Name.find("CRC32") != Name.npos);
-  HasFROperands    = hasFROperands();
   HasVEX_LPrefix   = Rec->getValueAsBit("hasVEX_L");
 
   // Check for 64-bit inst which does not require REX
@@ -275,17 +276,6 @@ RecognizableInstr::RecognizableInstr(DisassemblerTables &tables,
       break;
     }
   }
-  // FIXME: These instructions aren't marked as 64-bit in any way
-  Is64Bit |= Rec->getName() == "JMP64pcrel32" ||
-             Rec->getName() == "MASKMOVDQU64" ||
-             Rec->getName() == "POPFS64" ||
-             Rec->getName() == "POPGS64" ||
-             Rec->getName() == "PUSHFS64" ||
-             Rec->getName() == "PUSHGS64" ||
-             Rec->getName() == "REX64_PREFIX" ||
-             Rec->getName().find("MOV64") != Name.npos ||
-             Rec->getName().find("PUSH64") != Name.npos ||
-             Rec->getName().find("POP64") != Name.npos;
 
   ShouldBeEmitted  = true;
 }
@@ -321,7 +311,7 @@ InstructionContext RecognizableInstr::insnContext() const {
     }
     // VEX_L & VEX_W
     if (HasVEX_LPrefix && HasVEX_WPrefix) {
-      if (HasOpSizePrefix)
+      if (HasOpSizePrefix || Prefix == X86Local::PD)
         insnContext = EVEX_KB(IC_EVEX_L_W_OPSIZE);
       else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
         insnContext = EVEX_KB(IC_EVEX_L_W_XS);
@@ -332,7 +322,8 @@ InstructionContext RecognizableInstr::insnContext() const {
         insnContext = EVEX_KB(IC_EVEX_L_W);
     } else if (HasVEX_LPrefix) {
       // VEX_L
-      if (HasOpSizePrefix)
+      if (HasOpSizePrefix || Prefix == X86Local::PD ||
+          Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
         insnContext = EVEX_KB(IC_EVEX_L_OPSIZE);
       else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
         insnContext = EVEX_KB(IC_EVEX_L_XS);
@@ -344,7 +335,8 @@ InstructionContext RecognizableInstr::insnContext() const {
     }
     else if (HasEVEX_L2Prefix && HasVEX_WPrefix) {
       // EVEX_L2 & VEX_W
-      if (HasOpSizePrefix)
+      if (HasOpSizePrefix || Prefix == X86Local::PD ||
+          Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
         insnContext = EVEX_KB(IC_EVEX_L2_W_OPSIZE);
       else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
         insnContext = EVEX_KB(IC_EVEX_L2_W_XS);
@@ -355,10 +347,11 @@ InstructionContext RecognizableInstr::insnContext() const {
         insnContext = EVEX_KB(IC_EVEX_L2_W);
     } else if (HasEVEX_L2Prefix) {
       // EVEX_L2
-      if (HasOpSizePrefix)
+      if (HasOpSizePrefix || Prefix == X86Local::PD ||
+          Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
         insnContext = EVEX_KB(IC_EVEX_L2_OPSIZE);
       else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
-          Prefix == X86Local::TAXD)
+               Prefix == X86Local::TAXD)
         insnContext = EVEX_KB(IC_EVEX_L2_XD);
       else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
         insnContext = EVEX_KB(IC_EVEX_L2_XS);
@@ -367,7 +360,8 @@ InstructionContext RecognizableInstr::insnContext() const {
     }
     else if (HasVEX_WPrefix) {
       // VEX_W
-      if (HasOpSizePrefix)
+      if (HasOpSizePrefix || Prefix == X86Local::PD ||
+          Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
         insnContext = EVEX_KB(IC_EVEX_W_OPSIZE);
       else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
         insnContext = EVEX_KB(IC_EVEX_W_XS);
@@ -378,7 +372,8 @@ InstructionContext RecognizableInstr::insnContext() const {
         insnContext = EVEX_KB(IC_EVEX_W);
     }
     // No L, no W
-    else if (HasOpSizePrefix)
+    else if (HasOpSizePrefix || Prefix == X86Local::PD ||
+          Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
       insnContext = EVEX_KB(IC_EVEX_OPSIZE);
     else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
              Prefix == X86Local::TAXD)
@@ -390,7 +385,8 @@ InstructionContext RecognizableInstr::insnContext() const {
     /// eof EVEX
   } else if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix|| HasVEXPrefix) {
     if (HasVEX_LPrefix && HasVEX_WPrefix) {
-      if (HasOpSizePrefix)
+      if (HasOpSizePrefix || Prefix == X86Local::PD ||
+          Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
         insnContext = IC_VEX_L_W_OPSIZE;
       else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
         insnContext = IC_VEX_L_W_XS;
@@ -399,11 +395,16 @@ InstructionContext RecognizableInstr::insnContext() const {
         insnContext = IC_VEX_L_W_XD;
       else
         insnContext = IC_VEX_L_W;
-    } else if (HasOpSizePrefix && HasVEX_LPrefix)
+    } else if ((HasOpSizePrefix || Prefix == X86Local::PD ||
+                Prefix == X86Local::T8PD || Prefix == X86Local::TAPD) &&
+               HasVEX_LPrefix)
       insnContext = IC_VEX_L_OPSIZE;
-    else if (HasOpSizePrefix && HasVEX_WPrefix)
+    else if ((HasOpSizePrefix || Prefix == X86Local::PD ||
+              Prefix == X86Local::T8PD || Prefix == X86Local::TAPD) &&
+             HasVEX_WPrefix)
       insnContext = IC_VEX_W_OPSIZE;
-    else if (HasOpSizePrefix)
+    else if (HasOpSizePrefix || Prefix == X86Local::PD ||
+             Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
       insnContext = IC_VEX_OPSIZE;
     else if (HasVEX_LPrefix &&
              (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
@@ -431,7 +432,8 @@ InstructionContext RecognizableInstr::insnContext() const {
     else
       insnContext = IC_VEX;
   } else if (Is64Bit || HasREX_WPrefix) {
-    if (HasREX_WPrefix && HasOpSizePrefix)
+    if (HasREX_WPrefix && (HasOpSizePrefix || Prefix == X86Local::PD ||
+                           Prefix == X86Local::T8PD || Prefix == X86Local::TAPD))
       insnContext = IC_64BIT_REXW_OPSIZE;
     else if (HasOpSizePrefix && (Prefix == X86Local::XD ||
                                  Prefix == X86Local::T8XD ||
@@ -440,7 +442,8 @@ InstructionContext RecognizableInstr::insnContext() const {
     else if (HasOpSizePrefix &&
              (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
       insnContext = IC_64BIT_XS_OPSIZE;
-    else if (HasOpSizePrefix)
+    else if (HasOpSizePrefix || Prefix == X86Local::PD ||
+             Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
       insnContext = IC_64BIT_OPSIZE;
     else if (HasAdSizePrefix)
       insnContext = IC_64BIT_ADSIZE;
@@ -468,7 +471,10 @@ InstructionContext RecognizableInstr::insnContext() const {
     else if (HasOpSizePrefix &&
              (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
       insnContext = IC_XS_OPSIZE;
-    else if (HasOpSizePrefix)
+    else if (HasOpSizePrefix && HasAdSizePrefix)
+      insnContext = IC_OPSIZE_ADSIZE;
+    else if (HasOpSizePrefix || Prefix == X86Local::PD ||
+             Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
       insnContext = IC_OPSIZE;
     else if (HasAdSizePrefix)
       insnContext = IC_ADSIZE;
@@ -494,25 +500,13 @@ RecognizableInstr::filter_ret RecognizableInstr::filter() const {
 
   assert(Rec->isSubClassOf("X86Inst") && "Can only filter X86 instructions");
 
-  if (Form == X86Local::Pseudo ||
-      (IsCodeGenOnly && Name.find("_REV") == Name.npos &&
-       Name.find("INC32") == Name.npos && Name.find("DEC32") == Name.npos))
+  if (Form == X86Local::Pseudo || (IsCodeGenOnly && !ForceDisassemble))
     return FILTER_STRONG;
 
 
   // Filter out artificial instructions but leave in the LOCK_PREFIX so it is
   // printed as a separate "instruction".
 
-  if (Name.find("_Int") != Name.npos       ||
-      Name.find("Int_") != Name.npos)
-    return FILTER_STRONG;
-
-  // Filter out instructions with segment override prefixes.
-  // They're too messy to handle now and we'll special case them if needed.
-
-  if (SegOvr)
-    return FILTER_STRONG;
-
 
   /////////////////
   // FILTER_WEAK
@@ -524,19 +518,9 @@ RecognizableInstr::filter_ret RecognizableInstr::filter() const {
   if (HasLockPrefix)
     return FILTER_WEAK;
 
-  // Filter out alternate forms of AVX instructions
-  if (Name.find("_alt") != Name.npos ||
-      (Name.find("r64r") != Name.npos && Name.find("r64r64") == Name.npos && Name.find("r64r8") == Name.npos) ||
-      Name.find("_64mr") != Name.npos ||
-      Name.find("rr64") != Name.npos)
-    return FILTER_WEAK;
-
   // Special cases.
 
-  if (Name == "PUSH64i16"         ||
-      Name == "MOVPQI2QImr"       ||
-      Name == "VMOVPQI2QImr"      ||
-      Name == "VMASKMOVDQU64")
+  if (Name == "VMASKMOVDQU64")
     return FILTER_WEAK;
 
   // XACQUIRE and XRELEASE reuse REPNE and REP respectively.
@@ -548,19 +532,6 @@ RecognizableInstr::filter_ret RecognizableInstr::filter() const {
   return FILTER_NORMAL;
 }
 
-bool RecognizableInstr::hasFROperands() const {
-  const std::vector<CGIOperandList::OperandInfo> &OperandList = *Operands;
-  unsigned numOperands = OperandList.size();
-
-  for (unsigned operandIndex = 0; operandIndex < numOperands; ++operandIndex) {
-    const std::string &recName = OperandList[operandIndex].Rec->getName();
-
-    if (recName.find("FR") != recName.npos)
-      return true;
-  }
-  return false;
-}
-
 void RecognizableInstr::handleOperand(bool optional, unsigned &operandIndex,
                                       unsigned &physicalOperandIndex,
                                       unsigned &numPhysicalOperands,
@@ -896,7 +867,8 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
 
   switch (Prefix) {
   default: llvm_unreachable("Invalid prefix!");
-  // Extended two-byte opcodes can start with f2 0f, f3 0f, or 0f
+  // Extended two-byte opcodes can start with 66 0f, f2 0f, f3 0f, or 0f
+  case X86Local::PD:
   case X86Local::XD:
   case X86Local::XS:
   case X86Local::TB:
@@ -942,6 +914,7 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
     opcodeToSet = Opcode;
     break;
   case X86Local::T8:
+  case X86Local::T8PD:
   case X86Local::T8XD:
   case X86Local::T8XS:
     opcodeType = THREEBYTE_38;
@@ -985,6 +958,7 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
     opcodeToSet = Opcode;
     break;
   case X86Local::P_TA:
+  case X86Local::TAPD:
   case X86Local::TAXD:
     opcodeType = THREEBYTE_3A;
     if (needsModRMForDecode(Form))