Search in sources :

Example 1 with FunctionCall

use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.

the class LoopExtraction method analyze.

/**
 * Check whether the transformation can be applied.
 *
 * @param xcodeml    The XcodeML on which the transformations are applied.
 * @param translator The translator used to applied the transformations.
 * @return True if the transformation analysis succeeded. False otherwise.
 */
@Override
public boolean analyze(XcodeProgram xcodeml, Translator translator) {
    Xnode _exprStmt = _claw.getPragma().matchSibling(Xcode.EXPR_STATEMENT);
    if (_exprStmt == null) {
        xcodeml.addError("No function call detected after loop-extract", _claw.getPragma().lineNo());
        return false;
    }
    // Find function CALL
    Xnode fctCallNode = _exprStmt.matchDescendant(Xcode.FUNCTION_CALL);
    if (fctCallNode == null) {
        xcodeml.addError("No function call detected after loop-extract", _claw.getPragma().lineNo());
        return false;
    }
    _fctCall = new FunctionCall(fctCallNode);
    Xnode fctDef = _fctCall.matchAncestor(Xcode.F_FUNCTION_DEFINITION);
    if (fctDef == null) {
        xcodeml.addError("No function around the fct call", _claw.getPragma().lineNo());
        return false;
    }
    _fctDef = new FfunctionDefinition(fctDef);
    // Find function declaration
    String fctName = _fctCall.matchDirectDescendant(Xcode.NAME).value();
    _fctDefToExtract = xcodeml.getGlobalDeclarationsTable().getFunctionDefinition(fctName);
    if (_fctDefToExtract == null) {
        xcodeml.addError("Could not locate the function definition for: " + _fctCall.matchDirectDescendant(Xcode.NAME).value(), _claw.getPragma().lineNo());
        return false;
    }
    // Find the loop to be extracted
    try {
        _extractedLoop = locateDoStatement(_fctDefToExtract);
    } catch (IllegalTransformationException itex) {
        xcodeml.addError(itex.getMessage(), _claw.getPragma().lineNo());
        return false;
    }
    return checkMappingInformation(xcodeml);
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionDefinition(claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall)

Example 2 with FunctionCall

use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.

the class Serialization method createBaseSerFctCall.

/**
 * Create the skeletion of a function call for serialization functions.
 *
 * @param xcodeml  Current XcodeML translation unit.
 * @param callType Type of call for the
 * @return Newly create functionCall node.
 */
private static FunctionCall createBaseSerFctCall(XcodeProgram xcodeml, SerializationCall callType) {
    FfunctionType serType = xcodeml.createSubroutineType();
    Xnode savepointArg = xcodeml.createVar(FortranType.STRUCT, SER_PPSER_SAVEPOINT, Xscope.GLOBAL);
    String serFctName;
    switch(callType) {
        case SER_READ:
        case SER_READ_PERTURB:
            serFctName = SER_FS_READ_FIELD;
            break;
        case SER_ADD_METAINFO:
            serFctName = SER_FS_ADD_SP_METAINFO;
            break;
        case SER_WRITE:
        default:
            serFctName = SER_FS_WRITE_FIELD;
    }
    FunctionCall serCall = xcodeml.createFctCall(serType, serFctName);
    if (callType == SerializationCall.SER_WRITE) {
        Xnode serializerArg = xcodeml.createVar(FortranType.STRUCT, SER_PPSER_SERIALIZER, Xscope.GLOBAL);
        serCall.addArguments(serializerArg);
    } else if (callType == SerializationCall.SER_READ || callType == SerializationCall.SER_READ_PERTURB) {
        Xnode serializerArg = xcodeml.createVar(FortranType.STRUCT, SER_PPSER_SERIALIZER_REF, Xscope.GLOBAL);
        serCall.addArguments(serializerArg);
    }
    serCall.addArguments(savepointArg);
    return serCall;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FfunctionType(claw.tatsu.xcodeml.xnode.fortran.FfunctionType) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall)

Example 3 with FunctionCall

use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.

the class Serialization method createAddMetaInfoCall.

/**
 * Create a fs_add_savepoint_metainfo call to the serialization library.
 *
 * @param xcodeml Current XcodeML translation unit.
 * @param key     Metadata key.
 * @param value   Metadata value.
 * @return exprStmt node created with the specific function call inside.
 */
private static Xnode createAddMetaInfoCall(XcodeProgram xcodeml, String key, String value) {
    FunctionCall serCall = createBaseSerFctCall(xcodeml, SerializationCall.SER_ADD_METAINFO);
    // Create the char constant type
    Xnode metadataName = xcodeml.createCharConstant(key);
    serCall.addArguments(metadataName);
    if (value.contains("%")) {
        String[] values = value.split("%");
        serCall.addArguments(xcodeml.createNode(Xcode.F_MEMBER_REF).setAttribute(Xattr.MEMBER, values[1]).append(xcodeml.createNode(Xcode.VAR_REF).append(xcodeml.createNode(Xcode.VAR).setValue(values[0]))));
    } else {
        serCall.addArguments(xcodeml.createNode(Xcode.VAR).setValue(value));
    }
    return xcodeml.createNode(Xcode.EXPR_STATEMENT).insert(serCall);
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall)

Example 4 with FunctionCall

use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.

the class XnodeUtilTest method gatherArgumentsTest.

@Test
public void gatherArgumentsTest() {
    Context context = new TestContext();
    String arg1 = "nz";
    String arg2 = "q(:,1:60)";
    String arg3 = "ty%y(:,:)";
    String arg4 = "z(:)";
    String arg5 = "nproma";
    assertTrue(Files.exists(TestConstant.TEST_ARGUMENTS));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ARGUMENTS, context);
    assertNotNull(xcodeml);
    List<Xnode> functionCalls = xcodeml.matchAll(Xcode.FUNCTION_CALL);
    assertEquals(1, functionCalls.size());
    FunctionCall fctCall = new FunctionCall(functionCalls.get(0));
    assertSame(fctCall.opcode(), Xcode.FUNCTION_CALL);
    FfunctionType fctType = xcodeml.getTypeTable().getFunctionType(fctCall);
    List<String> allArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.ANY, false, false);
    assertEquals(5, allArguments.size());
    assertEquals(arg1, allArguments.get(0));
    assertEquals(arg2, allArguments.get(1));
    assertEquals(arg3, allArguments.get(2));
    assertEquals(arg4, allArguments.get(3));
    assertEquals(arg5, allArguments.get(4));
    List<String> inArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.IN, false, false);
    assertEquals(5, inArguments.size());
    assertEquals(arg1, inArguments.get(0));
    assertEquals(arg2, inArguments.get(1));
    assertEquals(arg3, inArguments.get(2));
    assertEquals(arg4, inArguments.get(3));
    assertEquals(arg5, inArguments.get(4));
    List<String> outArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.OUT, false, false);
    assertEquals(3, outArguments.size());
    assertEquals(arg2, outArguments.get(0));
    assertEquals(arg3, outArguments.get(1));
    assertEquals(arg4, outArguments.get(2));
    List<String> inArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.IN, true, false);
    assertEquals(3, inArrayArguments.size());
    assertEquals(arg2, inArrayArguments.get(0));
    assertEquals(arg3, inArrayArguments.get(1));
    assertEquals(arg4, inArrayArguments.get(2));
    List<String> outArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.OUT, true, false);
    assertEquals(3, outArrayArguments.size());
    assertEquals(arg2, outArrayArguments.get(0));
    assertEquals(arg3, outArrayArguments.get(1));
    assertEquals(arg4, outArrayArguments.get(2));
    List<String> inOutArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.INOUT, true, false);
    assertEquals(3, inOutArrayArguments.size());
    assertEquals(arg2, inOutArrayArguments.get(0));
    assertEquals(arg3, inOutArrayArguments.get(1));
    assertEquals(arg4, inOutArrayArguments.get(2));
// TODO add test with optional arguments
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionType(claw.tatsu.xcodeml.xnode.fortran.FfunctionType) TestContext(helper.Utils.TestContext) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall) Test(org.junit.Test)

Example 5 with FunctionCall

use of claw.tatsu.xcodeml.abstraction.FunctionCall 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)

Aggregations

FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)12 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)7 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)3 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)3 Context (claw.tatsu.common.Context)2 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)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 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)1 Range (claw.tatsu.primitive.Range)1 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)1 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)1 XnodeUtil (claw.tatsu.xcodeml.xnode.XnodeUtil)1 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)1 Xcode (claw.tatsu.xcodeml.xnode.common.Xcode)1 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)1 Xid (claw.tatsu.xcodeml.xnode.common.Xid)1