[llvm-commits] [llvm] r105531 - /llvm/trunk/utils/TableGen/NeonEmitter.cpp

Nate Begeman natebegeman at mac.com
Mon Jun 7 09:00:37 PDT 2010


Author: sampo
Date: Mon Jun  7 11:00:37 2010
New Revision: 105531

URL: http://llvm.org/viewvc/llvm-project?rev=105531&view=rev
Log:
clang codegen support

Modified:
    llvm/trunk/utils/TableGen/NeonEmitter.cpp

Modified: llvm/trunk/utils/TableGen/NeonEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/NeonEmitter.cpp?rev=105531&r1=105530&r2=105531&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/NeonEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/NeonEmitter.cpp Mon Jun  7 11:00:37 2010
@@ -100,24 +100,9 @@
   return ty[off];
 }
 
-static std::string TypeString(const char mod, StringRef typestr,
-                              bool ret = false) {
-  bool quad = false;
-  bool poly = false;
-  bool usgn = false;
-  bool scal = false;
-  bool cnst = false;
-  bool pntr = false;
-  
-  // base type to get the type string for.
-  char type = ClassifyType(typestr, quad, poly, usgn);
-  
-  // Based on the modifying character, change the type and width if necessary.
+static char ModType(const char mod, char type, bool &quad, bool &poly,
+                    bool &usgn, bool &scal, bool &cnst, bool &pntr) {
   switch (mod) {
-    case 'v':
-      return "void";
-    case 'i':
-      return "int";
     case 't':
       if (poly) {
         poly = false;
@@ -155,6 +140,8 @@
     case 'c':
       cnst = true;
     case 'p':
+      usgn = false;
+      poly = false;
       pntr = true;
       scal = true;
       break;
@@ -168,6 +155,28 @@
     default:
       break;
   }
+  return type;
+}
+
+static std::string TypeString(const char mod, StringRef typestr,
+                              bool ret = false) {
+  bool quad = false;
+  bool poly = false;
+  bool usgn = false;
+  bool scal = false;
+  bool cnst = false;
+  bool pntr = false;
+  
+  if (mod == 'v')
+    return "void";
+  if (mod == 'i')
+    return "int";
+  
+  // base type to get the type string for.
+  char type = ClassifyType(typestr, quad, poly, usgn);
+  
+  // Based on the modifying character, change the type and width if necessary.
+  type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
   
   SmallString<128> s;
   
@@ -256,60 +265,11 @@
   char type = ClassifyType(typestr, quad, poly, usgn);
   
   // Based on the modifying character, change the type and width if necessary.
-  switch (mod) {
-    case 't':
-      if (poly) {
-        poly = false;
-        usgn = true;
-      }
-      break;
-    case 'x':
-      usgn = true;
-      poly = false;
-      if (type == 'f')
-        type = 'i';
-      break;
-    case 'f':
-      type = 'f';
-      usgn = false;
-      break;
-    case 'w':
-      type = Widen(type);
-      quad = true;
-      break;
-    case 'n':
-      type = Widen(type);
-      break;
-    case 'l':
-      type = 'l';
-      scal = true;
-      usgn = true;
-      break;
-    case 's':
-      scal = true;
-      break;
-    case 'k':
-      quad = true;
-      break;
-    case 'c':
-      cnst = true;
-    case 'p':
-      type = 'v';
-      usgn = false;
-      poly = false;
-      pntr = true;
-      scal = true;
-      break;
-    case 'h':
-      type = Narrow(type);
-      break;
-    case 'e':
-      type = Narrow(type);
-      usgn = true;
-      break;
-    default:
-      break;
-  }
+  type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
+
+  if (pntr)
+    type = 'v';
+  
   if (type == 'h') {
     type = 's';
     usgn = true;
@@ -534,6 +494,57 @@
   return s;
 }
 
+static unsigned GetNeonEnum(const std::string &proto, StringRef typestr) {
+  unsigned mod = proto[0];
+  unsigned ret = 0;
+
+  if (mod == 'v')
+    mod = proto[1];
+
+  bool quad = false;
+  bool poly = false;
+  bool usgn = false;
+  bool scal = false;
+  bool cnst = false;
+  bool pntr = false;
+  
+  // base type to get the type string for.
+  char type = ClassifyType(typestr, quad, poly, usgn);
+  
+  // Based on the modifying character, change the type and width if necessary.
+  type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
+  
+  if (usgn)
+    ret |= 0x08;
+  if (quad)
+    ret |= 0x10;
+  
+  switch (type) {
+    case 'c': 
+      ret |= poly ? 5 : 0;
+      break;
+    case 's':
+      ret |= poly ? 6 : 1;
+      break;
+    case 'i':
+      ret |= 2;
+      break;
+    case 'l':
+      ret |= 3;
+      break;
+    case 'h':
+      ret |= 7;
+      break;
+    case 'f':
+      ret |= 4;
+      break;
+    default:
+      throw "unhandled type!";
+      break;
+  }
+  return ret;
+}
+
 // Generate the definition for this intrinsic, e.g. __builtin_neon_cls(a)
 // If structTypes is true, the NEON types are structs of vector types rather
 // than vector types, and the call becomes __builtin_neon_cls(a.val)
@@ -599,9 +610,8 @@
   }
   
   // Extra constant integer to hold type class enum for this function, e.g. s8
-  // FIXME: emit actual type num.
   if (ck == ClassB)
-    s += ", 0";
+    s += ", " + utostr(GetNeonEnum(proto, typestr));
   
   s += ");";
 





More information about the llvm-commits mailing list