Search in sources :

Example 1 with DirectiveGenerator

use of claw.tatsu.directive.generator.DirectiveGenerator in project claw-compiler by C2SM-RCM.

the class ScaRoutine method transform.

@Override
public void transform(XcodeProgram xcodeml, Translator translator, Transformation other) {
    Context context = xcodeml.context();
    if (context.isTarget(Target.GPU)) {
        DirectiveGenerator dirGen = context.getGenerator();
        if (_fctType.isElemental()) {
            _fctType.removeAttribute(Xattr.IS_PURE);
            _fctType.removeAttribute(Xattr.IS_ELEMENTAL);
        }
        if (Directive.hasDirectives(context, _fctDef)) {
            xcodeml.addWarning(String.format("%s %s", SCA_DEBUG_PREFIX, "Function/subroutine has some directives! " + "Cannot insert new directives without breaking existing ones!"), _claw.getPragma());
        } else {
            Directive.addPragmasBefore(xcodeml, dirGen.getRoutineDirective(true), _fctDef.body().child(0));
        }
    }
    removePragma();
}
Also used : Context(claw.tatsu.common.Context) DirectiveGenerator(claw.tatsu.directive.generator.DirectiveGenerator)

Example 2 with DirectiveGenerator

use of claw.tatsu.directive.generator.DirectiveGenerator 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 3 with DirectiveGenerator

use of claw.tatsu.directive.generator.DirectiveGenerator in project claw-compiler by C2SM-RCM.

the class Directive method findParallelRegionStart.

/**
 * Skip elements in preamble and find the first element that will be included in
 * the parallel region.
 *
 * @param functionDefinition Function definition in which body checked.
 * @param from               Optional element to start from. If null, starts
 *                           from first element in function's body.
 * @return First element for the parallel region.
 */
public static Xnode findParallelRegionStart(Context context, Xnode functionDefinition, Xnode from) {
    DirectiveGenerator dg = context.getGenerator();
    if (!Xnode.isOfCode(functionDefinition, Xcode.F_FUNCTION_DEFINITION)) {
        return null;
    }
    Xnode first = functionDefinition.body().firstChild();
    if (first == null) {
        return null;
    }
    if (from != null) {
        // Start from given element
        first = from;
    }
    if (dg.getSkippedStatementsInPreamble().isEmpty()) {
        return first;
    } else {
        while (first.nextSibling() != null && ((dg.getSkippedStatementsInPreamble().contains(first.opcode())) || (isClawDirective(first) && !first.value().contains("nodep")))) {
            if (Xnode.isOfCode(first, Xcode.F_IF_STATEMENT)) {
                Xnode then = first.matchDescendant(Xcode.THEN);
                if (then != null && then.hasBody()) {
                    for (Xnode child : then.body().children()) {
                        if (!dg.getSkippedStatementsInPreamble().contains(child.opcode())) {
                            return first;
                        }
                    }
                }
            } else if (first.hasBody()) {
                for (Xnode child : first.body().children()) {
                    if (!dg.getSkippedStatementsInPreamble().contains(child.opcode())) {
                        return first;
                    }
                }
            }
            first = first.nextSibling();
        }
    }
    return first;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) DirectiveGenerator(claw.tatsu.directive.generator.DirectiveGenerator)

Example 4 with DirectiveGenerator

use of claw.tatsu.directive.generator.DirectiveGenerator in project claw-compiler by C2SM-RCM.

the class Directive method generateDataRegionClause.

/**
 * Generate directive directive for a data region. Some clauses can be ignored
 * depending on the configuration, if this results to discard all variables then
 * the directive is not generated.
 *
 * @param xcodeml  Object representation of the current XcodeML representation
 *                 in which the pragmas will be generated.
 * @param presents List of variables to be set as present.
 * @param creates  List of variables to be created.
 * @param hook     Block around which data region is generated.
 * @return Block containing start and end of data region.
 */
public static Xblock generateDataRegionClause(XcodeProgram xcodeml, List<String> presents, List<String> creates, Xblock hook) {
    DirectiveGenerator generator = xcodeml.context().getGenerator();
    List<String> clauses = new ArrayList<>(Arrays.asList(generator.getPresentClause(presents), generator.getCreateClause(creates)));
    clauses.removeAll(Collections.singletonList(""));
    // No need to create an empty data region
    if (!clauses.isEmpty()) {
        return insertPragmas(xcodeml, hook, generator.getStartDataRegion(clauses), generator.getEndDataRegion());
    }
    return null;
}
Also used : DirectiveGenerator(claw.tatsu.directive.generator.DirectiveGenerator) ArrayList(java.util.ArrayList)

Example 5 with DirectiveGenerator

use of claw.tatsu.directive.generator.DirectiveGenerator in project claw-compiler by C2SM-RCM.

the class Directive method findParallelRegionEnd.

/**
 * Skip elements in epilogue and find the last element that will be included in
 * the parallel region.
 *
 * @param functionDefinition Function definition in which body checked.
 * @param from               Optional element to start from. If null, starts
 *                           from last element in function's body.
 * @return Last element for the parallel region.
 */
public static Xnode findParallelRegionEnd(Context context, Xnode functionDefinition, Xnode from) {
    DirectiveGenerator dg = context.getGenerator();
    if (!Xnode.isOfCode(functionDefinition, Xcode.F_FUNCTION_DEFINITION)) {
        return null;
    }
    Xnode last = functionDefinition.body().lastChild();
    if (last == null) {
        return null;
    }
    if (from != null) {
        // Start from given element
        last = from;
        if (last.is(Xcode.F_CONTAINS_STATEMENT)) {
            last = last.prevSibling();
        }
    }
    if (dg.getSkippedStatementsInEpilogue().isEmpty() || !last.matchAll(Xcode.F_ASSIGN_STATEMENT).isEmpty()) {
        return last;
    } else {
        while (last.prevSibling() != null && dg.getSkippedStatementsInEpilogue().contains(last.opcode())) {
            if (last.hasBody() || last.is(Xcode.F_IF_STATEMENT)) {
                List<Xnode> children = (last.hasBody()) ? last.body().children() : last.matchDirectDescendant(Xcode.THEN).body().children();
                for (Xnode child : children) {
                    if (!dg.getSkippedStatementsInEpilogue().contains(child.opcode())) {
                        return last;
                    }
                }
            }
            last = last.prevSibling();
        }
    }
    return last;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) DirectiveGenerator(claw.tatsu.directive.generator.DirectiveGenerator)

Aggregations

DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)7 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)4 Context (claw.tatsu.common.Context)2 ArrayList (java.util.ArrayList)2 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)1 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)1 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)1