Search in sources :

Example 16 with Xnode

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

the class ExpandNotation method generateUpdateClause.

/**
 * Generate update device/host directives to manage data before and after the
 * expand block.
 *
 * @param xcodeml Current XcodeML translation unit.
 * @param hook    Block around which directives are generated
 */
private Xblock generateUpdateClause(Configuration cfg, XcodeProgram xcodeml, Xblock hook, List<String> readArrays, List<String> writtenArrays) {
    Xnode startNode;
    Xnode endNode;
    // Generate host to device movement
    if ((_clawStart.getUpdateClauseValue() == DataMovement.TWO_WAY || _clawStart.getUpdateClauseValue() == DataMovement.HOST_TO_DEVICE) && cfg.updateAtInput()) {
        startNode = Directive.generateUpdate(xcodeml, hook.getStart(), readArrays, DataMovement.HOST_TO_DEVICE);
    } else {
        startNode = hook.getStart();
    }
    // Generate device to host movement
    if ((_clawStart.getUpdateClauseValue() == DataMovement.TWO_WAY || _clawStart.getUpdateClauseValue() == DataMovement.DEVICE_TO_HOST) && cfg.updateAtOutput()) {
        endNode = Directive.generateUpdate(xcodeml, hook.getEnd(), writtenArrays, DataMovement.DEVICE_TO_HOST);
    } else {
        endNode = hook.getEnd();
    }
    return new Xblock(startNode, endNode);
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) Xblock(claw.tatsu.xcodeml.abstraction.Xblock)

Example 17 with Xnode

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

the class XnodeUtil method getAllVarReferences.

/**
 * Find all var references elements in a given body and give var name.
 *
 * @param parent  The body element to search for the array references.
 * @param varName Name of the var for the reference to be found.
 * @return A list of all references found.
 */
public static List<Xnode> getAllVarReferences(Xnode parent, String varName) {
    List<Xnode> references = new ArrayList<>();
    NodeList nList = parent.element().getElementsByTagName(Xname.VAR);
    for (int i = 0; i < nList.getLength(); i++) {
        Node n = nList.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            Xnode var = new Xnode((Element) n);
            if (var.value().equalsIgnoreCase(varName)) {
                references.add(var);
            }
        }
    }
    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 18 with Xnode

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

the class XnodeUtil method deleteBetween.

/* XNODE SECTION */
/**
 * Delete all the elements between the two given elements.
 *
 * @param start The start element. Deletion start from next element.
 * @param end   The end element. Deletion end just before this element.
 */
public static void deleteBetween(Xnode start, Xnode end) {
    List<Xnode> toDelete = new ArrayList<>();
    Xnode node = start.nextSibling();
    while (node != null && node.element() != end.element()) {
        toDelete.add(node);
        node = node.nextSibling();
    }
    for (Xnode n : toDelete) {
        n.delete();
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) ArrayList(java.util.ArrayList)

Example 19 with Xnode

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

the class XnodeUtil method getSiblingsBetween.

/**
 * Gather all nodes at the same level between from and to.
 *
 * @param from Node from which the block starts.
 * @param to   Node to which the block ends.
 * @return List of nodes in the block.
 */
private static List<Xnode> getSiblingsBetween(Xnode from, Xnode to) {
    List<Xnode> siblingsInRegion = new LinkedList<>();
    Xnode current = from.nextSibling();
    while (current != null && !current.equals(to)) {
        siblingsInRegion.add(current);
        current = current.nextSibling();
    }
    return siblingsInRegion;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) LinkedList(java.util.LinkedList)

Example 20 with Xnode

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

the class XnodeUtil method getWrittenArraysInRegion.

/**
 * Gather all array identifiers written 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 written to in the block.
 */
public static List<String> getWrittenArraysInRegion(Xnode from, Xnode to) {
    Set<String> writtenArraysIds = new HashSet<>();
    List<Xnode> firstLevelNodesInRegion;
    if (to == null) {
        firstLevelNodesInRegion = Collections.singletonList(from.nextSibling());
    } else {
        firstLevelNodesInRegion = getSiblingsBetween(from, to);
    }
    for (Xnode node : firstLevelNodesInRegion) {
        List<AssignStatement> assignements;
        if (node.is(Xcode.F_ASSIGN_STATEMENT)) {
            assignements = Collections.singletonList(new AssignStatement(node.element()));
        } else {
            assignements = node.matchAll(Xcode.F_ASSIGN_STATEMENT).stream().map(Xnode::element).map(AssignStatement::new).collect(Collectors.toList());
        }
        for (AssignStatement as : assignements) {
            Xnode lhs = as.getLhs();
            if (lhs.is(Xcode.F_ARRAY_REF)) {
                writtenArraysIds.add(lhs.constructRepresentation(false, false));
            }
        }
    }
    return new ArrayList<>(writtenArraysIds);
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) ArrayList(java.util.ArrayList) AssignStatement(claw.tatsu.xcodeml.abstraction.AssignStatement) HashSet(java.util.HashSet)

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