Search in sources :

Example 1 with XcodeProgram

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;
    }
}
Also used : Serialization(claw.wani.serialization.Serialization) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall) ClawTranslator(claw.wani.x2t.translator.ClawTranslator) Transformation(claw.shenron.transformation.Transformation) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Directive(claw.tatsu.directive.common.Directive) Xblock(claw.tatsu.xcodeml.abstraction.Xblock) ClawPragma(claw.wani.language.ClawPragma) Range(claw.tatsu.primitive.Range) ClawBlockTransformation(claw.wani.transformation.ClawBlockTransformation) XnodeUtil(claw.tatsu.xcodeml.xnode.XnodeUtil) ArrayList(java.util.ArrayList) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) HashSet(java.util.HashSet) ClawClause(claw.wani.language.ClawClause) Target(claw.tatsu.common.Target) Set(java.util.Set) Context(claw.tatsu.common.Context) Translator(claw.shenron.translator.Translator) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) Collectors(java.util.stream.Collectors) SerializationStep(claw.wani.serialization.SerializationStep) FortranType(claw.tatsu.xcodeml.xnode.fortran.FortranType) List(java.util.List) Xid(claw.tatsu.xcodeml.xnode.common.Xid) Xcode(claw.tatsu.xcodeml.xnode.common.Xcode) Xintrinsic(claw.tatsu.xcodeml.xnode.fortran.Xintrinsic) DataMovement(claw.tatsu.directive.common.DataMovement) Xattr(claw.tatsu.xcodeml.xnode.common.Xattr) XstorageClass(claw.tatsu.xcodeml.xnode.common.XstorageClass) Configuration(claw.wani.x2t.configuration.Configuration) Xscope(claw.tatsu.xcodeml.xnode.common.Xscope) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) Collections(java.util.Collections) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode)

Example 2 with XcodeProgram

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();
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 3 with XcodeProgram

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));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 4 with XcodeProgram

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"));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 5 with XcodeProgram

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());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Aggregations

XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)25 Context (claw.tatsu.common.Context)24 TestContext (helper.Utils.TestContext)22 Test (org.junit.Test)22 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)20 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)7 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)4 ArrayList (java.util.ArrayList)3 Transformation (claw.shenron.transformation.Transformation)2 Translator (claw.shenron.translator.Translator)2 Target (claw.tatsu.common.Target)2 DataMovement (claw.tatsu.directive.common.DataMovement)2 Directive (claw.tatsu.directive.common.Directive)2 Range (claw.tatsu.primitive.Range)2 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)2 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)2 XnodeUtil (claw.tatsu.xcodeml.xnode.XnodeUtil)2 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)2 Xcode (claw.tatsu.xcodeml.xnode.common.Xcode)2 Xid (claw.tatsu.xcodeml.xnode.common.Xid)2