[llvm-dev] llvm compile too much memory when i userd global array

Davis, Matthew via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 28 18:02:43 PST 2017

I recently started looking into a similar issue.  What I have found is that during
compilation, clang will store a representation of the initialized array in memory. 
This internal representation is used during codegen to emit the initialized
contents as IR.  I assume this is similar for your case, the static array being
initialized as 0.  The, I assume similar case, that I am investigating is the following:

// test.c: clang -c test.c
int data[1024 * 1024 * 1024] = {1,2,3};
// end of test

To represent the above code in IR, clang will generate an internal SmallVector
that contains 1024*1024*1024 elements.  The first three will be initialized
to 1,2,3 respectively, and the remaining will be 0 elements.  From my
experience looking into the aforementioned case, large initialized arrays ca
produce the behavior that you are seeing.  The main difference between our
cases is that you are representing an initialized array of  non-POD items.


From: mats petersson via llvm-dev
Sent: Monday, November 27, 2017 8:32 AM
> Does it really make a difference what size the array is?
> Debug or release build of clang?
> --
> Mats

> On 27 November 2017 at 08:54, 王小小 via llvm-dev <mailto:llvm-dev at lists.llvm.org> wrote:
>> hi,all
>> when my code like
>> ------------------------------------
>> #include<iostream>
>> #include<string>
>> using namespace std;
>> static string s[1000010];
>> int main()
>> {
>>   return 0;
>> }
>> ------------------------------------
>> And I used clang-5 to compile it, it almost cost 1g memory to compile it.  how can i reduce the memory , if i don't want change the code? 
>> thank you 

More information about the llvm-dev mailing list