aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/include/clang/Serialization/ASTWriter.h
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/include/clang/Serialization/ASTWriter.h')
-rw-r--r--contrib/llvm-project/clang/include/clang/Serialization/ASTWriter.h207
1 files changed, 162 insertions, 45 deletions
diff --git a/contrib/llvm-project/clang/include/clang/Serialization/ASTWriter.h b/contrib/llvm-project/clang/include/clang/Serialization/ASTWriter.h
index 12073a38a77a..de69f99003d8 100644
--- a/contrib/llvm-project/clang/include/clang/Serialization/ASTWriter.h
+++ b/contrib/llvm-project/clang/include/clang/Serialization/ASTWriter.h
@@ -18,12 +18,14 @@
#include "clang/AST/Decl.h"
#include "clang/AST/Type.h"
#include "clang/Basic/LLVM.h"
+#include "clang/Basic/Module.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaConsumer.h"
#include "clang/Serialization/ASTBitCodes.h"
#include "clang/Serialization/ASTDeserializationListener.h"
#include "clang/Serialization/PCHContainerOperations.h"
+#include "clang/Serialization/SourceLocationEncoding.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
@@ -43,26 +45,13 @@
#include <utility>
#include <vector>
-namespace llvm {
-
-class APFloat;
-class APInt;
-class APSInt;
-
-} // namespace llvm
-
namespace clang {
class ASTContext;
class ASTReader;
-class ASTUnresolvedSet;
class Attr;
-class CXXBaseSpecifier;
-class CXXCtorInitializer;
class CXXRecordDecl;
-class CXXTemporary;
class FileEntry;
-class FPOptions;
class FPOptionsOverride;
class FunctionDecl;
class HeaderSearch;
@@ -79,16 +68,13 @@ class NamedDecl;
class ObjCInterfaceDecl;
class PreprocessingRecord;
class Preprocessor;
-struct QualifierInfo;
class RecordDecl;
class Sema;
class SourceManager;
class Stmt;
-struct StoredDeclsList;
+class StoredDeclsList;
class SwitchCase;
-class TemplateParameterList;
class Token;
-class TypeSourceInfo;
/// Writes an AST file containing the contents of a translation unit.
///
@@ -119,6 +105,8 @@ private:
using TypeIdxMap = llvm::DenseMap<QualType, serialization::TypeIdx,
serialization::UnsafeQualTypeDenseMapInfo>;
+ using LocSeq = SourceLocationSequence;
+
/// The bitstream writer used to emit this precompiled header.
llvm::BitstreamWriter &Stream;
@@ -140,10 +128,17 @@ private:
/// The module we're currently writing, if any.
Module *WritingModule = nullptr;
- /// The offset of the first bit inside the AST_BLOCK.
+ /// The byte range representing all the UNHASHED_CONTROL_BLOCK.
+ std::pair<uint64_t, uint64_t> UnhashedControlBlockRange;
+ /// The bit offset of the AST block hash blob.
+ uint64_t ASTBlockHashOffset = 0;
+ /// The bit offset of the signature blob.
+ uint64_t SignatureOffset = 0;
+
+ /// The bit offset of the first bit inside the AST_BLOCK.
uint64_t ASTBlockStartOffset = 0;
- /// The range representing all the AST_BLOCK.
+ /// The byte range representing all the AST_BLOCK.
std::pair<uint64_t, uint64_t> ASTBlockRange;
/// The base directory for any relative paths we emit.
@@ -155,6 +150,11 @@ private:
/// file is up to date, but not otherwise.
bool IncludeTimestamps;
+ /// Indicates whether the AST file being written is an implicit module.
+ /// If that's the case, we may be able to skip writing some information that
+ /// are guaranteed to be the same in the importer by the context hash.
+ bool BuildingImplicitModule = false;
+
/// Indicates when the AST writing is actively performing
/// serialization, rather than just queueing updates.
bool WritingAST = false;
@@ -347,7 +347,7 @@ private:
union {
const Decl *Dcl;
void *Type;
- unsigned Loc;
+ SourceLocation::UIntTy Loc;
unsigned Val;
Module *Mod;
const Attr *Attribute;
@@ -402,8 +402,8 @@ private:
/// headers. The declarations themselves are stored as declaration
/// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS
/// record.
- SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
- SmallVector<uint64_t, 16> ModularCodegenDecls;
+ SmallVector<serialization::DeclID, 16> EagerlyDeserializedDecls;
+ SmallVector<serialization::DeclID, 16> ModularCodegenDecls;
/// DeclContexts that have received extensions since their serialized
/// form.
@@ -450,12 +450,47 @@ private:
/// A mapping from each known submodule to its ID number, which will
/// be a positive integer.
- llvm::DenseMap<Module *, unsigned> SubmoduleIDs;
+ llvm::DenseMap<const Module *, unsigned> SubmoduleIDs;
/// A list of the module file extension writers.
std::vector<std::unique_ptr<ModuleFileExtensionWriter>>
ModuleFileExtensionWriters;
+ /// Mapping from a source location entry to whether it is affecting or not.
+ llvm::BitVector IsSLocAffecting;
+
+ /// Mapping from \c FileID to an index into the FileID adjustment table.
+ std::vector<FileID> NonAffectingFileIDs;
+ std::vector<unsigned> NonAffectingFileIDAdjustments;
+
+ /// Mapping from an offset to an index into the offset adjustment table.
+ std::vector<SourceRange> NonAffectingRanges;
+ std::vector<SourceLocation::UIntTy> NonAffectingOffsetAdjustments;
+
+ /// Collects input files that didn't affect compilation of the current module,
+ /// and initializes data structures necessary for leaving those files out
+ /// during \c SourceManager serialization.
+ void collectNonAffectingInputFiles();
+
+ /// Returns an adjusted \c FileID, accounting for any non-affecting input
+ /// files.
+ FileID getAdjustedFileID(FileID FID) const;
+ /// Returns an adjusted number of \c FileIDs created within the specified \c
+ /// FileID, accounting for any non-affecting input files.
+ unsigned getAdjustedNumCreatedFIDs(FileID FID) const;
+ /// Returns an adjusted \c SourceLocation, accounting for any non-affecting
+ /// input files.
+ SourceLocation getAdjustedLocation(SourceLocation Loc) const;
+ /// Returns an adjusted \c SourceRange, accounting for any non-affecting input
+ /// files.
+ SourceRange getAdjustedRange(SourceRange Range) const;
+ /// Returns an adjusted \c SourceLocation offset, accounting for any
+ /// non-affecting input files.
+ SourceLocation::UIntTy getAdjustedOffset(SourceLocation::UIntTy Offset) const;
+ /// Returns an adjustment for offset into SourceManager, accounting for any
+ /// non-affecting input files.
+ SourceLocation::UIntTy getAdjustment(SourceLocation::UIntTy Offset) const;
+
/// Retrieve or create a submodule ID for this module.
unsigned getSubmoduleID(Module *Mod);
@@ -464,18 +499,16 @@ private:
void WriteBlockInfoBlock();
void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
- StringRef isysroot, const std::string &OutputFile);
+ StringRef isysroot);
/// Write out the signature and diagnostic options, and return the signature.
- ASTFileSignature writeUnhashedControlBlock(Preprocessor &PP,
- ASTContext &Context);
+ void writeUnhashedControlBlock(Preprocessor &PP, ASTContext &Context);
+ ASTFileSignature backpatchSignature();
/// Calculate hash of the pcm content.
- static std::pair<ASTFileSignature, ASTFileSignature>
- createSignature(StringRef AllBytes, StringRef ASTBlockBytes);
+ std::pair<ASTFileSignature, ASTFileSignature> createSignature() const;
- void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
- bool Modules);
+ void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts);
void WriteSourceManagerBlock(SourceManager &SourceMgr,
const Preprocessor &PP);
void WritePreprocessor(const Preprocessor &PP, bool IsModule);
@@ -488,7 +521,6 @@ private:
bool isModule);
unsigned TypeExtQualAbbrev = 0;
- unsigned TypeFunctionProtoAbbrev = 0;
void WriteTypeAbbrevs();
void WriteType(QualType T);
@@ -510,8 +542,6 @@ private:
void WriteDeclContextVisibleUpdate(const DeclContext *DC);
void WriteFPPragmaOptions(const FPOptionsOverride &Opts);
void WriteOpenCLExtensions(Sema &SemaRef);
- void WriteOpenCLExtensionTypes(Sema &SemaRef);
- void WriteOpenCLExtensionDecls(Sema &SemaRef);
void WriteCUDAPragmas(Sema &SemaRef);
void WriteObjCCategories();
void WriteLateParsedTemplates(Sema &SemaRef);
@@ -534,17 +564,30 @@ private:
unsigned DeclEnumAbbrev = 0;
unsigned DeclObjCIvarAbbrev = 0;
unsigned DeclCXXMethodAbbrev = 0;
+ unsigned DeclDependentNonTemplateCXXMethodAbbrev = 0;
+ unsigned DeclTemplateCXXMethodAbbrev = 0;
+ unsigned DeclMemberSpecializedCXXMethodAbbrev = 0;
+ unsigned DeclTemplateSpecializedCXXMethodAbbrev = 0;
+ unsigned DeclDependentSpecializationCXXMethodAbbrev = 0;
+ unsigned DeclTemplateTypeParmAbbrev = 0;
+ unsigned DeclUsingShadowAbbrev = 0;
unsigned DeclRefExprAbbrev = 0;
unsigned CharacterLiteralAbbrev = 0;
unsigned IntegerLiteralAbbrev = 0;
unsigned ExprImplicitCastAbbrev = 0;
+ unsigned BinaryOperatorAbbrev = 0;
+ unsigned CompoundAssignOperatorAbbrev = 0;
+ unsigned CallExprAbbrev = 0;
+ unsigned CXXOperatorCallExprAbbrev = 0;
+ unsigned CXXMemberCallExprAbbrev = 0;
+
+ unsigned CompoundStmtAbbrev = 0;
void WriteDeclAbbrevs();
void WriteDecl(ASTContext &Context, Decl *D);
ASTFileSignature WriteASTCore(Sema &SemaRef, StringRef isysroot,
- const std::string &OutputFile,
Module *WritingModule);
public:
@@ -553,7 +596,7 @@ public:
ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer,
InMemoryModuleCache &ModuleCache,
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
- bool IncludeTimestamps = true);
+ bool IncludeTimestamps = true, bool BuildingImplicitModule = false);
~ASTWriter() override;
ASTContext &getASTContext() const {
@@ -582,9 +625,8 @@ public:
///
/// \return the module signature, which eventually will be a hash of
/// the module but currently is merely a random 32-bit number.
- ASTFileSignature WriteAST(Sema &SemaRef, const std::string &OutputFile,
+ ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
Module *WritingModule, StringRef isysroot,
- bool hasErrors = false,
bool ShouldCacheASTInMemory = false);
/// Emit a token.
@@ -594,11 +636,16 @@ public:
void AddAlignPackInfo(const Sema::AlignPackInfo &Info,
RecordDataImpl &Record);
+ /// Emit a FileID.
+ void AddFileID(FileID FID, RecordDataImpl &Record);
+
/// Emit a source location.
- void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record);
+ void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record,
+ LocSeq *Seq = nullptr);
/// Emit a source range.
- void AddSourceRange(SourceRange Range, RecordDataImpl &Record);
+ void AddSourceRange(SourceRange Range, RecordDataImpl &Record,
+ LocSeq *Seq = nullptr);
/// Emit a reference to an identifier.
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record);
@@ -673,7 +720,7 @@ public:
/// Retrieve or create a submodule ID for this module, or return 0 if
/// the submodule is neither local (a submodle of the currently-written module)
/// nor from an imported module.
- unsigned getLocalOrImportedSubmoduleID(Module *Mod);
+ unsigned getLocalOrImportedSubmoduleID(const Module *Mod);
/// Note that the identifier II occurs at the given offset
/// within the identifier table.
@@ -695,10 +742,6 @@ public:
return TypeExtQualAbbrev;
}
- unsigned getTypeFunctionProtoAbbrev() const {
- return TypeFunctionProtoAbbrev;
- }
-
unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; }
unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; }
unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }
@@ -706,16 +749,49 @@ public:
unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }
unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }
unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; }
- unsigned getDeclCXXMethodAbbrev() const { return DeclCXXMethodAbbrev; }
+ unsigned getDeclCXXMethodAbbrev(FunctionDecl::TemplatedKind Kind) const {
+ switch (Kind) {
+ case FunctionDecl::TK_NonTemplate:
+ return DeclCXXMethodAbbrev;
+ case FunctionDecl::TK_FunctionTemplate:
+ return DeclTemplateCXXMethodAbbrev;
+ case FunctionDecl::TK_MemberSpecialization:
+ return DeclMemberSpecializedCXXMethodAbbrev;
+ case FunctionDecl::TK_FunctionTemplateSpecialization:
+ return DeclTemplateSpecializedCXXMethodAbbrev;
+ case FunctionDecl::TK_DependentNonTemplate:
+ return DeclDependentNonTemplateCXXMethodAbbrev;
+ case FunctionDecl::TK_DependentFunctionTemplateSpecialization:
+ return DeclDependentSpecializationCXXMethodAbbrev;
+ }
+ llvm_unreachable("Unknwon Template Kind!");
+ }
+ unsigned getDeclTemplateTypeParmAbbrev() const {
+ return DeclTemplateTypeParmAbbrev;
+ }
+ unsigned getDeclUsingShadowAbbrev() const { return DeclUsingShadowAbbrev; }
unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; }
unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }
unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }
unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; }
+ unsigned getBinaryOperatorAbbrev() const { return BinaryOperatorAbbrev; }
+ unsigned getCompoundAssignOperatorAbbrev() const {
+ return CompoundAssignOperatorAbbrev;
+ }
+ unsigned getCallExprAbbrev() const { return CallExprAbbrev; }
+ unsigned getCXXOperatorCallExprAbbrev() { return CXXOperatorCallExprAbbrev; }
+ unsigned getCXXMemberCallExprAbbrev() { return CXXMemberCallExprAbbrev; }
+
+ unsigned getCompoundStmtAbbrev() const { return CompoundStmtAbbrev; }
bool hasChain() const { return Chain; }
ASTReader *getChain() const { return Chain; }
+ bool isWritingStdCXXNamedModules() const {
+ return WritingModule && WritingModule->isNamedModule();
+ }
+
private:
// ASTDeserializationListener implementation
void ReaderInitialized(ASTReader *Reader) override;
@@ -786,6 +862,7 @@ public:
std::shared_ptr<PCHBuffer> Buffer,
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
bool AllowASTWithErrors = false, bool IncludeTimestamps = true,
+ bool BuildingImplicitModule = false,
bool ShouldCacheASTInMemory = false);
~PCHGenerator() override;
@@ -796,6 +873,46 @@ public:
bool hasEmittedPCH() const { return Buffer->IsComplete; }
};
+/// A simple helper class to pack several bits in order into (a) 32 bit
+/// integer(s).
+class BitsPacker {
+ constexpr static uint32_t BitIndexUpbound = 32u;
+
+public:
+ BitsPacker() = default;
+ BitsPacker(const BitsPacker &) = delete;
+ BitsPacker(BitsPacker &&) = delete;
+ BitsPacker operator=(const BitsPacker &) = delete;
+ BitsPacker operator=(BitsPacker &&) = delete;
+ ~BitsPacker() = default;
+
+ bool canWriteNextNBits(uint32_t BitsWidth) const {
+ return CurrentBitIndex + BitsWidth < BitIndexUpbound;
+ }
+
+ void reset(uint32_t Value) {
+ UnderlyingValue = Value;
+ CurrentBitIndex = 0;
+ }
+
+ void addBit(bool Value) { addBits(Value, 1); }
+ void addBits(uint32_t Value, uint32_t BitsWidth) {
+ assert(BitsWidth < BitIndexUpbound);
+ assert((Value < (1u << BitsWidth)) && "Passing narrower bit width!");
+ assert(canWriteNextNBits(BitsWidth) &&
+ "Inserting too much bits into a value!");
+
+ UnderlyingValue |= Value << CurrentBitIndex;
+ CurrentBitIndex += BitsWidth;
+ }
+
+ operator uint32_t() { return UnderlyingValue; }
+
+private:
+ uint32_t UnderlyingValue = 0;
+ uint32_t CurrentBitIndex = 0;
+};
+
} // namespace clang
#endif // LLVM_CLANG_SERIALIZATION_ASTWRITER_H