[cfe-dev] Remove unused types from ASTContext

mats petersson via cfe-dev cfe-dev at lists.llvm.org
Thu Apr 27 01:54:38 PDT 2017


On 27 April 2017 at 03:13, Brian Cain via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> Do other compilers behave similarly in terms if memory consumption for
> your example code?
>
> On Apr 26, 2017 4:20 PM, "mateusz janek via cfe-dev" <
> cfe-dev at lists.llvm.org> wrote:
>
>> Hi,
>>
>> Before I'll begin, I want to say that I don't want to implement below
>> 'feature' in a clang production code. I want to create my own custom build
>> for my own needs.
>>
>> Abstract:
>> I'm developing a hobby project which creates a lot of types in a compile
>> time, in one .cpp file. Really a lot. I tried to compile next version, but
>> it was compiling whole night and took ~30G of memory (16G RAM + swap) and
>> wasn't able to finish. I know that almost all of these types are 'used'
>> only once, they're kind of helpers.
>> Basically what I want to achieve is to decrease memory usage to not need
>> to use the swap, because it increases compilation time a lot.
>>
>> Question:
>> Is there a way to implement a removing no longer used types? E.g.
>>
>> template <typename FooParam>
>> struct Foo
>> {
>>     using FooResult = typename Bar<FooParam>::BarResult;
>> };
>>
>> And I'd want to remove the 'Bar<FooParam>' type from a 'ASTContext'
>> because I know that I won't need it anymore. (then, if there will again
>> occur an initialization of very same 'Bar<FooParam>', I'm ok with that I'll
>> need to create it from the scratch).
>> So basically is there any way to detect if type is still referenced
>> somewhere, so I can remove it if it isn't?
>>
>
You will need ALL types (that are used at all) to be present at semantic
analysis, since types are used to determine for example implicit casts
(float to int, int to float, short to int, int to short - and even if your
type can't be converted, it still needs to be present during that phase).
Since Semantic analysis is done at the end of the compilation of a
translation unit. And of course, types are used during translation from AST
to IR, so need to be (at least somewhat) present during the IR generation
phase too. [And the compiler WILL need to know what `Bar<FooParam>` is to
find `Bar<FooParam>::BarResult`, even if that is then translated to
`size_t` or `int`.

Also, are you sure that it's the number of types that is the real cause of
the problem?

Can you provide a more complete example (preferrably one that compiles, but
does not take "over night", in a few minutes would be good, that
illustrates that it uses a lot more memory than a comparable piece of code
with less types introduced in it).

--
Mats

>
>> I hope I've described my problem well. I know that in fact I'm asking for
>> a explanation how types in clang are related to each other - that's a lot,
>> but I'd really like to learn and understand that (:
>>
>> Thanks in advance for help!
>>
>> Stryku
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170427/ffaa9af1/attachment.html>


More information about the cfe-dev mailing list