use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class OpenAccContinuation method createAndInsertPragma.
/**
* Create a new pragma node and insert it after the hook.
*
* @param xcodeml Current XcodeML file unit.
* @param hook Hook node. New node will be inserted after this one.
* @param lineIndex Line index specify the offset of the line number for the
* new node from the original pragma node.
* @param value Value of the pragma node.
* @param continued If true, continuation symbol is added at the end of the
* line.
* @return The newly created node to be able to insert after it.
*/
private Xnode createAndInsertPragma(XcodeProgram xcodeml, Xnode hook, int lineIndex, String value, boolean continued) {
Xnode p = new Xnode(Xcode.FPRAGMASTATEMENT, xcodeml);
p.setFilename(getDirective().getPragma().filename());
p.setLine(getDirective().getPragma().lineNo() + lineIndex);
if (continued) {
if (value.contains(ClawConstant.OPENACC_PREFIX)) {
value = value.replace(ClawConstant.OPENACC_PREFIX, "");
}
p.setValue(ClawConstant.OPENACC_PREFIX + " " + value.trim() + " " + ClawConstant.CONTINUATION_LINE_SYMBOL);
} else {
p.setValue(ClawConstant.OPENACC_PREFIX + " " + value.trim());
}
hook.insertAfter(p);
getDirective().getPragma().delete();
return p;
}
use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class LoopHoist method reloadDoStmts.
/**
* Relocated nested do statement inside a group of do statement.
*
* @param g The group of do statement.
* @param newStart The new outer do statement.
* @throws IllegalTransformationException If the nested group doesn't match
* the correct size.
*/
private void reloadDoStmts(LoopHoistDoStmtGroup g, Xnode newStart) throws IllegalTransformationException {
g.getDoStmts()[0] = newStart;
for (int j = 1; j < g.getDoStmts().length; ++j) {
Xnode next = g.getDoStmts()[j - 1].body().matchDirectDescendant(Xcode.FDOSTATEMENT);
if (next == null) {
throw new IllegalTransformationException("Unable to matchSeq enough nested do statements", _clawStart.getPragma().lineNo());
}
g.getDoStmts()[j] = next;
}
}
use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class ClawLanguageTest method analyzeValidClawLoopExtract.
/**
* Assert the result for valid loop extract CLAW directive
*
* @param raw Raw string value of the CLAW directive to be analyzed.
* @param induction Induction var to be found.
* @param lower Lower bound value to be found.
* @param upper Upper bound value to be found.
* @param step Step valu to be found if any.
*/
private ClawLanguage analyzeValidClawLoopExtract(String raw, String induction, String lower, String upper, String step, List<Target> targets) {
try {
Xnode p = XmlHelper.createXpragma();
p.setValue(raw);
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage l = ClawLanguage.analyze(p, generator, Target.GPU);
assertEquals(ClawDirective.LOOP_EXTRACT, l.getDirective());
assertEquals(induction, l.getRange().getInductionVar());
assertEquals(lower, l.getRange().getLowerBound());
assertEquals(upper, l.getRange().getUpperBound());
if (step != null) {
assertEquals(step, l.getRange().getStep());
}
assertTargets(l, targets);
return l;
} catch (IllegalDirectiveException idex) {
System.err.println(idex.getMessage());
fail();
return null;
}
}
use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class ClawXcodeMlTranslator method analyze.
/**
* Analysis the XcodeML code and produce a list of applicable transformation.
*/
public void analyze() {
_program = XcodeProgram.createFromFile(_xcodemlInputFile);
if (_program == null) {
abort();
}
// Check all pragma found in the program
for (Xnode pragma : _program.getAllStmt(Xcode.FPRAGMASTATEMENT)) {
// pragma does not start with the CLAW prefix
if (!ClawLanguage.startsWithClaw(pragma)) {
// Compile guard removal
if (_generator != null && _generator.isCompileGuard(pragma.value())) {
pragma.delete();
} else // Handle special transformation of OpenACC line continuation
if (pragma.value().toLowerCase().startsWith(ClawConstant.OPENACC_PREFIX)) {
OpenAccContinuation t = new OpenAccContinuation(new AnalyzedPragma(pragma));
addOrAbort(t);
}
// Not CLAW pragma, we do nothing
continue;
}
try {
// Analyze the raw pragma with the CLAW language parser
ClawLanguage analyzedPragma = ClawLanguage.analyze(pragma, _generator, _target);
// Create transformation object based on the directive
switch(analyzedPragma.getDirective()) {
case ARRAY_TO_CALL:
addOrAbort(new ArrayToFctCall(analyzedPragma));
break;
case KCACHE:
addOrAbort(new Kcaching(analyzedPragma));
break;
case LOOP_FUSION:
addOrAbort(new LoopFusion(analyzedPragma));
break;
case LOOP_INTERCHANGE:
addOrAbort(new LoopInterchange(analyzedPragma));
break;
case LOOP_EXTRACT:
addOrAbort(new LoopExtraction(analyzedPragma));
break;
case LOOP_HOIST:
HandleBlockDirective(analyzedPragma);
break;
case ARRAY_TRANSFORM:
HandleBlockDirective(analyzedPragma);
break;
case REMOVE:
HandleBlockDirective(analyzedPragma);
break;
case PARALLELIZE:
if (analyzedPragma.hasForwardClause()) {
addOrAbort(new ParallelizeForward(analyzedPragma));
} else {
addOrAbort(new Parallelize(analyzedPragma));
}
break;
case PRIMITIVE:
addOrAbort(new DirectivePrimitive(analyzedPragma));
break;
case IF_EXTRACT:
addOrAbort(new IfExtract(analyzedPragma));
break;
// driver handled directives
case IGNORE:
case VERBATIM:
break;
default:
_program.addError("Unrecognized CLAW directive", pragma.lineNo());
abort();
}
} catch (IllegalDirectiveException ex) {
System.err.println(ex.getMessage());
abort();
}
}
// Clean up block transformation map
for (Map.Entry<ClawDirectiveKey, ClawLanguage> entry : _blockDirectives.entrySet()) {
createBlockDirectiveTransformation(entry.getValue(), null);
}
// Add utility transformation
addOrAbort(new XcodeMLWorkaround(new ClawLanguage(_program)));
// Analysis done, the transformation can be performed.
_canTransform = true;
}
use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.
the class DependenceAnalysis method analyze.
/**
* Perform the analysis of the dependence on the given do statements.
*
* @throws Exception If the given node is null or is not a do statement node.
*/
private void analyze() throws Exception {
if (_mainLoop == null || _mainLoop.opcode() != Xcode.FDOSTATEMENT) {
throw new Exception("Analysis only on FdoStatement node");
}
Xnode inductionVarNode = _mainLoop.matchDirectDescendant(Xcode.VAR);
_inductionVariable = inductionVarNode.value();
Xnode body = _mainLoop.matchDescendant(Xcode.BODY);
List<Xnode> arrayRefs = body.matchAll(Xcode.FARRAYREF);
_distanceVector = 0;
_directionVector = DependenceDirection.NONE;
for (Xnode arrayRef : arrayRefs) {
List<Xnode> arrayIndexes = arrayRef.matchAll(Xcode.ARRAYINDEX);
for (Xnode arrayIndex : arrayIndexes) {
if (arrayIndex.firstChild().opcode() == Xcode.MINUSEXPR || arrayIndex.firstChild().opcode() == Xcode.PLUSEXPR) {
Xnode expr = arrayIndex.firstChild();
Xnode var = expr.firstChild();
Xnode intConst = expr.lastChild();
if (var.value().endsWith(_inductionVariable)) {
_distanceVector = Integer.parseInt(intConst.value());
switch(arrayIndex.firstChild().opcode()) {
case MINUSEXPR:
_directionVector = DependenceDirection.BACKWARD;
break;
case PLUSEXPR:
_directionVector = DependenceDirection.FORWARD;
break;
}
}
}
}
}
}
Aggregations