Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serialization] Use 32 bit aligned decl id instead of unaligned decl id #95348

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions clang/include/clang/Serialization/ASTBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ const unsigned int NUM_PREDEF_SUBMODULE_IDS = 1;
/// because blobs in bitstream are 32-bit aligned). This structure is
/// serialized "as is" to the AST file.
class UnalignedUInt64 {
uint32_t BitLow = 0;
uint32_t BitHigh = 0;
uint32_t BitLow;
uint32_t BitHigh;

public:
UnalignedUInt64() = default;
UnalignedUInt64(uint64_t BitOffset) { set(BitOffset); }

operator uint64_t() const {
return get();
}

void set(uint64_t Offset) {
BitLow = Offset;
BitHigh = Offset >> 32;
Expand Down Expand Up @@ -255,11 +259,9 @@ class DeclOffset {
}
};

// The unaligned decl ID used in the Blobs of bistreams.
using unaligned_decl_id_t =
llvm::support::detail::packed_endian_specific_integral<
serialization::DeclID, llvm::endianness::native,
llvm::support::unaligned>;
// The 32 bits aligned decl ID used in the Blobs of bistreams due the blobs
// are 32 bits aligned.
using SerializedDeclID = UnalignedUInt64;

/// The number of predefined preprocessed entity IDs.
const unsigned int NUM_PREDEF_PP_ENTITY_IDS = 1;
Expand Down Expand Up @@ -1986,9 +1988,9 @@ enum CleanupObjectKind { COK_Block, COK_CompoundLiteral };

/// Describes the categories of an Objective-C class.
struct ObjCCategoriesInfo {
// The ID of the definition. Use unaligned_decl_id_t to keep
// The ID of the definition. Use SerializedDeclID to keep
// ObjCCategoriesInfo 32-bit aligned.
unaligned_decl_id_t DefinitionID;
SerializedDeclID DefinitionID;

// Offset into the array of category lists.
unsigned Offset;
Expand Down
10 changes: 5 additions & 5 deletions clang/include/clang/Serialization/ASTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,11 @@ class ASTReader

struct FileDeclsInfo {
ModuleFile *Mod = nullptr;
ArrayRef<serialization::unaligned_decl_id_t> Decls;
ArrayRef<serialization::SerializedDeclID> Decls;

FileDeclsInfo() = default;
FileDeclsInfo(ModuleFile *Mod,
ArrayRef<serialization::unaligned_decl_id_t> Decls)
ArrayRef<serialization::SerializedDeclID> Decls)
: Mod(Mod), Decls(Decls) {}
};

Expand All @@ -599,7 +599,7 @@ class ASTReader

/// An array of lexical contents of a declaration context, as a sequence of
/// Decl::Kind, DeclID pairs.
using LexicalContents = ArrayRef<serialization::unaligned_decl_id_t>;
using LexicalContents = ArrayRef<serialization::SerializedDeclID>;

/// Map from a DeclContext to its lexical contents.
llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
Expand Down Expand Up @@ -1482,7 +1482,7 @@ class ASTReader
public:
class ModuleDeclIterator
: public llvm::iterator_adaptor_base<
ModuleDeclIterator, const serialization::unaligned_decl_id_t *,
ModuleDeclIterator, const serialization::SerializedDeclID *,
std::random_access_iterator_tag, const Decl *, ptrdiff_t,
const Decl *, const Decl *> {
ASTReader *Reader = nullptr;
Expand All @@ -1492,7 +1492,7 @@ class ASTReader
ModuleDeclIterator() : iterator_adaptor_base(nullptr) {}

ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
const serialization::unaligned_decl_id_t *Pos)
const serialization::SerializedDeclID *Pos)
: iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}

value_type operator*() const {
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Serialization/ModuleFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class ModuleFile {
unsigned BaseDeclIndex = 0;

/// Array of file-level DeclIDs sorted by file.
const serialization::unaligned_decl_id_t *FileSortedDecls = nullptr;
const serialization::SerializedDeclID *FileSortedDecls = nullptr;
unsigned NumFileSortedDecls = 0;

/// Array of category list location information within this
Expand Down
22 changes: 11 additions & 11 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M,
if (!Lex.first) {
Lex = std::make_pair(
&M, llvm::ArrayRef(
reinterpret_cast<const unaligned_decl_id_t *>(Blob.data()),
reinterpret_cast<const SerializedDeclID *>(Blob.data()),
Blob.size() / sizeof(DeclID)));
}
DC->setHasExternalLexicalStorage(true);
Expand Down Expand Up @@ -1658,7 +1658,7 @@ bool ASTReader::ReadSLocEntry(int ID) {

unsigned NumFileDecls = Record[7];
if (NumFileDecls && ContextObj) {
const unaligned_decl_id_t *FirstDecl = F->FileSortedDecls + Record[6];
const SerializedDeclID *FirstDecl = F->FileSortedDecls + Record[6];
assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?");
FileDeclIDs[FID] =
FileDeclsInfo(F, llvm::ArrayRef(FirstDecl, NumFileDecls));
Expand Down Expand Up @@ -3388,7 +3388,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
case TU_UPDATE_LEXICAL: {
DeclContext *TU = ContextObj->getTranslationUnitDecl();
LexicalContents Contents(
reinterpret_cast<const unaligned_decl_id_t *>(Blob.data()),
reinterpret_cast<const SerializedDeclID *>(Blob.data()),
static_cast<unsigned int>(Blob.size() / sizeof(DeclID)));
TULexicalDecls.push_back(std::make_pair(&F, Contents));
TU->setHasExternalLexicalStorage(true);
Expand Down Expand Up @@ -3616,7 +3616,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
break;

case FILE_SORTED_DECLS:
F.FileSortedDecls = (const unaligned_decl_id_t *)Blob.data();
F.FileSortedDecls = (const SerializedDeclID *)Blob.data();
F.NumFileSortedDecls = Record[0];
break;

Expand Down Expand Up @@ -7911,23 +7911,23 @@ class UnalignedDeclIDComp {
UnalignedDeclIDComp(ASTReader &Reader, ModuleFile &M)
: Reader(Reader), Mod(M) {}

bool operator()(unaligned_decl_id_t L, unaligned_decl_id_t R) const {
bool operator()(SerializedDeclID L, SerializedDeclID R) const {
SourceLocation LHS = getLocation(L);
SourceLocation RHS = getLocation(R);
return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
}

bool operator()(SourceLocation LHS, unaligned_decl_id_t R) const {
bool operator()(SourceLocation LHS, SerializedDeclID R) const {
SourceLocation RHS = getLocation(R);
return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
}

bool operator()(unaligned_decl_id_t L, SourceLocation RHS) const {
bool operator()(SerializedDeclID L, SourceLocation RHS) const {
SourceLocation LHS = getLocation(L);
return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS);
}

SourceLocation getLocation(unaligned_decl_id_t ID) const {
SourceLocation getLocation(SerializedDeclID ID) const {
return Reader.getSourceManager().getFileLoc(
Reader.getSourceLocationForDeclID(
Reader.getGlobalDeclID(Mod, (LocalDeclID)ID)));
Expand All @@ -7954,7 +7954,7 @@ void ASTReader::FindFileRegionDecls(FileID File,
SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length);

UnalignedDeclIDComp DIDComp(*this, *DInfo.Mod);
ArrayRef<unaligned_decl_id_t>::iterator BeginIt =
ArrayRef<SerializedDeclID>::iterator BeginIt =
llvm::lower_bound(DInfo.Decls, BeginLoc, DIDComp);
if (BeginIt != DInfo.Decls.begin())
--BeginIt;
Expand All @@ -7967,12 +7967,12 @@ void ASTReader::FindFileRegionDecls(FileID File,
->isTopLevelDeclInObjCContainer())
--BeginIt;

ArrayRef<unaligned_decl_id_t>::iterator EndIt =
ArrayRef<SerializedDeclID>::iterator EndIt =
llvm::upper_bound(DInfo.Decls, EndLoc, DIDComp);
if (EndIt != DInfo.Decls.end())
++EndIt;

for (ArrayRef<unaligned_decl_id_t>::iterator DIt = BeginIt; DIt != EndIt;
for (ArrayRef<SerializedDeclID>::iterator DIt = BeginIt; DIt != EndIt;
++DIt)
Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, (LocalDeclID)(*DIt))));
}
Expand Down
Loading