[llvm-commits] [llvm] r97423 - in /llvm/trunk: include/llvm/CodeGen/DAGISelHeader.h include/llvm/CodeGen/SelectionDAGISel.h utils/TableGen/DAGISelMatcherEmitter.cpp

Chris Lattner sabre at nondot.org
Sun Feb 28 14:14:32 PST 2010


Author: lattner
Date: Sun Feb 28 16:14:32 2010
New Revision: 97423

URL: http://llvm.org/viewvc/llvm-project?rev=97423&view=rev
Log:
change a few opcodes to use VBRs instead of embedding
immediate sizes into the opcode.

Modified:
    llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h
    llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h
    llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h?rev=97423&r1=97422&r2=97423&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h (original)
+++ llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h Sun Feb 28 16:14:32 2010
@@ -167,11 +167,6 @@
   return true;
 }
 
-void EmitInteger(int64_t Val, MVT::SimpleValueType VT,
-                 SmallVectorImpl<SDValue> &RecordedNodes) {
-  RecordedNodes.push_back(CurDAG->getTargetConstant(Val, VT));
-}
-
 // These functions are marked always inline so that Idx doesn't get pinned to
 // the stack.
 ALWAYS_INLINE static int8_t
@@ -186,28 +181,14 @@
   return Val;
 }
 
-ALWAYS_INLINE static int32_t
-GetInt4(const unsigned char *MatcherTable, unsigned &Idx) {
-  int32_t Val = (uint16_t)GetInt2(MatcherTable, Idx);
-  Val |= int32_t(GetInt2(MatcherTable, Idx)) << 16;
-  return Val;
-}
-
-ALWAYS_INLINE static int64_t
-GetInt8(const unsigned char *MatcherTable, unsigned &Idx) {
-  int64_t Val = (uint32_t)GetInt4(MatcherTable, Idx);
-  Val |= int64_t(GetInt4(MatcherTable, Idx)) << 32;
-  return Val;
-}
-
 /// GetVBR - decode a vbr encoding whose top bit is set.
-ALWAYS_INLINE static unsigned
-GetVBR(unsigned Val, const unsigned char *MatcherTable, unsigned &Idx) {
+ALWAYS_INLINE static uint64_t
+GetVBR(uint64_t Val, const unsigned char *MatcherTable, unsigned &Idx) {
   assert(Val >= 128 && "Not a VBR");
   Val &= 127;  // Remove first vbr bit.
   
   unsigned Shift = 7;
-  unsigned NextBits;
+  uint64_t NextBits;
   do {
     NextBits = GetInt1(MatcherTable, Idx);
     Val |= (NextBits&127) << Shift;
@@ -501,44 +482,27 @@
       }
       continue;
     }
-    case OPC_CheckInteger1:
-      if (CheckInteger(N, GetInt1(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckInteger2:
-      if (CheckInteger(N, GetInt2(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckInteger4:
-      if (CheckInteger(N, GetInt4(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckInteger8:
-      if (CheckInteger(N, GetInt8(MatcherTable, MatcherIndex))) break;
-      continue;
-        
-    case OPC_CheckAndImm1:
-      if (CheckAndImmediate(N, GetInt1(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckAndImm2:
-      if (CheckAndImmediate(N, GetInt2(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckAndImm4:
-      if (CheckAndImmediate(N, GetInt4(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckAndImm8:
-      if (CheckAndImmediate(N, GetInt8(MatcherTable, MatcherIndex))) break;
-      continue;
-
-    case OPC_CheckOrImm1:
-      if (CheckOrImmediate(N, GetInt1(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckOrImm2:
-      if (CheckOrImmediate(N, GetInt2(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckOrImm4:
-      if (CheckOrImmediate(N, GetInt4(MatcherTable, MatcherIndex))) break;
-      continue;
-    case OPC_CheckOrImm8:
-      if (CheckOrImmediate(N, GetInt8(MatcherTable, MatcherIndex))) break;
+    case OPC_CheckInteger: {
+      int64_t Val = MatcherTable[MatcherIndex++];
+      if (Val & 128)
+        Val = GetVBR(Val, MatcherTable, MatcherIndex);
+      if (CheckInteger(N, Val)) break;
+      continue;
+    }        
+    case OPC_CheckAndImm: {
+      int64_t Val = MatcherTable[MatcherIndex++];
+      if (Val & 128)
+        Val = GetVBR(Val, MatcherTable, MatcherIndex);
+      if (CheckAndImmediate(N, Val)) break;
+      continue;
+    }
+    case OPC_CheckOrImm: {
+      int64_t Val = MatcherTable[MatcherIndex++];
+      if (Val & 128)
+        Val = GetVBR(Val, MatcherTable, MatcherIndex);
+      if (CheckOrImmediate(N, Val)) break;
       continue;
+    }
         
     case OPC_CheckFoldableChainNode: {
       assert(NodeStack.size() != 1 && "No parent node");
@@ -581,31 +545,15 @@
       continue;
     }
         
-    case OPC_EmitInteger1: {
-      MVT::SimpleValueType VT =
-        (MVT::SimpleValueType)MatcherTable[MatcherIndex++];
-      EmitInteger(GetInt1(MatcherTable, MatcherIndex), VT, RecordedNodes);
-      continue;
-    }
-    case OPC_EmitInteger2: {
+    case OPC_EmitInteger: {
       MVT::SimpleValueType VT =
         (MVT::SimpleValueType)MatcherTable[MatcherIndex++];
-      EmitInteger(GetInt2(MatcherTable, MatcherIndex), VT, RecordedNodes);
+      int64_t Val = MatcherTable[MatcherIndex++];
+      if (Val & 128)
+        Val = GetVBR(Val, MatcherTable, MatcherIndex);
+      RecordedNodes.push_back(CurDAG->getTargetConstant(Val, VT));
       continue;
     }
-    case OPC_EmitInteger4: {
-      MVT::SimpleValueType VT =
-        (MVT::SimpleValueType)MatcherTable[MatcherIndex++];
-      EmitInteger(GetInt4(MatcherTable, MatcherIndex), VT, RecordedNodes);
-      continue;
-    }
-    case OPC_EmitInteger8: {
-      MVT::SimpleValueType VT =
-       (MVT::SimpleValueType)MatcherTable[MatcherIndex++];
-      EmitInteger(GetInt8(MatcherTable, MatcherIndex), VT, RecordedNodes);
-      continue;
-    }
-        
     case OPC_EmitRegister: {
       MVT::SimpleValueType VT =
         (MVT::SimpleValueType)MatcherTable[MatcherIndex++];

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h?rev=97423&r1=97422&r2=97423&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h Sun Feb 28 16:14:32 2010
@@ -117,16 +117,15 @@
     OPC_CheckChild0Type, OPC_CheckChild1Type, OPC_CheckChild2Type,
     OPC_CheckChild3Type, OPC_CheckChild4Type, OPC_CheckChild5Type,
     OPC_CheckChild6Type, OPC_CheckChild7Type,
-    OPC_CheckInteger1, OPC_CheckInteger2, OPC_CheckInteger4, OPC_CheckInteger8,
+    OPC_CheckInteger,
     OPC_CheckCondCode,
     OPC_CheckValueType,
     OPC_CheckComplexPat,
-    OPC_CheckAndImm1, OPC_CheckAndImm2, OPC_CheckAndImm4, OPC_CheckAndImm8,
-    OPC_CheckOrImm1, OPC_CheckOrImm2, OPC_CheckOrImm4, OPC_CheckOrImm8,
+    OPC_CheckAndImm, OPC_CheckOrImm,
     OPC_CheckFoldableChainNode,
     OPC_CheckChainCompatible,
     
-    OPC_EmitInteger1, OPC_EmitInteger2, OPC_EmitInteger4, OPC_EmitInteger8,
+    OPC_EmitInteger,
     OPC_EmitRegister,
     OPC_EmitConvertToTarget,
     OPC_EmitMergeInputChains,

Modified: llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp?rev=97423&r1=97422&r2=97423&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp Sun Feb 28 16:14:32 2010
@@ -24,46 +24,6 @@
   CommentIndent = 30
 };
 
-/// ClassifyInt - Classify an integer by size, return '1','2','4','8' if this
-/// fits in 1, 2, 4, or 8 sign extended bytes.
-static char ClassifyInt(int64_t Val) {
-  if (Val == int8_t(Val))  return '1';
-  if (Val == int16_t(Val)) return '2';
-  if (Val == int32_t(Val)) return '4';
-  return '8';
-}
-
-/// EmitInt - Emit the specified integer, returning the number of bytes emitted.
-static unsigned EmitInt(int64_t Val, formatted_raw_ostream &OS) {
-  unsigned BytesEmitted = 1;
-  OS << (int)(unsigned char)Val << ", ";
-  if (Val == int8_t(Val)) {
-    OS << '\n';
-    return BytesEmitted;
-  }
-  
-  OS << (int)(unsigned char)(Val >> 8) << ", ";
-  ++BytesEmitted;
-  
-  if (Val != int16_t(Val)) {
-    OS << (int)(unsigned char)(Val >> 16) << ", "
-       << (int)(unsigned char)(Val >> 24) << ", ";
-    BytesEmitted += 2;
-    
-    if (Val != int32_t(Val)) {
-      OS << (int)(unsigned char)(Val >> 32) << ", "
-         << (int)(unsigned char)(Val >> 40) << ", "
-         << (int)(unsigned char)(Val >> 48) << ", "
-         << (int)(unsigned char)(Val >> 56) << ", ";
-      BytesEmitted += 4;
-    }   
-  }
-  
-  OS.PadToColumn(CommentIndent) << "// " << Val << " aka 0x";
-  OS.write_hex(Val) << '\n';
-  return BytesEmitted;
-}
-
 namespace {
 class MatcherTableEmitter {
   StringMap<unsigned> NodePredicateMap, PatternPredicateMap;
@@ -142,13 +102,13 @@
 
 /// EmitVBRValue - Emit the specified value as a VBR, returning the number of
 /// bytes emitted.
-static unsigned EmitVBRValue(unsigned Val, raw_ostream &OS) {
+static uint64_t EmitVBRValue(uint64_t Val, raw_ostream &OS) {
   if (Val <= 127) {
     OS << Val << ", ";
     return 1;
   }
   
-  unsigned InVal = Val;
+  uint64_t InVal = Val;
   unsigned NumBytes = 0;
   while (Val >= 128) {
     OS << (Val&127) << "|128,";
@@ -291,11 +251,9 @@
        << getEnumName(cast<CheckChildTypeMatcher>(N)->getType()) << ",\n";
     return 2;
       
-  case Matcher::CheckInteger: {
-    int64_t Val = cast<CheckIntegerMatcher>(N)->getValue();
-    OS << "OPC_CheckInteger" << ClassifyInt(Val) << ", ";
-    return EmitInt(Val, OS)+1;
-  }   
+  case Matcher::CheckInteger:
+    OS << "OPC_CheckInteger, ";
+    return 1+EmitVBRValue(cast<CheckIntegerMatcher>(N)->getValue(), OS);
   case Matcher::CheckCondCode:
     OS << "OPC_CheckCondCode, ISD::"
        << cast<CheckCondCodeMatcher>(N)->getCondCodeName() << ",\n";
@@ -318,17 +276,14 @@
     return 2;
   }
       
-  case Matcher::CheckAndImm: {
-    int64_t Val = cast<CheckAndImmMatcher>(N)->getValue();
-    OS << "OPC_CheckAndImm" << ClassifyInt(Val) << ", ";
-    return EmitInt(Val, OS)+1;
-  }
-
-  case Matcher::CheckOrImm: {
-    int64_t Val = cast<CheckOrImmMatcher>(N)->getValue();
-    OS << "OPC_CheckOrImm" << ClassifyInt(Val) << ", ";
-    return EmitInt(Val, OS)+1;
-  }
+  case Matcher::CheckAndImm:
+    OS << "OPC_CheckAndImm, ";
+    return 1+EmitVBRValue(cast<CheckAndImmMatcher>(N)->getValue(), OS);
+
+  case Matcher::CheckOrImm:
+    OS << "OPC_CheckOrImm, ";
+    return 1+EmitVBRValue(cast<CheckOrImmMatcher>(N)->getValue(), OS);
+      
   case Matcher::CheckFoldableChainNode:
     OS << "OPC_CheckFoldableChainNode,\n";
     return 1;
@@ -339,14 +294,14 @@
       
   case Matcher::EmitInteger: {
     int64_t Val = cast<EmitIntegerMatcher>(N)->getValue();
-    OS << "OPC_EmitInteger" << ClassifyInt(Val) << ", "
+    OS << "OPC_EmitInteger, "
        << getEnumName(cast<EmitIntegerMatcher>(N)->getVT()) << ", ";
-    return EmitInt(Val, OS)+2;
+    return 2+EmitVBRValue(Val, OS);
   }
   case Matcher::EmitStringInteger: {
     const std::string &Val = cast<EmitStringIntegerMatcher>(N)->getValue();
     // These should always fit into one byte.
-    OS << "OPC_EmitInteger1, "
+    OS << "OPC_EmitInteger, "
       << getEnumName(cast<EmitStringIntegerMatcher>(N)->getVT()) << ", "
       << Val << ",\n";
     return 3;





More information about the llvm-commits mailing list