Search in sources :

Example 6 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class IfExtract method analyze.

@Override
public boolean analyze(XcodeProgram xcodeml, Transformer transformer) {
    _doStmt = _claw.getPragma().matchSibling(Xcode.FDOSTATEMENT);
    if (_doStmt == null) {
        xcodeml.addError("Do statement missing after directive.", _claw.getPragma().lineNo());
        return false;
    }
    _ifStmt = _doStmt.body().matchDirectDescendant(Xcode.FIFSTATEMENT);
    if (_ifStmt == null) {
        xcodeml.addError("If statement not found in the do statement.", _claw.getPragma().lineNo());
        return false;
    }
    int counterIfStmt = 0;
    for (Xnode n : _doStmt.body().children()) {
        if (n.opcode() != Xcode.FIFSTATEMENT && n.opcode() != Xcode.FPRAGMASTATEMENT) {
            xcodeml.addError("If statement is not purely nested in the do statement", _claw.getPragma().lineNo());
            return false;
        } else if (n.opcode() == Xcode.FIFSTATEMENT) {
            ++counterIfStmt;
        }
    }
    if (counterIfStmt > 1) {
        xcodeml.addError("Only one if statement can be present for extraction.", _claw.getPragma().lineNo());
        return false;
    }
    return true;
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode)

Example 7 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class UtilityRemove method analyze.

/**
   * Check whether the transformation can be applied or not.
   *
   * @param xcodeml     The XcodeML on which the transformations are applied.
   * @param transformer The transformer used to applied the transformations.
   * @return True if the transformation can be applied.
   */
@Override
public boolean analyze(XcodeProgram xcodeml, Transformer transformer) {
    // do statement
    if (_clawEnd == null) {
        Xnode next = _clawStart.getPragma().nextSibling();
        _do = next.opcode() == Xcode.FDOSTATEMENT ? next : null;
        _if = next.opcode() == Xcode.FIFSTATEMENT ? next : null;
        _contains = next.opcode() == Xcode.FCONTAINSSTATEMENT ? next : null;
        if (_do == null && _if == null && _contains == null) {
            xcodeml.addError("Directive remove without end not followed by a do " + ", if or contains statement", _clawStart.getPragma().lineNo());
            return false;
        }
    }
    return true;
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode)

Example 8 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class LoopFusion method analyze.

/**
   * Loop fusion analysis:
   * - Without collapse clause: check whether the pragma statement is followed
   * by a do statement.
   * - With collapse clause: Find the n do statements following the pragma.
   *
   * @param xcodeml     The XcodeML on which the transformations are applied.
   * @param transformer The transformer used to applied the transformations.
   * @return True if a do statement is found. False otherwise.
   */
@Override
public boolean analyze(XcodeProgram xcodeml, Transformer transformer) {
    // With collapse clause
    if (_claw.hasCollapseClause() && _claw.getCollapseValue() > 0) {
        _doStmts = new Xnode[_claw.getCollapseValue()];
        for (int i = 0; i < _claw.getCollapseValue(); ++i) {
            if (i == 0) {
                // Find the outer do statement from pragma
                _doStmts[0] = _claw.getPragma().matchSibling(Xcode.FDOSTATEMENT);
            } else {
                // Find the next i loops
                _doStmts[i] = _doStmts[i - 1].body().matchDirectDescendant(Xcode.FDOSTATEMENT);
            }
            if (_doStmts[i] == null) {
                xcodeml.addError("Do statement missing at depth " + i + " after directive.", _claw.getPragma().lineNo());
                return false;
            }
        }
        return true;
    } else {
        // Without collapse clause, locate the do statement after the pragma
        Xnode doStmt = _claw.getPragma().matchSibling(Xcode.FDOSTATEMENT);
        if (doStmt == null) {
            xcodeml.addError("Do statement missing after directive.", _claw.getPragma().lineNo());
            return false;
        }
        _doStmts = new Xnode[] { doStmt };
        return true;
    }
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode) ClawConstraint(cx2x.translator.language.common.ClawConstraint)

Example 9 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class LoopHoist method createIfStatementForLowerBound.

/**
   * Create an IF statement surrounding the entire most inner do statement body.
   * Condition if made from the lower bound (if(induction_var >= lower_bound).
   *
   * @param xcodeml Current XcodeML program
   * @param g       The group of do statements.
   */
private void createIfStatementForLowerBound(XcodeProgram xcodeml, LoopHoistDoStmtGroup g) {
    int nestedDepth = g.getDoStmts().length;
    Xnode ifStmt = new Xnode(Xcode.FIFSTATEMENT, xcodeml);
    Xnode condition = new Xnode(Xcode.CONDITION, xcodeml);
    Xnode thenBlock = new Xnode(Xcode.THEN, xcodeml);
    XnodeUtil.copyEnhancedInfo(g.getDoStmts()[0], ifStmt);
    Xnode cond = new Xnode(Xcode.LOGGEEXPR, xcodeml);
    Xnode inductionVar = g.getDoStmts()[0].matchDirectDescendant(Xcode.VAR);
    cond.append(inductionVar, true);
    cond.append(g.getDoStmts()[0].matchDirectDescendant(Xcode.INDEXRANGE).matchDirectDescendant(Xcode.LOWERBOUND).child(0), true);
    ifStmt.append(condition, false);
    ifStmt.append(thenBlock, false);
    condition.append(cond, false);
    thenBlock.append(g.getDoStmts()[nestedDepth - 1].body(), true);
    g.getDoStmts()[nestedDepth - 1].body().delete();
    Xnode body = new Xnode(Xcode.BODY, xcodeml);
    body.append(ifStmt, false);
    g.getDoStmts()[nestedDepth - 1].append(body, false);
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode)

Example 10 with Xnode

use of cx2x.xcodeml.xnode.Xnode in project claw-compiler by C2SM-RCM.

the class ClawRange method equals.

/**
   * Compare a ClawRange with a do statement.
   *
   * @param doStmt The do statement to compare iteration range.
   * @return True if the iteration range share the same property.
   */
public boolean equals(Xnode doStmt) {
    if (doStmt.opcode() != Xcode.FDOSTATEMENT) {
        return false;
    }
    Xnode inductionVar = doStmt.matchDirectDescendant(Xcode.VAR);
    Xnode indexRange = doStmt.matchDirectDescendant(Xcode.INDEXRANGE);
    Xnode lower = indexRange.matchDirectDescendant(Xcode.LOWERBOUND).child(0);
    Xnode upper = indexRange.matchDirectDescendant(Xcode.UPPERBOUND).child(0);
    Xnode step = indexRange.matchDirectDescendant(Xcode.STEP).child(0);
    return !(inductionVar == null || _inductionVar == null || !inductionVar.value().equals(_inductionVar)) && !(lower == null || _lowerBound == null || !lower.value().equals(_lowerBound)) && !(upper == null || _upperBound == null || !upper.value().equals(_upperBound)) && (step == null && _step == null || !(step == null || _step == null || !_step.equals(step.value())));
}
Also used : Xnode(cx2x.xcodeml.xnode.Xnode)

Aggregations

Xnode (cx2x.xcodeml.xnode.Xnode)31 Configuration (cx2x.translator.config.Configuration)12 AcceleratorGenerator (cx2x.translator.language.helper.accelerator.AcceleratorGenerator)12 IllegalDirectiveException (cx2x.xcodeml.exception.IllegalDirectiveException)12 ClawLanguage (cx2x.translator.language.base.ClawLanguage)11 ClawConstraint (cx2x.translator.language.common.ClawConstraint)6 Test (org.junit.Test)3 IllegalTransformationException (cx2x.xcodeml.exception.IllegalTransformationException)2 XcodeProgram (cx2x.xcodeml.xnode.XcodeProgram)2 File (java.io.File)2 ClawRange (cx2x.translator.language.common.ClawRange)1 ClawReshapeInfo (cx2x.translator.language.common.ClawReshapeInfo)1 ArrayToFctCall (cx2x.translator.transformation.claw.ArrayToFctCall)1 Kcaching (cx2x.translator.transformation.claw.Kcaching)1 Parallelize (cx2x.translator.transformation.claw.parallelize.Parallelize)1 ParallelizeForward (cx2x.translator.transformation.claw.parallelize.ParallelizeForward)1 DirectivePrimitive (cx2x.translator.transformation.openacc.DirectivePrimitive)1 OpenAccContinuation (cx2x.translator.transformation.openacc.OpenAccContinuation)1 XcodeMLWorkaround (cx2x.translator.transformation.utility.XcodeMLWorkaround)1 ClawTransformer (cx2x.translator.transformer.ClawTransformer)1