use of claw.tatsu.xcodeml.abstraction.AssignStatement in project claw-compiler by C2SM-RCM.
the class ScaCPUvectorizeGroup method detectIndirectPromotion.
/**
* Iterate over all assign statements to detect all indirect promotion. Apply
* correct promotion if detected.
*
* @param assignStatements List of assignment statements
*/
private void detectIndirectPromotion(List<AssignStatement> assignStatements) {
/*
* If the assignment is in the column loop and is composed with some promoted
* variables, the field must be promoted and the var reference switch to an
* array reference
*/
for (AssignStatement assign : assignStatements) {
Xnode lhs = assign.getLhs();
if ((Xnode.isOfCode(lhs, Xcode.VAR) || Xnode.isOfCode(lhs, Xcode.F_ARRAY_REF)) && !_noPromotion.contains(assign.getLhsName()) && !_inductionVariables.contains(assign.getLhsName()) && !_arrayFieldsInOut.contains(assign.getLhsName()) && shouldBePromoted(assign)) {
_arrayFieldsInOut.add(assign.getLhsName());
_temporaryFieldsToPromote.add(assign.getLhsName());
}
}
}
use of claw.tatsu.xcodeml.abstraction.AssignStatement in project claw-compiler by C2SM-RCM.
the class ScaCPUvectorizeGroup method checkMissingPromotion.
/**
* Check for potential missing promotions of scalar fields.
*
* @param blocks List of blocks.
*/
private void checkMissingPromotion(Context context, List<VectorBlock> blocks) {
for (String var : _scalarFields) {
// If shared by multiple block and not promoted yet.
if (isVarSharedByMultipleBlocks(blocks, var) && isVarNotOnlyConstant(var) && isVarWrittenInBlocks(blocks, var) && !_arrayFieldsInOut.contains(var) && !_inductionVariables.contains(var) && !_noPromotion.contains(var)) {
Message.debug(context, String.format("%s Promotion might be missing for: %s", SCA_DEBUG_PREFIX, var));
_temporaryFieldsToPromote.add(var);
for (AssignStatement as : _fctDef.gatherAssignStatementsByLhsName(var)) {
// Check that assignments are contained in a vector block
if (!VectorBlock.isContainedIn(blocks, as)) {
blocks.add(new VectorBlock(as));
}
}
}
}
}
use of claw.tatsu.xcodeml.abstraction.AssignStatement in project claw-compiler by C2SM-RCM.
the class ScaCPUvectorizeGroup method flagDoStatementLocation.
/**
* Go through all assignments and flag all location where a do statement should
* be inserted after variables promotion.
*
* @param assignStatements List of assignments.
* @return Set of vector blocks as flag to do statement insertion location.
*/
private Set<VectorBlock> flagDoStatementLocation(List<AssignStatement> assignStatements) {
Set<VectorBlock> blocks = flagIfStatementWithPromotion();
/*
* Iterate a second time over assign statements to flag places where to insert
* the do statements
*/
for (AssignStatement assign : assignStatements) {
Xnode lhs = assign.getLhs();
String lhsName = assign.getLhsName();
boolean wrapInDoStatement = true;
// Check if assignment is dependant of an if statement.
if (assign.isChildOf(Xcode.F_IF_STATEMENT)) {
// Gather all potential ancestor if statements
List<Xnode> ifStatements = assign.matchAllAncestor(Xcode.F_IF_STATEMENT, Xcode.F_FUNCTION_DEFINITION);
Xnode flaggedIfStmt = null;
Set<String> assignVars = assign.getVarNames();
assignVars.retainAll(_arrayFieldsInOut);
for (Xnode ifStmt : ifStatements) {
if (Condition.dependsOn(ifStmt.matchDirectDescendant(Xcode.CONDITION), assignVars)) {
// Have to put the do statement around the if as the assignment
// is conditional as well.
flaggedIfStmt = ifStmt;
}
}
if (flaggedIfStmt != null) {
wrapInDoStatement = false;
boolean addFlaggedIf = true;
// Get rid of previously flagged location in this if body.
Iterator<VectorBlock> iter = blocks.iterator();
while (iter.hasNext()) {
Xnode crt = iter.next().getStartStmt();
if (assign.isNestedIn(crt) || flaggedIfStmt.isNestedIn(crt)) {
addFlaggedIf = false;
}
if (crt.isNestedIn(flaggedIfStmt)) {
iter.remove();
}
}
if (addFlaggedIf) {
blocks.add(new VectorBlock(flaggedIfStmt));
}
}
}
for (VectorBlock block : blocks) {
if (assign.isNestedIn(block.getStartStmt())) {
wrapInDoStatement = false;
break;
}
}
if (((Xnode.isOfCode(lhs, Xcode.F_ARRAY_REF) || Xnode.isOfCode(lhs, Xcode.VAR)) && _arrayFieldsInOut.contains(lhsName) && wrapInDoStatement) || ((Xnode.isOfCode(lhs, Xcode.VAR) || Xnode.isOfCode(lhs, Xcode.F_ARRAY_REF) && _scalarFields.contains(lhsName)) && (shouldBePromoted(assign) && wrapInDoStatement))) {
blocks.add(new VectorBlock(assign));
}
}
return blocks;
}
use of claw.tatsu.xcodeml.abstraction.AssignStatement in project claw-compiler by C2SM-RCM.
the class XnodeUtil method getWrittenArraysInRegion.
/**
* Gather all array identifiers written in the given block.
*
* @param from Node from which the block starts.
* @param to Node to which the block ends.
* @return List of array identifiers written to in the block.
*/
public static List<String> getWrittenArraysInRegion(Xnode from, Xnode to) {
Set<String> writtenArraysIds = new HashSet<>();
List<Xnode> firstLevelNodesInRegion;
if (to == null) {
firstLevelNodesInRegion = Collections.singletonList(from.nextSibling());
} else {
firstLevelNodesInRegion = getSiblingsBetween(from, to);
}
for (Xnode node : firstLevelNodesInRegion) {
List<AssignStatement> assignements;
if (node.is(Xcode.F_ASSIGN_STATEMENT)) {
assignements = Collections.singletonList(new AssignStatement(node.element()));
} else {
assignements = node.matchAll(Xcode.F_ASSIGN_STATEMENT).stream().map(Xnode::element).map(AssignStatement::new).collect(Collectors.toList());
}
for (AssignStatement as : assignements) {
Xnode lhs = as.getLhs();
if (lhs.is(Xcode.F_ARRAY_REF)) {
writtenArraysIds.add(lhs.constructRepresentation(false, false));
}
}
}
return new ArrayList<>(writtenArraysIds);
}
use of claw.tatsu.xcodeml.abstraction.AssignStatement in project claw-compiler by C2SM-RCM.
the class VectorBlock method fillUpWrittenVariables.
private void fillUpWrittenVariables(Xnode root) {
List<Xnode> assignStatements = root.matchAll(Xcode.F_ASSIGN_STATEMENT);
for (Xnode assign : assignStatements) {
AssignStatement as = new AssignStatement(assign.element());
_writtenVariables.add(as.getLhsName());
}
}
Aggregations