[LLVMdev] Remove a GlobalValue and its orphaned references

Vassil Vassilev vvasilev at cern.ch
Mon Feb 10 13:04:26 PST 2014


Hi,
   I need to implement a llvm IR transformation pass, which removes a 
GlobalFunction/GlobalVariable and removes all the dead values, which 
were the *referenced* by the GlobalValue being removed. I.e all the 
orphaned values that were left after the death of the global value.
Eg.
...
@.str = private unnamed_addr constant [2 x i8] c"a\00", align 1
@.str1 = private unnamed_addr constant [2 x i8] c"b\00", align 1
@.str2 = private unnamed_addr constant [2 x i8] c"c\00", align 1
@options = constant [3 x %struct.OptionDef] [%struct.OptionDef { i8* 
getelementptr inbounds ([2 x i8]* @.str, i32 0, i32 0), i32 0, 
%union.anon { i32 3 } }, %struct.OptionDef { i8* getelementptr inbounds 
([2 x i8]* @.str1, i32 0, i32 0), i32 0, %union.anon { i32 4 } }, 
%struct.OptionDef zeroinitializer], align 16

(I need to remove options and ".str" and ".str1", but not ".str2" since 
it wasn't referenced by "options", it should work also with functions).

I think what I want to do is already very close to the GlobalDCEPass, 
only if I could give it a 'starting point'. I realize this is a little 
bit weird use case, but I was wondering is there a pass in llvm that 
could do it?

Many thanks,
Vassil



More information about the llvm-dev mailing list