[llvm-commits] [dragonegg] r152530 - /dragonegg/trunk/src/x86/Target.cpp

Duncan Sands baldrick at free.fr
Sat Mar 10 19:36:00 PST 2012


Author: baldrick
Date: Sat Mar 10 21:36:00 2012
New Revision: 152530

URL: http://llvm.org/viewvc/llvm-project?rev=152530&view=rev
Log:
Add support for the clzs and ctzs x86 builtins, which show up on
some processors.

Modified:
    dragonegg/trunk/src/x86/Target.cpp

Modified: dragonegg/trunk/src/x86/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/x86/Target.cpp?rev=152530&r1=152529&r2=152530&view=diff
==============================================================================
--- dragonegg/trunk/src/x86/Target.cpp (original)
+++ dragonegg/trunk/src/x86/Target.cpp Sat Mar 10 21:36:00 2012
@@ -61,6 +61,8 @@
 /// BuiltinCode - A enumerated type with one value for each supported builtin.
 enum BuiltinCode {
   SearchForHandler, // Builtin not seen before - search for a handler.
+  clzs, // Builtin with exceptional name.
+  ctzs, // Builtin with exceptional name.
 #define DEFINE_BUILTIN(x) x
 #include "x86_builtins"
 #undef DEFINE_BUILTIN
@@ -104,9 +106,11 @@
     // No associated BuiltinCode.  Work out what value to use based on the
     // builtin's name.
 
-    // List of builtin names (w/o '__builtin_ia32_') and associated BuiltinCode.
+    // List of builtin names and associated BuiltinCode.
     static const HandlerEntry Handlers[] = {
-#define DEFINE_BUILTIN(x) {#x, x}
+      {"__builtin_clzs", clzs}, // Builtin with exceptional name.
+      {"__builtin_ctzs", ctzs}, // Builtin with exceptional name.
+#define DEFINE_BUILTIN(x) {"__builtin_ia32_" #x, x}
 #include "x86_builtins"
 #undef DEFINE_BUILTIN
     };
@@ -123,14 +127,11 @@
 
     Handler = UnsupportedBuiltin;
     const char *Identifier = IDENTIFIER_POINTER(DECL_NAME(fndecl));
-    // All builtins handled here have a name starting with __builtin_ia32_.
-    if (!strncmp(Identifier, "__builtin_ia32_", 15)) {
-      HandlerEntry ToFind = { Identifier + 15, SearchForHandler };
-      const HandlerEntry *E = std::lower_bound(Handlers, Handlers + N, ToFind,
-                                               HandlerLT);
-      if ((E < Handlers + N) && !strcmp(E->Name, ToFind.Name))
-        Handler = E->Handler;
-    }
+    HandlerEntry ToFind = { Identifier, SearchForHandler };
+    const HandlerEntry *E = std::lower_bound(Handlers, Handlers + N, ToFind,
+                                             HandlerLT);
+    if ((E < Handlers + N) && !strcmp(E->Name, ToFind.Name))
+      Handler = E->Handler;
   }
 
   bool flip = false;
@@ -898,6 +899,18 @@
     Result = Builder.CreateBitCast(Result, ResultType);
     return true;
   }
+  case clzs: {
+    Function *ctlz = Intrinsic::getDeclaration(TheModule, Intrinsic::ctlz,
+                                               Ops[0]->getType());
+    Result = Builder.CreateCall2(ctlz, Ops[0], Builder.getTrue());
+    return true;
+  }
+  case ctzs: {
+    Function *cttz = Intrinsic::getDeclaration(TheModule, Intrinsic::cttz,
+                                               Ops[0]->getType());
+    Result = Builder.CreateCall2(cttz, Ops[0], Builder.getTrue());
+    return true;
+  }
   }
   llvm_unreachable("Forgot case for code?");
 }





More information about the llvm-commits mailing list