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

Manman Ren mren at apple.com
Mon Jan 19 11:25:45 PST 2015


Thanks Rafael and Duncan.

Updated patch is attached. It adds
+  /// Destroy ConstantArrays in LLVMContext if they are not used.
+  /// ConstantArrays constructed during linking can cause quadratic memory
+  /// explosion. Releasing all unused constants can cause a 20% LTO compile-time
+  /// slowdown for a large application.
+  /// NOTE: Constants are currently owned by LLVMContext. This can then only
+  /// be called where all uses of the LLVMContext are understood.
+  void dropTriviallyDeadConstantArrays();


> On Jan 16, 2015, at 6:17 PM, Rafael Espíndola <rafael.espindola at gmail.com> wrote:
> 
>> A 20% slowdown seems excessive.  Do I understand correctly that if you
>> don't delete unused `ConstantExpr`s there's no real slowdown?

Without deleting “ConstantExprs”, the run time is 10 minutes, and it reduces the memory footprint from 22GB to 6GB.
If we delete unused “ConstantExprs”, the run time is 12 minutes, the memory footprint is about the same.

Thanks,
Manman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: append_gv4.patch
Type: application/octet-stream
Size: 2611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150119/f2080da8/attachment.obj>
-------------- next part --------------

>> 
>> Realistically I don't expect `ModuleLinking` to create many surplus
>> `ConstantExpr`s.  Those referencing `GlobalValue`s from deleted modules
>> get destroyed when the `GlobalValue`s die, and otherwise most constants
>> probably get merged in anyway.  I'd prefer to leave that out and avoid
>> the slowdown.
>> 
>> (I'm tempted even to narrow the scope just to `ConstantArray`s, since the
>> only quadratic memory explosion is on arrays with appending linkage.)
>> 
>> Rafael, what do you think?
> 
> Yes, that is probably fine. Sorry for leading you down this path. Just
> include a comment about the cost and your remark about the quadratic
> explosion.
> 
> Once we change constant ownership we can refactor the linker to not
> copy dead constants and keep track of any constants it might delete on
> the target.
> 
> Cheers,
> Rafael



More information about the llvm-commits mailing list