Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Switch many type checks to a more optimal construct, based on profile…
…r feedback. Cuts the time spent in the optimizer to a third (!!!) of what it once was; on my machine we shave ~5s off CORE.setting build and > 10s off spectest run.
  • Loading branch information
jnthn committed Jul 25, 2012
1 parent 81f4e66 commit 48fdb9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/Perl6/Actions.pm
Expand Up @@ -2210,10 +2210,10 @@ class Perl6::Actions is HLL::Actions {
if +$block[1].list == 1 && $block[1][0].isa(QAST::Stmt) && +$block[1][0].list == 1 {
# Ensure there's no nested blocks.
for @($block[0]) {
if $_.isa(QAST::Block) { return 0; }
if $_.isa(QAST::Stmts) {
if nqp::istype($_, QAST::Block) { return 0; }
if nqp::istype($_, QAST::Stmts) {
for @($_) {
if $_.isa(QAST::Block) { return 0; }
if nqp::istype($_, QAST::Block) { return 0; }
}
}
}
Expand Down Expand Up @@ -3494,7 +3494,7 @@ class Perl6::Actions is HLL::Actions {
!! [$expr];
my %named_counts;
for @args {
if $_.isa(QAST::Op) && istype($_.returns, $Pair) {
if nqp::istype($_, QAST::Op) && istype($_.returns, $Pair) {
my $name := compile_time_value_str($_[1], 'LHS of pair', $/);
%named_counts{$name} := +%named_counts{$name} + 1;
$_[2].named($name);
Expand All @@ -3503,7 +3503,7 @@ class Perl6::Actions is HLL::Actions {

# Make result.
for @args {
if $_.isa(QAST::Op) && istype($_.returns, $Pair) {
if nqp::istype($_, QAST::Op) && istype($_.returns, $Pair) {
my $name := $_[2].named();
if %named_counts{$name} == 1 {
$past.push($_[2]);
Expand All @@ -3513,7 +3513,7 @@ class Perl6::Actions is HLL::Actions {
%named_counts{$name} := %named_counts{$name} - 1;
}
}
elsif $_ ~~ QAST::Op && $_.name eq '&prefix:<|>' {
elsif nqp::istype($_, QAST::Op) && $_.name eq '&prefix:<|>' {
my $reg := $past.unique('flattening_');
$past.push(QAST::Op.new(
:op('callmethod'), :name('FLATTENABLE_LIST'),
Expand Down Expand Up @@ -5093,14 +5093,14 @@ class Perl6::Actions is HLL::Actions {
my $WhateverCode := $*W.find_symbol(['WhateverCode']);
my $curried :=
# It must be an op and...
$past.isa(QAST::Op) && (
nqp::istype($past, QAST::Op) && (

# Either a call that we're allowed to curry...
(($past.op eq 'call' || $past.op eq 'chain') &&
(nqp::index($past.name, '&infix:') == 0 ||
nqp::index($past.name, '&prefix:') == 0 ||
nqp::index($past.name, '&postfix:') == 0 ||
($past[0].isa(QAST::Op) &&
(nqp::istype($past[0], QAST::Op) &&
nqp::index($past[0].name, '&METAOP') == 0)) &&
%curried{$past.name} // 2)

Expand Down
30 changes: 15 additions & 15 deletions src/Perl6/Optimizer.pm
Expand Up @@ -42,7 +42,7 @@ class Perl6::Optimizer {
my $unit := $past<UNIT>;
my $*GLOBALish := $past<GLOBALish>;
my $*W := $past<W>;
unless $unit.isa(QAST::Block) {
unless nqp::istype($unit, QAST::Block) {
nqp::die("Optimizer could not find UNIT");
}
self.visit_block($unit);
Expand Down Expand Up @@ -128,8 +128,8 @@ class Perl6::Optimizer {
if $optype eq 'chain' {
$!chain_depth := $!chain_depth + 1;
$optype := 'call' if $!chain_depth == 1 &&
!($op[0].isa(QAST::Op) && $op[0].op eq 'chain') &&
!($op[1].isa(QAST::Op) && $op[1].op eq 'chain');
!(nqp::istype($op[0], QAST::Op) && $op[0].op eq 'chain') &&
!(nqp::istype($op[1], QAST::Op) && $op[1].op eq 'chain');
}

# Visit the children.
Expand Down Expand Up @@ -334,24 +334,24 @@ class Perl6::Optimizer {
while $i < +@($node) {
unless $skip_selectors && $i % 2 {
my $visit := $node[$i];
if $visit.isa(QAST::Op) {
if nqp::istype($visit, QAST::Op) {
$node[$i] := self.visit_op($visit)
}
elsif $visit.isa(QAST::Block) {
elsif nqp::istype($visit, QAST::Want) {
self.visit_want($visit);
}
elsif nqp::istype($visit, QAST::Var) {
self.visit_var($visit);
}
elsif nqp::istype($visit, QAST::Block) {
$node[$i] := self.visit_block($visit);
}
elsif $visit.isa(QAST::Stmts) {
elsif nqp::istype($visit, QAST::Stmts) {
self.visit_children($visit);
}
elsif $visit.isa(QAST::Stmt) {
elsif nqp::istype($visit, QAST::Stmt) {
self.visit_children($visit);
}
elsif $visit.isa(QAST::Want) {
self.visit_want($visit);
}
elsif $visit.isa(QAST::Var) {
self.visit_var($visit);
}
}
$i := $i + 1;
}
Expand Down Expand Up @@ -410,11 +410,11 @@ class Perl6::Optimizer {

# Copy over interesting stuff in declaration section.
for @($decls) {
if $_.isa(QAST::Op) && ($_.op eq 'p6bindsig' ||
if nqp::istype($_, QAST::Op) && ($_.op eq 'p6bindsig' ||
$_.op eq 'bind' && $_[0].name eq 'call_sig') {
# Don't copy this binder call or setup.
}
elsif $_.isa(QAST::Var) && ($_.name eq '$/' || $_.name eq '$!' ||
elsif nqp::istype($_, QAST::Var) && ($_.name eq '$/' || $_.name eq '$!' ||
$_.name eq '$_' || $_.name eq '$*DISPATCHER') {
# Don't copy this variable node.
}
Expand Down

0 comments on commit 48fdb9e

Please sign in to comment.