llvm.org GIT mirror llvm / 1f05ba2
Function bitcode index in Value Symbol Table and lazy reading support Summary: Support for including the function bitcode indices in the Value Symbol Table. This requires writing the VST after the function blocks, which in turn requires a new VST forward declaration record encoding the offset of the full VST (which is backpatched to contain the offset after the VST is written). This patch also enables the lazy function reader to use the new function indices out of the VST. This support will be used by ThinLTO as well, which will be in a follow on patch. Backwards compatibility with older bitcode files is maintained. A new test is also included. The bitcode format (used for the lazy reader as well as the upcoming ThinLTO patches) came out of discussions with Duncan and others and is described here: https://drive.google.com/file/d/0B036uwnWM6RWdnBLakxmeDdOeXc/view Reviewers: dexonsmith, davidxl, joker.eph Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12536 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247894 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 5 years ago
5 changed file(s) with 341 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
4141
4242 TYPE_BLOCK_ID_NEW,
4343
44 USELIST_BLOCK_ID
44 USELIST_BLOCK_ID,
45
46 MODULE_STRTAB_BLOCK_ID,
47 FUNCTION_SUMMARY_BLOCK_ID
4548 };
4649
4750
7275
7376 MODULE_CODE_GCNAME = 11, // GCNAME: [strchr x N]
7477 MODULE_CODE_COMDAT = 12, // COMDAT: [selection_kind, name]
78
79 MODULE_CODE_VSTOFFSET = 13, // VSTOFFSET: [offset]
7580 };
7681
7782 /// PARAMATTR blocks have code for defining a parameter attribute set.
130135 TST_CODE_ENTRY = 1 // TST_ENTRY: [typeid, namechar x N]
131136 };
132137
133 // The value symbol table only has one code (VST_ENTRY_CODE).
138 // Value symbol table codes.
134139 enum ValueSymtabCodes {
135 VST_CODE_ENTRY = 1, // VST_ENTRY: [valid, namechar x N]
136 VST_CODE_BBENTRY = 2 // VST_BBENTRY: [bbid, namechar x N]
140 VST_CODE_ENTRY = 1, // VST_ENTRY: [valueid, namechar x N]
141 VST_CODE_BBENTRY = 2, // VST_BBENTRY: [bbid, namechar x N]
142 VST_CODE_FNENTRY = 3, // VST_FNENTRY: [valueid, offset, namechar x N]
137143 };
138144
139145 enum MetadataCodes {
146146 BitstreamCursor Stream;
147147 uint64_t NextUnreadBit = 0;
148148 bool SeenValueSymbolTable = false;
149 unsigned VSTOffset = 0;
149150
150151 std::vector TypeList;
151152 BitcodeReaderValueList ValueList;
369370 std::error_code parseTypeTable();
370371 std::error_code parseTypeTableBody();
371372
372 std::error_code parseValueSymbolTable();
373 ErrorOr recordValue(SmallVectorImpl &Record,
374 unsigned NameIndex, Triple &TT);
375 std::error_code parseValueSymbolTable(unsigned Offset = 0);
373376 std::error_code parseConstants();
374377 std::error_code rememberAndSkipFunctionBody();
375378 /// Save the positions of the Metadata blocks and skip parsing the blocks.
15821585 }
15831586 }
15841587
1585 std::error_code BitcodeReader::parseValueSymbolTable() {
1588 /// Associate a value with its name from the given index in the provided record.
1589 ErrorOr BitcodeReader::recordValue(SmallVectorImpl &Record,
1590 unsigned NameIndex, Triple &TT) {
1591 SmallString<128> ValueName;
1592 if (convertToString(Record, NameIndex, ValueName))
1593 return error("Invalid record");
1594 unsigned ValueID = Record[0];
1595 if (ValueID >= ValueList.size() || !ValueList[ValueID])
1596 return error("Invalid record");
1597 Value *V = ValueList[ValueID];
1598
1599 V->setName(StringRef(ValueName.data(), ValueName.size()));
1600 auto *GO = dyn_cast(V);
1601 if (GO) {
1602 if (GO->getComdat() == reinterpret_cast(1)) {
1603 if (TT.isOSBinFormatMachO())
1604 GO->setComdat(nullptr);
1605 else
1606 GO->setComdat(TheModule->getOrInsertComdat(V->getName()));
1607 }
1608 }
1609 return V;
1610 }
1611
1612 /// Parse the value symbol table at either the current parsing location or
1613 /// at the given bit offset if provided.
1614 std::error_code BitcodeReader::parseValueSymbolTable(unsigned Offset) {
1615 uint64_t CurrentBit;
1616 // Pass in the Offset to distinguish between calling for the module-level
1617 // VST (where we want to jump to the VST offset) and the function-level
1618 // VST (where we don't).
1619 if (Offset > 0) {
1620 // Save the current parsing location so we can jump back at the end
1621 // of the VST read.
1622 CurrentBit = Stream.GetCurrentBitNo();
1623 Stream.JumpToBit(Offset * 32);
1624 BitstreamEntry Entry = Stream.advance();
1625 assert(Entry.Kind == BitstreamEntry::SubBlock);
1626 assert(Entry.ID == bitc::VALUE_SYMTAB_BLOCK_ID);
1627 }
1628
1629 // Compute the delta between the bitcode indices in the VST (the word offset
1630 // to the word-aligned ENTER_SUBBLOCK for the function block, and that
1631 // expected by the lazy reader. The reader's EnterSubBlock expects to have
1632 // already read the ENTER_SUBBLOCK code (size getAbbrevIDWidth) and BlockID
1633 // (size BlockIDWidth). Note that we access the stream's AbbrevID width here
1634 // just before entering the VST subblock because: 1) the EnterSubBlock
1635 // changes the AbbrevID width; 2) the VST block is nested within the same
1636 // outer MODULE_BLOCK as the FUNCTION_BLOCKs and therefore have the same
1637 // AbbrevID width before calling EnterSubBlock; and 3) when we want to
1638 // jump to the FUNCTION_BLOCK using this offset later, we don't want
1639 // to rely on the stream's AbbrevID width being that of the MODULE_BLOCK.
1640 unsigned FuncBitcodeOffsetDelta =
1641 Stream.getAbbrevIDWidth() + bitc::BlockIDWidth;
1642
15861643 if (Stream.EnterSubBlock(bitc::VALUE_SYMTAB_BLOCK_ID))
15871644 return error("Invalid record");
15881645
16001657 case BitstreamEntry::Error:
16011658 return error("Malformed block");
16021659 case BitstreamEntry::EndBlock:
1660 if (Offset > 0)
1661 Stream.JumpToBit(CurrentBit);
16031662 return std::error_code();
16041663 case BitstreamEntry::Record:
16051664 // The interesting case.
16121671 default: // Default behavior: unknown type.
16131672 break;
16141673 case bitc::VST_CODE_ENTRY: { // VST_ENTRY: [valueid, namechar x N]
1615 if (convertToString(Record, 1, ValueName))
1616 return error("Invalid record");
1617 unsigned ValueID = Record[0];
1618 if (ValueID >= ValueList.size() || !ValueList[ValueID])
1619 return error("Invalid record");
1620 Value *V = ValueList[ValueID];
1621
1622 V->setName(StringRef(ValueName.data(), ValueName.size()));
1623 if (auto *GO = dyn_cast(V)) {
1624 if (GO->getComdat() == reinterpret_cast(1)) {
1625 if (TT.isOSBinFormatMachO())
1626 GO->setComdat(nullptr);
1627 else
1628 GO->setComdat(TheModule->getOrInsertComdat(V->getName()));
1629 }
1630 }
1631 ValueName.clear();
1674 ErrorOr ValOrErr = recordValue(Record, 1, TT);
1675 if (std::error_code EC = ValOrErr.getError())
1676 return EC;
1677 ValOrErr.get();
1678 break;
1679 }
1680 case bitc::VST_CODE_FNENTRY: {
1681 // VST_FNENTRY: [valueid, offset, namechar x N]
1682 ErrorOr ValOrErr = recordValue(Record, 2, TT);
1683 if (std::error_code EC = ValOrErr.getError())
1684 return EC;
1685 Value *V = ValOrErr.get();
1686
1687 auto *GO = dyn_cast(V);
1688 if (!GO) {
1689 // If this is an alias, need to get the actual Function object
1690 // it aliases, in order to set up the DeferredFunctionInfo entry below.
1691 auto *GA = dyn_cast(V);
1692 if (GA)
1693 GO = GA->getBaseObject();
1694 assert(GO);
1695 }
1696
1697 uint64_t FuncWordOffset = Record[1];
1698 Function *F = dyn_cast(GO);
1699 assert(F);
1700 uint64_t FuncBitOffset = FuncWordOffset * 32;
1701 DeferredFunctionInfo[F] = FuncBitOffset + FuncBitcodeOffsetDelta;
1702 // Set the NextUnreadBit to point to the last function block.
1703 // Later when parsing is resumed after function materialization,
1704 // we can simply skip that last function block.
1705 if (FuncBitOffset > NextUnreadBit)
1706 NextUnreadBit = FuncBitOffset;
16321707 break;
16331708 }
16341709 case bitc::VST_CODE_BBENTRY: {
28512926 return EC;
28522927 break;
28532928 case bitc::VALUE_SYMTAB_BLOCK_ID:
2854 if (std::error_code EC = parseValueSymbolTable())
2855 return EC;
2856 SeenValueSymbolTable = true;
2929 if (!SeenValueSymbolTable) {
2930 // Either this is an old form VST without function index and an
2931 // associated VST forward declaration record (which would have caused
2932 // the VST to be jumped to and parsed before it was encountered
2933 // normally in the stream), or there were no function blocks to
2934 // trigger an earlier parsing of the VST.
2935 assert(VSTOffset == 0 || FunctionsWithBodies.empty());
2936 if (std::error_code EC = parseValueSymbolTable())
2937 return EC;
2938 SeenValueSymbolTable = true;
2939 } else {
2940 // We must have had a VST forward declaration record, which caused
2941 // the parser to jump to and parse the VST earlier.
2942 assert(VSTOffset > 0);
2943 if (Stream.SkipBlock())
2944 return error("Invalid record");
2945 }
28572946 break;
28582947 case bitc::CONSTANTS_BLOCK_ID:
28592948 if (std::error_code EC = parseConstants())
28812970 SeenFirstFunctionBody = true;
28822971 }
28832972
2973 if (VSTOffset > 0) {
2974 // If we have a VST forward declaration record, make sure we
2975 // parse the VST now if we haven't already. It is needed to
2976 // set up the DeferredFunctionInfo vector for lazy reading.
2977 if (!SeenValueSymbolTable) {
2978 if (std::error_code EC =
2979 BitcodeReader::parseValueSymbolTable(VSTOffset))
2980 return EC;
2981 SeenValueSymbolTable = true;
2982 return std::error_code();
2983 } else {
2984 // If we have a VST forward declaration record, but have already
2985 // parsed the VST (just above, when the first function body was
2986 // encountered here), then we are resuming the parse after
2987 // materializing functions. The NextUnreadBit points to the start
2988 // of the last function block recorded in the VST (set when
2989 // parsing the VST function entries). Skip it.
2990 if (Stream.SkipBlock())
2991 return error("Invalid record");
2992 continue;
2993 }
2994 }
2995
2996 // Support older bitcode files that did not have the function
2997 // index in the VST, nor a VST forward declaration record.
2998 // Build the DeferredFunctionInfo vector on the fly.
28842999 if (std::error_code EC = rememberAndSkipFunctionBody())
28853000 return EC;
28863001 // Suspend parsing when we reach the function bodies. Subsequent
31833298 if (Record.size() < 1 || Record[0] > ValueList.size())
31843299 return error("Invalid record");
31853300 ValueList.shrinkTo(Record[0]);
3301 break;
3302 /// MODULE_CODE_VSTOFFSET: [offset]
3303 case bitc::MODULE_CODE_VSTOFFSET:
3304 if (Record.size() < 1)
3305 return error("Invalid record");
3306 VSTOffset = Record[0];
31863307 break;
31873308 }
31883309 Record.clear();
46414762 Function *F,
46424763 DenseMap::iterator DeferredFunctionInfoIterator) {
46434764 while (DeferredFunctionInfoIterator->second == 0) {
4765 // This is the fallback handling for the old format bitcode that
4766 // didn't contain the function index in the VST. Assert if we end up
4767 // here for the new format (which is the only time the VSTOffset would
4768 // be non-zero).
4769 assert(VSTOffset == 0);
46444770 if (Stream.AtEndOfStream())
46454771 return error("Could not find function in stream");
46464772 // ParseModule will parse the next body in the stream and set its
573573 }
574574 }
575575
576 // Emit top-level description of module, including target triple, inline asm,
577 // descriptors for global variables, and function prototype info.
578 static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
579 BitstreamWriter &Stream) {
576 /// Write a record that will eventually hold the word offset of the
577 /// module-level VST. For now the offset is 0, which will be backpatched
578 /// after the real VST is written. Returns the bit offset to backpatch.
579 static uint64_t WriteValueSymbolTableForwardDecl(const ValueSymbolTable &VST,
580 BitstreamWriter &Stream) {
581 if (VST.empty()) return 0;
582
583 // Write a placeholder value in for the offset of the real VST,
584 // which is written after the function blocks so that it can include
585 // the offset of each function. The placeholder offset will be
586 // updated when the real VST is written.
587 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
588 Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_VSTOFFSET));
589 // Blocks are 32-bit aligned, so we can use a 32-bit word offset to
590 // hold the real VST offset. Must use fixed instead of VBR as we don't
591 // know how many VBR chunks to reserve ahead of time.
592 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
593 unsigned VSTOffsetAbbrev = Stream.EmitAbbrev(Abbv);
594
595 // Emit the placeholder
596 ArrayRef Vals = {llvm::bitc::MODULE_CODE_VSTOFFSET, 0};
597 Stream.EmitRecordWithAbbrev(VSTOffsetAbbrev, Vals);
598
599 // Compute and return the bit offset to the placeholder, which will be
600 // patched when the real VST is written. We can simply subtract the 32-bit
601 // fixed size from the current bit number to get the location to backpatch.
602 return Stream.GetCurrentBitNo() - 32;
603 }
604
605 /// Emit top-level description of module, including target triple, inline asm,
606 /// descriptors for global variables, and function prototype info.
607 /// Returns the bit offset to backpatch with the location of the real VST.
608 static uint64_t WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
609 BitstreamWriter &Stream) {
580610 // Emit various pieces of data attached to a module.
581611 if (!M->getTargetTriple().empty())
582612 WriteStringRecord(bitc::MODULE_CODE_TRIPLE, M->getTargetTriple(),
736766 Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse);
737767 Vals.clear();
738768 }
769
770 uint64_t VSTOffsetPlaceholder =
771 WriteValueSymbolTableForwardDecl(M->getValueSymbolTable(), Stream);
772 return VSTOffsetPlaceholder;
739773 }
740774
741775 static uint64_t GetOptimizationFlags(const Value *V) {
20902124 return SE_Fixed7;
20912125 }
20922126
2093 // Emit names for globals/functions etc.
2094 static void WriteValueSymbolTable(const ValueSymbolTable &VST,
2095 const ValueEnumerator &VE,
2096 BitstreamWriter &Stream) {
2097 if (VST.empty()) return;
2127 /// Emit names for globals/functions etc. The VSTOffsetPlaceholder,
2128 /// BitcodeStartBit and FunctionIndex are only passed for the module-level
2129 /// VST, where we are including a function bitcode index and need to
2130 /// backpatch the VST forward declaration record.
2131 static void WriteValueSymbolTable(
2132 const ValueSymbolTable &VST, const ValueEnumerator &VE,
2133 BitstreamWriter &Stream, uint64_t VSTOffsetPlaceholder = 0,
2134 uint64_t BitcodeStartBit = 0,
2135 DenseMap *FunctionIndex = nullptr) {
2136 if (VST.empty()) {
2137 // WriteValueSymbolTableForwardDecl should have returned early as
2138 // well. Ensure this handling remains in sync by asserting that
2139 // the placeholder offset is not set.
2140 assert(VSTOffsetPlaceholder == 0);
2141 return;
2142 }
2143
2144 if (VSTOffsetPlaceholder > 0) {
2145 // Get the offset of the VST we are writing, and backpatch it into
2146 // the VST forward declaration record.
2147 uint64_t VSTOffset = Stream.GetCurrentBitNo();
2148 // The BitcodeStartBit was the stream offset of the actual bitcode
2149 // (e.g. excluding any initial darwin header).
2150 VSTOffset -= BitcodeStartBit;
2151 assert((VSTOffset & 31) == 0 && "VST block not 32-bit aligned");
2152 Stream.BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32);
2153 }
2154
20982155 Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
2156
2157 // For the module-level VST, add abbrev Ids for the VST_CODE_FNENTRY
2158 // records, which are not used in the per-function VSTs.
2159 unsigned FnEntry8BitAbbrev;
2160 unsigned FnEntry7BitAbbrev;
2161 unsigned FnEntry6BitAbbrev;
2162 if (VSTOffsetPlaceholder > 0) {
2163 // 8-bit fixed-width VST_FNENTRY function strings.
2164 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
2165 Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_FNENTRY));
2166 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // value id
2167 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // funcoffset
2168 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2169 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
2170 FnEntry8BitAbbrev = Stream.EmitAbbrev(Abbv);
2171
2172 // 7-bit fixed width VST_FNENTRY function strings.
2173 Abbv = new BitCodeAbbrev();
2174 Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_FNENTRY));
2175 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // value id
2176 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // funcoffset
2177 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2178 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
2179 FnEntry7BitAbbrev = Stream.EmitAbbrev(Abbv);
2180
2181 // 6-bit char6 VST_FNENTRY function strings.
2182 Abbv = new BitCodeAbbrev();
2183 Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_FNENTRY));
2184 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // value id
2185 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // funcoffset
2186 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2187 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
2188 FnEntry6BitAbbrev = Stream.EmitAbbrev(Abbv);
2189 }
20992190
21002191 // FIXME: Set up the abbrev, we know how many values there are!
21012192 // FIXME: We know if the type names can use 7-bit ascii.
21022193 SmallVector NameVals;
21032194
21042195 for (const ValueName &Name : VST) {
2105
21062196 // Figure out the encoding to use for the name.
21072197 StringEncoding Bits =
21082198 getStringEncoding(Name.getKeyData(), Name.getKeyLength());
21092199
21102200 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
2201 NameVals.push_back(VE.getValueID(Name.getValue()));
2202
2203 Function *F = dyn_cast(Name.getValue());
2204 if (!F) {
2205 // If value is an alias, need to get the aliased base object to
2206 // see if it is a function.
2207 auto *GA = dyn_cast(Name.getValue());
2208 if (GA && GA->getBaseObject())
2209 F = dyn_cast(GA->getBaseObject());
2210 }
21112211
21122212 // VST_ENTRY: [valueid, namechar x N]
2213 // VST_FNENTRY: [valueid, funcoffset, namechar x N]
21132214 // VST_BBENTRY: [bbid, namechar x N]
21142215 unsigned Code;
21152216 if (isa(Name.getValue())) {
21162217 Code = bitc::VST_CODE_BBENTRY;
21172218 if (Bits == SE_Char6)
21182219 AbbrevToUse = VST_BBENTRY_6_ABBREV;
2220 } else if (F && !F->isDeclaration()) {
2221 // Must be the module-level VST, where we pass in the Index and
2222 // have a VSTOffsetPlaceholder. The function-level VST should not
2223 // contain any Function symbols.
2224 assert(FunctionIndex);
2225 assert(VSTOffsetPlaceholder > 0);
2226
2227 // Save the word offset of the function (from the start of the
2228 // actual bitcode written to the stream).
2229 assert(FunctionIndex->count(F) == 1);
2230 uint64_t BitcodeIndex = (*FunctionIndex)[F] - BitcodeStartBit;
2231 assert((BitcodeIndex & 31) == 0 && "function block not 32-bit aligned");
2232 NameVals.push_back(BitcodeIndex / 32);
2233
2234 Code = bitc::VST_CODE_FNENTRY;
2235 AbbrevToUse = FnEntry8BitAbbrev;
2236 if (Bits == SE_Char6)
2237 AbbrevToUse = FnEntry6BitAbbrev;
2238 else if (Bits == SE_Fixed7)
2239 AbbrevToUse = FnEntry7BitAbbrev;
21192240 } else {
21202241 Code = bitc::VST_CODE_ENTRY;
21212242 if (Bits == SE_Char6)
21242245 AbbrevToUse = VST_ENTRY_7_ABBREV;
21252246 }
21262247
2127 NameVals.push_back(VE.getValueID(Name.getValue()));
21282248 for (const char *P = Name.getKeyData(),
21292249 *E = Name.getKeyData()+Name.getKeyLength(); P != E; ++P)
21302250 NameVals.push_back((unsigned char)*P);
21722292
21732293 /// WriteFunction - Emit a function body to the module stream.
21742294 static void WriteFunction(const Function &F, ValueEnumerator &VE,
2175 BitstreamWriter &Stream) {
2295 BitstreamWriter &Stream,
2296 DenseMap &FunctionIndex) {
2297 // Save the bitcode index of the start of this function block for recording
2298 // in the VST.
2299 uint64_t BitcodeIndex = Stream.GetCurrentBitNo();
2300 FunctionIndex[&F] = BitcodeIndex;
2301
21762302 Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 4);
21772303 VE.incorporateFunction(F);
21782304
24202546
24212547 /// WriteModule - Emit the specified module to the bitstream.
24222548 static void WriteModule(const Module *M, BitstreamWriter &Stream,
2423 bool ShouldPreserveUseListOrder) {
2549 bool ShouldPreserveUseListOrder,
2550 uint64_t BitcodeStartBit) {
24242551 Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
24252552
24262553 SmallVector Vals;
24472574
24482575 // Emit top-level description of module, including target triple, inline asm,
24492576 // descriptors for global variables, and function prototype info.
2450 WriteModuleInfo(M, VE, Stream);
2577 uint64_t VSTOffsetPlaceholder = WriteModuleInfo(M, VE, Stream);
24512578
24522579 // Emit constants.
24532580 WriteModuleConstants(VE, Stream);
24572584
24582585 // Emit metadata.
24592586 WriteModuleMetadataStore(M, Stream);
2460
2461 // Emit names for globals/functions etc.
2462 WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream);
24632587
24642588 // Emit module-level use-lists.
24652589 if (VE.shouldPreserveUseListOrder())
24662590 WriteUseListBlock(nullptr, VE, Stream);
24672591
24682592 // Emit function bodies.
2593 DenseMap FunctionIndex;
24692594 for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F)
24702595 if (!F->isDeclaration())
2471 WriteFunction(*F, VE, Stream);
2596 WriteFunction(*F, VE, Stream, FunctionIndex);
2597
2598 WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream,
2599 VSTOffsetPlaceholder, BitcodeStartBit, &FunctionIndex);
24722600
24732601 Stream.ExitBlock();
24742602 }
25592687 // Emit the module into the buffer.
25602688 {
25612689 BitstreamWriter Stream(Buffer);
2690 // Save the start bit of the actual bitcode, in case there is space
2691 // saved at the start for the darwin header above. The reader stream
2692 // will start at the bitcode, and we need the offset of the VST
2693 // to line up.
2694 uint64_t BitcodeStartBit = Stream.GetCurrentBitNo();
25622695
25632696 // Emit the file header.
25642697 Stream.Emit((unsigned)'B', 8);
25692702 Stream.Emit(0xD, 4);
25702703
25712704 // Emit the module.
2572 WriteModule(M, Stream, ShouldPreserveUseListOrder);
2705 WriteModule(M, Stream, ShouldPreserveUseListOrder, BitcodeStartBit);
25732706 }
25742707
25752708 if (TT.isOSDarwin())
0 ; RUN: llvm-as < %s | llvm-bcanalyzer -dump | FileCheck %s -check-prefix=BC
1 ; Check for VST forward declaration record and VST function index records.
2
3 ; BC:
4 ; BC:
5 ; BC:
6
7 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
8 ; Check that this round-trips correctly.
9
10 ; ModuleID = ''
11 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
12 target triple = "x86_64-unknown-linux-gnu"
13
14 ; CHECK: define i32 @foo()
15
16 ; Function Attrs: nounwind uwtable
17 define i32 @foo() #0 {
18 entry:
19 ret i32 1
20 }
21
22 ; CHECK: define i32 @bar(i32 %x)
23
24 ; Function Attrs: nounwind uwtable
25 define i32 @bar(i32 %x) #0 {
26 entry:
27 ret i32 %x
28 }
164164 STRINGIFY_CODE(MODULE_CODE, ALIAS)
165165 STRINGIFY_CODE(MODULE_CODE, PURGEVALS)
166166 STRINGIFY_CODE(MODULE_CODE, GCNAME)
167 STRINGIFY_CODE(MODULE_CODE, VSTOFFSET)
167168 }
168169 case bitc::PARAMATTR_BLOCK_ID:
169170 switch (CodeID) {
265266 default: return nullptr;
266267 STRINGIFY_CODE(VST_CODE, ENTRY)
267268 STRINGIFY_CODE(VST_CODE, BBENTRY)
269 STRINGIFY_CODE(VST_CODE, FNENTRY)
268270 }
269271 case bitc::METADATA_ATTACHMENT_ID:
270272 switch(CodeID) {