王小小 via llvm-dev
2017-Nov-27 08:54 UTC
[llvm-dev] llvm compile too much memory when i userd global array
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171127/43f61cda/attachment.html>
mats petersson via llvm-dev
2017-Nov-27 16:31 UTC
[llvm-dev] llvm compile too much memory when i userd global array
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 <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 > > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171127/280b7745/attachment.html>
Davis, Matthew via llvm-dev
2017-Nov-29 02:02 UTC
[llvm-dev] llvm compile too much memory when i userd global array
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. -Matt 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
Reasonably Related Threads
- [LLVMdev] is it impossible to use the external llvm custom pass on windows?
- Storing "blockaddress(@function, %block)" in a global variable?
- 2.2.5 fails to compile - SSL_OP_SINGLE_ECDH_USE : Solaris 10 + Sunstudio 12.3
- 2.2.30.2 fails to compile on centos 7
- samba idmap mystery