Parse metadata attachments.
| 1859 | |
| 1860 | /// Parse metadata attachments. |
| 1861 | Error MetadataLoader::MetadataLoaderImpl::parseMetadataAttachment( |
| 1862 | Function &F, const SmallVectorImpl<Instruction *> &InstructionList) { |
| 1863 | if (Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID)) |
| 1864 | return error("Invalid record"); |
| 1865 | |
| 1866 | SmallVector<uint64_t, 64> Record; |
| 1867 | PlaceholderQueue Placeholders; |
| 1868 | |
| 1869 | while (true) { |
| 1870 | BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| 1871 | |
| 1872 | switch (Entry.Kind) { |
| 1873 | case BitstreamEntry::SubBlock: // Handled for us already. |
| 1874 | case BitstreamEntry::Error: |
| 1875 | return error("Malformed block"); |
| 1876 | case BitstreamEntry::EndBlock: |
| 1877 | resolveForwardRefsAndPlaceholders(Placeholders); |
| 1878 | return Error::success(); |
| 1879 | case BitstreamEntry::Record: |
| 1880 | // The interesting case. |
| 1881 | break; |
| 1882 | } |
| 1883 | |
| 1884 | // Read a metadata attachment record. |
| 1885 | Record.clear(); |
| 1886 | ++NumMDRecordLoaded; |
| 1887 | switch (Stream.readRecord(Entry.ID, Record)) { |
| 1888 | default: // Default behavior: ignore. |
| 1889 | break; |
| 1890 | case bitc::METADATA_ATTACHMENT: { |
| 1891 | unsigned RecordLength = Record.size(); |
| 1892 | if (Record.empty()) |
| 1893 | return error("Invalid record"); |
| 1894 | if (RecordLength % 2 == 0) { |
| 1895 | // A function attachment. |
| 1896 | if (Error Err = parseGlobalObjectAttachment(F, Record)) |
| 1897 | return Err; |
| 1898 | continue; |
| 1899 | } |
| 1900 | |
| 1901 | // An instruction attachment. |
| 1902 | Instruction *Inst = InstructionList[Record[0]]; |
| 1903 | for (unsigned i = 1; i != RecordLength; i = i + 2) { |
| 1904 | unsigned Kind = Record[i]; |
| 1905 | DenseMap<unsigned, unsigned>::iterator I = MDKindMap.find(Kind); |
| 1906 | if (I == MDKindMap.end()) |
| 1907 | return error("Invalid ID"); |
| 1908 | if (I->second == LLVMContext::MD_tbaa && StripTBAA) |
| 1909 | continue; |
| 1910 | |
| 1911 | auto Idx = Record[i + 1]; |
| 1912 | if (Idx < (MDStringRef.size() + GlobalMetadataBitPosIndex.size()) && |
| 1913 | !MetadataList.lookup(Idx)) { |
| 1914 | // Load the attachment if it is in the lazy-loadable range and hasn't |
| 1915 | // been loaded yet. |
| 1916 | lazyLoadOneMetadata(Idx, Placeholders); |
| 1917 | resolveForwardRefsAndPlaceholders(Placeholders); |
| 1918 | } |
no test coverage detected