[cfe-commits] [patch] Qualifiers refactor
Chris Lattner
clattner at apple.com
Wed Sep 23 09:49:47 PDT 2009
On Sep 23, 2009, at 2:04 AM, John McCall wrote:
> The attached patch refactors how qualifiers are represented in clang.
>
> Currently, QualType uses the bottom three bits of a type pointer to
> represent the const, volatile, and restrict qualifiers. Extended
> qualifiers are represented using an ExtQualType object, which is an
> ordinary node in the type hierarchy --- except that it isn't. Most
> common operations on types have to explicitly check for these
> special qualifier nodes and handle them differently.
>
> This patch changes QualType to store only two qualifiers directly on
> the pointer; the third bit is repurposed to signal whether the
> pointer is a Type or an ExtQuals object (which holds, but is not, a
> Type). This makes it very cheap to decide whether a type carries
> any qualifiers, as well as to compute the unqualified version of a
> type.
>
> Because there are only two remaining bits, it's necessary to store
> 'volatile' on the ExtQuals object, 'const' being ubiquitous and
> 'restrict' being common in certain system headers. This could be
> avoided by using 16-byte alignment on Types, which would be
> extremely straightforward to do under the patch (modulo any possible
> required changes to the allocator, which I haven't investigated).
>
> This patch also audits many of the uses of qualifiers in clang,
> adjusting them to handle arbitrary qualifiers (or be augmentable for
> future qualifiers) when that was reasonably straightforward.
I haven't had a chance to look at the patch yet, but the approach
makes a lot of sense to me.
-Chris
More information about the cfe-commits
mailing list