-
-//===----------------------------------------------------------------------===//
-// DenseMap specialization
-//===----------------------------------------------------------------------===//
-
-unsigned DenseMapInfo<DebugLoc>::getHashValue(const DebugLoc &Key) {
- return static_cast<unsigned>(hash_combine(Key.LineCol, Key.ScopeIdx));
-}
-
-//===----------------------------------------------------------------------===//
-// LLVMContextImpl Implementation
-//===----------------------------------------------------------------------===//
-
-int LLVMContextImpl::getOrAddScopeRecordIdxEntry(MDNode *Scope,
- int ExistingIdx) {
- // If we already have an entry for this scope, return it.
- int &Idx = ScopeRecordIdx[Scope];
- if (Idx) return Idx;
-
- // If we don't have an entry, but ExistingIdx is specified, use it.
- if (ExistingIdx)
- return Idx = ExistingIdx;
-
- // Otherwise add a new entry.
-
- // Start out ScopeRecords with a minimal reasonable size to avoid
- // excessive reallocation starting out.
- if (ScopeRecords.empty())
- ScopeRecords.reserve(128);
-
- // Index is biased by 1 for index.
- Idx = ScopeRecords.size()+1;
- ScopeRecords.push_back(DebugRecVH(Scope, this, Idx));
- return Idx;
-}
-
-int LLVMContextImpl::getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,
- int ExistingIdx) {
- // If we already have an entry, return it.
- int &Idx = ScopeInlinedAtIdx[std::make_pair(Scope, IA)];
- if (Idx) return Idx;
-
- // If we don't have an entry, but ExistingIdx is specified, use it.
- if (ExistingIdx)
- return Idx = ExistingIdx;
-
- // Start out ScopeInlinedAtRecords with a minimal reasonable size to avoid
- // excessive reallocation starting out.
- if (ScopeInlinedAtRecords.empty())
- ScopeInlinedAtRecords.reserve(128);
-
- // Index is biased by 1 and negated.
- Idx = -ScopeInlinedAtRecords.size()-1;
- ScopeInlinedAtRecords.push_back(std::make_pair(DebugRecVH(Scope, this, Idx),
- DebugRecVH(IA, this, Idx)));
- return Idx;
-}
-
-
-//===----------------------------------------------------------------------===//
-// DebugRecVH Implementation
-//===----------------------------------------------------------------------===//
-
-/// deleted - The MDNode this is pointing to got deleted, so this pointer needs
-/// to drop to null and we need remove our entry from the DenseMap.
-void DebugRecVH::deleted() {
- // If this is a non-canonical reference, just drop the value to null, we know
- // it doesn't have a map entry.
- if (Idx == 0) {
- setValPtr(nullptr);
- return;
- }
-
- MDNode *Cur = get();
-
- // If the index is positive, it is an entry in ScopeRecords.
- if (Idx > 0) {
- assert(Ctx->ScopeRecordIdx[Cur] == Idx && "Mapping out of date!");
- Ctx->ScopeRecordIdx.erase(Cur);
- // Reset this VH to null and we're done.
- setValPtr(nullptr);
- Idx = 0;
- return;
- }
-
- // Otherwise, it is an entry in ScopeInlinedAtRecords, we don't know if it
- // is the scope or the inlined-at record entry.
- assert(unsigned(-Idx-1) < Ctx->ScopeInlinedAtRecords.size());
- std::pair<DebugRecVH, DebugRecVH> &Entry = Ctx->ScopeInlinedAtRecords[-Idx-1];
- assert((this == &Entry.first || this == &Entry.second) &&
- "Mapping out of date!");
-
- MDNode *OldScope = Entry.first.get();
- MDNode *OldInlinedAt = Entry.second.get();
- assert(OldScope && OldInlinedAt &&
- "Entry should be non-canonical if either val dropped to null");
-
- // Otherwise, we do have an entry in it, nuke it and we're done.
- assert(Ctx->ScopeInlinedAtIdx[std::make_pair(OldScope, OldInlinedAt)] == Idx&&
- "Mapping out of date");
- Ctx->ScopeInlinedAtIdx.erase(std::make_pair(OldScope, OldInlinedAt));
-
- // Reset this VH to null. Drop both 'Idx' values to null to indicate that
- // we're in non-canonical form now.
- setValPtr(nullptr);
- Entry.first.Idx = Entry.second.Idx = 0;
-}
-
-void DebugRecVH::allUsesReplacedWith(Value *NewVa) {
- // If being replaced with a non-mdnode value (e.g. undef) handle this as if
- // the mdnode got deleted.
- MDNode *NewVal = dyn_cast<MDNode>(NewVa);
- if (!NewVal) return deleted();
-
- // If this is a non-canonical reference, just change it, we know it already
- // doesn't have a map entry.
- if (Idx == 0) {
- setValPtr(NewVa);
- return;
- }
-
- MDNode *OldVal = get();
- assert(OldVal != NewVa && "Node replaced with self?");
-
- // If the index is positive, it is an entry in ScopeRecords.
- if (Idx > 0) {
- assert(Ctx->ScopeRecordIdx[OldVal] == Idx && "Mapping out of date!");
- Ctx->ScopeRecordIdx.erase(OldVal);
- setValPtr(NewVal);
-
- int NewEntry = Ctx->getOrAddScopeRecordIdxEntry(NewVal, Idx);
-
- // If NewVal already has an entry, this becomes a non-canonical reference,
- // just drop Idx to 0 to signify this.
- if (NewEntry != Idx)
- Idx = 0;
- return;
- }
-
- // Otherwise, it is an entry in ScopeInlinedAtRecords, we don't know if it
- // is the scope or the inlined-at record entry.
- assert(unsigned(-Idx-1) < Ctx->ScopeInlinedAtRecords.size());
- std::pair<DebugRecVH, DebugRecVH> &Entry = Ctx->ScopeInlinedAtRecords[-Idx-1];
- assert((this == &Entry.first || this == &Entry.second) &&
- "Mapping out of date!");
-
- MDNode *OldScope = Entry.first.get();
- MDNode *OldInlinedAt = Entry.second.get();
- assert(OldScope && OldInlinedAt &&
- "Entry should be non-canonical if either val dropped to null");
-
- // Otherwise, we do have an entry in it, nuke it and we're done.
- assert(Ctx->ScopeInlinedAtIdx[std::make_pair(OldScope, OldInlinedAt)] == Idx&&
- "Mapping out of date");
- Ctx->ScopeInlinedAtIdx.erase(std::make_pair(OldScope, OldInlinedAt));
-
- // Reset this VH to the new value.
- setValPtr(NewVal);
-
- int NewIdx = Ctx->getOrAddScopeInlinedAtIdxEntry(Entry.first.get(),
- Entry.second.get(), Idx);
- // If NewVal already has an entry, this becomes a non-canonical reference,
- // just drop Idx to 0 to signify this.
- if (NewIdx != Idx) {
- std::pair<DebugRecVH, DebugRecVH> &Entry=Ctx->ScopeInlinedAtRecords[-Idx-1];
- Entry.first.Idx = Entry.second.Idx = 0;
- }
-}