use of cx2x.translator.transformer.ClawTransformer in project claw-compiler by C2SM-RCM.
the class DependenceAnalysisTest method analyzeTest3d.
/**
* Test the IterationSpace feature of fusion and check the results.
*/
@Test
public void analyzeTest3d() {
// Load test data file
File f = new File(TestConstant.TEST_DEPENDENCE_3D);
assertTrue(f.exists());
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DEPENDENCE_3D);
assertNotNull(xcodeml);
// Match all the function definitions
List<Xnode> functions = xcodeml.matchAll(Xcode.FFUNCTIONDEFINITION);
assertEquals(2, functions.size());
// Match all the pragmas
List<Xnode> pragmas = xcodeml.matchAll(Xcode.FPRAGMASTATEMENT);
assertEquals(1, pragmas.size());
// Analyze the pragma
Configuration configuration = new Configuration(AcceleratorDirective.OPENACC, Target.GPU);
configuration.setMaxColumns(80);
ClawTransformer transformer = new ClawTransformer(configuration);
AcceleratorGenerator generator = AcceleratorHelper.createAcceleratorGenerator(configuration);
ClawLanguage main = null;
try {
main = ClawLanguage.analyze(pragmas.get(0), generator, Target.GPU);
} catch (Exception e) {
fail();
}
// Get the function definition that interests us
Xnode fctDef = functions.get(0);
// Match all the do statements in the function
List<Xnode> loops = fctDef.matchAll(Xcode.FDOSTATEMENT);
assertEquals(11, loops.size());
// Create an iteration space
try {
IterationSpace is = new IterationSpace(loops);
is.tryFusion(xcodeml, transformer, main);
System.out.println();
System.out.println("Iteration space before fusion");
is.printDebug(true);
loops = fctDef.matchAll(Xcode.FDOSTATEMENT);
assertEquals(8, loops.size());
is.reload(loops);
System.out.println();
System.out.println("Iteration space after fusion");
is.printDebug(true);
} catch (Exception e) {
fail();
}
}
use of cx2x.translator.transformer.ClawTransformer in project claw-compiler by C2SM-RCM.
the class Kcaching method applyInitClause.
/**
* Apply the init clause if it was part of the kcache directive.
*
* @param xcodeml Current program in which the transformation is
* performed.
* @param transformer Current transformer used to store elements information.
* @param cacheVar Newly created cache variable that will be used for the
* initialization (rhs of the assign statement). Element
* will be cloned before insertion.
* @param arrayRef Array reference to be modified that will be
* used for the initialization (lhs of the assign
* statement). Element will be cloned before insertion.
*/
private void applyInitClause(XcodeProgram xcodeml, Transformer transformer, Xnode cacheVar, Xnode arrayRef) {
if (_claw.hasInitClause()) {
ClawTransformer ct = (ClawTransformer) transformer;
Xnode initIfStmt = (Xnode) ct.hasElement(_doStmt);
if (initIfStmt == null) {
// If statement has not been created yet so we do it here
initIfStmt = xcodeml.createIfThen();
XnodeUtil.copyEnhancedInfo(_claw.getPragma(), initIfStmt);
Xnode logEq = new Xnode(Xcode.LOGEQEXPR, xcodeml);
// Set lhs of equality
logEq.append(_doStmt.matchDirectDescendant(Xcode.VAR), true);
// Set rhs of equality
logEq.append(_doStmt.matchDirectDescendant(Xcode.INDEXRANGE).matchDirectDescendant(Xcode.LOWERBOUND).child(0), true);
initIfStmt.matchDirectDescendant(Xcode.CONDITION).append(logEq, false);
_doStmt.body().insert(initIfStmt, false);
ct.storeElement(_doStmt, initIfStmt);
}
Xnode initAssignment = new Xnode(Xcode.FASSIGNSTATEMENT, xcodeml);
// set rhs
initAssignment.append(cacheVar, true);
// set lhs
initAssignment.append(arrayRef, true);
// Add assignment in the "then" body element
initIfStmt.matchDirectDescendant(Xcode.THEN).body().append(initAssignment, false);
}
}
use of cx2x.translator.transformer.ClawTransformer in project claw-compiler by C2SM-RCM.
the class Parallelize method transform.
@Override
public void transform(XcodeProgram xcodeml, Transformer transformer, Transformation other) throws Exception {
// Handle PURE function / subroutine
ClawTransformer trans = (ClawTransformer) transformer;
boolean pureRemoved = XnodeUtil.removePure(_fctDef, _fctType);
if (trans.getConfiguration().isForcePure() && pureRemoved) {
throw new IllegalTransformationException("PURE specifier cannot be removed", _fctDef.lineNo());
} else if (pureRemoved) {
String fctName = _fctDef.matchDirectDescendant(Xcode.NAME).value();
System.out.println("Warning: PURE specifier removed from function " + fctName + " at line " + _fctDef.lineNo() + ". Transformation and " + "code generation applied to it.");
}
// Prepare the array index that will be added to the array references.
prepareArrayIndexes(xcodeml);
// Insert the declarations of variables to iterate over the new dimensions.
insertVariableToIterateOverDimension(xcodeml);
// Promote all array fields with new dimensions.
promoteFields(xcodeml);
// Adapt array references.
if (_claw.hasOverDataClause()) {
for (int i = 0; i < _claw.getOverDataClauseValues().size(); ++i) {
TransformationHelper.adaptArrayReferences(_claw.getOverDataClauseValues().get(i), i, _fctDef.body(), _promotions, _beforeCrt, _inMiddle, _afterCrt, xcodeml);
}
} else {
TransformationHelper.adaptArrayReferences(_arrayFieldsInOut, DEFAULT_OVER, _fctDef.body(), _promotions, _beforeCrt, _inMiddle, _afterCrt, xcodeml);
}
// Delete the pragma
_claw.getPragma().delete();
// Apply specific target transformation
if (_claw.getTarget() == Target.GPU) {
transformForGPU(xcodeml);
} else if (_claw.getTarget() == Target.CPU) {
transformForCPU(xcodeml);
}
if (!_fctType.getBooleanAttribute(Xattr.IS_PRIVATE)) {
XmoduleDefinition modDef = _fctDef.findParentModule();
if (modDef != null) {
TransformationHelper.updateModuleSignature(xcodeml, _fctDef, _fctType, modDef, _claw, transformer, false);
}
}
}
Aggregations