Search in sources :

Example 6 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition 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 7 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition 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 8 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition in project claw-compiler by C2SM-RCM.

the class XdeclTableTest method addRemoveTest.

@Test
public void addRemoveTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = createFromFile(context);
    List<Xnode> functions = xcodeml.matchAll(Xcode.F_FUNCTION_DEFINITION);
    assertEquals(1, functions.size());
    FfunctionDefinition fctDef = new FfunctionDefinition(functions.get(0));
    assertNotNull(fctDef);
    XdeclTable fctDecl = fctDef.getDeclarationTable();
    assertNotNull(fctDecl);
    String key1 = "key1";
    String key2 = "key2";
    String key3 = "key3";
    // Add
    Xnode varDecl1 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key1);
    fctDecl.add(varDecl1);
    assertNotNull(fctDecl.get(key1));
    // Replace existing one
    Xnode varDecl2 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key1);
    fctDecl.replace(varDecl2, key1);
    assertNotNull(fctDecl.get(key1));
    assertEquals(varDecl2.getType(), fctDecl.get(key1).getType());
    // Replace non-existing - like add
    Xnode varDecl3 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key2);
    fctDecl.replace(varDecl3, key2);
    assertNotNull(fctDecl.get(key2));
    assertEquals(varDecl3.getType(), fctDecl.get(key2).getType());
    // Add at the beginning of the table
    Xnode varDecl4 = xcodeml.createVarDecl(xcodeml.getTypeTable().generateHash(FortranType.INTEGER), key3);
    fctDecl.addFirst(varDecl4);
    assertEquals(varDecl4.getType(), fctDecl.firstChild().getType());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Example 9 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition in project claw-compiler by C2SM-RCM.

the class Directive method generateRoutineDirectives.

/**
 * Generate all corresponding pragmas to be applied to an accelerated
 * function/subroutine.
 *
 * @param xcodeml Object representation of the current XcodeML representation in
 *                which the pragmas will be generated.
 * @param fctDef  Function/subroutine in which directive directives are
 *                generated.
 */
public static void generateRoutineDirectives(XcodeProgram xcodeml, FfunctionDefinition fctDef) {
    DirectiveGenerator dirGen = xcodeml.context().getGenerator();
    if (dirGen.getDirectiveLanguage() == CompilerDirective.NONE) {
        // Do nothing if "none" is selected for directive
        return;
    }
    // Find all fct call in the current transformed fct
    List<FunctionCall> fctCalls = fctDef.matchAll(Xcode.FUNCTION_CALL).stream().filter(f -> !f.getBooleanAttribute(Xattr.IS_INTRINSIC)).map(FunctionCall::new).collect(Collectors.toList());
    for (FunctionCall fctCall : fctCalls) {
        // Do nothing for intrinsic fct or null fctName
        if (fctCall.getFctName() == null) {
            continue;
        }
        Optional<FfunctionDefinition> calledFctDef = Function.findFunctionDefinitionFromFctCall(xcodeml, fctDef, fctCall);
        if (calledFctDef.isPresent()) {
            // TODO - Check that the directive is not present yet.
            // TODO - Directive.hasDirectives(calledFctDef)
            addPragmasBefore(xcodeml, dirGen.getRoutineDirective(true), calledFctDef.get().body().child(0));
            Message.debug(xcodeml.context(), dirGen.getPrefix() + "generated routine seq directive for " + fctCall.getFctName() + " subroutine/function.");
        } else {
            // Could not generate directive for called function.
            xcodeml.addWarning(fctCall.getFctName() + " has not been found. " + "Automatic routine directive generation could not be done.", fctCall.lineNo());
        }
    }
}
Also used : FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) DirectiveGenerator(claw.tatsu.directive.generator.DirectiveGenerator) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall)

Example 10 with FfunctionDefinition

use of claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition in project claw-compiler by C2SM-RCM.

the class Pragma method moveInExecution.

/**
 * If the first pragma statement is located as the first statement of the
 * execution block, the OMNI Compiler front-end places it with the declaration
 * block. If this doesn't make sense for a specific pragma, this method will
 * move it to the execution block.
 *
 * @param pragma The pragma to be moved.
 */
public static void moveInExecution(Xnode pragma) {
    if (!Xnode.isOfCode(pragma, Xcode.F_PRAGMA_STATEMENT)) {
        return;
    }
    if (Xnode.isOfCode(pragma.ancestor(), Xcode.DECLARATIONS)) {
        FfunctionDefinition fdef = pragma.findParentFunction();
        if (fdef != null) {
            if (Xnode.isOfCode(fdef.body().firstChild(), Xcode.F_PRAGMA_STATEMENT)) {
                Xnode hook = null;
                Xnode crtNode = fdef.body().firstChild();
                while (Xnode.isOfCode(crtNode, Xcode.F_PRAGMA_STATEMENT) && pragma.lineNo() > crtNode.lineNo()) {
                    hook = crtNode;
                    crtNode = crtNode.nextSibling();
                }
                if (hook != null) {
                    hook.insertAfter(pragma);
                } else {
                    fdef.body().append(pragma);
                }
            } else {
                fdef.body().insert(pragma);
            }
        }
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)

Aggregations

FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)27 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)16 Context (claw.tatsu.common.Context)13 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)11 Test (org.junit.Test)10 TestContext (helper.Utils.TestContext)9 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)6 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)6 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)6 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)3 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)3 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)3 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)3 HoistedNestedDoStatement (claw.tatsu.xcodeml.abstraction.HoistedNestedDoStatement)2 ReshapeInfo (claw.tatsu.xcodeml.abstraction.ReshapeInfo)2 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)2 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)2 Configuration (claw.wani.x2t.configuration.Configuration)2 Transformation (claw.shenron.transformation.Transformation)1