LLVM 24.0.0git
Metadata.cpp
Go to the documentation of this file.
1//===- Metadata.cpp - Implement Metadata classes --------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Metadata classes.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Metadata.h"
14#include "LLVMContextImpl.h"
15#include "MetadataImpl.h"
16#include "llvm/ADT/APFloat.h"
17#include "llvm/ADT/APInt.h"
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/DenseSet.h"
20#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/SetVector.h"
23#include "llvm/ADT/SmallSet.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/ADT/Twine.h"
29#include "llvm/IR/Argument.h"
30#include "llvm/IR/BasicBlock.h"
31#include "llvm/IR/Constant.h"
34#include "llvm/IR/Constants.h"
36#include "llvm/IR/DebugLoc.h"
38#include "llvm/IR/Function.h"
41#include "llvm/IR/Instruction.h"
42#include "llvm/IR/LLVMContext.h"
43#include "llvm/IR/MDBuilder.h"
44#include "llvm/IR/Module.h"
47#include "llvm/IR/Type.h"
48#include "llvm/IR/Value.h"
51
54#include "llvm/Support/ModRef.h"
55#include <cassert>
56#include <cstddef>
57#include <cstdint>
58#include <type_traits>
59#include <utility>
60#include <vector>
61
62using namespace llvm;
63
64MetadataAsValue::MetadataAsValue(Type *Ty, Metadata *MD)
65 : Value(Ty, MetadataAsValueVal), MD(MD) {
66 track();
67}
68
73
74/// Canonicalize metadata arguments to intrinsics.
75///
76/// To support bitcode upgrades (and assembly semantic sugar) for \a
77/// MetadataAsValue, we need to canonicalize certain metadata.
78///
79/// - nullptr is replaced by an empty MDNode.
80/// - An MDNode with a single null operand is replaced by an empty MDNode.
81/// - An MDNode whose only operand is a \a ConstantAsMetadata gets skipped.
82///
83/// This maintains readability of bitcode from when metadata was a type of
84/// value, and these bridges were unnecessary.
86 Metadata *MD) {
87 if (!MD)
88 // !{}
89 return MDNode::get(Context, {});
90
91 // Return early if this isn't a single-operand MDNode.
92 auto *N = dyn_cast<MDNode>(MD);
93 if (!N || N->getNumOperands() != 1)
94 return MD;
95
96 if (!N->getOperand(0))
97 // !{}
98 return MDNode::get(Context, {});
99
100 if (auto *C = dyn_cast<ConstantAsMetadata>(N->getOperand(0)))
101 // Look through the MDNode.
102 return C;
103
104 return MD;
105}
106
107MetadataAsValue *MetadataAsValue::get(LLVMContext &Context, Metadata *MD) {
108 MD = canonicalizeMetadataForValue(Context, MD);
109 auto *&Entry = Context.pImpl->MetadataAsValues[MD];
110 if (!Entry)
111 Entry = new MetadataAsValue(Type::getMetadataTy(Context), MD);
112 return Entry;
113}
114
116 Metadata *MD) {
117 MD = canonicalizeMetadataForValue(Context, MD);
118 auto &Store = Context.pImpl->MetadataAsValues;
119 return Store.lookup(MD);
120}
121
122void MetadataAsValue::handleChangedMetadata(Metadata *MD) {
123 LLVMContext &Context = getContext();
124 MD = canonicalizeMetadataForValue(Context, MD);
125 auto &Store = Context.pImpl->MetadataAsValues;
126
127 // Stop tracking the old metadata.
128 Store.erase(this->MD);
129 untrack();
130 this->MD = nullptr;
131
132 // Start tracking MD, or RAUW if necessary.
133 auto *&Entry = Store[MD];
134 if (Entry) {
135 replaceAllUsesWith(Entry);
136 delete this;
137 return;
138 }
139
140 this->MD = MD;
141 track();
142 Entry = this;
143}
144
145void MetadataAsValue::track() {
146 if (MD)
147 MetadataTracking::track(&MD, *MD, *this);
148}
149
150void MetadataAsValue::untrack() {
151 if (MD)
153}
154
156 return static_cast<DbgVariableRecord *>(this);
157}
159 return static_cast<const DbgVariableRecord *>(this);
160}
161
163 // NOTE: We could inform the "owner" that a value has changed through
164 // getOwner, if needed.
165 auto OldMD = static_cast<Metadata **>(Old);
166 ptrdiff_t Idx = std::distance(&*DebugValues.begin(), OldMD);
167 // If replacing a ValueAsMetadata with a nullptr, replace it with a
168 // PoisonValue instead.
169 if (OldMD && isa<ValueAsMetadata>(*OldMD) && !New) {
170 auto *OldVAM = cast<ValueAsMetadata>(*OldMD);
171 New = ValueAsMetadata::get(PoisonValue::get(OldVAM->getValue()->getType()));
172 }
173 resetDebugValue(Idx, New);
174}
175
176void DebugValueUser::trackDebugValue(size_t Idx) {
177 assert(Idx < 3 && "Invalid debug value index.");
178 Metadata *&MD = DebugValues[Idx];
179 if (!MD)
180 return;
181 MetadataTracking::track(&MD, *MD, *this);
182 if (auto *ID = Idx == AssignIDIdx ? dyn_cast<DIAssignID>(MD) : nullptr)
183 ID->Records.push_back(getUser());
184}
185
186void DebugValueUser::trackDebugValues() {
187 for (size_t I = 0, E = DebugValues.size(); I != E; ++I)
188 trackDebugValue(I);
189}
190
191void DebugValueUser::untrackDebugValue(size_t Idx) {
192 assert(Idx < 3 && "Invalid debug value index.");
193 Metadata *&MD = DebugValues[Idx];
194 if (!MD)
195 return;
197 if (auto *ID = Idx == AssignIDIdx ? dyn_cast<DIAssignID>(MD) : nullptr)
198 ID->Records.erase(llvm::find(ID->Records, getUser()));
199}
200
201void DebugValueUser::untrackDebugValues() {
202 for (size_t I = 0, E = DebugValues.size(); I != E; ++I)
203 untrackDebugValue(I);
204}
205
206void DebugValueUser::retrackDebugValues(DebugValueUser &X) {
207 assert(DebugValueUser::operator==(X) && "Expected values to match");
208 for (const auto &[MD, XMD] : zip(DebugValues, X.DebugValues))
209 if (XMD)
212 *llvm::find(ID->Records, X.getUser()) = getUser();
213 X.DebugValues.fill(nullptr);
214}
215
216bool MetadataTracking::track(void *Ref, Metadata &MD, OwnerTy Owner) {
217 assert(Ref && "Expected live reference");
218 assert((Owner || *static_cast<Metadata **>(Ref) == &MD) &&
219 "Reference without owner must be direct");
220 if (auto *R = ReplaceableUses::getOrCreate(MD)) {
221 R->addRef(Ref, Owner);
222 return true;
223 }
224 if (auto *PH = dyn_cast<DistinctMDOperandPlaceholder>(&MD)) {
225 assert(!PH->Use && "Placeholders can only be used once");
226 assert(!Owner && "Unexpected callback to owner");
227 PH->Use = static_cast<Metadata **>(Ref);
228 return true;
229 }
230 return false;
231}
232
234 assert(Ref && "Expected live reference");
235 if (auto *R = ReplaceableUses::getIfExists(MD))
236 R->dropRef(Ref);
237 else if (auto *PH = dyn_cast<DistinctMDOperandPlaceholder>(&MD))
238 PH->Use = nullptr;
239}
240
241bool MetadataTracking::retrack(void *Ref, Metadata &MD, void *New) {
242 assert(Ref && "Expected live reference");
243 assert(New && "Expected live reference");
244 assert(Ref != New && "Expected change");
245 if (auto *R = ReplaceableUses::getIfExists(MD)) {
246 R->moveRef(Ref, New, MD);
247 return true;
248 }
250 "Unexpected move of an MDOperand");
251 assert(!isReplaceable(MD) &&
252 "Expected un-replaceable metadata, since we didn't move a reference");
253 return false;
254}
255
257 return ReplaceableUses::isReplaceable(MD);
258}
259
262 for (auto Pair : UseMap) {
263 OwnerTy Owner = Pair.second.first;
264 if (Owner.isNull())
265 continue;
267 continue;
268 Metadata *OwnerMD = cast<Metadata *>(Owner);
269 if (OwnerMD->getMetadataID() == Metadata::DIArgListKind)
270 MDUsersWithID.push_back(&UseMap[Pair.first]);
271 }
272 llvm::sort(MDUsersWithID, [](auto UserA, auto UserB) {
273 return UserA->second < UserB->second;
274 });
276 for (auto *UserWithID : MDUsersWithID)
277 MDUsers.push_back(cast<Metadata *>(UserWithID->first));
278 return MDUsers;
279}
280
284 for (auto Pair : UseMap) {
285 OwnerTy Owner = Pair.second.first;
286 if (Owner.isNull())
287 continue;
289 continue;
290 DVRUsersWithID.push_back(&UseMap[Pair.first]);
291 }
292 // Order DbgVariableRecord users in reverse-creation order. Normal dbg.value
293 // users of MetadataAsValues are ordered by their UseList, i.e. reverse order
294 // of when they were added: we need to replicate that here. The structure of
295 // debug-info output depends on the ordering of intrinsics, thus we need
296 // to keep them consistent for comparisons sake.
297 llvm::sort(DVRUsersWithID, [](auto UserA, auto UserB) {
298 return UserA->second > UserB->second;
299 });
301 for (auto UserWithID : DVRUsersWithID)
302 DVRUsers.push_back(cast<DebugValueUser *>(UserWithID->first)->getUser());
303 return DVRUsers;
304}
305
306void ReplaceableUses::addRef(void *Ref, OwnerTy Owner) {
307 bool WasInserted =
308 UseMap.insert(std::make_pair(Ref, std::make_pair(Owner, NextIndex)))
309 .second;
310 (void)WasInserted;
311 assert(WasInserted && "Expected to add a reference");
312
313 ++NextIndex;
314 assert(NextIndex != 0 && "Unexpected overflow");
315}
316
317void ReplaceableUses::dropRef(void *Ref) {
318 bool WasErased = UseMap.erase(Ref);
319 (void)WasErased;
320 assert(WasErased && "Expected to drop a reference");
321}
322
323void ReplaceableUses::moveRef(void *Ref, void *New, const Metadata &MD) {
324 auto I = UseMap.find(Ref);
325 assert(I != UseMap.end() && "Expected to move a reference");
326 auto OwnerAndIndex = I->second;
327 UseMap.erase(I);
328 bool WasInserted = UseMap.insert(std::make_pair(New, OwnerAndIndex)).second;
329 (void)WasInserted;
330 assert(WasInserted && "Expected to add a reference");
331
332 // Check that the references are direct if there's no owner.
333 (void)MD;
334 assert((OwnerAndIndex.first || *static_cast<Metadata **>(Ref) == &MD) &&
335 "Reference without owner must be direct");
336 assert((OwnerAndIndex.first || *static_cast<Metadata **>(New) == &MD) &&
337 "Reference without owner must be direct");
338}
339
341 if (!C.isUsedByMetadata()) {
342 return;
343 }
344
345 LLVMContext &Context = C.getType()->getContext();
346 auto &Store = Context.pImpl->ValuesAsMetadata;
347 auto I = Store.find(&C);
348 ValueAsMetadata *MD = I->second;
349 using UseTy =
350 std::pair<void *, std::pair<MetadataTracking::OwnerTy, uint64_t>>;
351 // Copy out uses and update value of Constant used by debug info metadata with
352 // poison below
353 SmallVector<UseTy, 8> Uses(MD->UseMap.begin(), MD->UseMap.end());
354
355 for (const auto &Pair : Uses) {
356 MetadataTracking::OwnerTy Owner = Pair.second.first;
357 if (!Owner)
358 continue;
359 // Check for MetadataAsValue.
361 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(
363 continue;
364 }
366 continue;
368 if (!OwnerMD)
369 continue;
370 if (isa<DINode>(OwnerMD)) {
371 OwnerMD->handleChangedOperand(
372 Pair.first, ValueAsMetadata::get(PoisonValue::get(C.getType())));
373 }
374 }
375}
376
378 if (UseMap.empty())
379 return;
380
381 // Copy out uses since UseMap will get touched below.
382 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
383 SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end());
384 llvm::sort(Uses, [](const UseTy &L, const UseTy &R) {
385 return L.second.second < R.second.second;
386 });
387 for (const auto &Pair : Uses) {
388 // Check that this Ref hasn't disappeared after RAUW (when updating a
389 // previous Ref).
390 if (!UseMap.count(Pair.first))
391 continue;
392
393 OwnerTy Owner = Pair.second.first;
394 if (!Owner) {
395 // Update unowned tracking references directly.
396 Metadata *&Ref = *static_cast<Metadata **>(Pair.first);
397 Ref = MD;
398 if (MD)
400 UseMap.erase(Pair.first);
401 continue;
402 }
403
404 // Check for MetadataAsValue.
406 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(MD);
407 continue;
408 }
409
410 if (auto *DVU = dyn_cast<DebugValueUser *>(Owner)) {
411 DVU->handleChangedValue(Pair.first, MD);
412 continue;
413 }
414
415 // There's a Metadata owner -- dispatch.
416 Metadata *OwnerMD = cast<Metadata *>(Owner);
417 switch (OwnerMD->getMetadataID()) {
418#define HANDLE_METADATA_LEAF(CLASS) \
419 case Metadata::CLASS##Kind: \
420 cast<CLASS>(OwnerMD)->handleChangedOperand(Pair.first, MD); \
421 continue;
422#include "llvm/IR/Metadata.def"
423 default:
424 llvm_unreachable("Invalid metadata subclass");
425 }
426 }
427 assert(UseMap.empty() && "Expected all uses to be replaced");
428}
429
430void ReplaceableUses::resolveAllUses(bool ResolveUsers) {
431 if (UseMap.empty())
432 return;
433
434 if (!ResolveUsers) {
435 UseMap.clear();
436 return;
437 }
438
439 // Copy out uses since UseMap could get touched below.
440 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
441 SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end());
442 llvm::sort(Uses, [](const UseTy &L, const UseTy &R) {
443 return L.second.second < R.second.second;
444 });
445 UseMap.clear();
446 for (const auto &Pair : Uses) {
447 auto Owner = Pair.second.first;
448 if (!Owner)
449 continue;
451 continue;
452
453 // Resolve MDNodes that point at this.
455 if (!OwnerMD)
456 continue;
457 if (OwnerMD->isResolved())
458 continue;
459 OwnerMD->decrementUnresolvedOperandCount();
460 }
461}
462
463// A value without a use list (e.g. ConstantData) is never RAUW'd, so don't
464// create a ReplaceableUses instance for it.
465static bool isTrackedValue(const Metadata &MD) {
466 auto *VAM = dyn_cast<ValueAsMetadata>(&MD);
467 return VAM && VAM->getValue()->hasUseList();
468}
469
470// Special handing of DIArgList is required in the RemoveDIs project, see
471// commentry in DIArgList::handleChangedOperand for details. Hidden behind
472// conditional compilation to avoid a compile time regression.
473ReplaceableUses *ReplaceableUses::getOrCreate(Metadata &MD) {
474 if (auto *N = dyn_cast<MDNode>(&MD)) {
475 return N->isResolved() ? nullptr : N->Context.getOrCreateReplaceableUses();
476 }
477 if (auto ArgList = dyn_cast<DIArgList>(&MD))
478 return ArgList;
479 return isTrackedValue(MD) ? cast<ValueAsMetadata>(&MD) : nullptr;
480}
481
482ReplaceableUses *ReplaceableUses::getIfExists(Metadata &MD) {
483 if (auto *N = dyn_cast<MDNode>(&MD)) {
484 return N->isResolved() ? nullptr : N->Context.getReplaceableUses();
485 }
486 if (auto ArgList = dyn_cast<DIArgList>(&MD))
487 return ArgList;
488 return isTrackedValue(MD) ? cast<ValueAsMetadata>(&MD) : nullptr;
489}
490
491bool ReplaceableUses::isReplaceable(const Metadata &MD) {
492 if (auto *N = dyn_cast<MDNode>(&MD))
493 return !N->isResolved();
494 return isTrackedValue(MD) || isa<DIArgList>(&MD);
495}
496
498 assert(V && "Expected value");
499 if (auto *A = dyn_cast<Argument>(V)) {
500 if (auto *Fn = A->getParent())
501 return Fn->getSubprogram();
502 return nullptr;
503 }
504
505 if (BasicBlock *BB = cast<Instruction>(V)->getParent()) {
506 if (auto *Fn = BB->getParent())
507 return Fn->getSubprogram();
508 return nullptr;
509 }
510
511 return nullptr;
512}
513
515 assert(V && "Unexpected null Value");
516
517 auto &Context = V->getContext();
518 auto *&Entry = Context.pImpl->ValuesAsMetadata[V];
519 if (!Entry) {
521 "Expected constant or function-local value");
522 assert(!V->IsUsedByMD && "Expected this to be the only metadata use");
523 V->IsUsedByMD = true;
524 if (auto *C = dyn_cast<Constant>(V))
525 Entry = new ConstantAsMetadata(C);
526 else
527 Entry = new LocalAsMetadata(V);
528 }
529
530 return Entry;
531}
532
534 assert(V && "Unexpected null Value");
535 return V->getContext().pImpl->ValuesAsMetadata.lookup(V);
536}
537
539 assert(V && "Expected valid value");
540
541 auto &Store = V->getType()->getContext().pImpl->ValuesAsMetadata;
542 auto I = Store.find(V);
543 if (I == Store.end())
544 return;
545
546 // Remove old entry from the map.
547 ValueAsMetadata *MD = I->second;
548 assert(MD && "Expected valid metadata");
549 assert(MD->getValue() == V && "Expected valid mapping");
550 Store.erase(I);
551
552 // Delete the metadata.
553 MD->replaceAllUsesWith(nullptr);
554 delete MD;
555}
556
558 assert(From && "Expected valid value");
559 assert(To && "Expected valid value");
560 assert(From != To && "Expected changed value");
561 assert(&From->getContext() == &To->getContext() && "Expected same context");
562 assert(From->hasUseList() && "Must have use list");
563
564 auto &Store = From->getContext().pImpl->ValuesAsMetadata;
565 auto I = Store.find(From);
566 if (I == Store.end()) {
567 assert(!From->IsUsedByMD && "Expected From not to be used by metadata");
568 return;
569 }
570
571 assert(From->IsUsedByMD && "Expected From to be used by metadata");
572 From->IsUsedByMD = false;
573 ValueAsMetadata *MD = I->second;
574 assert(MD && "Expected valid metadata");
575 assert(MD->getValue() == From && "Expected valid mapping");
576 Store.erase(I);
577
578 // Move the uses to To's node. Uses of a function-local value are dropped if
579 // it becomes a local of another function or replaces a constant.
580 Metadata *New = nullptr;
581 if (isa<Constant>(To)) {
582 New = ValueAsMetadata::get(To);
583 } else if (isa<LocalAsMetadata>(MD)) {
585 DISubprogram *ToSP = FromSP ? getLocalFunctionMetadata(To) : nullptr;
586 if (!FromSP || !ToSP || FromSP == ToSP)
587 New = ValueAsMetadata::get(To);
590 delete MD;
591}
592
593//===----------------------------------------------------------------------===//
594// MDString implementation.
596
597MDString *MDString::get(LLVMContext &Context, StringRef Str) {
598 auto &Store = Context.pImpl->MDStringCache;
599 auto I = Store.try_emplace(Str);
600 auto &MapEntry = I.first->getValue();
601 if (!I.second)
602 return &MapEntry;
603 MapEntry.Entry = &*I.first;
604 return &MapEntry;
605}
606
608 auto &Store = Context.pImpl->MDStringCache;
609 auto I = Store.find(Str);
610 if (I == Store.end())
611 return nullptr;
612 return &I->getValue();
613}
614
616 assert(Entry && "Expected to find string map entry");
617 return Entry->first();
618}
619
620//===----------------------------------------------------------------------===//
621// MDNode implementation.
622//
623
624// Assert that the MDNode types will not be unaligned by the objects
625// prepended to them.
626#define HANDLE_MDNODE_LEAF(CLASS) \
627 static_assert( \
628 alignof(uint64_t) >= alignof(CLASS), \
629 "Alignment is insufficient after objects prepended to " #CLASS);
630#include "llvm/IR/Metadata.def"
631
632void *MDNode::operator new(size_t Size, size_t NumOps, StorageType Storage) {
633 // uint64_t is the most aligned type we need support (ensured by static_assert
634 // above)
635 static_assert(sizeof(Header) == sizeof(size_t) + 2 * sizeof(uint32_t),
636 "MDNode header fields poorly packed");
637 size_t AllocSize =
638 alignTo(Header::getAllocSize(Storage, NumOps), alignof(uint64_t));
639 char *Mem = reinterpret_cast<char *>(::operator new(AllocSize + Size));
640 Header *H = new (Mem + AllocSize - sizeof(Header)) Header(NumOps, Storage);
641 return reinterpret_cast<void *>(H + 1);
642}
643
644void MDNode::operator delete(void *N) {
645 Header *H = reinterpret_cast<Header *>(N) - 1;
646 void *Mem = H->getAllocation();
647 H->~Header();
648 ::operator delete(Mem);
649}
650
653 : Metadata(ID, Storage), Context(Context) {
654 getHeader().MetadataPrintID = Context.pImpl->allocateMetadataPrintID();
655
656 unsigned Op = 0;
657 for (Metadata *MD : Ops1)
658 setOperand(Op++, MD);
659 for (Metadata *MD : Ops2)
660 setOperand(Op++, MD);
661
662 if (!isUniqued())
663 return;
664
665 // Count the unresolved operands. If there are any, RAUW support will be
666 // added lazily on first reference.
667 countUnresolvedOperands();
668}
669
670TempMDNode MDNode::clone() const {
671 switch (getMetadataID()) {
672 default:
673 llvm_unreachable("Invalid MDNode subclass");
674#define HANDLE_MDNODE_LEAF(CLASS) \
675 case CLASS##Kind: \
676 return cast<CLASS>(this)->cloneImpl();
677#include "llvm/IR/Metadata.def"
678 }
679}
680
681MDNode::Header::Header(size_t NumOps, StorageType Storage) {
682 IsLarge = isLarge(NumOps);
683 IsResizable = isResizable(Storage);
684 SmallSize = getSmallSize(NumOps, IsResizable, IsLarge);
685 if (IsLarge) {
686 SmallNumOps = 0;
687 new (getLargePtr()) LargeStorageVector();
688 getLarge().resize(NumOps);
689 return;
690 }
691 SmallNumOps = NumOps;
692 MDOperand *O = reinterpret_cast<MDOperand *>(this) - SmallSize;
693 for (MDOperand *E = O + SmallSize; O != E;)
694 (void)new (O++) MDOperand();
695}
696
697MDNode::Header::~Header() {
698 if (IsLarge) {
699 getLarge().~LargeStorageVector();
700 return;
701 }
702 MDOperand *O = reinterpret_cast<MDOperand *>(this);
703 for (MDOperand *E = O - SmallSize; O != E; --O)
704 (O - 1)->~MDOperand();
705}
706
707void *MDNode::Header::getSmallPtr() {
708 static_assert(alignof(MDOperand) <= alignof(Header),
709 "MDOperand too strongly aligned");
710 return reinterpret_cast<char *>(const_cast<Header *>(this)) -
711 sizeof(MDOperand) * SmallSize;
712}
713
714void MDNode::Header::resize(size_t NumOps) {
715 assert(IsResizable && "Node is not resizable");
716 if (operands().size() == NumOps)
717 return;
718
719 if (IsLarge)
720 getLarge().resize(NumOps);
721 else if (NumOps <= SmallSize)
722 resizeSmall(NumOps);
723 else
724 resizeSmallToLarge(NumOps);
725}
726
727void MDNode::Header::resizeSmall(size_t NumOps) {
728 assert(!IsLarge && "Expected a small MDNode");
729 assert(NumOps <= SmallSize && "NumOps too large for small resize");
730
731 MutableArrayRef<MDOperand> ExistingOps = operands();
732 assert(NumOps != ExistingOps.size() && "Expected a different size");
733
734 int NumNew = (int)NumOps - (int)ExistingOps.size();
735 MDOperand *O = ExistingOps.end();
736 for (int I = 0, E = NumNew; I < E; ++I)
737 (O++)->reset();
738 for (int I = 0, E = NumNew; I > E; --I)
739 (--O)->reset();
740 SmallNumOps = NumOps;
741 assert(O == operands().end() && "Operands not (un)initialized until the end");
742}
743
744void MDNode::Header::resizeSmallToLarge(size_t NumOps) {
745 assert(!IsLarge && "Expected a small MDNode");
746 assert(NumOps > SmallSize && "Expected NumOps to be larger than allocation");
747 LargeStorageVector NewOps;
748 NewOps.resize(NumOps);
749 llvm::move(operands(), NewOps.begin());
750 resizeSmall(0);
751 new (getLargePtr()) LargeStorageVector(std::move(NewOps));
752 IsLarge = true;
753}
754
756 if (auto *N = dyn_cast_or_null<MDNode>(Op))
757 return !N->isResolved();
758 return false;
759}
760
761void MDNode::countUnresolvedOperands() {
762 assert(getNumUnresolved() == 0 && "Expected unresolved ops to be uncounted");
763 assert(isUniqued() && "Expected this to be uniqued");
765}
766
767void MDNode::makeUniqued() {
768 assert(isTemporary() && "Expected this to be temporary");
769 assert(!isResolved() && "Expected this to be unresolved");
770 bool WasTracked = getContext().pImpl->TemporaryMDNodes.erase(this);
771 assert(WasTracked && "Temporary node not tracked");
772 (void)WasTracked;
773
774 // Enable uniquing callbacks.
775 for (auto &Op : mutable_operands())
776 Op.reset(Op.get(), this);
777
778 // Make this 'uniqued'.
780 countUnresolvedOperands();
781 if (!getNumUnresolved()) {
782 dropReplaceableUses();
783 assert(isResolved() && "Expected this to be resolved");
784 }
785
786 assert(isUniqued() && "Expected this to be uniqued");
787}
788
789void MDNode::makeDistinct() {
790 assert(isTemporary() && "Expected this to be temporary");
791 assert(!isResolved() && "Expected this to be unresolved");
792
793 // Drop RAUW support and store as a distinct node.
794 dropReplaceableUses();
796
797 assert(isDistinct() && "Expected this to be distinct");
798 assert(isResolved() && "Expected this to be resolved");
799}
800
802 assert(isUniqued() && "Expected this to be uniqued");
803 assert(!isResolved() && "Expected this to be unresolved");
804
806 dropReplaceableUses();
807
808 assert(isResolved() && "Expected this to be resolved");
809}
810
811void MDNode::dropReplaceableUses() {
812 assert(!getNumUnresolved() && "Unexpected unresolved operand");
813
814 // Drop any RAUW support.
815 if (Context.hasReplaceableUses())
816 Context.takeReplaceableUses()->resolveAllUses();
817}
818
819void MDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) {
820 assert(isUniqued() && "Expected this to be uniqued");
821 assert(getNumUnresolved() != 0 && "Expected unresolved operands");
822
823 // Check if an operand was resolved.
824 if (!isOperandUnresolved(Old)) {
825 if (isOperandUnresolved(New))
826 // An operand was un-resolved!
828 } else if (!isOperandUnresolved(New))
829 decrementUnresolvedOperandCount();
830}
831
832void MDNode::decrementUnresolvedOperandCount() {
833 assert(!isResolved() && "Expected this to be unresolved");
834 if (isTemporary())
835 return;
836
837 assert(isUniqued() && "Expected this to be uniqued");
839 if (getNumUnresolved())
840 return;
841
842 // Last unresolved operand has just been resolved.
843 dropReplaceableUses();
844 assert(isResolved() && "Expected this to become resolved");
845}
846
848 if (isResolved())
849 return;
850
851 // Resolve this node immediately.
852 resolve();
853
854 // Resolve all operands.
855 for (const auto &Op : operands()) {
857 if (!N)
858 continue;
859
860 assert(!N->isTemporary() &&
861 "Expected all forward declarations to be resolved");
862 if (!N->isResolved())
863 N->resolveCycles();
864 }
865}
866
867static bool hasSelfReference(MDNode *N) {
868 return llvm::is_contained(N->operands(), N);
869}
870
871MDNode *MDNode::replaceWithPermanentImpl() {
872 switch (getMetadataID()) {
873 default:
874 // If this type isn't uniquable, replace with a distinct node.
875 return replaceWithDistinctImpl();
876
877#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
878 case CLASS##Kind: \
879 break;
880#include "llvm/IR/Metadata.def"
881 }
882
883 // Even if this type is uniquable, self-references have to be distinct.
884 if (hasSelfReference(this))
885 return replaceWithDistinctImpl();
886 return replaceWithUniquedImpl();
887}
888
889MDNode *MDNode::replaceWithUniquedImpl() {
890 // Try to uniquify in place.
891 MDNode *UniquedNode = uniquify();
892
893 if (UniquedNode == this) {
894 makeUniqued();
895 return this;
896 }
897
898 // Collision, so RAUW instead.
899 replaceAllUsesWith(UniquedNode);
900 deleteAsSubclass();
901 return UniquedNode;
902}
903
904MDNode *MDNode::replaceWithDistinctImpl() {
905 makeDistinct();
906 return this;
907}
908
909void MDTuple::recalculateHash() {
910 setHash(MDTupleInfo::KeyTy::calculateHash(this));
911}
912
914 for (unsigned I = 0, E = getNumOperands(); I != E; ++I)
915 setOperand(I, nullptr);
916 if (Context.hasReplaceableUses()) {
917 Context.getReplaceableUses()->resolveAllUses(/* ResolveUsers */ false);
918 (void)Context.takeReplaceableUses();
919 }
920}
921
922void MDNode::handleChangedOperand(void *Ref, Metadata *New) {
923 unsigned Op = static_cast<MDOperand *>(Ref) - op_begin();
924 assert(Op < getNumOperands() && "Expected valid operand");
925
926 if (!isUniqued()) {
927 // This node is not uniqued. Just set the operand and be done with it.
928 setOperand(Op, New);
929 return;
930 }
931
932 // This node is uniqued.
933 eraseFromStore();
934
935 Metadata *Old = getOperand(Op);
936 setOperand(Op, New);
937
938 // Drop uniquing for self-reference cycles and deleted constants.
939 if (New == this || (!New && Old && isa<ConstantAsMetadata>(Old))) {
940 if (!isResolved())
941 resolve();
943 return;
944 }
945
946 // Re-unique the node.
947 auto *Uniqued = uniquify();
948 if (Uniqued == this) {
949 if (!isResolved())
950 resolveAfterOperandChange(Old, New);
951 return;
952 }
953
954 // Collision.
955 if (!isResolved()) {
956 // Still unresolved, so RAUW.
957 //
958 // First, clear out all operands to prevent any recursion (similar to
959 // dropAllReferences(), but we still need the use-list).
960 for (unsigned O = 0, E = getNumOperands(); O != E; ++O)
961 setOperand(O, nullptr);
962 if (Context.hasReplaceableUses())
963 Context.getReplaceableUses()->replaceAllUsesWith(Uniqued);
964 deleteAsSubclass();
965 return;
966 }
967
968 // Store in non-uniqued form if RAUW isn't possible.
970}
971
972void MDNode::deleteAsSubclass() {
973 if (isTemporary()) {
974 bool WasTracked = getContext().pImpl->TemporaryMDNodes.erase(this);
975 assert(WasTracked && "Temporary node not tracked");
976 (void)WasTracked;
977 }
978 switch (getMetadataID()) {
979 default:
980 llvm_unreachable("Invalid subclass of MDNode");
981#define HANDLE_MDNODE_LEAF(CLASS) \
982 case CLASS##Kind: \
983 delete cast<CLASS>(this); \
984 break;
985#include "llvm/IR/Metadata.def"
986 }
987}
988
989template <class T, class InfoT>
991 if (T *U = getUniqued(Store, N))
992 return U;
993
994 Store.insert(N);
995 return N;
996}
997
998template <class NodeTy> struct MDNode::HasCachedHash {
999 template <class U>
1000 static std::true_type check(SameType<void (U::*)(unsigned), &U::setHash> *);
1001 template <class U> static std::false_type check(...);
1002
1003 static constexpr bool value = decltype(check<NodeTy>(nullptr))::value;
1004};
1005
1006MDNode *MDNode::uniquify() {
1007 assert(!hasSelfReference(this) && "Cannot uniquify a self-referencing node");
1008
1009 // Try to insert into uniquing store.
1010 switch (getMetadataID()) {
1011 default:
1012 llvm_unreachable("Invalid or non-uniquable subclass of MDNode");
1013#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1014 case CLASS##Kind: { \
1015 CLASS *SubclassThis = cast<CLASS>(this); \
1016 dispatchRecalculateHash(SubclassThis); \
1017 return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s); \
1018 }
1019#include "llvm/IR/Metadata.def"
1020 }
1021}
1022
1023void MDNode::eraseFromStore() {
1024 switch (getMetadataID()) {
1025 default:
1026 llvm_unreachable("Invalid or non-uniquable subclass of MDNode");
1027#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1028 case CLASS##Kind: \
1029 getContext().pImpl->CLASS##s.erase(cast<CLASS>(this)); \
1030 break;
1031#include "llvm/IR/Metadata.def"
1032 }
1033}
1034
1035MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
1036 StorageType Storage, bool ShouldCreate) {
1037 unsigned Hash = 0;
1038 if (Storage == Uniqued) {
1039 MDTupleInfo::KeyTy Key(MDs);
1040 if (auto *N = getUniqued(Context.pImpl->MDTuples, Key))
1041 return N;
1042 if (!ShouldCreate)
1043 return nullptr;
1044 Hash = Key.getHash();
1045 } else {
1046 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
1047 }
1048
1049 return storeImpl(new (MDs.size(), Storage)
1050 MDTuple(Context, Storage, Hash, MDs),
1051 Storage, Context.pImpl->MDTuples);
1052}
1053
1055 assert(N->isTemporary() && "Expected temporary node");
1056 N->replaceAllUsesWith(nullptr);
1057 N->deleteAsSubclass();
1058}
1059
1061 assert(!Context.hasReplaceableUses() && "Unexpected replaceable uses");
1062 assert(!getNumUnresolved() && "Unexpected unresolved nodes");
1063 if (isTemporary()) {
1064 bool WasTracked = getContext().pImpl->TemporaryMDNodes.erase(this);
1065 assert(WasTracked && "Temporary node not tracked");
1066 (void)WasTracked;
1067 }
1068 Storage = Distinct;
1069 assert(isResolved() && "Expected this to be resolved");
1070
1071 // Reset the hash.
1072 switch (getMetadataID()) {
1073 default:
1074 llvm_unreachable("Invalid subclass of MDNode");
1075#define HANDLE_MDNODE_LEAF(CLASS) \
1076 case CLASS##Kind: { \
1077 dispatchResetHash(cast<CLASS>(this)); \
1078 break; \
1079 }
1080#include "llvm/IR/Metadata.def"
1081 }
1082
1083 getContext().pImpl->DistinctMDNodes.push_back(this);
1084}
1085
1087 if (getOperand(I) == New)
1088 return;
1089
1090 if (!isUniqued()) {
1091 setOperand(I, New);
1092 return;
1093 }
1094
1095 handleChangedOperand(mutable_begin() + I, New);
1096}
1097
1098void MDNode::setOperand(unsigned I, Metadata *New) {
1099 assert(I < getNumOperands());
1100 mutable_begin()[I].reset(New, isUniqued() ? this : nullptr);
1101}
1102
1103/// Get a node or a self-reference that looks like it.
1104///
1105/// Special handling for finding self-references, for use by \a
1106/// MDNode::concatenate() and \a MDNode::intersect() to maintain behaviour from
1107/// when self-referencing nodes were still uniqued. If the first operand has
1108/// the same operands as \c Ops, return the first operand instead.
1111 if (!Ops.empty())
1113 if (N->getNumOperands() == Ops.size() && N == N->getOperand(0)) {
1114 for (unsigned I = 1, E = Ops.size(); I != E; ++I)
1115 if (Ops[I] != N->getOperand(I))
1116 return MDNode::get(Context, Ops);
1117 return N;
1118 }
1119
1120 return MDNode::get(Context, Ops);
1121}
1122
1124 if (!A)
1125 return B;
1126 if (!B)
1127 return A;
1128
1129 SmallSetVector<Metadata *, 4> MDs(A->op_begin(), A->op_end());
1130 MDs.insert(B->op_begin(), B->op_end());
1131
1132 // FIXME: This preserves long-standing behaviour, but is it really the right
1133 // behaviour? Or was that an unintended side-effect of node uniquing?
1134 return getOrSelfReference(A->getContext(), MDs.getArrayRef());
1135}
1136
1138 if (!A || !B)
1139 return nullptr;
1140
1141 SmallSetVector<Metadata *, 4> MDs(A->op_begin(), A->op_end());
1142 SmallPtrSet<Metadata *, 4> BSet(B->op_begin(), B->op_end());
1143 MDs.remove_if([&](Metadata *MD) { return !BSet.count(MD); });
1144
1145 // FIXME: This preserves long-standing behaviour, but is it really the right
1146 // behaviour? Or was that an unintended side-effect of node uniquing?
1147 return getOrSelfReference(A->getContext(), MDs.getArrayRef());
1148}
1149
1151 if (!A || !B)
1152 return nullptr;
1153
1154 // Take the intersection of domains then union the scopes
1155 // within those domains
1157 SmallPtrSet<const MDNode *, 16> IntersectDomains;
1159 for (const MDOperand &MDOp : A->operands())
1160 if (const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1161 if (const MDNode *Domain = AliasScopeNode(NAMD).getDomain())
1162 ADomains.insert(Domain);
1163
1164 for (const MDOperand &MDOp : B->operands())
1165 if (const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1166 if (const MDNode *Domain = AliasScopeNode(NAMD).getDomain())
1167 if (ADomains.contains(Domain)) {
1168 IntersectDomains.insert(Domain);
1169 MDs.insert(MDOp);
1170 }
1171
1172 for (const MDOperand &MDOp : A->operands())
1173 if (const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1174 if (const MDNode *Domain = AliasScopeNode(NAMD).getDomain())
1175 if (IntersectDomains.contains(Domain))
1176 MDs.insert(MDOp);
1177
1178 return MDs.empty() ? nullptr
1179 : getOrSelfReference(A->getContext(), MDs.getArrayRef());
1180}
1181
1183 if (!A || !B)
1184 return nullptr;
1185
1186 APFloat AVal = mdconst::extract<ConstantFP>(A->getOperand(0))->getValueAPF();
1187 APFloat BVal = mdconst::extract<ConstantFP>(B->getOperand(0))->getValueAPF();
1188 if (AVal < BVal)
1189 return A;
1190 return B;
1191}
1192
1193// Call instructions with branch weights are only used in SamplePGO as
1194// documented in
1195/// https://llvm.org/docs/BranchWeightMetadata.html#callinst).
1196MDNode *MDNode::mergeDirectCallProfMetadata(MDNode *A, MDNode *B,
1197 const Instruction *AInstr,
1198 const Instruction *BInstr) {
1199 assert(A && B && AInstr && BInstr && "Caller should guarantee");
1200 auto &Ctx = AInstr->getContext();
1201 MDBuilder MDHelper(Ctx);
1202
1203 // LLVM IR verifier verifies !prof metadata has at least 2 operands.
1204 assert(A->getNumOperands() >= 2 && B->getNumOperands() >= 2 &&
1205 "!prof annotations should have no less than 2 operands");
1206 MDString *AMDS = dyn_cast<MDString>(A->getOperand(0));
1207 MDString *BMDS = dyn_cast<MDString>(B->getOperand(0));
1208 // LLVM IR verfier verifies first operand is MDString.
1209 assert(AMDS != nullptr && BMDS != nullptr &&
1210 "first operand should be a non-null MDString");
1211 StringRef AProfName = AMDS->getString();
1212 StringRef BProfName = BMDS->getString();
1213 if (AProfName == MDProfLabels::BranchWeights &&
1214 BProfName == MDProfLabels::BranchWeights) {
1216 A->getOperand(getBranchWeightOffset(A)));
1218 B->getOperand(getBranchWeightOffset(B)));
1219 assert(AInstrWeight && BInstrWeight && "verified by LLVM verifier");
1220 return MDNode::get(Ctx,
1221 {MDHelper.createString(MDProfLabels::BranchWeights),
1222 MDHelper.createConstant(ConstantInt::get(
1223 Type::getInt64Ty(Ctx),
1224 SaturatingAdd(AInstrWeight->getZExtValue(),
1225 BInstrWeight->getZExtValue())))});
1226 }
1227 return nullptr;
1228}
1229
1230// Pass in both instructions and nodes. Instruction information (e.g.,
1231// instruction type) helps interpret profiles and make implementation clearer.
1233 const Instruction *AInstr,
1234 const Instruction *BInstr) {
1235 // Check that it is legal to merge prof metadata based on the opcode.
1236 auto IsLegal = [](const Instruction &I) -> bool {
1237 switch (I.getOpcode()) {
1238 case Instruction::Invoke:
1239 case Instruction::CondBr:
1240 case Instruction::Switch:
1241 case Instruction::Call:
1242 case Instruction::IndirectBr:
1243 case Instruction::Select:
1244 case Instruction::CallBr:
1245 return true;
1246 default:
1247 return false;
1248 }
1249 };
1250 if (AInstr && !IsLegal(*AInstr))
1251 return nullptr;
1252 if (BInstr && !IsLegal(*BInstr))
1253 return nullptr;
1254
1255 if (!(A && B)) {
1256 return A ? A : B;
1257 }
1258
1259 assert(AInstr->getMetadata(LLVMContext::MD_prof) == A &&
1260 "Caller should guarantee");
1261 assert(BInstr->getMetadata(LLVMContext::MD_prof) == B &&
1262 "Caller should guarantee");
1263
1264 const CallInst *ACall = dyn_cast<CallInst>(AInstr);
1265 const CallInst *BCall = dyn_cast<CallInst>(BInstr);
1266
1267 // Both ACall and BCall are direct callsites.
1268 if (ACall && BCall && ACall->getCalledFunction() &&
1269 BCall->getCalledFunction())
1270 return mergeDirectCallProfMetadata(A, B, AInstr, BInstr);
1271
1272 if (A == B)
1273 return A;
1274
1275 // The rest of the cases are not implemented but could be added
1276 // when there are use cases.
1277 return nullptr;
1278}
1279
1280static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
1281 return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
1282}
1283
1284static bool canBeMerged(const ConstantRange &A, const ConstantRange &B) {
1285 return !A.intersectWith(B).isEmptySet() || isContiguous(A, B);
1286}
1287
1290 ConstantRange NewRange(Low->getValue(), High->getValue());
1291 unsigned Size = EndPoints.size();
1292 const APInt &LB = EndPoints[Size - 2]->getValue();
1293 const APInt &LE = EndPoints[Size - 1]->getValue();
1294 ConstantRange LastRange(LB, LE);
1295 if (canBeMerged(NewRange, LastRange)) {
1296 ConstantRange Union = LastRange.unionWith(NewRange);
1297 Type *Ty = High->getType();
1298 EndPoints[Size - 2] =
1299 cast<ConstantInt>(ConstantInt::get(Ty, Union.getLower()));
1300 EndPoints[Size - 1] =
1301 cast<ConstantInt>(ConstantInt::get(Ty, Union.getUpper()));
1302 return true;
1303 }
1304 return false;
1305}
1306
1309 if (!EndPoints.empty())
1310 if (tryMergeRange(EndPoints, Low, High))
1311 return;
1312
1313 EndPoints.push_back(Low);
1314 EndPoints.push_back(High);
1315}
1316
1318 // Drop the callee_type metadata if either of the call instructions do not
1319 // have it.
1320 if (!A || !B)
1321 return nullptr;
1323 SmallPtrSet<Metadata *, 8> MergedCallees;
1324 auto AddUniqueCallees = [&AB, &MergedCallees](const MDNode *N) {
1325 for (Metadata *MD : N->operands()) {
1326 if (MergedCallees.insert(MD).second)
1327 AB.push_back(MD);
1328 }
1329 };
1330 AddUniqueCallees(A);
1331 AddUniqueCallees(B);
1332 return MDNode::get(A->getContext(), AB);
1333}
1334
1336 // The callees of the merged call are unknown unless both calls list theirs.
1337 if (!A || !B)
1338 return nullptr;
1339 if (A == B)
1340 return A;
1341 // The merged call may target any callee of either call.
1342 SmallSetVector<Metadata *, 8> Callees(llvm::from_range, A->operands());
1343 Callees.insert_range(B->operands());
1344 return MDNode::get(A->getContext(), Callees.getArrayRef());
1345}
1346
1348 // Drop !alloc_token metadata if either instruction lacks it to avoid mis-
1349 // classifying unclassified allocations, where the fallback token must be
1350 // used instead.
1351 if (!A || !B)
1352 return nullptr;
1353 if (A == B)
1354 return const_cast<MDNode *>(A);
1355 if (A->getNumOperands() != 2 || B->getNumOperands() != 2)
1356 return nullptr;
1357 auto *CIA = mdconst::dyn_extract_or_null<ConstantInt>(A->getOperand(1));
1358 auto *CIB = mdconst::dyn_extract_or_null<ConstantInt>(B->getOperand(1));
1359 if (!CIA || !CIB)
1360 return nullptr;
1361
1362 MDString *NameA = dyn_cast<MDString>(A->getOperand(0));
1363 MDString *NameB = dyn_cast<MDString>(B->getOperand(0));
1364 if (!NameA || !NameB)
1365 return nullptr;
1366
1367 if (NameA == NameB)
1368 return CIA->isOne() ? const_cast<MDNode *>(A) : const_cast<MDNode *>(B);
1369
1370 LLVMContext &Ctx = A->getContext();
1371 StringRef StrA = NameA->getString();
1372 StringRef StrB = NameB->getString();
1373
1374 SmallString<64> Buffer;
1375 Buffer.reserve(StrA.size() + 1 + StrB.size());
1376 Buffer.append(StrA);
1377 Buffer.push_back('|');
1378 Buffer.append(StrB);
1379
1380 bool MergedContainsPointer = CIA->isOne() || CIB->isOne();
1381 Metadata *Ops[] = {MDString::get(Ctx, Buffer),
1382 ConstantAsMetadata::get(ConstantInt::get(
1383 Type::getInt1Ty(Ctx), MergedContainsPointer))};
1384 return MDNode::get(Ctx, Ops);
1385}
1386
1388 // Given two ranges, we want to compute the union of the ranges. This
1389 // is slightly complicated by having to combine the intervals and merge
1390 // the ones that overlap.
1391
1392 if (!A || !B)
1393 return nullptr;
1394
1395 if (A == B)
1396 return A;
1397
1398 // First, walk both lists in order of the lower boundary of each interval.
1399 // At each step, try to merge the new interval to the last one we added.
1401 unsigned AI = 0;
1402 unsigned BI = 0;
1403 unsigned AN = A->getNumOperands() / 2;
1404 unsigned BN = B->getNumOperands() / 2;
1405 while (AI < AN && BI < BN) {
1406 ConstantInt *ALow = mdconst::extract<ConstantInt>(A->getOperand(2 * AI));
1407 ConstantInt *BLow = mdconst::extract<ConstantInt>(B->getOperand(2 * BI));
1408
1409 if (ALow->getValue().slt(BLow->getValue())) {
1410 addRange(EndPoints, ALow,
1411 mdconst::extract<ConstantInt>(A->getOperand(2 * AI + 1)));
1412 ++AI;
1413 } else {
1414 addRange(EndPoints, BLow,
1415 mdconst::extract<ConstantInt>(B->getOperand(2 * BI + 1)));
1416 ++BI;
1417 }
1418 }
1419 while (AI < AN) {
1420 addRange(EndPoints, mdconst::extract<ConstantInt>(A->getOperand(2 * AI)),
1421 mdconst::extract<ConstantInt>(A->getOperand(2 * AI + 1)));
1422 ++AI;
1423 }
1424 while (BI < BN) {
1425 addRange(EndPoints, mdconst::extract<ConstantInt>(B->getOperand(2 * BI)),
1426 mdconst::extract<ConstantInt>(B->getOperand(2 * BI + 1)));
1427 ++BI;
1428 }
1429
1430 // We haven't handled wrap in the previous merge,
1431 // if we have at least 2 ranges (4 endpoints) we have to try to merge
1432 // the last and first ones.
1433 unsigned Size = EndPoints.size();
1434 if (Size > 2) {
1435 ConstantInt *FB = EndPoints[0];
1436 ConstantInt *FE = EndPoints[1];
1437 if (tryMergeRange(EndPoints, FB, FE)) {
1438 for (unsigned i = 0; i < Size - 2; ++i) {
1439 EndPoints[i] = EndPoints[i + 2];
1440 }
1441 EndPoints.resize(Size - 2);
1442 }
1443 }
1444
1445 // If in the end we have a single range, it is possible that it is now the
1446 // full range. Just drop the metadata in that case.
1447 if (EndPoints.size() == 2) {
1448 ConstantRange Range(EndPoints[0]->getValue(), EndPoints[1]->getValue());
1449 if (Range.isFullSet())
1450 return nullptr;
1451 }
1452
1454 MDs.reserve(EndPoints.size());
1455 for (auto *I : EndPoints)
1457 return MDNode::get(A->getContext(), MDs);
1458}
1459
1461 if (!A || !B)
1462 return nullptr;
1463
1464 if (A == B)
1465 return A;
1466
1467 ConstantInt *AVal = mdconst::extract<ConstantInt>(A->getOperand(0));
1468 ConstantInt *BVal = mdconst::extract<ConstantInt>(B->getOperand(0));
1469 unsigned Intersect = AVal->getZExtValue() & BVal->getZExtValue();
1470 if (Intersect == 0)
1471 return nullptr;
1472
1473 return MDNode::get(A->getContext(), ConstantAsMetadata::get(ConstantInt::get(
1474 AVal->getType(), Intersect)));
1475}
1476
1478 if (!A || !B)
1479 return nullptr;
1480
1481 if (A == B)
1482 return A;
1483
1484 SmallVector<ConstantRange> RangeListA, RangeListB;
1485 for (unsigned I = 0, E = A->getNumOperands() / 2; I != E; ++I) {
1486 auto *LowA = mdconst::extract<ConstantInt>(A->getOperand(2 * I + 0));
1487 auto *HighA = mdconst::extract<ConstantInt>(A->getOperand(2 * I + 1));
1488 RangeListA.push_back(ConstantRange(LowA->getValue(), HighA->getValue()));
1489 }
1490
1491 for (unsigned I = 0, E = B->getNumOperands() / 2; I != E; ++I) {
1492 auto *LowB = mdconst::extract<ConstantInt>(B->getOperand(2 * I + 0));
1493 auto *HighB = mdconst::extract<ConstantInt>(B->getOperand(2 * I + 1));
1494 RangeListB.push_back(ConstantRange(LowB->getValue(), HighB->getValue()));
1495 }
1496
1497 ConstantRangeList CRLA(RangeListA);
1498 ConstantRangeList CRLB(RangeListB);
1499 ConstantRangeList Result = CRLA.intersectWith(CRLB);
1500 if (Result.empty())
1501 return nullptr;
1502
1504 for (const ConstantRange &CR : Result) {
1506 ConstantInt::get(A->getContext(), CR.getLower())));
1508 ConstantInt::get(A->getContext(), CR.getUpper())));
1509 }
1510
1511 return MDNode::get(A->getContext(), MDs);
1512}
1513
1515 if (!A || !B)
1516 return nullptr;
1517
1518 ConstantInt *AVal = mdconst::extract<ConstantInt>(A->getOperand(0));
1519 ConstantInt *BVal = mdconst::extract<ConstantInt>(B->getOperand(0));
1520 if (AVal->getZExtValue() < BVal->getZExtValue())
1521 return A;
1522 return B;
1523}
1524
1526 if (!MD)
1528
1530 for (Metadata *Op : MD->operands()) {
1531 CaptureComponents Component =
1533 .Case("address", CaptureComponents::Address)
1534 .Case("address_is_null", CaptureComponents::AddressIsNull)
1535 .Case("provenance", CaptureComponents::Provenance)
1536 .Case("read_provenance", CaptureComponents::ReadProvenance);
1537 CC |= Component;
1538 }
1539 return CC;
1540}
1541
1543 assert(!capturesNothing(CC) && "Can't encode captures(none)");
1544 if (capturesAll(CC))
1545 return nullptr;
1546
1547 SmallVector<Metadata *> Components;
1549 Components.push_back(MDString::get(Ctx, "address_is_null"));
1550 else if (capturesAddress(CC))
1551 Components.push_back(MDString::get(Ctx, "address"));
1553 Components.push_back(MDString::get(Ctx, "read_provenance"));
1554 else if (capturesFullProvenance(CC))
1555 Components.push_back(MDString::get(Ctx, "provenance"));
1556 return MDNode::get(Ctx, Components);
1557}
1558
1559//===----------------------------------------------------------------------===//
1560// NamedMDNode implementation.
1561//
1562
1566
1567NamedMDNode::NamedMDNode(const Twine &N)
1568 : Name(N.str()), Operands(new SmallVector<TrackingMDRef, 4>()) {}
1569
1572 delete &getNMDOps(Operands);
1573}
1574
1576 return (unsigned)getNMDOps(Operands).size();
1577}
1578
1580 assert(i < getNumOperands() && "Invalid Operand number!");
1581 auto *N = getNMDOps(Operands)[i].get();
1582 return cast_or_null<MDNode>(N);
1583}
1584
1585void NamedMDNode::addOperand(MDNode *M) { getNMDOps(Operands).emplace_back(M); }
1586
1587void NamedMDNode::setOperand(unsigned I, MDNode *New) {
1588 assert(I < getNumOperands() && "Invalid operand number");
1589 getNMDOps(Operands)[I].reset(New);
1590}
1591
1593
1594void NamedMDNode::clearOperands() { getNMDOps(Operands).clear(); }
1595
1597
1598//===----------------------------------------------------------------------===//
1599// Instruction Metadata method implementations.
1600//
1601
1602unsigned &Value::getMetadataIndex() {
1603 if (auto *I = dyn_cast<Instruction>(this))
1604 return I->MetadataIndex;
1605 return cast<GlobalObject>(this)->MetadataIndex;
1606}
1607
1608unsigned Value::getMetadataIndex() const {
1609 return const_cast<Value *>(this)->getMetadataIndex();
1610}
1611
1613 unsigned KindID = getContext().getMDKindID(Kind);
1614 return getMetadataImpl(KindID);
1615}
1616
1617MDNode *Value::getMetadataImpl(unsigned KindID) const {
1618 const LLVMContext &Ctx = getContext();
1619 unsigned Idx = getMetadataIndex();
1620 while (Idx) {
1621 const MDAttachment &A = Ctx.pImpl->Metadatas[Idx];
1622 if (A.MDKind == KindID)
1623 return A.Node;
1624 Idx = A.Next;
1625 }
1626 return nullptr;
1627}
1628
1629void GlobalObject::getMetadata(unsigned KindID,
1630 SmallVectorImpl<MDNode *> &MDs) const {
1631 const LLVMContext &Ctx = getContext();
1632 unsigned Idx = MetadataIndex;
1633 while (Idx) {
1634 const MDAttachment &A = Ctx.pImpl->Metadatas[Idx];
1635 if (A.MDKind == KindID)
1636 MDs.push_back(A.Node);
1637 Idx = A.Next;
1638 }
1639 // We store metadata in reverse order, so reverse for output.
1640 std::reverse(MDs.begin(), MDs.end());
1641}
1642
1644 SmallVectorImpl<MDNode *> &MDs) const {
1645 getMetadata(getContext().getMDKindID(Kind), MDs);
1646}
1647
1649 SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
1650 const LLVMContext &Ctx = getContext();
1651 unsigned Idx = getMetadataIndex();
1652 while (Idx) {
1653 const MDAttachment &A = Ctx.pImpl->Metadatas[Idx];
1654 MDs.emplace_back(A.MDKind, A.Node);
1655 Idx = A.Next;
1656 }
1657 // We store metadata in reverse order, so reverse for output in insertion
1658 // order. Sort by metadata ID for stable output.
1659 if (MDs.size() > 1) {
1660 std::reverse(MDs.begin(), MDs.end());
1662 }
1663}
1664
1665void Value::setMetadata(unsigned KindID, MDNode *Node) {
1667
1668 if (getMetadataIndex() != 0)
1669 eraseMetadata(KindID);
1670 if (Node)
1671 addMetadata(KindID, *Node);
1672}
1673
1675 if (!Node && getMetadataIndex() == 0)
1676 return;
1677 setMetadata(getContext().getMDKindID(Kind), Node);
1678}
1679
1680void Value::addMetadata(unsigned KindID, MDNode &MD) {
1681 const LLVMContext &Ctx = getContext();
1682 unsigned &Idx = getMetadataIndex();
1683 unsigned NewIdx = Ctx.pImpl->MetadataRecycleHead;
1684 if (NewIdx == 0) {
1685 NewIdx = Ctx.pImpl->Metadatas.size();
1686 if (NewIdx == 0)
1687 NewIdx = 1;
1688 Ctx.pImpl->Metadatas.resize(NewIdx + 1);
1689 } else {
1690 Ctx.pImpl->MetadataRecycleHead = Ctx.pImpl->Metadatas[NewIdx].Next;
1691#ifndef NDEBUG
1692 Ctx.pImpl->MetadataRecycleSize -= 1;
1693#endif
1694 }
1695 Ctx.pImpl->Metadatas[NewIdx] =
1696 MDAttachment{Idx, KindID, TrackingMDNodeRef(&MD)};
1697 Idx = NewIdx;
1698}
1699
1701 addMetadata(getContext().getMDKindID(Kind), MD);
1702}
1703
1704bool Value::eraseMetadata(unsigned KindID) {
1705 bool Changed = false;
1706 eraseMetadataIf([&Changed, KindID](unsigned MDKind, MDNode *) {
1707 Changed |= MDKind == KindID;
1708 return MDKind == KindID;
1709 });
1710 return Changed;
1711}
1712
1713void Value::eraseMetadataIf(function_ref<bool(unsigned, MDNode *)> Pred) {
1714 unsigned *Idx = &getMetadataIndex();
1715 const LLVMContext &Ctx = getContext();
1716 while (*Idx) {
1717 MDAttachment &A = Ctx.pImpl->Metadatas[*Idx];
1718 if (Pred(A.MDKind, A.Node)) {
1719 A.Node.reset();
1720 unsigned FreeIdx = *Idx;
1721 *Idx = A.Next;
1722 A.Next = Ctx.pImpl->MetadataRecycleHead;
1723 Ctx.pImpl->MetadataRecycleHead = FreeIdx;
1724#ifndef NDEBUG
1725 Ctx.pImpl->MetadataRecycleSize += 1;
1726#endif
1727 } else {
1728 Idx = &A.Next;
1729 }
1730 }
1731}
1732
1734 eraseMetadataIf([](unsigned, MDNode *) { return true; });
1735}
1736
1738 if (!Node && MetadataIndex == 0)
1739 return;
1740 setMetadata(getContext().getMDKindID(Kind), Node);
1741}
1742
1743MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
1744 const LLVMContext &Ctx = getContext();
1745 unsigned KindID = Ctx.getMDKindID(Kind);
1746 if (KindID == LLVMContext::MD_dbg)
1747 return DbgLoc.getAsMDNode();
1748 return Value::getMetadataImpl(KindID);
1749}
1750
1751void Instruction::eraseMetadataIf(function_ref<bool(unsigned, MDNode *)> Pred) {
1752 if (DbgLoc && Pred(LLVMContext::MD_dbg, DbgLoc.getAsMDNode()))
1753 DbgLoc = {};
1754
1756}
1757
1760 return; // Nothing to remove!
1761
1762 SmallSet<unsigned, 32> KnownSet(llvm::from_range, KnownIDs);
1763
1764 // A DIAssignID attachment is debug metadata, don't drop it.
1765 KnownSet.insert(LLVMContext::MD_DIAssignID);
1766
1767 Value::eraseMetadataIf([&KnownSet](unsigned MDKind, MDNode *Node) {
1768 return !KnownSet.count(MDKind);
1769 });
1770}
1771
1772void Instruction::updateDIAssignIDMapping(DIAssignID *ID) {
1773 if (auto *CurrentID =
1774 cast_or_null<DIAssignID>(getMetadata(LLVMContext::MD_DIAssignID))) {
1775 if (ID == CurrentID)
1776 return;
1777 CurrentID->Instrs.erase(llvm::find(CurrentID->Instrs, this));
1778 }
1779 if (ID)
1780 ID->Instrs.push_back(this);
1781}
1782
1783void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
1784 if (!Node && !hasMetadata())
1785 return;
1786
1787 // Handle 'dbg' as a special case since it is not stored in the hash table.
1788 if (KindID == LLVMContext::MD_dbg) {
1790 return;
1791 }
1792
1793 // Update DIAssignID to Instruction(s) mapping.
1794 if (KindID == LLVMContext::MD_DIAssignID) {
1795 // The DIAssignID tracking infrastructure doesn't support RAUWing temporary
1796 // nodes with DIAssignIDs. The cast_or_null below would also catch this, but
1797 // having a dedicated assert helps make this obvious.
1798 assert((!Node || !Node->isTemporary()) &&
1799 "Temporary DIAssignIDs are invalid");
1800 updateDIAssignIDMapping(cast_or_null<DIAssignID>(Node));
1801 }
1802
1803 Value::setMetadata(KindID, Node);
1804}
1805
1808 if (auto *Existing = getMetadata(LLVMContext::MD_annotation)) {
1809 SmallSetVector<StringRef, 2> AnnotationsSet(Annotations.begin(),
1810 Annotations.end());
1811 auto *Tuple = cast<MDTuple>(Existing);
1812 for (auto &N : Tuple->operands()) {
1813 if (isa<MDString>(N.get())) {
1814 Names.push_back(N);
1815 continue;
1816 }
1817 auto *MDAnnotationTuple = cast<MDTuple>(N);
1818 if (any_of(MDAnnotationTuple->operands(), [&AnnotationsSet](auto &Op) {
1819 return AnnotationsSet.contains(cast<MDString>(Op)->getString());
1820 }))
1821 return;
1822 Names.push_back(N);
1823 }
1824 }
1825
1826 MDBuilder MDB(getContext());
1827 SmallVector<Metadata *> MDAnnotationStrings;
1828 for (StringRef Annotation : Annotations)
1829 MDAnnotationStrings.push_back(MDB.createString(Annotation));
1830 MDNode *InfoTuple = MDTuple::get(getContext(), MDAnnotationStrings);
1831 Names.push_back(InfoTuple);
1832 MDNode *MD = MDTuple::get(getContext(), Names);
1833 setMetadata(LLVMContext::MD_annotation, MD);
1834}
1835
1838 if (auto *Existing = getMetadata(LLVMContext::MD_annotation)) {
1839 auto *Tuple = cast<MDTuple>(Existing);
1840 for (auto &N : Tuple->operands()) {
1841 if (isa<MDString>(N.get()) &&
1842 cast<MDString>(N.get())->getString() == Name)
1843 return;
1844 Names.push_back(N.get());
1845 }
1846 }
1847
1848 MDBuilder MDB(getContext());
1849 Names.push_back(MDB.createString(Name));
1850 MDNode *MD = MDTuple::get(getContext(), Names);
1851 setMetadata(LLVMContext::MD_annotation, MD);
1852}
1853
1855 AAMDNodes Result;
1857 unsigned Idx = MetadataIndex;
1858 const auto &Metadatas = getContext().pImpl->Metadatas;
1859 while (Idx) {
1860 const MDAttachment &A = Metadatas[Idx];
1861 switch (A.MDKind) {
1862 case LLVMContext::MD_tbaa:
1863 Result.TBAA = A.Node;
1864 break;
1865 case LLVMContext::MD_tbaa_struct:
1866 Result.TBAAStruct = A.Node;
1867 break;
1868 case LLVMContext::MD_alias_scope:
1869 Result.Scope = A.Node;
1870 break;
1871 case LLVMContext::MD_noalias:
1872 Result.NoAlias = A.Node;
1873 break;
1874 case LLVMContext::MD_noalias_addrspace:
1875 Result.NoAliasAddrSpace = A.Node;
1876 break;
1877 }
1878 Idx = A.Next;
1879 }
1880 }
1881 return Result;
1882}
1883
1885 setMetadata(LLVMContext::MD_tbaa, N.TBAA);
1886 setMetadata(LLVMContext::MD_tbaa_struct, N.TBAAStruct);
1887 setMetadata(LLVMContext::MD_alias_scope, N.Scope);
1888 setMetadata(LLVMContext::MD_noalias, N.NoAlias);
1889 setMetadata(LLVMContext::MD_noalias_addrspace, N.NoAliasAddrSpace);
1890}
1891
1893 setMetadata(llvm::LLVMContext::MD_nosanitize,
1895}
1896
1897void Instruction::getAllMetadataImpl(
1898 SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {
1899 Result.clear();
1900
1901 // Handle 'dbg' as a special case since it is not stored in the hash table.
1902 if (DbgLoc) {
1903 Result.push_back(
1904 std::make_pair((unsigned)LLVMContext::MD_dbg, DbgLoc.getAsMDNode()));
1905 }
1906 Value::getAllMetadata(Result);
1907}
1908
1909bool Instruction::extractProfTotalWeight(uint64_t &TotalVal) const {
1910 assert((getOpcode() == Instruction::CondBr ||
1911 getOpcode() == Instruction::Select ||
1912 getOpcode() == Instruction::Call ||
1913 getOpcode() == Instruction::Invoke ||
1914 getOpcode() == Instruction::IndirectBr ||
1915 getOpcode() == Instruction::Switch) &&
1916 "Looking for branch weights on something besides branch");
1917
1918 return ::extractProfTotalWeight(*this, TotalVal);
1919}
1920
1923 Other->getAllMetadata(MDs);
1924 for (auto &MD : MDs) {
1925 // We need to adjust the type metadata offset.
1926 if (Offset != 0 && MD.first == LLVMContext::MD_type) {
1927 auto *OffsetConst = cast<ConstantInt>(
1928 cast<ConstantAsMetadata>(MD.second->getOperand(0))->getValue());
1929 Metadata *TypeId = MD.second->getOperand(1);
1930 auto *NewOffsetMD = ConstantAsMetadata::get(ConstantInt::get(
1931 OffsetConst->getType(), OffsetConst->getValue() + Offset));
1932 addMetadata(LLVMContext::MD_type,
1933 *MDNode::get(getContext(), {NewOffsetMD, TypeId}));
1934 continue;
1935 }
1936 // If an offset adjustment was specified we need to modify the DIExpression
1937 // to prepend the adjustment:
1938 // !DIExpression(DW_OP_plus, Offset, [original expr])
1939 auto *Attachment = MD.second;
1940 if (Offset != 0 && MD.first == LLVMContext::MD_dbg) {
1942 DIExpression *E = nullptr;
1943 if (!GV) {
1944 auto *GVE = cast<DIGlobalVariableExpression>(Attachment);
1945 GV = GVE->getVariable();
1946 E = GVE->getExpression();
1947 }
1948 ArrayRef<uint64_t> OrigElements;
1949 if (E)
1950 OrigElements = E->getElements();
1951 std::vector<uint64_t> Elements(OrigElements.size() + 2);
1952 Elements[0] = dwarf::DW_OP_plus_uconst;
1953 Elements[1] = Offset;
1954 llvm::copy(OrigElements, Elements.begin() + 2);
1955 E = DIExpression::get(getContext(), Elements);
1956 Attachment = DIGlobalVariableExpression::get(getContext(), GV, E);
1957 }
1958 addMetadata(MD.first, *Attachment);
1959 }
1960}
1961
1964 LLVMContext::MD_type,
1966 {ConstantAsMetadata::get(ConstantInt::get(
1968 TypeID}));
1969}
1970
1972 // Remove any existing vcall visibility metadata first in case we are
1973 // updating.
1974 eraseMetadata(LLVMContext::MD_vcall_visibility);
1975 addMetadata(LLVMContext::MD_vcall_visibility,
1977 {ConstantAsMetadata::get(ConstantInt::get(
1979}
1980
1982 if (MDNode *MD = getMetadata(LLVMContext::MD_vcall_visibility)) {
1983 uint64_t Val = cast<ConstantInt>(
1984 cast<ConstantAsMetadata>(MD->getOperand(0))->getValue())
1985 ->getZExtValue();
1986 assert(Val <= 2 && "unknown vcall visibility!");
1987 return (VCallVisibility)Val;
1988 }
1990}
1991
1993 setMetadata(LLVMContext::MD_dbg, SP);
1994}
1995
1997 return cast_or_null<DISubprogram>(getMetadata(LLVMContext::MD_dbg));
1998}
1999
2001 if (DISubprogram *SP = getSubprogram()) {
2002 if (DICompileUnit *CU = SP->getUnit()) {
2003 return CU->getDebugInfoForProfiling();
2004 }
2005 }
2006 return false;
2007}
2008
2010 addMetadata(LLVMContext::MD_dbg, *GV);
2011}
2012
2016 getMetadata(LLVMContext::MD_dbg, MDs);
2017 for (MDNode *MD : MDs)
2019}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static const Function * getParent(const Value *V)
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Domain getDomain(const ConstantRange &CR)
dxil translate DXIL Translate Metadata
static ManagedStatic< DebugCounterOwner > Owner
This file defines the DenseSet and SmallDenseSet classes.
Module.h This file contains the declarations for the Module class.
static constexpr Value * getValue(Ty &ValueOrUse)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define I(x, y, z)
Definition MD5.cpp:57
#define H(x, y, z)
Definition MD5.cpp:56
static DISubprogram * getLocalFunctionMetadata(Value *V)
Definition Metadata.cpp:497
static Metadata * canonicalizeMetadataForValue(LLVMContext &Context, Metadata *MD)
Canonicalize metadata arguments to intrinsics.
Definition Metadata.cpp:85
static bool isOperandUnresolved(Metadata *Op)
Definition Metadata.cpp:755
static bool hasSelfReference(MDNode *N)
Definition Metadata.cpp:867
static void addRange(SmallVectorImpl< ConstantInt * > &EndPoints, ConstantInt *Low, ConstantInt *High)
static bool isTrackedValue(const Metadata &MD)
Definition Metadata.cpp:465
static SmallVector< TrackingMDRef, 4 > & getNMDOps(void *Operands)
static bool canBeMerged(const ConstantRange &A, const ConstantRange &B)
static T * uniquifyImpl(T *N, DenseSet< T *, InfoT > &Store)
Definition Metadata.cpp:990
static bool isContiguous(const ConstantRange &A, const ConstantRange &B)
static MDNode * getOrSelfReference(LLVMContext &Context, ArrayRef< Metadata * > Ops)
Get a node or a self-reference that looks like it.
static bool tryMergeRange(SmallVectorImpl< ConstantInt * > &EndPoints, ConstantInt *Low, ConstantInt *High)
This file contains the declarations for metadata subclasses.
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t High
This file contains the declarations for profiling metadata utility functions.
Remove Loads Into Fake Uses
SI Fold Operands
This file contains some templates that are useful if you are working with the STL at all.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
Definition APInt.h:78
bool slt(const APInt &RHS) const
Signed less than comparison.
Definition APInt.h:1134
This is a simple wrapper around an MDNode which provides a higher-level interface by hiding the detai...
Definition Metadata.h:1603
Annotations lets you mark points and ranges inside source code, for tests:
Definition Annotations.h:67
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
This class represents a function call, abstracting a target machine's calling convention.
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:548
This is the shared class of boolean and integer constants.
Definition Constants.h:87
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition Constants.h:168
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition Constants.h:159
This class represents a list of constant ranges.
LLVM_ABI ConstantRangeList intersectWith(const ConstantRangeList &CRL) const
Return the range list that results from the intersection of this ConstantRangeList with another Const...
This class represents a range of values.
LLVM_ABI ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
This is an important base class in LLVM.
Definition Constant.h:43
DWARF expression.
A pair of DIGlobalVariable and DIExpression.
Subprogram description. Uses SubclassData1.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LLVM_ABI MDNode * getAsMDNode() const
Return this as a bar MDNode.
Definition DebugLoc.cpp:76
Base class for tracking ValueAsMetadata/DIArgLists with user lookups and Owner callbacks outside of V...
Definition Metadata.h:221
static constexpr size_t AssignIDIdx
Definition Metadata.h:229
LLVM_ABI void handleChangedValue(void *Old, Metadata *NewDebugValue)
To be called by ReplaceableUses::replaceAllUsesWith, where Old is a pointer to one of the pointers in...
Definition Metadata.cpp:162
std::array< Metadata *, 3 > DebugValues
Definition Metadata.h:227
void resetDebugValue(size_t Idx, Metadata *DebugValue)
Definition Metadata.h:284
LLVM_ABI DbgVariableRecord * getUser()
Definition Metadata.cpp:155
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
void setSubprogram(DISubprogram *SP)
Set the attached subprogram.
DISubprogram * getSubprogram() const
Get the attached subprogram.
bool shouldEmitDebugInfoForProfiling() const
Returns true if we should emit debug info for profiling.
LLVM_ABI void addTypeMetadata(unsigned Offset, Metadata *TypeID)
unsigned MetadataIndex
Index of first metadata attachment in context, or zero.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
GlobalObject(Type *Ty, ValueTy VTy, AllocInfo AllocInfo, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace=0)
LLVM_ABI void copyMetadata(const GlobalObject *Src, unsigned Offset)
Copy metadata from Src, adjusting offsets by Offset.
LLVM_ABI VCallVisibility getVCallVisibility() const
LLVM_ABI bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this GlobalObject.
LLVM_ABI void setVCallVisibilityMetadata(VCallVisibility Visibility)
LLVM_ABI void getDebugInfo(SmallVectorImpl< DIGlobalVariableExpression * > &GVs) const
Fill the vector with all debug info attachements.
LLVM_ABI void addDebugInfo(DIGlobalVariableExpression *GV)
Attach a DIGlobalVariableExpression.
LLVM_ABI void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
LLVM_ABI bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
LLVM_ABI void addAnnotationMetadata(StringRef Annotation)
Adds an !annotation metadata node with Annotation to this instruction.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM_ABI void setNoSanitizeMetadata()
Sets the nosanitize metadata on this instruction.
LLVM_ABI void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs={})
Drop all unknown metadata except for debug locations.
LLVM_ABI AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)
Erase all metadata that matches the predicate.
DenseMap< Metadata *, MetadataAsValue * > MetadataAsValues
SmallVector< MDAttachment, 0 > Metadatas
Collection of metadata attachments in this context.
std::vector< MDNode * > DistinctMDNodes
DenseMap< Value *, ValueAsMetadata * > ValuesAsMetadata
DenseSet< MDNode * > TemporaryMDNodes
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
LLVM_ABI unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
LLVMContextImpl *const pImpl
Definition LLVMContext.h:70
LLVM_ABI MDString * createString(StringRef Str)
Return the given string as metadata.
Definition MDBuilder.cpp:21
Metadata node.
Definition Metadata.h:1081
static LLVM_ABI MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
LLVM_ABI void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
LLVM_ABI void resolveCycles()
Resolve cycles.
Definition Metadata.cpp:847
static LLVM_ABI CaptureComponents toCaptureComponents(const MDNode *MD)
Convert !captures metadata to CaptureComponents. MD may be nullptr.
mutable_op_range mutable_operands()
Definition Metadata.h:1219
static LLVM_ABI MDNode * getMergedCalleeTypeMetadata(const MDNode *A, const MDNode *B)
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
Definition Metadata.h:1277
static LLVM_ABI MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
static LLVM_ABI void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
LLVM_ABI void resolve()
Resolve a unique, unresolved node.
Definition Metadata.cpp:801
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1437
static LLVM_ABI MDNode * getMostGenericNoaliasAddrspace(MDNode *A, MDNode *B)
LLVM_ABI void storeDistinctInContext()
bool isTemporary() const
Definition Metadata.h:1265
ArrayRef< MDOperand > operands() const
Definition Metadata.h:1435
static LLVM_ABI MDNode * getMergedCalleesMetadata(MDNode *A, MDNode *B)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1579
static LLVM_ABI MDNode * getMergedProfMetadata(MDNode *A, MDNode *B, const Instruction *AInstr, const Instruction *BInstr)
Merge !prof metadata from two instructions.
bool isUniqued() const
Definition Metadata.h:1263
static LLVM_ABI MDNode * getMergedAllocTokenMetadata(const MDNode *A, const MDNode *B)
static LLVM_ABI MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
void setNumUnresolved(unsigned N)
Definition Metadata.h:1364
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1443
MDOperand * mutable_begin()
Definition Metadata.h:1214
LLVM_ABI MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
Definition Metadata.cpp:651
LLVM_ABI TempMDNode clone() const
Create a (temporary) clone of this.
Definition Metadata.cpp:670
static LLVM_ABI MDNode * getMostGenericRange(MDNode *A, MDNode *B)
bool isDistinct() const
Definition Metadata.h:1264
LLVM_ABI void setOperand(unsigned I, Metadata *New)
Set an operand.
bool isResolved() const
Check if node is fully resolved.
Definition Metadata.h:1261
op_iterator op_begin() const
Definition Metadata.h:1427
static LLVM_ABI MDNode * intersect(MDNode *A, MDNode *B)
static LLVM_ABI MDNode * getMostGenericNoFPClass(MDNode *A, MDNode *B)
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
LLVMContext & getContext() const
Definition Metadata.h:1245
static LLVM_ABI MDNode * fromCaptureComponents(LLVMContext &Ctx, CaptureComponents CC)
Convert CaptureComponents to !captures metadata.
LLVM_ABI void dropAllReferences()
Definition Metadata.cpp:913
static LLVM_ABI MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)
unsigned getNumUnresolved() const
Definition Metadata.h:1362
Tracking metadata reference owned by Metadata.
Definition Metadata.h:902
A single uniqued string.
Definition Metadata.h:733
LLVM_ABI StringRef getString() const
Definition Metadata.cpp:615
static LLVM_ABI MDString * getIfExists(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:607
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:597
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1525
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:107
static LLVM_ABI MetadataAsValue * getIfExists(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:115
LLVM_ABI ~MetadataAsValue()
Definition Metadata.cpp:69
static LLVM_ABI bool isReplaceable(const Metadata &MD)
Check whether metadata is replaceable.
Definition Metadata.cpp:256
static void untrack(Metadata *&MD)
Stop tracking a reference to metadata.
Definition Metadata.h:360
PointerUnion< MetadataAsValue *, Metadata *, DebugValueUser * > OwnerTy
Definition Metadata.h:379
static bool retrack(Metadata *&MD, Metadata *&New)
Move tracking from one reference to another.
Definition Metadata.h:371
static bool track(Metadata *&MD)
Track the reference to metadata.
Definition Metadata.h:326
Root of the metadata hierarchy.
Definition Metadata.h:64
StorageType
Active type of storage.
Definition Metadata.h:72
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition Metadata.h:75
unsigned getMetadataID() const
Definition Metadata.h:104
Metadata(unsigned ID, StorageType Storage)
Definition Metadata.h:88
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
Definition Module.cpp:322
iterator end() const
Definition ArrayRef.h:339
LLVM_ABI void setOperand(unsigned I, MDNode *New)
LLVM_ABI ~NamedMDNode()
LLVM_ABI StringRef getName() const
void dropAllReferences()
Remove all uses and clear node vector.
Definition Metadata.h:1832
LLVM_ABI void eraseFromParent()
Drop all references and remove the node from parent module.
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
LLVM_ABI void clearOperands()
Drop all references to this node's operands.
Module * getParent()
Get the module that holds this named metadata collection.
Definition Metadata.h:1837
LLVM_ABI void addOperand(MDNode *M)
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Shared implementation of use-lists for replaceable metadata.
Definition Metadata.h:393
MetadataTracking::OwnerTy OwnerTy
Definition Metadata.h:397
LLVM_ABI SmallVector< Metadata * > getAllArgListUsers()
Returns the list of all DIArgList users of this.
Definition Metadata.cpp:260
LLVM_ABI SmallVector< DbgVariableRecord * > getAllDbgVariableRecordUsers()
Returns the list of all DbgVariableRecord users of this.
Definition Metadata.cpp:282
LLVM_ABI void resolveAllUses(bool ResolveUsers=true)
Resolve all uses of this.
Definition Metadata.cpp:430
LLVM_ABI void replaceAllUsesWith(Metadata *MD)
Replace all uses of this with MD.
Definition Metadata.cpp:377
static LLVM_ABI void SalvageDebugInfo(const Constant &C)
Replace all uses of the constant with Undef in debug info metadata.
Definition Metadata.cpp:340
ArrayRef< value_type > getArrayRef() const
Definition SetVector.h:91
bool remove_if(UnaryPredicate P)
Remove items from the set vector based on a predicate function.
Definition SetVector.h:236
void insert_range(Range &&R)
Definition SetVector.h:182
bool empty() const
Determine if the SetVector is empty or not.
Definition SetVector.h:100
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:345
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:134
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition SmallSet.h:176
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:184
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
void append(StringRef RHS)
Append from a StringRef.
Definition SmallString.h:68
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void resize(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:278
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:296
Use & Op()
Definition User.h:171
Value wrapper in the Metadata hierarchy.
Definition Metadata.h:471
void replaceAllUsesWith(Metadata *MD)
Handle collisions after Value::replaceAllUsesWith().
Definition Metadata.h:530
static LLVM_ABI void handleDeletion(Value *V)
Definition Metadata.cpp:538
static LLVM_ABI ValueAsMetadata * get(Value *V)
Definition Metadata.cpp:514
static LLVM_ABI ValueAsMetadata * getIfExists(Value *V)
Definition Metadata.cpp:533
static LLVM_ABI void handleRAUW(Value *From, Value *To)
Definition Metadata.cpp:557
ValueAsMetadata(unsigned ID, Value *V)
Definition Metadata.h:483
Value * getValue() const
Definition Metadata.h:510
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
unsigned IsUsedByMD
Definition Value.h:112
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:260
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
bool hasUseList() const
Check if this Value has a use-list.
Definition Value.h:346
LLVM_ABI MDNode * getMetadataImpl(unsigned KindID) const LLVM_READONLY
Get metadata for the given kind, if any.
LLVM_ABI bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
LLVM_ABI MDNode * getMetadata(StringRef Kind) const LLVM_READONLY
Get the current metadata attachments for the given kind, if any.
LLVM_ABI void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)
Erase all metadata attachments matching the given predicate.
LLVM_ABI void clearMetadata()
Erase all metadata attached to this Value.
An efficient, type-erasing, non-owning reference to a callable.
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
Definition Metadata.h:720
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
Definition Metadata.h:707
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:679
iterator end() const
Definition BasicBlock.h:89
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
@ Offset
Definition DWP.cpp:577
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Definition STLExtras.h:846
bool capturesReadProvenanceOnly(CaptureComponents CC)
Definition ModRef.h:391
void stable_sort(R &&Range)
Definition STLExtras.h:2132
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1781
bool capturesAddressIsNullOnly(CaptureComponents CC)
Definition ModRef.h:383
TypedTrackingMDRef< MDNode > TrackingMDNodeRef
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
LLVM_ABI unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
bool capturesAddress(CaptureComponents CC)
Definition ModRef.h:387
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ Store
The extracted value is stored (ExtractElement only).
constexpr from_range_t from_range
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
auto cast_or_null(const Y &Val)
Definition Casting.h:714
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
bool capturesFullProvenance(CaptureComponents CC)
Definition ModRef.h:396
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1652
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
CaptureComponents
Components of the pointer that may be captured.
Definition ModRef.h:365
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
@ Other
Any other memory.
Definition ModRef.h:68
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1901
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition STLExtras.h:2035
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
bool capturesAll(CaptureComponents CC)
Definition ModRef.h:404
std::enable_if_t< std::is_unsigned_v< T >, T > SaturatingAdd(T X, T Y, bool *ResultOverflowed=nullptr)
Add two unsigned integers, X and Y, of type T.
Definition MathExtras.h:604
bool capturesNothing(CaptureComponents CC)
Definition ModRef.h:375
#define N
static constexpr bool value
static std::false_type check(...)
static std::true_type check(SameType< void(U::*)(unsigned), &U::setHash > *)
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:774
Single metadata attachment, forms linked list ended by index 0.
static LLVM_ABI const char * BranchWeights
Function object to check whether the first component of a container supported by std::get (like std::...
Definition STLExtras.h:1455