From a61f5e379675732666744bcba25efbc9922e016a Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Fri, 16 Dec 2016 21:25:01 +0000 Subject: [ThinLTO] Import composite types as declarations Summary: When reading the metadata bitcode, create a type declaration when possible for composite types when we are importing. Doing this in the bitcode reader saves memory. Also it works naturally in the case when the type ODR map contains a definition for the same composite type because it was used in the importing module (buildODRType will automatically use the existing definition and not create a type declaration). For Chromium built with -g2, this reduces the aggregate size of the generated native object files by 66% (from 31G to 10G). It reduced the time through the ThinLTO link and backend phases by about 20% on my machine. Reviewers: mehdi_amini, dblaikie, aprantl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27775 llvm-svn: 289993 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 37 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index ad4d9ce..4812b2c 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -488,7 +488,8 @@ public: /// \brief Main interface to parsing a bitcode buffer. /// \returns true if an error occurred. - Error parseBitcodeInto(Module *M, bool ShouldLazyLoadMetadata = false); + Error parseBitcodeInto(Module *M, bool ShouldLazyLoadMetadata = false, + bool IsImporting = false); static uint64_t decodeSignRotatedValue(uint64_t V); @@ -3084,9 +3085,10 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit, } } -Error BitcodeReader::parseBitcodeInto(Module *M, bool ShouldLazyLoadMetadata) { +Error BitcodeReader::parseBitcodeInto(Module *M, bool ShouldLazyLoadMetadata, + bool IsImporting) { TheModule = M; - MDLoader = MetadataLoader(Stream, *M, ValueList, + MDLoader = MetadataLoader(Stream, *M, ValueList, IsImporting, [&](unsigned ID) { return getTypeByID(ID); }); return parseModule(0, ShouldLazyLoadMetadata); } @@ -5220,7 +5222,7 @@ llvm::getBitcodeModuleList(MemoryBufferRef Buffer) { /// everything. Expected> BitcodeModule::getModuleImpl(LLVMContext &Context, bool MaterializeAll, - bool ShouldLazyLoadMetadata) { + bool ShouldLazyLoadMetadata, bool IsImporting) { BitstreamCursor Stream(Buffer); std::string ProducerIdentification; @@ -5243,7 +5245,8 @@ BitcodeModule::getModuleImpl(LLVMContext &Context, bool MaterializeAll, M->setMaterializer(R); // Delay parsing Metadata if ShouldLazyLoadMetadata is true. - if (Error Err = R->parseBitcodeInto(M.get(), ShouldLazyLoadMetadata)) + if (Error Err = + R->parseBitcodeInto(M.get(), ShouldLazyLoadMetadata, IsImporting)) return std::move(Err); if (MaterializeAll) { @@ -5259,9 +5262,9 @@ BitcodeModule::getModuleImpl(LLVMContext &Context, bool MaterializeAll, } Expected> -BitcodeModule::getLazyModule(LLVMContext &Context, - bool ShouldLazyLoadMetadata) { - return getModuleImpl(Context, false, ShouldLazyLoadMetadata); +BitcodeModule::getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, + bool IsImporting) { + return getModuleImpl(Context, false, ShouldLazyLoadMetadata, IsImporting); } // Parse the specified bitcode buffer, returning the function info index. @@ -5323,20 +5326,20 @@ static Expected getSingleModule(MemoryBufferRef Buffer) { } Expected> -llvm::getLazyBitcodeModule(MemoryBufferRef Buffer, - LLVMContext &Context, bool ShouldLazyLoadMetadata) { +llvm::getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, + bool ShouldLazyLoadMetadata, bool IsImporting) { Expected BM = getSingleModule(Buffer); if (!BM) return BM.takeError(); - return BM->getLazyModule(Context, ShouldLazyLoadMetadata); + return BM->getLazyModule(Context, ShouldLazyLoadMetadata, IsImporting); } -Expected> -llvm::getOwningLazyBitcodeModule(std::unique_ptr &&Buffer, - LLVMContext &Context, - bool ShouldLazyLoadMetadata) { - auto MOrErr = getLazyBitcodeModule(*Buffer, Context, ShouldLazyLoadMetadata); +Expected> llvm::getOwningLazyBitcodeModule( + std::unique_ptr &&Buffer, LLVMContext &Context, + bool ShouldLazyLoadMetadata, bool IsImporting) { + auto MOrErr = getLazyBitcodeModule(*Buffer, Context, ShouldLazyLoadMetadata, + IsImporting); if (MOrErr) (*MOrErr)->setOwnedMemoryBuffer(std::move(Buffer)); return MOrErr; @@ -5344,7 +5347,7 @@ llvm::getOwningLazyBitcodeModule(std::unique_ptr &&Buffer, Expected> BitcodeModule::parseModule(LLVMContext &Context) { - return getModuleImpl(Context, true, false); + return getModuleImpl(Context, true, false, false); // TODO: Restore the use-lists to the in-memory state when the bitcode was // written. We must defer until the Module has been fully materialized. } -- cgit v1.1