1 package Analysis.Loops;
4 import java.util.HashSet;
5 import java.util.Hashtable;
7 import java.util.Iterator;
8 import Analysis.Liveness;
11 Hashtable<TempFlatPair, Set<FlatNode>> defs;
12 Hashtable<TempFlatPair, Set<FlatNode>> uses;
17 public UseDef(FlatMethod fm) {
21 /* Return FlatNodes that define Temp */
22 public Set<FlatNode> defMap(FlatNode fn, TempDescriptor t) {
23 Set<FlatNode> s=defs.get(new TempFlatPair(t,fn));
25 return new HashSet<FlatNode>();
30 /* Return FlatNodes that use Temp */
31 public Set<FlatNode> useMap(FlatNode fn, TempDescriptor t) {
32 Set<FlatNode> s=uses.get(new TempFlatPair(t,fn));
34 return new HashSet<FlatNode>();
39 public void analyze(FlatMethod fm) {
40 Hashtable<FlatNode, Set<TempFlatPair>> tmp=new Hashtable<FlatNode, Set<TempFlatPair>>();
41 HashSet<FlatNode> toanalyze=new HashSet<FlatNode>();
42 Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm,-1);
43 toanalyze.addAll(fm.getNodeSet());
44 while(!toanalyze.isEmpty()) {
45 FlatNode fn=toanalyze.iterator().next();
46 TempDescriptor[] fnwrites=fn.writesTemps();
49 HashSet<TempFlatPair> s=new HashSet<TempFlatPair>();
50 Set<TempDescriptor> liveset=livemap.get(fn);
51 for(int i=0; i<fn.numPrev(); i++) {
52 FlatNode prev=fn.getPrev(i);
53 Set<TempFlatPair> prevs=tmp.get(prev);
56 for(Iterator<TempFlatPair> tfit=prevs.iterator(); tfit.hasNext(); ) {
57 TempFlatPair tfp=tfit.next();
58 if (!liveset.contains(tfp.t))
60 for(int j=0; j<fnwrites.length; j++) {
61 if (tfp.t==fnwrites[j])
67 for(int j=0; j<fnwrites.length; j++) {
68 TempFlatPair tfp=new TempFlatPair(fnwrites[j], fn);
72 if (!tmp.containsKey(fn)||
73 !tmp.get(fn).equals(s)) {
75 for(int i=0; i<fn.numNext(); i++)
76 toanalyze.add(fn.getNext(i));
79 Set<FlatNode> fset=fm.getNodeSet();
80 defs=new Hashtable<TempFlatPair, Set<FlatNode>>();
81 uses=new Hashtable<TempFlatPair, Set<FlatNode>>();
82 for(Iterator<FlatNode> fnit=fset.iterator(); fnit.hasNext(); ) {
83 FlatNode fn=fnit.next();
84 TempDescriptor[] fnreads=fn.readsTemps();
85 Set<TempFlatPair> tfpset=tmp.get(fn);
87 for(int i=0; i<fnreads.length; i++) {
88 TempDescriptor readt=fnreads[i];
89 for(Iterator<TempFlatPair> tfpit=tfpset.iterator(); tfpit.hasNext(); ) {
90 TempFlatPair tfp=tfpit.next();
93 if (!uses.containsKey(tfp))
94 uses.put(tfp,new HashSet<FlatNode>());
95 uses.get(tfp).add(fn);
96 TempFlatPair readtfp=new TempFlatPair(readt,fn);
97 if (!defs.containsKey(readtfp))
98 defs.put(readtfp,new HashSet<FlatNode>());
99 defs.get(readtfp).add(tfp.f);
110 TempFlatPair(TempDescriptor t, FlatNode f) {
115 public int hashCode() {
116 return f.hashCode()^t.hashCode();
118 public boolean equals(Object o) {
119 TempFlatPair tf=(TempFlatPair)o;
120 return t.equals(tf.t)&&f.equals(tf.f);