Skip to content

Commit

Permalink
Try to optimize takedispatcher to cleardispatcher.
Browse files Browse the repository at this point in the history
The latter is cheaper and simpler code. In many of the simple ops,
we do not make any kind of call, and thus could never call one of
the defering things (nextsame, etc.)
  • Loading branch information
jnthn committed Jul 5, 2014
1 parent 3756b5b commit ebd3166
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/Perl6/Optimizer.nqp
Expand Up @@ -414,6 +414,9 @@ my class BlockVarOptimizer {
has @!autoslurpy_setups;
has @!autoslurpy_binds;

# The takedispatcher operation.
has $!takedispatcher;

# If lowering is, for some reason, poisoned.
has $!poisoned;

Expand Down Expand Up @@ -449,6 +452,10 @@ my class BlockVarOptimizer {
nqp::push(@!autoslurpy_binds, $node);
}

method register_takedispatcher($node) {
$!takedispatcher := $node;
}

method poison_lowering() { $!poisoned := 1; }

method get_decls() { %!decls }
Expand Down Expand Up @@ -568,6 +575,15 @@ my class BlockVarOptimizer {
}
}

method simplify_takedispatcher() {
unless $!calls {
if $!takedispatcher {
$!takedispatcher.op('cleardispatcher');
$!takedispatcher.shift();
}
}
}

method lexicals_to_locals() {
return 0 if $!poisoned;
for %!decls {
Expand Down Expand Up @@ -841,9 +857,10 @@ class Perl6::Optimizer {
my $vars_info := @!block_var_stack.pop();

# We might be able to delete some of the magical variables when they
# are trivially unused.
# are trivially unused, and also simplify takedispatcher.
$vars_info.delete_unused_magicals($block);
$vars_info.delete_unused_autoslurpy();
$vars_info.simplify_takedispatcher();

# If the block is immediate, we may be able to inline it.
my int $flattened := 0;
Expand Down Expand Up @@ -1031,6 +1048,11 @@ class Perl6::Optimizer {
}
}

# Make be able to simplify takedispatcher ops.
elsif $optype eq 'takedispatcher' {
@!block_var_stack[nqp::elems(@!block_var_stack) - 1].register_takedispatcher($op);
}

# Calls are especially interesting as we may wish to do some
# kind of inlining.
elsif $optype eq 'call' && $op.name ne '' {
Expand Down
2 changes: 1 addition & 1 deletion tools/build/NQP_REVISION
@@ -1 +1 @@
2014.06-9-gd7f23d9
2014.06-16-g32ddb22

0 comments on commit ebd3166

Please sign in to comment.