Search in sources :

Example 81 with Xnode

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

the class XnodeUtil method getFirstArrayAssign.

/**
 * Get the first assignment statement for an array reference.
 *
 * @param from      Statement to look from.
 * @param arrayName Identifier of the array.
 * @return The assignment statement if found. Null otherwise.
 */
public static Xnode getFirstArrayAssign(Xnode from, String arrayName) {
    String s1 = String.format("following::%s[%s[%s[%s[text()=\"%s\"]] and position()=1]]", Xname.F_ASSIGN_STATEMENT, Xname.F_ARRAY_REF, Xname.VAR_REF, Xname.VAR, arrayName);
    try {
        NodeList output = evaluateXpath(from.element(), s1);
        if (output.getLength() == 0) {
            return null;
        }
        Element assign = (Element) output.item(0);
        return new Xnode(assign);
    } catch (XPathExpressionException ignored) {
        return null;
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 82 with Xnode

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

the class XnodeUtil method getAllArrayReferences.

/**
 * Find all array references elements in a given body and give var name.
 *
 * @param parent    The body element to search for the array references.
 * @param arrayName Name of the array for the array reference to be found.
 * @return A list of all array references found.
 */
public static List<Xnode> getAllArrayReferences(Xnode parent, String arrayName) {
    List<Xnode> references = new ArrayList<>();
    NodeList nList = parent.element().getElementsByTagName(Xname.F_ARRAY_REF);
    for (int i = 0; i < nList.getLength(); i++) {
        Node n = nList.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            Xnode ref = new Xnode((Element) n);
            Xnode var = ref.matchSeq(Xcode.VAR_REF, Xcode.VAR);
            if (var != null && var.value().equalsIgnoreCase(arrayName)) {
                references.add(ref);
            }
        }
    }
    return references;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 83 with Xnode

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

the class XnodeUtil method getReadArraysInRegion.

/**
 * Gather all array identifiers read in the given block.
 *
 * @param from Node from which the block starts.
 * @param to   Node to which the block ends.
 * @return List of array identifiers read to in the block.
 */
public static List<String> getReadArraysInRegion(Xnode from, Xnode to) {
    Set<String> readArrayIds = new HashSet<>();
    List<Xnode> firstLevelNodesInRegion;
    if (to == null) {
        firstLevelNodesInRegion = Collections.singletonList(from.nextSibling());
    } else {
        firstLevelNodesInRegion = getSiblingsBetween(from, to);
    }
    for (Xnode node : firstLevelNodesInRegion) {
        List<Xnode> arrayRefs = node.matchAll(Xcode.F_ARRAY_REF);
        for (Xnode arrayRef : arrayRefs) {
            if (arrayRef.ancestorIs(Xcode.F_ASSIGN_STATEMENT) && arrayRef.ancestor().firstChild().equals(arrayRef) || arrayRef.matchAncestor(Xcode.F_ARRAY_REF) != null) {
                continue;
            }
            if (arrayRef.matchAncestor(Xcode.F_MEMBER_REF) != null) {
                readArrayIds.add(arrayRef.matchAncestor(Xcode.F_MEMBER_REF).constructRepresentation(false, false));
            } else {
                readArrayIds.add(arrayRef.constructRepresentation(false, false));
            }
        }
    }
    return new ArrayList<>(readArrayIds);
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 84 with Xnode

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

the class ClawTranslator method applyInterchangeClause.

/**
 * Generate loop interchange transformation if the clause is present in the
 * directive.
 *
 * @param claw    ClawPragma object that tells encapsulates all information
 *                about the current directives and its clauses.
 * @param xcodeml Current XcodeML program.
 * @param stmt    Statement on which the transformation is attached. Must be a
 *                FdoStatement for the loop interchange transformation.
 */
private void applyInterchangeClause(ClawPragma claw, XcodeProgram xcodeml, Xnode stmt) throws IllegalTransformationException {
    if (claw.hasClause(ClawClause.INTERCHANGE) && Xnode.isOfCode(stmt, Xcode.F_DO_STATEMENT)) {
        Xnode p = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
        stmt.insertBefore(p);
        ClawPragma l = ClawPragma.createLoopInterchangeLanguage(claw, p);
        LoopInterchange interchange = new LoopInterchange(l);
        addTransformation(xcodeml, interchange);
        Message.debug(context(), "Loop interchange added: " + claw.values(ClawClause.INTERCHANGE_INDEXES));
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) LoopInterchange(claw.wani.transformation.ll.loop.LoopInterchange) ClawPragma(claw.wani.language.ClawPragma)

Example 85 with Xnode

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

the class ScaGPU method analyzeStandard.

/**
 * Perform analysis steps for SCA transformation on standard function/subroutine
 * for GPU target.
 *
 * @param xcodeml    Current translation unit.
 * @param translator Current translator.
 * @return True if the analysis succeed. False otherwise.
 */
private boolean analyzeStandard(XcodeProgram xcodeml, ClawTranslator translator) {
    final Context context = xcodeml.context();
    DirectiveGenerator dirGen = context.getGenerator();
    /*
         * Check if unsupported statements are located in the future parallel region.
         */
    if (dirGen.getDirectiveLanguage() != CompilerDirective.NONE) {
        Xnode contains = _fctDef.body().matchSeq(Xcode.F_CONTAINS_STATEMENT);
        Xnode parallelRegionStart;
        if (_fctDef.body().child(0).is(Xcode.F_PRAGMA_STATEMENT) && _fctDef.body().child(0).value().toLowerCase().startsWith(TatsuConstant.CLAW_PREFIX)) {
            parallelRegionStart = Directive.findParallelRegionStart(context, _fctDef, null);
        } else {
            parallelRegionStart = _claw.getPragma().nextSibling();
            _specialParallelRegionStart = parallelRegionStart;
        }
        Xnode parallelRegionEnd = Directive.findParallelRegionEnd(context, _fctDef, contains);
        List<Xnode> unsupportedStatements = XnodeUtil.getNodes(parallelRegionStart, parallelRegionEnd, dirGen.getUnsupportedStatements());
        if (!unsupportedStatements.isEmpty()) {
            List<Xnode> falsePositive = new ArrayList<>();
            for (Xnode statement : unsupportedStatements) {
                if (canTransformReturn(statement)) {
                    falsePositive.add(statement);
                } else {
                    if (statement != null) {
                        xcodeml.addError("Unsupported statement in parallel region: " + statement.opcode().fortran(), statement.lineNo());
                    } else {
                        throw new NullPointerException("statement is null");
                    }
                }
            }
            // Only one return statement can be transformed at the moment.
            if (falsePositive.size() > 1) {
                return false;
            }
            unsupportedStatements.removeAll(falsePositive);
            if (!unsupportedStatements.isEmpty()) {
                return false;
            }
        }
    }
    detectInductionVariables();
    return analyzeDimension(translator.cfg(), xcodeml) && analyzeData(xcodeml, translator);
}
Also used : Context(claw.tatsu.common.Context) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) DirectiveGenerator(claw.tatsu.directive.generator.DirectiveGenerator) ArrayList(java.util.ArrayList)

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