001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Eclipse Public License (EPL);
005 * You may not use this file except in compliance with the License. You
006 * may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 * See the COPYRIGHT.txt file distributed with this work for information
011 * regarding copyright ownership.
012 */
013 package org.jikesrvm.compilers.opt.util;
014
015 import java.util.Enumeration;
016
017
018 public abstract class SortedGraphNode extends SpaceEffGraphNode {
019
020 // Return enumerator for all the in nodes.
021 public abstract Enumeration<? extends SortedGraphNode> getInNodes(); // should be overridden
022 // by a subclass
023
024 // Return enumerator for all the out nodes.
025
026 public abstract Enumeration<? extends SortedGraphNode> getOutNodes(); // should be overridden by a
027 // subclass
028
029 public SortedGraphNode getSortedNext(boolean forward) {
030 if (forward) {
031 return sortedNext;
032 } else {
033 return sortedPrev;
034 }
035 }
036
037 public SortedGraphNode getForwardSortedNext() {
038 return sortedNext;
039 }
040
041 public SortedGraphNode getBackwardSortedNext() {
042 return sortedPrev;
043 }
044
045 public void setSortedNext(SortedGraphNode next, boolean forward) {
046 if (forward) {
047 sortedNext = next;
048 } else {
049 sortedPrev = next;
050 }
051 }
052
053 // preferred interface
054 public void setForwardSortNumber(int number) {
055 forwardSortNumber = number;
056 }
057
058 public int getForwardSortNumber() {
059 return forwardSortNumber;
060 }
061
062 public void setBackwardSortNumber(int number) {
063 backwardSortNumber = number;
064 }
065
066 public int getBackwardSortNumber() {
067 return backwardSortNumber;
068 }
069
070 // probably less efficient than above, but more flexible
071 public void setSortNumber(int number, boolean forward) {
072 if (forward) {
073 forwardSortNumber = number;
074 } else {
075 backwardSortNumber = number;
076 }
077 }
078
079 public int getSortNumber(boolean forward) {
080 if (forward) {
081 return forwardSortNumber;
082 } else {
083 return backwardSortNumber;
084 }
085 }
086
087 public void setSortNumber(int number) {
088 forwardSortNumber = number;
089 }
090
091 // Do we need this?
092 // public int isForwardSorted(SortedGraphNode node) {
093 // return forwardSortNumber - node.forwardSortNumber;
094 // }
095 public static int getNewSortMarker(SortedGraphNode anchor) {
096 if (currentSortMarker == Integer.MAX_VALUE) {
097 SortedGraphNode current;
098 for (current = anchor; current != null; current = current.sortedPrev) {
099 current.sortMarker = Integer.MIN_VALUE;
100 }
101 for (current = anchor; current != null; current = current.sortedNext) {
102 current.sortMarker = Integer.MIN_VALUE;
103 }
104 currentSortMarker = Integer.MIN_VALUE;
105 }
106 return ++currentSortMarker;
107 }
108
109 int sortMarker = Integer.MIN_VALUE;
110 private static int currentSortMarker = Integer.MIN_VALUE;
111
112 public int getSortMarker() {
113 return sortMarker;
114 }
115
116 public void setSortMarker(int sortMarker) {
117 this.sortMarker = sortMarker;
118 }
119
120 public boolean isSortMarkedWith(int sortMarker) {
121 return (this.sortMarker >= sortMarker);
122 }
123
124 public SortedGraphNode sortedPrev = null;
125 public SortedGraphNode sortedNext = null;
126 protected int forwardSortNumber;
127 protected int backwardSortNumber;
128 }