initial multicore gargbage collection, not finish yet
[IRC.git] / Robust / src / IR / State.java
1 package IR;
2 import IR.Tree.*;
3 import IR.Flat.*;
4 import IR.*;
5 import java.util.*;
6 import Analysis.TaskStateAnalysis.*;
7
8 public class State {
9
10     public int lines;
11   public State() {
12     this.classes=new SymbolTable();
13     this.tasks=new SymbolTable();
14     this.treemethodmap=new Hashtable();
15     this.flatmethodmap=new Hashtable();
16     this.parsetrees=new HashSet();
17     this.arraytypes=new HashSet();
18     this.arraytonumber=new Hashtable();
19     this.tagmap=new Hashtable();
20     this.selfloops=new HashSet();
21     this.excprefetch=new HashSet();
22     this.classpath=new Vector();
23     this.lines=0;
24   }
25
26   public void addParseNode(ParseNode parsetree) {
27     parsetrees.add(parsetree);
28   }
29
30   public void storeAnalysisResult(Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults) {
31     this.analysisresults=analysisresults;
32   }
33
34   public Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> getAnalysisResult() {
35     return analysisresults;
36   }
37
38
39   public void storeOptionalTaskDescriptors(Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors) {
40     this.optionaltaskdescriptors=optionaltaskdescriptors;
41   }
42
43   public Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> getOptionalTaskDescriptors() {
44     return optionaltaskdescriptors;
45   }
46
47
48   /** Boolean flag which indicates whether compiler is compiling a task-based
49    * program. */
50   public boolean WEBINTERFACE=false;
51   public boolean MINIMIZE=false;
52   public boolean TASK=false;
53   public boolean FASTCHECK=false;
54   public boolean DSM=false;
55   public boolean PREFETCH=false;
56   public boolean TASKSTATE=false;
57   public boolean TAGSTATE=false;
58   public boolean FLATIRGRAPH=false;
59   public boolean FLATIRGRAPHTASKS=false;
60   public boolean FLATIRGRAPHUSERMETHODS=false;
61   public boolean FLATIRGRAPHLIBMETHODS=false;
62   public boolean MULTICORE=false;
63         public boolean MULTICOREGC=false;
64   public boolean OWNERSHIP=false;
65   public int OWNERSHIPALLOCDEPTH=3;
66   public boolean OWNERSHIPWRITEDOTS=false;
67   public boolean OWNERSHIPWRITEALL=false;
68   public String OWNERSHIPALIASFILE=null;
69   public boolean OPTIONAL=false;
70   public boolean ARRAYBOUNDARYCHECK=true;
71   public boolean RAW=false;
72   public boolean ARRAYPAD=false;
73   public boolean SCHEDULING=false;
74   public boolean USEPROFILE=false;
75   public String profilename = null;
76   public boolean THREAD=false;
77   public boolean CONSCHECK=false;
78   public boolean INSTRUCTIONFAILURE=false;
79   public boolean MLP=false;
80   public boolean MLPDEBUG=false;
81   public int MLP_NUMCORES=0;
82   public int MLP_MAXSESEAGE=0;
83   public static double TRUEPROB=0.8;
84   public static boolean PRINTFLAT=false;
85   public static boolean PRINTSCHEDULING=false;
86   public static boolean PRINTSCHEDULESIM=false;
87   public static boolean PRINTCRITICALPATH=false;
88   public static boolean ABORTREADERS=false;
89   public static boolean SINGLETM=false;
90   public static boolean READSET=false;
91   public int CORENUM = 1;
92   public String structfile;
93   public String main;
94   public String outputdir = "/scratch/";
95   public boolean INLINEATOMIC=false;
96   public int inlineatomicdepth;
97   public HashSet selfloops;
98   public HashSet excprefetch;
99   public Vector classpath;
100   public SymbolTable classes;
101   public SymbolTable tasks;
102   public Set parsetrees;
103   public Hashtable treemethodmap;
104   public Hashtable flatmethodmap;
105   private HashSet arraytypes;
106   public Hashtable arraytonumber;
107   private int numclasses=0;
108   private int numtasks=0;
109   private int arraycount=0;
110   public boolean OPTIMIZE=false;
111   public boolean DCOPTS=false;
112   public boolean DELAYCOMP=false;
113
114
115   private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
116   private Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults;
117
118   private Hashtable tagmap;
119   private int numtags=0;
120
121   public void addArrayType(TypeDescriptor td) {
122     if (!arraytypes.contains(td)) {
123       arraytypes.add(td);
124       arraytonumber.put(td,new Integer(arraycount++));
125     }
126   }
127
128   public Iterator getArrayIterator() {
129     return arraytypes.iterator();
130   }
131
132   public int getTagId(TagDescriptor tag) {
133     if (tagmap.containsKey(tag)) {
134       return ((Integer) tagmap.get(tag)).intValue();
135     } else {
136       tagmap.put(tag, new Integer(numtags));
137       return numtags++;
138     }
139   }
140
141   public int getArrayNumber(TypeDescriptor td) {
142     if (arraytonumber.containsKey(td))
143       return ((Integer)arraytonumber.get(td)).intValue();
144     else return -1;
145   }
146
147   public int numArrays() {
148     return arraytypes.size();
149   }
150
151   public static TypeDescriptor getTypeDescriptor(int t) {
152     TypeDescriptor td=new TypeDescriptor(t);
153     return td;
154   }
155
156   public static TypeDescriptor getTypeDescriptor(NameDescriptor n) {
157     TypeDescriptor td=new TypeDescriptor(n);
158     return td;
159   }
160
161   public void addClass(ClassDescriptor tdn) {
162     if (classes.contains(tdn.getSymbol()))
163       throw new Error("Class "+tdn.getSymbol()+" defined twice");
164     classes.add(tdn);
165     numclasses++;
166   }
167
168   public int numClasses() {
169     return numclasses;
170   }
171
172   public BlockNode getMethodBody(MethodDescriptor md) {
173     return (BlockNode)treemethodmap.get(md);
174   }
175
176   public BlockNode getMethodBody(TaskDescriptor td) {
177     return (BlockNode)treemethodmap.get(td);
178   }
179
180   public SymbolTable getClassSymbolTable() {
181     return classes;
182   }
183
184   public SymbolTable getTaskSymbolTable() {
185     return tasks;
186   }
187
188   /** Returns Flat IR representation of MethodDescriptor md. */
189
190   public FlatMethod getMethodFlat(MethodDescriptor md) {
191     return (FlatMethod)flatmethodmap.get(md);
192   }
193
194   /** Returns Flat IR representation of TaskDescriptor td. */
195
196   public FlatMethod getMethodFlat(TaskDescriptor td) {
197     return (FlatMethod)flatmethodmap.get(td);
198   }
199
200   // The descriptor is either a method or task desc
201   // and should call one of the above methods
202   public FlatMethod getMethodFlat(Descriptor d) {
203     FlatMethod fm;
204     if( d instanceof MethodDescriptor ) {
205       fm = getMethodFlat( (MethodDescriptor) d);
206     } else {
207       assert d instanceof TaskDescriptor;
208       fm = getMethodFlat( (TaskDescriptor) d);
209     }
210     return fm;
211   }
212
213   public void addTreeCode(MethodDescriptor md, BlockNode bn) {
214     treemethodmap.put(md,bn);
215   }
216
217   public void addTreeCode(TaskDescriptor td, BlockNode bn) {
218     treemethodmap.put(td,bn);
219   }
220
221   public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
222     flatmethodmap.put(md,bn);
223   }
224
225   public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
226     flatmethodmap.put(td,bn);
227   }
228
229   public void addTask(TaskDescriptor td) {
230     if (tasks.contains(td.getSymbol()))
231       throw new Error("Task "+td.getSymbol()+" defined twice");
232     tasks.add(td);
233     numtasks++;
234   }
235 }