Search in sources :

Example 91 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class LoopExtraction method insertDeclaration.

/**
 * Insert new declaration in the function definition.
 *
 * @param id The id used for insertion.
 */
private void insertDeclaration(String id) {
    Xid inductionVarId = _fctDef.getSymbolTable().get(id);
    if (inductionVarId == null) {
        Xid copyId = _fctDefToExtract.getSymbolTable().get(id);
        _fctDef.getSymbolTable().add(copyId);
    }
    Xnode inductionVarDecl = _fctDef.getDeclarationTable().get(id);
    if (inductionVarDecl == null) {
        Xnode copyDecl = _fctDefToExtract.getDeclarationTable().get(id);
        _fctDef.getDeclarationTable().add(copyDecl);
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) Xid(claw.tatsu.xcodeml.xnode.common.Xid)

Example 92 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class LoopFusion method analyze.

/**
 * Loop fusion analysis: - Without collapse clause: check whether the pragma
 * statement is followed by a do statement. - With collapse clause: Find the n
 * do statements following the pragma.
 *
 * @param xcodeml    The XcodeML on which the transformations are applied.
 * @param translator The translator used to applied the transformations.
 * @return True if a do statement is found. False otherwise.
 */
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
    Xnode outerLoop = _claw.getPragma().matchSibling(Xcode.F_DO_STATEMENT);
    if (outerLoop == null) {
        xcodeml.addError("Do statement missing after directive.", _claw.getPragma().lineNo());
        return false;
    }
    _doStmt = new NestedDoStatement(outerLoop, _claw.getCollapseValue());
    // With collapse clause
    if (_claw.hasClause(ClawClause.COLLAPSE) && _claw.getCollapseValue() > 0 && _claw.getCollapseValue() > _doStmt.size()) {
        xcodeml.addError("not enough do statements for collapse value", _claw.getPragma().lineNo());
        return false;
    }
    return true;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) NestedDoStatement(claw.tatsu.xcodeml.abstraction.NestedDoStatement)

Example 93 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class LoopInterchange method analyze.

/**
 * Loop fusion analysis: - Find the different do statement that will be
 * reordered. - Check the validity of the new ordering option.
 *
 * @param xcodeml    The XcodeML on which the transformations are applied.
 * @param translator The translator used to applied the transformations.
 * @return True if the transformation can be performed. False otherwise.
 */
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
    // Find next loop after pragma
    Xnode outerDoStatement = _claw.getPragma().matchSibling(Xcode.F_DO_STATEMENT);
    if (outerDoStatement == null) {
        xcodeml.addError("top level loop not found", _claw.getPragma().lineNo());
        return false;
    }
    int nestedLevel = _claw.values(ClawClause.INTERCHANGE_INDEXES) != null ? _claw.values(ClawClause.INTERCHANGE_INDEXES).size() : 2;
    _doStmts = new NestedDoStatement(outerDoStatement, nestedLevel);
    if (_claw.values(ClawClause.INTERCHANGE_INDEXES) != null) {
        if (_claw.values(ClawClause.INTERCHANGE_INDEXES).size() != 3) {
            xcodeml.addError("new-order option has not enough parameters", _claw.getPragma().lineNo());
        }
        List<String> inductions = _doStmts.getInductionVariables();
        for (String idx : _claw.values(ClawClause.INTERCHANGE_INDEXES)) {
            if (!inductions.contains(idx.toLowerCase())) {
                xcodeml.addError("invalid induction variable in new-order option. " + idx, _claw.getPragma().lineNo());
                return false;
            }
        }
    } else {
        if (_doStmts.size() < 2) {
            xcodeml.addError("Not enough nested do statements to reorder", _claw.getPragma().lineNo());
        }
    }
    return true;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) NestedDoStatement(claw.tatsu.xcodeml.abstraction.NestedDoStatement)

Example 94 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class ScaCPUvectorizeGroup method flagIfStatementWithPromotion.

/**
 * Check whether condition includes a promoted variables. If so, the ancestor
 * node using the condition must be wrapped in a do statement.
 *
 * @return Set of vector block for flagged location.
 */
private Set<VectorBlock> flagIfStatementWithPromotion() {
    Set<VectorBlock> blocks = new HashSet<>();
    /*  */
    List<Xnode> conditions = _fctDef.body().matchAll(Xcode.CONDITION);
    for (Xnode condition : conditions) {
        if (Condition.dependsOn(condition, _arrayFieldsInOut) && !Condition.isAllocationRelated(condition)) {
            Xnode ancestor = condition.ancestor();
            Iterator<VectorBlock> iter = blocks.iterator();
            boolean addFlaggedLocation = true;
            while (iter.hasNext()) {
                if (ancestor.isNestedIn(iter.next().getStartStmt())) {
                    addFlaggedLocation = false;
                    break;
                }
            }
            if (addFlaggedLocation) {
                blocks.add(new VectorBlock(ancestor));
            }
        }
    }
    return blocks;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) HashSet(java.util.HashSet)

Example 95 with Xnode

use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.

the class Sca method insertVariableToIterateOverDimension.

/**
 * Insert the declaration of the different variables needed to iterate over the
 * additional dimensions.
 *
 * @param xcodeml Current XcodeML program unit in which element are created.
 */
private void insertVariableToIterateOverDimension(Configuration cfg, XcodeProgram xcodeml) {
    // Create type and declaration for iterations over the new dimensions
    FbasicType bt = xcodeml.createBasicType(FortranType.INTEGER, Intent.IN);
    xcodeml.getTypeTable().add(bt);
    // For each dimension defined in the directive
    for (DimensionDefinition dimension : _claw.getDefaultLayout(cfg)) {
        if (!forceAssumedShapedArrayPromotion) {
            // Create the parameter for the lower bound
            if (dimension.getLowerBound().isVar()) {
                xcodeml.createIdAndDecl(dimension.getLowerBound().getValue(), bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
                // Add parameter to the local type table
                Xnode param = xcodeml.createAndAddParam(dimension.getLowerBound().getValue(), bt.getType(), _fctType);
                param.setBooleanAttribute(Xattr.IS_INSERTED, true);
            }
            // Create parameter for the upper bound
            if (dimension.getUpperBound().isVar()) {
                xcodeml.createIdAndDecl(dimension.getUpperBound().getValue(), bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
                // Add parameter to the local type table
                Xnode param = xcodeml.createAndAddParam(dimension.getUpperBound().getValue(), bt.getType(), _fctType);
                param.setBooleanAttribute(Xattr.IS_INSERTED, true);
            }
            // Create the parameter for the iteration lower bound
            if (dimension.getIterationLowerBound().isVar()) {
                String itLowerBound = dimension.getIterationLowerBound().getValue();
                if (!itLowerBound.equals(dimension.getLowerBound().getValue())) {
                    xcodeml.createIdAndDecl(itLowerBound, bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
                    // Add parameter to the local type table
                    Xnode param = xcodeml.createAndAddParam(dimension.getIterationLowerBound().getValue(), bt.getType(), _fctType);
                    param.setBooleanAttribute(Xattr.IS_INSERTED, true);
                }
            }
            // Create parameter for the upper bound
            if (dimension.getIterationUpperBound().isVar()) {
                String itUpperBound = dimension.getIterationUpperBound().getValue();
                if (!itUpperBound.equals(dimension.getUpperBound().getValue())) {
                    xcodeml.createIdAndDecl(itUpperBound, bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
                    // Add parameter to the local type table
                    Xnode param = xcodeml.createAndAddParam(dimension.getIterationUpperBound().getValue(), bt.getType(), _fctType);
                    param.setBooleanAttribute(Xattr.IS_INSERTED, true);
                }
            }
        }
        // Create induction variable declaration
        xcodeml.createIdAndDecl(dimension.getIdentifier(), FortranType.INTEGER, XstorageClass.F_LOCAL, _fctDef, DeclarationPosition.LAST);
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Aggregations

Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)124 Context (claw.tatsu.common.Context)29 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)24 Test (org.junit.Test)24 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)20 TestContext (helper.Utils.TestContext)20 ArrayList (java.util.ArrayList)18 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)17 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)9 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)8 Xid (claw.tatsu.xcodeml.xnode.common.Xid)8 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)8 HashSet (java.util.HashSet)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)6 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)6 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)5 ClawPragma (claw.wani.language.ClawPragma)5 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)5 NodeList (org.w3c.dom.NodeList)5 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)4