Skip to content

Commit 2bb945d

Browse files
committed
Improve getattr/bindattr code gen quality
Recognize when we have a literal wrapped up in a QAST::Want, and emit a more efficient getattr_* instead of a const_s and getattrs_*.
1 parent e1929a4 commit 2bb945d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/vm/moar/QAST/QASTOperationsMAST.nqp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,12 +2618,14 @@ sub add_bindattr_op($nqpop, $hintedop, $namedop, $want) {
26182618
push_ilist(@ins, $obj_mast);
26192619
push_ilist(@ins, $type_mast);
26202620
push_op(@ins, 'decont', $type_mast.result_reg, $type_mast.result_reg);
2621-
if nqp::istype($op[2], QAST::SVal) {
2621+
my $name := $op[2];
2622+
$name := $name[2] if nqp::istype($name, QAST::Want) && $name[1] eq 'Ss';
2623+
if nqp::istype($name, QAST::SVal) {
26222624
if nqp::istype($op[1], QAST::WVal) {
2623-
$hint := nqp::hintfor($op[1].value, $op[2].value);
2625+
$hint := nqp::hintfor($op[1].value, $name.value);
26242626
}
26252627
push_op(@ins, $hintedop, $obj_mast.result_reg, $type_mast.result_reg,
2626-
MAST::SVal.new( :value($op[2].value) ),
2628+
MAST::SVal.new( :value($name.value) ),
26272629
$val_mast.result_reg, MAST::IVal.new( :value($hint) ));
26282630
} else {
26292631
my $name_mast := $qastcomp.as_mast( :want($MVM_reg_str), $op[2] );
@@ -2654,12 +2656,14 @@ sub add_getattr_op($nqpop, $hintedop, $namedop, $want) {
26542656
push_ilist(@ins, $type_mast);
26552657
my $res_reg := $regalloc.fresh_register($want);
26562658
push_op(@ins, 'decont', $type_mast.result_reg, $type_mast.result_reg);
2657-
if nqp::istype($op[2], QAST::SVal) {
2659+
my $name := $op[2];
2660+
$name := $name[2] if nqp::istype($name, QAST::Want) && $name[1] eq 'Ss';
2661+
if nqp::istype($name, QAST::SVal) {
26582662
if nqp::istype($op[1], QAST::WVal) {
2659-
$hint := nqp::hintfor($op[1].value, $op[2].value);
2663+
$hint := nqp::hintfor($op[1].value, $name.value);
26602664
}
26612665
push_op(@ins, $hintedop, $res_reg, $obj_mast.result_reg, $type_mast.result_reg,
2662-
MAST::SVal.new( :value($op[2].value) ), MAST::IVal.new( :value($hint) ));
2666+
MAST::SVal.new( :value($name.value) ), MAST::IVal.new( :value($hint) ));
26632667
} else {
26642668
my $name_mast := $qastcomp.as_mast( :want($MVM_reg_str), $op[2] );
26652669
push_ilist(@ins, $name_mast);

0 commit comments

Comments
 (0)