Search in sources :

Example 1 with PromotionInfo

use of cx2x.translator.transformation.claw.parallelize.PromotionInfo in project claw-compiler by C2SM-RCM.

the class TransformationHelper method promoteField.

/**
   * Promote a field with the information stored in the defined dimensions.
   *
   * @param fieldId   Id of the field as defined in the symbol table.
   * @param update    If true, update current type otherwise, create a type from
   *                  scratch.
   * @param assumed   If true, generate assumed dimension range, otherwise, use
   *                  the information in the defined dimension.
   * @param overIndex Over clause to be used for promotion.
   * @param xcodeml   Current XcodeML program unit in which the element will be
   *                  created.
   * @param overPos   Force behavior as if over clause is present.
   * @throws IllegalTransformationException If type cannot be found.
   */
public static PromotionInfo promoteField(String fieldId, boolean update, boolean assumed, int overIndex, int overDimensions, XfunctionDefinition fctDef, XfunctionType fctType, List<ClawDimension> dimensions, ClawLanguage claw, XcodeProgram xcodeml, OverPosition overPos) throws IllegalTransformationException {
    Xid id = fctDef.getSymbolTable().get(fieldId);
    Xdecl decl = fctDef.getDeclarationTable().get(fieldId);
    String type = xcodeml.getTypeTable().generateArrayTypeHash();
    XbasicType newType;
    if (update) {
        if (XnodeUtil.isBuiltInType(id.getType())) {
            newType = xcodeml.createBasicType(type, id.getType(), Xintent.NONE);
        } else {
            XbasicType old = (XbasicType) xcodeml.getTypeTable().get(id.getType());
            if (old == null) {
                throw new IllegalTransformationException("Cannot matchSeq type for " + fieldId, claw.getPragma().lineNo());
            } else {
                newType = old.cloneNode();
                newType.setType(type);
            }
        }
    } else {
        newType = xcodeml.createBasicType(type, id.getType(), Xintent.NONE);
    }
    PromotionInfo proInfo = new PromotionInfo(fieldId, newType.getDimensions(), newType.getDimensions() + dimensions.size(), type);
    if (assumed) {
        if (newType.isAllAssumedShape() && (fctType.hasParam(fieldId) || newType.isPointer())) {
            for (int i = 0; i < overDimensions; ++i) {
                Xnode index = xcodeml.createEmptyAssumedShaped();
                newType.addDimension(index, 0);
            }
        } else {
            if (claw.hasOverClause() || overPos != null) {
                /* If the directive has an over clause, there is three possibility to
           * insert the newly defined dimensions.
           * 1. Insert the dimensions in the middle on currently existing ones.
           * 2. Insert the dimensions before currently existing ones.
           * 3. Insert the dimensions after currently existing ones. */
                if (overPos == null) {
                    overPos = getOverPosition(claw.getOverClauseValues().get(overIndex));
                }
                if (overPos == OverPosition.MIDDLE) {
                    // Insert new dimension in middle (case 1)
                    int startIdx = 1;
                    for (ClawDimension dim : dimensions) {
                        Xnode index = dim.generateIndexRange(xcodeml, false);
                        newType.addDimension(index, startIdx++);
                    }
                } else if (overPos == OverPosition.AFTER) {
                    // Insert new dimensions at the end (case 3)
                    for (ClawDimension dim : dimensions) {
                        Xnode index = dim.generateIndexRange(xcodeml, false);
                        newType.addDimension(index, XbasicType.APPEND);
                    }
                } else {
                    // Insert new dimension at the beginning (case 2)
                    for (ClawDimension dim : dimensions) {
                        Xnode index = dim.generateIndexRange(xcodeml, false);
                        newType.addDimension(index, 0);
                    }
                }
            } else {
                for (ClawDimension dim : dimensions) {
                    Xnode index = dim.generateIndexRange(xcodeml, false);
                    newType.addDimension(index, 0);
                }
            }
        }
    } else {
        for (ClawDimension dim : dimensions) {
            Xnode index = dim.generateIndexRange(xcodeml, false);
            newType.addDimension(index, XbasicType.APPEND);
        }
    }
    id.setType(type);
    decl.matchSeq(Xcode.NAME).setAttribute(Xattr.TYPE, type);
    xcodeml.getTypeTable().add(newType);
    // Update params in function type
    for (Xnode param : fctType.getParams().getAll()) {
        if (param.value().equals(fieldId)) {
            // Update type with new promoted type
            param.setAttribute(Xattr.TYPE, type);
            // Save the over clause for parallelize forward transformation
            if (claw.hasOverClause()) {
                param.setAttribute(ClawAttr.OVER.toString(), getOverPosition(claw.getOverClauseValues().get(overIndex)).toString());
            }
        }
    }
    if (fctType.hasAttribute(Xattr.RESULT_NAME) && fctType.getAttribute(Xattr.RESULT_NAME).equals(fieldId)) {
        if (claw.hasOverClause()) {
            fctType.setAttribute(ClawAttr.OVER.toString(), getOverPosition(claw.getOverClauseValues().get(overIndex)).toString());
        }
    }
    return proInfo;
}
Also used : ClawDimension(cx2x.translator.language.common.ClawDimension) IllegalTransformationException(cx2x.xcodeml.exception.IllegalTransformationException) PromotionInfo(cx2x.translator.transformation.claw.parallelize.PromotionInfo)

Aggregations

ClawDimension (cx2x.translator.language.common.ClawDimension)1 PromotionInfo (cx2x.translator.transformation.claw.parallelize.PromotionInfo)1 IllegalTransformationException (cx2x.xcodeml.exception.IllegalTransformationException)1