Changeset 11452


Ignore:
Timestamp:
Aug 10, 2018 3:29:51 PM (16 months ago)
Author:
Jonathan Kämpe
Message:

#5658 Minor refactoring in alias elimination

Location:
trunk/Compiler/ModelicaMiddleEnd/src/jastadd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/ModelicaMiddleEnd/src/jastadd/TransformCanonical.jrag

    r11442 r11452  
    14021402
    14031403    /**
    1404      * Flag indicating if alias variables have been eliminated from the
    1405      * model.
    1406      */
    1407     public boolean FClass.aliasVariablesEliminated = false;
    1408    
    1409     /**
    14101404     * Eliminate alias variables from the flat model.
    14111405     *
     
    14141408     */
    14151409    public void FClass.eliminateAliasVariables() {
    1416         ArrayList<FVariable> nonAliasVars = new ArrayList<FVariable>();
    1417         ArrayList<FVariable> aliasVars    = new ArrayList<FVariable>();
    14181410        ArrayList<FAbstractEquation> eqns = new ArrayList<FAbstractEquation>();
    14191411        ArrayList<FAbstractEquation> pEqns = new ArrayList<FAbstractEquation>();
    14201412       
    14211413        //log.debug("FClass.eliminateAliasVariables(): l1 " + nonAliasVars + " l2 " + aliasVars);
    1422        
    1423         // Go through all variables and insert in correct list
    1424         for (FVariable fv : getAliasVariables()) {
    1425                 aliasVars.add(fv);
    1426         }
    1427         for (FVariable fv : getFVariables()) {
    1428             fv.aliasSort(nonAliasVars, aliasVars);
    1429         }
    1430        
     1414
    14311415        // Remove alias equations.
    14321416        for (FAbstractEquation equation : getFAbstractEquations())
     
    14491433        }
    14501434
    1451         setFVariableList(new List(nonAliasVars));
    1452         setAliasVariableList(new List(aliasVars));
    14531435        setFAbstractEquationList(new List(eqns));
    14541436        if (myOptions().getBooleanOption("eliminate_alias_parameters")) {
     
    14561438        }
    14571439       
    1458         aliasVariablesEliminated = true;
    1459         enableAliasRewrite();
     1440        sortAliasvariables(false);
    14601441       
    14611442        flush();
    14621443    }
    1463    
     1444
     1445    public void FClass.sortAliasvariables(boolean recompute) {
     1446        ArrayList<FVariable> nonAliasVars = new ArrayList<FVariable>();
     1447        ArrayList<FVariable> aliasVars    = new ArrayList<FVariable>();
     1448        if (recompute) {
     1449            for (FVariable fv : getAliasVariables()) {
     1450                fv.aliasSort(nonAliasVars, aliasVars);
     1451            }
     1452        } else {
     1453            for (FVariable fv : getAliasVariables()) {
     1454                aliasVars.add(fv);
     1455            }
     1456        }
     1457        for (FVariable fv : getFVariables()) {
     1458             fv.aliasSort(nonAliasVars, aliasVars);
     1459        }
     1460        setFVariableList(new List(nonAliasVars));
     1461        setAliasVariableList(new List(aliasVars));
     1462        enableAliasRewrite();
     1463    }
     1464
    14641465    /**
    14651466     * Adds this variable to <code>aliasVars</code>, if it is an alias, or
     
    15331534     * FIdUses referring to their alias targets.
    15341535     *
    1535      * This is done by rewrites which are activated once FClass.aliasVariablesEliminated
     1536     * This is done by rewrites which are activated once FIdUseExp.rewriteAlias
    15361537     * is true. Notice that in order for the rewrite to be enable, the is$final
    15371538     * field of FIdUseExp needs to be set to false: this is done by the recursive
     
    16091610     * FDerExps referring to their alias targets.
    16101611     *
    1611      * This is done by rewrites which are activated once FClass.aliasVariablesEliminated
     1612     * This is done by rewrites which are activated once FIdUseExp.rewriteAlias
    16121613     * is true. Notice that in order for the rewrite to be enable, the is$final
    16131614     * field of FIdUseExp needs to be set to false: this is done by the recursive
  • trunk/Compiler/ModelicaMiddleEnd/src/jastadd/optimizations/AliasVariables.jadd

    r10046 r11452  
    355355            private AliasSet() {
    356356            }
     357           
     358            /*
     359             * Recompute the model variable.
     360             */
     361            public void recompute() {
     362                AliasVariable oldModelVariable = model;
     363                java.util.List<AliasVariable> oldAliases = aliases;
     364                aliases = new ArrayList<>();
     365                model = null;
     366                score = 0;
     367                for (AliasVariable v : oldAliases) {
     368                    add(v);
     369                }
     370            }
    357371           
    358372            /**
     
    916930        long score = 0;
    917931
     932        if (!getVisibilityType().isHidden()) {
     933            score += 1;
     934        }
     935
    918936        // Temporary variables added during transformations or in expandable connectors.
     937        score *= 10;
    919938        if (isFromExpandableConnector()) {
    920939            score += 1;
Note: See TracChangeset for help on using the changeset viewer.