<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Currently, the debug intrinsic functions each have 3 arguments: an SSA value representing either the address or Value of a local variable, a DILocalVariable, and a complex expression. If the SSA value is an Instruction, and that Instruction
 is at some point deleted, we attempt to salvage the SSA value by recreating the instruction within the complex expression. If the instruction cannot be replicated by a complex expression, then the variable location is dropped causing a reduction in coverage.
 One of the key restrictions on this process at the moment is that each intrinsic can only reference a single SSA value; a numeric constant may be represented within the expression itself, allowing for binary operators with a constant operand to be salvaged:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:Consolas">%c = add i32 %a, 4<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">llvm.dbg.value(metadata i32 %c, DILocalVariable("x"), DIExpression())<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">; Salvage...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">llvm.dbg.value(metadata i32 %a, DILocalVariable("x"), DIExpression(DW_OP_constu, 4, DW_OP_plus))<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This proposal is to allow multiple SSA value references within a debug intrinsic, allowing binary operators with non-constant operands to be salvaged. This is a long-awaited feature, with an open bugzilla[0] and support from members of
 the community[1][2]. To implement this change, each debug intrinsic will contain a list of SSA values instead of just one, and a new operator will be added:
<span style="font-family:Consolas">DW_OP_LLVM_register</span>, which takes as its only argument the index of an SSA value within the intrinsic’s list, and pushes that SSA value onto the expression stack. Two proposed syntaxes for the list of SSA values - though
 suitable alternatives may be worth considering - are to either replace the first argument of the intrinsic function with an MDNode containing the SSA values as operands, or to remove the first argument and make the intrinsic function variadic, passing the
 SSA value list as vargs:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:Consolas">%c = add i32 %a, %b<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">llvm.dbg.value(metadata i32 %c, DILocalVariable("x"), DIExpression())<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">; Salvage...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">llvm.dbg.value(!{metadata i32 %a, metadata i32 %b}, DILocalVariable("x"), DIExpression(DW_OP_LLVM_register, 0, DW_OP_LLVM_register, 1, DW_OP_plus))<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">; Alternatively, the intrinsic function could be made variadic...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">llvm.dbg.value(DILocalVariable("x"), DIExpression(DW_OP_LLVM_register, 0, DW_OP_LLVM_register, 1, DW_OP_plus), metadata i32 %a, metadata i32 %b)<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The new operator <span style="font-family:Consolas">DW_OP_LLVM_register</span> would exist in the IR and MIR, and further down the pipeline be replaced by the appropriate operator for the target debug output. For example, when producing
 DWARF this would be replaced by <span style="font-family:Consolas">DW_OP_regval_type</span>, which pushes the contents of a given register interpreted as a value of a given type onto the DWARF expression stack.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This has the potential to allow salvaging in a much greater number of cases than is currently possible. There are also potential follow-up tasks, such as allowing the salvaging of conditional values, that would further improve debug variable
 availability. The following table gives, for several of the multi-source application projects in the test suite, the number of successful invocations of SalvageDebugInfo, and the number of failed salvages for each type of unsalvageable instruction:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:Consolas">            Success             Variadic Binops     Variadic GEPs       Cmp Insts           Select Insts        Load Insts          Phi Nodes           Alloca Insts        Call Insts<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">ALAC        261                 29                  61                  0                   0                   1                   12                  0                   0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">Burg        50                  1                   9                   0                   1                   95                  6                   0                   0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">hbd         514                 16                  1                   0                   3                   45                  10                  0                   4<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">Lua         270                 12                  54                  0                   12                  46                  32                  1                   0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">minisat     458                 10                  10                  3                   1                   35                  4                   0                   0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">sgefa       439                 1                   121                 0                   20                  14                  55                  0                   0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">SIBsim4     153                 15                  6                   0                   3                   40                  3                   0                   0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">siod        112                 2                   1                   0                   0                   11                  5                   2                   1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">SPASS       1241                70                  27                  27                  27                  2114                156                 0                   7<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">spiff       39                  0                   15                  0                   0                   7                   2                   1                   0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">sqlite3     2322                94                  167                 6                   37                  1143                136                 4                   10<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">treecc      127                 1                   0                   0                   1                   350                 37                  0                   1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:Consolas">viterbi     7                   0                   1                   0                   1                   1                   0                   0                   0<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Of these categories, the first 3 will become salvageable after this work is implemented, and Select Insts will also be salvageable with some follow-up work to enable conditional branching in complex expressions. The remainder are not salvageable
 in general, although it's possible that the specific passes that delete those instructions may be able to preserve the debug info as long as the code isn't totally dead.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[0] https://bugs.llvm.org/show_bug.cgi?id=39141<o:p></o:p></p>
<p class="MsoNormal">[1] https://reviews.llvm.org/D51976#1237060<o:p></o:p></p>
<p class="MsoNormal">[2] http://lists.llvm.org/pipermail/llvm-dev/2019-November/137021.html<o:p></o:p></p>
</div>
</body>
</html>