[cfe-dev] Remove unused types from ASTContext

mateusz janek via cfe-dev cfe-dev at lists.llvm.org
Sun Apr 30 13:12:48 PDT 2017


Sorry for no response, I was quite busy.

Thanks Brian for help with the build (: Also I've tried with the g++-6 and
it has same problem with the memory usage.

The problem here is caused by creating a lot of template class
specializations. As Mats partially said and I found in the llvm sources
here: https://github.com/stryku/llvm/blob/master/include/llvm/IR/Type.h#L42
types
are stored till the end of program life. AFAIU every class specialization
is a separate type.

Simpler program that shows my problem is e.g.
https://gist.github.com/stryku/986bcd6a5d5773ef0e0136a5eca97e20
There is a lot of specializations of values_container,
create_container, create_impl
etc. Additionally every values_container have a lot of template parameters
which in fact are also types (built-in types, but still).

For now, I'm playing with llvm and clang sources to understand what's going
on there and I'll probably try to implement my own mechanism of storing a
template class specializations.

Thanks for your interest,
Stryku



2017-04-29 0:02 GMT+02:00 Brian Cain <brian.cain at gmail.com>:

>
> On Fri, Apr 28, 2017 at 6:11 AM, mateusz janek <stryku2393 at gmail.com>
> wrote:
>
>> Did you use CMake? If no, ctai requres clang 4.0 and to be compiled with
>> flags: `-std=c++1z -ftemplate-backtrace-limit=0 -ftemplate-depth=8096`
>>
>>
> I got it to work with some tweaks to the CMake config.  It ran quickly for
> me, but it did allocate a decent amount of memory on the way.  Also I used
> a nightly build of clang and libc++ (and not libstdc++).
>
> 15.85user 0.48system 0:16.38elapsed 99%CPU (0avgtext+0avgdata
> 4053852maxresident)k
> 0inputs+24outputs (0major+381214minor)pagefaults 0swaps
>
>
>
> diff:
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 0143461..109d975 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -1,9 +1,9 @@
>  cmake_minimum_required(VERSION 3.5)
>  project(ctai)
>
> -add_definitions(-std=c++1z -ftemplate-backtrace-limit=0
> -ftemplate-depth=1024)
> -
> -set(CMAKE_CXX_COMPILER clang++-3.9)
> +set(CMAKE_CXX_COMPILER clang++-3.9 CACHE STRING "")
> +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -stdlib=libc++
> -ftemplate-backtrace-limit=0 -ftemplate-depth=8192" CACHE STRING "" FORCE)
> +set(CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS} "-std=c++1z
> -stdlib=libc++" CACHE STRING "" FORCE)
>
>  set(INCLUDE_FILES
>          register.hpp
> diff --git a/main.cpp b/main.cpp
> index b95eb4d..35e6d6f 100644
> --- a/main.cpp
> +++ b/main.cpp
> @@ -30,6 +30,66 @@ using code = decltype(
>      "mov ebx , 1 "
>      "add eax , ebx "
>      "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
> +    "mov DWORD PTR [ ebp + 4 ] , eax "
>      "jmp .loop_label "
>  ":end_label "
>      "mov eax , DWORD PTR [ ebp + 16 ] "
> @@ -39,4 +99,4 @@ int main()
>  {
>      std::cout << "15th element of fibonacci series is: " <<
> cai::execute_code<code>;
>      return 0;
> -}
> \ No newline at end of file
> +}
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170430/9b7e50a2/attachment.html>


More information about the cfe-dev mailing list