# HG changeset patch # User Lukas Stadler # Date 1397723173 -7200 # Node ID c570c2fe9d2b65a446b414880d47f933ce1a6c01 # Parent a9509e791df197e603c8f62022c0df2754b07b88 small refactoring of NodeClass.Position, remove duplicated functionality diff -r a9509e791df1 -r c570c2fe9d2b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Thu Apr 17 10:26:13 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Thu Apr 17 10:26:13 2014 +0200 @@ -83,10 +83,8 @@ private final int directInputCount; private final long[] inputOffsets; private final InputType[] inputTypes; - private final String[] inputNames; private final int directSuccessorCount; private final long[] successorOffsets; - private final String[] successorNames; private final Class[] dataTypes; private final boolean canGVN; private final boolean isLeafNode; @@ -126,20 +124,12 @@ directInputCount = scanner.inputOffsets.size(); inputOffsets = sortedLongCopy(scanner.inputOffsets, scanner.inputListOffsets); inputTypes = new InputType[inputOffsets.length]; - inputNames = new String[inputOffsets.length]; for (int i = 0; i < inputOffsets.length; i++) { inputTypes[i] = scanner.types.get(inputOffsets[i]); - inputNames[i] = scanner.names.get(inputOffsets[i]); assert inputTypes[i] != null; - assert inputNames[i] != null; } directSuccessorCount = scanner.successorOffsets.size(); successorOffsets = sortedLongCopy(scanner.successorOffsets, scanner.successorListOffsets); - successorNames = new String[successorOffsets.length]; - for (int i = 0; i < successorOffsets.length; i++) { - successorNames[i] = scanner.names.get(successorOffsets[i]); - assert successorNames[i] != null; - } dataOffsets = sortedLongCopy(scanner.dataOffsets); dataTypes = new Class[dataOffsets.length]; @@ -358,9 +348,9 @@ */ public static final class Position { - public final boolean input; - public final int index; - public final int subIndex; + private final boolean input; + private final int index; + private final int subIndex; public Position(boolean input, int index, int subIndex) { this.input = input; @@ -382,7 +372,7 @@ } public String getInputName(Node node) { - return node.getNodeClass().getEdgeName(this); + return node.getNodeClass().getName(this); } public void set(Node node, Node value) { @@ -426,6 +416,18 @@ } return true; } + + public int getSubIndex() { + return subIndex; + } + + public int getIndex() { + return index; + } + + public boolean isInput() { + return input; + } } private static Node getNode(Node node, long offset) { @@ -895,43 +897,39 @@ if (this == from) { return true; } - long[] offsets = pos.input ? inputOffsets : successorOffsets; - if (pos.index >= offsets.length) { + long[] offsets = pos.isInput() ? inputOffsets : successorOffsets; + if (pos.getIndex() >= offsets.length) { return false; } - long[] fromOffsets = pos.input ? from.inputOffsets : from.successorOffsets; - if (pos.index >= fromOffsets.length) { + long[] fromOffsets = pos.isInput() ? from.inputOffsets : from.successorOffsets; + if (pos.getIndex() >= fromOffsets.length) { return false; } - return offsets[pos.index] == fromOffsets[pos.index]; + return offsets[pos.getIndex()] == fromOffsets[pos.getIndex()]; } public Node get(Node node, Position pos) { - long offset = pos.input ? inputOffsets[pos.index] : successorOffsets[pos.index]; - if (pos.subIndex == NOT_ITERABLE) { + long offset = pos.isInput() ? inputOffsets[pos.getIndex()] : successorOffsets[pos.getIndex()]; + if (pos.getSubIndex() == NOT_ITERABLE) { return getNode(node, offset); } else { - return getNodeList(node, offset).get(pos.subIndex); + return getNodeList(node, offset).get(pos.getSubIndex()); } } public InputType getInputType(Position pos) { - assert pos.input; - return inputTypes[pos.index]; - } - - public String getEdgeName(Position pos) { - return pos.input ? inputNames[pos.index] : successorNames[pos.index]; + assert pos.isInput(); + return inputTypes[pos.getIndex()]; } public NodeList getNodeList(Node node, Position pos) { - long offset = pos.input ? inputOffsets[pos.index] : successorOffsets[pos.index]; - assert pos.subIndex == NODE_LIST; + long offset = pos.isInput() ? inputOffsets[pos.getIndex()] : successorOffsets[pos.getIndex()]; + assert pos.getSubIndex() == NODE_LIST; return getNodeList(node, offset); } public String getName(Position pos) { - return fieldNames.get(pos.input ? inputOffsets[pos.index] : successorOffsets[pos.index]); + return fieldNames.get(pos.isInput() ? inputOffsets[pos.getIndex()] : successorOffsets[pos.getIndex()]); } void updateInputSuccInPlace(Node node, InplaceUpdateClosure duplicationReplacement) { @@ -1017,22 +1015,22 @@ } public void set(Node node, Position pos, Node x) { - long offset = pos.input ? inputOffsets[pos.index] : successorOffsets[pos.index]; - if (pos.subIndex == NOT_ITERABLE) { + long offset = pos.isInput() ? inputOffsets[pos.getIndex()] : successorOffsets[pos.getIndex()]; + if (pos.getSubIndex() == NOT_ITERABLE) { Node old = getNode(node, offset); - assert x == null || fieldTypes.get((pos.input ? inputOffsets : successorOffsets)[pos.index]).isAssignableFrom(x.getClass()) : this + ".set(node, pos, " + x + ")"; + assert x == null || fieldTypes.get((pos.isInput() ? inputOffsets : successorOffsets)[pos.getIndex()]).isAssignableFrom(x.getClass()) : this + ".set(node, pos, " + x + ")"; putNode(node, offset, x); - if (pos.input) { + if (pos.isInput()) { node.updateUsages(old, x); } else { node.updatePredecessor(old, x); } } else { NodeList list = getNodeList(node, offset); - if (pos.subIndex < list.size()) { - list.set(pos.subIndex, x); + if (pos.getSubIndex() < list.size()) { + list.set(pos.getSubIndex(), x); } else { - while (pos.subIndex < list.size() - 1) { + while (pos.getSubIndex() < list.size() - 1) { list.add(null); } list.add(x); @@ -1455,7 +1453,7 @@ replacement = replacements.replacement(input); } if (replacement != input) { - assert isAssignable(nodeClass.fieldTypes.get(nodeClass.inputOffsets[pos.index]), replacement); + assert isAssignable(nodeClass.fieldTypes.get(nodeClass.inputOffsets[pos.getIndex()]), replacement); target = replacement; } else if (input.graph() == graph) { // patch to the outer world target = input; @@ -1474,7 +1472,7 @@ if (target == null) { Node replacement = replacements.replacement(succ); if (replacement != succ) { - assert isAssignable(nodeClass.fieldTypes.get(node.getNodeClass().successorOffsets[pos.index]), replacement); + assert isAssignable(nodeClass.fieldTypes.get(node.getNodeClass().successorOffsets[pos.getIndex()]), replacement); target = replacement; } } diff -r a9509e791df1 -r c570c2fe9d2b graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java Thu Apr 17 10:26:13 2014 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java Thu Apr 17 10:26:13 2014 +0200 @@ -297,13 +297,13 @@ Collection directInputPositions = nodeClass.getFirstLevelInputPositions(); writeShort((char) directInputPositions.size()); for (Position pos : directInputPositions) { - writeByte(pos.subIndex == NodeClass.NOT_ITERABLE ? 0 : 1); + writeByte(pos.getSubIndex() == NodeClass.NOT_ITERABLE ? 0 : 1); writePoolObject(nodeClass.getName(pos)); } Collection directSuccessorPositions = nodeClass.getFirstLevelSuccessorPositions(); writeShort((char) directSuccessorPositions.size()); for (Position pos : directSuccessorPositions) { - writeByte(pos.subIndex == NodeClass.NOT_ITERABLE ? 0 : 1); + writeByte(pos.getSubIndex() == NodeClass.NOT_ITERABLE ? 0 : 1); writePoolObject(nodeClass.getName(pos)); } } else if (object instanceof ResolvedJavaMethod) { @@ -433,7 +433,7 @@ private void writeEdges(Node node, Collection positions) throws IOException { NodeClass nodeClass = node.getNodeClass(); for (Position pos : positions) { - if (pos.subIndex == NodeClass.NOT_ITERABLE) { + if (pos.getSubIndex() == NodeClass.NOT_ITERABLE) { Node edge = nodeClass.get(node, pos); writeNodeRef(edge); } else { diff -r a9509e791df1 -r c570c2fe9d2b graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Thu Apr 17 10:26:13 2014 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Thu Apr 17 10:26:13 2014 +0200 @@ -380,12 +380,12 @@ continue; } - if (pos.index != lastIndex) { + if (pos.getIndex() != lastIndex) { if (lastIndex != -1) { out.print(suffix); } out.print(prefix).print(node.getNodeClass().getName(pos)).print(": "); - lastIndex = pos.index; + lastIndex = pos.getIndex(); } out.print(nodeToString(node.getNodeClass().get(node, pos))).print(" "); }