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"
30 //===----------------------------------------------------------------------===//
31 // MDString implementation.
34 void MDString::anchor() { }
36 MDString::MDString(LLVMContext &C)
37 : Value(Type::getMetadataTy(C), Value::MDStringVal) {}
39 MDString *MDString::get(LLVMContext &Context, StringRef Str) {
40 LLVMContextImpl *pImpl = Context.pImpl;
41 StringMapEntry<Value*> &Entry =
42 pImpl->MDStringCache.GetOrCreateValue(Str);
43 Value *&S = Entry.getValue();
44 if (!S) S = new MDString(Context);
45 S->setValueName(&Entry);
46 return cast<MDString>(S);
49 //===----------------------------------------------------------------------===//
50 // MDNodeOperand implementation.
53 // Use CallbackVH to hold MDNode operands.
55 class MDNodeOperand : public CallbackVH {
57 MDNodeOperand *Cur = this;
59 while (Cur->getValPtrInt() != 1)
62 assert(Cur->getValPtrInt() == 1 &&
63 "Couldn't find the beginning of the operand list!");
64 return reinterpret_cast<MDNode*>(Cur) - 1;
68 MDNodeOperand(Value *V) : CallbackVH(V) {}
69 virtual ~MDNodeOperand();
72 unsigned IsFirst = this->getValPtrInt();
74 this->setAsFirstOperand(IsFirst);
77 /// setAsFirstOperand - Accessor method to mark the operand as the first in
79 void setAsFirstOperand(unsigned V) { this->setValPtrInt(V); }
81 void deleted() override;
82 void allUsesReplacedWith(Value *NV) override;
84 } // end namespace llvm.
86 // Provide out-of-line definition to prevent weak vtable.
87 MDNodeOperand::~MDNodeOperand() {}
89 void MDNodeOperand::deleted() {
90 getParent()->replaceOperand(this, nullptr);
93 void MDNodeOperand::allUsesReplacedWith(Value *NV) {
94 getParent()->replaceOperand(this, NV);
97 //===----------------------------------------------------------------------===//
98 // MDNode implementation.
101 /// getOperandPtr - Helper function to get the MDNodeOperand's coallocated on
102 /// the end of the MDNode.
103 static MDNodeOperand *getOperandPtr(MDNode *N, unsigned Op) {
104 // Use <= instead of < to permit a one-past-the-end address.
105 assert(Op <= N->getNumOperands() && "Invalid operand number");
106 return reinterpret_cast<MDNodeOperand*>(N + 1) + Op;
109 void MDNode::replaceOperandWith(unsigned i, Value *Val) {
110 MDNodeOperand *Op = getOperandPtr(this, i);
111 replaceOperand(Op, Val);
114 MDNode::MDNode(LLVMContext &C, ArrayRef<Value*> Vals, bool isFunctionLocal)
115 : Value(Type::getMetadataTy(C), Value::MDNodeVal) {
116 NumOperands = Vals.size();
119 setValueSubclassData(getSubclassDataFromValue() | FunctionLocalBit);
121 // Initialize the operand list, which is co-allocated on the end of the node.
123 for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands;
124 Op != E; ++Op, ++i) {
125 new (Op) MDNodeOperand(Vals[i]);
127 // Mark the first MDNodeOperand as being the first in the list of operands.
129 Op->setAsFirstOperand(1);
133 /// ~MDNode - Destroy MDNode.
135 assert((getSubclassDataFromValue() & DestroyFlag) != 0 &&
136 "Not being destroyed through destroy()?");
137 LLVMContextImpl *pImpl = getType()->getContext().pImpl;
138 if (isNotUniqued()) {
139 pImpl->NonUniquedMDNodes.erase(this);
141 pImpl->MDNodeSet.RemoveNode(this);
144 // Destroy the operands.
145 for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands;
147 Op->~MDNodeOperand();
150 static const Function *getFunctionForValue(Value *V) {
151 if (!V) return nullptr;
152 if (Instruction *I = dyn_cast<Instruction>(V)) {
153 BasicBlock *BB = I->getParent();
154 return BB ? BB->getParent() : nullptr;
156 if (Argument *A = dyn_cast<Argument>(V))
157 return A->getParent();
158 if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
159 return BB->getParent();
160 if (MDNode *MD = dyn_cast<MDNode>(V))
161 return MD->getFunction();
166 static const Function *assertLocalFunction(const MDNode *N) {
167 if (!N->isFunctionLocal()) return nullptr;
169 // FIXME: This does not handle cyclic function local metadata.
170 const Function *F = nullptr, *NewF = nullptr;
171 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
172 if (Value *V = N->getOperand(i)) {
173 if (MDNode *MD = dyn_cast<MDNode>(V))
174 NewF = assertLocalFunction(MD);
176 NewF = getFunctionForValue(V);
181 assert((NewF == nullptr || F == NewF) &&
182 "inconsistent function-local metadata");
188 // getFunction - If this metadata is function-local and recursively has a
189 // function-local operand, return the first such operand's parent function.
190 // Otherwise, return null. getFunction() should not be used for performance-
191 // critical code because it recursively visits all the MDNode's operands.
192 const Function *MDNode::getFunction() const {
194 return assertLocalFunction(this);
196 if (!isFunctionLocal()) return nullptr;
197 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
198 if (const Function *F = getFunctionForValue(getOperand(i)))
204 // destroy - Delete this node. Only when there are no uses.
205 void MDNode::destroy() {
206 setValueSubclassData(getSubclassDataFromValue() | DestroyFlag);
207 // Placement delete, then free the memory.
212 /// isFunctionLocalValue - Return true if this is a value that would require a
213 /// function-local MDNode.
214 static bool isFunctionLocalValue(Value *V) {
215 return isa<Instruction>(V) || isa<Argument>(V) || isa<BasicBlock>(V) ||
216 (isa<MDNode>(V) && cast<MDNode>(V)->isFunctionLocal());
219 MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef<Value*> Vals,
220 FunctionLocalness FL, bool Insert) {
221 LLVMContextImpl *pImpl = Context.pImpl;
223 // Add all the operand pointers. Note that we don't have to add the
224 // isFunctionLocal bit because that's implied by the operands.
225 // Note that if the operands are later nulled out, the node will be
226 // removed from the uniquing map.
228 for (Value *V : Vals)
232 MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
237 bool isFunctionLocal = false;
240 for (Value *V : Vals) {
242 if (isFunctionLocalValue(V)) {
243 isFunctionLocal = true;
249 isFunctionLocal = false;
252 isFunctionLocal = true;
256 // Coallocate space for the node and Operands together, then placement new.
257 void *Ptr = malloc(sizeof(MDNode) + Vals.size() * sizeof(MDNodeOperand));
258 N = new (Ptr) MDNode(Context, Vals, isFunctionLocal);
260 // Cache the operand hash.
261 N->Hash = ID.ComputeHash();
263 // InsertPoint will have been set by the FindNodeOrInsertPos call.
264 pImpl->MDNodeSet.InsertNode(N, InsertPoint);
269 MDNode *MDNode::get(LLVMContext &Context, ArrayRef<Value*> Vals) {
270 return getMDNode(Context, Vals, FL_Unknown);
273 MDNode *MDNode::getWhenValsUnresolved(LLVMContext &Context,
274 ArrayRef<Value*> Vals,
275 bool isFunctionLocal) {
276 return getMDNode(Context, Vals, isFunctionLocal ? FL_Yes : FL_No);
279 MDNode *MDNode::getIfExists(LLVMContext &Context, ArrayRef<Value*> Vals) {
280 return getMDNode(Context, Vals, FL_Unknown, false);
283 MDNode *MDNode::getTemporary(LLVMContext &Context, ArrayRef<Value*> Vals) {
285 (MDNode *)malloc(sizeof(MDNode) + Vals.size() * sizeof(MDNodeOperand));
286 N = new (N) MDNode(Context, Vals, FL_No);
287 N->setValueSubclassData(N->getSubclassDataFromValue() |
289 LeakDetector::addGarbageObject(N);
293 void MDNode::deleteTemporary(MDNode *N) {
294 assert(N->use_empty() && "Temporary MDNode has uses!");
295 assert(!N->getContext().pImpl->MDNodeSet.RemoveNode(N) &&
296 "Deleting a non-temporary uniqued node!");
297 assert(!N->getContext().pImpl->NonUniquedMDNodes.erase(N) &&
298 "Deleting a non-temporary non-uniqued node!");
299 assert((N->getSubclassDataFromValue() & NotUniquedBit) &&
300 "Temporary MDNode does not have NotUniquedBit set!");
301 assert((N->getSubclassDataFromValue() & DestroyFlag) == 0 &&
302 "Temporary MDNode has DestroyFlag set!");
303 LeakDetector::removeGarbageObject(N);
307 /// getOperand - Return specified operand.
308 Value *MDNode::getOperand(unsigned i) const {
309 assert(i < getNumOperands() && "Invalid operand number");
310 return *getOperandPtr(const_cast<MDNode*>(this), i);
313 void MDNode::Profile(FoldingSetNodeID &ID) const {
314 // Add all the operand pointers. Note that we don't have to add the
315 // isFunctionLocal bit because that's implied by the operands.
316 // Note that if the operands are later nulled out, the node will be
317 // removed from the uniquing map.
318 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
319 ID.AddPointer(getOperand(i));
322 void MDNode::setIsNotUniqued() {
323 setValueSubclassData(getSubclassDataFromValue() | NotUniquedBit);
324 LLVMContextImpl *pImpl = getType()->getContext().pImpl;
325 pImpl->NonUniquedMDNodes.insert(this);
328 // Replace value from this node's operand list.
329 void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
332 // If is possible that someone did GV->RAUW(inst), replacing a global variable
333 // with an instruction or some other function-local object. If this is a
334 // non-function-local MDNode, it can't point to a function-local object.
335 // Handle this case by implicitly dropping the MDNode reference to null.
336 // Likewise if the MDNode is function-local but for a different function.
337 if (To && isFunctionLocalValue(To)) {
338 if (!isFunctionLocal())
341 const Function *F = getFunction();
342 const Function *FV = getFunctionForValue(To);
343 // Metadata can be function-local without having an associated function.
344 // So only consider functions to have changed if non-null.
345 if (F && FV && F != FV)
353 // Update the operand.
356 // If this node is already not being uniqued (because one of the operands
357 // already went to null), then there is nothing else to do here.
358 if (isNotUniqued()) return;
360 LLVMContextImpl *pImpl = getType()->getContext().pImpl;
362 // Remove "this" from the context map. FoldingSet doesn't have to reprofile
363 // this node to remove it, so we don't care what state the operands are in.
364 pImpl->MDNodeSet.RemoveNode(this);
366 // If we are dropping an argument to null, we choose to not unique the MDNode
367 // anymore. This commonly occurs during destruction, and uniquing these
368 // brings little reuse. Also, this means we don't need to include
369 // isFunctionLocal bits in FoldingSetNodeIDs for MDNodes.
375 // Now that the node is out of the folding set, get ready to reinsert it.
376 // First, check to see if another node with the same operands already exists
377 // in the set. If so, then this node is redundant.
381 if (MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint)) {
382 replaceAllUsesWith(N);
387 // Cache the operand hash.
388 Hash = ID.ComputeHash();
389 // InsertPoint will have been set by the FindNodeOrInsertPos call.
390 pImpl->MDNodeSet.InsertNode(this, InsertPoint);
392 // If this MDValue was previously function-local but no longer is, clear
393 // its function-local flag.
394 if (isFunctionLocal() && !isFunctionLocalValue(To)) {
395 bool isStillFunctionLocal = false;
396 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
397 Value *V = getOperand(i);
399 if (isFunctionLocalValue(V)) {
400 isStillFunctionLocal = true;
404 if (!isStillFunctionLocal)
405 setValueSubclassData(getSubclassDataFromValue() & ~FunctionLocalBit);
409 MDNode *MDNode::getMostGenericFPMath(MDNode *A, MDNode *B) {
413 APFloat AVal = cast<ConstantFP>(A->getOperand(0))->getValueAPF();
414 APFloat BVal = cast<ConstantFP>(B->getOperand(0))->getValueAPF();
415 if (AVal.compare(BVal) == APFloat::cmpLessThan)
420 static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
421 return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
424 static bool canBeMerged(const ConstantRange &A, const ConstantRange &B) {
425 return !A.intersectWith(B).isEmptySet() || isContiguous(A, B);
428 static bool tryMergeRange(SmallVectorImpl<Value *> &EndPoints, ConstantInt *Low,
430 ConstantRange NewRange(Low->getValue(), High->getValue());
431 unsigned Size = EndPoints.size();
432 APInt LB = cast<ConstantInt>(EndPoints[Size - 2])->getValue();
433 APInt LE = cast<ConstantInt>(EndPoints[Size - 1])->getValue();
434 ConstantRange LastRange(LB, LE);
435 if (canBeMerged(NewRange, LastRange)) {
436 ConstantRange Union = LastRange.unionWith(NewRange);
437 Type *Ty = High->getType();
438 EndPoints[Size - 2] = ConstantInt::get(Ty, Union.getLower());
439 EndPoints[Size - 1] = ConstantInt::get(Ty, Union.getUpper());
445 static void addRange(SmallVectorImpl<Value *> &EndPoints, ConstantInt *Low,
447 if (!EndPoints.empty())
448 if (tryMergeRange(EndPoints, Low, High))
451 EndPoints.push_back(Low);
452 EndPoints.push_back(High);
455 MDNode *MDNode::getMostGenericRange(MDNode *A, MDNode *B) {
456 // Given two ranges, we want to compute the union of the ranges. This
457 // is slightly complitade by having to combine the intervals and merge
458 // the ones that overlap.
466 // First, walk both lists in older of the lower boundary of each interval.
467 // At each step, try to merge the new interval to the last one we adedd.
468 SmallVector<Value*, 4> EndPoints;
471 int AN = A->getNumOperands() / 2;
472 int BN = B->getNumOperands() / 2;
473 while (AI < AN && BI < BN) {
474 ConstantInt *ALow = cast<ConstantInt>(A->getOperand(2 * AI));
475 ConstantInt *BLow = cast<ConstantInt>(B->getOperand(2 * BI));
477 if (ALow->getValue().slt(BLow->getValue())) {
478 addRange(EndPoints, ALow, cast<ConstantInt>(A->getOperand(2 * AI + 1)));
481 addRange(EndPoints, BLow, cast<ConstantInt>(B->getOperand(2 * BI + 1)));
486 addRange(EndPoints, cast<ConstantInt>(A->getOperand(2 * AI)),
487 cast<ConstantInt>(A->getOperand(2 * AI + 1)));
491 addRange(EndPoints, cast<ConstantInt>(B->getOperand(2 * BI)),
492 cast<ConstantInt>(B->getOperand(2 * BI + 1)));
496 // If we have more than 2 ranges (4 endpoints) we have to try to merge
497 // the last and first ones.
498 unsigned Size = EndPoints.size();
500 ConstantInt *FB = cast<ConstantInt>(EndPoints[0]);
501 ConstantInt *FE = cast<ConstantInt>(EndPoints[1]);
502 if (tryMergeRange(EndPoints, FB, FE)) {
503 for (unsigned i = 0; i < Size - 2; ++i) {
504 EndPoints[i] = EndPoints[i + 2];
506 EndPoints.resize(Size - 2);
510 // If in the end we have a single range, it is possible that it is now the
511 // full range. Just drop the metadata in that case.
512 if (EndPoints.size() == 2) {
513 ConstantRange Range(cast<ConstantInt>(EndPoints[0])->getValue(),
514 cast<ConstantInt>(EndPoints[1])->getValue());
515 if (Range.isFullSet())
519 return MDNode::get(A->getContext(), EndPoints);
522 //===----------------------------------------------------------------------===//
523 // NamedMDNode implementation.
526 static SmallVector<TrackingVH<MDNode>, 4> &getNMDOps(void *Operands) {
527 return *(SmallVector<TrackingVH<MDNode>, 4>*)Operands;
530 NamedMDNode::NamedMDNode(const Twine &N)
531 : Name(N.str()), Parent(nullptr),
532 Operands(new SmallVector<TrackingVH<MDNode>, 4>()) {
535 NamedMDNode::~NamedMDNode() {
537 delete &getNMDOps(Operands);
540 /// getNumOperands - Return number of NamedMDNode operands.
541 unsigned NamedMDNode::getNumOperands() const {
542 return (unsigned)getNMDOps(Operands).size();
545 /// getOperand - Return specified operand.
546 MDNode *NamedMDNode::getOperand(unsigned i) const {
547 assert(i < getNumOperands() && "Invalid Operand number!");
548 return dyn_cast<MDNode>(&*getNMDOps(Operands)[i]);
551 /// addOperand - Add metadata Operand.
552 void NamedMDNode::addOperand(MDNode *M) {
553 assert(!M->isFunctionLocal() &&
554 "NamedMDNode operands must not be function-local!");
555 getNMDOps(Operands).push_back(TrackingVH<MDNode>(M));
558 /// eraseFromParent - Drop all references and remove the node from parent
560 void NamedMDNode::eraseFromParent() {
561 getParent()->eraseNamedMetadata(this);
564 /// dropAllReferences - Remove all uses and clear node vector.
565 void NamedMDNode::dropAllReferences() {
566 getNMDOps(Operands).clear();
569 /// getName - Return a constant reference to this named metadata's name.
570 StringRef NamedMDNode::getName() const {
571 return StringRef(Name);
574 //===----------------------------------------------------------------------===//
575 // Instruction Metadata method implementations.
578 void Instruction::setMetadata(StringRef Kind, MDNode *Node) {
579 if (!Node && !hasMetadata()) return;
580 setMetadata(getContext().getMDKindID(Kind), Node);
583 MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
584 return getMetadataImpl(getContext().getMDKindID(Kind));
587 void Instruction::dropUnknownMetadata(ArrayRef<unsigned> KnownIDs) {
588 SmallSet<unsigned, 5> KnownSet;
589 KnownSet.insert(KnownIDs.begin(), KnownIDs.end());
591 // Drop debug if needed
592 if (KnownSet.erase(LLVMContext::MD_dbg))
595 if (!hasMetadataHashEntry())
596 return; // Nothing to remove!
598 DenseMap<const Instruction *, LLVMContextImpl::MDMapTy> &MetadataStore =
599 getContext().pImpl->MetadataStore;
601 if (KnownSet.empty()) {
602 // Just drop our entry at the store.
603 MetadataStore.erase(this);
604 setHasMetadataHashEntry(false);
608 LLVMContextImpl::MDMapTy &Info = MetadataStore[this];
611 // Walk the array and drop any metadata we don't know.
612 for (I = 0, E = Info.size(); I != E;) {
613 if (KnownSet.count(Info[I].first)) {
618 Info[I] = Info.back();
622 assert(E == Info.size());
625 // Drop our entry at the store.
626 MetadataStore.erase(this);
627 setHasMetadataHashEntry(false);
631 /// setMetadata - Set the metadata of of the specified kind to the specified
632 /// node. This updates/replaces metadata if already present, or removes it if
634 void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
635 if (!Node && !hasMetadata()) return;
637 // Handle 'dbg' as a special case since it is not stored in the hash table.
638 if (KindID == LLVMContext::MD_dbg) {
639 DbgLoc = DebugLoc::getFromDILocation(Node);
643 // Handle the case when we're adding/updating metadata on an instruction.
645 LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
646 assert(!Info.empty() == hasMetadataHashEntry() &&
647 "HasMetadata bit is wonked");
649 setHasMetadataHashEntry(true);
651 // Handle replacement of an existing value.
653 if (P.first == KindID) {
659 // No replacement, just add it to the list.
660 Info.push_back(std::make_pair(KindID, Node));
664 // Otherwise, we're removing metadata from an instruction.
665 assert((hasMetadataHashEntry() ==
666 (getContext().pImpl->MetadataStore.count(this) > 0)) &&
667 "HasMetadata bit out of date!");
668 if (!hasMetadataHashEntry())
669 return; // Nothing to remove!
670 LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
672 // Common case is removing the only entry.
673 if (Info.size() == 1 && Info[0].first == KindID) {
674 getContext().pImpl->MetadataStore.erase(this);
675 setHasMetadataHashEntry(false);
679 // Handle removal of an existing value.
680 for (unsigned i = 0, e = Info.size(); i != e; ++i)
681 if (Info[i].first == KindID) {
682 Info[i] = Info.back();
684 assert(!Info.empty() && "Removing last entry should be handled above");
687 // Otherwise, removing an entry that doesn't exist on the instruction.
690 void Instruction::setAAMetadata(const AAMDNodes &N) {
691 setMetadata(LLVMContext::MD_tbaa, N.TBAA);
694 MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
695 // Handle 'dbg' as a special case since it is not stored in the hash table.
696 if (KindID == LLVMContext::MD_dbg)
697 return DbgLoc.getAsMDNode(getContext());
699 if (!hasMetadataHashEntry()) return nullptr;
701 LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
702 assert(!Info.empty() && "bit out of sync with hash table");
704 for (const auto &I : Info)
705 if (I.first == KindID)
710 void Instruction::getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,
711 MDNode*> > &Result) const {
714 // Handle 'dbg' as a special case since it is not stored in the hash table.
715 if (!DbgLoc.isUnknown()) {
716 Result.push_back(std::make_pair((unsigned)LLVMContext::MD_dbg,
717 DbgLoc.getAsMDNode(getContext())));
718 if (!hasMetadataHashEntry()) return;
721 assert(hasMetadataHashEntry() &&
722 getContext().pImpl->MetadataStore.count(this) &&
723 "Shouldn't have called this");
724 const LLVMContextImpl::MDMapTy &Info =
725 getContext().pImpl->MetadataStore.find(this)->second;
726 assert(!Info.empty() && "Shouldn't have called this");
728 Result.append(Info.begin(), Info.end());
730 // Sort the resulting array so it is stable.
731 if (Result.size() > 1)
732 array_pod_sort(Result.begin(), Result.end());
736 getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl<std::pair<unsigned,
737 MDNode*> > &Result) const {
739 assert(hasMetadataHashEntry() &&
740 getContext().pImpl->MetadataStore.count(this) &&
741 "Shouldn't have called this");
742 const LLVMContextImpl::MDMapTy &Info =
743 getContext().pImpl->MetadataStore.find(this)->second;
744 assert(!Info.empty() && "Shouldn't have called this");
745 Result.append(Info.begin(), Info.end());
747 // Sort the resulting array so it is stable.
748 if (Result.size() > 1)
749 array_pod_sort(Result.begin(), Result.end());
752 /// clearMetadataHashEntries - Clear all hashtable-based metadata from
753 /// this instruction.
754 void Instruction::clearMetadataHashEntries() {
755 assert(hasMetadataHashEntry() && "Caller should check");
756 getContext().pImpl->MetadataStore.erase(this);
757 setHasMetadataHashEntry(false);