[LLVMdev] Global data order

Chris Lattner sabre at nondot.org
Tue Jul 13 10:17:52 PDT 2004


On Tue, 13 Jul 2004, Vladimir Prus wrote:

>     %TestArrayPtr = global %struct.test* getelementptr (
>            [10 x %struct.test]* %TestArray, ..........
>     %TestArray = weak global [10 x %struct.test] zeroinitialize
>
> my backend produce data declaration in the same order, so TestArrayPtr refers
> to TestArray before TestArray itself is defined.
>
> Is there a standard way to get the right ordering. I wrote my own code, but
> maybe there's something better.

There is no way to guarantee that there isn't a cycle in the references
between globals.  Does your assembler have some way of forward declaring
globals or something?  If so it would be reasonable to forward declare all
globals before they are emitted.  If not, then there are some programs
that your backend just won't be able to compile, e.g.:

extern void *B;
void *A = &B;
void *B = &A;

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://nondot.org/sabre/




More information about the llvm-dev mailing list