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() {
153 return static_cast<const DPValue *
>(
this);
159 auto OldMD =
static_cast<Metadata **
>(Old);
163 if (OldMD && isa<ValueAsMetadata>(*OldMD) && !New) {
164 auto *OldVAM = cast<ValueAsMetadata>(*OldMD);
170void DebugValueUser::trackDebugValue(
size_t Idx) {
171 assert(
Idx < 3 &&
"Invalid debug value index.");
177void DebugValueUser::trackDebugValues() {
183void DebugValueUser::untrackDebugValue(
size_t Idx) {
184 assert(
Idx < 3 &&
"Invalid debug value index.");
190void DebugValueUser::untrackDebugValues() {
197 assert(DebugValueUser::operator==(
X) &&
"Expected values to match");
201 X.DebugValues.fill(
nullptr);
205 assert(
Ref &&
"Expected live reference");
207 "Reference without owner must be direct");
208 if (
auto *R = ReplaceableMetadataImpl::getOrCreate(MD)) {
209 R->addRef(
Ref, Owner);
212 if (
auto *PH = dyn_cast<DistinctMDOperandPlaceholder>(&MD)) {
213 assert(!PH->Use &&
"Placeholders can only be used once");
214 assert(!Owner &&
"Unexpected callback to owner");
222 assert(
Ref &&
"Expected live reference");
223 if (
auto *R = ReplaceableMetadataImpl::getIfExists(MD))
225 else if (
auto *PH = dyn_cast<DistinctMDOperandPlaceholder>(&MD))
230 assert(
Ref &&
"Expected live reference");
231 assert(New &&
"Expected live reference");
233 if (
auto *R = ReplaceableMetadataImpl::getIfExists(MD)) {
234 R->moveRef(
Ref, New, MD);
237 assert(!isa<DistinctMDOperandPlaceholder>(MD) &&
238 "Unexpected move of an MDOperand");
240 "Expected un-replaceable metadata, since we didn't move a reference");
245 return ReplaceableMetadataImpl::isReplaceable(MD);
250 for (
auto Pair : UseMap) {
251 OwnerTy Owner = Pair.second.first;
254 if (!isa<Metadata *>(Owner))
256 Metadata *OwnerMD = cast<Metadata *>(Owner);
258 MDUsersWithID.
push_back(&UseMap[Pair.first]);
260 llvm::sort(MDUsersWithID, [](
auto UserA,
auto UserB) {
261 return UserA->second < UserB->second;
264 for (
auto *UserWithID : MDUsersWithID)
265 MDUsers.
push_back(cast<Metadata *>(UserWithID->first));
271 for (
auto Pair : UseMap) {
272 OwnerTy Owner = Pair.second.first;
277 DPVUsersWithID.
push_back(&UseMap[Pair.first]);
284 llvm::sort(DPVUsersWithID, [](
auto UserA,
auto UserB) {
285 return UserA->second > UserB->second;
288 for (
auto UserWithID : DPVUsersWithID)
293void ReplaceableMetadataImpl::addRef(
void *
Ref, OwnerTy Owner) {
295 UseMap.insert(std::make_pair(
Ref, std::make_pair(Owner, NextIndex)))
298 assert(WasInserted &&
"Expected to add a reference");
301 assert(NextIndex != 0 &&
"Unexpected overflow");
304void ReplaceableMetadataImpl::dropRef(
void *
Ref) {
305 bool WasErased = UseMap.erase(
Ref);
307 assert(WasErased &&
"Expected to drop a reference");
310void ReplaceableMetadataImpl::moveRef(
void *
Ref,
void *New,
312 auto I = UseMap.find(
Ref);
313 assert(
I != UseMap.end() &&
"Expected to move a reference");
314 auto OwnerAndIndex =
I->second;
316 bool WasInserted = UseMap.insert(std::make_pair(New, OwnerAndIndex)).second;
318 assert(WasInserted &&
"Expected to add a reference");
323 "Reference without owner must be direct");
324 assert((OwnerAndIndex.first || *
static_cast<Metadata **
>(New) == &MD) &&
325 "Reference without owner must be direct");
329 if (!
C.isUsedByMetadata()) {
335 auto I = Store.find(&
C);
338 std::pair<void *, std::pair<MetadataTracking::OwnerTy, uint64_t>>;
342 for (
const auto &Pair :
Uses) {
346 if (!isa<Metadata *>(Owner))
348 auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
351 if (isa<DINode>(OwnerMD)) {
352 OwnerMD->handleChangedOperand(
363 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
366 return L.second.second < R.second.second;
368 for (
const auto &Pair :
Uses) {
371 if (!UseMap.count(Pair.first))
374 OwnerTy Owner = Pair.second.first;
381 UseMap.erase(Pair.first);
386 if (isa<MetadataAsValue *>(Owner)) {
387 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(MD);
397 Metadata *OwnerMD = cast<Metadata *>(Owner);
399#define HANDLE_METADATA_LEAF(CLASS) \
400 case Metadata::CLASS##Kind: \
401 cast<CLASS>(OwnerMD)->handleChangedOperand(Pair.first, MD); \
403#include "llvm/IR/Metadata.def"
408 assert(UseMap.empty() &&
"Expected all uses to be replaced");
421 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
424 return L.second.second < R.second.second;
427 for (
const auto &Pair :
Uses) {
428 auto Owner = Pair.second.first;
435 auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
438 if (OwnerMD->isResolved())
440 OwnerMD->decrementUnresolvedOperandCount();
448 if (
auto *
N = dyn_cast<MDNode>(&MD)) {
449 return !
N->isResolved() ||
N->isAlwaysReplaceable()
450 ?
N->Context.getOrCreateReplaceableUses()
453 if (
auto ArgList = dyn_cast<DIArgList>(&MD))
455 return dyn_cast<ValueAsMetadata>(&MD);
459 if (
auto *
N = dyn_cast<MDNode>(&MD)) {
460 return !
N->isResolved() ||
N->isAlwaysReplaceable()
461 ?
N->Context.getReplaceableUses()
464 if (
auto ArgList = dyn_cast<DIArgList>(&MD))
466 return dyn_cast<ValueAsMetadata>(&MD);
469bool ReplaceableMetadataImpl::isReplaceable(
const Metadata &MD) {
470 if (
auto *
N = dyn_cast<MDNode>(&MD))
471 return !
N->isResolved() ||
N->isAlwaysReplaceable();
472 return isa<ValueAsMetadata>(&MD) || isa<DIArgList>(&MD);
476 assert(V &&
"Expected value");
477 if (
auto *
A = dyn_cast<Argument>(V)) {
478 if (
auto *Fn =
A->getParent())
479 return Fn->getSubprogram();
484 if (
auto *Fn = BB->getParent())
485 return Fn->getSubprogram();
493 assert(V &&
"Unexpected null Value");
495 auto &
Context = V->getContext();
498 assert((isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) &&
499 "Expected constant or function-local value");
500 assert(!V->IsUsedByMD &&
"Expected this to be the only metadata use");
501 V->IsUsedByMD =
true;
502 if (
auto *
C = dyn_cast<Constant>(V))
512 assert(V &&
"Unexpected null Value");
513 return V->getContext().pImpl->ValuesAsMetadata.lookup(V);
517 assert(V &&
"Expected valid value");
519 auto &Store = V->getType()->getContext().pImpl->ValuesAsMetadata;
520 auto I = Store.find(V);
521 if (
I == Store.end())
526 assert(MD &&
"Expected valid metadata");
537 assert(To &&
"Expected valid value");
538 assert(
From != To &&
"Expected changed value");
543 auto I = Store.find(
From);
544 if (
I == Store.end()) {
545 assert(!
From->IsUsedByMD &&
"Expected From not to be used by metadata");
550 assert(
From->IsUsedByMD &&
"Expected From to be used by metadata");
551 From->IsUsedByMD =
false;
553 assert(MD &&
"Expected valid metadata");
557 if (isa<LocalAsMetadata>(MD)) {
558 if (
auto *
C = dyn_cast<Constant>(To)) {
571 }
else if (!isa<Constant>(To)) {
578 auto *&Entry = Store[To];
599 auto I = Store.try_emplace(Str);
600 auto &MapEntry =
I.first->getValue();
603 MapEntry.Entry = &*
I.first;
608 assert(Entry &&
"Expected to find string map entry");
609 return Entry->first();
618#define HANDLE_MDNODE_LEAF(CLASS) \
620 alignof(uint64_t) >= alignof(CLASS), \
621 "Alignment is insufficient after objects prepended to " #CLASS);
622#include "llvm/IR/Metadata.def"
629 char *Mem =
reinterpret_cast<char *
>(::operator
new(AllocSize +
Size));
630 Header *
H =
new (Mem + AllocSize -
sizeof(Header)) Header(NumOps, Storage);
631 return reinterpret_cast<void *
>(
H + 1);
634void MDNode::operator
delete(
void *
N) {
635 Header *
H =
reinterpret_cast<Header *
>(
N) - 1;
636 void *Mem =
H->getAllocation();
638 ::operator
delete(Mem);
655 countUnresolvedOperands();
662#define HANDLE_MDNODE_LEAF(CLASS) \
664 return cast<CLASS>(this)->cloneImpl();
665#include "llvm/IR/Metadata.def"
669MDNode::Header::Header(
size_t NumOps, StorageType Storage) {
670 IsLarge = isLarge(NumOps);
671 IsResizable = isResizable(Storage);
672 SmallSize = getSmallSize(NumOps, IsResizable, IsLarge);
675 new (getLargePtr()) LargeStorageVector();
676 getLarge().resize(NumOps);
679 SmallNumOps = NumOps;
685MDNode::Header::~Header() {
687 getLarge().~LargeStorageVector();
695void *MDNode::Header::getSmallPtr() {
696 static_assert(
alignof(
MDOperand) <=
alignof(Header),
697 "MDOperand too strongly aligned");
698 return reinterpret_cast<char *
>(
const_cast<Header *
>(
this)) -
702void MDNode::Header::resize(
size_t NumOps) {
703 assert(IsResizable &&
"Node is not resizable");
704 if (operands().
size() == NumOps)
708 getLarge().resize(NumOps);
709 else if (NumOps <= SmallSize)
712 resizeSmallToLarge(NumOps);
715void MDNode::Header::resizeSmall(
size_t NumOps) {
716 assert(!IsLarge &&
"Expected a small MDNode");
717 assert(NumOps <= SmallSize &&
"NumOps too large for small resize");
720 assert(NumOps != ExistingOps.
size() &&
"Expected a different size");
722 int NumNew = (int)NumOps - (
int)ExistingOps.
size();
724 for (
int I = 0,
E = NumNew;
I <
E; ++
I)
726 for (
int I = 0,
E = NumNew;
I >
E; --
I)
728 SmallNumOps = NumOps;
729 assert(O == operands().
end() &&
"Operands not (un)initialized until the end");
732void MDNode::Header::resizeSmallToLarge(
size_t NumOps) {
733 assert(!IsLarge &&
"Expected a small MDNode");
734 assert(NumOps > SmallSize &&
"Expected NumOps to be larger than allocation");
735 LargeStorageVector NewOps;
736 NewOps.resize(NumOps);
739 new (getLargePtr()) LargeStorageVector(std::move(NewOps));
744 if (
auto *
N = dyn_cast_or_null<MDNode>(
Op))
745 return !
N->isResolved();
749void MDNode::countUnresolvedOperands() {
755void MDNode::makeUniqued() {
761 Op.reset(
Op.get(),
this);
765 countUnresolvedOperands();
767 dropReplaceableUses();
774void MDNode::makeDistinct() {
779 dropReplaceableUses();
791 dropReplaceableUses();
796void MDNode::dropReplaceableUses() {
800 if (
Context.hasReplaceableUses())
801 Context.takeReplaceableUses()->resolveAllUses();
814 decrementUnresolvedOperandCount();
817void MDNode::decrementUnresolvedOperandCount() {
828 dropReplaceableUses();
841 auto *
N = dyn_cast_or_null<MDNode>(
Op);
846 "Expected all forward declarations to be resolved");
847 if (!
N->isResolved())
856MDNode *MDNode::replaceWithPermanentImpl() {
860 return replaceWithDistinctImpl();
862#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
865#include "llvm/IR/Metadata.def"
870 return replaceWithDistinctImpl();
871 return replaceWithUniquedImpl();
874MDNode *MDNode::replaceWithUniquedImpl() {
876 MDNode *UniquedNode = uniquify();
878 if (UniquedNode ==
this) {
889MDNode *MDNode::replaceWithDistinctImpl() {
894void MDTuple::recalculateHash() {
895 setHash(MDTupleInfo::KeyTy::calculateHash(
this));
901 if (
Context.hasReplaceableUses()) {
902 Context.getReplaceableUses()->resolveAllUses(
false);
903 (void)
Context.takeReplaceableUses();
907void MDNode::handleChangedOperand(
void *
Ref,
Metadata *New) {
924 if (New ==
this || (!New && Old && isa<ConstantAsMetadata>(Old))) {
935 resolveAfterOperandChange(Old, New);
947 if (
Context.hasReplaceableUses())
957void MDNode::deleteAsSubclass() {
961#define HANDLE_MDNODE_LEAF(CLASS) \
963 delete cast<CLASS>(this); \
965#include "llvm/IR/Metadata.def"
969template <
class T,
class InfoT>
978template <
class NodeTy>
struct MDNode::HasCachedHash {
981 template <
class U, U Val>
struct SFINAE {};
984 static Yes &
check(SFINAE<
void (U::*)(
unsigned), &U::setHash> *);
987 static const bool value =
sizeof(check<NodeTy>(
nullptr)) ==
sizeof(
Yes);
990MDNode *MDNode::uniquify() {
997#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
998 case CLASS##Kind: { \
999 CLASS *SubclassThis = cast<CLASS>(this); \
1000 std::integral_constant<bool, HasCachedHash<CLASS>::value> \
1001 ShouldRecalculateHash; \
1002 dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash); \
1003 return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s); \
1005#include "llvm/IR/Metadata.def"
1009void MDNode::eraseFromStore() {
1013#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1015 getContext().pImpl->CLASS##s.erase(cast<CLASS>(this)); \
1017#include "llvm/IR/Metadata.def"
1022 StorageType Storage,
bool ShouldCreate) {
1025 MDTupleInfo::KeyTy
Key(MDs);
1030 Hash =
Key.getHash();
1032 assert(ShouldCreate &&
"Expected non-uniqued nodes to always be created");
1041 assert(
N->isTemporary() &&
"Expected temporary node");
1042 N->replaceAllUsesWith(
nullptr);
1043 N->deleteAsSubclass();
1047 assert(!
Context.hasReplaceableUses() &&
"Unexpected replaceable uses");
1056#define HANDLE_MDNODE_LEAF(CLASS) \
1057 case CLASS##Kind: { \
1058 std::integral_constant<bool, HasCachedHash<CLASS>::value> ShouldResetHash; \
1059 dispatchResetHash(cast<CLASS>(this), ShouldResetHash); \
1062#include "llvm/IR/Metadata.def"
1094 if (
MDNode *
N = dyn_cast_or_null<MDNode>(Ops[0]))
1095 if (
N->getNumOperands() == Ops.
size() &&
N ==
N->getOperand(0)) {
1096 for (
unsigned I = 1,
E = Ops.
size();
I !=
E; ++
I)
1097 if (Ops[
I] !=
N->getOperand(
I))
1112 MDs.
insert(
B->op_begin(),
B->op_end());
1142 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1147 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1155 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1160 return MDs.
empty() ? nullptr
1168 APFloat AVal = mdconst::extract<ConstantFP>(
A->getOperand(0))->getValueAPF();
1169 APFloat BVal = mdconst::extract<ConstantFP>(
B->getOperand(0))->getValueAPF();
1181 assert(
A &&
B && AInstr && BInstr &&
"Caller should guarantee");
1186 assert(
A->getNumOperands() >= 2 &&
B->getNumOperands() >= 2 &&
1187 "!prof annotations should have no less than 2 operands");
1188 MDString *AMDS = dyn_cast<MDString>(
A->getOperand(0));
1189 MDString *BMDS = dyn_cast<MDString>(
B->getOperand(0));
1191 assert(AMDS !=
nullptr && BMDS !=
nullptr &&
1192 "first operand should be a non-null MDString");
1195 if (AProfName.
equals(
"branch_weights") &&
1196 BProfName.
equals(
"branch_weights")) {
1198 mdconst::dyn_extract<ConstantInt>(
A->getOperand(1));
1200 mdconst::dyn_extract<ConstantInt>(
B->getOperand(1));
1201 assert(AInstrWeight && BInstrWeight &&
"verified by LLVM verifier");
1203 {MDHelper.createString(
"branch_weights"),
1204 MDHelper.createConstant(ConstantInt::get(
1222 "Caller should guarantee");
1224 "Caller should guarantee");
1226 const CallInst *ACall = dyn_cast<CallInst>(AInstr);
1227 const CallInst *BCall = dyn_cast<CallInst>(BInstr);
1232 return mergeDirectCallProfMetadata(
A,
B, AInstr, BInstr);
1240 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
1251 APInt LB = EndPoints[
Size - 2]->getValue();
1252 APInt LE = EndPoints[
Size - 1]->getValue();
1257 EndPoints[
Size - 2] =
1258 cast<ConstantInt>(ConstantInt::get(Ty, Union.getLower()));
1259 EndPoints[
Size - 1] =
1260 cast<ConstantInt>(ConstantInt::get(Ty, Union.getUpper()));
1268 if (!EndPoints.
empty())
1292 int AN =
A->getNumOperands() / 2;
1293 int BN =
B->getNumOperands() / 2;
1294 while (AI < AN && BI < BN) {
1295 ConstantInt *ALow = mdconst::extract<ConstantInt>(
A->getOperand(2 * AI));
1296 ConstantInt *BLow = mdconst::extract<ConstantInt>(
B->getOperand(2 * BI));
1300 mdconst::extract<ConstantInt>(
A->getOperand(2 * AI + 1)));
1304 mdconst::extract<ConstantInt>(
B->getOperand(2 * BI + 1)));
1309 addRange(EndPoints, mdconst::extract<ConstantInt>(
A->getOperand(2 * AI)),
1310 mdconst::extract<ConstantInt>(
A->getOperand(2 * AI + 1)));
1314 addRange(EndPoints, mdconst::extract<ConstantInt>(
B->getOperand(2 * BI)),
1315 mdconst::extract<ConstantInt>(
B->getOperand(2 * BI + 1)));
1326 for (
unsigned i = 0; i <
Size - 2; ++i) {
1327 EndPoints[i] = EndPoints[i + 2];
1335 if (EndPoints.
size() == 2) {
1336 ConstantRange Range(EndPoints[0]->getValue(), EndPoints[1]->getValue());
1337 if (Range.isFullSet())
1343 for (
auto *
I : EndPoints)
1352 ConstantInt *AVal = mdconst::extract<ConstantInt>(
A->getOperand(0));
1353 ConstantInt *BVal = mdconst::extract<ConstantInt>(
B->getOperand(0));
1367NamedMDNode::NamedMDNode(
const Twine &
N)
1376 return (
unsigned)
getNMDOps(Operands).size();
1382 return cast_or_null<MDNode>(
N);
1403 for (
const auto &
A : Attachments)
1410 for (
const auto &
A : Attachments)
1412 Result.push_back(
A.Node);
1417 for (
const auto &
A : Attachments)
1418 Result.emplace_back(
A.MDKind,
A.Node);
1422 if (Result.size() > 1)
1441 if (Attachments.size() == 1 && Attachments.back().MDKind ==
ID) {
1442 Attachments.pop_back();
1446 auto OldSize = Attachments.size();
1449 return OldSize != Attachments.size();
1462 return Attachements.
lookup(KindID);
1479 "bit out of sync with hash table");
1486 assert(isa<Instruction>(
this) || isa<GlobalObject>(
this));
1494 Info.set(KindID, Node);
1500 "bit out of sync with hash table");
1520 assert(isa<Instruction>(
this) || isa<GlobalObject>(
this));
1536 bool Changed = Store.erase(KindID);
1548 assert(!
Info.empty() &&
"bit out of sync with hash table");
1550 return Pred(
I.MDKind,
I.Node);
1561 "bit out of sync with hash table");
1575 if (KindID == LLVMContext::MD_dbg)
1581 if (DbgLoc && Pred(LLVMContext::MD_dbg, DbgLoc.
getAsMDNode()))
1595 KnownSet.
insert(LLVMContext::MD_DIAssignID);
1598 return !KnownSet.
count(MDKind);
1602void Instruction::updateDIAssignIDMapping(
DIAssignID *
ID) {
1605 cast_or_null<DIAssignID>(
getMetadata(LLVMContext::MD_DIAssignID))) {
1607 if (
ID == CurrentID)
1611 auto InstrsIt = IDToInstrs.find(CurrentID);
1612 assert(InstrsIt != IDToInstrs.end() &&
1613 "Expect existing attachment to be mapped");
1615 auto &InstVec = InstrsIt->second;
1617 assert(InstIt != InstVec.end() &&
1618 "Expect instruction to be mapped to attachment");
1622 if (InstVec.size() == 1)
1623 IDToInstrs.erase(InstrsIt);
1625 InstVec.erase(InstIt);
1630 IDToInstrs[
ID].push_back(
this);
1638 if (KindID == LLVMContext::MD_dbg) {
1644 if (KindID == LLVMContext::MD_DIAssignID) {
1648 assert((!Node || !Node->isTemporary()) &&
1649 "Temporary DIAssignIDs are invalid");
1650 updateDIAssignIDMapping(cast_or_null<DIAssignID>(Node));
1658 if (
auto *Existing =
getMetadata(LLVMContext::MD_annotation)) {
1661 auto *Tuple = cast<MDTuple>(Existing);
1662 for (
auto &
N : Tuple->operands()) {
1663 if (isa<MDString>(
N.get())) {
1667 auto *MDAnnotationTuple = cast<MDTuple>(
N);
1668 if (
any_of(MDAnnotationTuple->operands(), [&AnnotationsSet](
auto &
Op) {
1669 return AnnotationsSet.contains(cast<MDString>(Op)->getString());
1688 if (
auto *Existing =
getMetadata(LLVMContext::MD_annotation)) {
1689 auto *Tuple = cast<MDTuple>(Existing);
1690 for (
auto &
N : Tuple->operands()) {
1691 if (isa<MDString>(
N.get()) &&
1692 cast<MDString>(
N.get())->getString() ==
Name)
1710 Result.TBAA =
Info.lookup(LLVMContext::MD_tbaa);
1711 Result.TBAAStruct =
Info.lookup(LLVMContext::MD_tbaa_struct);
1712 Result.Scope =
Info.lookup(LLVMContext::MD_alias_scope);
1713 Result.NoAlias =
Info.lookup(LLVMContext::MD_noalias);
1720 setMetadata(LLVMContext::MD_tbaa_struct,
N.TBAAStruct);
1730void Instruction::getAllMetadataImpl(
1737 std::make_pair((
unsigned)LLVMContext::MD_dbg, DbgLoc.
getAsMDNode()));
1746 getOpcode() == Instruction::IndirectBr ||
1748 "Looking for branch weights on something besides branch");
1750 return ::extractProfTotalWeight(*
this, TotalVal);
1755 Other->getAllMetadata(MDs);
1756 for (
auto &MD : MDs) {
1758 if (
Offset != 0 && MD.first == LLVMContext::MD_type) {
1759 auto *OffsetConst = cast<ConstantInt>(
1760 cast<ConstantAsMetadata>(MD.second->getOperand(0))->getValue());
1761 Metadata *TypeId = MD.second->getOperand(1);
1763 OffsetConst->getType(), OffsetConst->getValue() +
Offset));
1771 auto *Attachment = MD.second;
1772 if (
Offset != 0 && MD.first == LLVMContext::MD_dbg) {
1776 auto *GVE = cast<DIGlobalVariableExpression>(Attachment);
1777 GV = GVE->getVariable();
1778 E = GVE->getExpression();
1782 OrigElements =
E->getElements();
1783 std::vector<uint64_t> Elements(OrigElements.
size() + 2);
1784 Elements[0] = dwarf::DW_OP_plus_uconst;
1786 llvm::copy(OrigElements, Elements.begin() + 2);
1796 LLVMContext::MD_type,
1816 cast<ConstantAsMetadata>(MD->getOperand(0))->getValue())
1818 assert(Val <= 2 &&
"unknown vcall visibility!");
1829 return cast_or_null<DISubprogram>(
getMetadata(LLVMContext::MD_dbg));
1835 return CU->getDebugInfoForProfiling();
1850 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")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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.
A pair of DIGlobalVariable and DIExpression.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
This class represents an Operation in the Expression.
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)
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.
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
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::...