let scheduling analysis be able to use profile data
[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   public State() {
10     this.classes=new SymbolTable();
11     this.tasks=new SymbolTable();
12     this.treemethodmap=new Hashtable();
13     this.flatmethodmap=new Hashtable();
14     this.parsetrees=new HashSet();
15     this.arraytypes=new HashSet();
16     this.arraytonumber=new Hashtable();
17     this.tagmap=new Hashtable();
18     this.selfloops=new HashSet();
19     this.excprefetch=new HashSet();
20   }
21
22   public void addParseNode(ParseNode parsetree) {
23     parsetrees.add(parsetree);
24   }
25
26   public void storeAnalysisResult(Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults) {
27     this.analysisresults=analysisresults;
28   }
29
30   public Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> getAnalysisResult() {
31     return analysisresults;
32   }
33
34
35   public void storeOptionalTaskDescriptors(Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors) {
36     this.optionaltaskdescriptors=optionaltaskdescriptors;
37   }
38
39   public Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> getOptionalTaskDescriptors() {
40     return optionaltaskdescriptors;
41   }
42
43   /** Boolean flag which indicates whether compiler is compiling a task-based
44    * program. */
45   public boolean WEBINTERFACE=false;
46   public boolean TASK=false;
47   public boolean DSM=false;
48   public boolean PREFETCH=false;
49   public boolean TASKSTATE=false;
50   public boolean TAGSTATE=false;
51   public boolean FLATIRGRAPH=false;
52   public boolean FLATIRGRAPHTASKS=false;
53   public boolean FLATIRGRAPHUSERMETHODS=false;
54   public boolean FLATIRGRAPHLIBMETHODS=false;
55   public boolean MULTICORE=false;
56   public boolean OWNERSHIP=false;
57   public int OWNERSHIPALLOCDEPTH=3;
58   public boolean OWNERSHIPWRITEDOTS=false;
59   public boolean OWNERSHIPWRITEALL=false;
60   public String OWNERSHIPALIASFILE=null;
61   public boolean OPTIONAL=false;
62   public boolean RAW=false;
63   public boolean SCHEDULING=false;
64   public boolean USEPROFILE=false;
65   public boolean THREAD=false;
66   public boolean CONSCHECK=false;
67   public boolean INSTRUCTIONFAILURE=false;
68   public static double TRUEPROB=0.8;
69   public static boolean PRINTFLAT=false;
70   public int CORENUM = 1;
71   public String structfile;
72   public String main;
73
74   public HashSet selfloops;
75   public HashSet excprefetch;
76   public SymbolTable classes;
77   public SymbolTable tasks;
78   public Set parsetrees;
79   public Hashtable treemethodmap;
80   public Hashtable flatmethodmap;
81   private HashSet arraytypes;
82   public Hashtable arraytonumber;
83   private int numclasses=0;
84   private int numtasks=0;
85   private int arraycount=0;
86
87
88   private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
89   private Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults;
90
91   private Hashtable tagmap;
92   private int numtags=0;
93
94   public void addArrayType(TypeDescriptor td) {
95     if (!arraytypes.contains(td)) {
96       arraytypes.add(td);
97       arraytonumber.put(td,new Integer(arraycount++));
98     }
99   }
100
101   public Iterator getArrayIterator() {
102     return arraytypes.iterator();
103   }
104
105   public int getTagId(TagDescriptor tag) {
106     if (tagmap.containsKey(tag)) {
107       return ((Integer) tagmap.get(tag)).intValue();
108     } else {
109       tagmap.put(tag, new Integer(numtags));
110       return numtags++;
111     }
112   }
113
114   public int getArrayNumber(TypeDescriptor td) {
115     return ((Integer)arraytonumber.get(td)).intValue();
116   }
117
118   public int numArrays() {
119     return arraytypes.size();
120   }
121
122   public static TypeDescriptor getTypeDescriptor(int t) {
123     TypeDescriptor td=new TypeDescriptor(t);
124     return td;
125   }
126
127   public static TypeDescriptor getTypeDescriptor(NameDescriptor n) {
128     TypeDescriptor td=new TypeDescriptor(n);
129     return td;
130   }
131
132   public void addClass(ClassDescriptor tdn) {
133     if (classes.contains(tdn.getSymbol()))
134       throw new Error("Class "+tdn.getSymbol()+" defined twice");
135     classes.add(tdn);
136     numclasses++;
137   }
138
139   public int numClasses() {
140     return numclasses;
141   }
142
143   public BlockNode getMethodBody(MethodDescriptor md) {
144     return (BlockNode)treemethodmap.get(md);
145   }
146
147   public BlockNode getMethodBody(TaskDescriptor td) {
148     return (BlockNode)treemethodmap.get(td);
149   }
150
151   public SymbolTable getClassSymbolTable() {
152     return classes;
153   }
154
155   public SymbolTable getTaskSymbolTable() {
156     return tasks;
157   }
158
159   /** Returns Flat IR representation of MethodDescriptor md. */
160
161   public FlatMethod getMethodFlat(MethodDescriptor md) {
162     return (FlatMethod)flatmethodmap.get(md);
163   }
164
165   /** Returns Flat IR representation of TaskDescriptor td. */
166
167   public FlatMethod getMethodFlat(TaskDescriptor td) {
168     return (FlatMethod)flatmethodmap.get(td);
169   }
170
171   public void addTreeCode(MethodDescriptor md, BlockNode bn) {
172     treemethodmap.put(md,bn);
173   }
174
175   public void addTreeCode(TaskDescriptor td, BlockNode bn) {
176     treemethodmap.put(td,bn);
177   }
178
179   public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
180     flatmethodmap.put(md,bn);
181   }
182
183   public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
184     flatmethodmap.put(td,bn);
185   }
186
187   public void addTask(TaskDescriptor td) {
188     if (tasks.contains(td.getSymbol()))
189       throw new Error("Task "+td.getSymbol()+" defined twice");
190     tasks.add(td);
191     numtasks++;
192   }
193 }