66#define DEBUG_TYPE "bitcode-reader"
68STATISTIC(NumMDStringLoaded,
"Number of MDStrings loaded");
69STATISTIC(NumMDNodeTemporary,
"Number of MDNode::Temporary created");
70STATISTIC(NumMDRecordLoaded,
"Number of Metadata records loaded");
76 cl::desc(
"Import full type definitions for ThinLTO."));
80 cl::desc(
"Force disable the lazy-loading on-demand of metadata when "
81 "loading bitcode for importing."));
85static int64_t unrotateSign(
uint64_t U) {
return (U & 1) ? ~(U >> 1) : U >> 1; }
87class BitcodeReaderMetadataList {
114 unsigned RefsUpperBound;
117 BitcodeReaderMetadataList(
LLVMContext &
C,
size_t RefsUpperBound)
123 unsigned size()
const {
return MetadataPtrs.
size(); }
124 void resize(
unsigned N) { MetadataPtrs.
resize(
N); }
126 void clear() { MetadataPtrs.
clear(); }
128 void pop_back() { MetadataPtrs.
pop_back(); }
129 bool empty()
const {
return MetadataPtrs.
empty(); }
131 Metadata *operator[](
unsigned i)
const {
133 return MetadataPtrs[i];
137 if (
I < MetadataPtrs.
size())
138 return MetadataPtrs[
I];
142 void shrinkTo(
unsigned N) {
143 assert(
N <=
size() &&
"Invalid shrinkTo request!");
145 assert(UnresolvedNodes.
empty() &&
"Unexpected unresolved node");
159 MDNode *getMDNodeFwdRefOrNull(
unsigned Idx);
161 void tryToResolveCycles();
163 int getNextFwdRef() {
181void BitcodeReaderMetadataList::assignValue(
Metadata *MD,
unsigned Idx) {
182 if (
auto *MDN = dyn_cast<MDNode>(MD))
183 if (!MDN->isResolved())
201 TempMDTuple PrevMD(cast<MDTuple>(OldMD.
get()));
202 PrevMD->replaceAllUsesWith(MD);
206Metadata *BitcodeReaderMetadataList::getMetadataFwdRef(
unsigned Idx) {
208 if (
Idx >= RefsUpperBound)
221 ++NumMDNodeTemporary;
223 MetadataPtrs[
Idx].reset(MD);
227Metadata *BitcodeReaderMetadataList::getMetadataIfResolved(
unsigned Idx) {
229 if (
auto *
N = dyn_cast_or_null<MDNode>(MD))
230 if (!
N->isResolved())
235MDNode *BitcodeReaderMetadataList::getMDNodeFwdRefOrNull(
unsigned Idx) {
236 return dyn_cast_or_null<MDNode>(getMetadataFwdRef(
Idx));
239void BitcodeReaderMetadataList::tryToResolveCycles() {
245 for (
const auto &
Ref : OldTypeRefs.FwdDecls)
246 OldTypeRefs.Final.insert(
Ref);
247 OldTypeRefs.FwdDecls.clear();
251 for (
const auto &Array : OldTypeRefs.Arrays)
252 Array.second->replaceAllUsesWith(resolveTypeRefArray(
Array.first.get()));
253 OldTypeRefs.Arrays.clear();
258 for (
const auto &
Ref : OldTypeRefs.Unknown) {
260 Ref.second->replaceAllUsesWith(CT);
262 Ref.second->replaceAllUsesWith(
Ref.first);
264 OldTypeRefs.Unknown.clear();
266 if (UnresolvedNodes.
empty())
271 for (
unsigned I : UnresolvedNodes) {
272 auto &MD = MetadataPtrs[
I];
273 auto *
N = dyn_cast_or_null<MDNode>(MD);
277 assert(!
N->isTemporary() &&
"Unexpected forward reference");
282 UnresolvedNodes.clear();
285void BitcodeReaderMetadataList::addTypeRef(
MDString &
UUID,
289 OldTypeRefs.FwdDecls.insert(std::make_pair(&
UUID, &CT));
291 OldTypeRefs.Final.insert(std::make_pair(&
UUID, &CT));
295 auto *
UUID = dyn_cast_or_null<MDString>(MaybeUUID);
299 if (
auto *CT = OldTypeRefs.Final.lookup(
UUID))
302 auto &
Ref = OldTypeRefs.Unknown[
UUID];
308Metadata *BitcodeReaderMetadataList::upgradeTypeRefArray(
Metadata *MaybeTuple) {
309 auto *Tuple = dyn_cast_or_null<MDTuple>(MaybeTuple);
310 if (!Tuple || Tuple->isDistinct())
314 if (!Tuple->isTemporary())
315 return resolveTypeRefArray(Tuple);
319 OldTypeRefs.Arrays.emplace_back(
320 std::piecewise_construct, std::forward_as_tuple(Tuple),
322 return OldTypeRefs.Arrays.back().second.get();
325Metadata *BitcodeReaderMetadataList::resolveTypeRefArray(
Metadata *MaybeTuple) {
326 auto *Tuple = dyn_cast_or_null<MDTuple>(MaybeTuple);
327 if (!Tuple || Tuple->isDistinct())
332 Ops.
reserve(Tuple->getNumOperands());
333 for (
Metadata *MD : Tuple->operands())
341class PlaceholderQueue {
344 std::deque<DistinctMDOperandPlaceholder> PHs;
347 ~PlaceholderQueue() {
349 "PlaceholderQueue hasn't been flushed before being destroyed");
351 bool empty()
const {
return PHs.empty(); }
353 void flush(BitcodeReaderMetadataList &MetadataList);
357 void getTemporaries(BitcodeReaderMetadataList &MetadataList,
359 for (
auto &PH : PHs) {
360 auto ID = PH.getID();
361 auto *MD = MetadataList.lookup(
ID);
366 auto *
N = dyn_cast_or_null<MDNode>(MD);
367 if (
N &&
N->isTemporary())
376 PHs.emplace_back(
ID);
380void PlaceholderQueue::flush(BitcodeReaderMetadataList &MetadataList) {
381 while (!PHs.empty()) {
382 auto *MD = MetadataList.lookup(PHs.front().getID());
383 assert(MD &&
"Flushing placeholder on unassigned MD");
385 if (
auto *MDN = dyn_cast<MDNode>(MD))
386 assert(MDN->isResolved() &&
387 "Flushing Placeholder while cycles aren't resolved");
389 PHs.front().replaceUseWith(MD);
397 return make_error<StringError>(
402 BitcodeReaderMetadataList MetadataList;
415 std::vector<StringRef> MDStringRef;
422 std::vector<uint64_t> GlobalMetadataBitPosIndex;
427 uint64_t GlobalDeclAttachmentPos = 0;
432 unsigned NumGlobalDeclAttachSkipped = 0;
433 unsigned NumGlobalDeclAttachParsed = 0;
446 void lazyLoadOneMetadata(
unsigned Idx, PlaceholderQueue &Placeholders);
450 std::vector<std::pair<DICompileUnit *, Metadata *>> CUSubprograms;
459 bool StripTBAA =
false;
460 bool HasSeenOldLoopTags =
false;
461 bool NeedUpgradeToDIGlobalVariableExpression =
false;
462 bool NeedDeclareExpressionUpgrade =
false;
468 bool IsImporting =
false;
471 PlaceholderQueue &Placeholders,
StringRef Blob,
472 unsigned &NextMetadataNo);
479 void resolveForwardRefsAndPlaceholders(PlaceholderQueue &Placeholders);
482 void upgradeCUSubprograms() {
483 for (
auto CU_SP : CUSubprograms)
484 if (
auto *SPs = dyn_cast_or_null<MDTuple>(CU_SP.second))
485 for (
auto &
Op : SPs->operands())
486 if (
auto *SP = dyn_cast_or_null<DISubprogram>(
Op))
487 SP->replaceUnit(CU_SP.first);
488 CUSubprograms.clear();
492 void upgradeCUVariables() {
493 if (!NeedUpgradeToDIGlobalVariableExpression)
498 for (
unsigned I = 0, E = CUNodes->getNumOperands();
I != E; ++
I) {
499 auto *
CU = cast<DICompileUnit>(CUNodes->getOperand(
I));
500 if (
auto *GVs = dyn_cast_or_null<MDTuple>(
CU->getRawGlobalVariables()))
501 for (
unsigned I = 0;
I < GVs->getNumOperands();
I++)
503 dyn_cast_or_null<DIGlobalVariable>(GVs->getOperand(
I))) {
506 GVs->replaceOperandWith(
I, DGVE);
511 for (
auto &GV : TheModule.
globals()) {
513 GV.getMetadata(LLVMContext::MD_dbg, MDs);
514 GV.eraseMetadata(LLVMContext::MD_dbg);
516 if (
auto *DGV = dyn_cast<DIGlobalVariable>(MD)) {
519 GV.addMetadata(LLVMContext::MD_dbg, *DGVE);
521 GV.addMetadata(LLVMContext::MD_dbg, *MD);
528 if (
auto *SP = ParentSubprogram[S]) {
534 while (S && !isa<DISubprogram>(S)) {
535 S = dyn_cast_or_null<DILocalScope>(S->
getScope());
536 if (!Visited.
insert(S).second)
540 return ParentSubprogram[InitialScope] =
541 llvm::dyn_cast_or_null<DISubprogram>(S);
546 void upgradeCULocals() {
548 for (
MDNode *
N : CUNodes->operands()) {
549 auto *
CU = dyn_cast<DICompileUnit>(
N);
553 if (
CU->getRawImportedEntities()) {
556 for (
Metadata *
Op :
CU->getImportedEntities()->operands()) {
557 auto *IE = cast<DIImportedEntity>(
Op);
558 if (isa_and_nonnull<DILocalScope>(IE->getScope())) {
559 EntitiesToRemove.
insert(IE);
563 if (!EntitiesToRemove.
empty()) {
566 for (
Metadata *
Op :
CU->getImportedEntities()->operands()) {
567 if (!EntitiesToRemove.
contains(cast<DIImportedEntity>(
Op))) {
573 std::map<DISubprogram *, SmallVector<Metadata *>> SPToEntities;
574 for (
auto *
I : EntitiesToRemove) {
575 auto *Entity = cast<DIImportedEntity>(
I);
576 if (
auto *SP = findEnclosingSubprogram(
577 cast<DILocalScope>(Entity->getScope()))) {
578 SPToEntities[SP].push_back(Entity);
583 for (
auto I = SPToEntities.begin();
I != SPToEntities.end(); ++
I) {
585 auto RetainedNodes = SP->getRetainedNodes();
587 RetainedNodes.end());
599 ParentSubprogram.
clear();
604 void upgradeDeclareExpressions(
Function &
F) {
605 if (!NeedDeclareExpressionUpgrade)
608 auto UpdateDeclareIfNeeded = [&](
auto *Declare) {
609 auto *DIExpr = Declare->getExpression();
610 if (!DIExpr || !DIExpr->startsWithDeref() ||
611 !isa_and_nonnull<Argument>(Declare->getAddress()))
614 Ops.
append(std::next(DIExpr->elements_begin()), DIExpr->elements_end());
621 if (DVR.isDbgDeclare())
622 UpdateDeclareIfNeeded(&DVR);
624 if (
auto *DDI = dyn_cast<DbgDeclareInst>(&
I))
625 UpdateDeclareIfNeeded(DDI);
633 auto N = Expr.
size();
634 switch (FromVersion) {
636 return error(
"Invalid record");
638 if (
N >= 3 && Expr[
N - 3] == dwarf::DW_OP_bit_piece)
643 if (
N && Expr[0] == dwarf::DW_OP_deref) {
645 if (Expr.
size() >= 3 &&
649 *std::prev(
End) = dwarf::DW_OP_deref;
651 NeedDeclareExpressionUpgrade =
true;
657 while (!SubExpr.empty()) {
662 switch (SubExpr.front()) {
666 case dwarf::DW_OP_constu:
667 case dwarf::DW_OP_minus:
668 case dwarf::DW_OP_plus:
678 HistoricSize = std::min(SubExpr.size(), HistoricSize);
681 switch (SubExpr.front()) {
682 case dwarf::DW_OP_plus:
683 Buffer.
push_back(dwarf::DW_OP_plus_uconst);
684 Buffer.
append(Args.begin(), Args.end());
686 case dwarf::DW_OP_minus:
688 Buffer.
append(Args.begin(), Args.end());
693 Buffer.
append(Args.begin(), Args.end());
698 SubExpr = SubExpr.slice(HistoricSize);
711 void upgradeDebugInfo(
bool ModuleLevel) {
712 upgradeCUSubprograms();
713 upgradeCUVariables();
724 : MetadataList(TheModule.getContext(), Stream.SizeInBytes()),
725 ValueList(ValueList), Stream(Stream),
Context(TheModule.getContext()),
726 TheModule(TheModule), Callbacks(
std::
move(Callbacks)),
727 IsImporting(IsImporting) {}
731 bool hasFwdRefs()
const {
return MetadataList.hasFwdRefs(); }
734 if (
ID < MDStringRef.size())
735 return lazyLoadOneMDString(
ID);
736 if (
auto *MD = MetadataList.lookup(
ID))
740 if (
ID < (MDStringRef.size() + GlobalMetadataBitPosIndex.size())) {
741 PlaceholderQueue Placeholders;
742 lazyLoadOneMetadata(
ID, Placeholders);
743 resolveForwardRefsAndPlaceholders(Placeholders);
744 return MetadataList.lookup(
ID);
746 return MetadataList.getMetadataFwdRef(
ID);
750 return FunctionsWithSPs.
lookup(
F);
763 unsigned size()
const {
return MetadataList.size(); }
769MetadataLoader::MetadataLoaderImpl::lazyLoadModuleMetadataBlock() {
770 IndexCursor = Stream;
772 GlobalDeclAttachmentPos = 0;
783 switch (Entry.Kind) {
786 return error(
"Malformed block");
801 return std::move(Err);
808 return MaybeRecord.takeError();
809 unsigned NumStrings =
Record[0];
810 MDStringRef.reserve(NumStrings);
811 auto IndexNextMDString = [&](
StringRef Str) {
812 MDStringRef.push_back(Str);
814 if (
auto Err = parseMetadataStrings(
Record, Blob, IndexNextMDString))
815 return std::move(Err);
822 return std::move(Err);
828 return MaybeRecord.takeError();
830 return error(
"Invalid record");
834 return std::move(Err);
842 "Corrupted bitcode: Expected `Record` when trying to find the "
848 "Corrupted bitcode: Expected `METADATA_INDEX` when trying to "
849 "find the Metadata index");
851 return MaybeCode.takeError();
853 auto CurrentValue = BeginPos;
854 GlobalMetadataBitPosIndex.reserve(
Record.size());
855 for (
auto &Elt :
Record) {
857 GlobalMetadataBitPosIndex.push_back(CurrentValue);
864 return error(
"Corrupted Metadata block");
868 return std::move(Err);
874 Code = MaybeCode.get();
877 return MaybeCode.takeError();
882 Code = MaybeCode.get();
884 return MaybeCode.takeError();
893 return MaybeNextBitCode.takeError();
898 for (
unsigned i = 0; i !=
Size; ++i) {
903 MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(
Record[i]);
904 assert(MD &&
"Invalid metadata: expect fwd ref to MDNode");
910 if (!GlobalDeclAttachmentPos)
911 GlobalDeclAttachmentPos = SavedPos;
913 NumGlobalDeclAttachSkipped++;
957 GlobalMetadataBitPosIndex.clear();
971Expected<bool> MetadataLoader::MetadataLoaderImpl::loadGlobalDeclAttachments() {
973 if (!GlobalDeclAttachmentPos)
982 return std::move(Err);
991 switch (
Entry.Kind) {
994 return error(
"Malformed block");
997 assert(NumGlobalDeclAttachSkipped == NumGlobalDeclAttachParsed);
1009 assert(NumGlobalDeclAttachSkipped == NumGlobalDeclAttachParsed);
1013 NumGlobalDeclAttachParsed++;
1018 return std::move(Err);
1024 return MaybeRecord.takeError();
1025 if (
Record.size() % 2 == 0)
1026 return error(
"Invalid record");
1027 unsigned ValueID =
Record[0];
1028 if (ValueID >= ValueList.size())
1029 return error(
"Invalid record");
1030 if (
auto *GO = dyn_cast<GlobalObject>(ValueList[ValueID])) {
1035 if (
Error Err = parseGlobalObjectAttachment(
1037 return std::move(Err);
1039 return std::move(Err);
1044void MetadataLoader::MetadataLoaderImpl::callMDTypeCallback(
Metadata **Val,
1046 if (Callbacks.MDType) {
1047 (*Callbacks.MDType)(Val,
TypeID, Callbacks.GetTypeByID,
1048 Callbacks.GetContainedTypeID);
1055 if (!ModuleLevel && MetadataList.hasFwdRefs())
1056 return error(
"Invalid metadata: fwd refs into function blocks");
1060 auto EntryPos = Stream.GetCurrentBitNo();
1066 PlaceholderQueue Placeholders;
1070 if (ModuleLevel && IsImporting && MetadataList.empty() &&
1072 auto SuccessOrErr = lazyLoadModuleMetadataBlock();
1074 return SuccessOrErr.takeError();
1075 if (SuccessOrErr.get()) {
1078 MetadataList.resize(MDStringRef.size() +
1079 GlobalMetadataBitPosIndex.size());
1084 SuccessOrErr = loadGlobalDeclAttachments();
1086 return SuccessOrErr.takeError();
1087 assert(SuccessOrErr.get());
1091 resolveForwardRefsAndPlaceholders(Placeholders);
1092 upgradeDebugInfo(ModuleLevel);
1095 Stream.ReadBlockEnd();
1096 if (
Error Err = IndexCursor.JumpToBit(EntryPos))
1098 if (
Error Err = Stream.SkipBlock()) {
1109 unsigned NextMetadataNo = MetadataList.size();
1114 if (
Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
1117 switch (Entry.Kind) {
1120 return error(
"Malformed block");
1122 resolveForwardRefsAndPlaceholders(Placeholders);
1123 upgradeDebugInfo(ModuleLevel);
1133 ++NumMDRecordLoaded;
1135 Stream.readRecord(Entry.ID,
Record, &Blob)) {
1136 if (
Error Err = parseOneMetadata(
Record, MaybeCode.
get(), Placeholders,
1137 Blob, NextMetadataNo))
1144MDString *MetadataLoader::MetadataLoaderImpl::lazyLoadOneMDString(
unsigned ID) {
1145 ++NumMDStringLoaded;
1147 return cast<MDString>(MD);
1149 MetadataList.assignValue(MDS,
ID);
1153void MetadataLoader::MetadataLoaderImpl::lazyLoadOneMetadata(
1154 unsigned ID, PlaceholderQueue &Placeholders) {
1155 assert(
ID < (MDStringRef.size()) + GlobalMetadataBitPosIndex.size());
1156 assert(
ID >= MDStringRef.size() &&
"Unexpected lazy-loading of MDString");
1158 if (
auto *MD = MetadataList.lookup(
ID)) {
1159 auto *
N = dyn_cast<MDNode>(MD);
1162 if (!
N || !
N->isTemporary())
1167 if (
Error Err = IndexCursor.JumpToBit(
1168 GlobalMetadataBitPosIndex[
ID - MDStringRef.size()]))
1172 if (
Error E = IndexCursor.advanceSkippingSubblocks().moveInto(Entry))
1176 ++NumMDRecordLoaded;
1178 IndexCursor.readRecord(Entry.ID,
Record, &Blob)) {
1180 parseOneMetadata(
Record, MaybeCode.
get(), Placeholders, Blob,
ID))
1190void MetadataLoader::MetadataLoaderImpl::resolveForwardRefsAndPlaceholders(
1191 PlaceholderQueue &Placeholders) {
1195 Placeholders.getTemporaries(MetadataList, Temporaries);
1198 if (Temporaries.
empty() && !MetadataList.hasFwdRefs())
1203 for (
auto ID : Temporaries)
1204 lazyLoadOneMetadata(
ID, Placeholders);
1205 Temporaries.clear();
1209 while (MetadataList.hasFwdRefs())
1210 lazyLoadOneMetadata(MetadataList.getNextFwdRef(), Placeholders);
1215 MetadataList.tryToResolveCycles();
1219 Placeholders.flush(MetadataList);
1223 Type *Ty,
unsigned TyID) {
1235 if (
Idx < ValueList.
size() && ValueList[
Idx] &&
1236 ValueList[
Idx]->getType() == Ty)
1242Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
1244 PlaceholderQueue &Placeholders,
StringRef Blob,
unsigned &NextMetadataNo) {
1246 bool IsDistinct =
false;
1247 auto getMD = [&](
unsigned ID) ->
Metadata * {
1248 if (
ID < MDStringRef.size())
1249 return lazyLoadOneMDString(
ID);
1251 if (
auto *MD = MetadataList.lookup(
ID))
1255 if (
ID < (MDStringRef.size() + GlobalMetadataBitPosIndex.size())) {
1259 MetadataList.getMetadataFwdRef(NextMetadataNo);
1260 lazyLoadOneMetadata(
ID, Placeholders);
1261 return MetadataList.lookup(
ID);
1264 return MetadataList.getMetadataFwdRef(
ID);
1266 if (
auto *MD = MetadataList.getMetadataIfResolved(
ID))
1268 return &Placeholders.getPlaceholderOp(
ID);
1270 auto getMDOrNull = [&](
unsigned ID) ->
Metadata * {
1272 return getMD(
ID - 1);
1275 auto getMDOrNullWithoutPlaceholders = [&](
unsigned ID) ->
Metadata * {
1277 return MetadataList.getMetadataFwdRef(
ID - 1);
1280 auto getMDString = [&](
unsigned ID) ->
MDString * {
1283 auto MDS = getMDOrNull(
ID);
1284 return cast_or_null<MDString>(MDS);
1288 auto getDITypeRefOrNull = [&](
unsigned ID) {
1289 return MetadataList.upgradeTypeRef(getMDOrNull(
ID));
1292 auto getMetadataOrConstant = [&](
bool IsMetadata,
1295 return getMDOrNull(Entry);
1300#define GET_OR_DISTINCT(CLASS, ARGS) \
1301 (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
1310 if (
Error E = Stream.ReadCode().moveInto(Code))
1313 ++NumMDRecordLoaded;
1316 return error(
"METADATA_NAME not followed by METADATA_NAMED_NODE");
1318 return MaybeNextBitCode.takeError();
1323 for (
unsigned i = 0; i !=
Size; ++i) {
1324 MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(
Record[i]);
1326 return error(
"Invalid named metadata: expect fwd ref to MDNode");
1335 if (
Record.size() % 2 == 1)
1336 return error(
"Invalid record");
1340 auto dropRecord = [&] {
1341 MetadataList.assignValue(
MDNode::get(Context, {}), NextMetadataNo);
1344 if (
Record.size() != 2) {
1349 unsigned TyID =
Record[0];
1350 Type *Ty = Callbacks.GetTypeByID(TyID);
1356 Value *
V = ValueList.getValueFwdRef(
Record[1], Ty, TyID,
1359 return error(
"Invalid value reference from old fn metadata");
1367 if (
Record.size() % 2 == 1)
1368 return error(
"Invalid record");
1372 for (
unsigned i = 0; i !=
Size; i += 2) {
1373 unsigned TyID =
Record[i];
1374 Type *Ty = Callbacks.GetTypeByID(TyID);
1376 return error(
"Invalid record");
1382 return error(
"Invalid value reference from old metadata");
1384 assert(isa<ConstantAsMetadata>(MD) &&
1385 "Expected non-function-local metadata");
1386 callMDTypeCallback(&MD, TyID);
1391 MetadataList.assignValue(
MDNode::get(Context, Elts), NextMetadataNo);
1397 return error(
"Invalid record");
1399 unsigned TyID =
Record[0];
1400 Type *Ty = Callbacks.GetTypeByID(TyID);
1402 return error(
"Invalid record");
1406 return error(
"Invalid value reference from metadata");
1409 callMDTypeCallback(&MD, TyID);
1410 MetadataList.assignValue(MD, NextMetadataNo);
1431 return error(
"Invalid record");
1435 unsigned Column =
Record[2];
1441 MetadataList.assignValue(
1443 ImplicitCode, AtomGroup, AtomRank)),
1450 return error(
"Invalid record");
1457 return error(
"Invalid record");
1459 auto *Header = getMDString(
Record[3]);
1461 for (
unsigned I = 4, E =
Record.size();
I != E; ++
I)
1463 MetadataList.assignValue(
1479 switch (
Record[0] >> 1) {
1486 unrotateSign(
Record[2])));
1494 return error(
"Invalid record: Unsupported version of DISubrange");
1497 MetadataList.assignValue(Val, NextMetadataNo);
1498 IsDistinct =
Record[0] & 1;
1505 (Context, getMDOrNull(
Record[1]),
1507 getMDOrNull(
Record[4])));
1509 MetadataList.assignValue(Val, NextMetadataNo);
1510 IsDistinct =
Record[0] & 1;
1516 return error(
"Invalid record");
1518 IsDistinct =
Record[0] & 1;
1519 bool IsUnsigned =
Record[0] & 2;
1520 bool IsBigInt =
Record[0] & 4;
1525 const size_t NumWords =
Record.size() - 3;
1530 MetadataList.assignValue(
1532 (Context,
Value, IsUnsigned, getMDString(
Record[2]))),
1539 return error(
"Invalid record");
1541 IsDistinct =
Record[0] & 1;
1542 bool SizeIsMetadata =
Record[0] & 2;
1548 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata,
Record[3]);
1550 MetadataList.assignValue(
1552 (Context,
Record[1], getMDString(
Record[2]), SizeInBits,
1560 return error(
"Invalid record");
1562 IsDistinct =
Record[0] & 1;
1563 bool SizeIsMetadata =
Record[0] & 2;
1566 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata,
Record[3]);
1570 auto ReadWideInt = [&]() {
1572 unsigned NumWords =
Encoded >> 32;
1579 APInt Numerator = ReadWideInt();
1580 APInt Denominator = ReadWideInt();
1583 return error(
"Invalid record");
1585 MetadataList.assignValue(
1587 (Context,
Record[1], getMDString(
Record[2]), SizeInBits,
1589 Numerator, Denominator)),
1596 return error(
"Invalid record");
1598 IsDistinct =
Record[0] & 1;
1599 bool SizeIsMetadata =
Record[0] & 2;
1600 bool SizeIs8 =
Record.size() == 8;
1603 Metadata *StringLocationExp = SizeIs8 ? nullptr : getMDOrNull(
Record[5]);
1604 unsigned Offset = SizeIs8 ? 5 : 6;
1608 MetadataList.assignValue(
1620 return error(
"Invalid record");
1624 std::optional<unsigned> DWARFAddressSpace;
1626 DWARFAddressSpace =
Record[12] - 1;
1629 std::optional<DIDerivedType::PtrAuthData> PtrAuthData;
1634 if (
Record.size() > 14) {
1638 PtrAuthData.emplace(
Record[14]);
1641 IsDistinct =
Record[0] & 1;
1642 bool SizeIsMetadata =
Record[0] & 2;
1645 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata,
Record[7]);
1646 Metadata *OffsetInBits = getMetadataOrConstant(SizeIsMetadata,
Record[9]);
1648 MetadataList.assignValue(
1652 getDITypeRefOrNull(
Record[5]),
1654 OffsetInBits, DWARFAddressSpace, PtrAuthData, Flags,
1662 return error(
"Invalid record");
1664 IsDistinct =
Record[0] & 1;
1665 bool SizeIsMetadata =
Record[0] & 2;
1668 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata,
Record[5]);
1670 MetadataList.assignValue(
1672 (Context, getMDString(
Record[1]),
1677 getMDOrNull(
Record[12]))),
1684 return error(
"Invalid record");
1688 IsDistinct =
Record[0] & 0x1;
1689 bool IsNotUsedInTypeRef =
Record[0] & 2;
1690 bool SizeIsMetadata =
Record[0] & 4;
1698 return error(
"Alignment value is too large");
1704 unsigned RuntimeLang =
Record[12];
1705 std::optional<uint32_t> EnumKind;
1708 Metadata *TemplateParams =
nullptr;
1733 (
Tag == dwarf::DW_TAG_enumeration_type ||
1734 Tag == dwarf::DW_TAG_class_type ||
1735 Tag == dwarf::DW_TAG_structure_type ||
1736 Tag == dwarf::DW_TAG_union_type)) {
1744 TemplateParams = getMDOrNull(
Record[14]);
1748 OffsetInBits = getMetadataOrConstant(SizeIsMetadata,
Record[9]);
1751 VTableHolder = getDITypeRefOrNull(
Record[13]);
1752 TemplateParams = getMDOrNull(
Record[14]);
1756 DataLocation = getMDOrNull(
Record[17]);
1757 if (
Record.size() > 19) {
1758 Associated = getMDOrNull(
Record[18]);
1759 Allocated = getMDOrNull(
Record[19]);
1761 if (
Record.size() > 20) {
1762 Rank = getMDOrNull(
Record[20]);
1764 if (
Record.size() > 21) {
1767 if (
Record.size() > 23) {
1768 Specification = getMDOrNull(
Record[23]);
1771 BitStride = getMDOrNull(
Record[25]);
1777 Metadata *SizeInBits = getMetadataOrConstant(SizeIsMetadata,
Record[7]);
1783 SizeInBits, AlignInBits, OffsetInBits, Specification,
1784 NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind,
1785 VTableHolder, TemplateParams, Discriminator, DataLocation, Associated,
1793 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, EnumKind,
1794 VTableHolder, TemplateParams, Identifier, Discriminator,
1795 DataLocation, Associated, Allocated, Rank,
Annotations,
1796 Specification, NumExtraInhabitants, BitStride));
1797 if (!IsNotUsedInTypeRef && Identifier)
1798 MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT));
1800 MetadataList.assignValue(CT, NextMetadataNo);
1806 return error(
"Invalid record");
1807 bool IsOldTypeRefArray =
Record[0] < 2;
1810 IsDistinct =
Record[0] & 0x1;
1814 Types = MetadataList.upgradeTypeRefArray(Types);
1816 MetadataList.assignValue(
1825 return error(
"Invalid record");
1829 MetadataList.assignValue(
1832 (Context,
Record.size() >= 8 ? getMDOrNull(
Record[1]) :
nullptr,
1845 return error(
"Invalid record");
1848 std::optional<DIFile::ChecksumInfo<MDString *>> Checksum;
1857 MetadataList.assignValue(
1859 (Context, getMDString(
Record[1]),
1860 getMDString(
Record[2]), Checksum,
1861 Record.size() > 5 ? getMDString(
Record[5]) :
nullptr)),
1868 return error(
"Invalid record");
1878 Record.size() <= 15 ?
nullptr : getMDOrNull(
Record[15]),
1884 Record.size() <= 20 ?
nullptr : getMDString(
Record[20]),
1885 Record.size() <= 21 ?
nullptr : getMDString(
Record[21]));
1887 MetadataList.assignValue(
CU, NextMetadataNo);
1892 CUSubprograms.push_back({
CU, SPs});
1897 return error(
"Invalid record");
1899 bool HasSPFlags =
Record[0] & 4;
1912 const unsigned DIFlagMainSubprogram = 1 << 21;
1913 bool HasOldMainSubprogramFlag =
Flags & DIFlagMainSubprogram;
1914 if (HasOldMainSubprogramFlag)
1918 Flags &= ~static_cast<DINode::DIFlags>(DIFlagMainSubprogram);
1920 if (HasOldMainSubprogramFlag && HasSPFlags)
1921 SPFlags |= DISubprogram::SPFlagMainSubprogram;
1922 else if (!HasSPFlags)
1926 HasOldMainSubprogramFlag);
1929 IsDistinct = (
Record[0] & 1) || (SPFlags & DISubprogram::SPFlagDefinition);
1935 bool HasUnit =
Record[0] & 2;
1936 if (!HasSPFlags && HasUnit &&
Record.size() < 19)
1937 return error(
"Invalid record");
1938 if (HasSPFlags && !HasUnit)
1939 return error(
"Invalid record");
1942 bool HasThisAdj =
true;
1943 bool HasThrownTypes =
true;
1944 bool HasAnnotations =
false;
1945 bool HasTargetFuncName =
false;
1946 unsigned OffsetA = 0;
1947 unsigned OffsetB = 0;
1950 bool UsesKeyInstructions =
false;
1954 if (
Record.size() >= 19) {
1958 HasThisAdj =
Record.size() >= 20;
1959 HasThrownTypes =
Record.size() >= 21;
1961 HasAnnotations =
Record.size() >= 19;
1962 HasTargetFuncName =
Record.size() >= 20;
1963 UsesKeyInstructions =
Record.size() >= 21 ?
Record[20] : 0;
1970 getDITypeRefOrNull(
Record[1]),
1977 getDITypeRefOrNull(
Record[8 + OffsetA]),
1979 HasThisAdj ?
Record[16 + OffsetB] : 0,
1982 HasUnit ? CUorFn :
nullptr,
1983 getMDOrNull(
Record[13 + OffsetB]),
1984 getMDOrNull(
Record[14 + OffsetB]),
1985 getMDOrNull(
Record[15 + OffsetB]),
1986 HasThrownTypes ? getMDOrNull(
Record[17 + OffsetB])
1988 HasAnnotations ? getMDOrNull(
Record[18 + OffsetB])
1990 HasTargetFuncName ? getMDString(
Record[19 + OffsetB])
1992 UsesKeyInstructions));
1993 MetadataList.assignValue(SP, NextMetadataNo);
1998 if (
auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(CUorFn))
1999 if (
auto *
F = dyn_cast<Function>(CMD->getValue())) {
2000 if (
F->isMaterializable())
2003 FunctionsWithSPs[
F] =
SP;
2004 else if (!
F->empty())
2005 F->setSubprogram(SP);
2012 return error(
"Invalid record");
2015 MetadataList.assignValue(
2017 (Context, getMDOrNull(
Record[1]),
2025 return error(
"Invalid record");
2028 MetadataList.assignValue(
2030 (Context, getMDOrNull(
Record[1]),
2037 IsDistinct =
Record[0] & 1;
2038 MetadataList.assignValue(
2040 (Context, getMDOrNull(
Record[1]),
2052 else if (
Record.size() == 5)
2055 return error(
"Invalid record");
2057 IsDistinct =
Record[0] & 1;
2058 bool ExportSymbols =
Record[0] & 2;
2059 MetadataList.assignValue(
2061 (Context, getMDOrNull(
Record[1]),
Name, ExportSymbols)),
2068 return error(
"Invalid record");
2071 MetadataList.assignValue(
2074 getMDString(
Record[4]))),
2081 return error(
"Invalid record");
2084 MetadataList.assignValue(
2087 getMDOrNull(
Record[4]))),
2094 return error(
"Invalid record");
2097 MetadataList.assignValue(
2099 (Context, getMDString(
Record[1]),
2100 getDITypeRefOrNull(
Record[2]),
2102 : getMDOrNull(
false))),
2109 return error(
"Invalid record");
2113 MetadataList.assignValue(
2117 getDITypeRefOrNull(
Record[3]),
2118 (
Record.size() == 6) ? getMDOrNull(
Record[4]) : getMDOrNull(
false),
2120 : getMDOrNull(
Record[4]))),
2127 return error(
"Invalid record");
2129 IsDistinct =
Record[0] & 1;
2137 MetadataList.assignValue(
2139 (Context, getMDOrNull(
Record[1]),
2151 MetadataList.assignValue(
2154 (Context, getMDOrNull(
Record[1]), getMDString(
Record[2]),
2157 getMDOrNull(
Record[10]),
nullptr,
Record[11],
nullptr)),
2164 NeedUpgradeToDIGlobalVariableExpression =
true;
2167 if (
Record.size() > 11) {
2169 return error(
"Alignment value is too large");
2170 AlignInBits =
Record[11];
2173 if (
auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(Expr)) {
2174 if (
auto *GV = dyn_cast<GlobalVariable>(CMD->getValue())) {
2177 }
else if (
auto *CI = dyn_cast<ConstantInt>(CMD->getValue())) {
2179 {dwarf::DW_OP_constu, CI->getZExtValue(),
2180 dwarf::DW_OP_stack_value});
2187 (Context, getMDOrNull(
Record[1]), getMDString(
Record[2]),
2190 getMDOrNull(
Record[10]),
nullptr, AlignInBits,
nullptr));
2200 MetadataList.assignValue(
MDNode, NextMetadataNo);
2203 return error(
"Invalid record");
2209 return error(
"Invalid DIAssignID record.");
2211 IsDistinct =
Record[0] & 1;
2213 return error(
"Invalid DIAssignID record. Must be distinct");
2222 return error(
"Invalid record");
2224 IsDistinct =
Record[0] & 1;
2225 bool HasAlignment =
Record[0] & 2;
2229 bool HasTag = !HasAlignment &&
Record.size() > 8;
2235 return error(
"Alignment value is too large");
2241 MetadataList.assignValue(
2243 (Context, getMDOrNull(
Record[1 + HasTag]),
2244 getMDString(
Record[2 + HasTag]),
2246 getDITypeRefOrNull(
Record[5 + HasTag]),
2254 return error(
"Invalid record");
2256 IsDistinct =
Record[0] & 1;
2259 bool IsArtificial =
Record[0] & 2;
2260 std::optional<unsigned> CoroSuspendIdx;
2263 if (RawSuspendIdx != std::numeric_limits<uint64_t>::max()) {
2264 if (RawSuspendIdx > (
uint64_t)std::numeric_limits<unsigned>::max())
2265 return error(
"CoroSuspendIdx value is too large");
2266 CoroSuspendIdx = RawSuspendIdx;
2270 MetadataList.assignValue(
2272 (Context, getMDOrNull(
Record[1]),
2274 Column, IsArtificial, CoroSuspendIdx)),
2281 return error(
"Invalid record");
2283 IsDistinct =
Record[0] & 1;
2288 if (
Error Err = upgradeDIExpression(
Version, Elts, Buffer))
2298 return error(
"Invalid record");
2304 MetadataList.assignValue(
2306 (Context, getMDOrNull(
Record[1]), Expr)),
2313 return error(
"Invalid record");
2316 MetadataList.assignValue(
2318 (Context, getMDString(
Record[1]),
2328 return error(
"Invalid DIImportedEntity record");
2331 bool HasFile = (
Record.size() >= 7);
2332 bool HasElements = (
Record.size() >= 8);
2333 MetadataList.assignValue(
2336 getDITypeRefOrNull(
Record[3]),
2337 HasFile ? getMDOrNull(
Record[6]) :
nullptr,
2339 HasElements ? getMDOrNull(
Record[7]) :
nullptr)),
2349 ++NumMDStringLoaded;
2351 MetadataList.assignValue(MD, NextMetadataNo);
2356 auto CreateNextMDString = [&](
StringRef Str) {
2357 ++NumMDStringLoaded;
2358 MetadataList.assignValue(
MDString::get(Context, Str), NextMetadataNo);
2361 if (
Error Err = parseMetadataStrings(
Record, Blob, CreateNextMDString))
2366 if (
Record.size() % 2 == 0)
2367 return error(
"Invalid record");
2368 unsigned ValueID =
Record[0];
2369 if (ValueID >= ValueList.size())
2370 return error(
"Invalid record");
2371 if (
auto *GO = dyn_cast<GlobalObject>(ValueList[ValueID]))
2372 if (
Error Err = parseGlobalObjectAttachment(
2389 if (isa<MDNode>(MD) && cast<MDNode>(MD)->isTemporary())
2391 "Invalid record: DIArgList should not contain forward refs");
2392 if (!isa<ValueAsMetadata>(MD))
2393 return error(
"Invalid record");
2394 Elts.
push_back(cast<ValueAsMetadata>(MD));
2397 MetadataList.assignValue(
DIArgList::get(Context, Elts), NextMetadataNo);
2403#undef GET_OR_DISTINCT
2406Error MetadataLoader::MetadataLoaderImpl::parseMetadataStrings(
2413 return error(
"Invalid record: metadata strings layout");
2415 unsigned NumStrings =
Record[0];
2416 unsigned StringsOffset =
Record[1];
2418 return error(
"Invalid record: metadata strings with no strings");
2419 if (StringsOffset > Blob.
size())
2420 return error(
"Invalid record: metadata strings corrupt offset");
2427 if (
R.AtEndOfStream())
2428 return error(
"Invalid record: metadata strings bad length");
2433 if (Strings.size() <
Size)
2434 return error(
"Invalid record: metadata strings truncated chars");
2436 CallBack(Strings.slice(0,
Size));
2437 Strings = Strings.drop_front(
Size);
2438 }
while (--NumStrings);
2443Error MetadataLoader::MetadataLoaderImpl::parseGlobalObjectAttachment(
2446 for (
unsigned I = 0, E =
Record.size();
I != E;
I += 2) {
2447 auto K = MDKindMap.find(
Record[
I]);
2448 if (K == MDKindMap.end())
2449 return error(
"Invalid ID");
2453 return error(
"Invalid metadata attachment: expect fwd ref to MDNode");
2466 PlaceholderQueue Placeholders;
2470 if (
Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
2473 switch (Entry.Kind) {
2476 return error(
"Malformed block");
2478 resolveForwardRefsAndPlaceholders(Placeholders);
2487 ++NumMDRecordLoaded;
2491 switch (MaybeRecord.
get()) {
2495 unsigned RecordLength =
Record.size();
2497 return error(
"Invalid record");
2498 if (RecordLength % 2 == 0) {
2500 if (
Error Err = parseGlobalObjectAttachment(
F,
Record))
2507 for (
unsigned i = 1; i != RecordLength; i = i + 2) {
2508 unsigned Kind =
Record[i];
2510 if (
I == MDKindMap.end())
2511 return error(
"Invalid ID");
2512 if (
I->second == LLVMContext::MD_tbaa && StripTBAA)
2516 if (
Idx < (MDStringRef.size() + GlobalMetadataBitPosIndex.size()) &&
2517 !MetadataList.lookup(
Idx)) {
2520 lazyLoadOneMetadata(
Idx, Placeholders);
2521 resolveForwardRefsAndPlaceholders(Placeholders);
2524 Metadata *Node = MetadataList.getMetadataFwdRef(
Idx);
2525 if (isa<LocalAsMetadata>(Node))
2529 MDNode *MD = dyn_cast_or_null<MDNode>(Node);
2531 return error(
"Invalid metadata attachment");
2533 if (HasSeenOldLoopTags &&
I->second == LLVMContext::MD_loop)
2536 if (
I->second == LLVMContext::MD_tbaa) {
2549Error MetadataLoader::MetadataLoaderImpl::parseMetadataKindRecord(
2552 return error(
"Invalid record");
2554 unsigned Kind =
Record[0];
2557 unsigned NewKind = TheModule.getMDKindID(
Name.str());
2558 if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
2559 return error(
"Conflicting METADATA_KIND records");
2573 if (
Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
2576 switch (Entry.Kind) {
2579 return error(
"Malformed block");
2589 ++NumMDRecordLoaded;
2593 switch (MaybeCode.
get()) {
2606 Pimpl = std::move(
RHS.Pimpl);
2618 Stream, TheModule, ValueList,
std::
move(Callbacks), IsImporting)) {}
2620Error MetadataLoader::parseMetadata(
bool ModuleLevel) {
2621 return Pimpl->parseMetadata(ModuleLevel);
2629 return Pimpl->getMetadataFwdRefOrLoad(
Idx);
2633 return Pimpl->lookupSubprogramForFunction(
F);
2638 return Pimpl->parseMetadataAttachment(
F, InstructionList);
2642 return Pimpl->parseMetadataKinds();
2646 return Pimpl->setStripTBAA(StripTBAA);
2655 return Pimpl->upgradeDebugIntrinsics(
F);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
#define LLVM_UNLIKELY(EXPR)
#define LLVM_LIKELY(EXPR)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
#define GET_OR_DISTINCT(CLASS, ARGS)
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallString class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
std::pair< llvm::MachO::Target, std::string > UUID
Class for arbitrary precision integers.
Annotations lets you mark points and ranges inside source code, for tests:
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
@ AF_DontPopBlockAtEnd
If this flag is used, the advance() method does not automatically pop the block scope when the end of...
Expected< BitstreamEntry > advanceSkippingSubblocks(unsigned Flags=0)
This is a convenience function for clients that don't expect any subblocks.
LLVM_ABI Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
LLVM_ABI Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
Expected< unsigned > ReadCode()
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
static DIAssignID * getDistinct(LLVMContext &Context)
Basic type, like 'int' or 'float'.
static LLVM_ABI DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, Metadata *Specification, uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, std::optional< uint32_t > EnumKind, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations, Metadata *BitStride)
Build a DICompositeType with the given ODR identifier.
MDString * getRawIdentifier() const
ChecksumKind
Which algorithm (e.g.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
LLVM_ABI DIScope * getScope() const
String type, Fortran CHARACTER(n)
Subprogram description. Uses SubclassData1.
static LLVM_ABI DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
DISPFlags
Debug info subprogram flags.
Type array for a subprogram.
bool isForwardDecl() const
This class represents an Operation in the Expression.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Implements a dense probed hash-table based set.
Placeholder metadata for operands of distinct MDNodes.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
Generic tagged DWARF-like metadata node.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
LLVM_ABI void addDebugInfo(DIGlobalVariableExpression *GV)
Attach a DIGlobalVariableExpression.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This is an important class for using LLVM in a threaded context.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
A Module instance is used to store all the information related to an LLVM module.
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
iterator_range< global_iterator > globals()
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
MutableArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
LLVM_ABI void addOperand(MDNode *M)
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A vector that has set insertion semantics.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool contains(const key_type &key) const
Check if the SetVector contains the given key.
This represents a position within a bitstream.
Implements a dense probed hash-table based set with some number of buckets stored inline.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
size - Get the string size.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Tracking metadata reference.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
TypeID
Definitions of all of the base types for the Type system.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
bool isMetadataTy() const
Return true if this is 'metadata'.
LLVM Value Representation.
std::pair< iterator, bool > insert(const ValueT &V)
An efficient, type-erasing, non-owning reference to a callable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_FIXED_POINT_TYPE
@ METADATA_GLOBAL_VAR_EXPR
initializer< Ty > init(const Ty &Val)
@ DW_OP_LLVM_fragment
Only used in LLVM metadata.
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
NodeAddr< CodeNode * > Code
This is an optimization pass for GlobalISel generic memory operations.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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.
std::error_code make_error_code(BitcodeError E)
LLVM_ABI MDNode * upgradeInstructionLoopAttachment(MDNode &N)
Upgrade the loop attachment metadata node.
bool mayBeOldLoopAttachmentTag(StringRef Name)
Check whether a string looks like an old loop attachment tag.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
@ Ref
The access may reference the value stored in memory.
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)
const char * toString(DWARFSectionKind Kind)
LLVM_ABI MDNode * UpgradeTBAANode(MDNode &TBAANode)
If the given TBAA tag uses the scalar TBAA format, create a new node corresponding to the upgrade to ...
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...