Ignore:
Timestamp:
May 17, 2018, 4:37:31 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
bfd0a1a
Parents:
d20a343
git-author:
Rob Schluntz <rschlunt@…> (05/17/18 16:37:16)
git-committer:
Rob Schluntz <rschlunt@…> (05/17/18 16:37:31)
Message:

Reduce the number of unnecessary temporaries generated for member tuple expressions, reduce pure (no side-effect) tuple index expressions to the relevant component expression

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    rd20a343 raee472e  
    3030#include "SynTree/Type.h"         // for Type, Type::Qualifiers, TupleType
    3131#include "SynTree/Visitor.h"      // for Visitor
     32#include "Tuples.h"
    3233
    3334class CompoundStmt;
     
    128129                        Expression * aggr = memberExpr->aggregate->clone()->acceptMutator( *visitor );
    129130                        // aggregate expressions which might be impure must be wrapped in unique expressions
    130                         // xxx - if there's a member-tuple expression nested in the aggregate, this currently generates the wrong code if a UniqueExpr is not used, and it's purely an optimization to remove the UniqueExpr
    131                         // if ( Tuples::maybeImpureIgnoreUnique( memberExpr->get_aggregate() ) ) aggr = new UniqueExpr( aggr );
    132                         aggr = new UniqueExpr( aggr );
     131                        if ( Tuples::maybeImpureIgnoreUnique( memberExpr->aggregate ) ) aggr = new UniqueExpr( aggr );
    133132                        for ( Expression *& expr : tupleExpr->exprs ) {
    134133                                expr = reconstructMemberExpr( expr, aggr, memberExpr->location );
     
    235234                delete tupleExpr;
    236235
     236                if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * > ( tuple ) ) {
     237                        if ( ! maybeImpureIgnoreUnique( tupleExpr ) ) {
     238                                // optimization: definitely pure tuple expr => can reduce to the only relevant component.
     239                                assert( tupleExpr->exprs.size() > idx );
     240                                Expression *& expr = *std::next(tupleExpr->exprs.begin(), idx);
     241                                Expression * ret = expr;
     242                                ret->env = env;
     243                                expr = nullptr; // remove from list so it can safely be deleted
     244                                delete tupleExpr;
     245                                return ret;
     246                        }
     247                }
     248
    237249                StructInstType * type = strict_dynamic_cast< StructInstType * >( tuple->result );
    238250                StructDecl * structDecl = type->baseStruct;
Note: See TracChangeset for help on using the changeset viewer.