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);
}
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;
}
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();
}
}
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;
}
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);
}
Aggregations