diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h index 0f745d9054b..68d94b773d1 100644 --- a/include/llvm/Bitcode/Deserialize.h +++ b/include/llvm/Bitcode/Deserialize.h @@ -230,6 +230,32 @@ public: } } + template + void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2, + bool A1=true, bool A2=true) { + + BatchIDVec.clear(); + + 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::Create(*this) : NULL; + + if (PtrID && A1) + RegisterPtr(PtrID,p); + + Ptrs[i] = p; + } + + P2 = (ID2) ? SerializeTrait::Create(*this) : NULL; + if (ID2 && A2) RegisterPtr(ID2,P2); + } + template void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2, T3*& P3, diff --git a/include/llvm/Bitcode/Serialize.h b/include/llvm/Bitcode/Serialize.h index 0b99c575436..60d9cb2c992 100644 --- a/include/llvm/Bitcode/Serialize.h +++ b/include/llvm/Bitcode/Serialize.h @@ -94,6 +94,20 @@ public: if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]); } + template + void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, T2* p2) { + + for (unsigned i = 0; i < NumT1Ptrs; ++i) + EmitPtr(Ptrs[i]); + + EmitPtr(p2); + + for (unsigned i = 0; i < NumT1Ptrs; ++i) + if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]); + + if (p2) SerializeTrait::Emit(*this,*p2); + } + template void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, T2* p2, T3* p3) { diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp index ea6b27a62e9..965ff708a2c 100644 --- a/lib/Bitcode/Reader/Deserialize.cpp +++ b/lib/Bitcode/Reader/Deserialize.cpp @@ -13,6 +13,8 @@ #include "llvm/Bitcode/Deserialize.h" +#define DEBUG_BACKPATCH + #ifdef DEBUG_BACKPATCH #include "llvm/Support/Streams.h" #endif @@ -346,18 +348,24 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef, return; } -#ifdef DEBUG_BACKPATCH - llvm::cerr << "ReadUintPtr: " << PtrId << "\n"; -#endif - MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId)); - if (HasFinalPtr(E)) + if (HasFinalPtr(E)) { PtrRef = GetFinalPtr(E); + +#ifdef DEBUG_BACKPATCH + llvm::cerr << "ReadUintPtr: " << PtrId + << " <-- " << (void*) GetFinalPtr(E) << '\n'; +#endif + } else { assert (AllowBackpatch && "Client forbids backpatching for this pointer."); +#ifdef DEBUG_BACKPATCH + llvm::cerr << "ReadUintPtr: " << PtrId << " (NO PTR YET)\n"; +#endif + // Register backpatch. Check the freelist for a BPNode. BPNode* N;