summaryrefslogtreecommitdiff
path: root/peep.c
Commit message (Collapse)AuthorAgeFilesLines
* peep.c - ensure deferred_queue is initialized before useYves Orton2023-03-291-1/+1
| | | | | HPUX was warning that it can be used before it is initialized. There is no cost to nulling it out early so do so.
* Correct typos as per GH 20435James E Keenan2022-12-291-3/+3
| | | | | | | | | | | | | | | | | | | In GH 20435 many typos in our C code were corrected. However, this pull request was not applied to blead and developed merge conflicts. I extracted diffs for the individual modified files and applied them with 'git apply', excepting four files where patch conflicts were reported. Those files were: handy.h locale.c regcomp.c toke.c We can handle these in a subsequent commit. Also, had to run these two programs to keep 'make test_porting' happy: $ ./perl -Ilib regen/uconfig_h.pl $ ./perl -Ilib regen/regcomp.pl regnodes.h
* peep.c - add a comment/question to a commentYves Orton2022-11-011-1/+5
| | | | | | | We optimize away certain nextstate ops, but it isn't clear if it is possible for the ops to be there to switch hints or feature flags. Tony thinks its fine however. So I have added the commentary to the comment for future readers.
* OP_EMPTYAVHV - optimized empty ANONLIST/ANONHASHRichard Leach2022-10-241-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | | This commit introduces a new OP to replace cases of OP_ANONLIST and OP_ANONHASH where there are zero elements, which is very common in Perl code. As an example, `my $x = {}` is currently implemented like this: ... 6 <2> sassign vKS/2 ->7 4 <@> anonhash sK* ->5 3 <0> pushmark s ->4 5 <0> padsv[$x:1,2] sRM*/LVINTRO ->6 The pushmark serves no meaningful purpose when there are zero elements and the anonhash, besides undoing the pushmark, performs work that is unnecessary for this special case. The peephole optimizer, which also checks for applicability of a related TARGMY optimization, transforms this example into: ... - <1> ex-sassign vKS/2 ->4 3 <@> emptyavhv[$x:1,2] vK*/LVINTRO,ANONHASH,TARGMY ->4 - <0> ex-pushmark s ->3 - <0> ex-padsv sRM*/LVINTRO ->-
* AELEMFASTLEX_STORE - support negative keys, skip unnecessary checkRichard Leach2022-10-221-2/+1
| | | | | | | | This commit: * Adds support for negative keys, as per the original AELEMFAST_LEX * Changes an if() check for a "useless assignment to a temporary" into an assert, since this condition should never be true when the LHS is the result of an array fetch.
* OP_AELEMFASTLEX_STORE - combined sassign/aelemfast_lexRichard Leach2022-09-071-0/+49
| | | | | | | | | | | | | | | | | | | | | | This commit introduces a new OP to replace simple cases of OP_SASSIGN and OP_AELEMFAST_LEX. (Similar concept to GH #19943) For example, `my @ary; $ary[0] = "boo"` is currently implemented as: 7 <2> sassign vKS/2 ->8 5 <$> const[PV "boo"] s ->6 - <1> ex-aelem sKRM*/2 ->7 6 <0> aelemfast_lex[@ary:1,2] sRM ->7 - <0> ex-const s ->- But now will be turned into: 6 <1> aelemfastlex_store[@ary:1,2] vKS ->7 5 <$> const(PV "boo") s ->6 - <1> ex-aelem sKRM*/2 ->6 - <0> ex-aelemfast_lex sRM ->6 - <0> ex-const s ->- This is intended to be a transparent performance optimization. It should be applicable for RHS optrees of varying complexity.
* peep.c:OP_PADSV_STORE - skip SASSIGN created by Memoize::OnceRichard Leach2022-09-061-1/+5
| | | | | | | Memoize::Once produces a non-standard SASSIGN which should not and need not be optimized. Because this SASSIGN has only one child, something that hasn't been seen elsewhere, that can be used as a heuristic for skipping this type of SASSIGN in rpeep().
* Add OPpTARGET_MY optimization to OP_UNDEFRichard Leach2022-08-251-0/+52
| | | | | | | | | | | | | | | | | | | | | | | | This allows the existing `undef` OP to act on a pad SV. The following two cases are optimized: `undef my $x`, currently implemented as: 4 <1> undef vK/1 ->5 3 <0> padsv[$x:1,2] sRM/LVINTRO ->4 `my $a = undef`, currently implemented as: 5 <2> sassign vKS/2 ->6 3 <0> undef s ->4 4 <0> padsv[$x:1,2] sRM*/LVINTRO ->5 These are now just represented as: 3 <1> undef[$x:1,2] vK/SOMEFLAGS ->4 Note: The two cases are not quite functionally identical, as `$x = undef` clears the SV flags but preserves any PV allocation for later reuse, whereas `undef $x` does free any PV allocation. This behaviour difference is preserved through use of the OPpUNDEF_KEEP_PV flag.
* rpeep: don't apply padsv_store and padrange togetherRichard Leach2022-08-231-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | As originally committed, the OP_PADSV_STORE optimization interacted negatively with OP_PADRANGE: 1. The new rpeep code was buggy, as it assumed that oldop must be the targ PADSV, when it could have been a padrange. In the first case, updating `oldoldop->op_next = o` is correct, in the second case the op_next chain must be left as-is. That was easily fixable. 2. There was some problem with stack book-keeping - probably of the mark stack. The following test case continued to fail even after the rpeep code had been fixed: my $x = {}; my $y; print keys %{$y = $x}; However, since both OP_PADSV_STORE and OP_PADRANGE optimize by taking the targ PADSV out of the op_next chain, it was apparent that there is reduced gain from having both optimizations applied to the same optree. Therefore, the simple fix applied by this commit is to modify peep(), such that the OP_PADSV_STORE optimization is not applied when OP_PADRANGE has already been applied. Existing tests did not pick up the problems, which were identified via Blead-Breaks-CPAN reports. Additional tests have thus been included.
* Add extra scope block for switch case (fix g++)Bram2022-08-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Code in 9fdd7fc4796d89d16dceea42f2af91e4fde296ed broke the g++ builds, Basically after the commit the code looked like: switch (o->op_type) { ... case OP_SASSIGN: ... OP* rhs = cBINOPx(o)->op_first; OP* lval = cBINOPx(o)->op_last; ... break; case OP_AASSIGN: { g++ does not allow this and errors with: peep.c:3897:14: error: jump to case label 3897 | case OP_AASSIGN: { | ^~~~~~~~~~ peep.c:3844:17: note: crosses initialization of 'OP* lval' 3844 | OP* lval = cBINOPx(o)->op_last; | ^~~~ peep.c:3843:17: note: crosses initialization of 'OP* rhs' 3843 | OP* rhs = cBINOPx(o)->op_first; | ^~~ This happens because `rhs` and `lval` are not scoped in the case statement so it could fall through to the next case. The solution is to scope them which this commit now does by adding a separate scope for `OP_SASSIGN` (similar to `OP_AASSIGN`). Fixes #20108
* Implement OP_PADSV_STORE - combined sassign/padsv OPRichard Leach2022-08-171-0/+52
| | | | | | | | | | | | | | | | | | | | | This commit introduces a new OP to replace simple cases of OP_SASSIGN and OP_PADSV. For example, 'my $x = 1' is currently implemented as: 1 <;> nextstate(main 1 -e:1) v:{ 2 <$> const(IV 1) s 3 <0> padsv[$x:1,2] sRM*/LVINTRO 4 <2> sassign vKS/2 But now will be turned into: 1 <;> nextstate(main 1 -e:1) v:{ 2 <$> const(IV 1) s 3 <1> padsv_store[$x:1,2] vKMS/LVINTRO This intended to be a transparent performance optimization. It should be applicable for RHS optrees of varying complexity.
* Use the cUNOPx-family of macros instead of manual (UNOP*) castingPaul "LeoNerd" Evans2022-08-151-3/+3
|
* Use the cLOGOPx-family of macros instead of manual (LOGOP*) castingPaul "LeoNerd" Evans2022-08-151-1/+1
|
* Use the cBINOPx-family of macros instead of manual (BINOP*) castingPaul "LeoNerd" Evans2022-08-151-3/+3
|
* Use the cLISTOPx-family of macros instead of manual (LISTOP*) castingPaul "LeoNerd" Evans2022-08-151-8/+8
|
* Use the cSVOPx-family of macros instead of manual (SVOP*) castingPaul "LeoNerd" Evans2022-08-151-2/+2
|
* Define the remaining convenience cMETHOP* macrosPaul "LeoNerd" Evans2022-08-031-1/+1
| | | | | | | | | | | Several of these were missing: cMETHOP, cMETHOPo, kMETHOP Also, the field-accessing ones: cMETHOP_meth cMETHOP_rclass cMETHOPo_meth cMETHOPo_rclass This commit adds them all, and use them to neaten other code where appropriate.
* prevent undefined behaviour in S_maybe_multideref()Tony Cook2022-07-181-22/+23
| | | | | | | | | | | The first pass that calculated the size of the required structure started with a NULL pointer, and incremented that pointer as the space needed for the multideref sequence was accumulated. This pointer math (adding to a non-object pointer) is undefined behaviour in C, even if the pointer is not de-referenced. Changed to use an integer index instead.
* Adjust comments in op.c and peep.c about the files' contentsPaul "LeoNerd" Evans2022-06-201-0/+4
|
* Add (C) declaration and an opening quote to peep.cPaul "LeoNerd" Evans2022-06-201-0/+19
|
* Split optree optimizer and finalizer from op.c into new peep.cPaul "LeoNerd" Evans2022-06-201-0/+3983
* Create a new `peep.c` file * Move the functions related to optree optimisation and finalisation out of `op.c` into this new file * Several previously-static functions now have to be non-static and declared as internal API in order to be shared between these two files.