Total size of global data

I wrote a pass that attempts to add up the total size of the global
data in a module. Currently, it iterates through all of the global
values and checks their type sizes using TargetData. I have realized
that this is not quite right because global values can point to the
same data in memory (or can at least overlap) as in the case of
constant strings.

Is there an easier way to approach this? It would be great if there
were some simple way to get the total size of global data. If there
is, please point me in the right direction. Otherwise I will need to
do some messy checking for duplicate addresses and overlapping data.

Thanks,
Scott

It's impossible to tell what exactly will get merged until link-time;
also, CodeGen often introduces constant globals. That said, as far as
I know, LLVM doesn't know how to merge constants beyond running the
constmerge pass and emitting globals into sections which can be
merged.

What are you actually trying to do?

-Eli

It's impossible to tell what exactly will get merged until link-time;
also, CodeGen often introduces constant globals.

This is something I had not yet considered. I will take a closer look.

That said, as far as
I know, LLVM doesn't know how to merge constants beyond running the
constmerge pass and emitting globals into sections which can be
merged.

Something is merging constants in my test cases. I do not explicitly
run "constmerge."

What are you actually trying to do?

-Eli

I want to calculate the high water mark of the memory footprint of a
program at run time. I instrument the LLVM IR with calls to my
library, which keeps track of the size of the allocated memory in
scope.

Everything works fine, except the accounting for global allocation is
not quite right because of the constant merging issue.

Scott