<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"></p>
<div><span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"> > the assumption that LLVM will lay the code out</span></div>
<div><br>
</div>
<div>In other project, using gcc, we have:</div>
<div><br>
</div>
<div>flag_reorder_blocks = false;                  /* breaks our exception handling? */</div>
<div>flag_reorder_blocks_and_partition = false;    /* breaks our exception handling? */</div>
<div><br>
</div>
<div>It might be nice to have that in LLVM.</div>
<div>It appears gcc actually uses these itself for similar reasons.</div>
<div>i.e. doesn't allow those optimizations when supporting exceptions.</div>
<div><br>
</div>
<div><span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"> > to the end of the function</span><br>
</div>
<div><span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"><br>
</span></div>
<div><span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">Or even further away, i.e. cold page not just cold
 cache line.</span></div>
<div><span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">Windows supports that at least with "chained" unwind.</span></div>
<div><br>
</div>
<div>Otherwise, understood.</div>
<div><br>
</div>
<p style="margin-top:0;margin-bottom:0">Thank you,</p>
<p style="margin-top:0;margin-bottom:0"> - Jay</p>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Reid Kleckner <rnk@google.com><br>
<b>Sent:</b> Wednesday, May 30, 2018 6:00 PM<br>
<b>To:</b> jayk123@hotmail.com<br>
<b>Cc:</b> llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] getting code ranges of multiple blocks and prevent reordering?</font>
<div> </div>
</div>
<meta content="text/html; charset=utf-8">
<div>
<div dir="ltr">
<div class="x_gmail_quote">
<div>The short answer is, no, there is no way to just ask LLVM not to reorder things. There isn't a good principled way to do this, because it relies on the assumption that LLVM will lay the code out the same way that you gave it do it.</div>
<div><br>
</div>
<div>At source level, the user usually writes something like this establishing a scoped try region:</div>
<div><br>
</div>
<div>try {</div>
<div>  *p = 42;</div>
<div>  if (p)</div>
<div>    a = fp_x / fp_y;</div>
<div>  if (a)</div>
<div>    might_throw(p, a);</div>
<div>} catch (...) {<br>
}</div>
<div><br>
</div>
<div>In LLVM, the backend could easily decide to move that conditional code out of line to the end of the function if its heuristics identify it as cold code. That means that it's not sufficient to do things like emitting labels in inline assembly at the try
 region start and try region end, or the equivalent with new intrinsics.</div>
<div><br>
</div>
<div>To do this reliably, you need to insert labels around every potentially throwing operation, which is what CodeGen does for the `invoke` LLVM IR instruction. Then, after code layout is done, you can walk over the code to find the labels you inserted before,
 and coalesce consecutive regions of potentially throwing instructions. Typically, you build a table called an LSDA, which contains relocations against your labels.</div>
<div><br>
</div>
<div>You can look at the code in llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp, WinException.cpp, and DwarfCFIException.cpp to find code that implements this logic.</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">On Tue, May 29, 2018 at 9:20 PM Jay K via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" id="LPlnk441253" class="OWAAutoLink" previewremoved="true">llvm-dev@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
Hi. I'm very new to LLVM.<br>
<br>
For reasons to do with custom exception handling, we have a need to check IP/PC at runtime against code ranges. This can encompass multiple logically adjacent blocks.<br>
<br>
How to do this?<br>
<br>
I'm guessing:<br>
  insert a label at end of every block, takes it address, store that somewhere in our data; preferably as an offset from module or function start, but full address with relocation would work<br>
  take address of start of every block, similarly<br>
   That is not allowed as I understand for function-entry block, so add an extra dummy block as entry, that branches to actual start.<br>
<br>
And then, somehow, ask LLVM not to reorder anything, with functions with such labels?<br>
<br>
Does this make sense and can anyone fill in details?<br>
<br>
Also, of course some reordering would be ok, as long as start of first block is first, and end of last block is last. The order of the blocks between doesn't matter.<br>
<br>
I realize, there is another approach, something like assigning our own numbers  to scopes, have a local volatile integer, that we assign as we enter/leave scopes. i.e. "NT/x86 EH style". But that is a bigger and less efficient change compared to what we have
 (a non-LLVM less-optimizing codegen that lets us do what I describe).<br>
<br>
Thank you,<br>
 - Jay<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" id="LPlnk845208" class="OWAAutoLink" previewremoved="true">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" id="LPlnk259703" class="OWAAutoLink" previewremoved="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</body>
</html>