Move some constant folding code shared by Analysis and Transform passes
authorJohn Criswell <criswell@uiuc.edu>
Thu, 27 Oct 2005 15:54:34 +0000 (15:54 +0000)
committerJohn Criswell <criswell@uiuc.edu>
Thu, 27 Oct 2005 15:54:34 +0000 (15:54 +0000)
into the LLVMAnalysis library.
This allows LLVMTranform and LLVMTransformUtils to be archives and linked
with LLVMAnalysis.a, which provides any missing definitions.

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

12 files changed:
Makefile.rules
lib/Analysis/ScalarEvolution.cpp
lib/Transforms/Utils/Local.cpp
lib/Transforms/Utils/Makefile
tools/analyze/Makefile
tools/bugpoint/Makefile
tools/gccas/Makefile
tools/gccld/Makefile
tools/llc/Makefile
tools/llvm-extract/Makefile
tools/llvm-ld/Makefile
tools/opt/Makefile

index 04f3660a1ab0c6b755850596e93810ae917b40c6..9f07c1ad6837f117ed359cfbff3d3878fca46d88 100644 (file)
@@ -617,7 +617,7 @@ ifdef ENABLE_ALPHA_JIT
   JIT_LIBS += LLVMAlpha LLVMSelectionDAG
 endif
 
-LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts.a LLVMTransformUtils LLVMAnalysis.a \
+LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts.a LLVMTransformUtils.a LLVMAnalysis.a \
             LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
             LLVMSystem.a $(PLATFORMLIBDL)
 endif
index 77f5e3872fc5ba3aa935569c4d86e2593ae3b256..120b9f5e48854e14fd86dc0bacefedf150f0313b 100644 (file)
 #include "llvm/DerivedTypes.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/Instructions.h"
+#include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/ConstantRange.h"
 #include "llvm/Support/InstIterator.h"
index a9cfcc0a9209d4cc18c11d0a22b3424e08d39905..d82b278f402cb51502960ae616bdef9d0452d36d 100644 (file)
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -234,148 +235,6 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) {
   return false;
 }
 
-/// canConstantFoldCallTo - Return true if its even possible to fold a call to
-/// the specified function.
-bool llvm::canConstantFoldCallTo(Function *F) {
-  const std::string &Name = F->getName();
-
-  switch (F->getIntrinsicID()) {
-  case Intrinsic::isunordered:
-  case Intrinsic::sqrt:
-    return true;
-  default: break;
-  }
-
-  switch (Name[0])
-  {
-    case 'a':
-      return Name == "acos" || Name == "asin" || Name == "atan" ||
-             Name == "atan2";
-    case 'c':
-      return Name == "ceil" || Name == "cos" || Name == "cosf" ||
-             Name == "cosh";
-    case 'e':
-      return Name == "exp";
-    case 'f':
-      return Name == "fabs" || Name == "fmod" || Name == "floor";
-    case 'l':
-      return Name == "log" || Name == "log10";
-    case 'p':
-      return Name == "pow";
-    case 's':
-      return Name == "sin" || Name == "sinh" || Name == "sqrt";
-    case 't':
-      return Name == "tan" || Name == "tanh";
-    default:
-      return false;
-  }
-}
-
-static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
-                                const Type *Ty) {
-  errno = 0;
-  V = NativeFP(V);
-  if (errno == 0)
-    return ConstantFP::get(Ty, V);
-  return 0;
-}
-
-/// ConstantFoldCall - Attempt to constant fold a call to the specified function
-/// with the specified arguments, returning null if unsuccessful.
-Constant *llvm::ConstantFoldCall(Function *F,
-                                 const std::vector<Constant*> &Operands) {
-  const std::string &Name = F->getName();
-  const Type *Ty = F->getReturnType();
-
-  if (Operands.size() == 1) {
-    if (ConstantFP *Op = dyn_cast<ConstantFP>(Operands[0])) {
-      double V = Op->getValue();
-      switch (Name[0])
-      {
-        case 'a':
-          if (Name == "acos")
-            return ConstantFoldFP(acos, V, Ty);
-          else if (Name == "asin")
-            return ConstantFoldFP(asin, V, Ty);
-          else if (Name == "atan")
-            return ConstantFP::get(Ty, atan(V));
-          break;
-        case 'c':
-          if (Name == "ceil")
-            return ConstantFoldFP(ceil, V, Ty);
-          else if (Name == "cos")
-            return ConstantFP::get(Ty, cos(V));
-          else if (Name == "cosh")
-            return ConstantFP::get(Ty, cosh(V));
-          break;
-        case 'e':
-          if (Name == "exp")
-            return ConstantFP::get(Ty, exp(V));
-          break;
-        case 'f':
-          if (Name == "fabs")
-            return ConstantFP::get(Ty, fabs(V));
-          else if (Name == "floor")
-            return ConstantFoldFP(floor, V, Ty);
-          break;
-        case 'l':
-          if (Name == "log" && V > 0)
-            return ConstantFP::get(Ty, log(V));
-          else if (Name == "log10" && V > 0)
-            return ConstantFoldFP(log10, V, Ty);
-          else if (Name == "llvm.sqrt") {
-            if (V >= -0.0)
-              return ConstantFP::get(Ty, sqrt(V));
-            else // Undefined
-              return ConstantFP::get(Ty, 0.0);
-          }
-          break;
-        case 's':
-          if (Name == "sin")
-            return ConstantFP::get(Ty, sin(V));
-          else if (Name == "sinh")
-            return ConstantFP::get(Ty, sinh(V));
-          else if (Name == "sqrt" && V >= 0)
-            return ConstantFP::get(Ty, sqrt(V));
-          break;
-        case 't':
-          if (Name == "tan")
-            return ConstantFP::get(Ty, tan(V));
-          else if (Name == "tanh")
-            return ConstantFP::get(Ty, tanh(V));
-          break;
-        default:
-          break;
-      }
-    }
-  } else if (Operands.size() == 2) {
-    if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
-      double Op1V = Op1->getValue();
-      if (ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
-        double Op2V = Op2->getValue();
-
-        if (Name == "llvm.isunordered")
-          return ConstantBool::get(IsNAN(Op1V) || IsNAN(Op2V));
-        else
-        if (Name == "pow") {
-          errno = 0;
-          double V = pow(Op1V, Op2V);
-          if (errno == 0)
-            return ConstantFP::get(Ty, V);
-        } else if (Name == "fmod") {
-          errno = 0;
-          double V = fmod(Op1V, Op2V);
-          if (errno == 0)
-            return ConstantFP::get(Ty, V);
-        } else if (Name == "atan2")
-          return ConstantFP::get(Ty, atan2(Op1V,Op2V));
-      }
-    }
-  }
-  return 0;
-}
-
-
 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
 /// getelementptr constantexpr, return the constant value being addressed by the
 /// constant expression, or null if something is funny and we can't decide.
index a0c49bd9dfe85c8f16b1dc13d42551acc778ccd7..26fc4261f161e4ee0b296a8b3c73c0bea10ca9fe 100644 (file)
@@ -9,6 +9,7 @@
 
 LEVEL = ../../..
 LIBRARYNAME = LLVMTransformUtils
+BUILD_ARCHIVE = 1
 
 include $(LEVEL)/Makefile.common
 
index 0d1c2485eba575d3d57c516f74fc604cb68b2184..06def88d01a0982f55fb94b99161ae50a77f8234 100644 (file)
@@ -11,6 +11,6 @@ TOOLNAME = analyze
 USEDLIBS = LLVMAsmParser LLVMBCReader LLVMAnalysis.a LLVMipa.a \
            LLVMDataStructure \
           LLVMScalarOpts.a LLVMTransforms.a LLVMTarget.a LLVMScalarOpts.a \
-          LLVMTransformUtils LLVMCore LLVMSupport.a LLVMbzip2 LLVMSystem.a
+          LLVMTransformUtils.a LLVMCore LLVMSupport.a LLVMbzip2 LLVMSystem.a
 
 include $(LEVEL)/Makefile.common
index 0b198323afeefb010b04aa23f446f4453a39430a..6460aa82aa2a44dc32f365b0f0a1f75d94244dff 100644 (file)
@@ -14,7 +14,7 @@ OPTLIBS  = LLVMTransforms.a LLVMInstrumentation.a
 ANALIBS  = LLVMDataStructure LLVMipa.a LLVMTarget.a 
 
 USEDLIBS = LLVMipo.a LLVMScalarOpts.a $(OPTLIBS) $(ANALIBS) LLVMAnalysis.a \
-          LLVMTransformUtils \
+          LLVMTransformUtils.a \
           LLVMAsmParser LLVMLinker.a LLVMBCReader LLVMBCWriter \
           LLVMCore LLVMSupport.a LLVMbzip2 LLVMSystem.a
 
index 8359a760810f68ef2108cb47c9104ce59ad865ca..32c10c88658d2408d257d8e54e19166b36814976 100644 (file)
@@ -10,7 +10,7 @@ LEVEL = ../..
 
 TOOLNAME = gccas
 USEDLIBS = LLVMAsmParser LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
-           LLVMScalarOpts.a LLVMAnalysis.a LLVMTarget.a LLVMTransformUtils \
+           LLVMScalarOpts.a LLVMAnalysis.a LLVMTarget.a LLVMTransformUtils.a \
            LLVMCore LLVMSupport.a LLVMbzip2 LLVMSystem.a
 
 include $(LEVEL)/Makefile.common
index e55a85e8f6763ba5926cf88ac8b836c60530c217..96e73d6871363364e2ef5878509899d7be8ff6dc 100644 (file)
@@ -11,7 +11,7 @@ LEVEL = ../..
 
 TOOLNAME = gccld
 USEDLIBS = LLVMipo.a LLVMTransforms.a LLVMScalarOpts.a LLVMAnalysis.a \
-           LLVMipa.a LLVMTransformUtils LLVMTarget.a LLVMLinker.a \
+           LLVMipa.a LLVMTransformUtils.a LLVMTarget.a LLVMLinker.a \
            LLVMArchive.a LLVMBCReader LLVMBCWriter \
            LLVMCore LLVMSupport.a LLVMbzip2 LLVMSystem.a
 
index ef21140a137b4ebfd88cfa9a89867d46aa06b33e..031012a8e58bda7a137a9e1cc3411b95c0c3742f 100644 (file)
@@ -70,7 +70,7 @@ USEDLIBS += \
        LLVMipa.a \
        LLVMTransforms.a \
        LLVMScalarOpts.a \
-       LLVMTransformUtils \
+       LLVMTransformUtils.a \
        LLVMAnalysis.a \
        LLVMBCReader \
        LLVMBCWriter \
index 69e7e7f92795b2e37c984584901b38b00b9fcd5e..80a90fa41a887eb60b1bd0cb5d8946a7b9480100 100644 (file)
@@ -10,7 +10,7 @@ LEVEL = ../..
 
 TOOLNAME = llvm-extract
 USEDLIBS = LLVMBCReader LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMTarget.a \
-           LLVMAnalysis.a LLVMTransformUtils LLVMipa.a \
+           LLVMAnalysis.a LLVMTransformUtils.a LLVMipa.a \
            LLVMCore LLVMSupport.a LLVMbzip2 LLVMSystem.a
 
 include $(LEVEL)/Makefile.common
index 880df9f4fc676a78c925b93ca514cf480d97b6bb..34d6dc69ca4690e9a8a8fe84ec1c09a30963fd6d 100644 (file)
@@ -11,7 +11,7 @@ LEVEL = ../..
 
 TOOLNAME = llvm-ld
 USEDLIBS = LLVMipo.a LLVMTransforms.a LLVMScalarOpts.a LLVMAnalysis.a \
-          LLVMipa.a LLVMTransformUtils LLVMTarget.a LLVMLinker.a \
+          LLVMipa.a LLVMTransformUtils.a LLVMTarget.a LLVMLinker.a \
           LLVMArchive.a LLVMBCReader LLVMBCWriter \
           LLVMCore LLVMSupport.a LLVMbzip2 LLVMSystem.a
 
index fcc6c5fc5dff758aedbfa6e604ecba8f75344c7d..4fd8293eb0319589f26e8c02680867810daeab0a 100644 (file)
@@ -11,7 +11,7 @@ TOOLNAME = opt
 
 USEDLIBS = LLVMBCReader LLVMBCWriter LLVMInstrumentation.a \
           LLVMScalarOpts.a LLVMipo.a LLVMipa.a LLVMDataStructure LLVMTransforms.a \
-          LLVMTarget.a LLVMAnalysis.a LLVMTransformUtils LLVMCore LLVMSupport.a \
+          LLVMTarget.a LLVMAnalysis.a LLVMTransformUtils.a LLVMCore LLVMSupport.a \
           LLVMbzip2 LLVMSystem.a 
 
 include $(LEVEL)/Makefile.common