aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-03 21:41:07 +0000
committerChris Lattner <sabre@nondot.org>2002-05-03 21:41:07 +0000
commit44540ddaa0eb8ea75c827a266dc98d70248e2afb (patch)
tree7e38a70505a512aac6f48eadf562ddee500e0db2 /lib/VMCore
parentbdd15ad565d5881251f84a9fd13bf89f81d340ec (diff)
downloadexternal_llvm-44540ddaa0eb8ea75c827a266dc98d70248e2afb.zip
external_llvm-44540ddaa0eb8ea75c827a266dc98d70248e2afb.tar.gz
external_llvm-44540ddaa0eb8ea75c827a266dc98d70248e2afb.tar.bz2
Implement remainder
Fix implementation of Not git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2464 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/ConstantFold.cpp55
1 files changed, 46 insertions, 9 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 8edcb42..5fd11c3 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -5,6 +5,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ConstantHandling.h"
+#include <cmath>
AnnotationID ConstRules::AID(AnnotationManager::getID("opt::ConstRules",
&ConstRules::find));
@@ -51,6 +52,10 @@ class TemplateRules : public ConstRules {
const Constant *V2) const {
return SubClassName::Div((const ArgType *)V1, (const ArgType *)V2);
}
+ virtual Constant *rem(const Constant *V1,
+ const Constant *V2) const {
+ return SubClassName::Rem((const ArgType *)V1, (const ArgType *)V2);
+ }
virtual ConstantBool *lessthan(const Constant *V1,
const Constant *V2) const {
@@ -114,6 +119,9 @@ class TemplateRules : public ConstRules {
inline static Constant *Div(const ArgType *V1, const ArgType *V2) {
return 0;
}
+ inline static Constant *Rem(const ArgType *V1, const ArgType *V2) {
+ return 0;
+ }
inline static ConstantBool *LessThan(const ArgType *V1, const ArgType *V2) {
return 0;
}
@@ -242,11 +250,8 @@ struct PointerRules : public TemplateRules<ConstantPointer, PointerRules> {
// different types. This allows the C++ compiler to automatically generate our
// constant handling operations in a typesafe and accurate manner.
//
-template<class ConstantClass, class BuiltinType, Type **Ty>
-struct DirectRules
- : public TemplateRules<ConstantClass,
- DirectRules<ConstantClass, BuiltinType, Ty> > {
-
+template<class ConstantClass, class BuiltinType, Type **Ty, class SuperClass>
+struct DirectRules : public TemplateRules<ConstantClass, SuperClass> {
inline static Constant *Add(const ConstantClass *V1,
const ConstantClass *V2) {
BuiltinType Result = (BuiltinType)V1->getValue() +
@@ -268,8 +273,9 @@ struct DirectRules
return ConstantClass::get(*Ty, Result);
}
- inline static Constant *Div(const ConstantClass *V1,
+ inline static Constant *Div(const ConstantClass *V1,
const ConstantClass *V2) {
+ if (V2->isNullValue()) return 0;
BuiltinType Result = (BuiltinType)V1->getValue() /
(BuiltinType)V2->getValue();
return ConstantClass::get(*Ty, Result);
@@ -317,10 +323,41 @@ struct DirectRules
// integer types, but not all types in general.
//
template <class ConstantClass, class BuiltinType, Type **Ty>
-struct DirectIntRules : public DirectRules<ConstantClass, BuiltinType, Ty> {
+struct DirectIntRules
+ : public DirectRules<ConstantClass, BuiltinType, Ty,
+ DirectIntRules<ConstantClass, BuiltinType, Ty> > {
inline static Constant *Not(const ConstantClass *V) {
return ConstantClass::get(*Ty, ~(BuiltinType)V->getValue());;
}
+
+ inline static Constant *Rem(const ConstantClass *V1,
+ const ConstantClass *V2) {
+ if (V2->isNullValue()) return 0;
+ BuiltinType Result = (BuiltinType)V1->getValue() %
+ (BuiltinType)V2->getValue();
+ return ConstantClass::get(*Ty, Result);
+ }
+};
+
+
+//===----------------------------------------------------------------------===//
+// DirectFPRules Class
+//===----------------------------------------------------------------------===//
+//
+// DirectFPRules provides implementations of functions that are valid on
+// floating point types, but not all types in general.
+//
+template <class ConstantClass, class BuiltinType, Type **Ty>
+struct DirectFPRules
+ : public DirectRules<ConstantClass, BuiltinType, Ty,
+ DirectFPRules<ConstantClass, BuiltinType, Ty> > {
+ inline static Constant *Rem(const ConstantClass *V1,
+ const ConstantClass *V2) {
+ if (V2->isNullValue()) return 0;
+ BuiltinType Result = std::fmod((BuiltinType)V1->getValue(),
+ (BuiltinType)V2->getValue());
+ return ConstantClass::get(*Ty, Result);
+ }
};
@@ -360,9 +397,9 @@ Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) {
case Type::ULongTyID:
return new DirectIntRules<ConstantUInt, uint64_t , &Type::ULongTy>();
case Type::FloatTyID:
- return new DirectRules<ConstantFP , float , &Type::FloatTy>();
+ return new DirectFPRules<ConstantFP , float , &Type::FloatTy>();
case Type::DoubleTyID:
- return new DirectRules<ConstantFP , double , &Type::DoubleTy>();
+ return new DirectFPRules<ConstantFP , double , &Type::DoubleTy>();
default:
return new EmptyRules();
}