[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp ConstantHandling.cpp Constants.cpp PassManagerT.h Type.cpp Value.cpp

John Criswell criswell at choi.cs.uiuc.edu
Thu Jun 26 16:41:39 PDT 2003


Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.88 -> 1.88.2.1
ConstantHandling.cpp updated: 1.31 -> 1.31.2.1
Constants.cpp updated: 1.44 -> 1.44.2.1
PassManagerT.h updated: 1.38.2.1 -> 1.38.2.2
Type.cpp updated: 1.47 -> 1.47.2.1
Value.cpp updated: 1.31 -> 1.31.2.1

---
Log message:

Merged with mainline on Thursday, June 26, 2003.


---
Diffs of the changes:

Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.88 llvm/lib/VMCore/AsmWriter.cpp:1.88.2.1
--- llvm/lib/VMCore/AsmWriter.cpp:1.88	Sat May 31 22:45:51 2003
+++ llvm/lib/VMCore/AsmWriter.cpp	Thu Jun 26 16:35:29 2003
@@ -234,7 +234,7 @@
     //
     if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
         ((StrVal[0] == '-' || StrVal[0] == '+') &&
-         (StrVal[0] >= '0' && StrVal[0] <= '9')))
+         (StrVal[1] >= '0' && StrVal[1] <= '9')))
       // Reparse stringized version!
       if (atof(StrVal.c_str()) == CFP->getValue()) {
         Out << StrVal; return;


Index: llvm/lib/VMCore/ConstantHandling.cpp
diff -u llvm/lib/VMCore/ConstantHandling.cpp:1.31 llvm/lib/VMCore/ConstantHandling.cpp:1.31.2.1
--- llvm/lib/VMCore/ConstantHandling.cpp:1.31	Tue May 27 14:16:07 2003
+++ llvm/lib/VMCore/ConstantHandling.cpp	Thu Jun 26 16:35:29 2003
@@ -141,12 +141,30 @@
 
   // FIXME: Implement folding of GEP constant exprs the same as instcombine does
 
-  // Implement folding of:
-  //    int* getelementptr ([2 x int]* cast ([3 x int]* %X to [2 x int]*),
-  //                        long 0, long 0)
-  // To: int* getelementptr ([3 x int]* %X, long 0, long 0)
-  //
-  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
+  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
+    // Implement folding of:
+    //    void ()** getelementptr (%struct..TorRec* getelementptr
+    //              ([N x %struct..TorRec]* %llvm.global_dtors, long 0, long 0),
+    //                 long 0, ubyte 1)
+    // Into:
+    //    %struct..TorRec* getelementptr ([N x %struct..TorRec]*
+    //                      %llvm.global_dtors, long 0, long 0, ubyte 1)
+    //
+    if (CE->getOpcode() == Instruction::GetElementPtr)
+      if (IdxList[0] == Constant::getNullValue(Type::LongTy)) {
+        std::vector<Constant*> NewIndices;
+        NewIndices.reserve(IdxList.size() + CE->getNumOperands());
+        for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
+          NewIndices.push_back(cast<Constant>(CE->getOperand(i)));
+        NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());
+        return ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices);
+      }
+
+    // Implement folding of:
+    //    int* getelementptr ([2 x int]* cast ([3 x int]* %X to [2 x int]*),
+    //                        long 0, long 0)
+    // To: int* getelementptr ([3 x int]* %X, long 0, long 0)
+    //
     if (CE->getOpcode() == Instruction::Cast && IdxList.size() > 1 &&
         IdxList[0]->isNullValue())
       if (const PointerType *SPT = 
@@ -157,6 +175,7 @@
             if (CAT->getElementType() == SAT->getElementType())
               return ConstantExpr::getGetElementPtr(
                       (Constant*)CE->getOperand(0), IdxList);
+  }
   return 0;
 }
 


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.44 llvm/lib/VMCore/Constants.cpp:1.44.2.1
--- llvm/lib/VMCore/Constants.cpp:1.44	Mon Jun  2 12:42:47 2003
+++ llvm/lib/VMCore/Constants.cpp	Thu Jun 26 16:35:29 2003
@@ -225,7 +225,9 @@
          "Invalid initializer vector for constant structure");
   Operands.reserve(V.size());
   for (unsigned i = 0, e = V.size(); i != e; ++i) {
-    assert(V[i]->getType() == ETypes[i] &&
+    assert((V[i]->getType() == ETypes[i] ||
+            (ETypes[i]->isAbstract() &&
+             ETypes[i]->getPrimitiveID()==V[i]->getType()->getPrimitiveID())) &&
            "Initializer for struct element doesn't match struct element type!");
     Operands.push_back(Use(V[i], this));
   }
@@ -241,8 +243,14 @@
   Operands.push_back(Use(C, this));
 }
 
+static bool isSetCC(unsigned Opcode) {
+  return Opcode == Instruction::SetEQ || Opcode == Instruction::SetNE ||
+         Opcode == Instruction::SetLT || Opcode == Instruction::SetGT ||
+         Opcode == Instruction::SetLE || Opcode == Instruction::SetGE;
+}
+
 ConstantExpr::ConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
-  : Constant(C1->getType()), iType(Opcode) {
+  : Constant(isSetCC(Opcode) ? Type::BoolTy : C1->getType()), iType(Opcode) {
   Operands.push_back(Use(C1, this));
   Operands.push_back(Use(C2, this));
 }
@@ -563,9 +571,11 @@
   std::vector<Constant*> C;
   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
     C.push_back(cast<Constant>(getOperand(i)));
-  replaceAllUsesWith(ConstantArray::get(cast<ArrayType>(NewTy),
-                                        C));
-  destroyConstant();    // This constant is now dead, destroy it.
+  Constant *New = ConstantArray::get(cast<ArrayType>(NewTy), C);
+  if (New != this) {
+    replaceAllUsesWith(New);
+    destroyConstant();    // This constant is now dead, destroy it.
+  }
 }
 
 
@@ -633,9 +643,11 @@
   std::vector<Constant*> C;
   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
     C.push_back(cast<Constant>(getOperand(i)));
-  replaceAllUsesWith(ConstantStruct::get(cast<StructType>(NewTy),
-                                         C));
-  destroyConstant();    // This constant is now dead, destroy it.
+  Constant *New = ConstantStruct::get(cast<StructType>(NewTy), C);
+  if (New != this) {
+    replaceAllUsesWith(New);
+    destroyConstant();    // This constant is now dead, destroy it.
+  }
 }
 
 
@@ -672,10 +684,13 @@
   if (OldTy == NewTy) return;
 
   // Make everyone now use a constant of the new type...
-  replaceAllUsesWith(ConstantPointerNull::get(cast<PointerType>(NewTy)));
+  Constant *New = ConstantPointerNull::get(cast<PointerType>(NewTy));
+  if (New != this) {
+    replaceAllUsesWith(New);
     
-  // This constant is now dead, destroy it.
-  destroyConstant();
+    // This constant is now dead, destroy it.
+    destroyConstant();
+  }
 }
 
 
@@ -806,13 +821,14 @@
   // ::get methods intuit the type of the result based on the types of the
   // operands.  The operand types may not have had their types resolved yet.
   //
+  Constant *New;
   if (getOpcode() == Instruction::Cast) {
-    replaceAllUsesWith(getCast(getOperand(0), NewTy));
+    New = getCast(getOperand(0), NewTy);
   } else if (getOpcode() >= Instruction::BinaryOpsBegin &&
              getOpcode() < Instruction::BinaryOpsEnd) {
-    replaceAllUsesWith(get(getOpcode(), getOperand(0), getOperand(0)));
+    New = get(getOpcode(), getOperand(0), getOperand(0));
   } else if (getOpcode() == Instruction::Shl || getOpcode() ==Instruction::Shr){
-    replaceAllUsesWith(getShift(getOpcode(), getOperand(0), getOperand(0)));
+    New = getShift(getOpcode(), getOperand(0), getOperand(0));
   } else {
     assert(getOpcode() == Instruction::GetElementPtr);
 
@@ -820,10 +836,12 @@
     std::vector<Constant*> C;
     for (unsigned i = 1, e = getNumOperands(); i != e; ++i)
       C.push_back(cast<Constant>(getOperand(i)));
-    replaceAllUsesWith(ConstantExpr::getGetElementPtr(getOperand(0),
-                                                      C));
+    New = ConstantExpr::getGetElementPtr(getOperand(0), C);
+  }
+  if (New != this) {
+    replaceAllUsesWith(New);
+    destroyConstant();    // This constant is now dead, destroy it.
   }
-  destroyConstant();    // This constant is now dead, destroy it.
 }
 
 


Index: llvm/lib/VMCore/PassManagerT.h
diff -u llvm/lib/VMCore/PassManagerT.h:1.38.2.1 llvm/lib/VMCore/PassManagerT.h:1.38.2.2
--- llvm/lib/VMCore/PassManagerT.h:1.38.2.1	Mon Jun 23 14:06:45 2003
+++ llvm/lib/VMCore/PassManagerT.h	Thu Jun 26 16:35:29 2003
@@ -130,12 +130,6 @@
   typedef typename Traits::BatcherClass BatcherClass;
   typedef typename Traits::ParentClass   ParentClass;
 
-  //
-  // JTC:
-  //	GCC 3.3 does not permit friend declarations without the class keyword.
-  //	Hence, I changed the following two lines to allow the code to compiler
-  //	under the new compiler.
-  //
   friend class PassManagerTraits<UnitType>::PassClass;
   friend class PassManagerTraits<UnitType>::SubPassClass;  
   friend class Traits;


Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.47 llvm/lib/VMCore/Type.cpp:1.47.2.1
--- llvm/lib/VMCore/Type.cpp:1.47	Thu May 22 16:31:52 2003
+++ llvm/lib/VMCore/Type.cpp	Thu Jun 26 16:35:29 2003
@@ -216,11 +216,11 @@
 FunctionType::FunctionType(const Type *Result,
                            const std::vector<const Type*> &Params, 
                            bool IsVarArgs) : DerivedType(FunctionTyID), 
-    ResultType(PATypeHandle<Type>(Result, this)),
+    ResultType(PATypeHandle(Result, this)),
     isVarArgs(IsVarArgs) {
   ParamTys.reserve(Params.size());
   for (unsigned i = 0; i < Params.size(); ++i)
-    ParamTys.push_back(PATypeHandle<Type>(Params[i], this));
+    ParamTys.push_back(PATypeHandle(Params[i], this));
 
   setDerivedTypeProperties();
 }
@@ -230,7 +230,7 @@
   ETypes.reserve(Types.size());
   for (unsigned i = 0; i < Types.size(); ++i) {
     assert(Types[i] != Type::VoidTy && "Void type in method prototype!!");
-    ETypes.push_back(PATypeHandle<Type>(Types[i], this));
+    ETypes.push_back(PATypeHandle(Types[i], this));
   }
   setDerivedTypeProperties();
 }
@@ -427,20 +427,20 @@
 //
 template<class ValType, class TypeClass>
 class TypeMap : public AbstractTypeUser {
-  typedef std::map<ValType, PATypeHandle<TypeClass> > MapTy;
+  typedef std::map<ValType, PATypeHandle> MapTy;
   MapTy Map;
 public:
   ~TypeMap() { print("ON EXIT"); }
 
   inline TypeClass *get(const ValType &V) {
-    typename std::map<ValType, PATypeHandle<TypeClass> >::iterator I
+    typename std::map<ValType, PATypeHandle>::iterator I
       = Map.find(V);
     // TODO: FIXME: When Types are not CONST.
     return (I != Map.end()) ? (TypeClass*)I->second.get() : 0;
   }
 
   inline void add(const ValType &V, TypeClass *T) {
-    Map.insert(std::make_pair(V, PATypeHandle<TypeClass>(T, this)));
+    Map.insert(std::make_pair(V, PATypeHandle(T, this)));
     print("add");
   }
 
@@ -521,7 +521,7 @@
 
     TypeMap<ValType, TypeClass> &Table = MyTable;     // Copy MyTable reference
     ValType Tmp(*(ValType*)this);                     // Copy this.
-    PATypeHandle<TypeClass> OldType(Table.get(*(ValType*)this), this);
+    PATypeHandle OldType(Table.get(*(ValType*)this), this);
     Table.remove(*(ValType*)this);                    // Destroy's this!
 
     // Refine temporary to new state...
@@ -546,8 +546,8 @@
 // FunctionValType - Define a class to hold the key that goes into the TypeMap
 //
 class FunctionValType : public ValTypeBase<FunctionValType, FunctionType> {
-  PATypeHandle<Type> RetTy;
-  std::vector<PATypeHandle<Type> > ArgTypes;
+  PATypeHandle RetTy;
+  std::vector<PATypeHandle> ArgTypes;
   bool isVarArg;
 public:
   FunctionValType(const Type *ret, const std::vector<const Type*> &args,
@@ -555,7 +555,7 @@
     : ValTypeBase<FunctionValType, FunctionType>(Tab), RetTy(ret, this),
       isVarArg(IVA) {
     for (unsigned i = 0; i < args.size(); ++i)
-      ArgTypes.push_back(PATypeHandle<Type>(args[i], this));
+      ArgTypes.push_back(PATypeHandle(args[i], this));
   }
 
   // We *MUST* have an explicit copy ctor so that the TypeHandles think that
@@ -566,7 +566,7 @@
       isVarArg(MVT.isVarArg) {
     ArgTypes.reserve(MVT.ArgTypes.size());
     for (unsigned i = 0; i < MVT.ArgTypes.size(); ++i)
-      ArgTypes.push_back(PATypeHandle<Type>(MVT.ArgTypes[i], this));
+      ArgTypes.push_back(PATypeHandle(MVT.ArgTypes[i], this));
   }
 
   // Subclass should override this... to update self as usual
@@ -615,7 +615,7 @@
 // Array Type Factory...
 //
 class ArrayValType : public ValTypeBase<ArrayValType, ArrayType> {
-  PATypeHandle<Type> ValTy;
+  PATypeHandle ValTy;
   unsigned Size;
 public:
   ArrayValType(const Type *val, int sz, TypeMap<ArrayValType, ArrayType> &Tab)
@@ -671,14 +671,14 @@
 // StructValType - Define a class to hold the key that goes into the TypeMap
 //
 class StructValType : public ValTypeBase<StructValType, StructType> {
-  std::vector<PATypeHandle<Type> > ElTypes;
+  std::vector<PATypeHandle> ElTypes;
 public:
   StructValType(const std::vector<const Type*> &args,
 		TypeMap<StructValType, StructType> &Tab)
     : ValTypeBase<StructValType, StructType>(Tab) {
     ElTypes.reserve(args.size());
     for (unsigned i = 0, e = args.size(); i != e; ++i)
-      ElTypes.push_back(PATypeHandle<Type>(args[i], this));
+      ElTypes.push_back(PATypeHandle(args[i], this));
   }
 
   // We *MUST* have an explicit copy ctor so that the TypeHandles think that
@@ -688,7 +688,7 @@
     : ValTypeBase<StructValType, StructType>(SVT){
     ElTypes.reserve(SVT.ElTypes.size());
     for (unsigned i = 0, e = SVT.ElTypes.size(); i != e; ++i)
-      ElTypes.push_back(PATypeHandle<Type>(SVT.ElTypes[i], this));
+      ElTypes.push_back(PATypeHandle(SVT.ElTypes[i], this));
   }
 
   // Subclass should override this... to update self as usual
@@ -731,7 +731,7 @@
 // PointerValType - Define a class to hold the key that goes into the TypeMap
 //
 class PointerValType : public ValTypeBase<PointerValType, PointerType> {
-  PATypeHandle<Type> ValTy;
+  PATypeHandle ValTy;
 public:
   PointerValType(const Type *val, TypeMap<PointerValType, PointerType> &Tab)
     : ValTypeBase<PointerValType, PointerType>(Tab), ValTy(val, this) {}


Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.31 llvm/lib/VMCore/Value.cpp:1.31.2.1
--- llvm/lib/VMCore/Value.cpp:1.31	Thu Feb 13 13:46:22 2003
+++ llvm/lib/VMCore/Value.cpp	Thu Jun 26 16:35:29 2003
@@ -40,7 +40,7 @@
                 << **I << "\n";
   }
 #endif
-  assert(Uses.begin() == Uses.end());
+  assert(Uses.begin() == Uses.end() &&"Uses remain when a value is destroyed!");
 
   // There should be no uses of this object anymore, remove it.
   LeakDetector::removeGarbageObject(this);





More information about the llvm-commits mailing list