<div dir="ltr">Ping</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jun 4, 2016 at 4:15 PM, Dylan McKay <span dir="ltr"><<a href="mailto:dylanmckay34@gmail.com" target="_blank">dylanmckay34@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><p style="margin:0px 0px 1.2em!important">Hello all,</p>
<p style="margin:0px 0px 1.2em!important">I am working on adding atomics support to the AVR backend.</p>
<p style="margin:0px 0px 1.2em!important">Because the target can only have one core, it is sufficient to:</p>
<ul style="margin:1.2em 0px;padding-left:2em">
<li style="margin:0.5em 0px">Save the status register</li>
<li style="margin:0.5em 0px">Disable interrupts</li>
<li style="margin:0.5em 0px">Do the nonatomic LOAD/STORE/SWAP/ADD</li>
<li style="margin:0.5em 0px">Restore the status register</li>
</ul>
<p style="margin:0px 0px 1.2em!important">I’d really like to be able to do this at the IR level. What I want to do is write a custom lowering hook to convert <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);border-radius:3px;display:inline;background-color:rgb(248,248,248)">ISD::ATOMIC_LOAD</code> into a standard <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);border-radius:3px;display:inline;background-color:rgb(248,248,248)">ISD::LOAD</code> with the save/restore/interrupt nodes glued to it.</p>
<p style="margin:0px 0px 1.2em!important">Here’s what I have so far:</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 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);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre-wrap;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)"> <span style="color:rgb(153,153,136);font-style:italic">// Store `SREG`</span>
<span style="color:rgb(51,51,51);font-weight:bold">auto</span> Save = DAG.getCopyFromReg(DAG.getEntryNode(), DL, AVR::SREG, MVT::i8);
<span style="color:rgb(153,153,136);font-style:italic">// Disable interrupts (`clr` is equivalent to `bclr 7`).</span>
<span style="color:rgb(51,51,51);font-weight:bold">auto</span> ClearInterrupts = DAG.getNode(AVRISD::BCLR, DL, MVT::Glue, DAG.getConstant(<span style="color:rgb(0,128,128)">7</span>, DL, MVT::i8));
<span style="color:rgb(153,153,136);font-style:italic">// Perform the nonatomic load.</span>
<span style="color:rgb(51,51,51);font-weight:bold">auto</span> *Node = cast<AtomicSDNode>(AtomicOp.getNode());
SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, SDLoc(AtomicOp), AtomicOp.getValueType(),
Node->getChain(), Node->getBasePtr(),
Node->getMemoryVT(), Node->getMemOperand());
<span style="color:rgb(51,51,51);font-weight:bold">auto</span> Restore = DAG.getCopyToReg(DAG.getEntryNode(), DL, AVR::SREG, Save);
<span style="color:rgb(51,51,51);font-weight:bold">return</span> Load;
</code></pre>
<p style="margin:0px 0px 1.2em!important">I can’t figure out how I can glue all these nodes together and return the nonatomic load.</p>
<p style="margin:0px 0px 1.2em!important">How can I do this?</p>
<p style="margin:0px 0px 1.2em!important">Cheers,<br>Dylan</p>
<div title="MDH:SGVsbG8gYWxsLDxkaXY+PGJyPjwvZGl2PjxkaXY+SSBhbSB3b3JraW5nIG9uIGFkZGluZyBhdG9t
aWNzIHN1cHBvcnQgdG8gdGhlIEFWUiBiYWNrZW5kLjwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+
QmVjYXVzZSB0aGUgdGFyZ2V0IGNhbiBvbmx5IGhhdmUgb25lIGNvcmUsIGl0IGlzIHN1Zm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