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