op.c: Correct comment added by c427f4d2d
op.c: cmmoent typo
perldiag: Correct ‘Can't use %s for loop variable’

It is no longer true that the variable can only be a simple scalar.
More to the point, this message should never be reached.  If you try
to use something prohibited as your loop variable, you get a syntax
error or ‘Missing $’.
readd noreturn and silence "noreturn that returns" warning on MSVC

Based on commit 73758d77 (by me), in commit 117af67d629 more things got
noreturn removed on MSVC. See also ML post
"(Hugmeir) Re: [perl.git] branch blead, updated. v5.21.0-377-gdc3bf40"
This caused a measurable increase in machine code size in 117af67d629 .
In commit 73758d77 , the reason there was no increase is
Perl_magic_regdatum_set is called only through a magic vtable. Optimizing
this to noreturn is forbidden unless the struct member type specifies it
(and it obviously doesn't, since this is the magic vtable).

The other not-noreturn on MSVC function, Perl_screaminstr, has no core
usage (its only reference is in the export table) or CPAN grep usage so
therefore it is being removed. It was made fatal in commit 9e3f0d16db .

before .text section of perl521.dll on VC 2003 32b, 0xc66a3 bytes, after
0xc6453
misc optimizing in DynaLoader

dl_last_error is "#define dl_last_error	(SvPVX(MY_CXT.x_dl_last_error))"
since the data is already in a SV *, use newSVsv instead of turning it into
a strlen-ed (eventually) char *.

-win32 dl_load_file never uses flags, so don't do a SvIV in void context
- dl_load_file cant use "flags=NULL" because of test
"calling DynaLoader::dl_load_file() with no argument" in DynaLoader.t
-OS_Error_String stop repeatedly computing address into MY_CXT and
 derefing after PerlProc_GetOSError

function sizes in machine code bytes on VC 2003
b4 0x69 OS_Error_String af 0x67
b4 0x9D _XS_DynaLoader_dl_error af 0x6B
b4 0x108 _XS_DynaLoader_dl_load_file af 0xD6
tweak PERL_TRACE_OPS for usability, use it.

Currently with -DPERL_TRACE_OPS builds, a table of OP dispatches per
optype is always printed in perl_destruct().  Since this also affects
miniperl, it makes both make & make test exceedingly noisy, and might
interfere with passing make test (I never waited til completion).

Although such builds arent meant for production, we can still make
them more usable; gate the printing with PL_debug to make it quiet by
default (-Dq -Dv -D0 options will all enable it).  Also dont print 0
values, which dramatically reduces output for simple one-liner
scripts.

So, patch does following:

interpvar.h: add PL_op_histo[PERL_TRACE_OPS_EXT] to create a 2nd set
of experimental/scratchpad counters (default size 48)

perl.c:perl_destruct: check PL_debug before printing PL_op_exec_cnt[]
and PL_op_histo[] counts, and skip printing 0 values in both.
PL_op_histo[] counts with "extra.%d" (vs OP_NAME with op_exec_cnt).
Also precede printed lines with "#:" to make it play nice with TAP and
to convey a JSON-ish name-value pair, and surround them with "#{" and
"#}" to envelop the results.

Define 2 macros; PERL_TRACE_OPS_INC, PERL_TRACE_OPS_HIT, to hide the
current #ifdeffery around counting uses.  Use them to show the
distribution of most of the OP->op_*flags* in exectuted-ops, and some
logical relations amongst them.

 - op-execs per optype
   (legacy example, now commented out to focus on ops-flags below)
 - total op-execs (OP_max+1, displays as CONSTRUCT)

 - ops w/wo op_opt		(extra 0,1)
 - ops w/wo op_slabbed		(extra 2,3)
 - ops w/wo op_static		(extra 4,5)
 - ops w/wo op_savefree		(extra 6,7)
 - ops w/wo op_folded		(extra 8,9)
 - ops w/wo op_folded		(extra 10,11)

 - ops w/wo (PL_op->op_ppaddr == PL_ppaddr[PL_op->op_type])	(extra 12,13)
   ie the postcondition cited in 10884df967

 - ops w &&,||,== relops between op_opt, op_slabbed		(extra 14-19)
 - others included, more discovery needed.			(extra 20-27)

With this patch, we get (with manual indenting of commit msg):

$ ./perl -Ilib -Dv ext/arybase/t/splice.t
 1..23
 ok 1
 ...
 ok 23
 #{ Trace of all OPs executed:
 #:  freed: 114745
 #:  CONSTRUCT: 114745
 #:  extra.0: 547
 #:  extra.1: 114198
 #:  extra.2: 2
 #:  extra.3: 114743
 #:  extra.4: 114745
 #:  extra.6: 114689
 #:  extra.7: 56
 #:  extra.8: 113725
 #:  extra.9: 1020
 #:  extra.10: 62682
 #:  extra.11: 52063
 #:  extra.12: 13
 #:  extra.13: 114732
 #:  extra.14: 545
 #:  extra.15: 114200
 #:  extra.16: 547
 #:  extra.17: 114198
 #:  extra.18: 2
 #:  extra.19: 114743
 #:  extra.20: 2
 #:  extra.21: 114743
 #:  extra.22: 114689
 #:  extra.23: 56
 #:  extra.24: 113669
 #:  extra.25: 1076
 #:  extra.26: 63586
 #:  extra.27: 51159
 #}
op.c: regularize OP_AELEMFAST_LEX vs OP_AELEMFAST setup.

commit 10884df96723d4 promoted CHANGE_TYPE as the "normal" way to
initialize op_type and op_ppaddr fields.  This suggests that
Perl_rpeep()s tweaking of OP_AELEMFAST and OP_AELEMFAST_LEX is
something of a special case.

It turns out that these are pretty normal too; since regen/opcode.pl
insures that PL_ppaddr[OP_AELEMFAST_LEX] == PL_ppaddr[OP_AELEMFAST],
the invariant: o->op_ppaddr == PL_ppaddr[o->op_type] holds after both
the OP_AELEMFAST and OP_AELEMFAST_LEX branches, and the stronger
semantics of CHANGE_TYPE() can be used to communicate this normality.

On a gcc x86-64 -DEBUGGING build, this enlarges 'size op.o' by 16
bytes, but before and after 'objdump -DS op.o' output suggests that
the code itself is identical.
op.c: CHANGE_TYPE for op_integerize and ck_spair

These 2 users do the ++o->op_type trick to modify the OP to its
optimized doppelganger.  But CHANGE_TYPE()s postcondition holds:
o->op_ppaddr = PL_ppaddr[o->op_type], so using it conveys this.
Also fix CHANGE_TYPE(o, ++type) expansion problem with an autovar
inside the "braces".
hoist CHANGE_TYPE to op.h from op.c, use in perl.c

hoist CHANGE_TYPE into op.h so its available to perl.c and others, use
it in perl.c  Also add braces around arg for robustness.
define OP_IS_PATCHED and OP_IS_UNPATCHED, use them.

these macros put names to a useful property of OPs, ie:
  (PL_op->op_ppaddr == PL_ppaddr[PL_op->op_type])

Use them in op.c:Perl_op_free,

macro-in-op.c
start reworking op_ppaddr

op->op_ppaddr is basically a cached copy of PL_ppaddr[op->op_type]
dispatch-table entry.  Its real purpose however is to support
patching/customizing OPs (as is done by ext/arybase when $[ is
diddled, see b82b06b8).

Use of this OP-patching facility is however statistically exceedingly
rare.  Basically, on modern processors, we could be optimized for the
wrong thing, and should be shrinking the OPtree instead.  OTOH, we
could just thrash the cache harder on load-slicing boundaries.  Point
is we have no idea.

To test this, add a %patched_ops to interpreter, populate it in
Perl_linklist and mark op->op_patched (still op->op_spare for now)
when OP_IS_PATCHED(op) says so.

Once its possible (WIP) to actually drop the op_ppaddr field (perhaps
-DPERL_NO_PPADDR), we can devise some experiments to tease out the
performance effects.

The patch does as follows:

- add %patched_ops to interpvar.  I used ptr-tables somewhat
  arbitrarily (HV <-> pointer nested-convert-macro phobia), and
  probly bugs lurk in lack of cloning, but its a line-in-the-sand.

- in Perl_linklist, use OP_IS_PATCHED to mark OPs (o->op_spare = 1,
  rename op_patched later), and store op_ppaddr to %patchedpp.  This
  appears to catch all in-core cases, particularly b82b06b8.

- in runloops, check o->op_spare, and fetch $patchpp{$op} when needed.
  hopefully a bit-test is cheap enough as to be unmeasurable.

NOTES:

Devel::Cover is likely the highest profile and most sophisticated user
of op_ppaddr, its worth considering wrt viability of this patchset.
DC has 2 OP-related techniques to apply:

- change PL_ppaddr[] entries to affect all OPs of that type (likely
  used for NEXTSTATE etc to take real control).
- change OP->op_ppaddr on per-OP basis.

These 2 techniques are available both before and after this patchset,
so modulo version branches, this is feasible in principle.  Managing
%patched_ops has extra overhead vs patching op_ppaddr, but toggling
op->op_spare is just as quick.

TODO:

finish %patched_ops rename

develop a good benchmarking scenario. (ya, just like that ;-)
- need make test under perf
- perlbench - real runtimes, less overhead than core tests.

build a branch with extra op_junk pointer in OP, benchmark it to get
costs (cache, footprint) of extra pointer, and infer from that
(caveats apply) the savings by eliminating op_ppaddr.

collect and analyse a lot of data.
missing patched might be causing extra failures, lessee
reset spare in CHANGE_TYPE, for op reuse
run-likely