LLVM API Documentation

Metadata.cpp
Go to the documentation of this file.
00001 //===-- Metadata.cpp - Implement Metadata classes -------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the Metadata classes.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/IR/Metadata.h"
00015 #include "LLVMContextImpl.h"
00016 #include "SymbolTableListTraitsImpl.h"
00017 #include "llvm/ADT/DenseMap.h"
00018 #include "llvm/ADT/STLExtras.h"
00019 #include "llvm/ADT/SmallSet.h"
00020 #include "llvm/ADT/SmallString.h"
00021 #include "llvm/ADT/StringMap.h"
00022 #include "llvm/IR/ConstantRange.h"
00023 #include "llvm/IR/Instruction.h"
00024 #include "llvm/IR/LLVMContext.h"
00025 #include "llvm/IR/Module.h"
00026 #include "llvm/IR/ValueHandle.h"
00027 
00028 using namespace llvm;
00029 
00030 MetadataAsValue::MetadataAsValue(Type *Ty, Metadata *MD)
00031     : Value(Ty, MetadataAsValueVal), MD(MD) {
00032   track();
00033 }
00034 
00035 MetadataAsValue::~MetadataAsValue() {
00036   getType()->getContext().pImpl->MetadataAsValues.erase(MD);
00037   untrack();
00038 }
00039 
00040 /// \brief Canonicalize metadata arguments to intrinsics.
00041 ///
00042 /// To support bitcode upgrades (and assembly semantic sugar) for \a
00043 /// MetadataAsValue, we need to canonicalize certain metadata.
00044 ///
00045 ///   - nullptr is replaced by an empty MDNode.
00046 ///   - An MDNode with a single null operand is replaced by an empty MDNode.
00047 ///   - An MDNode whose only operand is a \a ConstantAsMetadata gets skipped.
00048 ///
00049 /// This maintains readability of bitcode from when metadata was a type of
00050 /// value, and these bridges were unnecessary.
00051 static Metadata *canonicalizeMetadataForValue(LLVMContext &Context,
00052                                               Metadata *MD) {
00053   if (!MD)
00054     // !{}
00055     return MDNode::get(Context, None);
00056 
00057   // Return early if this isn't a single-operand MDNode.
00058   auto *N = dyn_cast<MDNode>(MD);
00059   if (!N || N->getNumOperands() != 1)
00060     return MD;
00061 
00062   if (!N->getOperand(0))
00063     // !{}
00064     return MDNode::get(Context, None);
00065 
00066   if (auto *C = dyn_cast<ConstantAsMetadata>(N->getOperand(0)))
00067     // Look through the MDNode.
00068     return C;
00069 
00070   return MD;
00071 }
00072 
00073 MetadataAsValue *MetadataAsValue::get(LLVMContext &Context, Metadata *MD) {
00074   MD = canonicalizeMetadataForValue(Context, MD);
00075   auto *&Entry = Context.pImpl->MetadataAsValues[MD];
00076   if (!Entry)
00077     Entry = new MetadataAsValue(Type::getMetadataTy(Context), MD);
00078   return Entry;
00079 }
00080 
00081 MetadataAsValue *MetadataAsValue::getIfExists(LLVMContext &Context,
00082                                               Metadata *MD) {
00083   MD = canonicalizeMetadataForValue(Context, MD);
00084   auto &Store = Context.pImpl->MetadataAsValues;
00085   auto I = Store.find(MD);
00086   return I == Store.end() ? nullptr : I->second;
00087 }
00088 
00089 void MetadataAsValue::handleChangedMetadata(Metadata *MD) {
00090   LLVMContext &Context = getContext();
00091   MD = canonicalizeMetadataForValue(Context, MD);
00092   auto &Store = Context.pImpl->MetadataAsValues;
00093 
00094   // Stop tracking the old metadata.
00095   Store.erase(this->MD);
00096   untrack();
00097   this->MD = nullptr;
00098 
00099   // Start tracking MD, or RAUW if necessary.
00100   auto *&Entry = Store[MD];
00101   if (Entry) {
00102     replaceAllUsesWith(Entry);
00103     delete this;
00104     return;
00105   }
00106 
00107   this->MD = MD;
00108   track();
00109   Entry = this;
00110 }
00111 
00112 void MetadataAsValue::track() {
00113   if (MD)
00114     MetadataTracking::track(&MD, *MD, *this);
00115 }
00116 
00117 void MetadataAsValue::untrack() {
00118   if (MD)
00119     MetadataTracking::untrack(MD);
00120 }
00121 
00122 void ReplaceableMetadataImpl::addRef(void *Ref, OwnerTy Owner) {
00123   bool WasInserted =
00124       UseMap.insert(std::make_pair(Ref, std::make_pair(Owner, NextIndex)))
00125           .second;
00126   (void)WasInserted;
00127   assert(WasInserted && "Expected to add a reference");
00128 
00129   ++NextIndex;
00130   assert(NextIndex != 0 && "Unexpected overflow");
00131 }
00132 
00133 void ReplaceableMetadataImpl::dropRef(void *Ref) {
00134   bool WasErased = UseMap.erase(Ref);
00135   (void)WasErased;
00136   assert(WasErased && "Expected to drop a reference");
00137 }
00138 
00139 void ReplaceableMetadataImpl::moveRef(void *Ref, void *New,
00140                                       const Metadata &MD) {
00141   auto I = UseMap.find(Ref);
00142   assert(I != UseMap.end() && "Expected to move a reference");
00143   auto OwnerAndIndex = I->second;
00144   UseMap.erase(I);
00145   bool WasInserted = UseMap.insert(std::make_pair(New, OwnerAndIndex)).second;
00146   (void)WasInserted;
00147   assert(WasInserted && "Expected to add a reference");
00148 
00149   // Check that the references are direct if there's no owner.
00150   (void)MD;
00151   assert((OwnerAndIndex.first || *static_cast<Metadata **>(Ref) == &MD) &&
00152          "Reference without owner must be direct");
00153   assert((OwnerAndIndex.first || *static_cast<Metadata **>(New) == &MD) &&
00154          "Reference without owner must be direct");
00155 }
00156 
00157 void ReplaceableMetadataImpl::replaceAllUsesWith(Metadata *MD) {
00158   assert(!(MD && isa<MDNode>(MD) && cast<MDNode>(MD)->isTemporary()) &&
00159          "Expected non-temp node");
00160 
00161   if (UseMap.empty())
00162     return;
00163 
00164   // Copy out uses since UseMap will get touched below.
00165   typedef std::pair<void *, std::pair<OwnerTy, uint64_t>> UseTy;
00166   SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end());
00167   std::sort(Uses.begin(), Uses.end(), [](const UseTy &L, const UseTy &R) {
00168     return L.second.second < R.second.second;
00169   });
00170   for (const auto &Pair : Uses) {
00171     // Check that this Ref hasn't disappeared after RAUW (when updating a
00172     // previous Ref).
00173     if (!UseMap.count(Pair.first))
00174       continue;
00175 
00176     OwnerTy Owner = Pair.second.first;
00177     if (!Owner) {
00178       // Update unowned tracking references directly.
00179       Metadata *&Ref = *static_cast<Metadata **>(Pair.first);
00180       Ref = MD;
00181       if (MD)
00182         MetadataTracking::track(Ref);
00183       UseMap.erase(Pair.first);
00184       continue;
00185     }
00186 
00187     // Check for MetadataAsValue.
00188     if (Owner.is<MetadataAsValue *>()) {
00189       Owner.get<MetadataAsValue *>()->handleChangedMetadata(MD);
00190       continue;
00191     }
00192 
00193     // There's a Metadata owner -- dispatch.
00194     Metadata *OwnerMD = Owner.get<Metadata *>();
00195     switch (OwnerMD->getMetadataID()) {
00196 #define HANDLE_METADATA_LEAF(CLASS)                                            \
00197   case Metadata::CLASS##Kind:                                                  \
00198     cast<CLASS>(OwnerMD)->handleChangedOperand(Pair.first, MD);                \
00199     continue;
00200 #include "llvm/IR/Metadata.def"
00201     default:
00202       llvm_unreachable("Invalid metadata subclass");
00203     }
00204   }
00205   assert(UseMap.empty() && "Expected all uses to be replaced");
00206 }
00207 
00208 void ReplaceableMetadataImpl::resolveAllUses(bool ResolveUsers) {
00209   if (UseMap.empty())
00210     return;
00211 
00212   if (!ResolveUsers) {
00213     UseMap.clear();
00214     return;
00215   }
00216 
00217   // Copy out uses since UseMap could get touched below.
00218   typedef std::pair<void *, std::pair<OwnerTy, uint64_t>> UseTy;
00219   SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end());
00220   std::sort(Uses.begin(), Uses.end(), [](const UseTy &L, const UseTy &R) {
00221     return L.second.second < R.second.second;
00222   });
00223   UseMap.clear();
00224   for (const auto &Pair : Uses) {
00225     auto Owner = Pair.second.first;
00226     if (!Owner)
00227       continue;
00228     if (Owner.is<MetadataAsValue *>())
00229       continue;
00230 
00231     // Resolve MDNodes that point at this.
00232     auto *OwnerMD = dyn_cast<MDNode>(Owner.get<Metadata *>());
00233     if (!OwnerMD)
00234       continue;
00235     if (OwnerMD->isResolved())
00236       continue;
00237     OwnerMD->decrementUnresolvedOperandCount();
00238   }
00239 }
00240 
00241 static Function *getLocalFunction(Value *V) {
00242   assert(V && "Expected value");
00243   if (auto *A = dyn_cast<Argument>(V))
00244     return A->getParent();
00245   if (BasicBlock *BB = cast<Instruction>(V)->getParent())
00246     return BB->getParent();
00247   return nullptr;
00248 }
00249 
00250 ValueAsMetadata *ValueAsMetadata::get(Value *V) {
00251   assert(V && "Unexpected null Value");
00252 
00253   auto &Context = V->getContext();
00254   auto *&Entry = Context.pImpl->ValuesAsMetadata[V];
00255   if (!Entry) {
00256     assert((isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) &&
00257            "Expected constant or function-local value");
00258     assert(!V->NameAndIsUsedByMD.getInt() &&
00259            "Expected this to be the only metadata use");
00260     V->NameAndIsUsedByMD.setInt(true);
00261     if (auto *C = dyn_cast<Constant>(V))
00262       Entry = new ConstantAsMetadata(C);
00263     else
00264       Entry = new LocalAsMetadata(V);
00265   }
00266 
00267   return Entry;
00268 }
00269 
00270 ValueAsMetadata *ValueAsMetadata::getIfExists(Value *V) {
00271   assert(V && "Unexpected null Value");
00272   return V->getContext().pImpl->ValuesAsMetadata.lookup(V);
00273 }
00274 
00275 void ValueAsMetadata::handleDeletion(Value *V) {
00276   assert(V && "Expected valid value");
00277 
00278   auto &Store = V->getType()->getContext().pImpl->ValuesAsMetadata;
00279   auto I = Store.find(V);
00280   if (I == Store.end())
00281     return;
00282 
00283   // Remove old entry from the map.
00284   ValueAsMetadata *MD = I->second;
00285   assert(MD && "Expected valid metadata");
00286   assert(MD->getValue() == V && "Expected valid mapping");
00287   Store.erase(I);
00288 
00289   // Delete the metadata.
00290   MD->replaceAllUsesWith(nullptr);
00291   delete MD;
00292 }
00293 
00294 void ValueAsMetadata::handleRAUW(Value *From, Value *To) {
00295   assert(From && "Expected valid value");
00296   assert(To && "Expected valid value");
00297   assert(From != To && "Expected changed value");
00298   assert(From->getType() == To->getType() && "Unexpected type change");
00299 
00300   LLVMContext &Context = From->getType()->getContext();
00301   auto &Store = Context.pImpl->ValuesAsMetadata;
00302   auto I = Store.find(From);
00303   if (I == Store.end()) {
00304     assert(!From->NameAndIsUsedByMD.getInt() &&
00305            "Expected From not to be used by metadata");
00306     return;
00307   }
00308 
00309   // Remove old entry from the map.
00310   assert(From->NameAndIsUsedByMD.getInt() &&
00311          "Expected From to be used by metadata");
00312   From->NameAndIsUsedByMD.setInt(false);
00313   ValueAsMetadata *MD = I->second;
00314   assert(MD && "Expected valid metadata");
00315   assert(MD->getValue() == From && "Expected valid mapping");
00316   Store.erase(I);
00317 
00318   if (isa<LocalAsMetadata>(MD)) {
00319     if (auto *C = dyn_cast<Constant>(To)) {
00320       // Local became a constant.
00321       MD->replaceAllUsesWith(ConstantAsMetadata::get(C));
00322       delete MD;
00323       return;
00324     }
00325     if (getLocalFunction(From) && getLocalFunction(To) &&
00326         getLocalFunction(From) != getLocalFunction(To)) {
00327       // Function changed.
00328       MD->replaceAllUsesWith(nullptr);
00329       delete MD;
00330       return;
00331     }
00332   } else if (!isa<Constant>(To)) {
00333     // Changed to function-local value.
00334     MD->replaceAllUsesWith(nullptr);
00335     delete MD;
00336     return;
00337   }
00338 
00339   auto *&Entry = Store[To];
00340   if (Entry) {
00341     // The target already exists.
00342     MD->replaceAllUsesWith(Entry);
00343     delete MD;
00344     return;
00345   }
00346 
00347   // Update MD in place (and update the map entry).
00348   assert(!To->NameAndIsUsedByMD.getInt() &&
00349          "Expected this to be the only metadata use");
00350   To->NameAndIsUsedByMD.setInt(true);
00351   MD->V = To;
00352   Entry = MD;
00353 }
00354 
00355 //===----------------------------------------------------------------------===//
00356 // MDString implementation.
00357 //
00358 
00359 MDString *MDString::get(LLVMContext &Context, StringRef Str) {
00360   auto &Store = Context.pImpl->MDStringCache;
00361   auto I = Store.find(Str);
00362   if (I != Store.end())
00363     return &I->second;
00364 
00365   auto *Entry =
00366       StringMapEntry<MDString>::Create(Str, Store.getAllocator(), MDString());
00367   bool WasInserted = Store.insert(Entry);
00368   (void)WasInserted;
00369   assert(WasInserted && "Expected entry to be inserted");
00370   Entry->second.Entry = Entry;
00371   return &Entry->second;
00372 }
00373 
00374 StringRef MDString::getString() const {
00375   assert(Entry && "Expected to find string map entry");
00376   return Entry->first();
00377 }
00378 
00379 //===----------------------------------------------------------------------===//
00380 // MDNode implementation.
00381 //
00382 
00383 void *MDNode::operator new(size_t Size, unsigned NumOps) {
00384   void *Ptr = ::operator new(Size + NumOps * sizeof(MDOperand));
00385   MDOperand *O = static_cast<MDOperand *>(Ptr);
00386   for (MDOperand *E = O + NumOps; O != E; ++O)
00387     (void)new (O) MDOperand;
00388   return O;
00389 }
00390 
00391 void MDNode::operator delete(void *Mem) {
00392   MDNode *N = static_cast<MDNode *>(Mem);
00393   MDOperand *O = static_cast<MDOperand *>(Mem);
00394   for (MDOperand *E = O - N->NumOperands; O != E; --O)
00395     (O - 1)->~MDOperand();
00396   ::operator delete(O);
00397 }
00398 
00399 MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
00400                ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2)
00401     : Metadata(ID, Storage), NumOperands(Ops1.size() + Ops2.size()),
00402       NumUnresolved(0), Context(Context) {
00403   unsigned Op = 0;
00404   for (Metadata *MD : Ops1)
00405     setOperand(Op++, MD);
00406   for (Metadata *MD : Ops2)
00407     setOperand(Op++, MD);
00408 
00409   if (isDistinct())
00410     return;
00411 
00412   if (isUniqued())
00413     // Check whether any operands are unresolved, requiring re-uniquing.  If
00414     // not, don't support RAUW.
00415     if (!countUnresolvedOperands())
00416       return;
00417 
00418   this->Context.makeReplaceable(make_unique<ReplaceableMetadataImpl>(Context));
00419 }
00420 
00421 TempMDNode MDNode::clone() const {
00422   switch (getMetadataID()) {
00423   default:
00424     llvm_unreachable("Invalid MDNode subclass");
00425 #define HANDLE_MDNODE_LEAF(CLASS)                                              \
00426   case CLASS##Kind:                                                            \
00427     return cast<CLASS>(this)->cloneImpl();
00428 #include "llvm/IR/Metadata.def"
00429   }
00430 }
00431 
00432 static bool isOperandUnresolved(Metadata *Op) {
00433   if (auto *N = dyn_cast_or_null<MDNode>(Op))
00434     return !N->isResolved();
00435   return false;
00436 }
00437 
00438 unsigned MDNode::countUnresolvedOperands() {
00439   assert(NumUnresolved == 0 && "Expected unresolved ops to be uncounted");
00440   for (const auto &Op : operands())
00441     NumUnresolved += unsigned(isOperandUnresolved(Op));
00442   return NumUnresolved;
00443 }
00444 
00445 void MDNode::makeUniqued() {
00446   assert(isTemporary() && "Expected this to be temporary");
00447   assert(!isResolved() && "Expected this to be unresolved");
00448 
00449   // Make this 'uniqued'.
00450   Storage = Uniqued;
00451   if (!countUnresolvedOperands())
00452     resolve();
00453 
00454   assert(isUniqued() && "Expected this to be uniqued");
00455 }
00456 
00457 void MDNode::makeDistinct() {
00458   assert(isTemporary() && "Expected this to be temporary");
00459   assert(!isResolved() && "Expected this to be unresolved");
00460 
00461   // Pretend to be uniqued, resolve the node, and then store in distinct table.
00462   Storage = Uniqued;
00463   resolve();
00464   storeDistinctInContext();
00465 
00466   assert(isDistinct() && "Expected this to be distinct");
00467   assert(isResolved() && "Expected this to be resolved");
00468 }
00469 
00470 void MDNode::resolve() {
00471   assert(isUniqued() && "Expected this to be uniqued");
00472   assert(!isResolved() && "Expected this to be unresolved");
00473 
00474   // Move the map, so that this immediately looks resolved.
00475   auto Uses = Context.takeReplaceableUses();
00476   NumUnresolved = 0;
00477   assert(isResolved() && "Expected this to be resolved");
00478 
00479   // Drop RAUW support.
00480   Uses->resolveAllUses();
00481 }
00482 
00483 void MDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) {
00484   assert(NumUnresolved != 0 && "Expected unresolved operands");
00485 
00486   // Check if an operand was resolved.
00487   if (!isOperandUnresolved(Old)) {
00488     if (isOperandUnresolved(New))
00489       // An operand was un-resolved!
00490       ++NumUnresolved;
00491   } else if (!isOperandUnresolved(New))
00492     decrementUnresolvedOperandCount();
00493 }
00494 
00495 void MDNode::decrementUnresolvedOperandCount() {
00496   if (!--NumUnresolved)
00497     // Last unresolved operand has just been resolved.
00498     resolve();
00499 }
00500 
00501 void MDNode::resolveCycles() {
00502   if (isResolved())
00503     return;
00504 
00505   // Resolve this node immediately.
00506   resolve();
00507 
00508   // Resolve all operands.
00509   for (const auto &Op : operands()) {
00510     auto *N = dyn_cast_or_null<MDNode>(Op);
00511     if (!N)
00512       continue;
00513 
00514     assert(!N->isTemporary() &&
00515            "Expected all forward declarations to be resolved");
00516     if (!N->isResolved())
00517       N->resolveCycles();
00518   }
00519 }
00520 
00521 MDNode *MDNode::replaceWithUniquedImpl() {
00522   // Try to uniquify in place.
00523   MDNode *UniquedNode = uniquify();
00524   if (UniquedNode == this) {
00525     makeUniqued();
00526     return this;
00527   }
00528 
00529   // Collision, so RAUW instead.
00530   replaceAllUsesWith(UniquedNode);
00531   deleteAsSubclass();
00532   return UniquedNode;
00533 }
00534 
00535 MDNode *MDNode::replaceWithDistinctImpl() {
00536   makeDistinct();
00537   return this;
00538 }
00539 
00540 void MDTuple::recalculateHash() {
00541   setHash(MDTupleInfo::KeyTy::calculateHash(this));
00542 }
00543 
00544 void GenericDebugNode::recalculateHash() {
00545   setHash(GenericDebugNodeInfo::KeyTy::calculateHash(this));
00546 }
00547 
00548 void MDNode::dropAllReferences() {
00549   for (unsigned I = 0, E = NumOperands; I != E; ++I)
00550     setOperand(I, nullptr);
00551   if (!isResolved()) {
00552     Context.getReplaceableUses()->resolveAllUses(/* ResolveUsers */ false);
00553     (void)Context.takeReplaceableUses();
00554   }
00555 }
00556 
00557 void MDNode::handleChangedOperand(void *Ref, Metadata *New) {
00558   unsigned Op = static_cast<MDOperand *>(Ref) - op_begin();
00559   assert(Op < getNumOperands() && "Expected valid operand");
00560 
00561   if (!isUniqued()) {
00562     // This node is not uniqued.  Just set the operand and be done with it.
00563     setOperand(Op, New);
00564     return;
00565   }
00566 
00567   // This node is uniqued.
00568   eraseFromStore();
00569 
00570   Metadata *Old = getOperand(Op);
00571   setOperand(Op, New);
00572 
00573   // Drop uniquing for self-reference cycles.
00574   if (New == this) {
00575     if (!isResolved())
00576       resolve();
00577     storeDistinctInContext();
00578     return;
00579   }
00580 
00581   // Re-unique the node.
00582   auto *Uniqued = uniquify();
00583   if (Uniqued == this) {
00584     if (!isResolved())
00585       resolveAfterOperandChange(Old, New);
00586     return;
00587   }
00588 
00589   // Collision.
00590   if (!isResolved()) {
00591     // Still unresolved, so RAUW.
00592     //
00593     // First, clear out all operands to prevent any recursion (similar to
00594     // dropAllReferences(), but we still need the use-list).
00595     for (unsigned O = 0, E = getNumOperands(); O != E; ++O)
00596       setOperand(O, nullptr);
00597     Context.getReplaceableUses()->replaceAllUsesWith(Uniqued);
00598     deleteAsSubclass();
00599     return;
00600   }
00601 
00602   // Store in non-uniqued form if RAUW isn't possible.
00603   storeDistinctInContext();
00604 }
00605 
00606 void MDNode::deleteAsSubclass() {
00607   switch (getMetadataID()) {
00608   default:
00609     llvm_unreachable("Invalid subclass of MDNode");
00610 #define HANDLE_MDNODE_LEAF(CLASS)                                              \
00611   case CLASS##Kind:                                                            \
00612     delete cast<CLASS>(this);                                                  \
00613     break;
00614 #include "llvm/IR/Metadata.def"
00615   }
00616 }
00617 
00618 template <class T, class InfoT>
00619 static T *getUniqued(DenseSet<T *, InfoT> &Store,
00620                      const typename InfoT::KeyTy &Key) {
00621   auto I = Store.find_as(Key);
00622   return I == Store.end() ? nullptr : *I;
00623 }
00624 
00625 template <class T, class InfoT>
00626 static T *uniquifyImpl(T *N, DenseSet<T *, InfoT> &Store) {
00627   if (T *U = getUniqued(Store, N))
00628     return U;
00629 
00630   Store.insert(N);
00631   return N;
00632 }
00633 
00634 template <class NodeTy> struct MDNode::HasCachedHash {
00635   typedef char Yes[1];
00636   typedef char No[2];
00637   template <class U, U Val> struct SFINAE {};
00638 
00639   template <class U>
00640   static Yes &check(SFINAE<void (U::*)(unsigned), &U::setHash> *);
00641   template <class U> static No &check(...);
00642 
00643   static const bool value = sizeof(check<NodeTy>(nullptr)) == sizeof(Yes);
00644 };
00645 
00646 MDNode *MDNode::uniquify() {
00647   // Try to insert into uniquing store.
00648   switch (getMetadataID()) {
00649   default:
00650     llvm_unreachable("Invalid subclass of MDNode");
00651 #define HANDLE_MDNODE_LEAF(CLASS)                                              \
00652   case CLASS##Kind: {                                                          \
00653     CLASS *SubclassThis = cast<CLASS>(this);                                   \
00654     std::integral_constant<bool, HasCachedHash<CLASS>::value>                  \
00655         ShouldRecalculateHash;                                                 \
00656     dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash);              \
00657     return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s);           \
00658   }
00659 #include "llvm/IR/Metadata.def"
00660   }
00661 }
00662 
00663 void MDNode::eraseFromStore() {
00664   switch (getMetadataID()) {
00665   default:
00666     llvm_unreachable("Invalid subclass of MDNode");
00667 #define HANDLE_MDNODE_LEAF(CLASS)                                              \
00668   case CLASS##Kind:                                                            \
00669     getContext().pImpl->CLASS##s.erase(cast<CLASS>(this));                     \
00670     break;
00671 #include "llvm/IR/Metadata.def"
00672   }
00673 }
00674 
00675 template <class T, class StoreT>
00676 T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
00677   switch (Storage) {
00678   case Uniqued:
00679     Store.insert(N);
00680     break;
00681   case Distinct:
00682     N->storeDistinctInContext();
00683     break;
00684   case Temporary:
00685     break;
00686   }
00687   return N;
00688 }
00689 
00690 MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
00691                           StorageType Storage, bool ShouldCreate) {
00692   unsigned Hash = 0;
00693   if (Storage == Uniqued) {
00694     MDTupleInfo::KeyTy Key(MDs);
00695     if (auto *N = getUniqued(Context.pImpl->MDTuples, Key))
00696       return N;
00697     if (!ShouldCreate)
00698       return nullptr;
00699     Hash = Key.getHash();
00700   } else {
00701     assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
00702   }
00703 
00704   return storeImpl(new (MDs.size()) MDTuple(Context, Storage, Hash, MDs),
00705                    Storage, Context.pImpl->MDTuples);
00706 }
00707 
00708 MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
00709                        unsigned Column, ArrayRef<Metadata *> MDs)
00710     : MDNode(C, MDLocationKind, Storage, MDs) {
00711   assert((MDs.size() == 1 || MDs.size() == 2) &&
00712          "Expected a scope and optional inlined-at");
00713 
00714   // Set line and column.
00715   assert(Line < (1u << 24) && "Expected 24-bit line");
00716   assert(Column < (1u << 16) && "Expected 16-bit column");
00717 
00718   SubclassData32 = Line;
00719   SubclassData16 = Column;
00720 }
00721 
00722 static void adjustLine(unsigned &Line) {
00723   // Set to unknown on overflow.  Still use 24 bits for now.
00724   if (Line >= (1u << 24))
00725     Line = 0;
00726 }
00727 
00728 static void adjustColumn(unsigned &Column) {
00729   // Set to unknown on overflow.  We only have 16 bits to play with here.
00730   if (Column >= (1u << 16))
00731     Column = 0;
00732 }
00733 
00734 MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
00735                                 unsigned Column, Metadata *Scope,
00736                                 Metadata *InlinedAt, StorageType Storage,
00737                                 bool ShouldCreate) {
00738   // Fixup line/column.
00739   adjustLine(Line);
00740   adjustColumn(Column);
00741 
00742   if (Storage == Uniqued) {
00743     if (auto *N = getUniqued(
00744             Context.pImpl->MDLocations,
00745             MDLocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
00746       return N;
00747     if (!ShouldCreate)
00748       return nullptr;
00749   } else {
00750     assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
00751   }
00752 
00753   SmallVector<Metadata *, 2> Ops;
00754   Ops.push_back(Scope);
00755   if (InlinedAt)
00756     Ops.push_back(InlinedAt);
00757   return storeImpl(new (Ops.size())
00758                        MDLocation(Context, Storage, Line, Column, Ops),
00759                    Storage, Context.pImpl->MDLocations);
00760 }
00761 
00762 GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
00763                                             StringRef Header,
00764                                             ArrayRef<Metadata *> DwarfOps,
00765                                             StorageType Storage,
00766                                             bool ShouldCreate) {
00767   unsigned Hash = 0;
00768   if (Storage == Uniqued) {
00769     GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps);
00770     if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key))
00771       return N;
00772     if (!ShouldCreate)
00773       return nullptr;
00774     Hash = Key.getHash();
00775   } else {
00776     assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
00777   }
00778 
00779   // Use a nullptr for empty headers.
00780   Metadata *PreOps[] = {Header.empty() ? nullptr
00781                                        : MDString::get(Context, Header)};
00782   return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
00783                        Context, Storage, Hash, Tag, PreOps, DwarfOps),
00784                    Storage, Context.pImpl->GenericDebugNodes);
00785 }
00786 
00787 void MDNode::deleteTemporary(MDNode *N) {
00788   assert(N->isTemporary() && "Expected temporary node");
00789   N->replaceAllUsesWith(nullptr);
00790   N->deleteAsSubclass();
00791 }
00792 
00793 void MDNode::storeDistinctInContext() {
00794   assert(isResolved() && "Expected resolved nodes");
00795   Storage = Distinct;
00796 
00797   // Reset the hash.
00798   switch (getMetadataID()) {
00799   default:
00800     llvm_unreachable("Invalid subclass of MDNode");
00801 #define HANDLE_MDNODE_LEAF(CLASS)                                              \
00802   case CLASS##Kind: {                                                          \
00803     std::integral_constant<bool, HasCachedHash<CLASS>::value> ShouldResetHash; \
00804     dispatchResetHash(cast<CLASS>(this), ShouldResetHash);                     \
00805     break;                                                                     \
00806   }
00807 #include "llvm/IR/Metadata.def"
00808   }
00809 
00810   getContext().pImpl->DistinctMDNodes.insert(this);
00811 }
00812 
00813 void MDNode::replaceOperandWith(unsigned I, Metadata *New) {
00814   if (getOperand(I) == New)
00815     return;
00816 
00817   if (!isUniqued()) {
00818     setOperand(I, New);
00819     return;
00820   }
00821 
00822   handleChangedOperand(mutable_begin() + I, New);
00823 }
00824 
00825 void MDNode::setOperand(unsigned I, Metadata *New) {
00826   assert(I < NumOperands);
00827   mutable_begin()[I].reset(New, isUniqued() ? this : nullptr);
00828 }
00829 
00830 /// \brief Get a node, or a self-reference that looks like it.
00831 ///
00832 /// Special handling for finding self-references, for use by \a
00833 /// MDNode::concatenate() and \a MDNode::intersect() to maintain behaviour from
00834 /// when self-referencing nodes were still uniqued.  If the first operand has
00835 /// the same operands as \c Ops, return the first operand instead.
00836 static MDNode *getOrSelfReference(LLVMContext &Context,
00837                                   ArrayRef<Metadata *> Ops) {
00838   if (!Ops.empty())
00839     if (MDNode *N = dyn_cast_or_null<MDNode>(Ops[0]))
00840       if (N->getNumOperands() == Ops.size() && N == N->getOperand(0)) {
00841         for (unsigned I = 1, E = Ops.size(); I != E; ++I)
00842           if (Ops[I] != N->getOperand(I))
00843             return MDNode::get(Context, Ops);
00844         return N;
00845       }
00846 
00847   return MDNode::get(Context, Ops);
00848 }
00849 
00850 MDNode *MDNode::concatenate(MDNode *A, MDNode *B) {
00851   if (!A)
00852     return B;
00853   if (!B)
00854     return A;
00855 
00856   SmallVector<Metadata *, 4> MDs(A->getNumOperands() + B->getNumOperands());
00857 
00858   unsigned j = 0;
00859   for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i)
00860     MDs[j++] = A->getOperand(i);
00861   for (unsigned i = 0, ie = B->getNumOperands(); i != ie; ++i)
00862     MDs[j++] = B->getOperand(i);
00863 
00864   // FIXME: This preserves long-standing behaviour, but is it really the right
00865   // behaviour?  Or was that an unintended side-effect of node uniquing?
00866   return getOrSelfReference(A->getContext(), MDs);
00867 }
00868 
00869 MDNode *MDNode::intersect(MDNode *A, MDNode *B) {
00870   if (!A || !B)
00871     return nullptr;
00872 
00873   SmallVector<Metadata *, 4> MDs;
00874   for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i) {
00875     Metadata *MD = A->getOperand(i);
00876     for (unsigned j = 0, je = B->getNumOperands(); j != je; ++j)
00877       if (MD == B->getOperand(j)) {
00878         MDs.push_back(MD);
00879         break;
00880       }
00881   }
00882 
00883   // FIXME: This preserves long-standing behaviour, but is it really the right
00884   // behaviour?  Or was that an unintended side-effect of node uniquing?
00885   return getOrSelfReference(A->getContext(), MDs);
00886 }
00887 
00888 MDNode *MDNode::getMostGenericFPMath(MDNode *A, MDNode *B) {
00889   if (!A || !B)
00890     return nullptr;
00891 
00892   APFloat AVal = mdconst::extract<ConstantFP>(A->getOperand(0))->getValueAPF();
00893   APFloat BVal = mdconst::extract<ConstantFP>(B->getOperand(0))->getValueAPF();
00894   if (AVal.compare(BVal) == APFloat::cmpLessThan)
00895     return A;
00896   return B;
00897 }
00898 
00899 static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
00900   return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
00901 }
00902 
00903 static bool canBeMerged(const ConstantRange &A, const ConstantRange &B) {
00904   return !A.intersectWith(B).isEmptySet() || isContiguous(A, B);
00905 }
00906 
00907 static bool tryMergeRange(SmallVectorImpl<ConstantInt *> &EndPoints,
00908                           ConstantInt *Low, ConstantInt *High) {
00909   ConstantRange NewRange(Low->getValue(), High->getValue());
00910   unsigned Size = EndPoints.size();
00911   APInt LB = EndPoints[Size - 2]->getValue();
00912   APInt LE = EndPoints[Size - 1]->getValue();
00913   ConstantRange LastRange(LB, LE);
00914   if (canBeMerged(NewRange, LastRange)) {
00915     ConstantRange Union = LastRange.unionWith(NewRange);
00916     Type *Ty = High->getType();
00917     EndPoints[Size - 2] =
00918         cast<ConstantInt>(ConstantInt::get(Ty, Union.getLower()));
00919     EndPoints[Size - 1] =
00920         cast<ConstantInt>(ConstantInt::get(Ty, Union.getUpper()));
00921     return true;
00922   }
00923   return false;
00924 }
00925 
00926 static void addRange(SmallVectorImpl<ConstantInt *> &EndPoints,
00927                      ConstantInt *Low, ConstantInt *High) {
00928   if (!EndPoints.empty())
00929     if (tryMergeRange(EndPoints, Low, High))
00930       return;
00931 
00932   EndPoints.push_back(Low);
00933   EndPoints.push_back(High);
00934 }
00935 
00936 MDNode *MDNode::getMostGenericRange(MDNode *A, MDNode *B) {
00937   // Given two ranges, we want to compute the union of the ranges. This
00938   // is slightly complitade by having to combine the intervals and merge
00939   // the ones that overlap.
00940 
00941   if (!A || !B)
00942     return nullptr;
00943 
00944   if (A == B)
00945     return A;
00946 
00947   // First, walk both lists in older of the lower boundary of each interval.
00948   // At each step, try to merge the new interval to the last one we adedd.
00949   SmallVector<ConstantInt *, 4> EndPoints;
00950   int AI = 0;
00951   int BI = 0;
00952   int AN = A->getNumOperands() / 2;
00953   int BN = B->getNumOperands() / 2;
00954   while (AI < AN && BI < BN) {
00955     ConstantInt *ALow = mdconst::extract<ConstantInt>(A->getOperand(2 * AI));
00956     ConstantInt *BLow = mdconst::extract<ConstantInt>(B->getOperand(2 * BI));
00957 
00958     if (ALow->getValue().slt(BLow->getValue())) {
00959       addRange(EndPoints, ALow,
00960                mdconst::extract<ConstantInt>(A->getOperand(2 * AI + 1)));
00961       ++AI;
00962     } else {
00963       addRange(EndPoints, BLow,
00964                mdconst::extract<ConstantInt>(B->getOperand(2 * BI + 1)));
00965       ++BI;
00966     }
00967   }
00968   while (AI < AN) {
00969     addRange(EndPoints, mdconst::extract<ConstantInt>(A->getOperand(2 * AI)),
00970              mdconst::extract<ConstantInt>(A->getOperand(2 * AI + 1)));
00971     ++AI;
00972   }
00973   while (BI < BN) {
00974     addRange(EndPoints, mdconst::extract<ConstantInt>(B->getOperand(2 * BI)),
00975              mdconst::extract<ConstantInt>(B->getOperand(2 * BI + 1)));
00976     ++BI;
00977   }
00978 
00979   // If we have more than 2 ranges (4 endpoints) we have to try to merge
00980   // the last and first ones.
00981   unsigned Size = EndPoints.size();
00982   if (Size > 4) {
00983     ConstantInt *FB = EndPoints[0];
00984     ConstantInt *FE = EndPoints[1];
00985     if (tryMergeRange(EndPoints, FB, FE)) {
00986       for (unsigned i = 0; i < Size - 2; ++i) {
00987         EndPoints[i] = EndPoints[i + 2];
00988       }
00989       EndPoints.resize(Size - 2);
00990     }
00991   }
00992 
00993   // If in the end we have a single range, it is possible that it is now the
00994   // full range. Just drop the metadata in that case.
00995   if (EndPoints.size() == 2) {
00996     ConstantRange Range(EndPoints[0]->getValue(), EndPoints[1]->getValue());
00997     if (Range.isFullSet())
00998       return nullptr;
00999   }
01000 
01001   SmallVector<Metadata *, 4> MDs;
01002   MDs.reserve(EndPoints.size());
01003   for (auto *I : EndPoints)
01004     MDs.push_back(ConstantAsMetadata::get(I));
01005   return MDNode::get(A->getContext(), MDs);
01006 }
01007 
01008 //===----------------------------------------------------------------------===//
01009 // NamedMDNode implementation.
01010 //
01011 
01012 static SmallVector<TrackingMDRef, 4> &getNMDOps(void *Operands) {
01013   return *(SmallVector<TrackingMDRef, 4> *)Operands;
01014 }
01015 
01016 NamedMDNode::NamedMDNode(const Twine &N)
01017     : Name(N.str()), Parent(nullptr),
01018       Operands(new SmallVector<TrackingMDRef, 4>()) {}
01019 
01020 NamedMDNode::~NamedMDNode() {
01021   dropAllReferences();
01022   delete &getNMDOps(Operands);
01023 }
01024 
01025 unsigned NamedMDNode::getNumOperands() const {
01026   return (unsigned)getNMDOps(Operands).size();
01027 }
01028 
01029 MDNode *NamedMDNode::getOperand(unsigned i) const {
01030   assert(i < getNumOperands() && "Invalid Operand number!");
01031   auto *N = getNMDOps(Operands)[i].get();
01032   return cast_or_null<MDNode>(N);
01033 }
01034 
01035 void NamedMDNode::addOperand(MDNode *M) { getNMDOps(Operands).emplace_back(M); }
01036 
01037 void NamedMDNode::setOperand(unsigned I, MDNode *New) {
01038   assert(I < getNumOperands() && "Invalid operand number");
01039   getNMDOps(Operands)[I].reset(New);
01040 }
01041 
01042 void NamedMDNode::eraseFromParent() {
01043   getParent()->eraseNamedMetadata(this);
01044 }
01045 
01046 void NamedMDNode::dropAllReferences() {
01047   getNMDOps(Operands).clear();
01048 }
01049 
01050 StringRef NamedMDNode::getName() const {
01051   return StringRef(Name);
01052 }
01053 
01054 //===----------------------------------------------------------------------===//
01055 // Instruction Metadata method implementations.
01056 //
01057 
01058 void Instruction::setMetadata(StringRef Kind, MDNode *Node) {
01059   if (!Node && !hasMetadata())
01060     return;
01061   setMetadata(getContext().getMDKindID(Kind), Node);
01062 }
01063 
01064 MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
01065   return getMetadataImpl(getContext().getMDKindID(Kind));
01066 }
01067 
01068 void Instruction::dropUnknownMetadata(ArrayRef<unsigned> KnownIDs) {
01069   SmallSet<unsigned, 5> KnownSet;
01070   KnownSet.insert(KnownIDs.begin(), KnownIDs.end());
01071 
01072   // Drop debug if needed
01073   if (KnownSet.erase(LLVMContext::MD_dbg))
01074     DbgLoc = DebugLoc();
01075 
01076   if (!hasMetadataHashEntry())
01077     return; // Nothing to remove!
01078 
01079   DenseMap<const Instruction *, LLVMContextImpl::MDMapTy> &MetadataStore =
01080       getContext().pImpl->MetadataStore;
01081 
01082   if (KnownSet.empty()) {
01083     // Just drop our entry at the store.
01084     MetadataStore.erase(this);
01085     setHasMetadataHashEntry(false);
01086     return;
01087   }
01088 
01089   LLVMContextImpl::MDMapTy &Info = MetadataStore[this];
01090   unsigned I;
01091   unsigned E;
01092   // Walk the array and drop any metadata we don't know.
01093   for (I = 0, E = Info.size(); I != E;) {
01094     if (KnownSet.count(Info[I].first)) {
01095       ++I;
01096       continue;
01097     }
01098 
01099     Info[I] = std::move(Info.back());
01100     Info.pop_back();
01101     --E;
01102   }
01103   assert(E == Info.size());
01104 
01105   if (E == 0) {
01106     // Drop our entry at the store.
01107     MetadataStore.erase(this);
01108     setHasMetadataHashEntry(false);
01109   }
01110 }
01111 
01112 /// setMetadata - Set the metadata of of the specified kind to the specified
01113 /// node.  This updates/replaces metadata if already present, or removes it if
01114 /// Node is null.
01115 void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
01116   if (!Node && !hasMetadata())
01117     return;
01118 
01119   // Handle 'dbg' as a special case since it is not stored in the hash table.
01120   if (KindID == LLVMContext::MD_dbg) {
01121     DbgLoc = DebugLoc::getFromDILocation(Node);
01122     return;
01123   }
01124   
01125   // Handle the case when we're adding/updating metadata on an instruction.
01126   if (Node) {
01127     LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
01128     assert(!Info.empty() == hasMetadataHashEntry() &&
01129            "HasMetadata bit is wonked");
01130     if (Info.empty()) {
01131       setHasMetadataHashEntry(true);
01132     } else {
01133       // Handle replacement of an existing value.
01134       for (auto &P : Info)
01135         if (P.first == KindID) {
01136           P.second.reset(Node);
01137           return;
01138         }
01139     }
01140 
01141     // No replacement, just add it to the list.
01142     Info.emplace_back(std::piecewise_construct, std::make_tuple(KindID),
01143                       std::make_tuple(Node));
01144     return;
01145   }
01146 
01147   // Otherwise, we're removing metadata from an instruction.
01148   assert((hasMetadataHashEntry() ==
01149           (getContext().pImpl->MetadataStore.count(this) > 0)) &&
01150          "HasMetadata bit out of date!");
01151   if (!hasMetadataHashEntry())
01152     return;  // Nothing to remove!
01153   LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
01154 
01155   // Common case is removing the only entry.
01156   if (Info.size() == 1 && Info[0].first == KindID) {
01157     getContext().pImpl->MetadataStore.erase(this);
01158     setHasMetadataHashEntry(false);
01159     return;
01160   }
01161 
01162   // Handle removal of an existing value.
01163   for (unsigned i = 0, e = Info.size(); i != e; ++i)
01164     if (Info[i].first == KindID) {
01165       Info[i] = std::move(Info.back());
01166       Info.pop_back();
01167       assert(!Info.empty() && "Removing last entry should be handled above");
01168       return;
01169     }
01170   // Otherwise, removing an entry that doesn't exist on the instruction.
01171 }
01172 
01173 void Instruction::setAAMetadata(const AAMDNodes &N) {
01174   setMetadata(LLVMContext::MD_tbaa, N.TBAA);
01175   setMetadata(LLVMContext::MD_alias_scope, N.Scope);
01176   setMetadata(LLVMContext::MD_noalias, N.NoAlias);
01177 }
01178 
01179 MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
01180   // Handle 'dbg' as a special case since it is not stored in the hash table.
01181   if (KindID == LLVMContext::MD_dbg)
01182     return DbgLoc.getAsMDNode();
01183 
01184   if (!hasMetadataHashEntry()) return nullptr;
01185   
01186   LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
01187   assert(!Info.empty() && "bit out of sync with hash table");
01188 
01189   for (const auto &I : Info)
01190     if (I.first == KindID)
01191       return I.second;
01192   return nullptr;
01193 }
01194 
01195 void Instruction::getAllMetadataImpl(
01196     SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {
01197   Result.clear();
01198   
01199   // Handle 'dbg' as a special case since it is not stored in the hash table.
01200   if (!DbgLoc.isUnknown()) {
01201     Result.push_back(
01202         std::make_pair((unsigned)LLVMContext::MD_dbg, DbgLoc.getAsMDNode()));
01203     if (!hasMetadataHashEntry()) return;
01204   }
01205   
01206   assert(hasMetadataHashEntry() &&
01207          getContext().pImpl->MetadataStore.count(this) &&
01208          "Shouldn't have called this");
01209   const LLVMContextImpl::MDMapTy &Info =
01210     getContext().pImpl->MetadataStore.find(this)->second;
01211   assert(!Info.empty() && "Shouldn't have called this");
01212 
01213   Result.reserve(Result.size() + Info.size());
01214   for (auto &I : Info)
01215     Result.push_back(std::make_pair(I.first, cast<MDNode>(I.second.get())));
01216 
01217   // Sort the resulting array so it is stable.
01218   if (Result.size() > 1)
01219     array_pod_sort(Result.begin(), Result.end());
01220 }
01221 
01222 void Instruction::getAllMetadataOtherThanDebugLocImpl(
01223     SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {
01224   Result.clear();
01225   assert(hasMetadataHashEntry() &&
01226          getContext().pImpl->MetadataStore.count(this) &&
01227          "Shouldn't have called this");
01228   const LLVMContextImpl::MDMapTy &Info =
01229     getContext().pImpl->MetadataStore.find(this)->second;
01230   assert(!Info.empty() && "Shouldn't have called this");
01231   Result.reserve(Result.size() + Info.size());
01232   for (auto &I : Info)
01233     Result.push_back(std::make_pair(I.first, cast<MDNode>(I.second.get())));
01234 
01235   // Sort the resulting array so it is stable.
01236   if (Result.size() > 1)
01237     array_pod_sort(Result.begin(), Result.end());
01238 }
01239 
01240 /// clearMetadataHashEntries - Clear all hashtable-based metadata from
01241 /// this instruction.
01242 void Instruction::clearMetadataHashEntries() {
01243   assert(hasMetadataHashEntry() && "Caller should check");
01244   getContext().pImpl->MetadataStore.erase(this);
01245   setHasMetadataHashEntry(false);
01246 }