Search in sources :

Example 11 with PromotionInfo

use of claw.tatsu.xcodeml.abstraction.PromotionInfo in project claw-compiler by C2SM-RCM.

the class FieldTest method readFromFormattedDimensionTest.

@Test
public void readFromFormattedDimensionTest() {
    DimensionDefinition dim1 = new DimensionDefinition("dim1", "1", "30");
    DimensionDefinition dim2 = new DimensionDefinition("dim2", "1", "nproma");
    PromotionInfo p1 = new PromotionInfo("a");
    p1.readDimensionsFromString("dim1(1:30),:");
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    assertEquals(1, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    p1.readDimensionsFromString(":,dim1(1:30)");
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(1, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    p1.readDimensionsFromString(":,dim1(1:30),:");
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals(1, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    p1.readDimensionsFromString("dim1(1:30),dim2(1:nproma),:");
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.BEFORE);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString(":,dim1(1:30),dim2(1:nproma),:");
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString(":,dim1(1:30),dim2(1:nproma)");
    dim1.setInsertionPosition(InsertionPosition.AFTER);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString("dim1(1:30),:,dim2(1:nproma)");
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString("dim1(1:30),:,dim2(1:nproma),:");
    dim1.setInsertionPosition(InsertionPosition.BEFORE);
    dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
    p1.readDimensionsFromString(":,dim1(1:30),:,dim2(1:nproma)");
    dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
    dim2.setInsertionPosition(InsertionPosition.AFTER);
    assertEquals(2, p1.getDimensions().size());
    assertDimensionEquals(dim1, p1.getDimensions().get(0));
    assertDimensionEquals(dim2, p1.getDimensions().get(1));
}
Also used : PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) DimensionDefinition(claw.tatsu.xcodeml.abstraction.DimensionDefinition) Test(org.junit.Test)

Example 12 with PromotionInfo

use of claw.tatsu.xcodeml.abstraction.PromotionInfo in project claw-compiler by C2SM-RCM.

the class FieldTest method performAndAssertPromotion.

/**
 * Perform the promotion transformation and assert its result.
 *
 * @param id         Identifier of the field to be promoted.
 * @param dims       Dimension definitions to use.
 * @param fctDef     Function definition in which the promotion is performed.
 * @param xcodeml    Current XcodeML translation unit.
 * @param base       Number of dimension before the promotion.
 * @param target     Number of dimension after the promotion.
 * @param dimensions Expected dimensions after promotion.
 */
private void performAndAssertPromotion(String id, List<DimensionDefinition> dims, FfunctionDefinition fctDef, XcodeProgram xcodeml, int base, int target, int[] dimensions) {
    try {
        int diff = target - base;
        PromotionInfo promotionInfo = new PromotionInfo(id);
        promotionInfo.setDimensions(dims);
        Xnode decl = fctDef.getDeclarationTable().get(id);
        assertNotNull(decl);
        FbasicType bt;
        if (base != 0) {
            bt = xcodeml.getTypeTable().getBasicType(decl);
            assertNotNull(bt);
            assertTrue(bt.isArray());
            assertEquals(base, bt.getDimensions());
        } else {
            assertEquals(FortranType.REAL, FortranType.fromString(decl.getType()));
        }
        // Perform the promotion
        Field.promote(promotionInfo, fctDef, xcodeml);
        decl = fctDef.getDeclarationTable().get(id);
        assertNotNull(decl);
        bt = xcodeml.getTypeTable().getBasicType(decl);
        assertNotNull(bt);
        assertTrue(bt.isArray());
        assertEquals(target, bt.getDimensions());
        assertEquals(target, dimensions.length / 2);
        assertEquals(target, promotionInfo.getTargetDimension());
        assertEquals(base, promotionInfo.getBaseDimension());
        assertEquals(diff, promotionInfo.diffDimension());
        assertEquals(bt.getType(), promotionInfo.getTargetType().getType());
        if (base > 0) {
            assertEquals(PromotionInfo.PromotionType.ARRAY_TO_ARRAY, promotionInfo.getPromotionType());
        } else {
            assertEquals(PromotionInfo.PromotionType.SCALAR_TO_ARRAY, promotionInfo.getPromotionType());
        }
        for (int i = 0; i < dimensions.length / 2; ++i) {
            assertDimension(bt.getDimensions(i), dimensions[i * 2], dimensions[(i * 2) + 1]);
        }
    } catch (IllegalTransformationException itex) {
        System.err.println(itex.getMessage());
        fail();
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Aggregations

PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)12 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)6 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)6 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)4 Context (claw.tatsu.common.Context)3 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)3 Xid (claw.tatsu.xcodeml.xnode.common.Xid)3 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)3 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)2 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)2 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)2 Test (org.junit.Test)2 AcceleratorConfiguration (claw.tatsu.directive.configuration.AcceleratorConfiguration)1 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)1 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)1 FortranModule (claw.tatsu.xcodeml.xnode.fortran.FortranModule)1 Configuration (claw.wani.x2t.configuration.Configuration)1 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)1