Fixes for PR114: Thanks to Reid Spencer!
[oota-llvm.git] / lib / VMCore / ConstantFolding.h
index 66719cda8e5687294eb87f9e8f171373c432d5e4..b392ad1173779d0bfb64dae15eb22f75b7903420 100644 (file)
@@ -1,4 +1,11 @@
-//===-- ConstantHandling.h - Stuff for manipulating constants ----*- C++ -*--=//
+//===-- ConstantHandling.h - Stuff for manipulating constants ---*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file contains the declarations of some cool operators that allow you
 // to do natural things with constant pool values.
@@ -35,6 +42,9 @@
 
 #include "llvm/Constants.h"
 #include "llvm/Type.h"
+
+namespace llvm {
+
 class PointerType;
 
 //===----------------------------------------------------------------------===//
@@ -103,7 +113,8 @@ public:
     case Type::LongTyID:   return castToLong(V);
     case Type::FloatTyID:  return castToFloat(V);
     case Type::DoubleTyID: return castToDouble(V);
-    case Type::PointerTyID:return castToPointer(V, (PointerType*)Ty);
+    case Type::PointerTyID:
+      return castToPointer(V, reinterpret_cast<const PointerType*>(Ty));
     default: return 0;
     }
   }
@@ -115,7 +126,7 @@ public:
   static inline ConstRules *get(const Constant &V1, const Constant &V2) {
     if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
       return getConstantExprRules();
-    return (ConstRules*)V1.getType()->getOrCreateAnnotation(AID);
+    return static_cast<ConstRules*>(V1.getType()->getOrCreateAnnotation(AID));
   }
 private:
   static ConstRules *getConstantExprRules();
@@ -127,11 +138,15 @@ private:
 
 // Unary operators...
 inline Constant *operator~(const Constant &V) {
-  assert(V.getType()->isIntegral() && "Cannot invert non-intergral constant!");
+  assert(V.getType()->isIntegral() && "Cannot invert non-integral constant!");
   return ConstRules::get(V, V)->op_xor(&V,
                                     ConstantInt::getAllOnesValue(V.getType()));
 }
 
+inline Constant *operator-(const Constant &V) {
+  return ConstRules::get(V, V)->sub(Constant::getNullValue(V.getType()), &V);
+}
+
 // Standard binary operators...
 inline Constant *operator+(const Constant &V1, const Constant &V2) {
   assert(V1.getType() == V2.getType() && "Constant types must be identical!");
@@ -233,4 +248,7 @@ Constant *ConstantFoldShiftInstruction(unsigned Opcode, const Constant *V1,
                                        const Constant *V2);
 Constant *ConstantFoldGetElementPtr(const Constant *C,
                                     const std::vector<Constant*> &IdxList);
+
+} // End llvm namespace
+
 #endif