Fix bug: test/Regression/Transforms/SCCP/2002-05-03-NotOperator.ll
[oota-llvm.git] / lib / VMCore / Constants.cpp
index 257bd7622c9dd9c5cb2588cadb832fcdb5f1550b..7487bb480195e28f2059793f40c475ccb069eb3e 100644 (file)
@@ -1,19 +1,22 @@
-//===-- ConstantVals.cpp - Implement Constant nodes --------------*- C++ -*--=//
+//===-- Constants.cpp - Implement Constant nodes -----------------*- C++ -*--=//
 //
 // This file implements the Constant* classes...
 //
 //===----------------------------------------------------------------------===//
 
 #define __STDC_LIMIT_MACROS           // Get defs for INT64_MAX and friends...
-#include "llvm/ConstantVals.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/GlobalValue.h"
 #include "llvm/Module.h"
-#include "llvm/Analysis/SlotCalculator.h"
+#include "llvm/SlotCalculator.h"
 #include "Support/StringExtras.h"
 #include <algorithm>
-#include <assert.h>
+
+using std::map;
+using std::pair;
+using std::make_pair;
 
 ConstantBool *ConstantBool::True  = new ConstantBool(true);
 ConstantBool *ConstantBool::False = new ConstantBool(false);
@@ -24,14 +27,14 @@ ConstantBool *ConstantBool::False = new ConstantBool(false);
 //===----------------------------------------------------------------------===//
 
 // Specialize setName to take care of symbol table majik
-void Constant::setName(const string &Name, SymbolTable *ST) {
+void Constant::setName(const std::string &Name, SymbolTable *ST) {
   assert(ST && "Type::setName - Must provide symbol table argument!");
 
   if (Name.size()) ST->insert(Name, this);
 }
 
 // Static constructor to create a '0' constant of arbitrary type...
-Constant *Constant::getNullConstant(const Type *Ty) {
+Constant *Constant::getNullValue(const Type *Ty) {
   switch (Ty->getPrimitiveID()) {
   case Type::BoolTyID:   return ConstantBool::get(false);
   case Type::SByteTyID:
@@ -54,10 +57,6 @@ Constant *Constant::getNullConstant(const Type *Ty) {
   }
 }
 
-#ifndef NDEBUG
-#include "llvm/Assembly/Writer.h"
-#endif
-
 void Constant::destroyConstantImpl() {
   // When a Constant is destroyed, there may be lingering
   // references to the constant by other constants in the constant pool.  These
@@ -70,8 +69,11 @@ void Constant::destroyConstantImpl() {
     Value *V = use_back();
 #ifndef NDEBUG      // Only in -g mode...
     if (!isa<Constant>(V)) {
-      cerr << "While deleting: " << this << endl;
-      cerr << "Use still stuck around after Def is destroyed: " << V << endl;
+      std::cerr << "While deleting: ";
+      dump();
+      std::cerr << "\nUse still stuck around after Def is destroyed: ";
+      V->dump();
+      std::cerr << "\n";
     }
 #endif
     assert(isa<Constant>(V) && "References remain to ConstantPointerRef!");
@@ -115,7 +117,7 @@ ConstantFP::ConstantFP(const Type *Ty, double V) : Constant(Ty) {
 }
 
 ConstantArray::ConstantArray(const ArrayType *T,
-                             const vector<Constant*> &V) : Constant(T) {
+                             const std::vector<Constant*> &V) : Constant(T) {
   for (unsigned i = 0; i < V.size(); i++) {
     assert(V[i]->getType() == T->getElementType());
     Operands.push_back(Use(V[i], this));
@@ -123,7 +125,7 @@ ConstantArray::ConstantArray(const ArrayType *T,
 }
 
 ConstantStruct::ConstantStruct(const StructType *T,
-                               const vector<Constant*> &V) : Constant(T) {
+                               const std::vector<Constant*> &V) : Constant(T) {
   const StructType::ElementTypes &ETypes = T->getElementTypes();
   
   for (unsigned i = 0; i < V.size(); i++) {
@@ -139,105 +141,6 @@ ConstantPointerRef::ConstantPointerRef(GlobalValue *GV)
 
 
 
-//===----------------------------------------------------------------------===//
-//                          getStrValue implementations
-
-string ConstantBool::getStrValue() const {
-  return Val ? "true" : "false";
-}
-
-string ConstantSInt::getStrValue() const {
-  return itostr(Val.Signed);
-}
-
-string ConstantUInt::getStrValue() const {
-  return utostr(Val.Unsigned);
-}
-
-string ConstantFP::getStrValue() const {
-  return ftostr(Val);
-}
-
-string ConstantArray::getStrValue() const {
-  string Result;
-  
-  // As a special case, print the array as a string if it is an array of
-  // ubytes or an array of sbytes with positive values.
-  // 
-  const Type *ETy = cast<ArrayType>(getType())->getElementType();
-  bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
-
-  if (ETy == Type::SByteTy) {
-    for (unsigned i = 0; i < Operands.size(); ++i)
-      if (ETy == Type::SByteTy &&
-          cast<ConstantSInt>(Operands[i])->getValue() < 0) {
-        isString = false;
-        break;
-      }
-  }
-
-  if (isString) {
-    Result = "c\"";
-    for (unsigned i = 0; i < Operands.size(); ++i) {
-      unsigned char C = (ETy == Type::SByteTy) ?
-        (unsigned char)cast<ConstantSInt>(Operands[i])->getValue() :
-        (unsigned char)cast<ConstantUInt>(Operands[i])->getValue();
-
-      if (isprint(C)) {
-        Result += C;
-      } else {
-        Result += '\\';
-        Result += ( C/16  < 10) ? ( C/16 +'0') : ( C/16 -10+'A');
-        Result += ((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A');
-      }
-    }
-    Result += "\"";
-
-  } else {
-    Result = "[";
-    if (Operands.size()) {
-      Result += " " + Operands[0]->getType()->getDescription() + 
-               " " + cast<Constant>(Operands[0])->getStrValue();
-      for (unsigned i = 1; i < Operands.size(); i++)
-        Result += ", " + Operands[i]->getType()->getDescription() + 
-                  " " + cast<Constant>(Operands[i])->getStrValue();
-    }
-    Result += " ]";
-  }
-  
-  return Result;
-}
-
-string ConstantStruct::getStrValue() const {
-  string Result = "{";
-  if (Operands.size()) {
-    Result += " " + Operands[0]->getType()->getDescription() + 
-             " " + cast<Constant>(Operands[0])->getStrValue();
-    for (unsigned i = 1; i < Operands.size(); i++)
-      Result += ", " + Operands[i]->getType()->getDescription() + 
-               " " + cast<Constant>(Operands[i])->getStrValue();
-  }
-
-  return Result + " }";
-}
-
-string ConstantPointerNull::getStrValue() const {
-  return "null";
-}
-
-string ConstantPointerRef::getStrValue() const {
-  const GlobalValue *V = getValue();
-  if (V->hasName()) return "%" + V->getName();
-
-  SlotCalculator *Table = new SlotCalculator(V->getParent(), true);
-  int Slot = Table->getValSlot(V);
-  delete Table;
-
-  if (Slot >= 0) return string(" %") + itostr(Slot);
-  else return "<pointer reference badref>";
-}
-
-
 //===----------------------------------------------------------------------===//
 //                           classof implementations
 
@@ -321,38 +224,6 @@ bool ConstantFP::isValueValidForType(const Type *Ty, double Val) {
   }
 };
 
-//===----------------------------------------------------------------------===//
-//                      Hash Function Implementations
-#if 0
-unsigned ConstantSInt::hash(const Type *Ty, int64_t V) {
-  return unsigned(Ty->getPrimitiveID() ^ V);
-}
-
-unsigned ConstantUInt::hash(const Type *Ty, uint64_t V) {
-  return unsigned(Ty->getPrimitiveID() ^ V);
-}
-
-unsigned ConstantFP::hash(const Type *Ty, double V) {
-  return Ty->getPrimitiveID() ^ unsigned(V);
-}
-
-unsigned ConstantArray::hash(const ArrayType *Ty,
-                             const vector<Constant*> &V) {
-  unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7);
-  for (unsigned i = 0; i < V.size(); ++i)
-    Result ^= V[i]->getHash() << (i & 7);
-  return Result;
-}
-
-unsigned ConstantStruct::hash(const StructType *Ty,
-                              const vector<Constant*> &V) {
-  unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7);
-  for (unsigned i = 0; i < V.size(); ++i)
-    Result ^= V[i]->getHash() << (i & 7);
-  return Result;
-}
-#endif
-
 //===----------------------------------------------------------------------===//
 //                      Factory Function Implementation
 
@@ -418,10 +289,10 @@ ConstantFP *ConstantFP::get(const Type *Ty, double V) {
 
 //---- ConstantArray::get() implementation...
 //
-static ValueMap<vector<Constant*>, ConstantArray> ArrayConstants;
+static ValueMap<std::vector<Constant*>, ConstantArray> ArrayConstants;
 
 ConstantArray *ConstantArray::get(const ArrayType *Ty,
-                                  const vector<Constant*> &V) {
+                                  const std::vector<Constant*> &V) {
   ConstantArray *Result = ArrayConstants.get(Ty, V);
   if (!Result)   // If no preexisting value, create one now...
     ArrayConstants.add(Ty, V, Result = new ConstantArray(Ty, V));
@@ -432,8 +303,8 @@ ConstantArray *ConstantArray::get(const ArrayType *Ty,
 // contain the specified string.  A null terminator is added to the specified
 // string so that it may be used in a natural way...
 //
-ConstantArray *ConstantArray::get(const string &Str) {
-  vector<Constant*> ElementVals;
+ConstantArray *ConstantArray::get(const std::string &Str) {
+  std::vector<Constant*> ElementVals;
 
   for (unsigned i = 0; i < Str.length(); ++i)
     ElementVals.push_back(ConstantSInt::get(Type::SByteTy, Str[i]));
@@ -455,10 +326,10 @@ void ConstantArray::destroyConstant() {
 
 //---- ConstantStruct::get() implementation...
 //
-static ValueMap<vector<Constant*>, ConstantStruct> StructConstants;
+static ValueMap<std::vector<Constant*>, ConstantStruct> StructConstants;
 
 ConstantStruct *ConstantStruct::get(const StructType *Ty,
-                                    const vector<Constant*> &V) {
+                                    const std::vector<Constant*> &V) {
   ConstantStruct *Result = StructConstants.get(Ty, V);
   if (!Result)   // If no preexisting value, create one now...
     StructConstants.add(Ty, V, Result = new ConstantStruct(Ty, V));