use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class ExpandNotation method analyze.
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
if (_clawEnd != null) {
// Block transformation
// TODO Analyse dependency between assignments. cf array9 example.
// Find assignments with vector notation
List<Xnode> foundAssignments = XnodeUtil.getArrayAssignInBlock(_clawStart.getPragma(), _clawEnd.getPragma());
if (foundAssignments.isEmpty()) {
xcodeml.addError("No vector notation assignments found in the expand block.", _clawStart.getPragma().lineNo());
return false;
}
/*
* Using a structure of list of list of assignments to group together the expand
* notation that share an identical iteration range.
*/
// 1st group always exists
_groupedAssignStmts.add(new ArrayList<>());
int crtGroup = 0;
Xnode refArrayRef = foundAssignments.get(0).matchSeq(Xcode.F_ARRAY_REF);
List<Xnode> refRanges = XnodeUtil.getIdxRangesFromArrayRef(refArrayRef);
// First vector notation is automatically in the 1st group as 1st element
_groupedAssignStmts.get(crtGroup).add(foundAssignments.get(0));
_groupIterationRanges.add(refRanges);
for (int i = 1; i < foundAssignments.size(); ++i) {
Xnode arrayRef = foundAssignments.get(i).matchSeq(Xcode.F_ARRAY_REF);
List<Xnode> ranges = XnodeUtil.getIdxRangesFromArrayRef(arrayRef);
// ranges are not identical so
if (!Range.compare(refRanges, ranges)) {
refRanges = ranges;
++crtGroup;
_groupedAssignStmts.add(new ArrayList<>());
_groupIterationRanges.add(refRanges);
}
_groupedAssignStmts.get(crtGroup).add(foundAssignments.get(i));
}
return true;
} else {
// single transformation
// pragma must be followed by an assign statement
Xnode stmt = _clawStart.getPragma().matchSibling(Xcode.F_ASSIGN_STATEMENT);
if (stmt == null) {
xcodeml.addError("Directive not followed by an assign statement", _clawStart.getPragma().lineNo());
return false;
}
// Check if we are dealing with an vector notation
if (!Xnode.isOfCode(stmt.child(0), Xcode.F_ARRAY_REF)) {
xcodeml.addError("Assign statement is not an array notation", _clawStart.getPragma().lineNo());
return false;
}
List<Xnode> ranges = stmt.firstChild().children().stream().filter(x -> x.is(Xcode.INDEX_RANGE)).collect(Collectors.toList());
if (ranges.isEmpty()) {
xcodeml.addError("Assign statement is not an array notation", _clawStart.getPragma().lineNo());
return false;
}
_groupedAssignStmts.add(Collections.singletonList(stmt));
_groupIterationRanges.add(ranges);
return true;
}
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class PragmaTest method splitByContTest2.
@Test
public void splitByContTest2() {
Context context = new TestContext();
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
assertFalse(fctDefs.isEmpty());
FfunctionDefinition fd = fctDefs.get(0);
assertNotNull(fd.body());
List<Xnode> previous = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
Xnode p = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
fd.body().append(p);
p.setValue("acc data copyin(a) acc present(b)");
try {
Pragma.splitByCont(p, CompilerDirective.OPENACC.getPrefix(), xcodeml);
List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(previous.size() + 2, splittedPragma.size());
} catch (IllegalTransformationException e) {
fail();
}
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class PragmaTest method getPragmaPrefixTest.
@Test
public void getPragmaPrefixTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p1.setValue(CompilerDirective.OPENACC.getPrefix());
assertEquals(CompilerDirective.OPENACC.getPrefix(), Pragma.getPrefix(p1));
Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p2.setValue(CompilerDirective.OPENMP.getPrefix());
assertEquals(CompilerDirective.OPENMP.getPrefix(), Pragma.getPrefix(p2));
Xnode p3 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p3.setValue("");
assertEquals("", Pragma.getPrefix(p3));
Xnode p4 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
assertEquals("", Pragma.getPrefix(p4));
Xnode p5 = xcodeml.createNode(Xcode.F_DO_STATEMENT);
p5.setValue("acc");
assertEquals("", Pragma.getPrefix(p5));
assertEquals("", Pragma.getPrefix(null));
Xnode p6 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p6.setValue(CompilerDirective.OPENACC.getPrefix() + " loop private(a)");
assertEquals(CompilerDirective.OPENACC.getPrefix(), Pragma.getPrefix(p6));
p6.setValue(CompilerDirective.OPENMP.getPrefix() + " target");
assertEquals(CompilerDirective.OPENMP.getPrefix(), Pragma.getPrefix(p6));
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class AssignStatementTest method gatherAssignmentTest1.
@Test
public void gatherAssignmentTest1() {
Context context = new TestContext();
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ASSIGN_STMT, context);
assertNotNull(xcodeml);
List<Xnode> nodes = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
assertEquals(1, nodes.size());
assertEquals(Xcode.F_FUNCTION_DEFINITION, nodes.get(0).opcode());
FfunctionDefinition fctDef = new FfunctionDefinition(nodes.get(0));
List<AssignStatement> assignStatements = fctDef.gatherAssignStatements();
assertEquals(2, assignStatements.size());
assertTrue(assignStatements.get(0).isChildOf(Xcode.F_IF_STATEMENT));
assertFalse(assignStatements.get(1).isChildOf(Xcode.F_IF_STATEMENT));
Set<String> vars = assignStatements.get(0).getVarNames();
assertEquals(2, vars.size());
assertTrue(vars.contains("t"));
assertTrue(vars.contains("q"));
}
use of claw.tatsu.xcodeml.xnode.common.XcodeProgram in project claw-compiler by C2SM-RCM.
the class AnalyzedPragmaTest method ctorTest.
@Test
public void ctorTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p1.setValue("acc parallel");
Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
p2.setValue("acc end parallel");
AnalyzedPragma ap1 = new AnalyzedPragma(p1);
assertFalse(ap1.isEndPragma());
assertNotNull(ap1.getPragma());
assertEquals("acc parallel", ap1.getPragma().value());
ap1.setEndPragma();
assertTrue(ap1.isEndPragma());
AnalyzedPragma ap2 = new AnalyzedPragma();
assertFalse(ap2.isEndPragma());
assertNull(ap2.getPragma());
ap2.setPragma(p2);
ap2.setEndPragma();
assertTrue(ap2.isEndPragma());
assertNotNull(ap2.getPragma());
}
Aggregations