[LLVMdev] Regarding ARM CodeGen

kapil anand kapilanand2 at gmail.com
Tue Jul 15 11:55:18 PDT 2008


Hi Gordon,

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

R3 = ADD PC, R2

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.

label: %tmp3 = add %label,%tmp2

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?

Thanks

Kapil








On Tue, Jul 15, 2008 at 12:47 PM, Gordon Henriksen <gordonhenriksen at mac.com>
wrote:

> On 2008-07-15, at 11:35, kapil anand wrote:
>
> > I have one more query regarding the LLVM representations. In LLVM
> > Infrastructure, "label" is defined as Primitive type. So, is there
> > any way of using a variable of Type Label in some arithmetic
> > operation or in "bitcast" instruction.
> >
> > Is there any other way to use label in arithmetic operations. I am
> > trying this to represent Program counter in LLVM, since in ARM, we
> > can have various instructions which operate on PC , eg.
>
> Hi Kapil,
>
> If this isn't a FAQ, it should be. In LLVM, 'label' values (in C++,
> BasicBlock*'s) can only be used as arguments to flow control
> instructions (br, switch, invoke, and phi, to be specific). The reason
> is that the SSA representation cannot be formed in the presence of
> dynamic flow control—consider how the code generator might implement
> PHI if sources and destinations are not decidable.
>
> What are you attempting to accomplish by reading the PC? The usual
> goal in using an 'address of label' is to implement a jump table by
> hand. In this case, your compiler should assign integers to labels and
> then, when it wants to emit a dynamic 'goto', it should branch into a
> switch statement, which the LLVM optimizer will transform into a jump
> table. If you use mem2reg, LLVM will take care of the phi nodes for you.
>
> -- Gordon
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080715/f81f9cae/attachment.html>


More information about the llvm-dev mailing list