Search in sources :

Example 1 with ParallelizeForward

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

the class ClawXcodeMlTranslator method analyze.

/**
   * Analysis the XcodeML code and produce a list of applicable transformation.
   */
public void analyze() {
    _program = XcodeProgram.createFromFile(_xcodemlInputFile);
    if (_program == null) {
        abort();
    }
    // Check all pragma found in the program
    for (Xnode pragma : _program.getAllStmt(Xcode.FPRAGMASTATEMENT)) {
        // pragma does not start with the CLAW prefix
        if (!ClawLanguage.startsWithClaw(pragma)) {
            // Compile guard removal
            if (_generator != null && _generator.isCompileGuard(pragma.value())) {
                pragma.delete();
            } else // Handle special transformation of OpenACC line continuation
            if (pragma.value().toLowerCase().startsWith(ClawConstant.OPENACC_PREFIX)) {
                OpenAccContinuation t = new OpenAccContinuation(new AnalyzedPragma(pragma));
                addOrAbort(t);
            }
            // Not CLAW pragma, we do nothing
            continue;
        }
        try {
            // Analyze the raw pragma with the CLAW language parser
            ClawLanguage analyzedPragma = ClawLanguage.analyze(pragma, _generator, _target);
            // Create transformation object based on the directive
            switch(analyzedPragma.getDirective()) {
                case ARRAY_TO_CALL:
                    addOrAbort(new ArrayToFctCall(analyzedPragma));
                    break;
                case KCACHE:
                    addOrAbort(new Kcaching(analyzedPragma));
                    break;
                case LOOP_FUSION:
                    addOrAbort(new LoopFusion(analyzedPragma));
                    break;
                case LOOP_INTERCHANGE:
                    addOrAbort(new LoopInterchange(analyzedPragma));
                    break;
                case LOOP_EXTRACT:
                    addOrAbort(new LoopExtraction(analyzedPragma));
                    break;
                case LOOP_HOIST:
                    HandleBlockDirective(analyzedPragma);
                    break;
                case ARRAY_TRANSFORM:
                    HandleBlockDirective(analyzedPragma);
                    break;
                case REMOVE:
                    HandleBlockDirective(analyzedPragma);
                    break;
                case PARALLELIZE:
                    if (analyzedPragma.hasForwardClause()) {
                        addOrAbort(new ParallelizeForward(analyzedPragma));
                    } else {
                        addOrAbort(new Parallelize(analyzedPragma));
                    }
                    break;
                case PRIMITIVE:
                    addOrAbort(new DirectivePrimitive(analyzedPragma));
                    break;
                case IF_EXTRACT:
                    addOrAbort(new IfExtract(analyzedPragma));
                    break;
                // driver handled directives
                case IGNORE:
                case VERBATIM:
                    break;
                default:
                    _program.addError("Unrecognized CLAW directive", pragma.lineNo());
                    abort();
            }
        } catch (IllegalDirectiveException ex) {
            System.err.println(ex.getMessage());
            abort();
        }
    }
    // Clean up block transformation map
    for (Map.Entry<ClawDirectiveKey, ClawLanguage> entry : _blockDirectives.entrySet()) {
        createBlockDirectiveTransformation(entry.getValue(), null);
    }
    // Add utility transformation
    addOrAbort(new XcodeMLWorkaround(new ClawLanguage(_program)));
    // Analysis done, the transformation can be performed.
    _canTransform = true;
}
Also used : ArrayToFctCall(cx2x.translator.transformation.claw.ArrayToFctCall) IllegalDirectiveException(cx2x.xcodeml.exception.IllegalDirectiveException) Parallelize(cx2x.translator.transformation.claw.parallelize.Parallelize) AnalyzedPragma(cx2x.xcodeml.language.AnalyzedPragma) Xnode(cx2x.xcodeml.xnode.Xnode) DirectivePrimitive(cx2x.translator.transformation.openacc.DirectivePrimitive) XcodeMLWorkaround(cx2x.translator.transformation.utility.XcodeMLWorkaround) OpenAccContinuation(cx2x.translator.transformation.openacc.OpenAccContinuation) ParallelizeForward(cx2x.translator.transformation.claw.parallelize.ParallelizeForward) ClawLanguage(cx2x.translator.language.base.ClawLanguage) Kcaching(cx2x.translator.transformation.claw.Kcaching)

Example 2 with ParallelizeForward

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

the class ClawXcodeMlTranslator method reorderTransformations.

private void reorderTransformations() {
    if (_transformer.getGroups().containsKey(ParallelizeForward.class)) {
        TransformationGroup tg = _transformer.getGroups().get(ParallelizeForward.class);
        if (tg.count() <= 1) {
            return;
        }
        DirectedGraph<Transformation> dg = new DirectedGraph<>();
        Map<String, List<Transformation>> fctMap = new HashMap<>();
        for (Transformation t : tg.getTransformations()) {
            ParallelizeForward p = (ParallelizeForward) t;
            dg.addNode(p);
            if (fctMap.containsKey(p.getCallingFctName())) {
                List<Transformation> tList = fctMap.get(p.getCallingFctName());
                tList.add(p);
            } else {
                List<Transformation> tList = new ArrayList<>();
                tList.add(p);
                fctMap.put(p.getCallingFctName(), tList);
            }
        }
        for (Transformation t : tg.getTransformations()) {
            ParallelizeForward p = (ParallelizeForward) t;
            if (p.getCalledFctName() != null) {
                if (fctMap.containsKey(p.getCalledFctName())) {
                    List<Transformation> tList = fctMap.get(p.getCalledFctName());
                    for (Transformation end : tList) {
                        dg.addEdge(p, end);
                    }
                }
            }
        }
        List<Transformation> ordered = TopologicalSort.sort(TopologicalSort.reverseGraph(dg));
        tg.setTransformations(ordered);
    }
}
Also used : Transformation(cx2x.xcodeml.transformation.Transformation) DirectedGraph(cx2x.translator.common.topology.DirectedGraph) TransformationGroup(cx2x.xcodeml.transformation.TransformationGroup) ParallelizeForward(cx2x.translator.transformation.claw.parallelize.ParallelizeForward)

Aggregations

ParallelizeForward (cx2x.translator.transformation.claw.parallelize.ParallelizeForward)2 DirectedGraph (cx2x.translator.common.topology.DirectedGraph)1 ClawLanguage (cx2x.translator.language.base.ClawLanguage)1 ArrayToFctCall (cx2x.translator.transformation.claw.ArrayToFctCall)1 Kcaching (cx2x.translator.transformation.claw.Kcaching)1 Parallelize (cx2x.translator.transformation.claw.parallelize.Parallelize)1 DirectivePrimitive (cx2x.translator.transformation.openacc.DirectivePrimitive)1 OpenAccContinuation (cx2x.translator.transformation.openacc.OpenAccContinuation)1 XcodeMLWorkaround (cx2x.translator.transformation.utility.XcodeMLWorkaround)1 IllegalDirectiveException (cx2x.xcodeml.exception.IllegalDirectiveException)1 AnalyzedPragma (cx2x.xcodeml.language.AnalyzedPragma)1 Transformation (cx2x.xcodeml.transformation.Transformation)1 TransformationGroup (cx2x.xcodeml.transformation.TransformationGroup)1 Xnode (cx2x.xcodeml.xnode.Xnode)1