aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Bitcode
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-10-28 21:17:59 +0000
committerTed Kremenek <kremenek@apple.com>2007-10-28 21:17:59 +0000
commit5973ef40ca290903e0b3a4952162c14b55af5d72 (patch)
treecdf6969c92acad8154ce83c273b947944a9ad824 /include/llvm/Bitcode
parentdc84650679b6330e0fcdd4cf8bc2a351387db7ca (diff)
Updated backpatching logic during object deserialization to perform
eager backpatching instead of waithing until all objects have been deserialized. This allows us to reduce the memory footprint needed for backpatching. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43422 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Bitcode')
-rw-r--r--include/llvm/Bitcode/Deserialize.h72
1 files changed, 53 insertions, 19 deletions
diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h
index 4a9b06381a..508b4deee8 100644
--- a/include/llvm/Bitcode/Deserialize.h
+++ b/include/llvm/Bitcode/Deserialize.h
@@ -26,11 +26,11 @@
namespace llvm {
class Deserializer {
- BitstreamReader& Stream;
- SmallVector<uint64_t,10> Record;
- unsigned RecIdx;
- BumpPtrAllocator Allocator;
-
+
+ //===----------------------------------------------------------===//
+ // Internal type definitions.
+ //===----------------------------------------------------------===//
+
struct PtrIdInfo {
static inline unsigned getEmptyKey() { return ~((unsigned) 0x0); }
static inline unsigned getTombstoneKey() { return getEmptyKey()-1; }
@@ -39,26 +39,58 @@ class Deserializer {
static inline bool isPod() { return true; }
};
- struct BPatchNode {
- BPatchNode* const Next;
+ struct BPNode {
+ BPNode* Next;
uintptr_t& PtrRef;
- BPatchNode(BPatchNode* n, void*& pref)
- : Next(n), PtrRef(reinterpret_cast<uintptr_t&>(pref)) {
+ BPNode(BPNode* n, uintptr_t& pref)
+ : Next(n), PtrRef(pref) {
PtrRef = 0;
}
};
- struct BPatchEntry {
- BPatchNode* Head;
- void* Ptr;
- BPatchEntry() : Head(NULL), Ptr(NULL) {}
+ class BPatchEntry {
+ uintptr_t Ptr;
+ public:
+
+ BPatchEntry() : Ptr(0x1) {}
+
+ BPatchEntry(void* P) : Ptr(reinterpret_cast<uintptr_t>(P)) {}
+
+ bool hasFinalPtr() const { return Ptr & 0x1 ? true : false; }
+ void setFinalPtr(BPNode*& FreeList, void* P);
+
+ BPNode* getBPNode() const {
+ assert (!hasFinalPtr());
+ return reinterpret_cast<BPNode*>(Ptr & ~0x1);
+ }
+
+ void setBPNode(BPNode* N) {
+ assert (!hasFinalPtr());
+ Ptr = reinterpret_cast<uintptr_t>(N) | 0x1;
+ }
+
+ uintptr_t getRawPtr() const { return Ptr; }
+
static inline bool isPod() { return true; }
- };
-
+ };
+
typedef llvm::DenseMap<unsigned,BPatchEntry,PtrIdInfo,BPatchEntry> MapTy;
+ //===----------------------------------------------------------===//
+ // Internal data members.
+ //===----------------------------------------------------------===//
+
+ BitstreamReader& Stream;
+ SmallVector<uint64_t,10> Record;
+ unsigned RecIdx;
+ BumpPtrAllocator Allocator;
+ BPNode* FreeList;
MapTy BPatchMap;
+ //===----------------------------------------------------------===//
+ // Public Interface.
+ //===----------------------------------------------------------===//
+
public:
Deserializer(BitstreamReader& stream);
~Deserializer();
@@ -99,13 +131,15 @@ public:
return x;
}
- void ReadPtr(void*& PtrRef);
- void ReadPtr(uintptr_t& PtrRef) { ReadPtr(reinterpret_cast<void*&>(PtrRef)); }
+ template <typename T>
+ void ReadPtr(T*& PtrRef) { ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef));}
+
+ void ReadPtr(uintptr_t& PtrRef) { ReadUIntPtr(PtrRef); }
+
+ void ReadUIntPtr(uintptr_t& PtrRef);
void RegisterPtr(unsigned PtrId, void* Ptr);
-
- void BackpatchPointers();
private:
void ReadRecord();
bool inRecord();