<div dir="ltr"><div>Alex,</div><div><br></div><div> No, it's removing it before, just like in ChangeToImmediate.</div><div><br></div><div>void MachineOperand::ChangeToGlobalAddress(const GlobalValue *GV, int64_t Offset) {<br> assert((!isReg() || !isTied()) && "Cannot change a tied operand into a global");<br> if (isReg() && isOnRegUseList())<br> if (MachineInstr *MI = getParent())<br> if (MachineBasicBlock *MBB = MI->getParent())<br> if (MachineFunction *MF = MBB->getParent())<br> MF->getRegInfo().removeRegOperandFromUseList(this);</div><div> OpKind = MO_GlobalAddress;<br> setOffset(Offset);<br> Contents.OffsetedInfo.Val.GV = GV;<br>}</div><div><br></div><div><br></div><div>The problem is that I'm getting a use before def on vreg5 now further down the instruction list. Not sure why this is the case?</div><div><br></div><div>Thanks.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 16, 2015 at 1:17 PM, Alex L <span dir="ltr"><<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@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">I'm not sure I understand what your problem is, but are you calling the removeRegOperandFromUseList on the machine operand after changing it to GA? You have to call removeRegOperandFromUseList before changing the operand's type, as it expects a register operand.</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2015-06-16 10:05 GMT-07:00 Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div>@Alex: Thanks. setOffset(0) eliminated any previous offsets, of course, so I added another param (int64_t Offset) and am adding that, this should preserve the orginial offset of the GA.</div><div><br></div><div>Sorry, I put the above response in the wrong thread.</div><div><br></div><div>Also, when I try to use this new function to do the same thing on it's uses, I get an error that vreg5 is somehow not a register? </div><div><br></div><div>So, the MI looks like this:</div><div><br></div><div>vreg5 = MOV <ga:@a></div><div>vreg2 = ABS vreg5</div><div>...</div><div>...</div><div>vreg9 = SUB vreg7, vreg5</div><div><br></div><div>In this case, I want to eliminate vreg5 and replace it with <ga:@a>, the ChangeToGlobalAddress is working for the ABS but for some reason, when I get the uses of vreg5 it tells me it's not an register operand (vreg5 is not), which makes sense since ChangeToGlobalAddress is calling removeRegOperandFromUseList(this) for ABS, but it's confusing because then why does vreg5 have any uses?</div><div><br></div><div><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 16, 2015 at 12:36 PM, Alex L <span dir="ltr"><<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr">Hey Ryan,<div><br></div><div>You end with a large constant immediate offset value because the register operand stores the register id in a union together with the offset that's used by the global address operand.</div><div><br></div><div>Just add 'setOffset(0)' to your change method and that should solve your problem.</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-06-16 9:15 GMT-07:00 Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div>So I have this for ChangeToGlobalAddress(const GlobalValue *GV):</div><div><br></div><div>...</div><div>OpKind = MO_GlobalAddress;</div><div>Contents.OffsetedInfo.Val.GV = GV; </div><div><br></div><div>and then I use the function like this:</div><div><br></div><div>MI->getOperand(1).ChangeToGlobalAddress(MII->getOperand(1).getOperand.getGlobal());</div><div><br></div><div>The operand ends up being replaced with the global; however, it's also adding a large constant immediate value with it.</div><div><br></div><div>For example, instead of <ga:@a> I end up with <ga:@a+2147483653> and instead of <ga:@a+100> I end up with <ga:@a+214748564></div><div><br></div><div>What might I be doing wrong?</div><div><br></div><div>Thanks.</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 16, 2015 at 10:12 AM, Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div>Tom,</div><div><br></div><div> My current example is a global address; however, it could be any operand in theory. The arch allows for direct mem op support for ex instructions, so it could be any type of address or any type of imm or any type of register. </div><div><br></div><div> For example, we are using intrinsics for some instructions since LLVM does not support them. Table gen does not allow for matching to direct mem op because the intrinsics are calls, so registers are setup for the call parameters. So we end up with something like:</div><div><br></div><div> mov @a, r0</div><div> abs r0, r1</div><div><br></div><div>In our arch, we should be able to do 'abs @a, r1'. So since the intrinsics won't match properly in the tblgen we're looking at doing a peephole where we want to replace the operand 'r0' with @a and remove the 'mov @a, r0' instruction, so it would look like:</div><div><br></div><div> abs @a, r1</div><div><br></div><div>Thanks.</div><div><br></div><div>ps. We could add these operators to LLVM instead of using intrinsics but that also introduces a lot of dev cost and maintenance cost and some other technical issues, but then we could have the operators match in the tblgen. We are looking to avoid this, we thought a simple peephole would do the trick instead.</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 16, 2015 at 9:57 AM, Tom Stellard <span dir="ltr"><<a href="mailto:tom@stellard.net" target="_blank">tom@stellard.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><span>On Mon, Jun 15, 2015 at 10:16:47PM -0400, Ryan Taylor wrote:<br>
> I have a MachineOperand that could be something other than a Reg: mem,<br>
> global address, imm, etc...<br>
><br>
> I want to replace a reg MachineOperand with this non-reg MachineOperand.<br>
><br>
> I've tried a few different things, but it doesn't seem like there is some<br>
> simple functionality to do this?<br>
><br>
> "RemoveOperand" and "addOperand" does not work.<br>
> There doesn't seem to be a valid "ChangeTo..." function for this.<br>
><br>
><br>
<br>
</span>What type of operand do you want to change it to? If there is no<br>
"ChangeTo..." function for the new type, I think the best thing to do<br>
would be to add a new "ChangeTo..." function to handle the new type.<br>
<br>
-Tom<br>
<span><br>
> What's the best way to do this without tearing down the instructions and<br>
> using BuildMI?<br>
><br>
> Thanks.<br>
<br>
</span>> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank" rel="noreferrer">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" rel="noreferrer">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank" rel="noreferrer">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" rel="noreferrer">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>