use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.
the class Serialization method createReadWriteFctCall.
/**
* @param xcodeml Current XcodeML translation unit.
* @param savepointName Name of the savepoint (will be part of the serialized
* name)
* @param field Representation of the field.
* @param callType Type of serialization call from the enum.
* @return exprStmt node created with the specific function call inside.
*/
private static Xnode createReadWriteFctCall(XcodeProgram xcodeml, String savepointName, String field, String fieldName, SerializationCall callType) {
// Create the char constant type
Xnode nameArg = xcodeml.createCharConstant(savepointName + "_" + fieldName);
Xnode varArg = xcodeml.createVar(FortranType.REAL, field, Xscope.GLOBAL);
FunctionCall serCall = createBaseSerFctCall(xcodeml, callType);
serCall.addArguments(nameArg);
serCall.addArguments(varArg);
if (callType == SerializationCall.SER_READ_PERTURB) {
Xnode perturbArg = xcodeml.createVar(FortranType.REAL, SER_PPSER_ZPERTURB, Xscope.GLOBAL);
serCall.addArguments(perturbArg);
}
Xnode exprStmt = xcodeml.createNode(Xcode.EXPR_STATEMENT);
exprStmt.insert(serCall);
return exprStmt;
}
use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.
the class ExpandNotation method generateDoStmtNotation.
/**
* Generate the corresponding do statements for the array notations. A do
* statement is generated per dimension of the arrays. Iteration index range are
* computed with array dimensions.
*
* @param xcodeml The XcodeML on which the transformations are applied.
* @param translator The translator used to applied the transformations.
* @param fctDef The function definition in which the array notation is
* nested.
* @param ranges The list of iteration ranges to be applied to the created
* do statements.
* @param statements The list of assign statements (array notation) that will be
* included in the nested do statements.
* @param doStmtGrip Grip for the code insertion. Do statements will be inserted
* after the grip element.
* @return Block surrounding the do statements generated.
*/
private Xblock generateDoStmtNotation(XcodeProgram xcodeml, ClawTranslator translator, FfunctionDefinition fctDef, List<Xnode> ranges, List<Xnode> statements, Xnode doStmtGrip) throws IllegalTransformationException {
String[] inductionVars = new String[ranges.size()];
Xnode[] doStmts = new Xnode[ranges.size()];
Xnode var = statements.get(0).matchSeq(Xcode.F_ARRAY_REF, Xcode.VAR_REF, Xcode.VAR);
if (var == null) {
var = statements.get(0).matchSeq(Xcode.F_ARRAY_REF, Xcode.VAR_REF, Xcode.F_MEMBER_REF);
}
// 1. Create do statements with induction variables
for (int i = 0; i < ranges.size(); ++i) {
// 1.1 Create induction variables
if (_clawStart.hasClause(ClawClause.INDUCTION)) {
// Use user names
inductionVars[i] = _clawStart.values(ClawClause.INDUCTION).get(i);
} else {
// generate new names
inductionVars[i] = "claw_induction_" + translator.getNextTransformationCounter();
}
// 2.2 inject a new entry in the symbol table
if (!fctDef.getSymbolTable().contains(inductionVars[i])) {
Xid inductionVarId = xcodeml.createId(FortranType.INTEGER, XstorageClass.F_LOCAL, inductionVars[i]);
fctDef.getSymbolTable().add(inductionVarId, false);
}
// 2.3 inject a new entry in the declaration table
if (!fctDef.getDeclarationTable().contains(inductionVars[i])) {
Xnode inductionVarDecl = xcodeml.createVarDecl(FortranType.INTEGER, inductionVars[i]);
fctDef.getDeclarationTable().add(inductionVarDecl);
}
// 2.4 create do statements
Xnode inductionVar = xcodeml.createVar(FortranType.INTEGER, inductionVars[i], Xscope.LOCAL);
Xnode range;
if (ranges.get(i).getBooleanAttribute(Xattr.IS_ASSUMED_SHAPE)) {
// Allocatable array
// dimension argument of size starts at one
range = xcodeml.createRangeForAssumedShapeArray(var, 1, i + 1);
} else {
range = ranges.get(i).cloneNode();
}
doStmts[i] = xcodeml.createDoStmt(inductionVar, range);
statements.get(0).copyEnhancedInfo(doStmts[i]);
if (i == 0) {
// most outer loop goes after the pragma
doStmtGrip.insertAfter(doStmts[i]);
} else {
// others loop go in the previous one
doStmts[i - 1].body().append(doStmts[i]);
}
}
for (Xnode stmt : statements) {
// 3. Adapt array reference with induction variables
List<Xnode> allArrayRef = stmt.matchAll(Xcode.F_ARRAY_REF);
for (Xnode arrayRef : allArrayRef) {
for (int i = 0; i < arrayRef.children().size() - 1; ++i) {
Xnode el = arrayRef.child(i + 1);
if (Xnode.isOfCode(el, Xcode.INDEX_RANGE) && i < doStmts.length) {
String induction = doStmts[i].matchSeq(Xcode.VAR).value();
Xnode inductionVar = xcodeml.createVar(FortranType.INTEGER, induction, Xscope.LOCAL);
Xnode arrayIdx = xcodeml.createNode(Xcode.ARRAY_INDEX);
arrayIdx.append(inductionVar);
el.insertAfter(arrayIdx);
el.delete();
}
}
}
stmt.matchAll(Xcode.FUNCTION_CALL).stream().map(FunctionCall::new).filter(x -> x.isIntrinsicCall(Xintrinsic.SUM)).forEach(FunctionCall::adaptIntrinsicSumCall);
stmt.matchAll(Xcode.FUNCTION_CALL).stream().map(FunctionCall::new).filter(x -> x.isIntrinsicCall(Xintrinsic.SPREAD)).forEach(FunctionCall::adaptIntrinsicSpreadCall);
// 4. Move assignment statement inside the most inner loop
doStmts[ranges.size() - 1].body().append(stmt, true);
stmt.delete();
}
// Add any additional transformation defined in the directive clauses
translator.generateAdditionalTransformation(_clawStart, xcodeml, doStmts[0]);
return new Xblock(doStmts[0]);
}
use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.
the class Loop method createDoStmtOverAssumedShapeArray.
/**
* Create a do statement to iterate over an array from 1 to size.
*
* @param fbt FbasicType of the array.
* @param arrayName Array name.
* @param inductionVar Identifier of a the induction variable.
* @param dimId Dimension on which size is called.
* @param xcodeml Current translation unit.
* @return Newly created node.
*/
public static Xnode createDoStmtOverAssumedShapeArray(FbasicType fbt, String arrayName, String inductionVar, int dimId, XcodeML xcodeml) {
// Induction variable
Xnode induction = xcodeml.createVar(FortranType.INTEGER, inductionVar, Xscope.LOCAL);
// Lower bound
Xnode lb = xcodeml.createNode(Xcode.LOWER_BOUND);
lb.append(xcodeml.createIntConstant(1));
// upper bound
Xnode up = xcodeml.createNode(Xcode.UPPER_BOUND);
FunctionCall sizeCall = xcodeml.createIntrinsicFctCall(FortranType.INTEGER, Xintrinsic.SIZE);
sizeCall.addArguments(xcodeml.createVar(fbt.getType(), arrayName, Xscope.LOCAL));
sizeCall.addArguments(xcodeml.createIntConstant(dimId));
up.append(sizeCall);
// step
Xnode step = xcodeml.createNode(Xcode.STEP);
step.append(xcodeml.createIntConstant(1));
Xnode range = xcodeml.createNode(Xcode.INDEX_RANGE);
range.append(lb);
range.append(up);
range.append(step);
return xcodeml.createDoStmt(induction, range);
}
use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.
the class XcodeML method createIntrinsicFctCall.
/**
* Create a new functionCall node with name and arguments as children nodes.
*
* {@code
* <functionCall type="returnType">
* <name type="fctType">fctName</name>
* <arguments></arguments>
* </functionCall>
* }
*
* @param returnType Value of the type attribute for the functionCall node.
* @param fctName Value of the name node.
* @return The newly created node detached in the current XcodeML unit.
*/
public FunctionCall createIntrinsicFctCall(FortranType returnType, Xintrinsic fctName) {
FunctionCall fctCall = createFctCall(returnType.toString(), fctName.toString(), null);
fctCall.setBooleanAttribute(Xattr.IS_INTRINSIC, true);
return fctCall;
}
use of claw.tatsu.xcodeml.abstraction.FunctionCall in project claw-compiler by C2SM-RCM.
the class XcodeML method createRangeForAssumedShapeArray.
/**
* Create an indexRange element to loop over an assumed shape array.
*
* @param arrayVar Var element representing the array variable.
* @param startIndex Lower bound index value.
* @param dimension Dimension index for the upper bound value.
* @return The newly created node detached in the current XcodeML unit.
*/
public Xnode createRangeForAssumedShapeArray(Xnode arrayVar, int startIndex, int dimension) {
// Lower bound
Xnode lower = createNode(Xcode.LOWER_BOUND).append(createIntConstant(startIndex));
// Upper bound
FunctionCall fctCall = createIntrinsicFctCall(FortranType.INTEGER, Xintrinsic.SIZE);
fctCall.addArguments(arrayVar.cloneNode());
fctCall.addArguments(createIntConstant(dimension));
Xnode upper = createNode(Xcode.UPPER_BOUND).append(fctCall);
return createNode(Xcode.INDEX_RANGE).append(lower).append(upper);
}
Aggregations