Hi Jacob, thank you for your reply.<br><br>Your suggestion works! But instead of using the Pat<>, I am using<br><br>def MOVE_ADDR : MYInst<(outs Int32Regs:$dst), (ins i32mem:$a),<br>                     "move $dst, $a;",<br>
                     [(set Int32Regs:$dst, (Wrapper tglobaladdr:$a))]>;<br><br><br>I don't quite understand what the semantics of Pat in general. Could you please explain what <br><br>def : Pat<(BfinWrapper (i32 tglobaladdr:$addr)),<br>

           (LOAD32imm tglobaladdr:$addr)>;<br>
<br>means?<br><br>And I totally agree it would be better if someone can explain why the Wrapper is needed here.<br><br>Regards,<br><br>P.B.<br><br><br><div class="gmail_quote">On Sun, Apr 19, 2009 at 11:01 PM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk">stoklund@2pi.dk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im"><br>
On 20/04/2009, at 07.35, Peter Bacon wrote:<br>
<br>
> Hello, I am learning to write a new backend for LLVM and have a few<br>
> simple questions.<br>
<br>
</div>Hi Peter,<br>
<br>
I am a newbie too, but I have recently dealt with the same issues.<br>
<div class="im"><br>
> 1) What are the differences between 'constant' and 'targetconstant',<br>
> 'globaladdress' and 'targetglobaladdress'? It is not clear from the<br>
> document when and which should be used.<br>
<br>
</div>The target* variants are 'done' and will not be changed further by the<br>
instruction selection. After instruction selection, everything should<br>
be converted to the target* variants.<br>
<div class="im"><br>
> 2) On the processor I am working on, there is a 'move reg, mem_addr'<br>
> instruction.<br>
><br>
> When I try to match it using the pattern  [(set Int32Regs::reg,<br>
> tglobaladdr::mem_addr)]. the code generated by tblgen cannot be<br>
> compiled because there will be a switch statement that contains two<br>
> cases for the 'tglobaladdr', one is hard-coded in by tblgen and the<br>
> other is generated by tbglen following the pattern I specified. The<br>
> compilation fails because of the two duplicated and conflicting cases.<br>
<br>
</div>This happened to me too. I stole a solution from the other targets -<br>
create a wrapper node:<br>
<br>
def BfinWrapper: SDNode<"BfinISD::Wrapper", SDTIntUnaryOp>;<br>
<br>
Then custom lower ISD::GlobalAddress, converting it to a wrapped<br>
TargetGlobalAddress:<br>
<br>
SDValue<br>
BlackfinTargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG<br>
&DAG)<br>
{<br>
   DebugLoc DL = Op.getDebugLoc();<br>
   GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();<br>
<br>
   Op = DAG.getTargetGlobalAddress(GV, MVT::i32);<br>
   return DAG.getNode(BfinISD::Wrapper, DL, MVT::i32, Op);<br>
}<br>
<br>
Now you can pattern match on the wrapper:<br>
<br>
def : Pat<(BfinWrapper (i32 tglobaladdr:$addr)),<br>
           (LOAD32imm tglobaladdr:$addr)>;<br>
<br>
If you think this is overly complicated, I agree.<br>
Does anybody know why this is necessary?<br>
<br>
/jakob<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">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/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br>