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.dfsolver; 014 015 import java.util.Enumeration; 016 import java.util.HashSet; 017 import java.util.Iterator; 018 019 import org.jikesrvm.compilers.opt.util.GraphNode; 020 021 /** 022 * Represents a single lattice cell in a dataflow system. 023 */ 024 public abstract class DF_AbstractCell implements DF_LatticeCell { 025 /** 026 * Set of DF_Equations which use this lattice cell. 027 */ 028 private final HashSet<DF_Equation> uses; 029 /** 030 * Set of DF_Equations which define this lattice cell. 031 */ 032 private final HashSet<DF_Equation> defs; 033 034 /** 035 * Default Constructor 036 */ 037 public DF_AbstractCell() { 038 uses = new HashSet<DF_Equation>(1); 039 defs = new HashSet<DF_Equation>(1); 040 } 041 042 /** 043 * This constructor bounds the initial capacity to save space. 044 * @param capacity the initial capacity of the "uses" set 045 */ 046 public DF_AbstractCell(int capacity) { 047 uses = new HashSet<DF_Equation>(capacity); 048 defs = new HashSet<DF_Equation>(capacity); 049 } 050 051 @Override 052 public Iterator<DF_Equation> getUses() { 053 return uses.iterator(); 054 } 055 056 @Override 057 public Iterator<DF_Equation> getDefs() { 058 return defs.iterator(); 059 } 060 061 @Override 062 public abstract String toString(); 063 064 @Override 065 public void addUse(DF_Equation eq) { 066 uses.add(eq); 067 } 068 069 @Override 070 public void addDef(DF_Equation eq) { 071 defs.add(eq); 072 } 073 074 @Override 075 public Enumeration<GraphNode> inNodes() { 076 return new Enumeration<GraphNode>() { 077 private final Iterator<DF_Equation> i = defs.iterator(); 078 079 @Override 080 public boolean hasMoreElements() { return i.hasNext(); } 081 082 @Override 083 public GraphNode nextElement() { return i.next(); } 084 }; 085 } 086 087 @Override 088 public Enumeration<GraphNode> outNodes() { 089 return new Enumeration<GraphNode>() { 090 private final Iterator<DF_Equation> i = uses.iterator(); 091 092 @Override 093 public boolean hasMoreElements() { return i.hasNext(); } 094 095 @Override 096 public GraphNode nextElement() { return i.next(); } 097 }; 098 } 099 100 /** 101 * Field used for GraphNode interface. TODO: is this needed? 102 */ 103 private int index; 104 105 /** 106 * Implementation of GraphNode interface. 107 */ 108 @Override 109 public void setIndex(int i) { 110 index = i; 111 } 112 113 @Override 114 public int getIndex() { 115 return index; 116 } 117 118 private int scratch; 119 120 @Override 121 public int getScratch() { 122 return scratch; 123 } 124 125 @Override 126 public int setScratch(int o) { 127 return (scratch = o); 128 } 129 } 130 131 132