<div dir="ltr"><div>Hi Gordon,</div>
<div> </div>
<div>I am trying to represent ARM instruction in LLVM. In ARM ISA, PC is itself a General Purpose Register and we can have following kind of instruction </div>
<div> </div>
<div>R3 = ADD PC, R2</div>
<div> </div>
<div>Since label in LLVM corresponds to current position and thus is like a logical Program Counter. I was trying to implement the above instruction by using label as an arguement to LLVM Add instruction, based on the assumption that LLVM CodeGen will finally take care of PC mapping accordingly.</div>

<div> </div>
<div>label: %tmp3 = add %label,%tmp2</div>
<div> </div>
<div>But it seems that this kind of operation is not possible and my assumption is not correct. Is there any way to represent this kind of operation in LLVM?</div>
<div> </div>
<div>Thanks</div>
<div> </div>
<div>Kapil</div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div><br><br> </div>
<div class="gmail_quote">On Tue, Jul 15, 2008 at 12:47 PM, Gordon Henriksen <<a href="mailto:gordonhenriksen@mac.com" target="_blank">gordonhenriksen@mac.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>On 2008-07-15, at 11:35, kapil anand wrote:<br><br>> I have one more query regarding the LLVM representations. In LLVM<br>> Infrastructure, "label" is defined as Primitive type. So, is there<br>> any way of using a variable of Type Label in some arithmetic<br>
> operation or in "bitcast" instruction.<br>><br></div>
<div>> Is there any other way to use label in arithmetic operations. I am<br>> trying this to represent Program counter in LLVM, since in ARM, we<br>> can have various instructions which operate on PC , eg.<br><br>
</div>Hi Kapil,<br><br>If this isn't a FAQ, it should be. In LLVM, 'label' values (in C++,<br>BasicBlock*'s) can only be used as arguments to flow control<br>instructions (br, switch, invoke, and phi, to be specific). The reason<br>
is that the SSA representation cannot be formed in the presence of<br>dynamic flow control—consider how the code generator might implement<br>PHI if sources and destinations are not decidable.<br><br>What are you attempting to accomplish by reading the PC? The usual<br>
goal in using an 'address of label' is to implement a jump table by<br>hand. In this case, your compiler should assign integers to labels and<br>then, when it wants to emit a dynamic 'goto', it should branch into a<br>
switch statement, which the LLVM optimizer will transform into a jump<br>table. If you use mem2reg, LLVM will take care of the phi nodes for you.<br><font color="#888888"><br>-- Gordon<br></font>
<div>
<div></div>
<div><br><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">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></div></div></blockquote></div><br></div>