Ivan,<div><br>Sorry, no, I wasn't clear enough. Both "op dst_reg,immediate,src_reg" and "op dst_reg,src_reg,immediate" are allowed in the ALU ops. For most instructions these are two different things - e.g. sub a,5,b is different from sub,a,b,5 obviously - but for things like add they just define the same thing.</div>
<div><br></div><div>My problem is that LLVM won't allow immediates on the LHS of nodes so I am forced to have a non-clean layout due to TableGen issues. Aside from my disliking that I have to care about a TableGen restriction like that, I was looking to see if there was a better solution to the problem than using nested multiclasses like I showed.</div>
<div><br></div><div>Stephen<br><br>PS: Your message was off-list - I wasn't sure if that was deliberate and I thought that I should make the matter clear for anyone else, so I cc'd the list back in. I hope you do not mind. :)<br>
<br><div class="gmail_quote">On 14 January 2012 22:21, Ivan Llopard <span dir="ltr"><<a href="mailto:ivanllopard@gmail.com">ivanllopard@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Stephen,<div class="im"><br>
<br>
On 14/01/2012 21:26, Stephen McGruer wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear all,<br>
<br>
I was wondering if it is possible in TableGen to either:<br>
<br>
1. Selectively define an instruction depending on an SDNode's<br>
properties, e.g. if the SDNode is not commutative.<br>
2. Override/ignore the TableGen error given when a commutative node has<br>
an immediate on the LHS.<br>
<br>
My case comes from trying to define a generic ALU operation multiclass<br>
for my target, which includes a "dest_reg,immediate,src_reg" format.<br>
This is disallowed for commutative SDAG nodes (e.g. 'add') in LLVM, as<br>
the RHS cannot be an immediate (I assume for optimization purposes). I<br>
think I could achieve this with nested multiclasses, e.g.:<br>
<br>
</blockquote>
<br></div>
If your target supports only additions with immediates in LHS, it is just an asm printing issue if I understand your problem correctly. You can just print out your immediate where you want it to be printed. For example:<br>

<br>
def ADDLHSImm: Instruction {<br>
  let OutOperandList = (outs R:$dst);<br>
  let InOperandList  = (ins R:$src, i32imm:$b);<br>
  let AsmString = "add $dst, $b, $src";<br>
  let Pattern = (set R:$dst, (add R:$src, imm:$b);<br>
}<br>
<br>
Because "add" is commutative, the instruction selector will have both patterns to match, one with LHS as an immediate and the other one with RHS as an immediate.<br>
<br>
Regards,<br>
Ivan<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
multiclass ALUOp<..> {<br>
...<br>
}<br>
<br>
multiclass ALUOp_not_comm<..> {<br>
   defm : ALUOp<...>;<br>
<br>
   // Plus the 'dest_reg,immediate,src_reg' format.<br>
}<br>
<br>
defm ADD : ALUOp<..><br>
defm SUB : ALUOp_not_comm<..><br>
<br>
<br>
But this feels slightly dirty to me, not to mention more annoying to<br>
maintain (since in my target's eyes there is no difference between the<br>
formats for ADD and SUB), so I just wanted to check if there was any way<br>
to avoid this.<br>
<br>
Thanks,<br>
Stephen<br>
<br>
<br></div>
______________________________<u></u>_________________<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">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</blockquote>
</blockquote></div><br></div>