Search in sources :

Example 1 with Xid

use of claw.tatsu.xcodeml.xnode.common.Xid in project claw-compiler by C2SM-RCM.

the class ScaCPUvectorizeGroup method promote.

/**
 * Promote the given variable and adapt references.
 *
 * @param xcodeml Current translation unit.
 * @param var     Variable name to be promoted.
 * @throws IllegalTransformationException If promotion cannot be done.
 */
private void promote(Configuration cfg, XcodeProgram xcodeml, String var) throws IllegalTransformationException {
    PromotionInfo promotionInfo;
    // Do the promotion if needed
    if (!_promotions.containsKey(var)) {
        Message.debug(xcodeml.context(), String.format("%s promote variable %s", SCA_DEBUG_PREFIX, var));
        promotionInfo = new PromotionInfo(var, _claw.getLayoutForData(cfg, var));
        Field.promote(promotionInfo, _fctDef, xcodeml);
        _promotions.put(var, promotionInfo);
    } else {
        promotionInfo = _promotions.get(var);
    }
    // Adapt references
    Xid id = _fctDef.getSymbolTable().get(var);
    FbasicType bType = xcodeml.getTypeTable().getBasicType(id);
    if (!bType.isArray()) {
        Field.adaptScalarRefToArrayRef(_promotions.get(var), _fctDef, _claw.getDefaultLayout(cfg), xcodeml);
    } else {
        Field.adaptArrayRef(_promotions.get(var), _fctDef.body(), false, xcodeml);
        Field.adaptAllocate(_promotions.get(var), _fctDef.body(), xcodeml);
    }
    promotionInfo.setRefAdapted();
}
Also used : Xid(claw.tatsu.xcodeml.xnode.common.Xid) PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Example 2 with Xid

use of claw.tatsu.xcodeml.xnode.common.Xid in project claw-compiler by C2SM-RCM.

the class ScaForward method transformStd.

/**
 * Do the standard transformation for the forward directive. This transformation
 * adapt the function call and replicates any necessary changes to the
 * containing subroutine.
 *
 * @param xcodeml    Current XcodeML file unit.
 * @param translator Current translator.
 * @throws Exception If something goes wrong.
 */
private void transformStd(XcodeProgram xcodeml, Translator translator) throws Exception {
    ClawTranslator trans = (ClawTranslator) translator;
    final Context context = trans.context();
    final Configuration cfg = trans.cfg();
    FfunctionDefinition fDef = _claw.getPragma().findParentFunction();
    if (fDef == null) {
        throw new IllegalTransformationException("SCA directive is not " + "nested in a function/subroutine.", _claw.getPragma().lineNo());
    }
    FfunctionType parentFctType = xcodeml.getTypeTable().getFunctionType(fDef);
    if (_fctType.isElemental() || _fctType.getBooleanAttribute(Xattr.WAS_ELEMENTAL)) {
        _flatten = true;
    }
    List<Xnode> params = _fctType.getParameters();
    /*
         * Compute the position of the first new arguments. In the case of a type-bound
         * procedure call, the first parameter declared in the procedure is not actually
         * passed as an argument. In this case, we add an offset of one to the starting
         * arguments. TODO the check might be change to fit with the XcodeML/F2008
         * specs. The TODO cont: attribute data_ref will probably be gone and replaced
         * by a TODO cont: FmemberRef element
         */
    int argOffset = 0;
    if (!params.isEmpty() && FortranType.STRUCT.isOfType(params.get(0).getType()) && _fCall.isTbpCall()) {
        argOffset = 1;
    }
    // 1. Adapt function call with potential new arguments
    for (int i = 0; i < params.size(); i++) {
        Xnode p = params.get(i);
        String varId = p.value();
        String type;
        FbasicType paramType = xcodeml.getTypeTable().getBasicType(p);
        if (!p.getBooleanAttribute(Xattr.IS_INSERTED)) {
            continue;
        }
        if (!fDef.getSymbolTable().contains(varId)) {
            if (_flatten && !paramType.getBooleanAttribute(Xattr.IS_OPTIONAL)) {
                throw new IllegalTransformationException("Variable " + varId + " must be locally defined where the last call to one_column " + "is made.", _claw.getPragma().lineNo());
            }
            // Size variable have to be declared
            FbasicType bt = xcodeml.createBasicType(FortranType.INTEGER, Intent.IN);
            xcodeml.getTypeTable().add(bt);
            xcodeml.createIdAndDecl(varId, bt.getType(), XstorageClass.F_PARAM, fDef, DeclarationPosition.FIRST);
            type = bt.getType();
            Xnode param = xcodeml.createAndAddParam(varId, type, parentFctType);
            param.setBooleanAttribute(Xattr.IS_INSERTED, true);
        } else {
            // Var exists already. Add to the parameters if not here.
            type = fDef.getSymbolTable().get(varId).getType();
            /*
                 * If flatten mode, we do not add extra parameters to the function definition.
                 */
            if (!_flatten && !fDef.getSymbolTable().contains(varId)) {
                Xnode param = xcodeml.createAndAddParamIfNotExists(varId, type, parentFctType);
                if (param != null) {
                    param.setBooleanAttribute(Xattr.IS_INSERTED, true);
                }
            }
        }
        // Add variable in the function call before the optional parameters
        Xnode arg = xcodeml.createNamedValue(varId);
        arg.append(xcodeml.createVar(type, varId, Xscope.LOCAL));
        Xnode hook = _fCall.arguments().get((i - 1) - argOffset);
        if (hook != null) {
            hook.insertAfter(arg);
        } else {
            _fCall.addArguments(arg);
        }
    }
    // In flatten mode, arguments are demoted if needed.
    if (_flatten) {
        for (Xnode arg : _fCall.arguments()) {
            if (arg.is(Xcode.F_ARRAY_REF) && arg.matchDirectDescendant(Arrays.asList(Xcode.INDEX_RANGE, Xcode.ARRAY_INDEX)) != null) {
                List<Xnode> arrayIndexes = arg.matchAll(Xcode.ARRAY_INDEX);
                for (Xnode n : arrayIndexes) {
                    if (_doStatements != null && XnodeUtil.isInductionIndex(n, _doStatements.getInductionVariables())) {
                        n.insertAfter(xcodeml.createEmptyAssumedShaped());
                        XnodeUtil.safeDelete(n);
                    }
                }
            }
        }
    } else {
        // 2. Adapt function/subroutine in which the function call is nested
        for (Xnode pBase : _fctType.getParameters()) {
            String originalParam = pBase.value();
            if (_fctCallMapping.containsKey(originalParam)) {
                originalParam = _fctCallMapping.get(originalParam);
            }
            Xnode pUpdate = null;
            for (Xnode param : parentFctType.getParameters()) {
                if (originalParam.equals(param.value())) {
                    pUpdate = param;
                }
            }
            if (pUpdate == null) {
                // field is not a parameter but maybe out field
                Xnode d = fDef.getDeclarationTable().get(originalParam);
                if (d != null) {
                    pUpdate = d.matchSeq(Xcode.NAME);
                }
            }
            if (pUpdate != null) {
                if (pUpdate.getType() == null || FortranType.isBuiltInType(pUpdate.getType())) {
                    continue;
                }
                FbasicType typeBase = (_localFct) ? xcodeml.getTypeTable().getBasicType(pBase) : _mod.getTypeTable().getBasicType(pBase);
                FbasicType typeToUpdate = xcodeml.getTypeTable().getBasicType(pUpdate);
                int targetDim = typeBase.getDimensions();
                int baseDim = typeToUpdate.getDimensions();
                // Types have different dimensions
                if (typeBase.getDimensions() > typeToUpdate.getDimensions()) {
                    PromotionInfo promotionInfo = new PromotionInfo(originalParam);
                    promotionInfo.readDimensionsFromString(pBase.getAttribute(Xattr.PROMOTION_INFO));
                    FbasicType type = _localFct ? Type.duplicateWithDimension(typeBase, typeToUpdate, xcodeml, xcodeml, promotionInfo.getDimensions()) : Type.duplicateWithDimension(typeBase, typeToUpdate, _mod, xcodeml, promotionInfo.getDimensions());
                    pUpdate.setType(type);
                    Xid id = fDef.getSymbolTable().get(originalParam);
                    if (id != null) {
                        id.setType(type);
                    }
                    Xnode varDecl = fDef.getDeclarationTable().get(originalParam);
                    if (varDecl != null) {
                        varDecl.matchSeq(Xcode.NAME).setType(type);
                    }
                    promotionInfo.setBaseDimension(baseDim);
                    promotionInfo.setTargetDimension(targetDim);
                    promotionInfo.setTargetType(type);
                    _promotions.put(originalParam, promotionInfo);
                    _promotedVar.add(originalParam);
                    pBase.copyAttribute(pUpdate, Xattr.PROMOTION_INFO);
                }
            }
        }
        if (!parentFctType.getBooleanAttribute(Xattr.IS_PRIVATE)) {
            // 3. Replicate the change in a potential module file
            FmoduleDefinition modDef = fDef.findParentModule();
            if (modDef != null) {
                Xmod.updateSignature(modDef.getName(), xcodeml, fDef, parentFctType, false);
            }
        } else if (_fCall.matchSeq(Xcode.NAME).hasAttribute(Xattr.DATA_REF)) {
            /*
                 * The function/subroutine is private but accessible through the type as a
                 * type-bound procedure. In this case, the function is not in the type table of
                 * the .xmod file. We need to insert it first and then we can update it.
                 */
            FmoduleDefinition modDef = fDef.findParentModule();
            if (modDef != null) {
                Xmod.updateSignature(modDef.getName(), xcodeml, fDef, parentFctType, true);
            }
        }
    }
    updateResultVar(xcodeml);
    propagatePromotion(xcodeml, (ClawTranslator) translator);
    Xnode fctCallAncestor = _fCall.matchAncestor(Xcode.EXPR_STATEMENT);
    if (fctCallAncestor == null) {
        fctCallAncestor = _fCall.matchAncestor(Xcode.F_ASSIGN_STATEMENT);
    }
    if (_claw.hasClause(ClawClause.CREATE) && context.isTarget(Target.GPU)) {
        List<String> creates = _fCall.gatherArguments(xcodeml, _fctType, _mod, Intent.INOUT, true, false);
        if (_fctType.isFunction()) {
            String returnValue = XnodeUtil.gatherReturnValue(xcodeml, _fCall);
            if (returnValue != null) {
                creates.add(returnValue);
            }
        }
        Xblock fctCallBlock = new Xblock(fctCallAncestor);
        Directive.generateDataRegionClause(xcodeml, Collections.emptyList(), creates, fctCallBlock);
    }
    // Serialization input
    if (_claw.hasClause(ClawClause.SAVEPOINT)) {
        List<String> inFields = _fCall.gatherArguments(xcodeml, _fctType, _mod != null ? _mod : xcodeml, Intent.IN, true, false);
        Serialization.insertImports(cfg, xcodeml, _fCall.findParentFunction());
        if (context.isTarget(Target.CPU)) {
            Serialization.generateWriteSavepoint(cfg, xcodeml, fctCallAncestor, _claw.getMetadataMap(), inFields, _claw.value(ClawClause.SAVEPOINT), SerializationStep.SER_IN);
        } else {
            Serialization.generateReadSavepoint(cfg, xcodeml, fctCallAncestor, _claw.getMetadataMap(), inFields, _claw.value(ClawClause.SAVEPOINT), SerializationStep.SER_IN);
        }
    }
    Xnode postHook = fctCallAncestor;
    if (_claw.hasClause(ClawClause.UPDATE) && context.isTarget(Target.GPU) && cfg.getBooleanParameter(Configuration.SCA_FORWARD_UPDATE_ENABLED)) {
        // Generate update from HOST TO DEVICE
        if ((_claw.getUpdateClauseValue() == DataMovement.TWO_WAY || _claw.getUpdateClauseValue() == DataMovement.HOST_TO_DEVICE) && cfg.updateAtInput()) {
            List<String> in = _fCall.gatherArguments(xcodeml, _fctType, _mod != null ? _mod : xcodeml, Intent.IN, true, false);
            Directive.generateUpdate(xcodeml, fctCallAncestor, in, DataMovement.HOST_TO_DEVICE);
        }
        // Generate update from DEVICE to HOST
        if ((_claw.getUpdateClauseValue() == DataMovement.TWO_WAY || _claw.getUpdateClauseValue() == DataMovement.DEVICE_TO_HOST) && cfg.updateAtOutput()) {
            List<String> out = _fCall.gatherArguments(xcodeml, _fctType, _mod != null ? _mod : xcodeml, Intent.OUT, true, false);
            if (_fctType.isFunction()) {
                String returnValue = XnodeUtil.gatherReturnValue(xcodeml, _fCall);
                if (returnValue != null) {
                    out.add(returnValue);
                }
            }
            postHook = Directive.generateUpdate(xcodeml, fctCallAncestor, out, DataMovement.DEVICE_TO_HOST);
        }
    }
    if (_claw.hasClause(ClawClause.PARALLEL) && context.isTarget(Target.GPU)) {
        Directive.generateParallelRegion(xcodeml, fctCallAncestor, fctCallAncestor);
    }
    // Serialization output
    if (_claw.hasClause(ClawClause.SAVEPOINT)) {
        List<String> outFields = _fCall.gatherArguments(xcodeml, _fctType, _mod != null ? _mod : xcodeml, Intent.OUT, true, false);
        Serialization.insertImports(cfg, xcodeml, _fCall.findParentFunction());
        Serialization.generateWriteSavepoint(cfg, xcodeml, postHook, _claw.getMetadataMap(), outFields, _claw.value(ClawClause.SAVEPOINT), SerializationStep.SER_OUT);
    }
}
Also used : Context(claw.tatsu.common.Context) Configuration(claw.wani.x2t.configuration.Configuration) FfunctionType(claw.tatsu.xcodeml.xnode.fortran.FfunctionType) PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) Xid(claw.tatsu.xcodeml.xnode.common.Xid) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) Xblock(claw.tatsu.xcodeml.abstraction.Xblock) FmoduleDefinition(claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition) ClawTranslator(claw.wani.x2t.translator.ClawTranslator)

Example 3 with Xid

use of claw.tatsu.xcodeml.xnode.common.Xid in project claw-compiler by C2SM-RCM.

the class FortranModule method findFunctionType.

/**
 * Try to find the function type in the module.
 *
 * @param fctName Function name.
 * @return Function type if found. Null otherwise.
 */
public FfunctionType findFunctionType(String fctName) {
    Xid id = getIdentifiers().get(fctName);
    FfunctionType fctType;
    if (id != null) {
        fctType = getTypeTable().getFunctionType(id);
    } else {
        String typeHash = findFunctionImplementationInInterface(fctName);
        fctType = getTypeTable().getFunctionType(typeHash);
    }
    return fctType;
}
Also used : Xid(claw.tatsu.xcodeml.xnode.common.Xid)

Example 4 with Xid

use of claw.tatsu.xcodeml.xnode.common.Xid in project claw-compiler by C2SM-RCM.

the class ExpandNotation method generateDoStmtNotation.

/**
 * Generate the corresponding do statements for the array notations. A do
 * statement is generated per dimension of the arrays. Iteration index range are
 * computed with array dimensions.
 *
 * @param xcodeml    The XcodeML on which the transformations are applied.
 * @param translator The translator used to applied the transformations.
 * @param fctDef     The function definition in which the array notation is
 *                   nested.
 * @param ranges     The list of iteration ranges to be applied to the created
 *                   do statements.
 * @param statements The list of assign statements (array notation) that will be
 *                   included in the nested do statements.
 * @param doStmtGrip Grip for the code insertion. Do statements will be inserted
 *                   after the grip element.
 * @return Block surrounding the do statements generated.
 */
private Xblock generateDoStmtNotation(XcodeProgram xcodeml, ClawTranslator translator, FfunctionDefinition fctDef, List<Xnode> ranges, List<Xnode> statements, Xnode doStmtGrip) throws IllegalTransformationException {
    String[] inductionVars = new String[ranges.size()];
    Xnode[] doStmts = new Xnode[ranges.size()];
    Xnode var = statements.get(0).matchSeq(Xcode.F_ARRAY_REF, Xcode.VAR_REF, Xcode.VAR);
    if (var == null) {
        var = statements.get(0).matchSeq(Xcode.F_ARRAY_REF, Xcode.VAR_REF, Xcode.F_MEMBER_REF);
    }
    // 1. Create do statements with induction variables
    for (int i = 0; i < ranges.size(); ++i) {
        // 1.1 Create induction variables
        if (_clawStart.hasClause(ClawClause.INDUCTION)) {
            // Use user names
            inductionVars[i] = _clawStart.values(ClawClause.INDUCTION).get(i);
        } else {
            // generate new names
            inductionVars[i] = "claw_induction_" + translator.getNextTransformationCounter();
        }
        // 2.2 inject a new entry in the symbol table
        if (!fctDef.getSymbolTable().contains(inductionVars[i])) {
            Xid inductionVarId = xcodeml.createId(FortranType.INTEGER, XstorageClass.F_LOCAL, inductionVars[i]);
            fctDef.getSymbolTable().add(inductionVarId, false);
        }
        // 2.3 inject a new entry in the declaration table
        if (!fctDef.getDeclarationTable().contains(inductionVars[i])) {
            Xnode inductionVarDecl = xcodeml.createVarDecl(FortranType.INTEGER, inductionVars[i]);
            fctDef.getDeclarationTable().add(inductionVarDecl);
        }
        // 2.4 create do statements
        Xnode inductionVar = xcodeml.createVar(FortranType.INTEGER, inductionVars[i], Xscope.LOCAL);
        Xnode range;
        if (ranges.get(i).getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE)) {
            // Allocatable array
            // dimension argument of size starts at one
            range = xcodeml.createRangeForAssumedShapeArray(var, 1, i + 1);
        } else {
            range = ranges.get(i).cloneNode();
        }
        doStmts[i] = xcodeml.createDoStmt(inductionVar, range);
        statements.get(0).copyEnhancedInfo(doStmts[i]);
        if (i == 0) {
            // most outer loop goes after the pragma
            doStmtGrip.insertAfter(doStmts[i]);
        } else {
            // others loop go in the previous one
            doStmts[i - 1].body().append(doStmts[i]);
        }
    }
    for (Xnode stmt : statements) {
        // 3. Adapt array reference with induction variables
        List<Xnode> allArrayRef = stmt.matchAll(Xcode.F_ARRAY_REF);
        for (Xnode arrayRef : allArrayRef) {
            for (int i = 0; i < arrayRef.children().size() - 1; ++i) {
                Xnode el = arrayRef.child(i + 1);
                if (Xnode.isOfCode(el, Xcode.INDEX_RANGE) && i < doStmts.length) {
                    String induction = doStmts[i].matchSeq(Xcode.VAR).value();
                    Xnode inductionVar = xcodeml.createVar(FortranType.INTEGER, induction, Xscope.LOCAL);
                    Xnode arrayIdx = xcodeml.createNode(Xcode.ARRAY_INDEX);
                    arrayIdx.append(inductionVar);
                    el.insertAfter(arrayIdx);
                    el.delete();
                }
            }
        }
        stmt.matchAll(Xcode.FUNCTION_CALL).stream().map(FunctionCall::new).filter(x -> x.isIntrinsicCall(Xintrinsic.SUM)).forEach(FunctionCall::adaptIntrinsicSumCall);
        stmt.matchAll(Xcode.FUNCTION_CALL).stream().map(FunctionCall::new).filter(x -> x.isIntrinsicCall(Xintrinsic.SPREAD)).forEach(FunctionCall::adaptIntrinsicSpreadCall);
        // 4. Move assignment statement inside the most inner loop
        doStmts[ranges.size() - 1].body().append(stmt, true);
        stmt.delete();
    }
    // Add any additional transformation defined in the directive clauses
    translator.generateAdditionalTransformation(_clawStart, xcodeml, doStmts[0]);
    return new Xblock(doStmts[0]);
}
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) Xid(claw.tatsu.xcodeml.xnode.common.Xid) Xblock(claw.tatsu.xcodeml.abstraction.Xblock) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall)

Example 5 with Xid

use of claw.tatsu.xcodeml.xnode.common.Xid in project claw-compiler by C2SM-RCM.

the class Xmod method updateSignature.

/**
 * Update the function signature in the module file to reflects local changes.
 *
 * @param moduleName    Xmod name to update.
 * @param xcodeml       Current XcodeML file unit.
 * @param fctDef        Function definition that has been changed.
 * @param fctType       Function type that has been changed.
 * @param importFctType If true, import the functionType.
 * @throws IllegalTransformationException If the module file or the function
 *                                        cannot be located
 */
public static void updateSignature(String moduleName, XcodeProgram xcodeml, FfunctionDefinition fctDef, FfunctionType fctType, boolean importFctType) throws IllegalTransformationException {
    final Context context = xcodeml.context();
    FortranModule mod;
    if (context.getModuleCache().isModuleLoaded(moduleName)) {
        mod = context.getModuleCache().get(moduleName);
    } else {
        mod = fctDef.findContainingXmod(context);
        if (mod == null) {
            throw new IllegalTransformationException("Unable to locate module file for: " + moduleName);
        }
        context.getModuleCache().add(moduleName, mod);
    }
    FfunctionType fctTypeMod;
    if (importFctType) {
        // TODO should be part of XcodeML
        Xnode importedNode = mod.importNode(fctType);
        mod.getTypeTable().append(importedNode);
        FfunctionType importedFctType = new FfunctionType(importedNode);
        Xid importedFctTypeId = mod.createId(importedFctType.getType(), XstorageClass.F_FUNC, fctDef.getName());
        mod.getIdentifiers().add(importedFctTypeId);
        // check if params need to be imported as well
        if (!importedFctType.getParameters().isEmpty()) {
            for (Xnode param : importedFctType.getParameters()) {
                mod.importType(xcodeml, param.getType());
            }
        }
        return;
    } else {
        fctTypeMod = mod.findFunctionType(fctDef.getName());
    }
    if (fctTypeMod == null) {
        /*
             * Workaround for a bug in OMNI Compiler. Look at test case claw/abstraction12.
             * 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.
             */
        String errorMsg = "Unable to locate fct " + fctDef.getName() + " in module " + moduleName;
        /*
             * If not, try to matchSeq the correct FfunctionType in the module definitions
             */
        fctTypeMod = mod.findFunctionType(fctDef.getName());
        if (fctTypeMod == null) {
            throw new IllegalTransformationException(errorMsg);
        }
    }
    FbasicType modIntTypeIntentIn = mod.createBasicType(FortranType.INTEGER, Intent.IN);
    mod.getTypeTable().add(modIntTypeIntentIn);
    List<Xnode> paramsLocal = fctType.getParameters();
    List<Xnode> paramsMod = fctTypeMod.getParameters();
    if (paramsLocal.size() < paramsMod.size()) {
        throw new IllegalTransformationException("Local function has more parameters than module counterpart.");
    }
    for (int i = 0; i < paramsLocal.size(); ++i) {
        Xnode pLocal = paramsLocal.get(i);
        // Number of parameters in the module function as been
        if (pLocal.getBooleanAttribute(Xattr.IS_INSERTED)) {
            // new parameter
            Xnode param = mod.createAndAddParamIfNotExists(pLocal.value(), modIntTypeIntentIn.getType(), fctTypeMod);
            if (param != null) {
                param.setBooleanAttribute(Xattr.IS_INSERTED, true);
            }
        } else {
            Xnode pMod = paramsMod.get(i);
            String localType = pLocal.getType();
            String modType = pMod.getType();
            if (!localType.equals(modType)) {
                // Param has been updated so have to replicate the change to mod file
                FbasicType lType = xcodeml.getTypeTable().getBasicType(pLocal);
                FbasicType crtType = mod.getTypeTable().getBasicType(pMod);
                if (pLocal.hasAttribute(Xattr.PROMOTION_INFO)) {
                    PromotionInfo promotionInfo = new PromotionInfo();
                    promotionInfo.readDimensionsFromString(pLocal.getAttribute(Xattr.PROMOTION_INFO));
                    if (lType.isArray()) {
                        FbasicType newType = Type.duplicateWithDimension(lType, crtType, xcodeml, mod, promotionInfo.getDimensions());
                        pMod.setType(newType);
                    }
                }
            }
            // Copy the promotion information
            pLocal.copyAttribute(pMod, Xattr.PROMOTION_INFO);
        }
    }
    // Sync attribute between local fct type and module fct type.
    for (Xattr attr : SYNCABLE_ATTR) {
        fctType.syncBooleanAttribute(fctTypeMod, attr);
    }
}
Also used : Context(claw.tatsu.common.Context) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FortranModule(claw.tatsu.xcodeml.xnode.fortran.FortranModule) Xid(claw.tatsu.xcodeml.xnode.common.Xid) FfunctionType(claw.tatsu.xcodeml.xnode.fortran.FfunctionType) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) Xattr(claw.tatsu.xcodeml.xnode.common.Xattr) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Aggregations

Xid (claw.tatsu.xcodeml.xnode.common.Xid)9 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)7 Context (claw.tatsu.common.Context)5 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)4 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)4 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)4 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)3 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)3 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)3 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)2 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)2 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)2 Configuration (claw.wani.x2t.configuration.Configuration)2 Transformation (claw.shenron.transformation.Transformation)1 Translator (claw.shenron.translator.Translator)1 Target (claw.tatsu.common.Target)1 DataMovement (claw.tatsu.directive.common.DataMovement)1 Directive (claw.tatsu.directive.common.Directive)1 Range (claw.tatsu.primitive.Range)1 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)1