aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Bitcode/Reader/MetadataLoader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/MetadataLoader.cpp82
1 files changed, 53 insertions, 29 deletions
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 13d53a35084d..4b5cfedaa99c 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -14,8 +14,6 @@
#include "llvm/ADT/BitmaskEnum.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
@@ -55,6 +53,7 @@
#include <deque>
#include <iterator>
#include <limits>
+#include <optional>
#include <string>
#include <tuple>
#include <type_traits>
@@ -222,7 +221,7 @@ Metadata *BitcodeReaderMetadataList::getMetadataFwdRef(unsigned Idx) {
// Create and return a placeholder, which will later be RAUW'd.
++NumMDNodeTemporary;
- Metadata *MD = MDNode::getTemporary(Context, None).release();
+ Metadata *MD = MDNode::getTemporary(Context, std::nullopt).release();
MetadataPtrs[Idx].reset(MD);
return MD;
}
@@ -304,7 +303,7 @@ Metadata *BitcodeReaderMetadataList::upgradeTypeRef(Metadata *MaybeUUID) {
auto &Ref = OldTypeRefs.Unknown[UUID];
if (!Ref)
- Ref = MDNode::getTemporary(Context, None);
+ Ref = MDNode::getTemporary(Context, std::nullopt);
return Ref.get();
}
@@ -321,7 +320,7 @@ Metadata *BitcodeReaderMetadataList::upgradeTypeRefArray(Metadata *MaybeTuple) {
// resolveTypeRefArrays() will be resolve this forward reference.
OldTypeRefs.Arrays.emplace_back(
std::piecewise_construct, std::forward_as_tuple(Tuple),
- std::forward_as_tuple(MDTuple::getTemporary(Context, None)));
+ std::forward_as_tuple(MDTuple::getTemporary(Context, std::nullopt)));
return OldTypeRefs.Arrays.back().second.get();
}
@@ -407,7 +406,7 @@ class MetadataLoader::MetadataLoaderImpl {
BitstreamCursor &Stream;
LLVMContext &Context;
Module &TheModule;
- std::function<Type *(unsigned)> getTypeByID;
+ MetadataLoaderCallbacks Callbacks;
/// Cursor associated with the lazy-loading of Metadata. This is the easy way
/// to keep around the right "context" (Abbrev list) to be able to jump in
@@ -552,7 +551,7 @@ class MetadataLoader::MetadataLoaderImpl {
case 0:
if (N >= 3 && Expr[N - 3] == dwarf::DW_OP_bit_piece)
Expr[N - 3] = dwarf::DW_OP_LLVM_fragment;
- LLVM_FALLTHROUGH;
+ [[fallthrough]];
case 1:
// Move DW_OP_deref to the end.
if (N && Expr[0] == dwarf::DW_OP_deref) {
@@ -564,7 +563,7 @@ class MetadataLoader::MetadataLoaderImpl {
*std::prev(End) = dwarf::DW_OP_deref;
}
NeedDeclareExpressionUpgrade = true;
- LLVM_FALLTHROUGH;
+ [[fallthrough]];
case 2: {
// Change DW_OP_plus to DW_OP_plus_uconst.
// Change DW_OP_minus to DW_OP_uconst, DW_OP_minus
@@ -613,7 +612,7 @@ class MetadataLoader::MetadataLoaderImpl {
SubExpr = SubExpr.slice(HistoricSize);
}
Expr = MutableArrayRef<uint64_t>(Buffer);
- LLVM_FALLTHROUGH;
+ [[fallthrough]];
}
case 3:
// Up-to-date!
@@ -628,14 +627,15 @@ class MetadataLoader::MetadataLoaderImpl {
upgradeCUVariables();
}
+ void callMDTypeCallback(Metadata **Val, unsigned TypeID);
+
public:
MetadataLoaderImpl(BitstreamCursor &Stream, Module &TheModule,
BitcodeReaderValueList &ValueList,
- std::function<Type *(unsigned)> getTypeByID,
- bool IsImporting)
+ MetadataLoaderCallbacks Callbacks, bool IsImporting)
: MetadataList(TheModule.getContext(), Stream.SizeInBytes()),
ValueList(ValueList), Stream(Stream), Context(TheModule.getContext()),
- TheModule(TheModule), getTypeByID(std::move(getTypeByID)),
+ TheModule(TheModule), Callbacks(std::move(Callbacks)),
IsImporting(IsImporting) {}
Error parseMetadata(bool ModuleLevel);
@@ -856,6 +856,7 @@ MetadataLoader::MetadataLoaderImpl::lazyLoadModuleMetadataBlock() {
case bitc::METADATA_TEMPLATE_VALUE:
case bitc::METADATA_GLOBAL_VAR:
case bitc::METADATA_LOCAL_VAR:
+ case bitc::METADATA_ASSIGN_ID:
case bitc::METADATA_LABEL:
case bitc::METADATA_EXPRESSION:
case bitc::METADATA_OBJC_PROPERTY:
@@ -952,6 +953,14 @@ Expected<bool> MetadataLoader::MetadataLoaderImpl::loadGlobalDeclAttachments() {
}
}
+void MetadataLoader::MetadataLoaderImpl::callMDTypeCallback(Metadata **Val,
+ unsigned TypeID) {
+ if (Callbacks.MDType) {
+ (*Callbacks.MDType)(Val, TypeID, Callbacks.GetTypeByID,
+ Callbacks.GetContainedTypeID);
+ }
+}
+
/// Parse a METADATA_BLOCK. If ModuleLevel is true then we are parsing
/// module level metadata.
Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel) {
@@ -1211,7 +1220,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
// If this isn't a LocalAsMetadata record, we're dropping it. This used
// to be legal, but there's no upgrade path.
auto dropRecord = [&] {
- MetadataList.assignValue(MDNode::get(Context, None), NextMetadataNo);
+ MetadataList.assignValue(MDNode::get(Context, std::nullopt),
+ NextMetadataNo);
NextMetadataNo++;
};
if (Record.size() != 2) {
@@ -1220,7 +1230,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
}
unsigned TyID = Record[0];
- Type *Ty = getTypeByID(TyID);
+ Type *Ty = Callbacks.GetTypeByID(TyID);
if (Ty->isMetadataTy() || Ty->isVoidTy()) {
dropRecord();
break;
@@ -1244,7 +1254,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
SmallVector<Metadata *, 8> Elts;
for (unsigned i = 0; i != Size; i += 2) {
unsigned TyID = Record[i];
- Type *Ty = getTypeByID(TyID);
+ Type *Ty = Callbacks.GetTypeByID(TyID);
if (!Ty)
return error("Invalid record");
if (Ty->isMetadataTy())
@@ -1254,9 +1264,10 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
/*ConstExprInsertBB*/ nullptr);
if (!V)
return error("Invalid value reference from old metadata");
- auto *MD = ValueAsMetadata::get(V);
+ Metadata *MD = ValueAsMetadata::get(V);
assert(isa<ConstantAsMetadata>(MD) &&
"Expected non-function-local metadata");
+ callMDTypeCallback(&MD, TyID);
Elts.push_back(MD);
} else
Elts.push_back(nullptr);
@@ -1270,7 +1281,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
return error("Invalid record");
unsigned TyID = Record[0];
- Type *Ty = getTypeByID(TyID);
+ Type *Ty = Callbacks.GetTypeByID(TyID);
if (Ty->isMetadataTy() || Ty->isVoidTy())
return error("Invalid record");
@@ -1279,13 +1290,15 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (!V)
return error("Invalid value reference from metadata");
- MetadataList.assignValue(ValueAsMetadata::get(V), NextMetadataNo);
+ Metadata *MD = ValueAsMetadata::get(V);
+ callMDTypeCallback(&MD, TyID);
+ MetadataList.assignValue(MD, NextMetadataNo);
NextMetadataNo++;
break;
}
case bitc::METADATA_DISTINCT_NODE:
IsDistinct = true;
- LLVM_FALLTHROUGH;
+ [[fallthrough]];
case bitc::METADATA_NODE: {
SmallVector<Metadata *, 8> Elts;
Elts.reserve(Record.size());
@@ -1392,7 +1405,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (IsBigInt) {
const uint64_t BitWidth = Record[1];
const size_t NumWords = Record.size() - 3;
- Value = readWideAPInt(makeArrayRef(&Record[3], NumWords), BitWidth);
+ Value = readWideAPInt(ArrayRef(&Record[3], NumWords), BitWidth);
} else
Value = APInt(64, unrotateSign(Record[1]), !IsUnsigned);
@@ -1446,7 +1459,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
// DWARF address space is encoded as N->getDWARFAddressSpace() + 1. 0 means
// that there is no DWARF address space associated with DIDerivedType.
- Optional<unsigned> DWARFAddressSpace;
+ std::optional<unsigned> DWARFAddressSpace;
if (Record.size() > 12 && Record[12])
DWARFAddressSpace = Record[12] - 1;
@@ -1609,7 +1622,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
return error("Invalid record");
IsDistinct = Record[0];
- Optional<DIFile::ChecksumInfo<MDString *>> Checksum;
+ std::optional<DIFile::ChecksumInfo<MDString *>> Checksum;
// The BitcodeWriter writes null bytes into Record[3:4] when the Checksum
// is not present. This matches up with the old internal representation,
// and the old encoding for CSK_None in the ChecksumKind. The new
@@ -1619,11 +1632,10 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Checksum.emplace(static_cast<DIFile::ChecksumKind>(Record[3]),
getMDString(Record[4]));
MetadataList.assignValue(
- GET_OR_DISTINCT(
- DIFile,
- (Context, getMDString(Record[1]), getMDString(Record[2]), Checksum,
- Record.size() > 5 ? Optional<MDString *>(getMDString(Record[5]))
- : None)),
+ GET_OR_DISTINCT(DIFile,
+ (Context, getMDString(Record[1]),
+ getMDString(Record[2]), Checksum,
+ Record.size() > 5 ? getMDString(Record[5]) : nullptr)),
NextMetadataNo);
NextMetadataNo++;
break;
@@ -1964,6 +1976,18 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
+ case bitc::METADATA_ASSIGN_ID: {
+ if (Record.size() != 1)
+ return error("Invalid DIAssignID record.");
+
+ IsDistinct = Record[0] & 1;
+ if (!IsDistinct)
+ return error("Invalid DIAssignID record. Must be distinct");
+
+ MetadataList.assignValue(DIAssignID::getDistinct(Context), NextMetadataNo);
+ NextMetadataNo++;
+ break;
+ }
case bitc::METADATA_LOCAL_VAR: {
// 10th field is for the obseleted 'inlinedAt:' field.
if (Record.size() < 8 || Record.size() > 10)
@@ -2347,9 +2371,9 @@ MetadataLoader::~MetadataLoader() = default;
MetadataLoader::MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
BitcodeReaderValueList &ValueList,
bool IsImporting,
- std::function<Type *(unsigned)> getTypeByID)
+ MetadataLoaderCallbacks Callbacks)
: Pimpl(std::make_unique<MetadataLoaderImpl>(
- Stream, TheModule, ValueList, std::move(getTypeByID), IsImporting)) {}
+ Stream, TheModule, ValueList, std::move(Callbacks), IsImporting)) {}
Error MetadataLoader::parseMetadata(bool ModuleLevel) {
return Pimpl->parseMetadata(ModuleLevel);