60 :
Value(Ty, MetadataAsValueVal), MD(MD) {
87 auto *
N = dyn_cast<MDNode>(MD);
88 if (!
N ||
N->getNumOperands() != 1)
91 if (!
N->getOperand(0))
95 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
N->getOperand(0)))
114 return Store.lookup(MD);
117void MetadataAsValue::handleChangedMetadata(
Metadata *MD) {
123 Store.erase(this->MD);
128 auto *&Entry = Store[MD];
140void MetadataAsValue::track() {
145void MetadataAsValue::untrack() {
151 assert(
Ref &&
"Expected live reference");
153 "Reference without owner must be direct");
154 if (
auto *R = ReplaceableMetadataImpl::getOrCreate(MD)) {
155 R->addRef(
Ref, Owner);
158 if (
auto *PH = dyn_cast<DistinctMDOperandPlaceholder>(&MD)) {
159 assert(!PH->Use &&
"Placeholders can only be used once");
160 assert(!Owner &&
"Unexpected callback to owner");
168 assert(
Ref &&
"Expected live reference");
169 if (
auto *R = ReplaceableMetadataImpl::getIfExists(MD))
171 else if (
auto *PH = dyn_cast<DistinctMDOperandPlaceholder>(&MD))
176 assert(
Ref &&
"Expected live reference");
177 assert(New &&
"Expected live reference");
179 if (
auto *R = ReplaceableMetadataImpl::getIfExists(MD)) {
180 R->moveRef(
Ref, New, MD);
183 assert(!isa<DistinctMDOperandPlaceholder>(MD) &&
184 "Unexpected move of an MDOperand");
186 "Expected un-replaceable metadata, since we didn't move a reference");
191 return ReplaceableMetadataImpl::isReplaceable(MD);
196 for (
auto Pair : UseMap) {
197 OwnerTy Owner = Pair.second.first;
198 if (!isa<Metadata *>(Owner))
200 Metadata *OwnerMD = cast<Metadata *>(Owner);
202 MDUsersWithID.
push_back(&UseMap[Pair.first]);
204 llvm::sort(MDUsersWithID, [](
auto UserA,
auto UserB) {
205 return UserA->second < UserB->second;
208 for (
auto *UserWithID : MDUsersWithID)
209 MDUsers.
push_back(cast<Metadata *>(UserWithID->first));
213void ReplaceableMetadataImpl::addRef(
void *
Ref, OwnerTy Owner) {
215 UseMap.insert(std::make_pair(
Ref, std::make_pair(Owner, NextIndex)))
218 assert(WasInserted &&
"Expected to add a reference");
221 assert(NextIndex != 0 &&
"Unexpected overflow");
224void ReplaceableMetadataImpl::dropRef(
void *
Ref) {
225 bool WasErased = UseMap.erase(
Ref);
227 assert(WasErased &&
"Expected to drop a reference");
230void ReplaceableMetadataImpl::moveRef(
void *
Ref,
void *New,
232 auto I = UseMap.find(
Ref);
233 assert(
I != UseMap.end() &&
"Expected to move a reference");
234 auto OwnerAndIndex =
I->second;
236 bool WasInserted = UseMap.insert(std::make_pair(New, OwnerAndIndex)).second;
238 assert(WasInserted &&
"Expected to add a reference");
243 "Reference without owner must be direct");
244 assert((OwnerAndIndex.first || *
static_cast<Metadata **
>(New) == &MD) &&
245 "Reference without owner must be direct");
249 if (!
C.isUsedByMetadata()) {
255 auto I = Store.find(&
C);
258 std::pair<void *, std::pair<MetadataTracking::OwnerTy, uint64_t>>;
262 for (
const auto &Pair :
Uses) {
266 if (!isa<Metadata *>(Owner))
268 auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
271 if (isa<DINode>(OwnerMD)) {
272 OwnerMD->handleChangedOperand(
283 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
286 return L.second.second < R.second.second;
288 for (
const auto &Pair :
Uses) {
291 if (!UseMap.count(Pair.first))
294 OwnerTy Owner = Pair.second.first;
301 UseMap.erase(Pair.first);
306 if (isa<MetadataAsValue *>(Owner)) {
307 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(MD);
312 Metadata *OwnerMD = cast<Metadata *>(Owner);
314#define HANDLE_METADATA_LEAF(CLASS) \
315 case Metadata::CLASS##Kind: \
316 cast<CLASS>(OwnerMD)->handleChangedOperand(Pair.first, MD); \
318#include "llvm/IR/Metadata.def"
323 assert(UseMap.empty() &&
"Expected all uses to be replaced");
336 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
339 return L.second.second < R.second.second;
342 for (
const auto &Pair :
Uses) {
343 auto Owner = Pair.second.first;
346 if (isa<MetadataAsValue *>(Owner))
350 auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
353 if (OwnerMD->isResolved())
355 OwnerMD->decrementUnresolvedOperandCount();
360 if (
auto *
N = dyn_cast<MDNode>(&MD))
361 return N->isResolved() ? nullptr :
N->Context.getOrCreateReplaceableUses();
362 return dyn_cast<ValueAsMetadata>(&MD);
366 if (
auto *
N = dyn_cast<MDNode>(&MD))
367 return N->isResolved() ? nullptr :
N->Context.getReplaceableUses();
368 return dyn_cast<ValueAsMetadata>(&MD);
371bool ReplaceableMetadataImpl::isReplaceable(
const Metadata &MD) {
372 if (
auto *
N = dyn_cast<MDNode>(&MD))
373 return !
N->isResolved();
374 return isa<ValueAsMetadata>(&MD);
378 assert(V &&
"Expected value");
379 if (
auto *
A = dyn_cast<Argument>(V)) {
380 if (
auto *Fn =
A->getParent())
381 return Fn->getSubprogram();
386 if (
auto *Fn = BB->getParent())
387 return Fn->getSubprogram();
395 assert(V &&
"Unexpected null Value");
397 auto &
Context = V->getContext();
400 assert((isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) &&
401 "Expected constant or function-local value");
402 assert(!V->IsUsedByMD &&
"Expected this to be the only metadata use");
403 V->IsUsedByMD =
true;
404 if (
auto *
C = dyn_cast<Constant>(V))
414 assert(V &&
"Unexpected null Value");
415 return V->getContext().pImpl->ValuesAsMetadata.lookup(V);
419 assert(V &&
"Expected valid value");
421 auto &Store = V->getType()->getContext().pImpl->ValuesAsMetadata;
422 auto I = Store.find(V);
423 if (
I == Store.end())
428 assert(MD &&
"Expected valid metadata");
439 assert(To &&
"Expected valid value");
440 assert(
From != To &&
"Expected changed value");
445 auto I = Store.find(
From);
446 if (
I == Store.end()) {
447 assert(!
From->IsUsedByMD &&
"Expected From not to be used by metadata");
452 assert(
From->IsUsedByMD &&
"Expected From to be used by metadata");
453 From->IsUsedByMD =
false;
455 assert(MD &&
"Expected valid metadata");
459 if (isa<LocalAsMetadata>(MD)) {
460 if (
auto *
C = dyn_cast<Constant>(To)) {
473 }
else if (!isa<Constant>(To)) {
480 auto *&Entry = Store[To];
501 auto I = Store.try_emplace(Str);
502 auto &MapEntry =
I.first->getValue();
505 MapEntry.Entry = &*
I.first;
510 assert(Entry &&
"Expected to find string map entry");
511 return Entry->first();
520#define HANDLE_MDNODE_LEAF(CLASS) \
522 alignof(uint64_t) >= alignof(CLASS), \
523 "Alignment is insufficient after objects prepended to " #CLASS);
524#include "llvm/IR/Metadata.def"
531 char *Mem =
reinterpret_cast<char *
>(::operator
new(AllocSize +
Size));
532 Header *
H =
new (Mem + AllocSize -
sizeof(Header)) Header(NumOps, Storage);
533 return reinterpret_cast<void *
>(
H + 1);
536void MDNode::operator
delete(
void *
N) {
537 Header *
H =
reinterpret_cast<Header *
>(
N) - 1;
538 void *Mem =
H->getAllocation();
540 ::operator
delete(Mem);
557 countUnresolvedOperands();
564#define HANDLE_MDNODE_LEAF(CLASS) \
566 return cast<CLASS>(this)->cloneImpl();
567#include "llvm/IR/Metadata.def"
571MDNode::Header::Header(
size_t NumOps, StorageType Storage) {
572 IsLarge = isLarge(NumOps);
573 IsResizable = isResizable(Storage);
574 SmallSize = getSmallSize(NumOps, IsResizable, IsLarge);
577 new (getLargePtr()) LargeStorageVector();
578 getLarge().resize(NumOps);
581 SmallNumOps = NumOps;
587MDNode::Header::~Header() {
589 getLarge().~LargeStorageVector();
597void *MDNode::Header::getSmallPtr() {
598 static_assert(
alignof(
MDOperand) <=
alignof(Header),
599 "MDOperand too strongly aligned");
600 return reinterpret_cast<char *
>(
const_cast<Header *
>(
this)) -
604void MDNode::Header::resize(
size_t NumOps) {
605 assert(IsResizable &&
"Node is not resizable");
606 if (operands().
size() == NumOps)
610 getLarge().resize(NumOps);
611 else if (NumOps <= SmallSize)
614 resizeSmallToLarge(NumOps);
617void MDNode::Header::resizeSmall(
size_t NumOps) {
618 assert(!IsLarge &&
"Expected a small MDNode");
619 assert(NumOps <= SmallSize &&
"NumOps too large for small resize");
622 assert(NumOps != ExistingOps.
size() &&
"Expected a different size");
624 int NumNew = (int)NumOps - (
int)ExistingOps.
size();
626 for (
int I = 0,
E = NumNew;
I <
E; ++
I)
628 for (
int I = 0,
E = NumNew;
I >
E; --
I)
630 SmallNumOps = NumOps;
631 assert(O == operands().end() &&
"Operands not (un)initialized until the end");
634void MDNode::Header::resizeSmallToLarge(
size_t NumOps) {
635 assert(!IsLarge &&
"Expected a small MDNode");
636 assert(NumOps > SmallSize &&
"Expected NumOps to be larger than allocation");
637 LargeStorageVector NewOps;
638 NewOps.resize(NumOps);
641 new (getLargePtr()) LargeStorageVector(std::move(NewOps));
646 if (
auto *
N = dyn_cast_or_null<MDNode>(Op))
647 return !
N->isResolved();
651void MDNode::countUnresolvedOperands() {
657void MDNode::makeUniqued() {
663 Op.reset(
Op.get(),
this);
667 countUnresolvedOperands();
669 dropReplaceableUses();
676void MDNode::makeDistinct() {
681 dropReplaceableUses();
693 dropReplaceableUses();
698void MDNode::dropReplaceableUses() {
702 if (
Context.hasReplaceableUses())
703 Context.takeReplaceableUses()->resolveAllUses();
716 decrementUnresolvedOperandCount();
719void MDNode::decrementUnresolvedOperandCount() {
730 dropReplaceableUses();
743 auto *
N = dyn_cast_or_null<MDNode>(Op);
748 "Expected all forward declarations to be resolved");
749 if (!
N->isResolved())
758MDNode *MDNode::replaceWithPermanentImpl() {
762 return replaceWithDistinctImpl();
764#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
767#include "llvm/IR/Metadata.def"
772 return replaceWithDistinctImpl();
773 return replaceWithUniquedImpl();
776MDNode *MDNode::replaceWithUniquedImpl() {
778 MDNode *UniquedNode = uniquify();
780 if (UniquedNode ==
this) {
791MDNode *MDNode::replaceWithDistinctImpl() {
796void MDTuple::recalculateHash() {
797 setHash(MDTupleInfo::KeyTy::calculateHash(
this));
803 if (
Context.hasReplaceableUses()) {
804 Context.getReplaceableUses()->resolveAllUses(
false);
805 (void)
Context.takeReplaceableUses();
809void MDNode::handleChangedOperand(
void *
Ref,
Metadata *New) {
826 if (New ==
this || (!New && Old && isa<ConstantAsMetadata>(Old))) {
837 resolveAfterOperandChange(Old, New);
849 if (
Context.hasReplaceableUses())
859void MDNode::deleteAsSubclass() {
863#define HANDLE_MDNODE_LEAF(CLASS) \
865 delete cast<CLASS>(this); \
867#include "llvm/IR/Metadata.def"
871template <
class T,
class InfoT>
880template <
class NodeTy>
struct MDNode::HasCachedHash {
883 template <
class U, U Val>
struct SFINAE {};
886 static Yes &
check(SFINAE<
void (U::*)(
unsigned), &U::setHash> *);
889 static const bool value =
sizeof(check<NodeTy>(
nullptr)) ==
sizeof(
Yes);
892MDNode *MDNode::uniquify() {
899#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
900 case CLASS##Kind: { \
901 CLASS *SubclassThis = cast<CLASS>(this); \
902 std::integral_constant<bool, HasCachedHash<CLASS>::value> \
903 ShouldRecalculateHash; \
904 dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash); \
905 return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s); \
907#include "llvm/IR/Metadata.def"
911void MDNode::eraseFromStore() {
915#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
917 getContext().pImpl->CLASS##s.erase(cast<CLASS>(this)); \
919#include "llvm/IR/Metadata.def"
924 StorageType Storage,
bool ShouldCreate) {
927 MDTupleInfo::KeyTy
Key(MDs);
932 Hash =
Key.getHash();
934 assert(ShouldCreate &&
"Expected non-uniqued nodes to always be created");
943 assert(
N->isTemporary() &&
"Expected temporary node");
944 N->replaceAllUsesWith(
nullptr);
945 N->deleteAsSubclass();
949 assert(!
Context.hasReplaceableUses() &&
"Unexpected replaceable uses");
958#define HANDLE_MDNODE_LEAF(CLASS) \
959 case CLASS##Kind: { \
960 std::integral_constant<bool, HasCachedHash<CLASS>::value> ShouldResetHash; \
961 dispatchResetHash(cast<CLASS>(this), ShouldResetHash); \
964#include "llvm/IR/Metadata.def"
996 if (
MDNode *
N = dyn_cast_or_null<MDNode>(Ops[0]))
997 if (
N->getNumOperands() == Ops.
size() &&
N ==
N->getOperand(0)) {
998 for (
unsigned I = 1,
E = Ops.
size();
I !=
E; ++
I)
999 if (Ops[
I] !=
N->getOperand(
I))
1014 MDs.
insert(
B->op_begin(),
B->op_end());
1044 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1049 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1057 if (
const MDNode *NAMD = dyn_cast<MDNode>(MDOp))
1062 return MDs.
empty() ? nullptr
1070 APFloat AVal = mdconst::extract<ConstantFP>(
A->getOperand(0))->getValueAPF();
1071 APFloat BVal = mdconst::extract<ConstantFP>(
B->getOperand(0))->getValueAPF();
1083 assert(
A &&
B && AInstr && BInstr &&
"Caller should guarantee");
1088 assert(
A->getNumOperands() >= 2 &&
B->getNumOperands() >= 2 &&
1089 "!prof annotations should have no less than 2 operands");
1090 MDString *AMDS = dyn_cast<MDString>(
A->getOperand(0));
1091 MDString *BMDS = dyn_cast<MDString>(
B->getOperand(0));
1093 assert(AMDS !=
nullptr && BMDS !=
nullptr &&
1094 "first operand should be a non-null MDString");
1097 if (AProfName.
equals(
"branch_weights") &&
1098 BProfName.
equals(
"branch_weights")) {
1100 mdconst::dyn_extract<ConstantInt>(
A->getOperand(1));
1102 mdconst::dyn_extract<ConstantInt>(
B->getOperand(1));
1103 assert(AInstrWeight && BInstrWeight &&
"verified by LLVM verifier");
1105 {MDHelper.createString(
"branch_weights"),
1124 "Caller should guarantee");
1126 "Caller should guarantee");
1128 const CallInst *ACall = dyn_cast<CallInst>(AInstr);
1129 const CallInst *BCall = dyn_cast<CallInst>(BInstr);
1134 return mergeDirectCallProfMetadata(
A,
B, AInstr, BInstr);
1142 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
1153 APInt LB = EndPoints[
Size - 2]->getValue();
1154 APInt LE = EndPoints[
Size - 1]->getValue();
1159 EndPoints[
Size - 2] =
1161 EndPoints[
Size - 1] =
1170 if (!EndPoints.
empty())
1194 int AN =
A->getNumOperands() / 2;
1195 int BN =
B->getNumOperands() / 2;
1196 while (AI < AN && BI < BN) {
1197 ConstantInt *ALow = mdconst::extract<ConstantInt>(
A->getOperand(2 * AI));
1198 ConstantInt *BLow = mdconst::extract<ConstantInt>(
B->getOperand(2 * BI));
1202 mdconst::extract<ConstantInt>(
A->getOperand(2 * AI + 1)));
1206 mdconst::extract<ConstantInt>(
B->getOperand(2 * BI + 1)));
1211 addRange(EndPoints, mdconst::extract<ConstantInt>(
A->getOperand(2 * AI)),
1212 mdconst::extract<ConstantInt>(
A->getOperand(2 * AI + 1)));
1216 addRange(EndPoints, mdconst::extract<ConstantInt>(
B->getOperand(2 * BI)),
1217 mdconst::extract<ConstantInt>(
B->getOperand(2 * BI + 1)));
1228 for (
unsigned i = 0; i <
Size - 2; ++i) {
1229 EndPoints[i] = EndPoints[i + 2];
1237 if (EndPoints.
size() == 2) {
1238 ConstantRange Range(EndPoints[0]->getValue(), EndPoints[1]->getValue());
1239 if (Range.isFullSet())
1245 for (
auto *
I : EndPoints)
1254 ConstantInt *AVal = mdconst::extract<ConstantInt>(
A->getOperand(0));
1255 ConstantInt *BVal = mdconst::extract<ConstantInt>(
B->getOperand(0));
1269NamedMDNode::NamedMDNode(
const Twine &
N)
1278 return (
unsigned)
getNMDOps(Operands).size();
1284 return cast_or_null<MDNode>(
N);
1305 for (
const auto &
A : Attachments)
1312 for (
const auto &
A : Attachments)
1314 Result.push_back(
A.Node);
1319 for (
const auto &
A : Attachments)
1320 Result.emplace_back(
A.MDKind,
A.Node);
1324 if (Result.size() > 1)
1343 if (Attachments.size() == 1 && Attachments.back().MDKind ==
ID) {
1344 Attachments.pop_back();
1348 auto OldSize = Attachments.size();
1351 return OldSize != Attachments.size();
1358 assert(!
Info.empty() &&
"bit out of sync with hash table");
1359 return Info.lookup(KindID);
1366 assert(!
Info.empty() &&
"bit out of sync with hash table");
1384 "bit out of sync with hash table");
1386 assert(!
Info.empty() &&
"Shouldn't have called this");
1392 assert(isa<Instruction>(
this) || isa<GlobalObject>(
this));
1400 Info.set(KindID, Node);
1406 "bit out of sync with hash table");
1426 assert(isa<Instruction>(
this) || isa<GlobalObject>(
this));
1442 bool Changed = Store.erase(KindID);
1452 "bit out of sync with hash table");
1464 return getMetadataImpl(
getContext().getMDKindID(Kind));
1475 KnownSet.
insert(LLVMContext::MD_DIAssignID);
1478 auto &
Info = MetadataStore[
this];
1479 assert(!
Info.empty() &&
"bit out of sync with hash table");
1481 return !KnownSet.
count(
I.MDKind);
1490void Instruction::updateDIAssignIDMapping(
DIAssignID *
ID) {
1493 cast_or_null<DIAssignID>(
getMetadata(LLVMContext::MD_DIAssignID))) {
1495 if (
ID == CurrentID)
1499 auto InstrsIt = IDToInstrs.find(CurrentID);
1500 assert(InstrsIt != IDToInstrs.end() &&
1501 "Expect existing attachment to be mapped");
1503 auto &InstVec = InstrsIt->second;
1504 auto *InstIt = std::find(InstVec.begin(), InstVec.end(),
this);
1505 assert(InstIt != InstVec.end() &&
1506 "Expect instruction to be mapped to attachment");
1510 if (InstVec.size() == 1)
1511 IDToInstrs.erase(InstrsIt);
1513 InstVec.erase(InstIt);
1518 IDToInstrs[
ID].push_back(
this);
1526 if (KindID == LLVMContext::MD_dbg) {
1532 if (KindID == LLVMContext::MD_DIAssignID) {
1536 assert((!Node || !Node->isTemporary()) &&
1537 "Temporary DIAssignIDs are invalid");
1538 updateDIAssignIDMapping(cast_or_null<DIAssignID>(Node));
1549 auto *Existing =
getMetadata(LLVMContext::MD_annotation);
1552 auto *Tuple = cast<MDTuple>(Existing);
1553 for (
auto &
N : Tuple->operands()) {
1554 if (isa<MDString>(
N.get()))
1556 auto *MDAnnotationTuple = cast<MDTuple>(
N);
1557 if (
any_of(MDAnnotationTuple->operands(), [&AnnotationsSet](
auto &
Op) {
1558 return AnnotationsSet.contains(cast<MDString>(Op)->getString());
1569 Names.push_back(InfoTuple);
1577 auto *Existing =
getMetadata(LLVMContext::MD_annotation);
1580 auto *Tuple = cast<MDTuple>(Existing);
1581 for (
auto &
N : Tuple->operands()) {
1582 if (isa<MDString>(
N.get()) &&
1583 cast<MDString>(
N.get())->getString() ==
Name)
1585 Names.push_back(
N.get());
1600 Result.TBAA =
Info.lookup(LLVMContext::MD_tbaa);
1601 Result.TBAAStruct =
Info.lookup(LLVMContext::MD_tbaa_struct);
1602 Result.Scope =
Info.lookup(LLVMContext::MD_alias_scope);
1603 Result.NoAlias =
Info.lookup(LLVMContext::MD_noalias);
1610 setMetadata(LLVMContext::MD_tbaa_struct,
N.TBAAStruct);
1620MDNode *Instruction::getMetadataImpl(
unsigned KindID)
const {
1622 if (KindID == LLVMContext::MD_dbg)
1627void Instruction::getAllMetadataImpl(
1634 std::make_pair((
unsigned)LLVMContext::MD_dbg, DbgLoc.
getAsMDNode()));
1643 getOpcode() == Instruction::IndirectBr ||
1645 "Looking for branch weights on something besides branch");
1647 return ::extractProfTotalWeight(*
this, TotalVal);
1652 Other->getAllMetadata(MDs);
1653 for (
auto &MD : MDs) {
1655 if (
Offset != 0 && MD.first == LLVMContext::MD_type) {
1656 auto *OffsetConst = cast<ConstantInt>(
1657 cast<ConstantAsMetadata>(MD.second->getOperand(0))->getValue());
1658 Metadata *TypeId = MD.second->getOperand(1);
1660 OffsetConst->getType(), OffsetConst->getValue() +
Offset));
1668 auto *Attachment = MD.second;
1669 if (
Offset != 0 && MD.first == LLVMContext::MD_dbg) {
1673 auto *GVE = cast<DIGlobalVariableExpression>(Attachment);
1674 GV = GVE->getVariable();
1675 E = GVE->getExpression();
1679 OrigElements =
E->getElements();
1680 std::vector<uint64_t> Elements(OrigElements.
size() + 2);
1681 Elements[0] = dwarf::DW_OP_plus_uconst;
1683 llvm::copy(OrigElements, Elements.begin() + 2);
1693 LLVMContext::MD_type,
1713 cast<ConstantAsMetadata>(MD->getOperand(0))->getValue())
1715 assert(Val <= 2 &&
"unknown vcall visibility!");
1726 return cast_or_null<DISubprogram>(
getMetadata(LLVMContext::MD_dbg));
1732 return CU->getDebugInfoForProfiling();
1747 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...
Given that RA is a live value
This file defines the DenseSet and SmallDenseSet classes.
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.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
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.
MDNode * getAsMDNode() const
Return this as a bar MDNode.
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.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
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.
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()
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.
LLVMContextImpl *const pImpl
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 remove_if(UnaryPredicate P)
Remove items from the set vector based on a predicate function.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
ArrayRef< value_type > getArrayRef() const
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 * getMetadata(unsigned KindID) const
Get the current metadata attachments 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.
LLVMContext & getContext() const
All values hold a context through their type.
void clearMetadata()
Erase all metadata attached to this Value.
#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.
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.
void stable_sort(R &&Range)
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::...