use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class LoopExtraction method insertDeclaration.
/**
* Insert new declaration in the function definition.
*
* @param id The id used for insertion.
*/
private void insertDeclaration(String id) {
Xid inductionVarId = _fctDef.getSymbolTable().get(id);
if (inductionVarId == null) {
Xid copyId = _fctDefToExtract.getSymbolTable().get(id);
_fctDef.getSymbolTable().add(copyId);
}
Xnode inductionVarDecl = _fctDef.getDeclarationTable().get(id);
if (inductionVarDecl == null) {
Xnode copyDecl = _fctDefToExtract.getDeclarationTable().get(id);
_fctDef.getDeclarationTable().add(copyDecl);
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class LoopFusion method analyze.
/**
* Loop fusion analysis: - Without collapse clause: check whether the pragma
* statement is followed by a do statement. - With collapse clause: Find the n
* do statements following the pragma.
*
* @param xcodeml The XcodeML on which the transformations are applied.
* @param translator The translator used to applied the transformations.
* @return True if a do statement is found. False otherwise.
*/
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
Xnode outerLoop = _claw.getPragma().matchSibling(Xcode.F_DO_STATEMENT);
if (outerLoop == null) {
xcodeml.addError("Do statement missing after directive.", _claw.getPragma().lineNo());
return false;
}
_doStmt = new NestedDoStatement(outerLoop, _claw.getCollapseValue());
// With collapse clause
if (_claw.hasClause(ClawClause.COLLAPSE) && _claw.getCollapseValue() > 0 && _claw.getCollapseValue() > _doStmt.size()) {
xcodeml.addError("not enough do statements for collapse value", _claw.getPragma().lineNo());
return false;
}
return true;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class LoopInterchange method analyze.
/**
* Loop fusion analysis: - Find the different do statement that will be
* reordered. - Check the validity of the new ordering option.
*
* @param xcodeml The XcodeML on which the transformations are applied.
* @param translator The translator used to applied the transformations.
* @return True if the transformation can be performed. False otherwise.
*/
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
// Find next loop after pragma
Xnode outerDoStatement = _claw.getPragma().matchSibling(Xcode.F_DO_STATEMENT);
if (outerDoStatement == null) {
xcodeml.addError("top level loop not found", _claw.getPragma().lineNo());
return false;
}
int nestedLevel = _claw.values(ClawClause.INTERCHANGE_INDEXES) != null ? _claw.values(ClawClause.INTERCHANGE_INDEXES).size() : 2;
_doStmts = new NestedDoStatement(outerDoStatement, nestedLevel);
if (_claw.values(ClawClause.INTERCHANGE_INDEXES) != null) {
if (_claw.values(ClawClause.INTERCHANGE_INDEXES).size() != 3) {
xcodeml.addError("new-order option has not enough parameters", _claw.getPragma().lineNo());
}
List<String> inductions = _doStmts.getInductionVariables();
for (String idx : _claw.values(ClawClause.INTERCHANGE_INDEXES)) {
if (!inductions.contains(idx.toLowerCase())) {
xcodeml.addError("invalid induction variable in new-order option. " + idx, _claw.getPragma().lineNo());
return false;
}
}
} else {
if (_doStmts.size() < 2) {
xcodeml.addError("Not enough nested do statements to reorder", _claw.getPragma().lineNo());
}
}
return true;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class ScaCPUvectorizeGroup method flagIfStatementWithPromotion.
/**
* Check whether condition includes a promoted variables. If so, the ancestor
* node using the condition must be wrapped in a do statement.
*
* @return Set of vector block for flagged location.
*/
private Set<VectorBlock> flagIfStatementWithPromotion() {
Set<VectorBlock> blocks = new HashSet<>();
/* */
List<Xnode> conditions = _fctDef.body().matchAll(Xcode.CONDITION);
for (Xnode condition : conditions) {
if (Condition.dependsOn(condition, _arrayFieldsInOut) && !Condition.isAllocationRelated(condition)) {
Xnode ancestor = condition.ancestor();
Iterator<VectorBlock> iter = blocks.iterator();
boolean addFlaggedLocation = true;
while (iter.hasNext()) {
if (ancestor.isNestedIn(iter.next().getStartStmt())) {
addFlaggedLocation = false;
break;
}
}
if (addFlaggedLocation) {
blocks.add(new VectorBlock(ancestor));
}
}
}
return blocks;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class Sca method insertVariableToIterateOverDimension.
/**
* Insert the declaration of the different variables needed to iterate over the
* additional dimensions.
*
* @param xcodeml Current XcodeML program unit in which element are created.
*/
private void insertVariableToIterateOverDimension(Configuration cfg, XcodeProgram xcodeml) {
// Create type and declaration for iterations over the new dimensions
FbasicType bt = xcodeml.createBasicType(FortranType.INTEGER, Intent.IN);
xcodeml.getTypeTable().add(bt);
// For each dimension defined in the directive
for (DimensionDefinition dimension : _claw.getDefaultLayout(cfg)) {
if (!forceAssumedShapedArrayPromotion) {
// Create the parameter for the lower bound
if (dimension.getLowerBound().isVar()) {
xcodeml.createIdAndDecl(dimension.getLowerBound().getValue(), bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getLowerBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
// Create parameter for the upper bound
if (dimension.getUpperBound().isVar()) {
xcodeml.createIdAndDecl(dimension.getUpperBound().getValue(), bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getUpperBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
// Create the parameter for the iteration lower bound
if (dimension.getIterationLowerBound().isVar()) {
String itLowerBound = dimension.getIterationLowerBound().getValue();
if (!itLowerBound.equals(dimension.getLowerBound().getValue())) {
xcodeml.createIdAndDecl(itLowerBound, bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getIterationLowerBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
}
// Create parameter for the upper bound
if (dimension.getIterationUpperBound().isVar()) {
String itUpperBound = dimension.getIterationUpperBound().getValue();
if (!itUpperBound.equals(dimension.getUpperBound().getValue())) {
xcodeml.createIdAndDecl(itUpperBound, bt.getType(), XstorageClass.F_PARAM, _fctDef, DeclarationPosition.FIRST);
// Add parameter to the local type table
Xnode param = xcodeml.createAndAddParam(dimension.getIterationUpperBound().getValue(), bt.getType(), _fctType);
param.setBooleanAttribute(Xattr.IS_INSERTED, true);
}
}
}
// Create induction variable declaration
xcodeml.createIdAndDecl(dimension.getIdentifier(), FortranType.INTEGER, XstorageClass.F_LOCAL, _fctDef, DeclarationPosition.LAST);
}
}
Aggregations