[clang] [Clang] Cache DeclContext-to-Decl conversions (NFC) (PR #223042)
Mehdi Amini via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 15 11:20:00 PDT 2026
joker-eph wrote:
The offset bitfield idea is a good one, I threw an agent at evaluating it:
> On x86-64, DeclContext begins at only five offsets from its corresponding Decl: 40, 48, 56, 64, or 72 bytes. Encoding
`(offset - 40) / 8` therefore needs three bits.
>
> Current assertions-off code generation is:
>
> - Baseline: kind load, 79-entry indirect jump table, then one of five adjustments.
> - Eager pointer: one load and return.
> - Tagged offset: load, extract three bits, scale, and subtract—six straight-line instructions with no branch or table
lookup.
>
> LastDecl is appropriate because Decl is guaranteed 8-byte aligned and it has substantially fewer accesses than FirstDecl or LookupPtr. The masking overhead is included in the measurements below.
I also took some measurements (Eager pointer vs Tagged offset)
- RegisterAllDialects instructions −2.78% vs −2.01%
- RegisterAllDialects RSS +0.52% vs effectively flat
- NVVMDialect instructions −1.60% vs −1.17%
- NVVMDialect RSS +0.04% vs effectively flat
- CTMark compile time −1.52% vs −1.46%
- CTMark RSS +0.17% vs no measurable increase
The tagged implementation recovers about 72–73% of the eager instruction reduction on the large MLIR TUs and
essentially all of its CTMark result.
https://github.com/llvm/llvm-project/pull/223042
More information about the cfe-commits
mailing list