use of claw.tatsu.directive.generator.DirectiveGenerator 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);
}
use of claw.tatsu.directive.generator.DirectiveGenerator in project claw-compiler by C2SM-RCM.
the class Directive method generateParallelLoopClause.
/**
* Generate directive directive for a parallel loop.
*
* @param xcodeml Object representation of the current XcodeML representation
* in which the pragmas will be generated.
* @param privates List of variables to be set privates.
* @param startStmt Start statement representing the beginning of the parallel
* region.
* @param endStmt End statement representing the end of the parallel region.
* @param collapse If value bigger than 0, a corresponding collapse constructs
* can be generated.
* @return Block with start and end directive if generated.
*/
public static Xblock generateParallelLoopClause(XcodeProgram xcodeml, List<String> privates, Xnode startStmt, Xnode endStmt, String extraDirective, int collapse) {
if (xcodeml.context().getGenerator().getDirectiveLanguage() == CompilerDirective.NONE) {
return null;
}
DirectiveGenerator dg = xcodeml.context().getGenerator();
Xnode startBlock = addPragmasBefore(xcodeml, dg.getStartParallelDirective(null), startStmt);
addPragmasBefore(xcodeml, dg.getStartLoopDirective(collapse, false, false, format(dg.getPrivateClause(privates), extraDirective)), startStmt);
Xnode endBlock = addPragmaAfter(xcodeml, dg.getEndParallelDirective(), endStmt);
addPragmaAfter(xcodeml, dg.getEndLoopDirective(), endStmt);
return new Xblock(startBlock, endBlock);
}
Aggregations