Changes for ffs lib call simplification:
authorReid Spencer <rspencer@reidspencer.com>
Sat, 14 May 2005 16:42:52 +0000 (16:42 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sat, 14 May 2005 16:42:52 +0000 (16:42 +0000)
* Check for availability of ffsll call in configure script
* Support ffs, ffsl, and ffsll conversion to constant value if the argument
  is constant.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22027 91177308-0d34-0410-b5e6-96231b3b80d8

autoconf/configure.ac
configure
lib/Transforms/IPO/SimplifyLibCalls.cpp

index 093d9f1f47d35a19cfd6b5c1e8c50adc7cd08b99..becdb14b32c6bb013934a0a677593f926f781aa0 100644 (file)
@@ -484,8 +484,8 @@ dnl=== SECTION 8: Check for specific functions needed
 dnl===
 dnl===-----------------------------------------------------------------------===
 
-AC_CHECK_FUNCS([backtrace getcwd getpagesize getrusage gettimeofday isatty ])
-AC_CHECK_FUNCS([mkdtemp mkstemp mktemp ])
+AC_CHECK_FUNCS([backtrace ffsll getcwd getpagesize getrusage gettimeofday ])
+AC_CHECK_FUNCS([isatty mkdtemp mkstemp mktemp ])
 AC_CHECK_FUNCS([realpath sbrk setrlimit strdup strerror strerror_r ])
 AC_CHECK_FUNCS([strtoll strtoq sysconf])
 AC_C_PRINTF_A
index 948517019d26d5571867198839418825aaf0e0bd..4948bc61c548219d8aaf3b3727ceb6e488fd64c7 100755 (executable)
--- a/configure
+++ b/configure
@@ -27227,7 +27227,7 @@ fi
 
 
 
-for ac_func in backtrace getcwd getpagesize getrusage gettimeofday isatty
+for ac_func in backtrace ffsll getcwd getpagesize getrusage gettimeofday
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -27331,7 +27331,8 @@ done
 
 
 
-for ac_func in mkdtemp mkstemp mktemp
+
+for ac_func in isatty mkdtemp mkstemp mktemp
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 echo "$as_me:$LINENO: checking for $ac_func" >&5
index 24bcf4ed63075366445d917c32691d979140f240..951516a184227b849433dcdcaecef5e95a8efa92 100644 (file)
@@ -1672,6 +1672,80 @@ public:
   }
 } ToAsciiOptimizer;
 
+#if defined(HAVE_FFSLL)
+/// This LibCallOptimization will simplify calls to the "ffs" library
+/// calls which find the first set bit in an int, long, or long long. The 
+/// optimization is to compute the result at compile time if the argument is
+/// a constant.
+/// @brief Simplify the ffs library function.
+struct FFSOptimization : public LibCallOptimization
+{
+protected:
+  /// @brief Subclass Constructor
+  FFSOptimization(const char* funcName, const char* description)
+    : LibCallOptimization(funcName, description)
+    {}
+
+public:
+  /// @brief Default Constructor
+  FFSOptimization() : LibCallOptimization("ffs",
+      "Number of 'ffs' calls simplified") {}
+
+  /// @brief Destructor
+  virtual ~FFSOptimization() {}
+
+  /// @brief Make sure that the "fputs" function has the right prototype
+  virtual bool ValidateCalledFunction(const Function* f, SimplifyLibCalls& SLC)
+  {
+    // Just make sure this has 2 arguments
+    return (f->arg_size() == 1 && f->getReturnType() == Type::IntTy);
+  }
+
+  /// @brief Perform the ffs optimization.
+  virtual bool OptimizeCall(CallInst* ci, SimplifyLibCalls& SLC)
+  {
+    if (ConstantInt* CI = dyn_cast<ConstantInt>(ci->getOperand(1)))
+    {
+      // ffs(cnst)  -> bit#
+      // ffsl(cnst) -> bit#
+      uint64_t val = CI->getRawValue();
+      int result = ffsll(static_cast<long long>(val));
+      ci->replaceAllUsesWith(ConstantSInt::get(Type::IntTy, result));
+      ci->eraseFromParent();
+      return true;
+    }
+    return false;
+  }
+} FFSOptimizer;
+
+/// This LibCallOptimization will simplify calls to the "ffsl" library
+/// calls. It simply uses FFSOptimization for which the transformation is
+/// identical.
+/// @brief Simplify the ffsl library function.
+struct FFSLOptimization : public FFSOptimization
+{
+public:
+  /// @brief Default Constructor
+  FFSLOptimization() : FFSOptimization("ffsl",
+      "Number of 'ffsl' calls simplified") {}
+
+} FFSLOptimizer;
+
+/// This LibCallOptimization will simplify calls to the "ffsll" library
+/// calls. It simply uses FFSOptimization for which the transformation is
+/// identical.
+/// @brief Simplify the ffsl library function.
+struct FFSLLOptimization : public FFSOptimization
+{
+public:
+  /// @brief Default Constructor
+  FFSLLOptimization() : FFSOptimization("ffsll",
+      "Number of 'ffsll' calls simplified") {}
+
+} FFSLLOptimizer;
+
+#endif
+
 /// A function to compute the length of a null-terminated constant array of
 /// integers.  This function can't rely on the size of the constant array 
 /// because there could be a null terminator in the middle of the array. 
@@ -1788,9 +1862,6 @@ bool getConstantStringLength(Value* V, uint64_t& len, ConstantArray** CA )
 // exp, expf, expl:
 //   * exp(log(x))  -> x
 //
-// ffs, ffsl, ffsll:
-//   * ffs(cnst)     -> cnst'
-//
 // isascii:
 //   * isascii(c)    -> ((c & ~0x7f) == 0)
 //