[LLVMdev] Removing unused global constant

Christophe Duvernois christophe.duvernois at gmail.com
Tue Nov 20 13:08:45 PST 2012


Hi

I create a simple bytecode file with clang -c -emit-llvm test.c -o test.bc

#include <stdio.h>
void hello(){
        printf("hello\n");
}
void hello2(){
        printf("hello2\n");
}

Then i want to keep only the hello function so i do :

llvm-extract -func=hello -o test2.bc test.bc

but the string constants are removed and "@.str" is marked as external
@str = external hidden unnamed_addr constant [6 x i8]

How do you keep the global constant that are used in a function ?

I tried to keep all the .str* with
llvm-extract -func=hello -rglob=.str* -o toto2.bc toto.bc

The two string are available in the module :
@.str = private unnamed_addr constant [7 x i8] c"hello\0A\00", align 1
@.str1 = private unnamed_addr constant [8 x i8] c"hello2\0A\00", align 1

Then i run opt with a global dead code elimination
opt -globaldce test2.bc -o test3.bc

I still have the two string. ".str1" is not used anymore and shoud have
been removed?
Why @.str1 is not removed? Which pass can do that?

Thanks for your clarification.
Christophe.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121120/395e9314/attachment.html>


More information about the llvm-dev mailing list