
On Tue, Sep 8, 2009 at 3:51 AM, troy d. straszheim<troy@resophonic.com> wrote:
David Abrahams wrote:
on Tue Sep 08 2009, Vicente Botet Escriba <vicente.botet-AT-wanadoo.fr> wrote:
Do you have a specific pointer for CLang related to this usage?
Nope, this is hearsay. Doug?
If I remember Doug's explanation correctly, one of the optimizations inside clang is: There is a global table of 'plain' types, e.g. int, bool, float, std::string. Clang internally represents CV qualified types by e.g. creating a pointer to the type 'int', then using the small bits of the pointer to tag const and volatile. I don't recall whether they used more than two bits (for, say reference, static, pointer, etc.) Sebastian Redl gave a great intro to clang @ boostcon, I'd bet he knows the details as well.
Clang's QualType smart pointer uses three bits, for const, volatile, and restrict, so we have to force 8-byte alignment when we allocate Type structures. There's a tiny bit of explanation of this part of the type system here: http://clang.llvm.org/docs/InternalsManual.html#QualType The actual QualType class is here: https://llvm.org/svn/llvm-project/cfe/trunk/include/clang/AST/Type.h We use this bit-mangling trick a *lot* in Clang. The general infrastructure is "PointerIntPair", which is what it says it is: a pointer and an integer mangled together, with accessors for each. The code is here: https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/ADT/PointerIntPair... We build most of our bit-mangled structures on top of PointerIntPair or PointerUnion, a union of two (distinct) pointer types: https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/ADT/PointerUnion.h - Doug