<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#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="moz-cite-prefix">On 11/7/18 5:22 PM, Jordan Rudd via
llvm-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CY1PR19MB0030E91A571763C8426C4F3FC7C50@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);">
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="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
</body>
</html>