Movatterモバイル変換


[0]ホーム

URL:


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

Generated on Thu Jul 17 2025 12:30:46 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp