edcb828c20ebd6f9c0a93d8c7c78b52aa74e2adf
[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 boolean METHODEFFECTS=false;
84   public static double TRUEPROB=0.8;
85   public static boolean PRINTFLAT=false;
86   public static boolean PRINTSCHEDULING=false;
87   public static boolean PRINTSCHEDULESIM=false;
88   public static boolean PRINTCRITICALPATH=false;
89   public static boolean ABORTREADERS=false;
90   public static boolean SINGLETM=false;
91   public static boolean READSET=false;
92   public int CORENUM = 1;
93   public String structfile;
94   public String main;
95   public String outputdir = "/scratch/";
96   public boolean INLINEATOMIC=false;
97   public int inlineatomicdepth;
98   public HashSet selfloops;
99   public HashSet excprefetch;
100   public Vector classpath;
101   public SymbolTable classes;
102   public SymbolTable tasks;
103   public Set parsetrees;
104   public Hashtable treemethodmap;
105   public Hashtable flatmethodmap;
106   private HashSet arraytypes;
107   public Hashtable arraytonumber;
108   private int numclasses=1; // start from 1 instead of 0 for multicore gc
109   private int numtasks=0;
110   private int arraycount=0;
111   public boolean OPTIMIZE=false;
112   public boolean DCOPTS=false;
113   public boolean DELAYCOMP=false;
114
115
116   private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
117   private Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults;
118
119   private Hashtable tagmap;
120   private int numtags=0;
121
122   public void addArrayType(TypeDescriptor td) {
123     if (!arraytypes.contains(td)) {
124       arraytypes.add(td);
125       arraytonumber.put(td,new Integer(arraycount++));
126     }
127   }
128
129   public Iterator getArrayIterator() {
130     return arraytypes.iterator();
131   }
132
133   public int getTagId(TagDescriptor tag) {
134     if (tagmap.containsKey(tag)) {
135       return ((Integer) tagmap.get(tag)).intValue();
136     } else {
137       tagmap.put(tag, new Integer(numtags));
138       return numtags++;
139     }
140   }
141
142   public int getArrayNumber(TypeDescriptor td) {
143     if (arraytonumber.containsKey(td))
144       return ((Integer)arraytonumber.get(td)).intValue();
145     else return -1;
146   }
147
148   public int numArrays() {
149     return arraytypes.size();
150   }
151
152   public static TypeDescriptor getTypeDescriptor(int t) {
153     TypeDescriptor td=new TypeDescriptor(t);
154     return td;
155   }
156
157   public static TypeDescriptor getTypeDescriptor(NameDescriptor n) {
158     TypeDescriptor td=new TypeDescriptor(n);
159     return td;
160   }
161
162   public void addClass(ClassDescriptor tdn) {
163     if (classes.contains(tdn.getSymbol()))
164       throw new Error("Class "+tdn.getSymbol()+" defined twice");
165     classes.add(tdn);
166     numclasses++;
167   }
168
169   public int numClasses() {
170     return numclasses;
171   }
172
173   public BlockNode getMethodBody(MethodDescriptor md) {
174     return (BlockNode)treemethodmap.get(md);
175   }
176
177   public BlockNode getMethodBody(TaskDescriptor td) {
178     return (BlockNode)treemethodmap.get(td);
179   }
180
181   public SymbolTable getClassSymbolTable() {
182     return classes;
183   }
184
185   public SymbolTable getTaskSymbolTable() {
186     return tasks;
187   }
188
189   /** Returns Flat IR representation of MethodDescriptor md. */
190
191   public FlatMethod getMethodFlat(MethodDescriptor md) {
192     return (FlatMethod)flatmethodmap.get(md);
193   }
194
195   /** Returns Flat IR representation of TaskDescriptor td. */
196
197   public FlatMethod getMethodFlat(TaskDescriptor td) {
198     return (FlatMethod)flatmethodmap.get(td);
199   }
200
201   // The descriptor is either a method or task desc
202   // and should call one of the above methods
203   public FlatMethod getMethodFlat(Descriptor d) {
204     FlatMethod fm;
205     if( d instanceof MethodDescriptor ) {
206       fm = getMethodFlat( (MethodDescriptor) d);
207     } else {
208       assert d instanceof TaskDescriptor;
209       fm = getMethodFlat( (TaskDescriptor) d);
210     }
211     return fm;
212   }
213
214   public void addTreeCode(MethodDescriptor md, BlockNode bn) {
215     treemethodmap.put(md,bn);
216   }
217
218   public void addTreeCode(TaskDescriptor td, BlockNode bn) {
219     treemethodmap.put(td,bn);
220   }
221
222   public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
223     flatmethodmap.put(md,bn);
224   }
225
226   public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
227     flatmethodmap.put(td,bn);
228   }
229
230   public void addTask(TaskDescriptor td) {
231     if (tasks.contains(td.getSymbol()))
232       throw new Error("Task "+td.getSymbol()+" defined twice");
233     tasks.add(td);
234     numtasks++;
235   }
236 }