<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Yes, program counter. Also known as instruction pointer. On
X86-64, RIP register.</p>
<p><br>
</p>
<p>Philip<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 11/8/18 10:48 AM, Jordan Rudd wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CY1PR19MB00304E13C29636787FC1C606C7C50@CY1PR19MB0030.namprd19.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
<div style="font-family: Calibri, Helvetica, sans-serif;
font-size: 12pt; color: rgb(0, 0, 0);">
Program counter?</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
face="Calibri, sans-serif" color="#000000"><b>From:</b>
llvm-dev <a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev-bounces@lists.llvm.org"><llvm-dev-bounces@lists.llvm.org></a> on behalf of
Jordan Rudd via llvm-dev <a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org"><llvm-dev@lists.llvm.org></a><br>
<b>Sent:</b> Thursday, November 8, 2018 10:47 AM<br>
<b>To:</b> Philip Reames; <a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] Passing stack pointer to
statepoint-gc</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
Sorry, what does "PC" mean here?</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
face="Calibri, sans-serif" color="#000000"><b>From:</b>
Philip Reames <a class="moz-txt-link-rfc2396E" href="mailto:listmail@philipreames.com"><listmail@philipreames.com></a><br>
<b>Sent:</b> Thursday, November 8, 2018 7:27 AM<br>
<b>To:</b> Jordan Rudd; <a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] Passing stack pointer to
statepoint-gc</font>
<div> </div>
</div>
<div style="background-color:#FFFFFF">
<p>Jordon,</p>
<p><br>
</p>
<p>First of all, StackMaps are keyed by PC, not by SP. Each
entry corresponds to given location within the generated
code.
<br>
</p>
<p><br>
</p>
<p>This isn't something you want to do in generated code.
Your runtime should be responsible for this. If you support
stack walking or back traces for any purpose, you should
already have the code to identify the PC for a suspended
frame on the stack.</p>
<p><br>
</p>
<p>If you don't, the easiest approach will be to use a
assembly stub between your generated code and your C/C++
runtime code which grabs the PC from the stack, and moves it
into an argument register.</p>
<p><br>
</p>
<p>Philip</p>
<p><br>
</p>
<div class="x_x_moz-cite-prefix">On 11/7/18 5:22 PM, Jordan
Rudd via llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<style type="text/css" style="display:none">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
Hi,</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
I'm trying to use the statepoint-example strategy to build
a simple garbage collector. After using the
PlaceSafepoints and RewriteStatepointsForGC passes, I can
successfully generate a stack map in my binary and call
into my runtime's gc poll.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
As far as I can tell, I need the stack pointer at the
point of the poll to find the correct frame in the stack
map. I'm having trouble doing that.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
One library I looked at online (statepoint-utils) simply
defines a helper function written in assembly that pushes
the RSP register to RDI before calling into the runtime,
so that the runtime gc polling function can read it as a
parameter.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
I was trying to do the same thing except in llvm, so from
my gc.safepoint_poll definition, I tried adding these
lines:</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;
font-size:10pt">declare void
@runtime_safepoint_poll(i64)</span><span><br>
</span>
<div><span style="font-family:Consolas,Courier,monospace;
font-size:10pt">declare i64
@llvm.read_register.i64(metadata) #1</span><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace;
font-size:10pt">!0 = !{!"rsp\00"}</span><br>
</div>
<div><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace;
font-size:10pt">; Read the stack pointer and pass it
to our polling function (assumes x64)</span><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace;
font-size:10pt">define void @gc.safepoint_poll() {</span><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace;
font-size:10pt"> %stackpointer = call i64
@llvm.read_register.i64(metadata !0)</span><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace;
font-size:10pt"> call void
@runtime_safepoint_poll(i64 %stackpointer)</span><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace;
font-size:10pt"> ret void</span><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace;
font-size:10pt">}</span><br>
</div>
<div><br>
</div>
<span style="font-family:Consolas,Courier,monospace;
font-size:10pt">attributes #1 = { "gc-leaf-function"
nounwind readnone }</span><br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<span>Note that the target triple
is x86_64-pc-windows-msvc.</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<span>When I test this, the values that come from reading
RSP are never in the address space of the module. Like,
not even close.</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
As far as I can tell, this <i>should </i>work, and I'm a
little stymied as to why I'm getting back garbage. Do I
misunderstand the read_register call here?</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
Thanks,</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
Jordan</div>
<div style="font-family:Calibri,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<br>
<fieldset class="x_x_mimeAttachmentHeader"></fieldset>
<pre class="x_x_moz-quote-pre">_______________________________________________
LLVM Developers mailing list
<a class="x_x_moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>
<a class="x_x_moz-txt-link-freetext" href="https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev&data=02%7C01%7C%7Cbb88aac921f247a9080b08d645aaa91e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636772996613513985&sdata=IQb%2B6Gs6UMJYw9iNiQpbM5veWc8%2F4SVcDStnSqE5DLQ%3D&reserved=0" originalsrc="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" shash="R8SCr3gfcFy/kKRJ07KecRKeECxnm7Zt861tX7EMpbNgGhmBWfKQEKxf37yw5DcsE51vnuFlL5jqxJ2IRxD8IAYlYFsMd+z0gpLVuHLHhxse4M4Xr6cE2jowrGuqN9kciYEyQfHOK2em47rZkXPPdRc+YtJYPUr6hDLD49Spcs0=" moz-do-not-send="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
</div>
</div>
</blockquote>
</body>
</html>