<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 7, 2016 at 1:35 PM, Krzysztof Parzyszek <span dir="ltr"><<a href="mailto:kparzysz@codeaurora.org" target="_blank">kparzysz@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On 1/7/2016 3:25 PM, Phil Tomson wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
That's better, but now I get:<br>
<br>
  XSTGInstrInfo.td:902:3: error: In RelAddr: XSTGRELADDR node requires<br>
exactly 2 operands!<br>
<br>
Which makes some sense as XSTGRELADDR is defined as:<br>
def SDT_RELADDR       : SDTypeProfile<1, 2, [SDTCisInt<0>,<br>
SDTCisSameAs<0, 1>]>;<br>
def XSTGRELADDR       : SDNode<"XSTGISD::RELADDR", SDT_RELADDR>;<br>
</blockquote>
<br></span>
The problem is that the pattern that you use in the instruction definition cannot have any value.  That is, the top node has to consume all values produced by the nodes below it.  The node XSTGRELADDR does have a value, and so it cannot be the top node.<br>
If the intent is to have the second operand as the target register for that value, it shouldn't be an operand to the SDNode, and in the instruction definition it should be listed in the (outs) list.  If the second operand is not an output operand, then the RelAddr instruction should have some additional operand in (outs) and use "set ..." in the pattern, or have some other consumer as the top node in the selection pattern.<div class=""><div class="h5"><br> <br></div></div></blockquote><div><br></div><div>Let me explain what I'm trying to achieve: In certain relocation modes we need to have addresses for symbols be relative to a special pointer register we call GRP. For example, let's say we want to access a global variable called 'answer'. The relevant part of the .ll file looks like:<br><br>@answer = addrspace(4) global i32 42, align 4<br>@two = addrspace(3) global i32 2, align 4<br>@seven = addrspace(2) global i32 7, align 4<br>@xint = common global i32 0, align 4<br>@y = global [1 x i32*] [i32* @xint], align 8<br><br>; Function Attrs: nounwind uwtable<br>define i32 @main(i32 %argc, i8** %argv) #0 {<br>entry:<br>  %argc.addr = alloca i32, align 4<br>  %argv.addr = alloca i8**, align 8<br>  %bint = alloca i32, align 4<br>  %cint = alloca i32, align 4<br>  %a = alloca i32**, align 8<br>  %b = alloca i32*, align 8<br>  store i32 %argc, i32* %argc.addr, align 4<br>  store i8** %argv, i8*** %argv.addr, align 8<br>  %0 = load i32 addrspace(4)* @answer, align 4<br>  store i32 %0, i32* @xint, align 4<br>...<br><br>Currently this produces the following assembly code:<br>.Ltmp0:<br>    .cfi_def_cfa_offset 48<br>    store        r510, r509, 0, 64<br>.Ltmp1:<br>    .cfi_offset 510, -48<br>    bitop1        r510, r509, 0, OR, 64<br>.Ltmp2:<br>    .cfi_def_cfa_register 510<br>    store        r0, r510, 44, 32<br>    store        r1, r510, 32, 64<br>    movimm        r0, %hi(xint), 64<br>    movimmshf32    r0, r0, %lo(xint)<br>    movimm        r1, %rel(answer), 64  #<--- relevant lines<br>    load        r1, r1, 0, 32                      #<---<br>...<br></div><div>(%rel is a macro that returns the delta from the global section to the 'answer' symbol)<br><br></div><div>Instead of that last load instruction there, I want it to be:<br><br></div><div>    load       r1, GRP, r1, 32 # r1 <-mem[GRP+r1]<br><br></div><div>GRP is what we call the Global Relocation Pointer - it  holds the address of the global address segment. So what this should do is load the contents pointed to by the address (GRP+r1) into r1. <br></div><div><br></div><div>Of course, this is only if a non-static relocation model is chosen via commandline options.<br><br></div><div>Phil<br></div><div><br><br><br> <br></div></div></div></div>