[LLVMdev] Regarding ARM CodeGen
Gordon Henriksen
gordonhenriksen at mac.com
Tue Jul 15 09:47:02 PDT 2008
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
More information about the llvm-dev
mailing list