C++ Logo

std-proposals

Advanced search

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

From: Ehsan Amiri <ehsan.amiri_at_[hidden]>
Date: Fri, 10 Jan 2025 15:16:14 +0000
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


Received on 2025-01-10 15:16:22