61 :
Value(Ty, MetadataAsValueVal), MD(MD) {
88 auto *
N = dyn_cast<MDNode>(MD);
89 if (!
N ||
N->getNumOperands() != 1)
92 if (!
N->getOperand(0))
96 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
N->getOperand(0)))
115 return Store.lookup(MD);
118void MetadataAsValue::handleChangedMetadata(
Metadata *MD) {
124 Store.erase(this->MD);
129 auto *&Entry = Store[MD];
141void MetadataAsValue::track() {
146void MetadataAsValue::untrack() {
161 auto OldMD =
static_cast<Metadata **
>(Old);
165 if (OldMD && isa<ValueAsMetadata>(*OldMD) && !New) {
166 auto *OldVAM = cast<ValueAsMetadata>(*OldMD);
172void DebugValueUser::trackDebugValue(
size_t Idx) {
173 assert(
Idx < 3 &&
"Invalid debug value index.");
179void DebugValueUser::trackDebugValues() {
185void DebugValueUser::untrackDebugValue(
size_t Idx) {
186 assert(
Idx < 3 &&
"Invalid debug value index.");
192void DebugValueUser::untrackDebugValues() {
199 assert(DebugValueUser::operator==(
X) &&
"Expected values to match");
203 X.DebugValues.fill(
nullptr);
207 assert(
Ref &&
"Expected live reference");
209 "Reference without owner must be direct");
210 if (
auto *R = ReplaceableMetadataImpl::getOrCreate(MD)) {
211 R->addRef(
Ref, Owner);
214 if (
auto *PH = dyn_cast<DistinctMDOperandPlaceholder>(&MD)) {
215 assert(!PH->Use &&
"Placeholders can only be used once");
216 assert(!Owner &&
"Unexpected callback to owner");
224 assert(
Ref &&
"Expected live reference");
225 if (
auto *R = ReplaceableMetadataImpl::getIfExists(MD))
227 else if (
auto *PH = dyn_cast<DistinctMDOperandPlaceholder>(&MD))
232 assert(
Ref &&
"Expected live reference");
233 assert(New &&
"Expected live reference");
235 if (
auto *R = ReplaceableMetadataImpl::getIfExists(MD)) {
236 R->moveRef(
Ref, New, MD);
239 assert(!isa<DistinctMDOperandPlaceholder>(MD) &&
240 "Unexpected move of an MDOperand");
242 "Expected un-replaceable metadata, since we didn't move a reference");
247 return ReplaceableMetadataImpl::isReplaceable(MD);
252 for (
auto Pair : UseMap) {
253 OwnerTy Owner = Pair.second.first;
256 if (!isa<Metadata *>(Owner))
258 Metadata *OwnerMD = cast<Metadata *>(Owner);
260 MDUsersWithID.
push_back(&UseMap[Pair.first]);
262 llvm::sort(MDUsersWithID, [](
auto UserA,
auto UserB) {
263 return UserA->second < UserB->second;
266 for (
auto *UserWithID : MDUsersWithID)
267 MDUsers.
push_back(cast<Metadata *>(UserWithID->first));
274 for (
auto Pair : UseMap) {
275 OwnerTy Owner = Pair.second.first;
280 DVRUsersWithID.
push_back(&UseMap[Pair.first]);
287 llvm::sort(DVRUsersWithID, [](
auto UserA,
auto UserB) {
288 return UserA->second > UserB->second;
291 for (
auto UserWithID : DVRUsersWithID)
296void ReplaceableMetadataImpl::addRef(
void *
Ref, OwnerTy Owner) {
298 UseMap.insert(std::make_pair(
Ref, std::make_pair(Owner, NextIndex)))
301 assert(WasInserted &&
"Expected to add a reference");
304 assert(NextIndex != 0 &&
"Unexpected overflow");
307void ReplaceableMetadataImpl::dropRef(
void *
Ref) {
308 bool WasErased = UseMap.erase(
Ref);
310 assert(WasErased &&
"Expected to drop a reference");
313void ReplaceableMetadataImpl::moveRef(
void *
Ref,
void *New,
315 auto I = UseMap.find(
Ref);
316 assert(
I != UseMap.end() &&
"Expected to move a reference");
317 auto OwnerAndIndex =
I->second;
319 bool WasInserted = UseMap.insert(std::make_pair(New, OwnerAndIndex)).second;
321 assert(WasInserted &&
"Expected to add a reference");
326 "Reference without owner must be direct");
327 assert((OwnerAndIndex.first || *
static_cast<Metadata **
>(New) == &MD) &&
328 "Reference without owner must be direct");
332 if (!
C.isUsedByMetadata()) {
338 auto I = Store.find(&
C);
341 std::pair<void *, std::pair<MetadataTracking::OwnerTy, uint64_t>>;
345 for (
const auto &Pair :
Uses) {
349 if (!isa<Metadata *>(Owner))
351 auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
354 if (isa<DINode>(OwnerMD)) {
355 OwnerMD->handleChangedOperand(
366 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
369 return L.second.second < R.second.second;
371 for (
const auto &Pair :
Uses) {
374 if (!UseMap.count(Pair.first))
377 OwnerTy Owner = Pair.second.first;
384 UseMap.erase(Pair.first);
389 if (isa<MetadataAsValue *>(Owner)) {
390 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(MD);
400 Metadata *OwnerMD = cast<Metadata *>(Owner);
402#define HANDLE_METADATA_LEAF(CLASS) \
403 case Metadata::CLASS##Kind: \
404 cast<CLASS>(OwnerMD)->handleChangedOperand(Pair.first, MD); \
406#include "llvm/IR/Metadata.def"
411 assert(UseMap.empty() &&
"Expected all uses to be replaced");
424 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
427 return L.second.second < R.second.second;
430 for (
const auto &Pair :
Uses) {
431 auto Owner = Pair.second.first;
438 auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
441 if (OwnerMD->isResolved())
443 OwnerMD->decrementUnresolvedOperandCount();
451 if (
auto *
N = dyn_cast<MDNode>(&MD)) {
452 return !
N->isResolved() ||
N->isAlwaysReplaceable()
453 ?
N->Context.getOrCreateReplaceableUses()
456 if (
auto ArgList = dyn_cast<DIArgList>(&MD))
458 return dyn_cast<ValueAsMetadata>(&MD);
462 if (
auto *
N = dyn_cast<MDNode>(&MD)) {
463 return !
N->isResolved() ||
N->isAlwaysReplaceable()
464 ?
N->Context.getReplaceableUses()
467 if (
auto ArgList = dyn_cast<DIArgList>(&MD))
469 return dyn_cast<ValueAsMetadata>(&MD);
472bool ReplaceableMetadataImpl::isReplaceable(
const Metadata &MD) {
473 if (
auto *
N = dyn_cast<MDNode>(&MD))
474 return !
N->isResolved() ||
N->isAlwaysReplaceable();
475 return isa<ValueAsMetadata>(&MD) || isa<DIArgList>(&MD);
479 assert(V &&
"Expected value");
480 if (
auto *
A = dyn_cast<Argument>(V)) {
481 if (
auto *Fn =
A->getParent())
482 return Fn->getSubprogram();
487 if (
auto *Fn = BB->getParent())
488 return Fn->getSubprogram();
496 assert(V &&
"Unexpected null Value");
498 auto &
Context = V->getContext();
501 assert((isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) &&
502 "Expected constant or function-local value");
503 assert(!V->IsUsedByMD &&
"Expected this to be the only metadata use");
504 V->IsUsedByMD =
true;
505 if (
auto *
C = dyn_cast<Constant>(V))
515 assert(V &&
"Unexpected null Value");
516 return V->getContext().pImpl->ValuesAsMetadata.lookup(V);
520 assert(V &&
"Expected valid value");
522 auto &Store = V->getType()->getContext().pImpl->ValuesAsMetadata;
523 auto I = Store.find(V);
524 if (
I == Store.end())
529 assert(MD &&
"Expected valid metadata");
540 assert(To &&
"Expected valid value");
541 assert(
From != To &&
"Expected changed value");
546 auto I = Store.find(
From);
547 if (
I == Store.end()) {
548 assert(!
From->IsUsedByMD &&
"Expected From not to be used by metadata");
553 assert(
From->IsUsedByMD &&
"Expected From to be used by metadata");
554 From->IsUsedByMD =
false;
556 assert(MD &&
"Expected valid metadata");
560 if (isa<LocalAsMetadata>(MD)) {
561 if (
auto *
C = dyn_cast<Constant>(To)) {
574 }
else if (!isa<Constant>(To)) {
581 auto *&Entry = Store[To];
602 auto I = Store.try_emplace(Str);
603 auto &MapEntry =
I.first->getValue();
606 MapEntry.Entry = &*
I.first;
611 assert(Entry &&
"Expected to find string map entry");
612 return Entry->first();
621#define HANDLE_MDNODE_LEAF(CLASS) \
623 alignof(uint64_t) >= alignof(CLASS), \
624 "Alignment is insufficient after objects prepended to " #CLASS);
625#include "llvm/IR/Metadata.def"
632 char *Mem =
reinterpret_cast<char *
>(::operator
new(AllocSize +
Size));
633 Header *
H =
new (Mem + AllocSize -
sizeof(Header)) Header(NumOps, Storage);
634 return reinterpret_cast<void *
>(
H + 1);
637void MDNode::operator
delete(
void *
N) {
638 Header *
H =
reinterpret_cast<Header *
>(
N) - 1;
639 void *Mem =
H->getAllocation();
641 ::operator
delete(Mem);
658 countUnresolvedOperands();
665#define HANDLE_MDNODE_LEAF(CLASS) \
667 return cast<CLASS>(this)->cloneImpl();
668#include "llvm/IR/Metadata.def"
672MDNode::Header::Header(
size_t NumOps, StorageType Storage) {
673 IsLarge = isLarge(NumOps);
674 IsResizable = isResizable(Storage);
675 SmallSize = getSmallSize(NumOps, IsResizable, IsLarge);
678 new (getLargePtr()) LargeStorageVector();
679 getLarge().resize(NumOps);
682 SmallNumOps = NumOps;
684 for (
MDOperand *E = O + SmallSize; O != E;)
688MDNode::Header::~Header() {
690 getLarge().~LargeStorageVector();
698void *MDNode::Header::getSmallPtr() {
699 static_assert(
alignof(
MDOperand) <=
alignof(Header),
700 "MDOperand too strongly aligned");
701 return reinterpret_cast<char *
>(
const_cast<Header *
>(
this)) -
705void MDNode::Header::resize(
size_t NumOps) {
706 assert(IsResizable &&
"Node is not resizable");
707 if (operands().
size() == NumOps)
711 getLarge().resize(NumOps);
712 else if (NumOps <= SmallSize)
715 resizeSmallToLarge(NumOps);
718void MDNode::Header::resizeSmall(
size_t NumOps) {
719 assert(!IsLarge &&
"Expected a small MDNode");
720 assert(NumOps <= SmallSize &&
"NumOps too large for small resize");
723 assert(NumOps != ExistingOps.
size() &&
"Expected a different size");
725 int NumNew = (int)NumOps - (
int)ExistingOps.
size();
727 for (
int I = 0, E = NumNew;
I < E; ++
I)
729 for (
int I = 0, E = NumNew;
I > E; --
I)
731 SmallNumOps = NumOps;
732 assert(O == operands().
end() &&
"Operands not (un)initialized until the end");
735void MDNode::Header::resizeSmallToLarge(
size_t NumOps) {
736 assert(!IsLarge &&
"Expected a small MDNode");
737 assert(NumOps > SmallSize &&
"Expected NumOps to be larger than allocation");
738 LargeStorageVector NewOps;
739 NewOps.resize(NumOps);
742 new (getLargePtr()) LargeStorageVector(std::move(NewOps));
747 if (
auto *
N = dyn_cast_or_null<MDNode>(
Op))
748 return !
N->isResolved();
752void MDNode::countUnresolvedOperands() {
758void MDNode::makeUniqued() {
764 Op.reset(
Op.get(),
this);
768 countUnresolvedOperands();
770 dropReplaceableUses();
777void MDNode::makeDistinct() {
782 dropReplaceableUses();
794 dropReplaceableUses();
799void MDNode::dropReplaceableUses() {
803 if (
Context.hasReplaceableUses())
804 Context.takeReplaceableUses()->resolveAllUses();
817 decrementUnresolvedOperandCount();
820void MDNode::decrementUnresolvedOperandCount() {
831 dropReplaceableUses();
844 auto *
N = dyn_cast_or_null<MDNode>(
Op);
849 "Expected all forward declarations to be resolved");
850 if (!
N->isResolved())
859MDNode *MDNode::replaceWithPermanentImpl() {
863 return replaceWithDistinctImpl();
865#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
868#include "llvm/IR/Metadata.def"
873 return replaceWithDistinctImpl();
874 return replaceWithUniquedImpl();
877MDNode *MDNode::replaceWithUniquedImpl() {
879 MDNode *UniquedNode = uniquify();
881 if (UniquedNode ==
this) {
892MDNode *MDNode::replaceWithDistinctImpl() {
897void MDTuple::recalculateHash() {
898 setHash(MDTupleInfo::KeyTy::calculateHash(
this));
904 if (
Context.hasReplaceableUses()) {
905 Context.getReplaceableUses()->resolveAllUses(
false);
906 (void)
Context.takeReplaceableUses();
910void MDNode::handleChangedOperand(
void *
Ref,
Metadata *New) {
927 if (New ==
this || (!New && Old && isa<ConstantAsMetadata>(Old))) {
938 resolveAfterOperandChange(Old, New);
950 if (
Context.hasReplaceableUses())
960void MDNode::deleteAsSubclass() {
964#define HANDLE_MDNODE_LEAF(CLASS) \
966 delete cast<CLASS>(this); \
968#include "llvm/IR/Metadata.def"
972template <
class T,
class InfoT>
981template <
class NodeTy>
struct MDNode::HasCachedHash {
984 template <
class U, U Val>
struct SFINAE {};
987 static Yes &
check(SFINAE<
void (U::*)(
unsigned), &U::setHash> *);
990 static const bool value =
sizeof(check<NodeTy>(
nullptr)) ==
sizeof(
Yes);
993MDNode *MDNode::uniquify() {
1000#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1001 case CLASS##Kind: { \
1002 CLASS *SubclassThis = cast<CLASS>(this); \
1003 std::integral_constant<bool, HasCachedHash<CLASS>::value> \
1004 ShouldRecalculateHash; \
1005 dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash); \
1006 return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s); \
1008#include "llvm/IR/Metadata.def"
1012void MDNode::eraseFromStore() {
1016#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1018 getContext().pImpl->CLASS##s.erase(cast<CLASS>(this)); \
1020#include "llvm/IR/Metadata.def"
1025 StorageType Storage,
bool ShouldCreate) {
1028 MDTupleInfo::KeyTy
Key(MDs);
1033 Hash =
Key.getHash();
1035 assert(ShouldCreate &&
"Expected non-uniqued nodes to always be created");
1044 assert(
N->isTemporary() &&
"Expected temporary node");
1045 N->replaceAllUsesWith(
nullptr);
1046 N->deleteAsSubclass();
1050 assert(!
Context.hasReplaceableUses() &&
"Unexpected replaceable uses");
1059#define HANDLE_MDNODE_LEAF(CLASS) \
1060 case CLASS##Kind: { \
1061 std::integral_constant<bool, HasCachedHash<CLASS>::value> ShouldResetHash; \
1062 dispatchResetHash(cast<CLASS>(this), ShouldResetHash); \
1065#include "llvm/IR/Metadata.def"
1097 if (
MDNode *
N = dyn_cast_or_null<MDNode>(Ops[0]))
1098 if (
N->getNumOperands() == Ops.
size() &&
N ==
N->getOperand(0)) {
1099 for (
unsigned I = 1, E = Ops.
size();
I != E; ++
I)
1100 if (Ops[
I] !=
N->getOperand(
I))
1115 MDs.
insert(
B->op_begin(),
B->op_end());
1145 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1150 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1158 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1163 return MDs.
empty() ? nullptr
1171 APFloat AVal = mdconst::extract<ConstantFP>(
A->getOperand(0))->getValueAPF();
1172 APFloat BVal = mdconst::extract<ConstantFP>(
B->getOperand(0))->getValueAPF();
1184 assert(
A &&
B && AInstr && BInstr &&
"Caller should guarantee");
1189 assert(
A->getNumOperands() >= 2 &&
B->getNumOperands() >= 2 &&
1190 "!prof annotations should have no less than 2 operands");
1191 MDString *AMDS = dyn_cast<MDString>(
A->getOperand(0));
1192 MDString *BMDS = dyn_cast<MDString>(
B->getOperand(0));
1194 assert(AMDS !=
nullptr && BMDS !=
nullptr &&
1195 "first operand should be a non-null MDString");
1198 if (AProfName ==
"branch_weights" && BProfName ==
"branch_weights") {
1200 mdconst::dyn_extract<ConstantInt>(
A->getOperand(1));
1202 mdconst::dyn_extract<ConstantInt>(
B->getOperand(1));
1203 assert(AInstrWeight && BInstrWeight &&
"verified by LLVM verifier");
1205 {MDHelper.createString(
"branch_weights"),
1206 MDHelper.createConstant(ConstantInt::get(
1224 "Caller should guarantee");
1226 "Caller should guarantee");
1228 const CallInst *ACall = dyn_cast<CallInst>(AInstr);
1229 const CallInst *BCall = dyn_cast<CallInst>(BInstr);
1234 return mergeDirectCallProfMetadata(
A,
B, AInstr, BInstr);
1242 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
1253 APInt LB = EndPoints[
Size - 2]->getValue();
1254 APInt LE = EndPoints[
Size - 1]->getValue();
1259 EndPoints[
Size - 2] =
1260 cast<ConstantInt>(ConstantInt::get(Ty, Union.getLower()));
1261 EndPoints[
Size - 1] =
1262 cast<ConstantInt>(ConstantInt::get(Ty, Union.getUpper()));
1270 if (!EndPoints.
empty())
1294 int AN =
A->getNumOperands() / 2;
1295 int BN =
B->getNumOperands() / 2;
1296 while (AI < AN && BI < BN) {
1297 ConstantInt *ALow = mdconst::extract<ConstantInt>(
A->getOperand(2 * AI));
1298 ConstantInt *BLow = mdconst::extract<ConstantInt>(
B->getOperand(2 * BI));
1302 mdconst::extract<ConstantInt>(
A->getOperand(2 * AI + 1)));
1306 mdconst::extract<ConstantInt>(
B->getOperand(2 * BI + 1)));
1311 addRange(EndPoints, mdconst::extract<ConstantInt>(
A->getOperand(2 * AI)),
1312 mdconst::extract<ConstantInt>(
A->getOperand(2 * AI + 1)));
1316 addRange(EndPoints, mdconst::extract<ConstantInt>(
B->getOperand(2 * BI)),
1317 mdconst::extract<ConstantInt>(
B->getOperand(2 * BI + 1)));
1328 for (
unsigned i = 0; i <
Size - 2; ++i) {
1329 EndPoints[i] = EndPoints[i + 2];
1337 if (EndPoints.
size() == 2) {
1338 ConstantRange Range(EndPoints[0]->getValue(), EndPoints[1]->getValue());
1339 if (Range.isFullSet())
1345 for (
auto *
I : EndPoints)
1354 ConstantInt *AVal = mdconst::extract<ConstantInt>(
A->getOperand(0));
1355 ConstantInt *BVal = mdconst::extract<ConstantInt>(
B->getOperand(0));
1369NamedMDNode::NamedMDNode(
const Twine &
N)
1378 return (
unsigned)
getNMDOps(Operands).size();
1384 return cast_or_null<MDNode>(
N);
1405 for (
const auto &
A : Attachments)
1412 for (
const auto &
A : Attachments)
1414 Result.push_back(
A.Node);
1419 for (
const auto &
A : Attachments)
1420 Result.emplace_back(
A.MDKind,
A.Node);
1424 if (Result.size() > 1)
1443 if (Attachments.size() == 1 && Attachments.back().MDKind ==
ID) {
1444 Attachments.pop_back();
1448 auto OldSize = Attachments.size();
1451 return OldSize != Attachments.size();
1464 return Attachements.
lookup(KindID);
1481 "bit out of sync with hash table");
1488 assert(isa<Instruction>(
this) || isa<GlobalObject>(
this));
1496 Info.set(KindID, Node);
1502 "bit out of sync with hash table");
1522 assert(isa<Instruction>(
this) || isa<GlobalObject>(
this));
1538 bool Changed = Store.erase(KindID);
1550 assert(!
Info.empty() &&
"bit out of sync with hash table");
1552 return Pred(
I.MDKind,
I.Node);
1563 "bit out of sync with hash table");
1577 if (KindID == LLVMContext::MD_dbg)
1583 if (DbgLoc && Pred(LLVMContext::MD_dbg, DbgLoc.
getAsMDNode()))
1597 KnownSet.
insert(LLVMContext::MD_DIAssignID);
1600 return !KnownSet.
count(MDKind);
1604void Instruction::updateDIAssignIDMapping(
DIAssignID *
ID) {
1607 cast_or_null<DIAssignID>(
getMetadata(LLVMContext::MD_DIAssignID))) {
1609 if (
ID == CurrentID)
1613 auto InstrsIt = IDToInstrs.find(CurrentID);
1614 assert(InstrsIt != IDToInstrs.end() &&
1615 "Expect existing attachment to be mapped");
1617 auto &InstVec = InstrsIt->second;
1619 assert(InstIt != InstVec.end() &&
1620 "Expect instruction to be mapped to attachment");
1624 if (InstVec.size() == 1)
1625 IDToInstrs.erase(InstrsIt);
1627 InstVec.erase(InstIt);
1632 IDToInstrs[
ID].push_back(
this);
1640 if (KindID == LLVMContext::MD_dbg) {
1646 if (KindID == LLVMContext::MD_DIAssignID) {
1650 assert((!Node || !Node->isTemporary()) &&
1651 "Temporary DIAssignIDs are invalid");
1652 updateDIAssignIDMapping(cast_or_null<DIAssignID>(Node));
1660 if (
auto *Existing =
getMetadata(LLVMContext::MD_annotation)) {
1663 auto *Tuple = cast<MDTuple>(Existing);
1664 for (
auto &
N : Tuple->operands()) {
1665 if (isa<MDString>(
N.get())) {
1669 auto *MDAnnotationTuple = cast<MDTuple>(
N);
1670 if (
any_of(MDAnnotationTuple->operands(), [&AnnotationsSet](
auto &
Op) {
1671 return AnnotationsSet.contains(cast<MDString>(Op)->getString());
1690 if (
auto *Existing =
getMetadata(LLVMContext::MD_annotation)) {
1691 auto *Tuple = cast<MDTuple>(Existing);
1692 for (
auto &
N : Tuple->operands()) {
1693 if (isa<MDString>(
N.get()) &&
1694 cast<MDString>(
N.get())->getString() ==
Name)
1712 Result.TBAA =
Info.lookup(LLVMContext::MD_tbaa);
1713 Result.TBAAStruct =
Info.lookup(LLVMContext::MD_tbaa_struct);
1714 Result.Scope =
Info.lookup(LLVMContext::MD_alias_scope);
1715 Result.NoAlias =
Info.lookup(LLVMContext::MD_noalias);
1722 setMetadata(LLVMContext::MD_tbaa_struct,
N.TBAAStruct);
1732void Instruction::getAllMetadataImpl(
1739 std::make_pair((
unsigned)LLVMContext::MD_dbg, DbgLoc.
getAsMDNode()));
1748 getOpcode() == Instruction::IndirectBr ||
1750 "Looking for branch weights on something besides branch");
1752 return ::extractProfTotalWeight(*
this, TotalVal);
1757 Other->getAllMetadata(MDs);
1758 for (
auto &MD : MDs) {
1760 if (
Offset != 0 && MD.first == LLVMContext::MD_type) {
1761 auto *OffsetConst = cast<ConstantInt>(
1762 cast<ConstantAsMetadata>(MD.second->getOperand(0))->getValue());
1763 Metadata *TypeId = MD.second->getOperand(1);
1765 OffsetConst->getType(), OffsetConst->getValue() +
Offset));
1773 auto *Attachment = MD.second;
1774 if (
Offset != 0 && MD.first == LLVMContext::MD_dbg) {
1778 auto *GVE = cast<DIGlobalVariableExpression>(Attachment);
1779 GV = GVE->getVariable();
1780 E = GVE->getExpression();
1785 std::vector<uint64_t> Elements(OrigElements.
size() + 2);
1786 Elements[0] = dwarf::DW_OP_plus_uconst;
1788 llvm::copy(OrigElements, Elements.begin() + 2);
1798 LLVMContext::MD_type,
1818 cast<ConstantAsMetadata>(MD->getOperand(0))->getValue())
1820 assert(Val <= 2 &&
"unknown vcall visibility!");
1831 return cast_or_null<DISubprogram>(
getMetadata(LLVMContext::MD_dbg));
1837 return CU->getDebugInfoForProfiling();
1852 GVs.
push_back(cast<DIGlobalVariableExpression>(MD));
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)
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Given that RA is a live value
This file defines the DenseSet and SmallDenseSet classes.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Rewrite Partial Register Uses
mir Rename Register Operands
Module.h This file contains the declarations for the Module class.
This file contains the declarations for profiling metadata utility functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 SmallVector class.
Class for arbitrary precision integers.
bool slt(const APInt &RHS) const
Signed less than comparison.
This is a simple wrapper around an MDNode which provides a higher-level interface by hiding the detai...
Annotations lets you mark points and ranges inside source code, for tests:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
LLVM Basic Block Representation.
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.
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
This class represents a range of values.
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.
ArrayRef< uint64_t > getElements() const
A pair of DIGlobalVariable and DIExpression.
This class represents an Operation in the Expression.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
MDNode * getAsMDNode() const
Return this as a bar MDNode.
Base class for tracking ValueAsMetadata/DIArgLists with user lookups and Owner callbacks outside of V...
void handleChangedValue(void *Old, Metadata *NewDebugValue)
To be called by ReplaceableMetadataImpl::replaceAllUsesWith, where Old is a pointer to one of the poi...
std::array< Metadata *, 3 > DebugValues
void resetDebugValue(size_t Idx, Metadata *DebugValue)
DbgVariableRecord * getUser()
Implements a dense probed hash-table based set.
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.
void addTypeMetadata(unsigned Offset, Metadata *TypeID)
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
void copyMetadata(const GlobalObject *Src, unsigned Offset)
Copy metadata from Src, adjusting offsets by Offset.
VCallVisibility getVCallVisibility() const
bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
void setVCallVisibilityMetadata(VCallVisibility Visibility)
void getDebugInfo(SmallVectorImpl< DIGlobalVariableExpression * > &GVs) const
Fill the vector with all debug info attachements.
void addDebugInfo(DIGlobalVariableExpression *GV)
Attach a DIGlobalVariableExpression.
void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
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.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
void setNoSanitizeMetadata()
Sets the nosanitize metadata on this instruction.
AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void dropUnknownNonDebugMetadata()
void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)
Erase all metadata that matches the predicate.
DenseMap< Metadata *, MetadataAsValue * > MetadataAsValues
StringMap< MDString, BumpPtrAllocator > MDStringCache
DenseMap< DIAssignID *, SmallVector< Instruction *, 1 > > AssignmentIDToInstrs
Map DIAssignID -> Instructions with that attachment.
std::vector< MDNode * > DistinctMDNodes
DenseMap< const Value *, MDAttachments > ValueMetadata
Collection of metadata used in this context.
DenseMap< Value *, ValueAsMetadata * > ValuesAsMetadata
This is an important class for using LLVM in a threaded context.
unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
LLVMContextImpl *const pImpl
Multimap-like storage for metadata attachments.
void insert(unsigned ID, MDNode &MD)
Adds an attachment to a particular node.
void get(unsigned ID, SmallVectorImpl< MDNode * > &Result) const
Appends all attachments with the given ID to Result in insertion order.
void getAll(SmallVectorImpl< std::pair< unsigned, MDNode * > > &Result) const
Appends all attachments for the global to Result, sorting by attachment ID.
void set(unsigned ID, MDNode *MD)
Set an attachment to a particular node.
MDNode * lookup(unsigned ID) const
Returns the first attachment with the given ID or nullptr if no such attachment exists.
bool erase(unsigned ID)
Remove attachments with the given ID.
MDString * createString(StringRef Str)
Return the given string as metadata.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
void resolveCycles()
Resolve cycles.
mutable_op_range mutable_operands()
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
static MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
void resolve()
Resolve a unique, unresolved node.
const MDOperand & getOperand(unsigned I) const
void storeDistinctInContext()
ArrayRef< MDOperand > operands() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDNode * getMergedProfMetadata(MDNode *A, MDNode *B, const Instruction *AInstr, const Instruction *BInstr)
Merge !prof metadata from two instructions.
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
void setNumUnresolved(unsigned N)
unsigned getNumOperands() const
Return number of MDNode operands.
MDOperand * mutable_begin()
TempMDNode clone() const
Create a (temporary) clone of this.
static MDNode * getMostGenericRange(MDNode *A, MDNode *B)
void setOperand(unsigned I, Metadata *New)
Set an operand.
MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2=std::nullopt)
bool isResolved() const
Check if node is fully resolved.
op_iterator op_begin() const
static MDNode * intersect(MDNode *A, MDNode *B)
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
LLVMContext & getContext() const
static MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)
unsigned getNumUnresolved() const
Tracking metadata reference owned by Metadata.
StringRef getString() const
static MDString * get(LLVMContext &Context, StringRef Str)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
void setOperand(unsigned I, MDNode *New)
StringRef getName() const
void dropAllReferences()
Remove all uses and clear node vector.
void eraseFromParent()
Drop all references and remove the node from parent module.
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
void clearOperands()
Drop all references to this node's operands.
Module * getParent()
Get the module that holds this named metadata collection.
void addOperand(MDNode *M)
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
T get() const
Returns the value of the specified pointer type.
bool is() const
Test if the Union currently holds the type matching T.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
ArrayRef< value_type > getArrayRef() const
bool remove_if(UnaryPredicate P)
Remove items from the set vector based on a predicate function.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
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.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(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.
StringRef - Represent a constant reference to a string, i.e.
Tracking metadata reference.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getMetadataTy(LLVMContext &C)
TypeID
Definitions of all of the base types for the Type system.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt64Ty(LLVMContext &C)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasMetadata() const
Return true if this value has any metadata attached to it.
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
MDNode * getMetadataImpl(unsigned KindID) const
Get metadata for the given kind, if any.
bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)
Erase all metadata attachments matching the given predicate.
LLVMContext & getContext() const
All values hold a context through their type.
void clearMetadata()
Erase all metadata attached to this Value.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
const_iterator end(StringRef path)
Get end iterator over path.
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.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
void stable_sort(R &&Range)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
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.
static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)
TypedTrackingMDRef< MDNode > TrackingMDNodeRef
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
void sort(IteratorTy Start, IteratorTy End)
@ Ref
The access may reference the value stored in memory.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
OutputIt copy(R &&Range, OutputIt Out)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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...
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
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.
static Yes & check(SFINAE< void(U::*)(unsigned), &U::setHash > *)
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Function object to check whether the first component of a container supported by std::get (like std::...