3 import java.io.FileOutputStream;
4 import java.io.PrintStream;
6 import java.io.BufferedReader;
7 import java.io.FileReader;
8 import java.io.FileInputStream;
9 import java.util.Hashtable;
10 import java.util.Iterator;
12 import java.util.Vector;
14 import IR.Tree.ParseNode;
15 import IR.Tree.BuildIR;
16 import IR.Tree.JavaBuilder;
17 import IR.Tree.SemanticCheck;
19 import IR.Flat.Inliner;
20 import IR.ClassDescriptor;
22 import IR.TaskDescriptor;
24 import Analysis.SSJava.SSJavaAnalysis;
25 import Analysis.Scheduling.MCImplSynthesis;
26 import Analysis.Scheduling.Schedule;
27 import Analysis.Scheduling.ScheduleAnalysis;
28 import Analysis.Scheduling.ScheduleSimulator;
29 import Analysis.TaskStateAnalysis.TaskAnalysis;
30 import Analysis.TaskStateAnalysis.TaskTagAnalysis;
31 import Analysis.TaskStateAnalysis.TaskGraph;
32 import Analysis.CallGraph.CallGraph;
33 import Analysis.CallGraph.BaseCallGraph;
34 import Analysis.CallGraph.JavaCallGraph;
35 import Analysis.TaskStateAnalysis.FEdge;
36 import Analysis.TaskStateAnalysis.FlagState;
37 import Analysis.TaskStateAnalysis.TagAnalysis;
38 import Analysis.TaskStateAnalysis.GarbageAnalysis;
39 import Analysis.TaskStateAnalysis.ExecutionGraph;
40 import Analysis.TaskStateAnalysis.SafetyAnalysis;
41 import Analysis.Locality.LocalityAnalysis;
42 import Analysis.Locality.GenerateConversions;
43 import Analysis.Prefetch.PrefetchAnalysis;
44 import Analysis.FlatIRGraph.FlatIRGraph;
45 import Analysis.OwnershipAnalysis.OwnershipAnalysis;
46 import Analysis.Disjoint.DisjointAnalysis;
47 import Analysis.OoOJava.OoOJavaAnalysis;
48 import Analysis.Loops.*;
49 import Analysis.Liveness;
50 import Analysis.ArrayReferencees;
51 import Analysis.Pointer.Pointer;
52 import Analysis.Disjoint.HeapAnalysis;
53 import IR.MethodDescriptor;
54 import IR.Flat.FlatMethod;
56 import Util.GraphNode;
57 import Util.GraphNode.DFS;
58 import Util.GraphNode.SCC;
62 /** Main method for the compiler. */
64 public static void main(String args[]) throws Exception {
65 String ClassLibraryPrefix="./ClassLibrary/";
66 State state=new State();
67 Vector<String> sourcefiles=new Vector<String>();
69 state.classpath.add(".");
71 String outputdir = null;
72 boolean isDistributeInfo = false;
73 boolean isDisAll = false;
77 for(int i=0; i<args.length; i++) {
78 String option=args[i];
79 if (option.equals("-precise"))
80 IR.Flat.BuildCode.GENERATEPRECISEGC=true;
81 else if (option.equals("-jni"))
83 else if (option.equals("-capture-null-dereferences"))
84 state.CAPTURE_NULL_DEREFERENCES=true;
85 else if (option.equals("-prefetch"))
87 else if (option.equals("-dir"))
88 IR.Flat.BuildCode.PREFIX=args[++i]+"/";
89 else if (option.equals("-fastcheck"))
91 else if (option.equals("-selfloop"))
92 state.selfloops.add(args[++i]);
93 else if (option.equals("-outputdir"))
94 state.outputdir = args[++i];
95 else if (option.equals("-excprefetch"))
96 state.excprefetch.add(args[++i]);
97 else if (option.equals("-classlibrary"))
98 state.classpath.add(args[++i]);
99 else if (option.equals("-inlineatomic")) {
100 state.INLINEATOMIC=true;
101 state.inlineatomicdepth=Integer.parseInt(args[++i]);
102 } else if(option.equals("-numcore")) {
104 state.CORENUM = Integer.parseInt(args[i]);
105 } else if(option.equals("-numcore4gc")) {
107 state.CORENUM4GC = Integer.parseInt(args[i]);
108 } else if (option.equals("-mainclass"))
109 state.main=args[++i];
110 else if (option.equals("-trueprob")) {
111 state.TRUEPROB=Double.parseDouble(args[++i]);
112 } else if (option.equals("-printflat"))
113 State.PRINTFLAT=true;
114 else if (option.equals("-printscheduling"))
115 State.PRINTSCHEDULING=true;
116 else if (option.equals("-minimize"))
118 else if (option.equals("-printschedulesim"))
119 State.PRINTSCHEDULESIM=true;
120 else if (option.equals("-printcriticalpath"))
121 State.PRINTCRITICALPATH=true;
122 else if (option.equals("-struct"))
123 state.structfile=args[++i];
124 else if (option.equals("-conscheck"))
125 state.CONSCHECK=true;
126 else if (option.equals("-task"))
128 else if (option.equals("-abortreaders"))
129 state.ABORTREADERS=true;
130 else if (option.equals("-sandbox"))
132 else if (option.equals("-taskstate"))
133 state.TASKSTATE=true;
134 else if (option.equals("-tagstate"))
136 else if (option.equals("-stmarray"))
138 else if (option.equals("-eventmonitor"))
139 state.EVENTMONITOR=true;
140 else if (option.equals("-dualview"))
142 else if (option.equals("-hybrid"))
144 else if (option.equals("-flatirtasks")) {
145 state.FLATIRGRAPH=true;
146 state.FLATIRGRAPHTASKS=true;
147 } else if (option.equals("-flatirusermethods")) {
148 state.FLATIRGRAPH=true;
149 state.FLATIRGRAPHUSERMETHODS=true;
150 } else if (option.equals("-flatirlibmethods")) {
151 state.FLATIRGRAPH=true;
152 state.FLATIRGRAPHLIBMETHODS=true;
153 } else if (option.equals("-bamboocompiletime")) {
154 state.BAMBOOCOMPILETIME = true;
155 } else if (option.equals("-multicore"))
156 state.MULTICORE=true;
157 else if (option.equals("-multicoregc"))
158 state.MULTICOREGC=true;
159 else if (option.equals("-pmc"))
161 else if (option.equals("-mgc")) {
163 } else if (option.equals("-objectlockdebug")) {
164 state.OBJECTLOCKDEBUG = true;
165 } else if (option.equals("-ownership"))
166 state.OWNERSHIP=true;
167 else if (option.equals("-ownallocdepth")) {
168 state.OWNERSHIPALLOCDEPTH=Integer.parseInt(args[++i]);
169 } else if (option.equals("-ownwritedots")) {
170 state.OWNERSHIPWRITEDOTS=true;
171 if (args[++i].equals("all")) {
172 state.OWNERSHIPWRITEALL=true;
174 } else if (option.equals("-ownaliasfile")) {
175 state.OWNERSHIPALIASFILE=args[++i];
176 } else if (option.equals("-ownaliasfiletab")) {
177 state.OWNERSHIPALIASFILE=args[++i];
178 state.OWNERSHIPALIASTAB=true;
179 } else if (option.equals("-owndebugcallee")) {
180 state.OWNERSHIPDEBUGCALLEE=args[++i];
181 } else if (option.equals("-owndebugcaller")) {
182 state.OWNERSHIPDEBUGCALLER=args[++i];
183 } else if (option.equals("-owndebugcallcount")) {
184 state.OWNERSHIPDEBUGCALLCOUNT=Integer.parseInt(args[++i]);
185 } else if (option.equals("-pointer")) {
187 } else if (option.equals("-disjoint"))
189 else if (option.equals("-disjoint-k")) {
190 state.DISJOINTALLOCDEPTH=Integer.parseInt(args[++i]);
192 } else if (option.equals("-disjoint-write-dots")) {
193 state.DISJOINTWRITEDOTS = true;
194 String arg = args[++i];
195 if( arg.equals("all") ) {
196 state.DISJOINTWRITEALL = true;
197 } else if( arg.equals("final") ) {
198 state.DISJOINTWRITEALL = false;
200 throw new Error("disjoint-write-dots requires argument <all/final>");
203 } else if (option.equals("-disjoint-write-initial-contexts")) {
204 state.DISJOINTWRITEINITCONTEXTS = true;
206 } else if (option.equals("-disjoint-write-ihms")) {
207 state.DISJOINTWRITEIHMS = true;
209 } else if (option.equals("-disjoint-write-all-node-graphs")) {
210 state.DISJOINT_WRITE_ALL_NODE_FINAL_GRAPHS = true;
212 } else if (option.equals("-disjoint-alias-file")) {
213 state.DISJOINTALIASFILE = args[++i];
214 String arg = args[++i];
215 if( arg.equals("normal") ) {
216 state.DISJOINTALIASTAB = false;
217 } else if( arg.equals("tabbed") ) {
218 state.DISJOINTALIASTAB = true;
220 throw new Error("disjoint-alias-file requires arguments: <filename> <normal/tabbed>");
223 } else if (option.equals("-disjoint-debug-callsite")) {
224 state.DISJOINTDEBUGCALLEE=args[++i];
225 state.DISJOINTDEBUGCALLER=args[++i];
226 state.DISJOINTDEBUGCALLVISITTOSTART=Integer.parseInt(args[++i]);
227 state.DISJOINTDEBUGCALLNUMVISITS=Integer.parseInt(args[++i]);
228 String arg = args[++i];
229 if( arg.equals("true") ) {
230 state.DISJOINTDEBUGCALLSTOPAFTER = true;
231 } else if( arg.equals("false") ) {
232 state.DISJOINTDEBUGCALLSTOPAFTER = false;
234 throw new Error("disjoint-debug-callsite requires arguments:\n"+
235 " <callee symbol> <caller symbol> <# visit to start> <# visits to capture> <T/F stop after>");
237 System.out.println( "Disjoint analysis is debugging when "+
238 state.DISJOINTDEBUGCALLER+" calls "+
239 state.DISJOINTDEBUGCALLEE+" starting after "+
240 state.DISJOINTDEBUGCALLVISITTOSTART+" visits and running for "+
241 state.DISJOINTDEBUGCALLNUMVISITS+ " visits." );
243 } else if (option.equals("-disjoint-debug-snap-method")) {
244 state.DISJOINTSNAPSYMBOL=args[++i];
245 state.DISJOINTSNAPVISITTOSTART=Integer.parseInt(args[++i]);
246 state.DISJOINTSNAPNUMVISITS=Integer.parseInt(args[++i]);
247 String arg = args[++i];
248 if( arg.equals("true") ) {
249 state.DISJOINTSNAPSTOPAFTER = true;
250 } else if( arg.equals("false") ) {
251 state.DISJOINTSNAPSTOPAFTER = false;
253 throw new Error("disjoint-debug-snap-method requires arguments:\n"+
254 " <method symbol> <# visit to start> <# visits to snap> <T/F stop after>");
257 } else if( option.equals("-disjoint-release-mode") ) {
258 state.DISJOINTRELEASEMODE = true;
260 } else if( option.equals("-disjoint-dvisit-stack") ) {
261 state.DISJOINTDVISITSTACK = true;
262 state.DISJOINTDVISITPQUE = false;
263 state.DISJOINTDVISITSTACKEESONTOP = false;
265 } else if( option.equals("-disjoint-dvisit-pqueue") ) {
266 state.DISJOINTDVISITPQUE = true;
267 state.DISJOINTDVISITSTACK = false;
268 state.DISJOINTDVISITSTACKEESONTOP = false;
270 } else if( option.equals("-disjoint-dvisit-stack-callees-on-top") ) {
271 state.DISJOINTDVISITSTACKEESONTOP = true;
272 state.DISJOINTDVISITPQUE = false;
273 state.DISJOINTDVISITSTACK = false;
275 } else if( option.equals("-disjoint-desire-determinism") ) {
276 state.DISJOINTDETERMINISM = true;
278 // when asking analysis for a deterministic result, force
279 // a stack-based visiting scheme, because the priority queue
280 // requires a non-deterministic topological sort
281 state.DISJOINTDVISITSTACKEESONTOP = true;
282 state.DISJOINTDVISITPQUE = false;
283 state.DISJOINTDVISITSTACK = false;
286 } else if( option.equals("-disjoint-debug-scheduling") ) {
287 state.DISJOINTDEBUGSCHEDULING = true;
290 } else if( option.equals("-pointsto-check-v-runtime") ) {
291 state.POINTSTO_CHECK_V_RUNTIME = true;
294 } else if( option.equals("-do-definite-reach-analysis") ) {
295 state.DO_DEFINITE_REACH_ANALYSIS = true;
298 } else if( option.equals("-count-visits") ) {
299 state.DISJOINT_COUNT_VISITS = true;
302 } else if (option.equals("-optional"))
304 else if (option.equals("-optimize"))
306 else if (option.equals("-noloop"))
308 else if (option.equals("-dcopts"))
310 else if (option.equals("-arraypad"))
312 else if (option.equals("-delaycomp"))
313 state.DELAYCOMP=true;
314 else if (option.equals("-raw"))
316 else if (option.equals("-scheduling"))
317 state.SCHEDULING=true;
318 else if (option.equals("-distributioninfo"))
319 isDistributeInfo=true;
320 else if (option.equals("-disall"))
322 else if (option.equals("-disstart"))
323 startnum = Integer.parseInt(args[++i]);
324 else if (option.equals("-useprofile")) {
325 state.USEPROFILE=true;
326 state.profilename = args[++i];
327 } else if (option.equals("-thread"))
329 else if (option.equals("-dsm"))
331 else if (option.equals("-recoverystats"))
332 state.DSMRECOVERYSTATS=true;
333 else if (option.equals("-dsmtask"))
335 else if (option.equals("-singleTM"))
337 else if (option.equals("-readset"))
339 else if (option.equals("-webinterface"))
340 state.WEBINTERFACE=true;
341 else if (option.equals("-instructionfailures"))
342 state.INSTRUCTIONFAILURE=true;
343 else if (option.equals("-abcclose"))
344 state.ARRAYBOUNDARYCHECK=false;
346 else if (option.equals("-methodeffects")) {
347 state.METHODEFFECTS=true;
349 } else if (option.equals("-coreprof")) {
352 } else if (option.equals("-ooojava")) {
353 state.OOOJAVA = true;
354 state.DISJOINT = true;
355 state.OOO_NUMCORES = Integer.parseInt(args[++i]);
356 state.OOO_MAXSESEAGE = Integer.parseInt(args[++i]);
358 } else if (option.equals("-ooodebug") ) {
359 state.OOODEBUG = true;
360 } else if (option.equals("-rcr")) {
362 state.KEEP_RG_FOR_ALL_PROGRAM_POINTS=true;
363 } else if (option.equals("-rcr_debug")) {
364 state.RCR_DEBUG = true;
365 state.KEEP_RG_FOR_ALL_PROGRAM_POINTS=true;
366 } else if (option.equals("-rcr_debug_verbose")) {
367 state.RCR_DEBUG_VERBOSE = true;
368 state.KEEP_RG_FOR_ALL_PROGRAM_POINTS=true;
369 } else if (option.equals("-nostalltr")) {
370 state.NOSTALLTR = true;
372 } else if (option.equals("-ssjava")) {
374 state.SSJAVA_GENCODE_PREVENT_CRASHES = true;
376 } else if (option.equals("-ssjavadebug")) {
377 state.SSJAVADEBUG = true;
379 } else if( option.equals( "-ssjava-inject-error" ) ) {
380 state.SSJAVA_GENCODE_PREVENT_CRASHES = true;
381 state.SSJAVA_INJECT_ERROR = true;
382 state.SSJAVA_INV_ERROR_PROB = Integer.parseInt( args[++i] );
383 state.SSJAVA_ERROR_SEED = Integer.parseInt( args[++i] );
385 // special case, if the inverse prob is 0, turn off errors
386 if( state.SSJAVA_INV_ERROR_PROB == 0 ) {
387 state.SSJAVA_INJECT_ERROR = false;
391 }else if (option.equals("-printlinenum")) {
393 } else if (option.equals("-help")) {
394 System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
395 System.out.println("-selfloop task -- this task doesn't self loop its parameters forever");
396 System.out.println("-dir outputdirectory -- output code in outputdirectory");
397 System.out.println("-struct structfile -- output structure declarations for repair tool");
398 System.out.println("-mainclass -- main function to call");
399 System.out.println("-dsm -- distributed shared memory support");
400 System.out.println("-singleTM -- single machine committing transactions");
401 System.out.println("-abortreaders -- abort readers");
402 System.out.println("-precise -- use precise garbage collection");
403 System.out.println("-conscheck -- turn on consistency checking");
404 System.out.println("-task -- compiler for tasks");
405 System.out.println("-fastcheck -- fastcheckpointing for Bristlecone");
406 System.out.println("-thread -- threads");
407 System.out.println("-trueprob <d> -- probability of true branch");
408 System.out.println("-printflat -- print out flat representation");
409 System.out.println("-instructionfailures -- insert code for instruction level failures");
410 System.out.println("-taskstate -- do task state analysis");
411 System.out.println("-flatirtasks -- create dot files for flat IR graphs of tasks");
412 System.out.println("-flatirusermethods -- create dot files for flat IR graphs of user methods");
413 System.out.println("-flatirlibmethods -- create dot files for flat IR graphs of library class methods");
414 System.out.println(" note: -flatirusermethods or -flatirlibmethods currently generate all class method flat IR graphs");
415 System.out.println("-ownership -- do ownership analysis");
416 System.out.println("-ownallocdepth <d> -- set allocation depth for ownership analysis");
417 System.out.println("-ownwritedots <all/final> -- write ownership graphs; can be all results or just final results");
418 System.out.println("-ownaliasfile <filename> -- write a text file showing all detected aliases in program tasks");
419 System.out.println("-optimize -- enable optimizations");
420 System.out.println("-noloop -- disable loop optimizations");
421 System.out.println("-optional -- enable optional arguments");
422 System.out.println("-abcclose close the array boundary check");
423 System.out.println("-scheduling do task scheduling");
424 System.out.println("-mlp <num cores> <max sese age> build mlp code");
425 System.out.println("-mlpdebug if mlp, report progress and interim results");
426 System.out.println("-multicore generate multi-core version binary");
427 System.out.println("-numcore set the number of cores (should be used together with -multicore), defaultly set as 1");
428 System.out.println("-interrupt generate raw version binary with interruption (should be used togethere with -raw)");
429 System.out.println("-rawconfig config raw simulator as 4xn (should be used together with -raw)");
430 System.out.println("-rawpath print out execute path information for raw version (should be used together with -raw)");
431 System.out.println("-useprofile use profiling data for scheduling (should be used together with -raw)");
432 System.out.println("-threadsimulate generate multi-thread simulate version binary");
433 System.out.println("-rawuseio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version");
434 System.out.println("-printscheduling -- print out scheduling graphs");
435 System.out.println("-printschedulesim -- print out scheduling simulation result graphs");
436 System.out.println("-webinterface -- enable web interface");
437 System.out.println("-linenum print out line numbers in generated C codes");
438 System.out.println("-help -- print out help");
441 sourcefiles.add(args[i]);
445 //add default classpath
446 if (state.classpath.size()==1)
447 state.classpath.add(ClassLibraryPrefix);
449 State.logEvent("Done Parsing Commands");
450 System.out.println("Classpath: "+state.classpath);
459 BuildIR bir=new BuildIR(state);
460 tu=new TypeUtil(state, bir);
461 SemanticCheck sc=new SemanticCheck(state,tu);
463 for(int i=0; i<sourcefiles.size(); i++)
464 loadClass(state, bir, sourcefiles.get(i));
466 //Stuff the runtime wants to see
469 sc.getClass(null, "TagDescriptor");
473 State.logEvent("Done Semantic Checking");
475 tu.createFullTable();
476 State.logEvent("Done Creating TypeUtil");
478 bf=new BuildFlat(state,tu);
480 State.logEvent("Done Building Flat");
482 jb=new JavaBuilder(state);
485 bf=jb.getBuildFlat();
488 SafetyAnalysis sa=null;
489 PrefetchAnalysis pa=null;
490 OoOJavaAnalysis oooa=null;
491 HeapAnalysis heapAnalysis=null;
493 if (state.INLINEATOMIC) {
494 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
495 while(classit.hasNext()) {
496 ClassDescriptor cn=(ClassDescriptor)classit.next();
497 Iterator methodit=cn.getMethods();
498 while(methodit.hasNext()) {
500 MethodDescriptor md=(MethodDescriptor)methodit.next();
501 FlatMethod fm=state.getMethodFlat(md);
502 Inliner.inlineAtomic(state, tu, fm, state.inlineatomicdepth);
507 CallGraph callgraph=jb!=null?jb:(state.TASK?new BaseCallGraph(state, tu):new JavaCallGraph(state, tu));
510 SSJavaAnalysis ssjava=new SSJavaAnalysis(state,tu,bf,callgraph);
513 State.logEvent("Done SSJava Checking");
516 if (state.OPTIMIZE) {
517 CopyPropagation cp=new CopyPropagation();
518 DeadCode dc=new DeadCode();
519 GlobalFieldType gft=new GlobalFieldType(callgraph, state, tu.getMain());
520 CSE cse=new CSE(gft, tu);
521 localCSE lcse=new localCSE(gft, tu);
522 LoopOptimize lo=null;
524 lo=new LoopOptimize(gft, tu);
525 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
526 while(classit.hasNext()) {
527 ClassDescriptor cn=(ClassDescriptor)classit.next();
528 Iterator methodit=cn.getMethods();
529 while(methodit.hasNext()) {
530 /* Classify parameters */
531 MethodDescriptor md=(MethodDescriptor)methodit.next();
532 FlatMethod fm=state.getMethodFlat(md);
553 State.logEvent("Done Optimizing");
557 if (state.FLATIRGRAPH) {
558 FlatIRGraph firg = new FlatIRGraph(state,
559 state.FLATIRGRAPHTASKS,
560 state.FLATIRGRAPHUSERMETHODS,
561 state.FLATIRGRAPHLIBMETHODS);
564 if (state.OWNERSHIP) {
565 Liveness liveness = new Liveness();
566 ArrayReferencees ar = new ArrayReferencees(state, tu, callgraph);
567 OwnershipAnalysis oa = new OwnershipAnalysis(state,
572 state.OWNERSHIPALLOCDEPTH,
573 state.OWNERSHIPWRITEDOTS,
574 state.OWNERSHIPWRITEALL,
575 state.OWNERSHIPALIASFILE,
576 state.METHODEFFECTS);
579 if (state.DISJOINT && !state.OOOJAVA) {
580 Liveness l = new Liveness();
581 ArrayReferencees ar = new ArrayReferencees(state, tu, callgraph);
582 DisjointAnalysis da = new DisjointAnalysis(state, tu, callgraph, l, ar, null, null);
587 Liveness l = new Liveness();
588 ArrayReferencees ar = new ArrayReferencees(state, tu, callgraph);
589 oooa = new OoOJavaAnalysis(state, tu, callgraph, l, ar);
590 heapAnalysis = oooa.getHeapAnalysis();
594 if (state.TAGSTATE) {
595 TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
596 TaskTagAnalysis tta=new TaskTagAnalysis(state, taganalysis, tu);
599 if (state.TASKSTATE) {
600 TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
601 TaskAnalysis ta=new TaskAnalysis(state, taganalysis, tu);
603 TaskGraph tg=new TaskGraph(state, ta);
606 if (state.OPTIONAL) {
607 ExecutionGraph et=new ExecutionGraph(state, ta);
608 et.createExecutionGraph();
609 sa = new SafetyAnalysis(et.getExecutionGraph(), state, ta);
611 state.storeAnalysisResult(sa.getResult());
612 state.storeOptionalTaskDescriptors(sa.getOptionalTaskDescriptors());
615 if (state.WEBINTERFACE) {
616 GarbageAnalysis ga=new GarbageAnalysis(state, ta);
617 WebInterface wi=new WebInterface(state, ta, tg, ga, taganalysis);
618 JhttpServer serve=new JhttpServer(8000,wi);
622 if (state.SCHEDULING) {
623 // Use ownership analysis to get alias information
624 Liveness liveness = new Liveness();
625 ArrayReferencees ar = new ArrayReferencees(state, tu, callgraph);
626 OwnershipAnalysis oa = null; /*new OwnershipAnalysis(state,
631 state.OWNERSHIPALLOCDEPTH,
632 state.OWNERSHIPWRITEDOTS,
633 state.OWNERSHIPWRITEALL,
634 state.OWNERSHIPALIASFILE);*/
636 // synthesis a layout according to target multicore processor
637 MCImplSynthesis mcImplSynthesis = new MCImplSynthesis(state,
640 if(isDistributeInfo) {
641 mcImplSynthesis.distribution(isDisAll, startnum);
643 double timeStartAnalysis = (double) System.nanoTime();
644 mcImplSynthesis.setScheduleThreshold(20);
645 mcImplSynthesis.setProbThreshold(0);
646 mcImplSynthesis.setGenerateThreshold(30);
647 Vector<Schedule> scheduling = mcImplSynthesis.synthesis();
649 double timeEndAnalysis = (double) System.nanoTime();
650 if(state.BAMBOOCOMPILETIME) {
651 double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow(10.0, 9.0) );
652 System.err.println("The analysis took" + dt + "sec.");
656 // generate multicore codes
657 if(state.MULTICORE) {
658 BuildCodeMultiCore bcm=new BuildCodeMultiCore(state,
663 mcImplSynthesis.getCoreNum(),
664 state.CORENUM4GC, callgraph);
665 bcm.setOwnershipAnalysis(oa);
675 // generate multicore codes
676 if(state.MULTICORE) {
677 BuildCodeMGC bcmgc=new BuildCodeMGC(state,
683 state.CORENUM4GC, callgraph);
688 if(!state.MULTICORE) {
691 if (state.DSM||state.SINGLETM) {
692 if (state.PREFETCH) {
693 //speed up prefetch generation using locality analysis results
694 LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
695 pa=new PrefetchAnalysis(state, callgraph, tu, la);
697 LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
698 GenerateConversions gc=new GenerateConversions(la, state);
699 bc=new BuildCodeTran(state, bf.getMap(), tu, la, pa, callgraph);
701 if( state.OOOJAVA ) {
702 bc=new BuildOoOJavaCode(state, bf.getMap(), tu, sa, oooa, callgraph);
704 bc=new BuildCode(state, bf.getMap(), tu, sa, callgraph, jb);
708 if( (state.OOOJAVA || state.POINTSTO_CHECK_V_RUNTIME) &&
709 heapAnalysis != null ) {
710 // use this extension to generate the allocsite field of Object and
711 // ArrayObject for whatever other extensions and systems need it
712 BCXallocsiteObjectField bcx = new BCXallocsiteObjectField( bc, tu, heapAnalysis );
713 bc.registerExtension( bcx );
716 if( state.POINTSTO_CHECK_V_RUNTIME &&
717 heapAnalysis != null ) {
718 BCXPointsToCheckVRuntime bcx = new BCXPointsToCheckVRuntime( state, bc, tu, heapAnalysis );
719 bc.registerExtension( bcx );
722 if( state.SSJAVA_INJECT_ERROR ) {
723 BCXSSJavaInjectError bcx = new BCXSSJavaInjectError( state, bc );
724 bc.registerExtension( bcx );
728 State.logEvent("Done With BuildCode");
732 System.out.println("Lines="+state.lines);
736 public static void loadClass(State state, BuildIR bir, String sourcefile) {
738 ParseNode pn=readSourceFile(state, sourcefile);
739 bir.buildtree(pn, null,sourcefile);
740 } catch (Exception e) {
741 System.out.println("Error in sourcefile:"+sourcefile);
745 System.out.println("Error in sourcefile:"+sourcefile);
751 /** Reads in a source file and adds the parse tree to the state object. */
753 public static ParseNode readSourceFile(State state, String sourcefile) {
755 Reader fr= new BufferedReader(new FileReader(sourcefile));
756 Lex.Lexer l = new Lex.Lexer(fr, state.TASK, state.DSM);
757 java_cup.runtime.lr_parser g;
758 g = new Parse.Parser(l);
761 p=(ParseNode) g./*debug_*/ parse().value;
762 } catch (Exception e) {
763 System.err.println("Error parsing file:"+sourcefile);
767 state.addParseNode(p);
768 if (l.numErrors()!=0) {
769 System.out.println("Error parsing "+sourcefile);
770 System.exit(l.numErrors());
772 state.lines+=l.line_num;
775 } catch (Exception e) {