aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Bitcode/Deserialize.h
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-01 00:57:37 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-01 00:57:37 +0000
commit066ff5b7f2de0fd263269e822858aa174e162a89 (patch)
tree998754ed112887ed825a90888a582f914431ad8a /include/llvm/Bitcode/Deserialize.h
parentaef806e9cb021919be8f3a988af0478f3da75758 (diff)
Rewrote backpatcher. Backpatcher now stores the "has final pointer"
flag in the **key** of the backpatch map, as opposed to the mapped value which contains either the final pointer, or a pointer to a chain of pointers that need to be backpatched. The bit flag was moved to the key because we were erroneously assuming that the backpatched pointers would be at an alignment of >= 2 bytes, which obviously doesn't work for character strings. Now we just steal the bit from the key. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43595 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Bitcode/Deserialize.h')
-rw-r--r--include/llvm/Bitcode/Deserialize.h80
1 files changed, 48 insertions, 32 deletions
diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h
index f883a5a0bc..d7ad7c1614 100644
--- a/include/llvm/Bitcode/Deserialize.h
+++ b/include/llvm/Bitcode/Deserialize.h
@@ -30,54 +30,49 @@ class Deserializer {
//===----------------------------------------------------------===//
// Internal type definitions.
//===----------------------------------------------------------===//
-
- struct PtrIdInfo {
- static inline unsigned getEmptyKey() { return ~((unsigned) 0x0); }
- static inline unsigned getTombstoneKey() { return getEmptyKey()-1; }
- static inline unsigned getHashValue(unsigned X) { return X; }
- static inline bool isEqual(unsigned X, unsigned Y) { return X == Y; }
- static inline bool isPod() { return true; }
- };
struct BPNode {
BPNode* Next;
uintptr_t& PtrRef;
+
BPNode(BPNode* n, uintptr_t& pref)
: Next(n), PtrRef(pref) {
PtrRef = 0;
}
};
- class BPatchEntry {
- uintptr_t Ptr;
+ struct BPEntry {
+ union { BPNode* Head; void* Ptr; };
+
+ BPEntry() : Head(NULL) {}
+
+ static inline bool isPod() { return true; }
+
+ void SetPtr(BPNode*& FreeList, void* P);
+ };
+
+ class BPKey {
+ unsigned Raw;
+
public:
+ BPKey(unsigned PtrId) : Raw(PtrId << 1) { assert (PtrId > 0); }
- BPatchEntry() : Ptr(0x1) {}
-
- BPatchEntry(void* P) : Ptr(reinterpret_cast<uintptr_t>(P)) {}
-
- bool hasFinalPtr() const { return Ptr & 0x1 ? false : true; }
- void setFinalPtr(BPNode*& FreeList, const void* P);
-
- BPNode* getBPNode() const {
- assert (!hasFinalPtr());
- return reinterpret_cast<BPNode*>(Ptr & ~0x1);
- }
+ void MarkFinal() { Raw |= 0x1; }
+ bool hasFinalPtr() const { return Raw & 0x1 ? true : false; }
+ unsigned getID() const { return Raw >> 1; }
- void setBPNode(BPNode* N) {
- assert (!hasFinalPtr());
- Ptr = reinterpret_cast<uintptr_t>(N) | 0x1;
+ static inline BPKey getEmptyKey() { return 0; }
+ static inline BPKey getTombstoneKey() { return 1; }
+ static inline unsigned getHashValue(const BPKey& K) { return K.Raw & ~0x1; }
+
+ static bool isEqual(const BPKey& K1, const BPKey& K2) {
+ return (K1.Raw ^ K2.Raw) & ~0x1 ? false : true;
}
- uintptr_t getFinalPtr() const {
- assert (!(Ptr & 0x1) && "Backpatch pointer not yet deserialized.");
- return Ptr;
- }
-
- static inline bool isPod() { return true; }
+ static bool isPod() { return true; }
};
-
- typedef llvm::DenseMap<unsigned,BPatchEntry,PtrIdInfo,BPatchEntry> MapTy;
+
+ typedef llvm::DenseMap<BPKey,BPEntry,BPKey,BPEntry> MapTy;
//===----------------------------------------------------------===//
// Internal data members.
@@ -162,6 +157,27 @@ private:
void ReadRecord();
bool inRecord();
uintptr_t ReadInternalRefPtr();
+
+ static inline bool HasFinalPtr(MapTy::value_type& V) {
+ return V.first.hasFinalPtr();
+ }
+
+ static inline uintptr_t GetFinalPtr(MapTy::value_type& V) {
+ return reinterpret_cast<uintptr_t>(V.second.Ptr);
+ }
+
+ static inline BPNode* GetBPNode(MapTy::value_type& V) {
+ return V.second.Head;
+ }
+
+ static inline void SetBPNode(MapTy::value_type& V, BPNode* N) {
+ V.second.Head = N;
+ }
+
+ void SetPtr(MapTy::value_type& V, const void* P) {
+ V.first.MarkFinal();
+ V.second.SetPtr(FreeList,const_cast<void*>(P));
+ }
};
} // end namespace llvm