Fix bugs in faster dependency algorithm

This commit is contained in:
konsoletyper 2015-03-13 22:48:24 +03:00
parent 2745f1c7f5
commit 3449257db7
2 changed files with 20 additions and 8 deletions

View File

@ -299,11 +299,13 @@ public class DataFlowGraphBuilder implements InstructionReader {
@Override @Override
public void getElement(VariableReader receiver, VariableReader array, VariableReader index) { public void getElement(VariableReader receiver, VariableReader array, VariableReader index) {
important(array.getIndex());
builder.addEdge(getArrayElementNode(array.getIndex()), receiver.getIndex()); builder.addEdge(getArrayElementNode(array.getIndex()), receiver.getIndex());
} }
@Override @Override
public void putElement(VariableReader array, VariableReader index, VariableReader value) { public void putElement(VariableReader array, VariableReader index, VariableReader value) {
important(array.getIndex());
builder.addEdge(value.getIndex(), getArrayElementNode(array.getIndex())); builder.addEdge(value.getIndex(), getArrayElementNode(array.getIndex()));
} }

View File

@ -48,10 +48,6 @@ class DependencyGraphBuilder {
return; return;
} }
program = method.getProgram(); program = method.getProgram();
if (DependencyChecker.shouldLog) {
System.out.println("Method reached: " + method.getReference());
System.out.println(new ListingBuilder().buildListing(program, " "));
}
resultNode = dep.getResult(); resultNode = dep.getResult();
DataFlowGraphBuilder dfgBuilder = new DataFlowGraphBuilder(); DataFlowGraphBuilder dfgBuilder = new DataFlowGraphBuilder();
@ -60,6 +56,17 @@ class DependencyGraphBuilder {
} }
int[] nodeMapping = dfgBuilder.buildMapping(program, dep.getParameterCount(), int[] nodeMapping = dfgBuilder.buildMapping(program, dep.getParameterCount(),
!(method.getResultType() instanceof ValueType.Primitive) && method.getResultType() != ValueType.VOID); !(method.getResultType() instanceof ValueType.Primitive) && method.getResultType() != ValueType.VOID);
if (DependencyChecker.shouldLog) {
System.out.println("Method reached: " + method.getReference());
System.out.print(new ListingBuilder().buildListing(program, " "));
for (int i = 0; i < nodeMapping.length; ++i) {
System.out.print(i + ":" + nodeMapping[i] + " ");
}
System.out.println();
System.out.println();
}
int nodeClassCount = 0; int nodeClassCount = 0;
for (int i = 0; i < nodeMapping.length; ++i) { for (int i = 0; i < nodeMapping.length; ++i) {
nodeClassCount = Math.max(nodeClassCount, nodeMapping[i] + 1); nodeClassCount = Math.max(nodeClassCount, nodeMapping[i] + 1);
@ -67,6 +74,9 @@ class DependencyGraphBuilder {
DependencyNode[] nodeClasses = Arrays.copyOf(dep.getVariables(), nodeClassCount); DependencyNode[] nodeClasses = Arrays.copyOf(dep.getVariables(), nodeClassCount);
for (int i = dep.getVariableCount(); i < nodeClasses.length; ++i) { for (int i = dep.getVariableCount(); i < nodeClasses.length; ++i) {
nodeClasses[i] = dependencyChecker.createNode(); nodeClasses[i] = dependencyChecker.createNode();
if (DependencyChecker.shouldLog) {
nodeClasses[i].setTag(dep.getMethod().getReference() + ":" + i);
}
} }
nodes = new DependencyNode[dep.getMethod().getProgram().variableCount()]; nodes = new DependencyNode[dep.getMethod().getProgram().variableCount()];
for (int i = 0; i < nodes.length; ++i) { for (int i = 0; i < nodes.length; ++i) {
@ -415,9 +425,9 @@ class DependencyGraphBuilder {
@Override @Override
public void getField(VariableReader receiver, VariableReader instance, FieldReference field, public void getField(VariableReader receiver, VariableReader instance, FieldReference field,
ValueType fieldType) { ValueType fieldType) {
FieldDependency fieldDep = dependencyChecker.linkField(field,
new CallLocation(caller.getMethod(), currentLocation));
if (!(fieldType instanceof ValueType.Primitive)) { if (!(fieldType instanceof ValueType.Primitive)) {
FieldDependency fieldDep = dependencyChecker.linkField(field,
new CallLocation(caller.getMethod(), currentLocation));
DependencyNode receiverNode = nodes[receiver.getIndex()]; DependencyNode receiverNode = nodes[receiver.getIndex()];
if (receiverNode != null) { if (receiverNode != null) {
fieldDep.getValue().connect(receiverNode); fieldDep.getValue().connect(receiverNode);
@ -429,9 +439,9 @@ class DependencyGraphBuilder {
@Override @Override
public void putField(VariableReader instance, FieldReference field, VariableReader value, public void putField(VariableReader instance, FieldReference field, VariableReader value,
ValueType fieldType) { ValueType fieldType) {
FieldDependency fieldDep = dependencyChecker.linkField(field,
new CallLocation(caller.getMethod(), currentLocation));
if (!(fieldType instanceof ValueType.Primitive)) { if (!(fieldType instanceof ValueType.Primitive)) {
FieldDependency fieldDep = dependencyChecker.linkField(field,
new CallLocation(caller.getMethod(), currentLocation));
DependencyNode valueNode = nodes[value.getIndex()]; DependencyNode valueNode = nodes[value.getIndex()];
if (valueNode != null) { if (valueNode != null) {
valueNode.connect(fieldDep.getValue()); valueNode.connect(fieldDep.getValue());