[PATCH] D14219: [TargetLibraryInfo] Add support for fls, flsl, flsll

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 1 09:32:33 PST 2015


davide created this revision.
davide added a reviewer: echristo.
davide added a subscriber: llvm-commits.

These three function are similar to ffs but find the last bit set. They're available (at least) on FreeBSD. I'm not sure they're availalble elsewhere, I don't have a machine to test. A quick search shows Linux hasn't them.
I would like top perform fairly basic transformations on these, e.g. constant folding, so this patch can be seen as a preliminary step for those.


http://reviews.llvm.org/D14219

Files:
  include/llvm/Analysis/TargetLibraryInfo.def
  lib/Analysis/TargetLibraryInfo.cpp

Index: lib/Analysis/TargetLibraryInfo.cpp
===================================================================
--- lib/Analysis/TargetLibraryInfo.cpp
+++ lib/Analysis/TargetLibraryInfo.cpp
@@ -343,6 +343,16 @@
     TLI.setUnavailable(LibFunc::ffsll);
   }
 
+  // The following functions are available on at least FreeBSD:
+  // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
+  // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
+  // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
+  if (!T.isOSFreeBSD()) {
+    TLI.setUnavailable(LibFunc::fls);
+    TLI.setUnavailable(LibFunc::flsl);
+    TLI.setUnavailable(LibFunc::flsll);
+  }
+
   // The following functions are available on at least Linux:
   if (!T.isOSLinux()) {
     TLI.setUnavailable(LibFunc::dunder_strdup);
Index: include/llvm/Analysis/TargetLibraryInfo.def
===================================================================
--- include/llvm/Analysis/TargetLibraryInfo.def
+++ include/llvm/Analysis/TargetLibraryInfo.def
@@ -406,6 +406,15 @@
 /// long double floorl(long double x);
 TLI_DEFINE_ENUM_INTERNAL(floorl)
 TLI_DEFINE_STRING_INTERNAL("floorl")
+/// int fls(int i);
+TLI_DEFINE_ENUM_INTERNAL(fls)
+TLI_DEFINE_STRING_INTERNAL("fls")
+/// int flsl(long int i);
+TLI_DEFINE_ENUM_INTERNAL(flsl)
+TLI_DEFINE_STRING_INTERNAL("flsl")
+/// int flsll(long long int i);
+TLI_DEFINE_ENUM_INTERNAL(flsll)
+TLI_DEFINE_STRING_INTERNAL("flsll")
 /// double fmax(double x, double y);
 TLI_DEFINE_ENUM_INTERNAL(fmax)
 TLI_DEFINE_STRING_INTERNAL("fmax")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14219.38856.patch
Type: text/x-patch
Size: 1538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151101/3f777d6a/attachment.bin>


More information about the llvm-commits mailing list