[LLVMdev] How to explain?

Chris Lattner sabre at nondot.org
Mon Dec 22 20:06:01 PST 2003


On Tue, 23 Dec 2003, yue wrote:

> I want to know what is exact meaning in the following code.
>
> target endian--

The target directives specify information about the target the C front-end
was compiling to when it compiled the file.  Since C is not a type-safe
language, various aspects of the target machine can creep into the
resultant bytecode file.  These directives tell the optimizer and final
code generators what target properties were assumed.

> %struct..TorRec--
> %struct.TorRec--

These are two LLVM type definitions, sortof like C typedefs.  In LLVM,
type definitions just provide symbolic names for types, they don't
introduce new types (in other words, you don't have to declare types
before using them in LLVM, you can just use them with non-symbolic forms).

> implementation--

This is a marker between the "declaration" and "implementation" sections
of the .ll files.  This marker is only needed because the LLVM grammar
requires two tokens of lookahead without it.  When the AsmParser
eventually gets rewritten to use something other than bison, this wart
will go away.  Note that noone is currently planning to do this rewrite,
so the implementation keyword will probably be with us for a while.

> ;<sbyte>[#uses=1/0]--

In .ll files, anything that follows a ; is a comment.  In this case, the
comment indicates the type of the value computed on that line, as well as
the number of things using the result.  In this case, for example:

         %tmp.7.i = load sbyte* %Str.0.i         ; <sbyte> [#uses=1]

A load through an 'sbyte*' pointer produces a value of type 'sbyte'.
There is one instruction using the computed value, the %tmp.8.i cast.
Note that the comment is just there to help us feable human readers, it
has no semantic content and the asmparser ignores the comments.

Hope this helps,

-Chris

> yueqiang
> --------------------------------------------------------------
> target endian = little
> target pointersize = 32
>          %struct..TorRec = type { int, void ()* }
>          %struct.TorRec = type { int, void ()* }
> %.str_1 = internal constant [13 x sbyte] c"hello world\0A\00"
> ; <[13 x sbyte]*> [#uses=1]
>
> implementation   ; Functions:
>
> int %main() {
> entry:
>          br label %no_exit.i1
>
> no_exit.i1:             ; preds = %entry, %no_exit.i1
>          %Str.0.i = phi sbyte* [ %inc.i, %no_exit.i1 ], [ getelementptr
> ([13 x sbyte]* %.str_1, long 0, long 0), %entry ]
>                  ; <sbyte*> [#uses=2]
>          %inc.i = getelementptr sbyte* %Str.0.i, long 1          ;
> <sbyte*> [#uses=2]
>          %tmp.7.i = load sbyte* %Str.0.i         ; <sbyte> [#uses=1]
>          %tmp.8.i = cast sbyte %tmp.7.i to int           ; <int> [#uses=1]
>          %tmp.5.i = call int %putchar( int %tmp.8.i )            ; <int>
> [#uses=0]
>          %tmp.2.i = load sbyte* %inc.i           ; <sbyte> [#uses=1]
>          %tmp.3.i = setne sbyte %tmp.2.i, 0              ; <bool> [#uses=1]
>          br bool %tmp.3.i, label %no_exit.i1, label %loopexit.i
>
> loopexit.i:             ; preds = %no_exit.i1
>          %tmp.9.i = call int %putchar( int 10 )          ; <int> [#uses=0]
>          ret int 0
> }
>
> declare int %putchar(int)
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

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




More information about the llvm-dev mailing list