llvm.org GIT mirror llvm / 778af35
Use a different block id for block of metadata kind records Summary: There are currently two blocks with the METADATA_BLOCK id at module scope. The first has the module-level metadata values (consisting of some combination of METADATA_* record codes except for METADATA_KIND). The second consists only of METADATA_KIND records. The latter is used only in the METADATA_ATTACHMENT block within function blocks (for metadata attached to instructions). For ThinLTO we want to delay the parsing of module level metadata until all functions have been imported from that module (there is some bookkeeping used to suture it up when we read it during a post-pass). However, we do need the METADATA_KIND records when parsing the function body during importing, since those kinds are used as described above. To simplify identification and parsing of just the block containing the metadata kinds, use a different block id (METADATA_KIND_BLOCK_ID). Support older bitcode without the new block id as well. Reviewers: dexonsmith, joker.eph Subscribers: davidxl, llvm-commits Differential Revision: http://reviews.llvm.org/D14654 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253154 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 4 years ago
4 changed file(s) with 74 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
4949 MODULE_STRTAB_BLOCK_ID,
5050 FUNCTION_SUMMARY_BLOCK_ID,
5151
52 OPERAND_BUNDLE_TAGS_BLOCK_ID
52 OPERAND_BUNDLE_TAGS_BLOCK_ID,
53
54 METADATA_KIND_BLOCK_ID
5355 };
5456
5557 /// Identification block contains a string that describes the producer details,
404404 std::error_code globalCleanup();
405405 std::error_code resolveGlobalAndAliasInits();
406406 std::error_code parseMetadata();
407 std::error_code parseMetadataKinds();
408 std::error_code parseMetadataKindRecord(SmallVectorImpl &Record);
407409 std::error_code parseMetadataAttachment(Function &F);
408410 ErrorOr parseModuleTriple();
409411 std::error_code parseUseLists();
18921894 }
18931895 }
18941896
1897 /// Parse a single METADATA_KIND record, inserting result in MDKindMap.
1898 std::error_code
1899 BitcodeReader::parseMetadataKindRecord(SmallVectorImpl &Record) {
1900 if (Record.size() < 2)
1901 return error("Invalid record");
1902
1903 unsigned Kind = Record[0];
1904 SmallString<8> Name(Record.begin() + 1, Record.end());
1905
1906 unsigned NewKind = TheModule->getMDKindID(Name.str());
1907 if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
1908 return error("Conflicting METADATA_KIND records");
1909 return std::error_code();
1910 }
1911
18951912 static int64_t unrotateSign(uint64_t U) { return U & 1 ? ~(U >> 1) : U >> 1; }
18961913
18971914 std::error_code BitcodeReader::parseMetadata() {
23502367 break;
23512368 }
23522369 case bitc::METADATA_KIND: {
2353 if (Record.size() < 2)
2354 return error("Invalid record");
2355
2356 unsigned Kind = Record[0];
2357 SmallString<8> Name(Record.begin()+1, Record.end());
2358
2359 unsigned NewKind = TheModule->getMDKindID(Name.str());
2360 if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
2361 return error("Conflicting METADATA_KIND records");
2370 // Support older bitcode files that had METADATA_KIND records in a
2371 // block with METADATA_BLOCK_ID.
2372 if (std::error_code EC = parseMetadataKindRecord(Record))
2373 return EC;
23622374 break;
23632375 }
23642376 }
23652377 }
23662378 #undef GET_OR_DISTINCT
2379 }
2380
2381 /// Parse the metadata kinds out of the METADATA_KIND_BLOCK.
2382 std::error_code BitcodeReader::parseMetadataKinds() {
2383 if (Stream.EnterSubBlock(bitc::METADATA_KIND_BLOCK_ID))
2384 return error("Invalid record");
2385
2386 SmallVector Record;
2387
2388 // Read all the records.
2389 while (1) {
2390 BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
2391
2392 switch (Entry.Kind) {
2393 case BitstreamEntry::SubBlock: // Handled for us already.
2394 case BitstreamEntry::Error:
2395 return error("Malformed block");
2396 case BitstreamEntry::EndBlock:
2397 return std::error_code();
2398 case BitstreamEntry::Record:
2399 // The interesting case.
2400 break;
2401 }
2402
2403 // Read a record.
2404 Record.clear();
2405 unsigned Code = Stream.readRecord(Entry.ID, Record);
2406 switch (Code) {
2407 default: // Default behavior: ignore.
2408 break;
2409 case bitc::METADATA_KIND: {
2410 if (std::error_code EC = parseMetadataKindRecord(Record))
2411 return EC;
2412 break;
2413 }
2414 }
2415 }
23672416 }
23682417
23692418 /// Decode a signed value stored with the sign bit in the LSB for dense VBR
32283277 if (std::error_code EC = parseMetadata())
32293278 return EC;
32303279 break;
3280 case bitc::METADATA_KIND_BLOCK_ID:
3281 if (std::error_code EC = parseMetadataKinds())
3282 return EC;
3283 break;
32313284 case bitc::FUNCTION_BLOCK_ID:
32323285 // If this is the first function body we've seen, reverse the
32333286 // FunctionsWithBodies list.
13821382
13831383 if (Names.empty()) return;
13841384
1385 Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
1385 Stream.EnterSubblock(bitc::METADATA_KIND_BLOCK_ID, 3);
13861386
13871387 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
13881388 Record.push_back(MDKindID);
113113 return "IDENTIFICATION_BLOCK_ID";
114114 case bitc::VALUE_SYMTAB_BLOCK_ID: return "VALUE_SYMTAB";
115115 case bitc::METADATA_BLOCK_ID: return "METADATA_BLOCK";
116 case bitc::METADATA_KIND_BLOCK_ID: return "METADATA_KIND_BLOCK";
116117 case bitc::METADATA_ATTACHMENT_ID: return "METADATA_ATTACHMENT_BLOCK";
117118 case bitc::USELIST_BLOCK_ID: return "USELIST_BLOCK_ID";
118119 case bitc::FUNCTION_SUMMARY_BLOCK_ID:
304305 default:return nullptr;
305306 STRINGIFY_CODE(METADATA, STRING)
306307 STRINGIFY_CODE(METADATA, NAME)
307 STRINGIFY_CODE(METADATA, KIND)
308 STRINGIFY_CODE(METADATA, KIND) // Older bitcode has it in a MODULE_BLOCK
308309 STRINGIFY_CODE(METADATA, NODE)
309310 STRINGIFY_CODE(METADATA, VALUE)
310311 STRINGIFY_CODE(METADATA, OLD_NODE)
334335 STRINGIFY_CODE(METADATA, IMPORTED_ENTITY)
335336 STRINGIFY_CODE(METADATA, MODULE)
336337 }
338 case bitc::METADATA_KIND_BLOCK_ID:
339 switch (CodeID) {
340 default:
341 return nullptr;
342 STRINGIFY_CODE(METADATA, KIND)
343 }
337344 case bitc::USELIST_BLOCK_ID:
338345 switch(CodeID) {
339346 default:return nullptr;