<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style>
</head>
<body><div class="markdown-here-wrapper" defang_data-md-url="www.fastmail.com" style=""><p style="margin: 0px 0px 1.2em !important;">Hi list,</p>
<p style="margin: 0px 0px 1.2em !important;">Let’s talk about adding a new type of debug info metadata. Here are the steps (at minimum - probably incomplete) one needs to take:</p>
<ol style="margin: 1.2em 0px;padding-left: 2em;">
<li style="margin: 0.5em 0px;">Create a new class in the hierarchy</li>
<li style="margin: 0.5em 0px;">Implement two forms of <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;">MD_NODE_GET</code></li>
<li style="margin: 0.5em 0px;">Specialize <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;">MDNodeKeyImpl</code></li>
<li style="margin: 0.5em 0px;">Modify <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;">LLParser.cpp</code> and add serialization code for your special type</li>
<li style="margin: 0.5em 0px;">Modify <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;">AsmWriter.cpp</code> and add serialization code for your special type </li>
</ol>
<p style="margin: 0px 0px 1.2em !important;">I believe we can accomplish everything needed for debug info with just step 1 using a pattern found in Boost Serialization. Imagine a new API based on this concept:</p>
<pre style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;font-size: 1em; line-height: 1.2em;margin: 1.2em 0px;"><code defang_class="hljs language-c++" style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline; white-space: pre; overflow: auto; border-radius: 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em 0.7em; display: block !important; display: block; overflow-x: auto; padding: 0.5em; color: rgb(51, 51, 51); background: rgb(248, 248, 248); text-size-adjust: none;"><span class="hljs-keyword" style="color: rgb(51, 51, 51); font-weight: bold;">class</span> DIMyFancyType : <span class="hljs-keyword" style="color: rgb(51, 51, 51); font-weight: bold;">public</span> MDNode {
StringRef FileName;
<span class="hljs-keyword" style="color: rgb(51, 51, 51); font-weight: bold;">template</span><<span class="hljs-keyword" style="color: rgb(51, 51, 51); font-weight: bold;">typename</span> Visitor>
<span class="hljs-keyword" style="color: rgb(51, 51, 51); font-weight: bold;">void</span> visit(Visitor & v) {
DINode::visit(s); <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// or not, if you stay true to boost.serialization</span>
v.name(<span class="hljs-string" style="color: rgb(221, 17, 68);">"DIMyFancyType"</span>);
v.property(<span class="hljs-string" style="color: rgb(221, 17, 68);">"FileName"</span>,FileName);
}
};
</code></pre>
<p style="margin: 0px 0px 1.2em !important;">With this, we could implement steps 2-5 using a little bit of template meta-programming and we could also implement escape hatches where needed to get more specific, allowing us to keep many things in one place.</p>
<p style="margin: 0px 0px 1.2em !important;">I imagine since there is now a <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;">.def</code> file for the metadata (very useful!) that this is on somebody’s mind and not just my own, so I’m curious about what people think. I realize that “new forms of debug metadata” is possibly not a very popular use case as there has been only one new kind added in the last few years. However, in my humble opinion, it would make it easier to add richer information allowing those of us extending LLVM to create better debuggers/debugging experiences.</p>
<p style="margin: 0px 0px 1.2em !important;">Thanks for your time!</p>
<p style="margin: 0px 0px 1.2em !important;">—<br>Sohail Somani<br>Fizz Buzz Inc.<br>Booking schedule: <a href="https://sohailsomani.youcanbook.me">https://sohailsomani.youcanbook.me</a></p>
<div title="MDH:PGRpdiBzdHlsZT0iZm9udC1mYW1pbHk6QXJpYWw7Ij5IaSBsaXN0LDxicj48L2Rpdj48ZGl2IHN0
eWxlPSJmb250LWZhbWlseTpBcmlhbDsiPjxicj48L2Rpdj48ZGl2IHN0eWxlPSJmb250LWZhbWls
eTpBcmlhbDsiPkxldCdzIHRhbGsgYWJvdXQgYWRkaW5nIGEgbmV3IHR5cGUgb2YgZGVidWcgaW5m
byBtZXRhZGF0YS4gSGVyZSBhcmUgdGhlIHN0ZXBzIChhdCBtaW5pbXVtIC0gcHJvYmFibHkgaW5j
b21wbGV0ZSkgb25lIG5lZWRzIHRvIHRha2U6PGJyPjwvZGl2PjxkaXYgc3R5bGU9ImZvbnQtZmFt
aWx5OkFyaWFsOyI+PGJyPjwvZGl2PjxkaXYgc3R5bGU9ImZvbnQtZmFtaWx5OkFyaWFsOyI+MS4g
Q3JlYXRlIGEgbmV3IGNsYXNzIGluIHRoZSBoaWVyYXJjaHk8YnI+PC9kaXY+PGRpdiBzdHlsZT0i
Zm9udC1mYW1pbHk6QXJpYWw7Ij4yLiBJbXBsZW1lbnQgdHdvIGZvcm1zIG9mIGBNRF9OT0RFX0dF
VGA8YnI+PC9kaXY+PGRpdiBzdHlsZT0iZm9udC1mYW1pbHk6QXJpYWw7Ij4zLiBTcGVjaWFsaXpl
IGBNRE5vZGVLZXlJbXBsYDxicj48L2Rpdj48ZGl2IHN0eWxlPSJmb250LWZhbWlseTpBcmlhbDsi
PjQuIE1vZGlmeSBgTExQYXJzZXIuY3BwYCBhbmQgYWRkI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