<div dir="ltr"><div><div>Thanks for the tip on getRegAllocationHints.<br><br></div>How is this callback called? Is it called separately for each register assignment for an instruction, or is it called once for each instruction? I'm afraid it's probably the former and thus it wouldn't be so useful as I need to check that the first and third register operands are not in the same bank (doesn't matter if the first and second one are).<br><br></div><br><div><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 3, 2016 at 6:39 PM, Marcello Maggioni <span dir="ltr"><<a href="mailto:mmaggioni@apple.com" target="_blank">mmaggioni@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You can also give hints to the register allocator to not allocate the registers in a way that would create bank conflicts.<br>
<br>
I suggest looking for getRegAllocationHits() in the targets ***RegisterInfo.cpp file for examples.<br>
<span class="HOEnZb"><font color="#888888"><br>
Marcello<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On 3 May 2016, at 18:32, Matthias Braun via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> As there are no physical registers allocated at instruction selection time. This sounds something you should rather do in a custom target pass running after register allocation. Or you could indeed fix it up at ASMPrinter time (though a custom pass would be more typical I think).<br>
><br>
> - Matthias<br>
><br>
>> On May 3, 2016, at 5:20 PM, Phil Tomson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
>><br>
>> In our generated asm code we've got a constraint such that two registers in a ternary op have to be in different "banks", best illustrated with an example:<br>
>><br>
>>   add  r1,r2,r1 # r1 <- r2 + r1<br>
>><br>
>> The problem here is that the first operand (the receiver of the value) is in the same "bank" as the 3rd operand (r1 again). This will cause an extra cycle to be burned. As it turns out the first and second operands can be in the same bank, so the issue is with the first and third operand being in the same bank.<br>
>><br>
>> This example is easily "fixed" (the performance is optimized) by swapping the 2nd and 3rd operands:<br>
>><br>
>>  add  r1, r1, r2 # r1 <- r1 + r2<br>
>><br>
>><br>
>> There are four banks and the formula to figure out which bank a register is in is just: r%4<br>
>><br>
>> Which brings me to tablegen:<br>
>><br>
>> We've got this in our specialized ArchInstrInfo.td:<br>
>><br>
>> // r1 = r2 op r3<br>
>> //<br>
>> class ArithOp_RR< bits<7> op,<br>
>>                  string instr_asm,<br>
>>                  SDNode opNode,<br>
>>                  OperandInfo info,<br>
>>                  InstrItinClass itin ><br>
>>  : FR3< op,<br>
>>        (outs info.regClass:$r1),<br>
>>        (ins info.regClass:$r2, info.regClass:$r3),<br>
>>        instr_asm # "\t\t$r1, $r2, $r3, " # info.sizeStr,<br>
>>        [(set info.regClass:$r1, (opNode info.regClass:$r2, info.regClass:$r3))],<br>
>>        itin > {<br>
>>          let isFloat = info.isFloat;<br>
>>          let opsize = info.sizeCode;<br>
>>        }<br>
>><br>
>> Is there a way to do something like:<br>
>><br>
>><br>
>> // r1 = r2 op r3<br>
>> //<br>
>> class ArithOp_RR< bits<7> op,<br>
>>                  string instr_asm,<br>
>>                  SDNode opNode,<br>
>>                  OperandInfo info,<br>
>>                  InstrItinClass itin ><br>
>>  : FR3< op,<br>
>>        (outs info.regClass:$r1),<br>
>>        (ins info.regClass:$r2, info.regClass:$r3),<br>
>> if( $r1%4 == $r3%4 ) {<br>
>>       instr_asm # "\t\t$r1, $r3, $r2, " # info.sizeStr,<br>
>>        [(set info.regClass:$r1, (opNode info.regClass:$r3, info.regClass:$r2))],<br>
>> } else {<br>
>>       instr_asm # "\t\t$r1, $r2, $r3, " # info.sizeStr,<br>
>>        [(set info.regClass:$r1, (opNode info.regClass:$r2, info.regClass:$r3))],<br>
>> }<br>
>>        itin > {<br>
>>          let isFloat = info.isFloat;<br>
>>          let opsize = info.sizeCode;<br>
>>        }<br>
>><br>
>><br>
>> Is that even remotely possible? If not, are there other ways to achieve this sort of thing? Would I be better off doing it in the ArchASMPrinter.cpp (I would think this could be problematic)? Or is there somewhere "further up" which would be more appropriate?<br>
>><br>
>> Phil<br>
>> _______________________________________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
</div></div></blockquote></div><br></div>