use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class DependenceAnalysisTest method perfectlyNestedNoDependencyTest.
@Test
public void perfectlyNestedNoDependencyTest() {
Context context = new TestContext();
// Load test data file
assertTrue(Files.exists(TestConstant.TEST_PERFECTLY_NESTED_NO_DEP));
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PERFECTLY_NESTED_NO_DEP, context);
assertNotNull(xcodeml);
// Match all the function definitions
List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
assertEquals(1, functions.size());
// Match all the pragmas
List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(1, pragmas.size());
// Analyze the pragma
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
// 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.F_DO_STATEMENT);
assertEquals(2, loops.size());
// Create an iteration space
try {
IterationSpace is = new IterationSpace(loops);
System.out.println();
assertEquals(2, is.getNbLevel());
is.printDebug(true);
assertTrue(is.isPerfectlyNested());
} catch (Exception e) {
fail();
}
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram 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() {
Context context = new TestContext();
// Load test data file
assertTrue(Files.exists(TestConstant.TEST_DEPENDENCE_3D));
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DEPENDENCE_3D, context);
assertNotNull(xcodeml);
// Match all the function definitions
List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
assertEquals(2, functions.size());
// Match all the pragmas
List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(1, pragmas.size());
// Analyze the pragma
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
// 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.F_DO_STATEMENT);
assertEquals(11, loops.size());
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class DependenceAnalysisTest method analyzeTest.
/**
* Test the analysis feature of the DependenceAnalysis class.
*/
@Test
public void analyzeTest() {
Context context = new TestContext();
// Load test data file
assertTrue(Files.exists(TestConstant.TEST_DEPENDENCE));
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DEPENDENCE, context);
assertNotNull(xcodeml);
// Match all the function definitions
List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
assertEquals(2, functions.size());
// Match all the pragma
List<Xnode> pragmas = xcodeml.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(1, pragmas.size());
// Get the function definition that interests us
Xnode fctDef = functions.get(0);
List<Xnode> loops = fctDef.matchAll(Xcode.F_DO_STATEMENT);
assertEquals(10, loops.size());
// Create dependence analysis object for each do statement
List<DependenceAnalysis> dependencies = new ArrayList<>();
for (Xnode loop : loops) {
try {
dependencies.add(new DependenceAnalysis(loop));
} catch (Exception e) {
fail();
}
}
// Assert the information for each do statement
assertTrue(dependencies.get(0).isIndependent());
assertTrue(dependencies.get(1).isIndependent());
assertTrue(dependencies.get(2).isIndependent());
assertFalse(dependencies.get(3).isIndependent());
assertEquals(1, dependencies.get(3).getDistanceVector());
assertEquals(DependenceDirection.BACKWARD, dependencies.get(3).getDirectionVector());
assertFalse(dependencies.get(4).isIndependent());
assertEquals(1, dependencies.get(4).getDistanceVector());
assertEquals(DependenceDirection.FORWARD, dependencies.get(4).getDirectionVector());
assertFalse(dependencies.get(5).isIndependent());
assertEquals(1, dependencies.get(5).getDistanceVector());
assertEquals(DependenceDirection.FORWARD, dependencies.get(5).getDirectionVector());
assertFalse(dependencies.get(6).isIndependent());
assertEquals(1, dependencies.get(6).getDistanceVector());
assertEquals(DependenceDirection.BACKWARD, dependencies.get(6).getDirectionVector());
assertTrue(dependencies.get(7).isIndependent());
assertTrue(dependencies.get(8).isIndependent());
assertTrue(dependencies.get(9).isIndependent());
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class ConditionTest method dependsOnTest.
@Test
public void dependsOnTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ASSIGN_STMT, context);
assertNotNull(xcodeml);
List<Xnode> nodes = xcodeml.matchAll(Xcode.F_IF_STATEMENT);
assertEquals(1, nodes.size());
Xnode ifStmt = nodes.get(0);
assertEquals(Xcode.F_IF_STATEMENT, ifStmt.opcode());
Xnode condition = ifStmt.matchDirectDescendant(Xcode.CONDITION);
assertNotNull(condition);
assertFalse(Condition.dependsOn(condition, Collections.emptySet()));
assertFalse(Condition.dependsOn(null, Collections.singleton("t")));
assertFalse(Condition.dependsOn(ifStmt, Collections.singleton("t")));
assertTrue(Condition.dependsOn(condition, Collections.singleton("t")));
assertFalse(Condition.dependsOn(condition, Collections.singleton("k")));
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class DimensionTest method boundDefinitionTest.
@Test
public void boundDefinitionTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
BoundDefinition lowerBound = new BoundDefinition("1", BoundDefinition.BoundType.LOWER);
BoundDefinition upperBound = new BoundDefinition("nend", BoundDefinition.BoundType.LOWER);
BoundDefinition step = new BoundDefinition("1", BoundDefinition.BoundType.STEP);
assertFalse(lowerBound.isVar());
assertTrue(upperBound.isVar());
assertFalse(step.isVar());
assertEquals(1, lowerBound.getIntValue());
assertEquals("nend", upperBound.getValue());
assertEquals(1, step.getIntValue());
Xnode lowerNode = lowerBound.generate(xcodeml);
assertNotNull(lowerNode);
assertNotNull(lowerNode.firstChild());
assertEquals(Xcode.F_INT_CONSTANT, lowerNode.firstChild().opcode());
assertEquals("1", lowerNode.firstChild().value());
Xnode upperNode = upperBound.generate(xcodeml);
assertNotNull(upperNode);
assertNotNull(upperNode.firstChild());
assertEquals(Xcode.VAR, upperNode.firstChild().opcode());
assertEquals("nend", upperNode.firstChild().value());
}
Aggregations