Add support for casting operators
[oota-llvm.git] / lib / VMCore / ConstantFold.cpp
index 438ea4b37c2ec834a2b1268346a3eabfb9c94201..e573c4b82ba20460371fe1e52e874b2473413b89 100644 (file)
@@ -4,7 +4,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Opt/ConstantHandling.h"
+#include "llvm/Optimizations/ConstantHandling.h"
+
+namespace opt {
 
 //===----------------------------------------------------------------------===//
 //                             TemplateRules Class
@@ -25,10 +27,6 @@ class TemplateRules : public ConstRules {
   // Redirecting functions that cast to the appropriate types
   //===--------------------------------------------------------------------===//
 
-  virtual ConstPoolVal *neg(const ConstPoolVal *V) const {
-    return SubClassName::Neg((const ArgType *)V);
-  }
-
   virtual ConstPoolVal *not(const ConstPoolVal *V) const {
     return SubClassName::Not((const ArgType *)V);
   }
@@ -44,6 +42,11 @@ class TemplateRules : public ConstRules {
     return SubClassName::Sub((const ArgType *)V1, (const ArgType *)V2);  
   }
 
+  virtual ConstPoolVal *mul(const ConstPoolVal *V1, 
+                            const ConstPoolVal *V2) const { 
+    return SubClassName::Mul((const ArgType *)V1, (const ArgType *)V2);  
+  }
+
   virtual ConstPoolBool *lessthan(const ConstPoolVal *V1, 
                                   const ConstPoolVal *V2) const { 
     return SubClassName::LessThan((const ArgType *)V1, (const ArgType *)V2);
@@ -53,17 +56,17 @@ class TemplateRules : public ConstRules {
   // Default "noop" implementations
   //===--------------------------------------------------------------------===//
 
-  inline static ConstPoolVal *Neg(const ArgType *V) { return 0; }
   inline static ConstPoolVal *Not(const ArgType *V) { return 0; }
 
   inline static ConstPoolVal *Add(const ArgType *V1, const ArgType *V2) {
     return 0;
   }
-
   inline static ConstPoolVal *Sub(const ArgType *V1, const ArgType *V2) {
     return 0;
   }
-
+  inline static ConstPoolVal *Mul(const ArgType *V1, const ArgType *V2) {
+    return 0;
+  }
   inline static ConstPoolBool *LessThan(const ArgType *V1, const ArgType *V2) {
     return 0;
   }
@@ -123,9 +126,6 @@ struct DirectRules
   : public TemplateRules<ConstPoolClass, 
                          DirectRules<ConstPoolClass, BuiltinType, Ty> > {
 
-  inline static ConstPoolVal *Neg(const ConstPoolClass *V) { 
-    return new ConstPoolClass(*Ty, -(BuiltinType)V->getValue());;
-  }
   inline static ConstPoolVal *Not(const ConstPoolClass *V) { 
     return new ConstPoolClass(*Ty, !(BuiltinType)V->getValue());;
   }
@@ -144,6 +144,13 @@ struct DirectRules
     return new ConstPoolClass(*Ty, Result);
   }
 
+  inline static ConstPoolVal *Mul(const ConstPoolClass *V1, 
+                                  const ConstPoolClass *V2) {
+    BuiltinType Result = (BuiltinType)V1->getValue() *
+                         (BuiltinType)V2->getValue();
+    return new ConstPoolClass(*Ty, Result);
+  }
+
   inline static ConstPoolBool *LessThan(const ConstPoolClass *V1, 
                                         const ConstPoolClass *V2) {
     bool Result = (BuiltinType)V1->getValue() < (BuiltinType)V2->getValue();
@@ -195,3 +202,6 @@ const ConstRules *ConstRules::find(const Type *Ty) {
   Ty->setConstRules(Result);   // Cache the value for future short circuiting!
   return Result;
 }
+
+
+} // End namespace opt