Search in sources :

Example 1 with TransformationGroup

use of cx2x.xcodeml.transformation.TransformationGroup in project claw-compiler by C2SM-RCM.

the class ClawXcodeMlTranslator method transform.

/**
   * Apply all the transformation in the pipeline.
   */
public void transform() {
    try {
        if (!_canTransform) {
            _program.write(_xcodemlOutputFile, ClawConstant.INDENT_OUTPUT);
            return;
        }
        reorderTransformations();
        for (Map.Entry<Class, TransformationGroup> entry : _transformer.getGroups().entrySet()) {
            if (XmOption.isDebugOutput()) {
                System.out.println("Apply transformation: " + entry.getValue().transformationName() + " - " + entry.getValue().count());
            }
            try {
                entry.getValue().applyTranslations(_program, _transformer);
                displayWarnings();
            } catch (IllegalTransformationException itex) {
                _program.addError(itex.getMessage(), itex.getStartLine());
                abort();
            } catch (Exception ex) {
                ex.printStackTrace();
                _program.addError("Unexpected error: " + ex.getMessage(), 0);
                if (XmOption.isDebugOutput()) {
                    StringWriter errors = new StringWriter();
                    ex.printStackTrace(new PrintWriter(errors));
                    _program.addError(errors.toString(), 0);
                }
                abort();
            }
        }
        // Write transformed IR to file
        _program.write(_xcodemlOutputFile, ClawConstant.INDENT_OUTPUT);
    } catch (Exception ex) {
        System.err.println("Transformation exception: " + ex.getMessage());
    }
}
Also used : StringWriter(java.io.StringWriter) IllegalTransformationException(cx2x.xcodeml.exception.IllegalTransformationException) TransformationGroup(cx2x.xcodeml.transformation.TransformationGroup) IllegalDirectiveException(cx2x.xcodeml.exception.IllegalDirectiveException) IllegalTransformationException(cx2x.xcodeml.exception.IllegalTransformationException) PrintWriter(java.io.PrintWriter)

Example 2 with TransformationGroup

use of cx2x.xcodeml.transformation.TransformationGroup 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

TransformationGroup (cx2x.xcodeml.transformation.TransformationGroup)2 DirectedGraph (cx2x.translator.common.topology.DirectedGraph)1 ParallelizeForward (cx2x.translator.transformation.claw.parallelize.ParallelizeForward)1 IllegalDirectiveException (cx2x.xcodeml.exception.IllegalDirectiveException)1 IllegalTransformationException (cx2x.xcodeml.exception.IllegalTransformationException)1 Transformation (cx2x.xcodeml.transformation.Transformation)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1