Skip to content

Commit aafefcb

Browse files
committed
OP_AELEMFASTLEX_STORE - combined sassign/aelemfast_lex
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.
1 parent ec18fac commit aafefcb

File tree

12 files changed

+451
-282
lines changed

12 files changed

+451
-282
lines changed

ext/Opcode/Opcode.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ invert_opset function.
305305
rv2sv sassign padsv_store
306306
307307
rv2av aassign aelem aelemfast aelemfast_lex aslice kvaslice
308-
av2arylen
308+
av2arylen aelemfastlex_store
309309
310310
rv2hv helem hslice kvhslice each values keys exists delete
311311
aeach akeys avalues multideref argelem argdefelem argcheck

lib/B/Deparse.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4305,6 +4305,17 @@ sub pp_gv {
43054305
return $self->maybe_qualify("", $self->gv_name($gv));
43064306
}
43074307

4308+
sub pp_aelemfastlex_store {
4309+
my $self = shift;
4310+
my($op, $cx) = @_;
4311+
my $name = $self->padname($op->targ);
4312+
$name =~ s/^@/\$/;
4313+
my $i = $op->private;
4314+
$i -= 256 if $i > 127;
4315+
my $val = $self->deparse($op->first, 7);
4316+
return $self->maybe_parens("${name}[$i] = $val", $cx, 7);
4317+
}
4318+
43084319
sub pp_aelemfast_lex {
43094320
my $self = shift;
43104321
my($op, $cx) = @_;

lib/B/Op_private.pm

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opcode.h

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)