summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorJohn Criswell <criswell@uiuc.edu>2005-10-27 15:54:34 +0000
committerJohn Criswell <criswell@uiuc.edu>2005-10-27 15:54:34 +0000
commitfe5f33b120376d0fe3dbbbc84be0783ddcd0be7b (patch)
treeb228cf783c13f7c9ba39ff7a3f7b50a70d689bd1 /llvm/lib/Transforms
parent4b6d583d7a22d339a026b4f3602a4861681d3bab (diff)
downloadbcm5719-llvm-fe5f33b120376d0fe3dbbbc84be0783ddcd0be7b.tar.gz
bcm5719-llvm-fe5f33b120376d0fe3dbbbc84be0783ddcd0be7b.zip
Move some constant folding code shared by Analysis and Transform passes
into the LLVMAnalysis library. This allows LLVMTranform and LLVMTransformUtils to be archives and linked with LLVMAnalysis.a, which provides any missing definitions. llvm-svn: 24036
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp143
-rw-r--r--llvm/lib/Transforms/Utils/Makefile1
2 files changed, 2 insertions, 142 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index a9cfcc0a920..d82b278f402 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -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.
diff --git a/llvm/lib/Transforms/Utils/Makefile b/llvm/lib/Transforms/Utils/Makefile
index a0c49bd9dfe..26fc4261f16 100644
--- a/llvm/lib/Transforms/Utils/Makefile
+++ b/llvm/lib/Transforms/Utils/Makefile
@@ -9,6 +9,7 @@
LEVEL = ../../..
LIBRARYNAME = LLVMTransformUtils
+BUILD_ARCHIVE = 1
include $(LEVEL)/Makefile.common
OpenPOWER on IntegriCloud