Re: [RFC PATCH] pre-process: add __VA_OPT__ support

Al Viro <[email protected]> Thu, 26 Feb 2026 07:29:45 +0000
Newsgroups org.kernel.vger.linux-sparse
Message-ID <20260226072945.GA4104757@ZenIV>
On Wed, Feb 25, 2026 at 10:18:51PM +0000, Al Viro wrote:

> NOTE: substitute() is the second hottest loop in the entire thing; only
> tokenizer is hotter.  And gcc is too enthusiastic about the inlining
> around that function, ending up with bad register spills, along with
> a bunch of stalls.  Worse, decisions are sensitive to minor changes in
> places textually far away, making it a real bitch to deal with.
> Makes for fun reordering the commits in local queue... ;-/

FWIW, looking at that thing again, I wonder if we would be better off
with doing argument expansion on demand rather than doing it in
expand_arguments().  Should be doable with a bit of care - we'd need
to mark the TOKEN_..._ARG with several bits to decide whether we
want to duplicate or not, etc., but that's worth doing anyway -
better than playing with the counters.

Note, BTW, that collapsing TOKEN_..._ARG together, with "kind of argument"
moved into bits stolen from ->argnum improves code generation - that
switch by token type is _hot_ and it reducing the number of cases
gives a measurable speedup.  Sure, we don't want heavy work at #define
time - most of the macros are never expanded at all, but AFAICS this
kind of processing can be dealt with while parsing the body, with no
extra passes needed, etc.

I'm going down right now, will look into that tomorrow morning...