This is an archive of the discontinued LLVM Phabricator instance.

[LazyValueInfo] Reduce memory usage
ClosedPublic

Authored by ahatanak on Dec 9 2015, 12:02 PM.

Details

Summary

When the lattice value of a value is overdefined, LazyValueInfoCache inserts the lattice value into LazyValueInfoCache::ValueCache in addition to inserting it into OverDefinedCache. This isn't necessary and causes LazyValueInfo to use an excessive amount of memory in some cases.

This patch attempts to reduce memory usage of LazyValueInfo by avoiding inserting entries into LazyValueInfoCache::ValueCache when the lattice value type is overdefined. The memory usage decreases by 70 to 75% (from 1.5GB to 400MB) when I build one of the files in llvm.

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak updated this revision to Diff 42325.Dec 9 2015, 12:02 PM
ahatanak retitled this revision from to [LazyValueInfo] Reduce memory usage.
ahatanak updated this object.
ahatanak added a subscriber: llvm-commits.

Hi Akira,

Thanks for working on this! The numbers look impressive.

I didn't really look into the patch but wonder if you can elaborate a little more on the issue.
When the lattice value of a value is overdefined, LazyValueInfoCache inserts the lattice value into LazyValueInfoCache::ValueCache in addition to inserting it into OverDefinedCache. This isn't necessary and causes LazyValueInfo to use an excessive amount of memory in some cases.
--> Is it possible to give a simple example where LazyValueInfo uses an excessive amount of memory?
--> Maybe a testing case?

Cheers,
Manman

--> Is it possible to give a simple example where LazyValueInfo uses an excessive amount of memory?

LazyValueInfoCache is inserting a large number of overdefined lattice values into ValueCache when the test case I have is compiled with opt. This is the stats I have:

4 - inserted lattice const
873 - inserted lattice constrange
280419 - inserted lattice nonconst
38308250 - inserted lattice overdefined

So 99% of the entries in ValueCache are overdefined. However, it isn't necessary to write overdefined values into ValueCache because OverDefinedCache keeps track of which values are overdefined in which basic blocks and, unlike const or constrange, overdefined doesn't need any of the information in LVILatticeVal (Val and Range).

I don't have a simple explanation as to why I'm seeing this behavior when I compile the particular test case yet.

--> Maybe a testing case?

The test case I have is a preprocessed file of lib/ARCMigrate/Transforms.cpp (from an internal branch of clang) from 2012. I'll see if I can come up with the exact command that exhibits the same behavior.

I tried compiling Transforms.cpp of r152020, but unfortunately clang (r255133) didn't exhibit an excessive memory usage (perhaps because some of the header files changed).

It seems that a large number of values are inserted into ValueCache because of the way LazyValueInfoCache gets the lattice value for a (basic block, value) pair. When LazyValueInfoCache needs a lattice value, it recursively visits the basic block's predecessors (it emulates recursion using a stack) until it gets an answer and inserts lattice values for all basic blocks that were visited.

hfinkel accepted this revision.Dec 10 2015, 2:21 AM
hfinkel added a reviewer: hfinkel.
hfinkel added a subscriber: hfinkel.

LGTM.

lib/Analysis/LazyValueInfo.cpp
368 ↗(On Diff #42325)

We should add a comment somewhere, maybe here, explaining that we insert overdefined values into their own cache to reduce memory overhead.

This revision is now accepted and ready to land.Dec 10 2015, 2:21 AM
ahatanak updated this revision to Diff 42485.Dec 10 2015, 4:41 PM
ahatanak edited edge metadata.

Thank you for the review.

I've added comments that explain why overdefined values are recorded in OverDefinedCache.

This revision was automatically updated to reflect the committed changes.