[WIP] Local memory optimal alloc heuristic phase
@@ -29,8 +29,6 @@ import org.graalvm.compiler.nodes.ConstantNode;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.phases.BasePhase;
-import jdk.vm.ci.meta.JavaConstant;
-
/**
*
* It filters the nodes for the lenght of the FixedArray node for the local
@@ -47,37 +45,47 @@ public class TornadoLocalMemOptimalAlloc extends BasePhase<TornadoHighTierContex
return;
}
- if (context.getMeta().getDomain().getDepth() != 0) {
+ if ((context.getMeta().getDomain() != null)) {
+ if ((context.getMeta().getDomain().getDepth() != 0)) {
System.out.println("---Optimal Size - - - " + calculateLocalMemAllocSize(context));
+
int opt = calculateLocalMemAllocSize(context);
- NodeIterable<ConstantNode> cNodes = graph.getNodes().filter(ConstantNode.class);
+ // NodeIterable<ConstantNode> cNodes =
+ // graph.getNodes().filter(ConstantNode.class);
NodeIterable<Node> sumNodes = graph.getNodes();
for (Node n : sumNodes) {
- if (n instanceof MarkFixed) {
- System.out.println("Mark access" + n.inputs().first().toString());
+ if (n instanceof MarkFixed && isPowerOfTwo(opt)) {
+ if (((MarkFixed) n).isMemLocal()) {
ConstantNode newLengthNode = ConstantNode.forInt(opt, graph);
n.inputs().first().replaceAndDelete(newLengthNode);
+ System.out.println("Mark access" + n.inputs().first().toString());
+ System.out.println("Is mem local" + ((MarkFixed) n).isMemLocal());
}
}
-
- for (ConstantNode cn : cNodes) {
- int length = ((JavaConstant) cn.getValue()).asInt();
- // System.out.println(cn.predecessor().toString());
- // cn.//
- System.out.println(cn.successors().first());
- // System.out.println(cn.);
- // if (length == 0) {
- // ConstantNode newLengthNode = ConstantNode.forInt(opt, graph);
- // cn.replaceAtUsages(newLengthNode);
- // System.out.println(cn.getValue().toValueString());
+ }
+ // for (ConstantNode cn : cNodes) {
+ // int length = ((JavaConstant) cn.getValue()).asInt();
+ // // System.out.println(cn.predecessor().toString());
+ // // cn.//
+ // System.out.println(cn.successors().first());
+ // // System.out.println(cn.);
+ // // if (length == 0) {
+ // // ConstantNode newLengthNode = ConstantNode.forInt(opt, graph);
+ // // cn.replaceAtUsages(newLengthNode);
+ // // System.out.println(cn.getValue().toValueString());
+ // // }
// }
}
}
}
+ public static boolean isPowerOfTwo(int num) {
+ return num > 0 && (num & (num - 1)) == 0;
+ }
+
private int calculateLocalMemAllocSize(TornadoHighTierContext context) {
int maxBlockSize = (int) context.getDeviceMapping().getDevice().getDeviceMaxWorkItemSizes()[0];
