use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class ScaForward method detectParameterMapping.
/**
* Get all the mapping between local variable and parameter names in the
* function call.
*
* @param fctCall Function call to be analyzed.
*/
private void detectParameterMapping(Context context, FunctionCall fctCall) {
if (!Xnode.isOfCode(fctCall, Xcode.FUNCTION_CALL)) {
return;
}
for (Xnode arg : fctCall.arguments()) {
if (arg.is(Xcode.NAMED_VALUE)) {
String originalName = arg.getAttribute(Xattr.NAME);
Xnode targetVar = arg.matchDescendant(Xcode.VAR);
if (targetVar != null) {
_fctCallMapping.put(originalName, targetVar.value());
Message.debug(context, "Fct parameter mapping: original_name=" + originalName + " target_name=" + targetVar.value());
}
}
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class IfExtract method analyze.
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
_doStmt = _claw.getPragma().matchSibling(Xcode.F_DO_STATEMENT);
if (_doStmt == null) {
xcodeml.addError("Do statement missing after directive.", _claw.getPragma().lineNo());
return false;
}
_ifStmt = _doStmt.body().matchDirectDescendant(Xcode.F_IF_STATEMENT);
if (_ifStmt == null) {
xcodeml.addError("If statement not found in the do statement.", _claw.getPragma().lineNo());
return false;
}
int counterIfStmt = 0;
for (Xnode n : _doStmt.body().children()) {
if (!n.is(Xcode.F_IF_STATEMENT) && !n.is(Xcode.F_PRAGMA_STATEMENT)) {
xcodeml.addError("If statement is not purely nested in the do statement", _claw.getPragma().lineNo());
return false;
} else if (n.is(Xcode.F_IF_STATEMENT)) {
++counterIfStmt;
}
}
if (counterIfStmt > 1) {
xcodeml.addError("Only one if statement can be present for extraction.", _claw.getPragma().lineNo());
return false;
}
return true;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class LoopExtraction method wrapCallWithLoop.
/**
* Wrap a function call with a do statement.
*
* @param xcodeml The XcodeML representation.
* @param doStmt Iteration range to be applied to the do statement.
* @return The created do statement.
*/
private Xnode wrapCallWithLoop(XcodeProgram xcodeml, Xnode doStmt) {
// Create a new empty loop
Xnode loop = xcodeml.createDoStmt(doStmt.matchDirectDescendant(Xcode.VAR).cloneNode(), doStmt.matchDirectDescendant(Xcode.INDEX_RANGE).cloneNode());
// Insert the new empty loop just after the pragma
_claw.getPragma().insertAfter(loop);
// Move the call into the loop body
loop.body().element().appendChild(_fctCall.element().getParentNode());
insertDeclaration(doStmt.matchSeq(Xcode.VAR).value());
if (doStmt.matchSeq(Xcode.INDEX_RANGE, Xcode.LOWER_BOUND, Xcode.VAR) != null) {
insertDeclaration(doStmt.matchSeq(Xcode.INDEX_RANGE, Xcode.LOWER_BOUND, Xcode.VAR).value());
}
if (doStmt.matchSeq(Xcode.INDEX_RANGE, Xcode.UPPER_BOUND, Xcode.VAR) != null) {
insertDeclaration(doStmt.matchSeq(Xcode.INDEX_RANGE, Xcode.UPPER_BOUND, Xcode.VAR).value());
}
if (doStmt.matchSeq(Xcode.INDEX_RANGE, Xcode.STEP, Xcode.VAR) != null) {
insertDeclaration(doStmt.matchSeq(Xcode.INDEX_RANGE, Xcode.STEP, Xcode.VAR).value());
}
return loop;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class LoopExtraction method analyze.
/**
* Check whether the transformation can be applied.
*
* @param xcodeml The XcodeML on which the transformations are applied.
* @param translator The translator used to applied the transformations.
* @return True if the transformation analysis succeeded. False otherwise.
*/
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
Xnode _exprStmt = _claw.getPragma().matchSibling(Xcode.EXPR_STATEMENT);
if (_exprStmt == null) {
xcodeml.addError("No function call detected after loop-extract", _claw.getPragma().lineNo());
return false;
}
// Find function CALL
Xnode fctCallNode = _exprStmt.matchDescendant(Xcode.FUNCTION_CALL);
if (fctCallNode == null) {
xcodeml.addError("No function call detected after loop-extract", _claw.getPragma().lineNo());
return false;
}
_fctCall = new FunctionCall(fctCallNode);
Xnode fctDef = _fctCall.matchAncestor(Xcode.F_FUNCTION_DEFINITION);
if (fctDef == null) {
xcodeml.addError("No function around the fct call", _claw.getPragma().lineNo());
return false;
}
_fctDef = new FfunctionDefinition(fctDef);
// Find function declaration
String fctName = _fctCall.matchDirectDescendant(Xcode.NAME).value();
_fctDefToExtract = xcodeml.getGlobalDeclarationsTable().getFunctionDefinition(fctName);
if (_fctDefToExtract == null) {
xcodeml.addError("Could not locate the function definition for: " + _fctCall.matchDirectDescendant(Xcode.NAME).value(), _claw.getPragma().lineNo());
return false;
}
// Find the loop to be extracted
try {
_extractedLoop = locateDoStatement(_fctDefToExtract);
} catch (IllegalTransformationException itex) {
xcodeml.addError(itex.getMessage(), _claw.getPragma().lineNo());
return false;
}
return checkMappingInformation(xcodeml);
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class LoopHoist method analyze.
/**
* @see Transformation#analyze(XcodeProgram, Translator)
*/
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
if (_clawEnd == null) {
xcodeml.addError("loop-hoist directive requires an end directive.", _clawStart.getPragma().lineNo());
return false;
}
int pragmaDepthLevel = _clawStart.getPragma().depth();
// Find all the group of nested loops that can be part of the hoisting
List<HoistedNestedDoStatement> statements = XnodeUtil.findDoStatementForHoisting(_clawStart.getPragma(), _clawEnd.getPragma(), _clawStart.values(ClawClause.HOIST_INDUCTIONS));
if (statements.isEmpty()) {
xcodeml.addError("No do statement group meets the criteria of hoisting.", _clawStart.getPragma().lineNo());
return false;
}
for (HoistedNestedDoStatement hoistedNestedDoStmt : statements) {
int depth = hoistedNestedDoStmt.getOuterStatement().depth();
if (depth != pragmaDepthLevel) {
Xnode tmpIf = hoistedNestedDoStmt.getOuterStatement().matchAncestor(Xcode.F_IF_STATEMENT);
Xnode tmpSelect = hoistedNestedDoStmt.getOuterStatement().matchAncestor(Xcode.F_SELECT_CASE_STATEMENT);
Xnode tmpDo = hoistedNestedDoStmt.getOuterStatement().matchAncestor(Xcode.F_DO_STATEMENT);
if (tmpIf == null && tmpSelect == null && tmpDo == null) {
xcodeml.addError("A nested do stmt group is nested in an unsupported " + "statement for loop hoisting.", hoistedNestedDoStmt.getOuterStatement().lineNo());
return false;
}
int ifDepth = (tmpIf != null) ? tmpIf.depth() : Xnode.UNDEF_DEPTH;
int selectDepth = (tmpSelect != null) ? tmpSelect.depth() : Xnode.UNDEF_DEPTH;
int doDepth = (tmpDo != null) ? tmpDo.depth() : Xnode.UNDEF_DEPTH;
if ((pragmaDepthLevel <= ifDepth || pragmaDepthLevel <= selectDepth || pragmaDepthLevel <= doDepth) && (ifDepth < depth || selectDepth < depth || doDepth < depth)) {
hoistedNestedDoStmt.setExtraction();
} else {
xcodeml.addError("Group is nested in an unsupported " + "statement for loop hoisting or depth is too high " + "(Group index starts at 0).", _clawStart.getPragma().lineNo());
return false;
}
}
_hoistedGroups.add(hoistedNestedDoStmt);
}
HoistedNestedDoStatement master = _hoistedGroups.get(0);
for (int i = 1; i < _hoistedGroups.size(); ++i) {
HoistedNestedDoStatement next = _hoistedGroups.get(i);
for (int j = 0; j < master.size(); ++j) {
// Iteration range are identical, just merge
if (j == 0 && (!Loop.hasSameIndexRange(master.get(j), next.get(j)) && Loop.hasSameIndexRangeBesidesLower(master.get(j), next.get(j)))) {
// Iteration range are identical besides lower-bound, if creation
next.setIfStatement();
} else if (!Loop.hasSameIndexRange(master.get(j), next.get(j))) {
// Iteration range are too different, stop analysis
xcodeml.addError("Iteration range of do statements group " + i + " differs from group 0. Loop hoisting aborted.", _clawStart.getPragma().lineNo());
return false;
}
}
}
// Check reshape mandatory points
if (_clawStart.hasClause(ClawClause.RESHAPE)) {
FfunctionDefinition fctDef = _clawStart.getPragma().findParentFunction();
if (fctDef == null) {
xcodeml.addError("Unable to matchSeq the function/subroutine/module " + "definition including the current directive", _clawStart.getPragma().lineNo());
return false;
}
for (ReshapeInfo r : _clawStart.getReshapeClauseValues()) {
if (!fctDef.getSymbolTable().contains(r.getArrayName()) || !fctDef.getDeclarationTable().contains(r.getArrayName())) {
// Check in the parent def if present
if (!checkUpperDefinition(fctDef, r.getArrayName())) {
xcodeml.addError(String.format("Reshape variable %s not found in " + "the definition of %s", r.getArrayName(), fctDef.getName()), _clawStart.getPragma().lineNo());
return false;
}
}
}
}
return true;
}
Aggregations