Add suppport for ConstantExprs of shufflevectors whose result type is not equal to the
[oota-llvm.git] / include / llvm / Bitcode / Deserialize.h
index 87d0f12728aa79c9bd7e383181d7560d08eb5487..8c9ea89d15225817f73fd14b3bbeee0262be7262 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Ted Kremenek and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -125,8 +125,7 @@ private:
   llvm::SmallVector<Location,8> BlockStack;
   unsigned AbbrevNo;
   unsigned RecordCode;
-  Location StreamStart;
-  std::vector<SerializedPtrID> BatchIDVec;
+  uint64_t StreamStart;
   
   //===----------------------------------------------------------===//
   // Public Interface.
@@ -152,12 +151,12 @@ public:
   }
 
   template <typename T>
-  inline T* Materialize() {
-    return SerializeTrait<T>::Materialize(*this);
+  inline T* Create() {
+    return SerializeTrait<T>::Create(*this);
   }
   
   char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
-  void ReadCStr(std::vector<char>& buff, bool isNullTerm=false);
+  void ReadCStr(std::vector<char>& buff, bool isNullTerm=false, unsigned Idx=0);
 
   template <typename T>
   inline T* ReadOwnedPtr(bool AutoRegister = true) {
@@ -166,14 +165,29 @@ public:
     if (!PtrID)
       return NULL;
     
-    T* x = SerializeTrait<T>::Materialize(*this);
+    T* x = SerializeTrait<T>::Create(*this);
 
     if (AutoRegister)
       RegisterPtr(PtrID,x);
     
     return x;
   }
-  
+
+  template <typename T, typename Arg1>
+  inline T* ReadOwnedPtr(Arg1& arg1, bool AutoRegister = true) {
+    SerializedPtrID PtrID = ReadPtrID();
+
+    if (!PtrID)
+      return NULL;
+
+    T* x = SerializeTrait<T>::Create(*this, arg1);
+
+    if (AutoRegister)
+      RegisterPtr(PtrID,x);
+
+    return x;
+  }
+
   template <typename T>
   inline void ReadOwnedPtr(T*& Ptr, bool AutoRegister = true) {
     Ptr = ReadOwnedPtr<T>(AutoRegister);
@@ -186,10 +200,24 @@ public:
     SerializedPtrID ID1 = ReadPtrID();
     SerializedPtrID ID2 = ReadPtrID();
 
-    P1 = (ID1) ? SerializeTrait<T1>::Materialize(*this) : NULL;
+    P1 = (ID1) ? SerializeTrait<T1>::Create(*this) : NULL;
+    if (ID1 && A1) RegisterPtr(ID1,P1);
+
+    P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
+    if (ID2 && A2) RegisterPtr(ID2,P2);
+  }
+
+  template <typename T1, typename T2, typename Arg1>
+  void BatchReadOwnedPtrs(T1*& P1, T2*& P2, Arg1& arg1,
+                          bool A1=true, bool A2=true) {
+
+    SerializedPtrID ID1 = ReadPtrID();
+    SerializedPtrID ID2 = ReadPtrID();
+
+    P1 = (ID1) ? SerializeTrait<T1>::Create(*this, arg1) : NULL;
     if (ID1 && A1) RegisterPtr(ID1,P1);
 
-    P2 = (ID2) ? SerializeTrait<T2>::Materialize(*this) : NULL;
+    P2 = (ID2) ? SerializeTrait<T2>::Create(*this, arg1) : NULL;
     if (ID2 && A2) RegisterPtr(ID2,P2);
   }
 
@@ -201,33 +229,188 @@ public:
     SerializedPtrID ID2 = ReadPtrID();
     SerializedPtrID ID3 = ReadPtrID();
     
-    P1 = (ID1) ? SerializeTrait<T1>::Materialize(*this) : NULL;
+    P1 = (ID1) ? SerializeTrait<T1>::Create(*this) : NULL;
     if (ID1 && A1) RegisterPtr(ID1,P1);    
     
-    P2 = (ID2) ? SerializeTrait<T2>::Materialize(*this) : NULL;
+    P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
     if (ID2 && A2) RegisterPtr(ID2,P2);
     
-    P3 = (ID3) ? SerializeTrait<T2>::Materialize(*this) : NULL;
+    P3 = (ID3) ? SerializeTrait<T3>::Create(*this) : NULL;
     if (ID3 && A3) RegisterPtr(ID3,P3);
   }
-  
+
+  template <typename T1, typename T2, typename T3, typename Arg1>
+  void BatchReadOwnedPtrs(T1*& P1, T2*& P2, T3*& P3, Arg1& arg1,
+                          bool A1=true, bool A2=true, bool A3=true) {
+
+    SerializedPtrID ID1 = ReadPtrID();
+    SerializedPtrID ID2 = ReadPtrID();
+    SerializedPtrID ID3 = ReadPtrID();
+
+    P1 = (ID1) ? SerializeTrait<T1>::Create(*this, arg1) : NULL;
+    if (ID1 && A1) RegisterPtr(ID1,P1);
+
+    P2 = (ID2) ? SerializeTrait<T2>::Create(*this, arg1) : NULL;
+    if (ID2 && A2) RegisterPtr(ID2,P2);
+
+    P3 = (ID3) ? SerializeTrait<T3>::Create(*this, arg1) : NULL;
+    if (ID3 && A3) RegisterPtr(ID3,P3);
+  }
+
   template <typename T>
   void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, bool AutoRegister=true) {
+    llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+    
     for (unsigned i = 0; i < NumPtrs; ++i)
       BatchIDVec.push_back(ReadPtrID());
     
     for (unsigned i = 0; i < NumPtrs; ++i) {
       SerializedPtrID& PtrID = BatchIDVec[i];
       
-      T* p = PtrID ? SerializeTrait<T>::Materialize(*this) : NULL;
+      T* p = PtrID ? SerializeTrait<T>::Create(*this) : NULL;
       
       if (PtrID && AutoRegister)
         RegisterPtr(PtrID,p);
       
       Ptrs[i] = p;
     }
+  }
+  
+  template <typename T, typename Arg1>
+  void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, Arg1& arg1,
+                          bool AutoRegister=true) {
+
+    llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+
+    for (unsigned i = 0; i < NumPtrs; ++i)
+      BatchIDVec.push_back(ReadPtrID());
+
+    for (unsigned i = 0; i < NumPtrs; ++i) {
+      SerializedPtrID& PtrID = BatchIDVec[i];
+
+      T* p = PtrID ? SerializeTrait<T>::Create(*this, arg1) : NULL;
+
+      if (PtrID && AutoRegister)
+        RegisterPtr(PtrID,p);
+
+      Ptrs[i] = p;
+    }
+  }
+
+  template <typename T1, typename T2>
+  void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2,
+                          bool A1=true, bool A2=true) {
+    
+    llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+
+    for (unsigned i = 0; i < NumT1Ptrs; ++i)
+      BatchIDVec.push_back(ReadPtrID());
+    
+    SerializedPtrID ID2 = ReadPtrID();
+    
+    for (unsigned i = 0; i < NumT1Ptrs; ++i) {
+      SerializedPtrID& PtrID = BatchIDVec[i];
+      
+      T1* p = PtrID ? SerializeTrait<T1>::Create(*this) : NULL;
+      
+      if (PtrID && A1)
+        RegisterPtr(PtrID,p);
+      
+      Ptrs[i] = p;
+    }
+    
+    P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
+    if (ID2 && A2) RegisterPtr(ID2,P2);    
   }    
   
+  template <typename T1, typename T2, typename Arg1>
+  void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2, Arg1& arg1,
+                          bool A1=true, bool A2=true) {
+
+    llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+
+    for (unsigned i = 0; i < NumT1Ptrs; ++i)
+      BatchIDVec.push_back(ReadPtrID());
+
+    SerializedPtrID ID2 = ReadPtrID();
+
+    for (unsigned i = 0; i < NumT1Ptrs; ++i) {
+      SerializedPtrID& PtrID = BatchIDVec[i];
+
+      T1* p = PtrID ? SerializeTrait<T1>::Create(*this, arg1) : NULL;
+
+      if (PtrID && A1)
+        RegisterPtr(PtrID,p);
+
+      Ptrs[i] = p;
+    }
+
+    P2 = (ID2) ? SerializeTrait<T2>::Create(*this, arg1) : NULL;
+    if (ID2 && A2) RegisterPtr(ID2,P2);
+  }
+
+  template <typename T1, typename T2, typename T3>
+  void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, 
+                          T2*& P2, T3*& P3,
+                          bool A1=true, bool A2=true, bool A3=true) {
+    
+    llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+    
+    for (unsigned i = 0; i < NumT1Ptrs; ++i)
+      BatchIDVec.push_back(ReadPtrID());
+    
+    SerializedPtrID ID2 = ReadPtrID();
+    SerializedPtrID ID3 = ReadPtrID();    
+    
+    for (unsigned i = 0; i < NumT1Ptrs; ++i) {
+      SerializedPtrID& PtrID = BatchIDVec[i];
+      
+      T1* p = PtrID ? SerializeTrait<T1>::Create(*this) : NULL;
+      
+      if (PtrID && A1)
+        RegisterPtr(PtrID,p);
+      
+      Ptrs[i] = p;
+    }
+    
+    P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
+    if (ID2 && A2) RegisterPtr(ID2,P2);
+    
+    P3 = (ID3) ? SerializeTrait<T3>::Create(*this) : NULL;
+    if (ID3 && A3) RegisterPtr(ID3,P3);    
+  }    
+
+  template <typename T1, typename T2, typename T3, typename Arg1>
+  void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs,
+                          T2*& P2, T3*& P3, Arg1& arg1,
+                          bool A1=true, bool A2=true, bool A3=true) {
+
+    llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+
+    for (unsigned i = 0; i < NumT1Ptrs; ++i)
+      BatchIDVec.push_back(ReadPtrID());
+
+    SerializedPtrID ID2 = ReadPtrID();
+    SerializedPtrID ID3 = ReadPtrID();
+
+    for (unsigned i = 0; i < NumT1Ptrs; ++i) {
+      SerializedPtrID& PtrID = BatchIDVec[i];
+
+      T1* p = PtrID ? SerializeTrait<T1>::Create(*this, arg1) : NULL;
+
+      if (PtrID && A1)
+        RegisterPtr(PtrID,p);
+
+      Ptrs[i] = p;
+    }
+
+    P2 = (ID2) ? SerializeTrait<T2>::Create(*this, arg1) : NULL;
+    if (ID2 && A2) RegisterPtr(ID2,P2);
+
+    P3 = (ID3) ? SerializeTrait<T3>::Create(*this, arg1) : NULL;
+    if (ID3 && A3) RegisterPtr(ID3,P3);
+  }
+
   template <typename T>
   void ReadPtr(T*& PtrRef, bool AllowBackpatch = true) {
     ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef), AllowBackpatch);
@@ -238,10 +421,29 @@ public:
     ReadPtr(const_cast<T*&>(PtrRef), AllowBackpatch);
   }
   
+  
   template <typename T>
-  T* ReadPtr() { T* x; ReadPtr<T>(x,false); return x; }
+  void ReadPtr(T*& PtrRef, const SerializedPtrID& PtrID, 
+               bool AllowBackpatch = true) {
+    ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef), PtrID, AllowBackpatch);
+  }
+  
+  template <typename T>
+  void ReadPtr(const T*& PtrRef, const SerializedPtrID& PtrID, 
+               bool AllowBackpatch = true) {
+    
+    ReadPtr(const_cast<T*&>(PtrRef), PtrID, AllowBackpatch);
+  }
+  
+  template <typename T>
+  T* ReadPtr() { T* x = 0; ReadPtr<T>(x,false); return x; }
 
-  void ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch = true);
+  void ReadUIntPtr(uintptr_t& PtrRef, const SerializedPtrID& PtrID, 
+                   bool AllowBackpatch = true);
+  
+  void ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch = true) {
+    ReadUIntPtr(PtrRef,ReadPtrID(),AllowBackpatch);
+  }
   
   template <typename T>
   T& ReadRef() {
@@ -249,7 +451,7 @@ public:
     return *p;
   }
 
-  void RegisterPtr(SerializedPtrID PtrId, const void* Ptr);
+  void RegisterPtr(const SerializedPtrID& PtrID, const void* Ptr);
   
   void RegisterPtr(const void* Ptr) {
     RegisterPtr(ReadPtrID(),Ptr);
@@ -261,7 +463,7 @@ public:
   }
   
   template<typename T>
-  void RegisterRef(SerializedPtrID PtrID, const T& x) {
+  void RegisterRef(const SerializedPtrID& PtrID, const T& x) {
     RegisterPtr(PtrID,&x);
   }  
   
@@ -271,7 +473,7 @@ public:
   
   bool FinishedBlock(Location BlockLoc);
   bool JumpTo(const Location& BlockLoc);
-  void Rewind() { JumpTo(StreamStart); }
+  void Rewind();
   
   bool AtEnd();
   bool inRecord();