llvm.org GIT mirror llvm / acfba51
[ThinLTO] Remove unused/incomplete lazy summary reading support (NFC) This removes the interfaces added (and not yet complete) to support lazy reading of summaries. This support is not expected to be needed since we are moving to a model where the full index is only being traversed in the thin link step, instead of the back ends. (The second part of this that I plan to do next is remove the GlobalValueInfo from the ModuleSummaryIndex - it was mostly needed to support lazy parsing of summaries. The index can instead reference the summary structures directly.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267097 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 4 years ago
5 changed file(s) with 16 addition(s) and 110 deletion(s). Raw diff Collapse all Expand all
7474 DiagnosticHandlerFunction DiagnosticHandler);
7575
7676 /// Parse the specified bitcode buffer, returning the module summary index.
77 /// If IsLazy is true, parse the entire module summary into
78 /// the index. Otherwise skip the module summary section, and only create
79 /// an index object with a map from value name to the value's summary offset.
80 /// The index is used to perform lazy summary reading later.
8177 ErrorOr>
8278 getModuleSummaryIndex(MemoryBufferRef Buffer,
83 DiagnosticHandlerFunction DiagnosticHandler,
84 bool IsLazy = false);
85
86 /// This method supports lazy reading of summary data from the
87 /// combined index during function importing. When reading the combined index
88 /// file, getModuleSummaryIndex is first invoked with IsLazy=true.
89 /// Then this method is called for each value considered for importing,
90 /// to parse the summary information for the given value name into
91 /// the index.
92 std::error_code readGlobalValueSummary(
93 MemoryBufferRef Buffer, DiagnosticHandlerFunction DiagnosticHandler,
94 StringRef ValueName, std::unique_ptr Index);
79 DiagnosticHandlerFunction DiagnosticHandler);
9580
9681 /// \brief Write the specified module to the specified raw output stream.
9782 ///
8888 /// Return new ModuleSummaryIndexObjectFile instance containing parsed module
8989 /// summary/index.
9090 static ErrorOr>
91 create(MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler,
92 bool IsLazy = false);
93
94 /// \brief Parse the summary information for global value with the
95 /// given name out of the given buffer. Parsed information is
96 /// stored on the index object saved in this object.
97 std::error_code
98 findGlobalValueSummaryInMemBuffer(MemoryBufferRef Object,
99 DiagnosticHandlerFunction DiagnosticHandler,
100 StringRef ValueName);
91 create(MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler);
10192 };
10293 }
10394
429429 std::unique_ptr StreamFile;
430430 BitstreamCursor Stream;
431431
432 /// \brief Used to indicate whether we are doing lazy parsing of summary data.
433 ///
434 /// If false, the summary section is fully parsed into the index during
435 /// the initial parse. Otherwise, if true, the caller is expected to
436 /// invoke \a readGlobalValueSummary for each summary needed, and the summary
437 /// section is thus parsed lazily.
438 bool IsLazy = false;
439
440432 /// Used to indicate whether caller only wants to check for the presence
441433 /// of the global value summary bitcode section. All blocks are skipped,
442434 /// but the SeenGlobalValSummary boolean is set.
482474
483475 ModuleSummaryIndexBitcodeReader(
484476 MemoryBuffer *Buffer, DiagnosticHandlerFunction DiagnosticHandler,
485 bool IsLazy = false, bool CheckGlobalValSummaryPresenceOnly = false);
477 bool CheckGlobalValSummaryPresenceOnly = false);
486478 ModuleSummaryIndexBitcodeReader(
487 DiagnosticHandlerFunction DiagnosticHandler, bool IsLazy = false,
479 DiagnosticHandlerFunction DiagnosticHandler,
488480 bool CheckGlobalValSummaryPresenceOnly = false);
489481 ~ModuleSummaryIndexBitcodeReader() { freeState(); }
490482
55115503
55125504 ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
55135505 MemoryBuffer *Buffer, DiagnosticHandlerFunction DiagnosticHandler,
5514 bool IsLazy, bool CheckGlobalValSummaryPresenceOnly)
5515 : DiagnosticHandler(DiagnosticHandler), Buffer(Buffer), IsLazy(IsLazy),
5506 bool CheckGlobalValSummaryPresenceOnly)
5507 : DiagnosticHandler(DiagnosticHandler), Buffer(Buffer),
55165508 CheckGlobalValSummaryPresenceOnly(CheckGlobalValSummaryPresenceOnly) {}
55175509
55185510 ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
5519 DiagnosticHandlerFunction DiagnosticHandler, bool IsLazy,
5511 DiagnosticHandlerFunction DiagnosticHandler,
55205512 bool CheckGlobalValSummaryPresenceOnly)
5521 : DiagnosticHandler(DiagnosticHandler), Buffer(nullptr), IsLazy(IsLazy),
5513 : DiagnosticHandler(DiagnosticHandler), Buffer(nullptr),
55225514 CheckGlobalValSummaryPresenceOnly(CheckGlobalValSummaryPresenceOnly) {}
55235515
55245516 void ModuleSummaryIndexBitcodeReader::freeState() { Buffer = nullptr; }
56055597 return error("Invalid record");
56065598 unsigned ValueID = Record[0];
56075599 uint64_t FuncOffset = Record[1];
5608 assert(!IsLazy && "Lazy summary read only supported for combined index");
56095600 std::unique_ptr FuncInfo =
56105601 llvm::make_unique(FuncOffset);
56115602 assert(!SourceFileName.empty());
56495640 // Parse just the blocks needed for building the index out of the module.
56505641 // At the end of this routine the module Index is populated with a map
56515642 // from global value name to GlobalValueInfo. The global value info contains
5652 // either the parsed summary information (when parsing summaries
5653 // eagerly), or just to the summary record's offset
5654 // if parsing lazily (IsLazy).
5643 // the parsed summary information (when parsing summaries eagerly).
56555644 std::error_code ModuleSummaryIndexBitcodeReader::parseModule() {
56565645 if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
56575646 return error("Invalid record");
57095698 return EC;
57105699 SeenValueSymbolTable = true;
57115700 SeenGlobalValSummary = true;
5712 if (IsLazy) {
5713 // Lazy parsing of summary info, skip it.
5714 if (Stream.SkipBlock())
5715 return error("Invalid record");
5716 } else if (std::error_code EC = parseEntireSummary())
5701 if (std::error_code EC = parseEntireSummary())
57175702 return EC;
57185703 break;
57195704 case bitc::MODULE_STRTAB_BLOCK_ID:
63466331 }
63476332
63486333 // Parse the specified bitcode buffer, returning the function info index.
6349 // If IsLazy is false, parse the entire function summary into
6350 // the index. Otherwise skip the function summary section, and only create
6351 // an index object with a map from function name to function summary offset.
6352 // The index is used to perform lazy function summary reading later.
63536334 ErrorOr>
63546335 llvm::getModuleSummaryIndex(MemoryBufferRef Buffer,
6355 DiagnosticHandlerFunction DiagnosticHandler,
6356 bool IsLazy) {
6336 DiagnosticHandlerFunction DiagnosticHandler) {
63576337 std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Buffer, false);
6358 ModuleSummaryIndexBitcodeReader R(Buf.get(), DiagnosticHandler, IsLazy);
6338 ModuleSummaryIndexBitcodeReader R(Buf.get(), DiagnosticHandler);
63596339
63606340 auto Index = llvm::make_unique();
63616341
63756355 bool llvm::hasGlobalValueSummary(MemoryBufferRef Buffer,
63766356 DiagnosticHandlerFunction DiagnosticHandler) {
63776357 std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Buffer, false);
6378 ModuleSummaryIndexBitcodeReader R(Buf.get(), DiagnosticHandler, false, true);
6358 ModuleSummaryIndexBitcodeReader R(Buf.get(), DiagnosticHandler, true);
63796359
63806360 auto cleanupOnError = [&](std::error_code EC) {
63816361 R.releaseBuffer(); // Never take ownership on error.
63886368 Buf.release(); // The ModuleSummaryIndexBitcodeReader owns it now.
63896369 return R.foundGlobalValSummary();
63906370 }
6391
6392 // This method supports lazy reading of summary data from the combined
6393 // index during ThinLTO function importing. When reading the combined index
6394 // file, getModuleSummaryIndex is first invoked with IsLazy=true.
6395 // Then this method is called for each value considered for importing,
6396 // to parse the summary information for the given value name into
6397 // the index.
6398 std::error_code llvm::readGlobalValueSummary(
6399 MemoryBufferRef Buffer, DiagnosticHandlerFunction DiagnosticHandler,
6400 StringRef ValueName, std::unique_ptr Index) {
6401 std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Buffer, false);
6402 ModuleSummaryIndexBitcodeReader R(Buf.get(), DiagnosticHandler);
6403
6404 auto cleanupOnError = [&](std::error_code EC) {
6405 R.releaseBuffer(); // Never take ownership on error.
6406 return EC;
6407 };
6408
6409 // Lookup the given value name in the GlobalValueMap, which may
6410 // contain a list of global value infos in the case of a COMDAT. Walk through
6411 // and parse each summary info at the summary offset
6412 // recorded when parsing the value symbol table.
6413 for (const auto &FI : Index->getGlobalValueInfoList(ValueName)) {
6414 size_t SummaryOffset = FI->bitcodeIndex();
6415 if (std::error_code EC =
6416 R.parseGlobalValueSummary(nullptr, Index.get(), SummaryOffset))
6417 return cleanupOnError(EC);
6418 }
6419
6420 Buf.release(); // The ModuleSummaryIndexBitcodeReader owns it now.
6421 return std::error_code();
6422 }
546546 for (auto &ModuleBuffer : Modules) {
547547 ErrorOr> ObjOrErr =
548548 object::ModuleSummaryIndexObjectFile::create(ModuleBuffer,
549 diagnosticHandler, false);
549 diagnosticHandler);
550550 if (std::error_code EC = ObjOrErr.getError()) {
551551 // FIXME diagnose
552552 errs() << "error: can't create ModuleSummaryIndexObjectFile for buffer: "
8282 // module summary/index.
8383 ErrorOr>
8484 ModuleSummaryIndexObjectFile::create(
85 MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler,
86 bool IsLazy) {
85 MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler) {
8786 std::unique_ptr Index;
8887
8988 ErrorOr BCOrErr = findBitcodeInMemBuffer(Object);
9190 return BCOrErr.getError();
9291
9392 ErrorOr> IOrErr =
94 getModuleSummaryIndex(BCOrErr.get(), DiagnosticHandler, IsLazy);
93 getModuleSummaryIndex(BCOrErr.get(), DiagnosticHandler);
9594
9695 if (std::error_code EC = IOrErr.getError())
9796 return EC;
10099
101100 return llvm::make_unique(Object,
102101 std::move(Index));
103 }
104
105 // Parse the summary information for value with the
106 // given name out of the given buffer. Parsed information is
107 // stored on the index object saved in this object.
108 std::error_code ModuleSummaryIndexObjectFile::findGlobalValueSummaryInMemBuffer(
109 MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler,
110 StringRef ValueName) {
111 sys::fs::file_magic Type = sys::fs::identify_magic(Object.getBuffer());
112 switch (Type) {
113 case sys::fs::file_magic::bitcode: {
114 return readGlobalValueSummary(Object, DiagnosticHandler, ValueName,
115 std::move(Index));
116 }
117 default:
118 return object_error::invalid_file_type;
119 }
120102 }
121103
122104 // Parse the module summary index out of an IR file and return the summary