Free memory used by initializers of global variables, created during linking

Manman Ren mren at
Wed Jan 14 11:58:16 PST 2015

> On Jan 9, 2015, at 3:13 PM, Rafael EspĂ­ndola <rafael.espindola at> wrote:
>> CAZConstants, CPNConstants and UVConstants are special constants (AggregateZero, PointerNull, UndefValue), it is likely that they will occupy a small amount of space and will be used quite often.
>> Same arguments apply to IntConstants and FPConstants.
>> But for completeness, we can include them.
> Thanks. The main intention is to make sure that any code that calls
> this while holding a Constant pointer will noticed the problem
> quickly.

Done except IntConstants and FPConstants (we currently do not have destroyConstant methods for ConstantInt and ConstantFP).
It should be easy to add those methods, let me know what you prefer.

>> InlineAsm is not a subclass of Constant.
> True. It is a bit odd that it is also uniqued at the Context. We can
> just skip it.
>>> * Deleting a constant can cause other constants to become dead. Should
>>> we iterate until no constants are deleted in a pass?
>> Theoretically yes, deleting a constant can cause other constants used by it, to be dead.


Updated patch is attached.

For the application I am working on, ld now runs for 12 minutes with the attached patch; If we do not release memory for ConstantExprs, ld will run for 10 minutes.
The average # of iterations when releasing memory is 2.7 when we include ConstantExprs. The memory footprint is about the same, peak at 6.4GB.

One idea is to give finer control over what constant stores to release.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: append_gv3.patch
Type: application/octet-stream
Size: 4267 bytes
Desc: not available
URL: <>
-------------- next part --------------

> Cheers,
> Rafael

More information about the llvm-commits mailing list