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) {
350 if (isa<MetadataAsValue *>(Owner)) {
351 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(
355 if (!isa<Metadata *>(Owner))
357 auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
360 if (isa<DINode>(OwnerMD)) {
361 OwnerMD->handleChangedOperand(
372 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
375 return L.second.second < R.second.second;
377 for (
const auto &Pair :
Uses) {
380 if (!UseMap.count(Pair.first))
383 OwnerTy Owner = Pair.second.first;
390 UseMap.erase(Pair.first);
395 if (isa<MetadataAsValue *>(Owner)) {
396 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(MD);
406 Metadata *OwnerMD = cast<Metadata *>(Owner);
408#define HANDLE_METADATA_LEAF(CLASS) \
409 case Metadata::CLASS##Kind: \
410 cast<CLASS>(OwnerMD)->handleChangedOperand(Pair.first, MD); \
412#include "llvm/IR/Metadata.def"
417 assert(UseMap.empty() &&
"Expected all uses to be replaced");
430 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
433 return L.second.second < R.second.second;
436 for (
const auto &Pair :
Uses) {
437 auto Owner = Pair.second.first;
444 auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
447 if (OwnerMD->isResolved())
449 OwnerMD->decrementUnresolvedOperandCount();
457 if (
auto *
N = dyn_cast<MDNode>(&MD)) {
458 return !
N->isResolved() ||
N->isAlwaysReplaceable()
459 ?
N->Context.getOrCreateReplaceableUses()
462 if (
auto ArgList = dyn_cast<DIArgList>(&MD))
464 return dyn_cast<ValueAsMetadata>(&MD);
468 if (
auto *
N = dyn_cast<MDNode>(&MD)) {
469 return !
N->isResolved() ||
N->isAlwaysReplaceable()
470 ?
N->Context.getReplaceableUses()
473 if (
auto ArgList = dyn_cast<DIArgList>(&MD))
475 return dyn_cast<ValueAsMetadata>(&MD);
478bool ReplaceableMetadataImpl::isReplaceable(
const Metadata &MD) {
479 if (
auto *
N = dyn_cast<MDNode>(&MD))
480 return !
N->isResolved() ||
N->isAlwaysReplaceable();
481 return isa<ValueAsMetadata>(&MD) || isa<DIArgList>(&MD);
485 assert(V &&
"Expected value");
486 if (
auto *
A = dyn_cast<Argument>(V)) {
487 if (
auto *Fn =
A->getParent())
488 return Fn->getSubprogram();
493 if (
auto *Fn = BB->getParent())
494 return Fn->getSubprogram();
502 assert(V &&
"Unexpected null Value");
504 auto &Context = V->getContext();
507 assert((isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) &&
508 "Expected constant or function-local value");
509 assert(!V->IsUsedByMD &&
"Expected this to be the only metadata use");
510 V->IsUsedByMD =
true;
511 if (
auto *
C = dyn_cast<Constant>(V))
521 assert(V &&
"Unexpected null Value");
522 return V->getContext().pImpl->ValuesAsMetadata.lookup(V);
526 assert(V &&
"Expected valid value");
528 auto &Store = V->getType()->getContext().pImpl->ValuesAsMetadata;
529 auto I = Store.find(V);
530 if (
I == Store.end())
535 assert(MD &&
"Expected valid metadata");
546 assert(To &&
"Expected valid value");
547 assert(
From != To &&
"Expected changed value");
552 auto I = Store.find(
From);
553 if (
I == Store.end()) {
554 assert(!
From->IsUsedByMD &&
"Expected From not to be used by metadata");
559 assert(
From->IsUsedByMD &&
"Expected From to be used by metadata");
560 From->IsUsedByMD =
false;
562 assert(MD &&
"Expected valid metadata");
566 if (isa<LocalAsMetadata>(MD)) {
567 if (
auto *
C = dyn_cast<Constant>(To)) {
580 }
else if (!isa<Constant>(To)) {
587 auto *&Entry = Store[To];
608 auto I = Store.try_emplace(Str);
609 auto &MapEntry =
I.first->getValue();
612 MapEntry.Entry = &*
I.first;
617 assert(Entry &&
"Expected to find string map entry");
618 return Entry->first();
627#define HANDLE_MDNODE_LEAF(CLASS) \
629 alignof(uint64_t) >= alignof(CLASS), \
630 "Alignment is insufficient after objects prepended to " #CLASS);
631#include "llvm/IR/Metadata.def"
638 char *Mem =
reinterpret_cast<char *
>(::operator
new(AllocSize +
Size));
639 Header *
H =
new (Mem + AllocSize -
sizeof(Header)) Header(NumOps, Storage);
640 return reinterpret_cast<void *
>(
H + 1);
643void MDNode::operator
delete(
void *
N) {
644 Header *
H =
reinterpret_cast<Header *
>(
N) - 1;
645 void *Mem =
H->getAllocation();
647 ::operator
delete(Mem);
664 countUnresolvedOperands();
671#define HANDLE_MDNODE_LEAF(CLASS) \
673 return cast<CLASS>(this)->cloneImpl();
674#include "llvm/IR/Metadata.def"
678MDNode::Header::Header(
size_t NumOps, StorageType Storage) {
679 IsLarge = isLarge(NumOps);
680 IsResizable = isResizable(Storage);
681 SmallSize = getSmallSize(NumOps, IsResizable, IsLarge);
684 new (getLargePtr()) LargeStorageVector();
685 getLarge().resize(NumOps);
688 SmallNumOps = NumOps;
690 for (
MDOperand *E = O + SmallSize; O != E;)
694MDNode::Header::~Header() {
696 getLarge().~LargeStorageVector();
704void *MDNode::Header::getSmallPtr() {
705 static_assert(
alignof(
MDOperand) <=
alignof(Header),
706 "MDOperand too strongly aligned");
707 return reinterpret_cast<char *
>(
const_cast<Header *
>(
this)) -
711void MDNode::Header::resize(
size_t NumOps) {
712 assert(IsResizable &&
"Node is not resizable");
713 if (operands().
size() == NumOps)
717 getLarge().resize(NumOps);
718 else if (NumOps <= SmallSize)
721 resizeSmallToLarge(NumOps);
724void MDNode::Header::resizeSmall(
size_t NumOps) {
725 assert(!IsLarge &&
"Expected a small MDNode");
726 assert(NumOps <= SmallSize &&
"NumOps too large for small resize");
729 assert(NumOps != ExistingOps.
size() &&
"Expected a different size");
731 int NumNew = (int)NumOps - (
int)ExistingOps.
size();
733 for (
int I = 0, E = NumNew;
I < E; ++
I)
735 for (
int I = 0, E = NumNew;
I > E; --
I)
737 SmallNumOps = NumOps;
738 assert(O == operands().
end() &&
"Operands not (un)initialized until the end");
741void MDNode::Header::resizeSmallToLarge(
size_t NumOps) {
742 assert(!IsLarge &&
"Expected a small MDNode");
743 assert(NumOps > SmallSize &&
"Expected NumOps to be larger than allocation");
744 LargeStorageVector NewOps;
745 NewOps.resize(NumOps);
748 new (getLargePtr()) LargeStorageVector(std::move(NewOps));
753 if (
auto *
N = dyn_cast_or_null<MDNode>(
Op))
754 return !
N->isResolved();
758void MDNode::countUnresolvedOperands() {
764void MDNode::makeUniqued() {
770 Op.reset(
Op.get(),
this);
774 countUnresolvedOperands();
776 dropReplaceableUses();
783void MDNode::makeDistinct() {
788 dropReplaceableUses();
800 dropReplaceableUses();
805void MDNode::dropReplaceableUses() {
809 if (Context.hasReplaceableUses())
810 Context.takeReplaceableUses()->resolveAllUses();
823 decrementUnresolvedOperandCount();
826void MDNode::decrementUnresolvedOperandCount() {
837 dropReplaceableUses();
850 auto *
N = dyn_cast_or_null<MDNode>(
Op);
855 "Expected all forward declarations to be resolved");
856 if (!
N->isResolved())
865MDNode *MDNode::replaceWithPermanentImpl() {
869 return replaceWithDistinctImpl();
871#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
874#include "llvm/IR/Metadata.def"
879 return replaceWithDistinctImpl();
880 return replaceWithUniquedImpl();
883MDNode *MDNode::replaceWithUniquedImpl() {
885 MDNode *UniquedNode = uniquify();
887 if (UniquedNode ==
this) {
898MDNode *MDNode::replaceWithDistinctImpl() {
903void MDTuple::recalculateHash() {
904 setHash(MDTupleInfo::KeyTy::calculateHash(
this));
910 if (Context.hasReplaceableUses()) {
911 Context.getReplaceableUses()->resolveAllUses(
false);
912 (void)Context.takeReplaceableUses();
916void MDNode::handleChangedOperand(
void *
Ref,
Metadata *New) {
933 if (New ==
this || (!New && Old && isa<ConstantAsMetadata>(Old))) {
944 resolveAfterOperandChange(Old, New);
956 if (Context.hasReplaceableUses())
957 Context.getReplaceableUses()->replaceAllUsesWith(
Uniqued);
966void MDNode::deleteAsSubclass() {
970#define HANDLE_MDNODE_LEAF(CLASS) \
972 delete cast<CLASS>(this); \
974#include "llvm/IR/Metadata.def"
978template <
class T,
class InfoT>
987template <
class NodeTy>
struct MDNode::HasCachedHash {
990 template <
class U, U Val>
struct SFINAE {};
993 static Yes &
check(SFINAE<
void (U::*)(
unsigned), &U::setHash> *);
996 static const bool value =
sizeof(check<NodeTy>(
nullptr)) ==
sizeof(
Yes);
999MDNode *MDNode::uniquify() {
1006#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1007 case CLASS##Kind: { \
1008 CLASS *SubclassThis = cast<CLASS>(this); \
1009 std::integral_constant<bool, HasCachedHash<CLASS>::value> \
1010 ShouldRecalculateHash; \
1011 dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash); \
1012 return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s); \
1014#include "llvm/IR/Metadata.def"
1018void MDNode::eraseFromStore() {
1022#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1024 getContext().pImpl->CLASS##s.erase(cast<CLASS>(this)); \
1026#include "llvm/IR/Metadata.def"
1031 StorageType Storage,
bool ShouldCreate) {
1034 MDTupleInfo::KeyTy
Key(MDs);
1039 Hash =
Key.getHash();
1041 assert(ShouldCreate &&
"Expected non-uniqued nodes to always be created");
1050 assert(
N->isTemporary() &&
"Expected temporary node");
1051 N->replaceAllUsesWith(
nullptr);
1052 N->deleteAsSubclass();
1056 assert(!Context.hasReplaceableUses() &&
"Unexpected replaceable uses");
1065#define HANDLE_MDNODE_LEAF(CLASS) \
1066 case CLASS##Kind: { \
1067 std::integral_constant<bool, HasCachedHash<CLASS>::value> ShouldResetHash; \
1068 dispatchResetHash(cast<CLASS>(this), ShouldResetHash); \
1071#include "llvm/IR/Metadata.def"
1103 if (
MDNode *
N = dyn_cast_or_null<MDNode>(Ops[0]))
1104 if (
N->getNumOperands() == Ops.
size() &&
N ==
N->getOperand(0)) {
1105 for (
unsigned I = 1, E = Ops.
size();
I != E; ++
I)
1106 if (Ops[
I] !=
N->getOperand(
I))
1121 MDs.
insert(
B->op_begin(),
B->op_end());
1151 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1156 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1164 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1169 return MDs.
empty() ? nullptr
1177 APFloat AVal = mdconst::extract<ConstantFP>(
A->getOperand(0))->getValueAPF();
1178 APFloat BVal = mdconst::extract<ConstantFP>(
B->getOperand(0))->getValueAPF();
1190 assert(
A &&
B && AInstr && BInstr &&
"Caller should guarantee");
1195 assert(
A->getNumOperands() >= 2 &&
B->getNumOperands() >= 2 &&
1196 "!prof annotations should have no less than 2 operands");
1197 MDString *AMDS = dyn_cast<MDString>(
A->getOperand(0));
1198 MDString *BMDS = dyn_cast<MDString>(
B->getOperand(0));
1200 assert(AMDS !=
nullptr && BMDS !=
nullptr &&
1201 "first operand should be a non-null MDString");
1204 if (AProfName ==
"branch_weights" && BProfName ==
"branch_weights") {
1205 ConstantInt *AInstrWeight = mdconst::dyn_extract<ConstantInt>(
1207 ConstantInt *BInstrWeight = mdconst::dyn_extract<ConstantInt>(
1209 assert(AInstrWeight && BInstrWeight &&
"verified by LLVM verifier");
1211 {MDHelper.createString(
"branch_weights"),
1212 MDHelper.createConstant(ConstantInt::get(
1230 "Caller should guarantee");
1232 "Caller should guarantee");
1234 const CallInst *ACall = dyn_cast<CallInst>(AInstr);
1235 const CallInst *BCall = dyn_cast<CallInst>(BInstr);
1240 return mergeDirectCallProfMetadata(
A,
B, AInstr, BInstr);
1248 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
1259 const APInt &LB = EndPoints[
Size - 2]->getValue();
1260 const APInt &LE = EndPoints[
Size - 1]->getValue();
1265 EndPoints[
Size - 2] =
1266 cast<ConstantInt>(ConstantInt::get(Ty, Union.getLower()));
1267 EndPoints[
Size - 1] =
1268 cast<ConstantInt>(ConstantInt::get(Ty, Union.getUpper()));
1276 if (!EndPoints.
empty())
1300 unsigned AN =
A->getNumOperands() / 2;
1301 unsigned BN =
B->getNumOperands() / 2;
1302 while (AI < AN && BI < BN) {
1303 ConstantInt *ALow = mdconst::extract<ConstantInt>(
A->getOperand(2 * AI));
1304 ConstantInt *BLow = mdconst::extract<ConstantInt>(
B->getOperand(2 * BI));
1308 mdconst::extract<ConstantInt>(
A->getOperand(2 * AI + 1)));
1312 mdconst::extract<ConstantInt>(
B->getOperand(2 * BI + 1)));
1317 addRange(EndPoints, mdconst::extract<ConstantInt>(
A->getOperand(2 * AI)),
1318 mdconst::extract<ConstantInt>(
A->getOperand(2 * AI + 1)));
1322 addRange(EndPoints, mdconst::extract<ConstantInt>(
B->getOperand(2 * BI)),
1323 mdconst::extract<ConstantInt>(
B->getOperand(2 * BI + 1)));
1335 for (
unsigned i = 0; i <
Size - 2; ++i) {
1336 EndPoints[i] = EndPoints[i + 2];
1344 if (EndPoints.
size() == 2) {
1352 for (
auto *
I : EndPoints)
1361 ConstantInt *AVal = mdconst::extract<ConstantInt>(
A->getOperand(0));
1362 ConstantInt *BVal = mdconst::extract<ConstantInt>(
B->getOperand(0));
1376NamedMDNode::NamedMDNode(
const Twine &
N)
1385 return (
unsigned)
getNMDOps(Operands).size();
1391 return cast_or_null<MDNode>(
N);
1412 for (
const auto &
A : Attachments)
1419 for (
const auto &
A : Attachments)
1421 Result.push_back(
A.Node);
1426 for (
const auto &
A : Attachments)
1427 Result.emplace_back(
A.MDKind,
A.Node);
1431 if (Result.size() > 1)
1450 if (Attachments.size() == 1 && Attachments.back().MDKind ==
ID) {
1451 Attachments.pop_back();
1455 auto OldSize = Attachments.size();
1458 return OldSize != Attachments.size();
1471 return Attachements.
lookup(KindID);
1488 "bit out of sync with hash table");
1495 assert(isa<Instruction>(
this) || isa<GlobalObject>(
this));
1503 Info.set(KindID, Node);
1509 "bit out of sync with hash table");
1529 assert(isa<Instruction>(
this) || isa<GlobalObject>(
this));
1545 bool Changed = Store.erase(KindID);
1557 assert(!
Info.empty() &&
"bit out of sync with hash table");
1559 return Pred(
I.MDKind,
I.Node);
1570 "bit out of sync with hash table");
1584 if (KindID == LLVMContext::MD_dbg)
1590 if (DbgLoc && Pred(LLVMContext::MD_dbg, DbgLoc.
getAsMDNode()))
1604 KnownSet.
insert(LLVMContext::MD_DIAssignID);
1607 return !KnownSet.
count(MDKind);
1611void Instruction::updateDIAssignIDMapping(
DIAssignID *
ID) {
1614 cast_or_null<DIAssignID>(
getMetadata(LLVMContext::MD_DIAssignID))) {
1616 if (
ID == CurrentID)
1620 auto InstrsIt = IDToInstrs.find(CurrentID);
1621 assert(InstrsIt != IDToInstrs.end() &&
1622 "Expect existing attachment to be mapped");
1624 auto &InstVec = InstrsIt->second;
1626 assert(InstIt != InstVec.end() &&
1627 "Expect instruction to be mapped to attachment");
1631 if (InstVec.size() == 1)
1632 IDToInstrs.erase(InstrsIt);
1634 InstVec.erase(InstIt);
1639 IDToInstrs[
ID].push_back(
this);
1647 if (KindID == LLVMContext::MD_dbg) {
1653 if (KindID == LLVMContext::MD_DIAssignID) {
1657 assert((!Node || !Node->isTemporary()) &&
1658 "Temporary DIAssignIDs are invalid");
1659 updateDIAssignIDMapping(cast_or_null<DIAssignID>(Node));
1667 if (
auto *Existing =
getMetadata(LLVMContext::MD_annotation)) {
1670 auto *Tuple = cast<MDTuple>(Existing);
1671 for (
auto &
N : Tuple->operands()) {
1672 if (isa<MDString>(
N.get())) {
1676 auto *MDAnnotationTuple = cast<MDTuple>(
N);
1677 if (
any_of(MDAnnotationTuple->operands(), [&AnnotationsSet](
auto &
Op) {
1678 return AnnotationsSet.contains(cast<MDString>(Op)->getString());
1697 if (
auto *Existing =
getMetadata(LLVMContext::MD_annotation)) {
1698 auto *Tuple = cast<MDTuple>(Existing);
1699 for (
auto &
N : Tuple->operands()) {
1700 if (isa<MDString>(
N.get()) &&
1701 cast<MDString>(
N.get())->getString() ==
Name)
1719 Result.TBAA =
Info.lookup(LLVMContext::MD_tbaa);
1720 Result.TBAAStruct =
Info.lookup(LLVMContext::MD_tbaa_struct);
1721 Result.Scope =
Info.lookup(LLVMContext::MD_alias_scope);
1722 Result.NoAlias =
Info.lookup(LLVMContext::MD_noalias);
1729 setMetadata(LLVMContext::MD_tbaa_struct,
N.TBAAStruct);
1739void Instruction::getAllMetadataImpl(
1746 std::make_pair((
unsigned)LLVMContext::MD_dbg, DbgLoc.
getAsMDNode()));
1755 getOpcode() == Instruction::IndirectBr ||
1757 "Looking for branch weights on something besides branch");
1759 return ::extractProfTotalWeight(*
this, TotalVal);
1764 Other->getAllMetadata(MDs);
1765 for (
auto &MD : MDs) {
1767 if (
Offset != 0 && MD.first == LLVMContext::MD_type) {
1768 auto *OffsetConst = cast<ConstantInt>(
1769 cast<ConstantAsMetadata>(MD.second->getOperand(0))->getValue());
1770 Metadata *TypeId = MD.second->getOperand(1);
1772 OffsetConst->getType(), OffsetConst->getValue() +
Offset));
1780 auto *Attachment = MD.second;
1781 if (
Offset != 0 && MD.first == LLVMContext::MD_dbg) {
1785 auto *GVE = cast<DIGlobalVariableExpression>(Attachment);
1786 GV = GVE->getVariable();
1787 E = GVE->getExpression();
1792 std::vector<uint64_t> Elements(OrigElements.
size() + 2);
1793 Elements[0] = dwarf::DW_OP_plus_uconst;
1795 llvm::copy(OrigElements, Elements.begin() + 2);
1805 LLVMContext::MD_type,
1825 cast<ConstantAsMetadata>(MD->getOperand(0))->getValue())
1827 assert(Val <= 2 &&
"unknown vcall visibility!");
1838 return cast_or_null<DISubprogram>(
getMetadata(LLVMContext::MD_dbg));
1844 return CU->getDebugInfoForProfiling();
1859 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.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
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.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
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 dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs=std::nullopt)
Drop all unknown metadata except for debug locations.
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 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.
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)
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::...