use of cx2x.translator.language.common.ClawConstraint in project claw-compiler by C2SM-RCM.
the class LoopFusion method canBeTransformedWith.
/**
* Check whether the loop fusion unit can be merged with the given loop fusion
* unit. To be able to be transformed together, the loop fusion units must
* share the same parent block, the same iteration range, the same group
* option and both units must be not transformed.
*
* @param transformation The other loop fusion unit to be merge with this one.
* @return True if the two loop fusion unit can be merge together.
*/
@Override
public boolean canBeTransformedWith(XcodeProgram xcodeml, Transformation transformation) {
if (!(transformation instanceof LoopFusion)) {
return false;
}
LoopFusion other = (LoopFusion) transformation;
// No loop is transformed already
if (this.isTransformed() || other.isTransformed()) {
return false;
}
// Loop must share the same group option
if (!hasSameGroupClause(other)) {
return false;
}
ClawConstraint currentConstraint = ClawConstraint.DIRECT;
if (_claw.hasConstraintClause() && other.getLanguageInfo().hasConstraintClause()) {
// Check the constraint clause. Must be identical if set.
if (_claw.getConstraintClauseValue() != other.getLanguageInfo().getConstraintClauseValue()) {
return false;
}
currentConstraint = _claw.getConstraintClauseValue();
} else {
if (_claw.hasConstraintClause() || other.getLanguageInfo().hasConstraintClause()) {
// Constraint are not consistent
return false;
}
}
// is set to none, there are note checked.
if (currentConstraint == ClawConstraint.DIRECT) {
// Only pragma statement can be between the two loops.
if (!XnodeUtil.isDirectSibling(_doStmts[0], other.getDoStmtAtIndex(0), Collections.singletonList(Xcode.FPRAGMASTATEMENT))) {
return false;
}
} else {
xcodeml.addWarning("Unconstrained loop-fusion generated", Arrays.asList(_claw.getPragma().lineNo(), other.getLanguageInfo().getPragma().lineNo()));
}
// Loops can only be merged if they are at the same level
if (!XnodeUtil.hasSameParentBlock(_doStmts[0], other.getDoStmtAtIndex(0))) {
return false;
}
if (_claw.hasCollapseClause() && _claw.getCollapseValue() > 0) {
for (int i = 0; i < _claw.getCollapseValue(); ++i) {
if (!XnodeUtil.hasSameIndexRange(_doStmts[i], other.getDoStmtAtIndex(i))) {
return false;
}
}
return true;
} else {
// Loop must share the same iteration range
return XnodeUtil.hasSameIndexRange(_doStmts[0], other.getDoStmtAtIndex(0));
}
}
Aggregations