1 //===-- Metadata.cpp - Implement Metadata classes -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Metadata classes.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/IR/Metadata.h"
15 #include "LLVMContextImpl.h"
16 #include "SymbolTableListTraitsImpl.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallSet.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/IR/ConstantRange.h"
23 #include "llvm/IR/Instruction.h"
24 #include "llvm/IR/LLVMContext.h"
25 #include "llvm/IR/LeakDetector.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/IR/ValueHandle.h"
31 Metadata::Metadata(LLVMContext &Context, unsigned ID)
32 : Value(Type::getMetadataTy(Context), ID) {}
34 //===----------------------------------------------------------------------===//
35 // MDString implementation.
38 void MDString::anchor() { }
40 MDString *MDString::get(LLVMContext &Context, StringRef Str) {
41 auto &Store = Context.pImpl->MDStringCache;
42 auto I = Store.find(Str);
47 StringMapEntry<MDString>::Create(Str, Store.getAllocator(), Context);
48 bool WasInserted = Store.insert(Entry);
50 assert(WasInserted && "Expected entry to be inserted");
51 return &Entry->second;
54 StringRef MDString::getString() const {
55 return StringMapEntry<MDString>::GetStringMapEntryFromValue(*this).first();
58 //===----------------------------------------------------------------------===//
59 // MDNodeOperand implementation.
62 // Use CallbackVH to hold MDNode operands.
64 class MDNodeOperand : public CallbackVH {
66 MDNodeOperand *Cur = this;
68 while (Cur->getValPtrInt() != 1)
71 assert(Cur->getValPtrInt() == 1 &&
72 "Couldn't find the beginning of the operand list!");
73 return reinterpret_cast<MDNode*>(Cur) - 1;
77 MDNodeOperand(Value *V) : CallbackVH(V) {}
78 virtual ~MDNodeOperand();
81 unsigned IsFirst = this->getValPtrInt();
83 this->setAsFirstOperand(IsFirst);
86 /// \brief Accessor method to mark the operand as the first in the list.
87 void setAsFirstOperand(unsigned V) { this->setValPtrInt(V); }
89 void deleted() override;
90 void allUsesReplacedWith(Value *NV) override;
92 } // end namespace llvm.
94 // Provide out-of-line definition to prevent weak vtable.
95 MDNodeOperand::~MDNodeOperand() {}
97 void MDNodeOperand::deleted() {
98 getParent()->replaceOperand(this, nullptr);
101 void MDNodeOperand::allUsesReplacedWith(Value *NV) {
102 getParent()->replaceOperand(this, NV);
105 //===----------------------------------------------------------------------===//
106 // MDNode implementation.
109 /// \brief Get the MDNodeOperand's coallocated on the end of the MDNode.
110 static MDNodeOperand *getOperandPtr(MDNode *N, unsigned Op) {
111 static_assert(sizeof(GenericMDNode) == sizeof(MDNode),
112 "Expected subclasses to have no size overhead");
113 static_assert(sizeof(MDNodeFwdDecl) == sizeof(MDNode),
114 "Expected subclasses to have no size overhead");
116 // Use <= instead of < to permit a one-past-the-end address.
117 assert(Op <= N->getNumOperands() && "Invalid operand number");
118 return reinterpret_cast<MDNodeOperand*>(N + 1) + Op;
121 void MDNode::replaceOperandWith(unsigned i, Value *Val) {
122 MDNodeOperand *Op = getOperandPtr(this, i);
123 replaceOperand(Op, Val);
126 MDNode::MDNode(LLVMContext &C, unsigned ID, ArrayRef<Value *> Vals,
127 bool isFunctionLocal)
128 : Metadata(C, ID), Hash(0) {
129 NumOperands = Vals.size();
132 setValueSubclassData(getSubclassDataFromValue() | FunctionLocalBit);
134 // Initialize the operand list, which is co-allocated on the end of the node.
136 for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands;
137 Op != E; ++Op, ++i) {
138 new (Op) MDNodeOperand(Vals[i]);
140 // Mark the first MDNodeOperand as being the first in the list of operands.
142 Op->setAsFirstOperand(1);
146 GenericMDNode::~GenericMDNode() {
147 LLVMContextImpl *pImpl = getType()->getContext().pImpl;
148 if (isNotUniqued()) {
149 pImpl->NonUniquedMDNodes.erase(this);
151 pImpl->MDNodeSet.erase(this);
156 assert((getSubclassDataFromValue() & DestroyFlag) != 0 &&
157 "Not being destroyed through destroy()?");
159 // Destroy the operands.
160 for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands;
162 Op->~MDNodeOperand();
165 static const Function *getFunctionForValue(Value *V) {
166 if (!V) return nullptr;
167 if (Instruction *I = dyn_cast<Instruction>(V)) {
168 BasicBlock *BB = I->getParent();
169 return BB ? BB->getParent() : nullptr;
171 if (Argument *A = dyn_cast<Argument>(V))
172 return A->getParent();
173 if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
174 return BB->getParent();
175 if (MDNode *MD = dyn_cast<MDNode>(V))
176 return MD->getFunction();
181 static const Function *assertLocalFunction(const MDNode *N) {
182 if (!N->isFunctionLocal()) return nullptr;
184 // FIXME: This does not handle cyclic function local metadata.
185 const Function *F = nullptr, *NewF = nullptr;
186 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
187 if (Value *V = N->getOperand(i)) {
188 if (MDNode *MD = dyn_cast<MDNode>(V))
189 NewF = assertLocalFunction(MD);
191 NewF = getFunctionForValue(V);
196 assert((NewF == nullptr || F == NewF) &&
197 "inconsistent function-local metadata");
203 // getFunction - If this metadata is function-local and recursively has a
204 // function-local operand, return the first such operand's parent function.
205 // Otherwise, return null. getFunction() should not be used for performance-
206 // critical code because it recursively visits all the MDNode's operands.
207 const Function *MDNode::getFunction() const {
209 return assertLocalFunction(this);
211 if (!isFunctionLocal()) return nullptr;
212 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
213 if (const Function *F = getFunctionForValue(getOperand(i)))
219 // destroy - Delete this node. Only when there are no uses.
220 void GenericMDNode::destroy() {
221 setValueSubclassData(getSubclassDataFromValue() | DestroyFlag);
222 // Placement delete, then free the memory.
223 this->~GenericMDNode();
227 void MDNodeFwdDecl::destroy() {
228 setValueSubclassData(getSubclassDataFromValue() | DestroyFlag);
229 // Placement delete, then free the memory.
230 this->~MDNodeFwdDecl();
234 /// \brief Check if the Value would require a function-local MDNode.
235 static bool isFunctionLocalValue(Value *V) {
236 return isa<Instruction>(V) || isa<Argument>(V) || isa<BasicBlock>(V) ||
237 (isa<MDNode>(V) && cast<MDNode>(V)->isFunctionLocal());
240 MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef<Value*> Vals,
241 FunctionLocalness FL, bool Insert) {
242 auto &Store = Context.pImpl->MDNodeSet;
244 GenericMDNodeInfo::KeyTy Key(Vals);
245 auto I = Store.find_as(Key);
246 if (I != Store.end())
251 bool isFunctionLocal = false;
254 for (Value *V : Vals) {
256 if (isFunctionLocalValue(V)) {
257 isFunctionLocal = true;
263 isFunctionLocal = false;
266 isFunctionLocal = true;
270 // Coallocate space for the node and Operands together, then placement new.
272 malloc(sizeof(GenericMDNode) + Vals.size() * sizeof(MDNodeOperand));
273 GenericMDNode *N = new (Ptr) GenericMDNode(Context, Vals, isFunctionLocal);
280 MDNode *MDNode::get(LLVMContext &Context, ArrayRef<Value*> Vals) {
281 return getMDNode(Context, Vals, FL_Unknown);
284 MDNode *MDNode::getWhenValsUnresolved(LLVMContext &Context,
285 ArrayRef<Value*> Vals,
286 bool isFunctionLocal) {
287 return getMDNode(Context, Vals, isFunctionLocal ? FL_Yes : FL_No);
290 MDNode *MDNode::getIfExists(LLVMContext &Context, ArrayRef<Value*> Vals) {
291 return getMDNode(Context, Vals, FL_Unknown, false);
294 MDNode *MDNode::getTemporary(LLVMContext &Context, ArrayRef<Value*> Vals) {
295 MDNode *N = (MDNode *)malloc(sizeof(MDNodeFwdDecl) +
296 Vals.size() * sizeof(MDNodeOperand));
297 N = new (N) MDNodeFwdDecl(Context, Vals, FL_No);
298 N->setValueSubclassData(N->getSubclassDataFromValue() |
300 LeakDetector::addGarbageObject(N);
304 void MDNode::deleteTemporary(MDNode *N) {
305 assert(N->use_empty() && "Temporary MDNode has uses!");
306 assert(isa<MDNodeFwdDecl>(N) && "Expected forward declaration");
307 assert((N->getSubclassDataFromValue() & NotUniquedBit) &&
308 "Temporary MDNode does not have NotUniquedBit set!");
309 assert((N->getSubclassDataFromValue() & DestroyFlag) == 0 &&
310 "Temporary MDNode has DestroyFlag set!");
311 LeakDetector::removeGarbageObject(N);
312 cast<MDNodeFwdDecl>(N)->destroy();
315 /// \brief Return specified operand.
316 Value *MDNode::getOperand(unsigned i) const {
317 assert(i < getNumOperands() && "Invalid operand number");
318 return *getOperandPtr(const_cast<MDNode*>(this), i);
321 void MDNode::setIsNotUniqued() {
322 setValueSubclassData(getSubclassDataFromValue() | NotUniquedBit);
323 LLVMContextImpl *pImpl = getType()->getContext().pImpl;
324 auto *G = cast<GenericMDNode>(this);
326 pImpl->NonUniquedMDNodes.insert(G);
329 // Replace value from this node's operand list.
330 void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
333 // If is possible that someone did GV->RAUW(inst), replacing a global variable
334 // with an instruction or some other function-local object. If this is a
335 // non-function-local MDNode, it can't point to a function-local object.
336 // Handle this case by implicitly dropping the MDNode reference to null.
337 // Likewise if the MDNode is function-local but for a different function.
338 if (To && isFunctionLocalValue(To)) {
339 if (!isFunctionLocal())
342 const Function *F = getFunction();
343 const Function *FV = getFunctionForValue(To);
344 // Metadata can be function-local without having an associated function.
345 // So only consider functions to have changed if non-null.
346 if (F && FV && F != FV)
354 // If this node is already not being uniqued (because one of the operands
355 // already went to null), then there is nothing else to do here.
356 if (isNotUniqued()) {
361 auto &Store = getContext().pImpl->MDNodeSet;
362 auto *N = cast<GenericMDNode>(this);
364 // Remove "this" from the context map.
367 // Update the operand.
370 // If we are dropping an argument to null, we choose to not unique the MDNode
371 // anymore. This commonly occurs during destruction, and uniquing these
372 // brings little reuse. Also, this means we don't need to include
373 // isFunctionLocal bits in the hash for MDNodes.
379 // Now that the node is out of the table, get ready to reinsert it. First,
380 // check to see if another node with the same operands already exists in the
381 // set. If so, then this node is redundant.
382 SmallVector<Value *, 8> Vals;
383 GenericMDNodeInfo::KeyTy Key(N, Vals);
384 auto I = Store.find_as(Key);
385 if (I != Store.end()) {
386 N->replaceAllUsesWith(*I);
394 // If this MDValue was previously function-local but no longer is, clear
395 // its function-local flag.
396 if (isFunctionLocal() && !isFunctionLocalValue(To)) {
397 bool isStillFunctionLocal = false;
398 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
399 Value *V = getOperand(i);
401 if (isFunctionLocalValue(V)) {
402 isStillFunctionLocal = true;
406 if (!isStillFunctionLocal)
407 setValueSubclassData(getSubclassDataFromValue() & ~FunctionLocalBit);
411 MDNode *MDNode::concatenate(MDNode *A, MDNode *B) {
417 SmallVector<Value *, 4> Vals(A->getNumOperands() +
418 B->getNumOperands());
421 for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i)
422 Vals[j++] = A->getOperand(i);
423 for (unsigned i = 0, ie = B->getNumOperands(); i != ie; ++i)
424 Vals[j++] = B->getOperand(i);
426 return MDNode::get(A->getContext(), Vals);
429 MDNode *MDNode::intersect(MDNode *A, MDNode *B) {
433 SmallVector<Value *, 4> Vals;
434 for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i) {
435 Value *V = A->getOperand(i);
436 for (unsigned j = 0, je = B->getNumOperands(); j != je; ++j)
437 if (V == B->getOperand(j)) {
443 return MDNode::get(A->getContext(), Vals);
446 MDNode *MDNode::getMostGenericFPMath(MDNode *A, MDNode *B) {
450 APFloat AVal = cast<ConstantFP>(A->getOperand(0))->getValueAPF();
451 APFloat BVal = cast<ConstantFP>(B->getOperand(0))->getValueAPF();
452 if (AVal.compare(BVal) == APFloat::cmpLessThan)
457 static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
458 return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
461 static bool canBeMerged(const ConstantRange &A, const ConstantRange &B) {
462 return !A.intersectWith(B).isEmptySet() || isContiguous(A, B);
465 static bool tryMergeRange(SmallVectorImpl<Value *> &EndPoints, ConstantInt *Low,
467 ConstantRange NewRange(Low->getValue(), High->getValue());
468 unsigned Size = EndPoints.size();
469 APInt LB = cast<ConstantInt>(EndPoints[Size - 2])->getValue();
470 APInt LE = cast<ConstantInt>(EndPoints[Size - 1])->getValue();
471 ConstantRange LastRange(LB, LE);
472 if (canBeMerged(NewRange, LastRange)) {
473 ConstantRange Union = LastRange.unionWith(NewRange);
474 Type *Ty = High->getType();
475 EndPoints[Size - 2] = ConstantInt::get(Ty, Union.getLower());
476 EndPoints[Size - 1] = ConstantInt::get(Ty, Union.getUpper());
482 static void addRange(SmallVectorImpl<Value *> &EndPoints, ConstantInt *Low,
484 if (!EndPoints.empty())
485 if (tryMergeRange(EndPoints, Low, High))
488 EndPoints.push_back(Low);
489 EndPoints.push_back(High);
492 MDNode *MDNode::getMostGenericRange(MDNode *A, MDNode *B) {
493 // Given two ranges, we want to compute the union of the ranges. This
494 // is slightly complitade by having to combine the intervals and merge
495 // the ones that overlap.
503 // First, walk both lists in older of the lower boundary of each interval.
504 // At each step, try to merge the new interval to the last one we adedd.
505 SmallVector<Value*, 4> EndPoints;
508 int AN = A->getNumOperands() / 2;
509 int BN = B->getNumOperands() / 2;
510 while (AI < AN && BI < BN) {
511 ConstantInt *ALow = cast<ConstantInt>(A->getOperand(2 * AI));
512 ConstantInt *BLow = cast<ConstantInt>(B->getOperand(2 * BI));
514 if (ALow->getValue().slt(BLow->getValue())) {
515 addRange(EndPoints, ALow, cast<ConstantInt>(A->getOperand(2 * AI + 1)));
518 addRange(EndPoints, BLow, cast<ConstantInt>(B->getOperand(2 * BI + 1)));
523 addRange(EndPoints, cast<ConstantInt>(A->getOperand(2 * AI)),
524 cast<ConstantInt>(A->getOperand(2 * AI + 1)));
528 addRange(EndPoints, cast<ConstantInt>(B->getOperand(2 * BI)),
529 cast<ConstantInt>(B->getOperand(2 * BI + 1)));
533 // If we have more than 2 ranges (4 endpoints) we have to try to merge
534 // the last and first ones.
535 unsigned Size = EndPoints.size();
537 ConstantInt *FB = cast<ConstantInt>(EndPoints[0]);
538 ConstantInt *FE = cast<ConstantInt>(EndPoints[1]);
539 if (tryMergeRange(EndPoints, FB, FE)) {
540 for (unsigned i = 0; i < Size - 2; ++i) {
541 EndPoints[i] = EndPoints[i + 2];
543 EndPoints.resize(Size - 2);
547 // If in the end we have a single range, it is possible that it is now the
548 // full range. Just drop the metadata in that case.
549 if (EndPoints.size() == 2) {
550 ConstantRange Range(cast<ConstantInt>(EndPoints[0])->getValue(),
551 cast<ConstantInt>(EndPoints[1])->getValue());
552 if (Range.isFullSet())
556 return MDNode::get(A->getContext(), EndPoints);
559 //===----------------------------------------------------------------------===//
560 // NamedMDNode implementation.
563 static SmallVector<TrackingVH<MDNode>, 4> &getNMDOps(void *Operands) {
564 return *(SmallVector<TrackingVH<MDNode>, 4> *)Operands;
567 NamedMDNode::NamedMDNode(const Twine &N)
568 : Name(N.str()), Parent(nullptr),
569 Operands(new SmallVector<TrackingVH<MDNode>, 4>()) {}
571 NamedMDNode::~NamedMDNode() {
573 delete &getNMDOps(Operands);
576 unsigned NamedMDNode::getNumOperands() const {
577 return (unsigned)getNMDOps(Operands).size();
580 MDNode *NamedMDNode::getOperand(unsigned i) const {
581 assert(i < getNumOperands() && "Invalid Operand number!");
582 return &*getNMDOps(Operands)[i];
585 void NamedMDNode::addOperand(MDNode *M) {
586 assert(!M->isFunctionLocal() &&
587 "NamedMDNode operands must not be function-local!");
588 getNMDOps(Operands).push_back(TrackingVH<MDNode>(M));
591 void NamedMDNode::eraseFromParent() {
592 getParent()->eraseNamedMetadata(this);
595 void NamedMDNode::dropAllReferences() {
596 getNMDOps(Operands).clear();
599 StringRef NamedMDNode::getName() const {
600 return StringRef(Name);
603 //===----------------------------------------------------------------------===//
604 // Instruction Metadata method implementations.
607 void Instruction::setMetadata(StringRef Kind, MDNode *Node) {
608 if (!Node && !hasMetadata())
610 setMetadata(getContext().getMDKindID(Kind), Node);
613 MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
614 return getMetadataImpl(getContext().getMDKindID(Kind));
617 void Instruction::dropUnknownMetadata(ArrayRef<unsigned> KnownIDs) {
618 SmallSet<unsigned, 5> KnownSet;
619 KnownSet.insert(KnownIDs.begin(), KnownIDs.end());
621 // Drop debug if needed
622 if (KnownSet.erase(LLVMContext::MD_dbg))
625 if (!hasMetadataHashEntry())
626 return; // Nothing to remove!
628 DenseMap<const Instruction *, LLVMContextImpl::MDMapTy> &MetadataStore =
629 getContext().pImpl->MetadataStore;
631 if (KnownSet.empty()) {
632 // Just drop our entry at the store.
633 MetadataStore.erase(this);
634 setHasMetadataHashEntry(false);
638 LLVMContextImpl::MDMapTy &Info = MetadataStore[this];
641 // Walk the array and drop any metadata we don't know.
642 for (I = 0, E = Info.size(); I != E;) {
643 if (KnownSet.count(Info[I].first)) {
648 Info[I] = Info.back();
652 assert(E == Info.size());
655 // Drop our entry at the store.
656 MetadataStore.erase(this);
657 setHasMetadataHashEntry(false);
661 /// setMetadata - Set the metadata of of the specified kind to the specified
662 /// node. This updates/replaces metadata if already present, or removes it if
664 void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
665 if (!Node && !hasMetadata())
668 // Handle 'dbg' as a special case since it is not stored in the hash table.
669 if (KindID == LLVMContext::MD_dbg) {
670 DbgLoc = DebugLoc::getFromDILocation(Node);
674 // Handle the case when we're adding/updating metadata on an instruction.
676 LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
677 assert(!Info.empty() == hasMetadataHashEntry() &&
678 "HasMetadata bit is wonked");
680 setHasMetadataHashEntry(true);
682 // Handle replacement of an existing value.
684 if (P.first == KindID) {
690 // No replacement, just add it to the list.
691 Info.push_back(std::make_pair(KindID, Node));
695 // Otherwise, we're removing metadata from an instruction.
696 assert((hasMetadataHashEntry() ==
697 (getContext().pImpl->MetadataStore.count(this) > 0)) &&
698 "HasMetadata bit out of date!");
699 if (!hasMetadataHashEntry())
700 return; // Nothing to remove!
701 LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
703 // Common case is removing the only entry.
704 if (Info.size() == 1 && Info[0].first == KindID) {
705 getContext().pImpl->MetadataStore.erase(this);
706 setHasMetadataHashEntry(false);
710 // Handle removal of an existing value.
711 for (unsigned i = 0, e = Info.size(); i != e; ++i)
712 if (Info[i].first == KindID) {
713 Info[i] = Info.back();
715 assert(!Info.empty() && "Removing last entry should be handled above");
718 // Otherwise, removing an entry that doesn't exist on the instruction.
721 void Instruction::setAAMetadata(const AAMDNodes &N) {
722 setMetadata(LLVMContext::MD_tbaa, N.TBAA);
723 setMetadata(LLVMContext::MD_alias_scope, N.Scope);
724 setMetadata(LLVMContext::MD_noalias, N.NoAlias);
727 MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
728 // Handle 'dbg' as a special case since it is not stored in the hash table.
729 if (KindID == LLVMContext::MD_dbg)
730 return DbgLoc.getAsMDNode(getContext());
732 if (!hasMetadataHashEntry()) return nullptr;
734 LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
735 assert(!Info.empty() && "bit out of sync with hash table");
737 for (const auto &I : Info)
738 if (I.first == KindID)
743 void Instruction::getAllMetadataImpl(
744 SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {
747 // Handle 'dbg' as a special case since it is not stored in the hash table.
748 if (!DbgLoc.isUnknown()) {
749 Result.push_back(std::make_pair((unsigned)LLVMContext::MD_dbg,
750 DbgLoc.getAsMDNode(getContext())));
751 if (!hasMetadataHashEntry()) return;
754 assert(hasMetadataHashEntry() &&
755 getContext().pImpl->MetadataStore.count(this) &&
756 "Shouldn't have called this");
757 const LLVMContextImpl::MDMapTy &Info =
758 getContext().pImpl->MetadataStore.find(this)->second;
759 assert(!Info.empty() && "Shouldn't have called this");
761 Result.append(Info.begin(), Info.end());
763 // Sort the resulting array so it is stable.
764 if (Result.size() > 1)
765 array_pod_sort(Result.begin(), Result.end());
768 void Instruction::getAllMetadataOtherThanDebugLocImpl(
769 SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {
771 assert(hasMetadataHashEntry() &&
772 getContext().pImpl->MetadataStore.count(this) &&
773 "Shouldn't have called this");
774 const LLVMContextImpl::MDMapTy &Info =
775 getContext().pImpl->MetadataStore.find(this)->second;
776 assert(!Info.empty() && "Shouldn't have called this");
777 Result.append(Info.begin(), Info.end());
779 // Sort the resulting array so it is stable.
780 if (Result.size() > 1)
781 array_pod_sort(Result.begin(), Result.end());
784 /// clearMetadataHashEntries - Clear all hashtable-based metadata from
785 /// this instruction.
786 void Instruction::clearMetadataHashEntries() {
787 assert(hasMetadataHashEntry() && "Caller should check");
788 getContext().pImpl->MetadataStore.erase(this);
789 setHasMetadataHashEntry(false);