Search in sources :

Example 36 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class ScaForward method analyzeForward.

/**
 * Analyze the directive when it is used just before a function call.
 *
 * @param xcodeml Current XcodeML file unit.
 * @return True if the analysis succeed. False otherwise.
 */
private boolean analyzeForward(XcodeProgram xcodeml) {
    final Context context = xcodeml.context();
    if (_fCall == null) {
        xcodeml.addError("Directive is not followed by a fct call.", _claw.getPragma());
        return false;
    }
    detectParameterMapping(context, _fCall);
    _calledFctName = _fCall.getFctName();
    FfunctionDefinition fctDef = xcodeml.getGlobalDeclarationsTable().getFunctionDefinition(_calledFctName);
    FfunctionDefinition parentFctDef = _claw.getPragma().findParentFunction();
    if (parentFctDef == null) {
        xcodeml.addError("SCA directive is not nested in a " + "function/subroutine.", _claw.getPragma());
        return false;
    }
    FmoduleDefinition parentModule = parentFctDef.findParentModule();
    if (_fCall.isTbpCall()) {
        /*
             * If type is a FbasicType element for a type-bound procedure, we have to
             * matchSeq the correct function in the typeTable. TODO if there is a rename.
             * TODO generic call
             */
        Xid id = parentModule.getSymbolTable().get(_calledFctName);
        if (id == null) {
            List<Xnode> uses = parentFctDef.getDeclarationTable().uses();
            uses.addAll(parentModule.getDeclarationTable().uses());
            if (!findInModule(context, uses)) {
                xcodeml.addError("Function definition not found in module ", _claw.getPragma());
                return false;
            }
        } else {
            _fctType = xcodeml.getTypeTable().getFunctionType(id);
        }
    } else {
        if (xcodeml.getTypeTable().isFunctionType(_fCall)) {
            _fctType = xcodeml.getTypeTable().getFunctionType(_fCall);
        } else {
            xcodeml.addError("Unsupported type of XcodeML/F element for the function " + _calledFctName, _claw.getPragma());
            return false;
        }
    }
    /*
         * Workaround for a bug in OMNI Compiler. Look at test case claw/abstraction10.
         * In this test case, the XcodeML/F intermediate representation for the function
         * call points to a FfunctionType element with no parameters. Thus, we have to
         * matchSeq the correct FfunctionType for the same function/subroutine with the
         * same name in the module symbol table.
         */
    if (_fctType.getParameters().isEmpty()) {
        /*
             * If not, try to matchSeq the correct FfunctionType in the module definitions
             */
        Xid id = (parentModule == null) ? null : parentModule.getSymbolTable().get(_calledFctName);
        if (id == null) {
            // Function is not located in the current module.
            List<Xnode> uses = parentFctDef.getDeclarationTable().uses();
            if (parentModule != null) {
                uses.addAll(parentModule.getDeclarationTable().uses());
            }
            if (!findInModule(context, uses)) {
                xcodeml.addError(String.format("Function definition %s not found in module.", _calledFctName), _claw.getPragma());
                return false;
            }
        } else {
            _fctType = xcodeml.getTypeTable().getFunctionType(id);
            if (_fctType == null) {
                xcodeml.addError("Called function cannot be found in the same module ", _claw.getPragma());
                return false;
            }
        }
    }
    // end of workaround
    _callingFctName = parentFctDef.getName();
    if (_fctType != null && fctDef != null) {
        _localFct = true;
    } else {
        // Has been found already
        if (_fctType != null && _calledFctName == null) {
            return true;
        }
        // Get all the use statements in the fct and module definitions
        List<Xnode> uses = parentFctDef.getDeclarationTable().uses();
        if (parentModule != null) {
            uses.addAll(parentModule.getDeclarationTable().uses());
        }
        // Try to locate the fct in the modules defined in use statements
        if (findInModule(context, uses)) {
            return true;
        }
        xcodeml.addError("Function signature not found in the current module.", _claw.getPragma());
        return false;
    }
    return true;
}
Also used : Context(claw.tatsu.common.Context) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) Xid(claw.tatsu.xcodeml.xnode.common.Xid) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) FmoduleDefinition(claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)

Example 37 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class FieldTest method promoteTest.

@Test
public void promoteTest() {
    DimensionDefinition dim1 = new DimensionDefinition("dim1", "1", "30");
    DimensionDefinition dim2 = new DimensionDefinition("dim2", "1", "40");
    List<DimensionDefinition> dimensions1 = Collections.singletonList(dim1);
    List<DimensionDefinition> dimensions2 = Arrays.asList(dim1, dim2);
    Context context = new TestContext();
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PROMOTION, context);
    assertNotNull(xcodeml);
    List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
    assertEquals(1, fctDefs.size());
    FfunctionDefinition fctDef = fctDefs.get(0);
    assertEquals("sub1", fctDef.getName());
    // Scalar to array promotion with 1 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("s1", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("s2", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("s3", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
    // Scalar to array promotion with 2 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("s4", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("s5", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("s6", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
    // Promotion with 1 additional dimension
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("a", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 30, 1, 10, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("b", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 10, 1, 20, 1, 30 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("c", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 10, 1, 30, 1, 20 });
    // Promotion with 2 additional dimensions at the same position
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    performAndAssertPromotion("d", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 40, 1, 10, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("e", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 20, 1, 30, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("f", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 30, 1, 40, 1, 20 });
    // Promotion with 2 additional dimensions at different position
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("g", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 30, 1, 20, 1, 40 });
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    performAndAssertPromotion("h", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 10, 1, 40, 1, 20 });
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    performAndAssertPromotion("i", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 10, 1, 20, 1, 40 });
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) TestContext(helper.Utils.TestContext) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 38 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class PragmaTest method getCompilerDirectiveTest.

@Test
public void getCompilerDirectiveTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    Xnode n1 = xcodeml.createNode(Xcode.F_DO_STATEMENT);
    p1.setValue("claw loop-fusion");
    assertEquals(CompilerDirective.CLAW, Pragma.getCompilerDirective(p1));
    p1.setValue("omp teams distribute");
    assertEquals(CompilerDirective.OPENMP, Pragma.getCompilerDirective(p1));
    p1.setValue("acc parallel");
    assertEquals(CompilerDirective.OPENACC, Pragma.getCompilerDirective(p1));
    p1.setValue("ivdep");
    assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(p1));
    assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(null));
    assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(n1));
}
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 39 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class PragmaTest method splitByContTest.

@Test
public void splitByContTest() {
    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 p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p1);
    p1.setValue("acc data present(q,acc& p,acc& h)acc& create(pt)");
    try {
        Pragma.splitByCont(p1, CompilerDirective.OPENACC.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 4, splittedPragma.size());
    } catch (IllegalTransformationException e) {
        fail();
    }
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    fd.body().append(p2);
    p2.setValue("omp target teams omp& distribute simd");
    try {
        Pragma.splitByCont(p2, CompilerDirective.OPENMP.getPrefix(), xcodeml);
        List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
        assertEquals(previous.size() + 6, 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 40 with Context

use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.

the class PragmaTest method splitTest.

@Test
public void splitTest() {
    Context context = new TestContext();
    context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
    String p1 = "acc data present(var1,var2,var3,var4,var5,var6,var7,var8," + "var10,var11,var12,var13,var14,var15,var16)";
    int maxCol = 40;
    // Just commas
    List<String> splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
    checkSplitted(splitted, 5, maxCol);
    // Just spaces
    p1 = "acc data present(var1, var2, var3, var4, var5, var6, var7, " + "var8, var10, var11, var12, var13, var14, var15, var16)";
    splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
    checkSplitted(splitted, 4, maxCol);
    // Mixed spaces and commas
    p1 = "acc data present(var1, var2,var3,var4, var5, var6, var7, " + "var8,var10,var11, var12,var13,var14, var15,var16, var17, var18)";
    splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
    checkSplitted(splitted, 5, maxCol);
    p1 = "omp target teams distribute parallel do simd";
    splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENMP.getPrefix());
    checkSplitted(splitted, 2, maxCol);
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Aggregations

Context (claw.tatsu.common.Context)54 TestContext (helper.Utils.TestContext)44 Test (org.junit.Test)43 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)27 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)22 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)12 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)9 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)4 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)3 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)3 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)3 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)3 Configuration (claw.wani.x2t.configuration.Configuration)3 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)3 ArrayList (java.util.ArrayList)3 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)2 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 XcodeML (claw.tatsu.xcodeml.xnode.common.XcodeML)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2