C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Providing information about data structures to the compiler

From: Tony V E <tvaneerd_at_[hidden]>
Date: Sat, 15 Mar 2025 14:37:42 -0400
Stepanov originally hoped that something like concepts would eventually
help with compiler optimizations.

ie if your type is Regular, then the compiler could make assumptions about
copies, temporaries, etc.

Not sure what he was thinking wrt containers.

One that I recently noticed was this common anti-pattern:

for (int i = 0; i < some_fixed_value; i++)
    vec.push_back(something());

the developer probably should have called reserve() before the loop, but
didn't.

If compilers knew more about vector, they could do the reserve for you.



On Fri, Jan 10, 2025 at 10:16 AM Ehsan Amiri via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hello
>
>
>
> Compiler optimizations can benefit from knowledge of properties of data
> structures and algorithms. AFAIK, there is no good mechanism to provide
> this information to the compiler.
>
>
>
> Recent proposals to develop C++ compilers using MLIR [1, 2, 3] mention
> optimizations of standard library data structures as one of the
> motivations. This relies on recognizing what data structure is being used
> (e.g. a vector) and what functionality of each function is (e.g.
> push_back() will add a new element to the underlying array). However many
> projects develop their own data structures that won’t be recognizable this
> way.
>
>
>
> It may make sense to have a mechanism to provide such information to the
> compiler (for example, a class implements a vector-like data structure.
> Certain functions of the class will add/remove elements or reallocate
> memory, etc.). I suspect, concepts, named requirements, or attributes might
> be reasonable starting points to think about this.
>
>
>
> I would appreciate any feedback on this topic. I don’t have any experience
> with C++ standardization, so I keep it short and high level to get some
> feedback first.
>
>
>
> Thanks
>
> Ehsan
>
>
>
> [1] https://www.youtube.com/watch?v=XNOPO3ogdfQ
>
> [2]
> https://llvm.github.io/clangir/Dialect/passes.html#-cir-idiom-recognizer
>
> [3] https://www.youtube.com/watch?v=3gcw-8C9UbA&t=1s
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


-- 
Be seeing you,
Tony

Received on 2025-03-15 18:37:59