[LLVMdev] merging globals

Chris Lattner clattner at apple.com
Fri Oct 17 08:25:29 PDT 2008

On Oct 17, 2008, at 7:30 AM, Anton Korobeynikov wrote:

> Hello, Tatu
>> Is that correct? I think it's just something to be aware of.
> Currently we're aggressively merging globals by default. Do you  
> think it
> will be better to provide special flag to control this behavior?

Please no flag.  If we want to fix this problem, lets do it right.  To  
me this consists of some flag on GlobalVariable that says that it is  
'mergable' or something like that.  Then -constmerge would be changed  
to only merge globals with this flag on it, or globals that are  
provably not "address exposed" (which could be modeled by having the  
optimizer set the bit).  We'd also have to change the code generator  
to stop sending these globals into the various sections that the  
linker merges.

It is important to model this so that we don't lose string merging.   
We need to distinguish between the string globals in these two cases:

char x[] = "foo";
char *y = "foo";

Both will end up with a 4 byte string global variable in LLVM IR, but  
only one of those is mergable.


More information about the llvm-dev mailing list