<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 3, 2017 at 8:13 PM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class="m_-3918021130855566634gmail-"><blockquote type="cite"><div>On Apr 3, 2017, at 7:08 PM, Peter Collingbourne <<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>> wrote:</div><br class="m_-3918021130855566634gmail-m_-7006201566700826442Apple-interchange-newline"><div><div dir="ltr">Hi,<div><br></div><div>As part of PR27551 I want to add a string table to the bitcode format to allow global value and comdat names to be shared with the proposed symbol table (and, as side effects, allow comdat names to be shared with value names, make bitcode files more compressible and make bitcode easier to parse). The format of the string table would be a top-level block containing a blob containing null-terminated strings [0] similar to the string table format used in most object files. </div></div></div></blockquote><div><br></div><div><br></div></span><div>I’m in favor of this, but note that currently string can be encoded with less than 8 bits / char in some cases (there might some size increase because of this).</div></div></div></blockquote><div><br></div><div>Sure, but I think we need to make the right tradeoff between making data more efficient to read and using fewer bits. In this case I think the right tradeoff is clearly in favour of being efficient to read, because accessing it is in the critical path of a consumer (i.e. a linker), and the part that needs to be efficient to read is a relatively small part of the data in the bitcode file. The same logic applies to the symbol table (note that we use support::ulittle32_t instead of a bit encoding).</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div>That said we already paid this with the metadata table in the recent past for example.</div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><span class="m_-3918021130855566634gmail-"><br><blockquote type="cite"><div><div dir="ltr"><div>The format of MODULE_CODE_{FUNCTION,GLOBALVA<wbr>R,ALIAS,IFUNC,COMDAT} records would change so that their first operand would specify their names with a byte offset into the string table. (To allow for backwards compatibility, I would increment the bitcode version.)</div></div></div></blockquote><div><br></div></span><div>I assume you mean the EPOCH?</div></div></div></blockquote><div><br></div><div>No, the MODULE_CODE_VERSION.</div><div><a href="http://llvm-cs.pcc.me.uk/lib/Bitcode/Writer/BitcodeWriter.cpp#3822" target="_blank">http://llvm-cs.pcc.me.uk/lib/<wbr>Bitcode/Writer/BitcodeWriter.<wbr>cpp#3822</a></div><div>It isn't clear to me why we have both.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><span class="m_-3918021130855566634gmail-"><br><blockquote type="cite"><div><div dir="ltr"><div> Here is what it would look like as bcanalyzer output:</div><div><br></div><div><MODULE_BLOCK></div><div> <VERSION op0=2></div><div> <COMDAT op0=0 ...> ; name = foo</div><div> <FUNCTION op0=0 ...> ; name = foo</div><div> <GLOBALVAR op0=4 ...> ; name = bar</div><div> <ALIAS op0=8 ...> ; name = baz</div><div> ; function bodies, etc.<br></div><div></MODULE_BLOCK></div><div><STRTAB_BLOCK></div><div> <STRTAB_BLOB blob="foo\0bar\0baz\0"></div><div></STRTAB_BLOCK></div></div></div></blockquote><div><br></div></span><div>Why is the string table after the module instead of before?</div></div></div></blockquote><div><br></div><div>For implementation simplicity. The idea is that the BitcodeWriter would have a member of type StringTableBuilder which would accumulate strings while writing the bitcode module(s) (and symtab in the future). At the end, the client would call something like BitcodeWriter::writeStrtab() which would write out the string table.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><span class="m_-3918021130855566634gmail-"><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div>Each STRTAB_BLOCK would apply to all preceding MODULE_BLOCKs. This means that bitcode files can continue to be concatenated with "llvm-cat -b". (Normally bitcode files would contain a single string table, which in multi-module bitcode files would be shared between modules.)</div><div><br></div><div>This *almost* allows us to remove the global (top-level) VST entirely, if not for the function offset in the FNENTRY record. However, this offset is not actually required because we can scan the module's FUNCTION_BLOCK_IDs as we were doing before <a href="http://reviews.llvm.org/D12536" target="_blank">http://reviews.llvm.org<wbr>/D12536</a> (this may have a performance impact, so I'll measure it first).</div><div><br></div><div>Assuming that performance looks good, does this seem reasonable to folks?</div></div></div></blockquote></span></div><br><div><br></div><div>I rather seek to have a symbol table that entirely replace the VST, kee. If there is a perf impact with the FNENTRY offset, why can’t it be replicated in the symbol table?</div></div></blockquote><div><br></div><div>Sure, we could in principle store function offsets in the symbol table as well, if that helps with performance. But I want to measure the impact and find out whether that is actually the case first.</div><div><br></div><div>Thanks,</div></div>-- <br><div class="m_-3918021130855566634gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div></div>