<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 26, 2019 at 12:38 PM Tim Northover <<a href="mailto:t.p.northover@gmail.com">t.p.northover@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Gleb,<br>
<br>
On Wed, 26 Jun 2019 at 07:28, Gleb Popov <<a href="mailto:6yearold@gmail.com" target="_blank">6yearold@gmail.com</a>> wrote:<br>
> def StoreStackF : InstRI<2, (outs), (ins IntRegs:$reg, i32imm:$i),<br>
> "storestackf $reg, [$i]", [(store_stack i32:$reg, AddrFI:$i)]>;<br>
><br>
> I'm puzzled why despite having "IntRegs:$reg" in ins list, it still matches FrameIndex:<br>
<br>
A register-class will match anything with the appropriate type (i32<br>
here). The idea is that any value of that type can be put into a<br>
register somehow, and matching whatever it happens to be (a FrameIndex<br>
in this case) is exactly what's needed to do that.<br></blockquote><div><br></div><div>That's a useful explanation, thanks.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> ISEL: Starting selection on root node: t11: i32 = FrameIndex<2><br>
> ISEL: Starting pattern match<br>
> Initial Opcode index to 0<br>
> Match failed at index 0<br>
> LLVM ERROR: Cannot select: t11: i32 = FrameIndex<2><br>
<br>
Ah good, this is what I thought was probably happening so it's nothing<br>
exotic. You need to be able to match a FrameIndex somehow. Not just<br>
for this, but for something like:<br>
<br>
void foo() {<br>
int arr[5];<br>
bar(&arr[0]);<br>
}<br>
<br>
It's pretty simple to implement matching, you generally just need to<br>
convert it to some add instruction that can do SP+imm. </blockquote><div><br></div><div>For the sake of simplicity I decided not to bother with stack register yet and instead I just emit FrameIndex as immediate:</div><div><br></div><div>bool MyBackendDAGToDAGISel::SelectAddrFI(SDValue &N, SDValue &R) {<br> if (N.getOpcode() != ISD::FrameIndex)<br> return false;<br> MachineFrameInfo &MFI = MF->getFrameInfo();<br> int FX = cast<FrameIndexSDNode>(N)->getIndex();<br> R = CurDAG->getTargetFrameIndex(FX, MVT::i32);<br> return true;<br>}</div><div><br></div><div>This way I end up with</div><div><br></div><div>store %r1, [1]</div><div><br></div><div>and handle it in my CPU emulator accordingly.<br></div><div><br></div><div>So, instead of matching that FrameIndex in store, I really want to emit a load first and then use a register in the store instruction.</div><div>Can you, please, advise me how to implement that?<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">See for example<br>
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp:2916.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
</blockquote></div></div>