[LLVMdev] c const
Ryan M. Lefever
lefever at crhc.uiuc.edu
Wed Aug 8 04:54:04 PDT 2007
Thanks for the help. I'm surprised that llvm doesn't preserve the const
property. I thought that it was supposed to be useful for various
compiler optimizations.
Holger Schurig wrote:
>>How is c's const keyword translated when compiling c into
>>llvm bytecode.
>
>
> It isn't. You can verify this quite simply with the following
> test program:
>
> void a(const void *p)
> {
> }
>
> void b(void *p)
> {
> }
>
>
>
> $ clang --emit-llvm test.c
> ; ModuleID = 'foo'
>
> define void @a(i8* %p) {
> entry:
> %p.addr = alloca i8* ; <i8**> [#uses=1]
> %allocapt = bitcast i32 undef to i32 ; <i32> [#uses=0]
> store i8* %p, i8** %p.addr
> ret void
> }
>
> define void @b(i8* %p) {
> entry:
> %p.addr = alloca i8* ; <i8**> [#uses=1]
> %allocapt = bitcast i32 undef to i32 ; <i32> [#uses=0]
> store i8* %p, i8** %p.addr
> ret void
> }
>
>
>
> Now, I tried this with the gcc 4.0 frontend as well:
>
> $ gcc -c --emit-llvm test.c -o - | llvm-dis -o -
> ; ModuleID = '<stdin>'
> target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
> target triple = "i686-pc-linux-gnu"
>
> define void @a(i8* %p) {
> entry:
> %p_addr = alloca i8* ; <i8**> [#uses=1]
> %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
> store i8* %p, i8** %p_addr
> br label %return
>
> return: ; preds = %entry
> ret void
> }
>
> define void @b(i8* %p) {
> entry:
> %p_addr = alloca i8* ; <i8**> [#uses=1]
> %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
> store i8* %p, i8** %p_addr
> br label %return
>
> return: ; preds = %entry
> ret void
> }
>
>
> As you can see, with both C compilers the generated intermediate language
> is the same for both function a() and b().
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
--
Ryan M. Lefever [http://www.ews.uiuc.edu/~lefever]
More information about the llvm-dev
mailing list