diff options
Diffstat (limited to 'lib/Serialization/ASTWriter.cpp')
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 127 |
1 files changed, 104 insertions, 23 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 37adcb7064..756411a8c5 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1,9 +1,8 @@ //===- ASTWriter.cpp - AST File Writer ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -42,7 +41,6 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/Lambda.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/MemoryBufferCache.h" #include "clang/Basic/Module.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/OpenCLOptions.h" @@ -66,6 +64,7 @@ #include "clang/Sema/Sema.h" #include "clang/Sema/Weak.h" #include "clang/Serialization/ASTReader.h" +#include "clang/Serialization/InMemoryModuleCache.h" #include "clang/Serialization/Module.h" #include "clang/Serialization/ModuleFileExtension.h" #include "clang/Serialization/SerializationDiagnostic.h" @@ -310,7 +309,7 @@ void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { Record.push_back(T->isVariadic()); Record.push_back(T->hasTrailingReturn()); - Record.push_back(T->getTypeQuals().getAsOpaqueValue()); + Record.push_back(T->getMethodQuals().getAsOpaqueValue()); Record.push_back(static_cast<unsigned>(T->getRefQualifier())); addExceptionSpec(T, Record); @@ -323,7 +322,7 @@ void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { Record.push_back(T->getExtParameterInfo(I).getOpaqueValue()); } - if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || + if (T->isVariadic() || T->hasTrailingReturn() || T->getMethodQuals() || T->getRefQualifier() || T->getExceptionSpecType() != EST_None || T->hasExtParameterInfos()) AbbrevToUse = 0; @@ -1299,6 +1298,7 @@ void ASTWriter::WriteBlockInfoBlock() { RECORD(DECL_PRAGMA_COMMENT); RECORD(DECL_PRAGMA_DETECT_MISMATCH); RECORD(DECL_OMP_DECLARE_REDUCTION); + RECORD(DECL_OMP_ALLOCATE); // Statements and Exprs can occur in the Decls and Types block. AddStmtsExprs(Stream, Record); @@ -4278,14 +4278,32 @@ void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) { if (!SemaRef.Context.getLangOpts().OpenCL) return; + // Sort the elements of the map OpenCLTypeExtMap by TypeIDs, + // without copying them. + const llvm::DenseMap<const Type *, std::set<std::string>> &OpenCLTypeExtMap = + SemaRef.OpenCLTypeExtMap; + using ElementTy = std::pair<TypeID, const std::set<std::string> *>; + llvm::SmallVector<ElementTy, 8> StableOpenCLTypeExtMap; + StableOpenCLTypeExtMap.reserve(OpenCLTypeExtMap.size()); + + for (const auto &I : OpenCLTypeExtMap) + StableOpenCLTypeExtMap.emplace_back( + getTypeID(I.first->getCanonicalTypeInternal()), &I.second); + + auto CompareByTypeID = [](const ElementTy &E1, const ElementTy &E2) -> bool { + return E1.first < E2.first; + }; + llvm::sort(StableOpenCLTypeExtMap, CompareByTypeID); + RecordData Record; - for (const auto &I : SemaRef.OpenCLTypeExtMap) { - Record.push_back( - static_cast<unsigned>(getTypeID(I.first->getCanonicalTypeInternal()))); - Record.push_back(I.second.size()); - for (auto Ext : I.second) + for (const ElementTy &E : StableOpenCLTypeExtMap) { + Record.push_back(E.first); // TypeID + const std::set<std::string> *ExtSet = E.second; + Record.push_back(static_cast<unsigned>(ExtSet->size())); + for (const std::string &Ext : *ExtSet) AddString(Ext, Record); } + Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record); } @@ -4293,13 +4311,31 @@ void ASTWriter::WriteOpenCLExtensionDecls(Sema &SemaRef) { if (!SemaRef.Context.getLangOpts().OpenCL) return; + // Sort the elements of the map OpenCLDeclExtMap by DeclIDs, + // without copying them. + const llvm::DenseMap<const Decl *, std::set<std::string>> &OpenCLDeclExtMap = + SemaRef.OpenCLDeclExtMap; + using ElementTy = std::pair<DeclID, const std::set<std::string> *>; + llvm::SmallVector<ElementTy, 8> StableOpenCLDeclExtMap; + StableOpenCLDeclExtMap.reserve(OpenCLDeclExtMap.size()); + + for (const auto &I : OpenCLDeclExtMap) + StableOpenCLDeclExtMap.emplace_back(getDeclID(I.first), &I.second); + + auto CompareByDeclID = [](const ElementTy &E1, const ElementTy &E2) -> bool { + return E1.first < E2.first; + }; + llvm::sort(StableOpenCLDeclExtMap, CompareByDeclID); + RecordData Record; - for (const auto &I : SemaRef.OpenCLDeclExtMap) { - Record.push_back(getDeclID(I.first)); - Record.push_back(static_cast<unsigned>(I.second.size())); - for (auto Ext : I.second) + for (const ElementTy &E : StableOpenCLDeclExtMap) { + Record.push_back(E.first); // DeclID + const std::set<std::string> *ExtSet = E.second; + Record.push_back(static_cast<unsigned>(ExtSet->size())); + for (const std::string &Ext : *ExtSet) AddString(Ext, Record); } + Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record); } @@ -4568,10 +4604,11 @@ void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { } ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, - SmallVectorImpl<char> &Buffer, MemoryBufferCache &PCMCache, + SmallVectorImpl<char> &Buffer, + InMemoryModuleCache &ModuleCache, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, bool IncludeTimestamps) - : Stream(Stream), Buffer(Buffer), PCMCache(PCMCache), + : Stream(Stream), Buffer(Buffer), ModuleCache(ModuleCache), IncludeTimestamps(IncludeTimestamps) { for (const auto &Ext : Extensions) { if (auto Writer = Ext->createExtensionWriter(*this)) @@ -4595,7 +4632,8 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, Module *WritingModule, StringRef isysroot, - bool hasErrors) { + bool hasErrors, + bool ShouldCacheASTInMemory) { WritingAST = true; ASTHasCompilerErrors = hasErrors; @@ -4619,11 +4657,11 @@ ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, this->BaseDirectory.clear(); WritingAST = false; - if (SemaRef.Context.getLangOpts().ImplicitModules && WritingModule) { + if (ShouldCacheASTInMemory) { // Construct MemoryBuffer and update buffer manager. - PCMCache.addBuffer(OutputFile, - llvm::MemoryBuffer::getMemBufferCopy( - StringRef(Buffer.begin(), Buffer.size()))); + ModuleCache.addBuiltPCM(OutputFile, + llvm::MemoryBuffer::getMemBufferCopy( + StringRef(Buffer.begin(), Buffer.size()))); } return Signature; } @@ -5288,6 +5326,14 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); break; + case UPD_DECL_MARKED_OPENMP_ALLOCATE: { + auto *A = D->getAttr<OMPAllocateDeclAttr>(); + Record.push_back(A->getAllocatorType()); + Record.AddStmt(A->getAllocator()); + Record.AddSourceRange(A->getRange()); + break; + } + case UPD_DECL_MARKED_OPENMP_DECLARETARGET: Record.push_back(D->getAttr<OMPDeclareTargetDeclAttr>()->getMapType()); Record.AddSourceRange( @@ -6405,6 +6451,15 @@ void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); } +void ASTWriter::DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) { + if (Chain && Chain->isProcessingUpdateRecords()) return; + assert(!WritingAST && "Already writing the AST!"); + if (!D->isFromASTFile()) + return; + + DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_ALLOCATE, A)); +} + void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, const Attr *Attr) { if (Chain && Chain->isProcessingUpdateRecords()) return; @@ -6519,6 +6574,11 @@ void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) { Record.AddSourceLocation(C->getLParenLoc()); } +void OMPClauseWriter::VisitOMPAllocatorClause(OMPAllocatorClause *C) { + Record.AddStmt(C->getAllocator()); + Record.AddSourceLocation(C->getLParenLoc()); +} + void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) { Record.AddStmt(C->getNumForLoops()); Record.AddSourceLocation(C->getLParenLoc()); @@ -6786,11 +6846,15 @@ void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) { Record.push_back(C->getMapTypeModifier(I)); Record.AddSourceLocation(C->getMapTypeModifierLoc(I)); } + Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); + Record.AddDeclarationNameInfo(C->getMapperIdInfo()); Record.push_back(C->getMapType()); Record.AddSourceLocation(C->getMapLoc()); Record.AddSourceLocation(C->getColonLoc()); for (auto *E : C->varlists()) Record.AddStmt(E); + for (auto *E : C->mapperlists()) + Record.AddStmt(E); for (auto *D : C->all_decls()) Record.AddDeclRef(D); for (auto N : C->all_num_lists()) @@ -6803,6 +6867,15 @@ void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) { } } +void OMPClauseWriter::VisitOMPAllocateClause(OMPAllocateClause *C) { + Record.push_back(C->varlist_size()); + Record.AddSourceLocation(C->getLParenLoc()); + Record.AddSourceLocation(C->getColonLoc()); + Record.AddStmt(C->getAllocator()); + for (auto *VE : C->varlists()) + Record.AddStmt(VE); +} + void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { VisitOMPClauseWithPreInit(C); Record.AddStmt(C->getNumTeams()); @@ -6858,8 +6931,12 @@ void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) { Record.push_back(C->getTotalComponentListNum()); Record.push_back(C->getTotalComponentsNum()); Record.AddSourceLocation(C->getLParenLoc()); + Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); + Record.AddDeclarationNameInfo(C->getMapperIdInfo()); for (auto *E : C->varlists()) Record.AddStmt(E); + for (auto *E : C->mapperlists()) + Record.AddStmt(E); for (auto *D : C->all_decls()) Record.AddDeclRef(D); for (auto N : C->all_num_lists()) @@ -6878,8 +6955,12 @@ void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) { Record.push_back(C->getTotalComponentListNum()); Record.push_back(C->getTotalComponentsNum()); Record.AddSourceLocation(C->getLParenLoc()); + Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); + Record.AddDeclarationNameInfo(C->getMapperIdInfo()); for (auto *E : C->varlists()) Record.AddStmt(E); + for (auto *E : C->mapperlists()) + Record.AddStmt(E); for (auto *D : C->all_decls()) Record.AddDeclRef(D); for (auto N : C->all_num_lists()) |