start of new file
[IRC.git] / Robust / src / Main / Main.java
index 78d7d61e7e9bcd4ab35e36b38fcd5cd0cbd4cac8..e218d333aa46ea1060175e2276071f4dc2c8ff54 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Vector;
 import IR.Tree.ParseNode;
 import IR.Tree.BuildIR;
 import IR.Tree.SemanticCheck;
+import IR.Flat.BuildCodeMultiCore;
 import IR.Flat.BuildFlat;
 import IR.Flat.BuildCode;
 import IR.ClassDescriptor;
@@ -59,10 +60,20 @@ public class Main {
              IR.Flat.BuildCode.PREFIX=args[++i]+"/";
          else if (option.equals("-selfloop"))
              state.selfloops.add(args[++i]);
+         else if (option.equals("-excprefetch"))
+             state.excprefetch.add(args[++i]);
          else if (option.equals("-classlibrary"))
              ClassLibraryPrefix=args[++i]+"/";
+         else if(option.equals("-numcore")) {
+             ++i;
+             state.CORENUM = Integer.parseInt(args[i]);
+         }
          else if (option.equals("-mainclass"))
              state.main=args[++i];
+         else if (option.equals("-trueprob")) {
+             state.TRUEPROB=Double.parseDouble(args[++i]);
+         } else if (option.equals("-printflat"))
+             State.PRINTFLAT=true;
          else if (option.equals("-struct"))
              state.structfile=args[++i];
          else if (option.equals("-conscheck"))
@@ -85,10 +96,14 @@ public class Main {
              state.FLATIRGRAPH=true;
              state.FLATIRGRAPHLIBMETHODS=true;
          }
+         else if (option.equals("-multicore"))
+                 state.MULTICORE=true;
          else if (option.equals("-ownership"))
              state.OWNERSHIP=true;
          else if (option.equals("-optional"))
              state.OPTIONAL=true;
+         else if (option.equals("-raw"))
+                 state.RAW=true;
          else if (option.equals("-scheduling"))
                  state.SCHEDULING=true; 
          else if (option.equals("-thread"))
@@ -110,6 +125,8 @@ public class Main {
              System.out.println("-conscheck -- turn on consistency checking");
              System.out.println("-task -- compiler for tasks");
              System.out.println("-thread -- threads");
+             System.out.println("-trueprob <d> -- probability of true branch");
+             System.out.println("-printflat -- print out flat representation");
              System.out.println("-instructionfailures -- insert code for instruction level failures");
              System.out.println("-taskstate -- do task state analysis");
              System.out.println("-flatirtasks -- create dot files for flat IR graphs of tasks");
@@ -135,17 +152,20 @@ public class Main {
       readSourceFile(state, ClassLibraryPrefix+"HashEntry.java");
       readSourceFile(state, ClassLibraryPrefix+"Integer.java");
       readSourceFile(state, ClassLibraryPrefix+"StringBuffer.java");
+      //if(!state.RAW) {
       readSourceFile(state, ClassLibraryPrefix+"FileInputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"InputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"OutputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"File.java");
-      readSourceFile(state, ClassLibraryPrefix+"Math.java");
       readSourceFile(state, ClassLibraryPrefix+"InetAddress.java");
       readSourceFile(state, ClassLibraryPrefix+"SocketInputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"SocketOutputStream.java");
+      //}
+      readSourceFile(state, ClassLibraryPrefix+"Math.java");
       readSourceFile(state, ClassLibraryPrefix+"gnu/Random.java");
-
+         readSourceFile(state, ClassLibraryPrefix+"Vector.java");
+         readSourceFile(state, ClassLibraryPrefix+"Enumeration.java");
 
       if (state.TASK) {
          readSourceFile(state, ClassLibraryPrefix+"Object.java");
@@ -153,6 +173,7 @@ public class Main {
       } else if (state.DSM) {
          readSourceFile(state, ClassLibraryPrefix+"ThreadDSM.java");
          readSourceFile(state, ClassLibraryPrefix+"ObjectJavaDSM.java");
+         readSourceFile(state, ClassLibraryPrefix+"Barrier.java");
       } else {
          if (state.THREAD) {
              readSourceFile(state, ClassLibraryPrefix+"Thread.java");
@@ -182,6 +203,7 @@ public class Main {
       BuildFlat bf=new BuildFlat(state,tu);
       bf.buildFlat();
       SafetyAnalysis sa=null;
+      PrefetchAnalysis pa=null;
 
       if (state.TAGSTATE) {
          CallGraph callgraph=new CallGraph(state);
@@ -231,9 +253,9 @@ public class Main {
              // Print stuff to the original output and error streams.
              // On most systems all of this will end up on your console when you
              // run this application.
-             origOut.println ("\nRedirect:  Round #1");
-             System.out.println ("Test output via 'System.out'.");
-             origOut.println ("Test output via 'origOut' reference.");
+             //origOut.println ("\nRedirect:  Round #1");
+             //System.out.println ("Test output via 'System.out'.");
+             //origOut.println ("Test output via 'origOut' reference.");
 
              // Set the System out and err streams to use our replacements.
              System.setOut(stdout);
@@ -243,9 +265,9 @@ public class Main {
              // should go to the console on most systems while the messages
              // printed through the 'System.out' and 'System.err' will end up in
              // the files we created for them.
-             origOut.println ("\nRedirect:  Round #2");
-             System.out.println ("Test output via 'SimulatorResult.out'.");
-             origOut.println ("Test output via 'origOut' reference.");
+             //origOut.println ("\nRedirect:  Round #2");
+             //System.out.println ("Test output via 'SimulatorResult.out'.");
+             //origOut.println ("Test output via 'origOut' reference.");
              
              // for test
              // Randomly set the newRate and probability of FEdges
@@ -270,7 +292,7 @@ public class Main {
                                          if(numEdges - j == 1) {
                                              pfe.setProbability(total);
                                          } else {
-                                             if(total != 0) {
+                                             if((total != 0) && (total != 1)){
                                                  do {
                                                      tint = r.nextInt()%total;
                                                  } while(tint <= 0);
@@ -278,11 +300,21 @@ public class Main {
                                              pfe.setProbability(tint);
                                              total -= tint;
                                          }
-                                         do {
+                                         /*do {
                                              tint = r.nextInt()%10;
-                                         } while(tint <= 0);
+                                         } while(tint <= 0);*/
                                          //int newRate = tint;
-                                         int newRate = (j+1)%2+1;
+                                         //int newRate = (j+1)%2+1;
+                                         int newRate = 1;
+                                         String cdname = cd.getSymbol();
+                                         if((cdname.equals("SeriesRunner")) || 
+                                                 (cdname.equals("MDRunner"))) {
+                                             newRate = 16;
+                                         } else if(cdname.equals("SentenceParser")) {
+                                             newRate = 4;
+                                         } /*else if(cdname.equals("ReduceWorker")) {
+                                             newRate = 3;
+                                         }*/
                                          /*do {
                                              tint = r.nextInt()%100;
                                          } while(tint <= 0);
@@ -299,9 +331,10 @@ public class Main {
                          FlagState fs = (FlagState)it_flags.next();
                          Iterator it_edges = fs.edges();
                          while(it_edges.hasNext()) {
-                             do {
+                             /*do {
                                  tint = r.nextInt()%10;
-                             } while(tint <= 0);
+                             } while(tint <= 0);*/
+                             tint = 3;
                              ((FEdge)it_edges.next()).setExeTime(tint);
                          }
                      }
@@ -312,7 +345,8 @@ public class Main {
              ScheduleAnalysis scheduleAnalysis = new ScheduleAnalysis(state, ta);
              scheduleAnalysis.preSchedule();
              scheduleAnalysis.scheduleAnalysis();
-             scheduleAnalysis.setCoreNum(scheduleAnalysis.getSEdges4Test().size());
+             //scheduleAnalysis.setCoreNum(scheduleAnalysis.getSEdges4Test().size());
+             scheduleAnalysis.setCoreNum(state.CORENUM);
              scheduleAnalysis.schedule();
              
              //simulate these schedulings
@@ -336,7 +370,7 @@ public class Main {
              }
              System.out.print("Selected schedulings with least exectution time " + processTime + ": \n\t");
              for(int i = 0; i < selectedScheduling.size(); i++) {
-                 System.out.print(selectedScheduling.elementAt(i) + ", ");
+                 System.out.print((selectedScheduling.elementAt(i) + 1) + ", ");
              }
              System.out.println();
              
@@ -380,22 +414,35 @@ public class Main {
              } catch (Exception e) {
                  origOut.println ("Redirect:  Unable to close files!");
              }
+             
+             if(state.MULTICORE) {
+                 //it_scheduling = scheduleAnalysis.getSchedulingsIter();
+                 //Vector<Schedule> scheduling = (Vector<Schedule>)it_scheduling.next();
+                 Vector<Schedule> scheduling = scheduleAnalysis.getSchedulings().elementAt(selectedScheduling.elementAt(0));
+                 BuildCodeMultiCore bcm=new BuildCodeMultiCore(state, bf.getMap(), tu, sa, scheduling, scheduleAnalysis.getCoreNum(), pa);
+                 bcm.buildCode();
+             }
          }
          
       }
 
-      if (state.DSM) {
-         CallGraph callgraph=new CallGraph(state);
-         if (state.PREFETCH) {
-             PrefetchAnalysis pa=new PrefetchAnalysis(state, callgraph, tu);
+      if(!state.MULTICORE) {
+         if (state.DSM) {
+             CallGraph callgraph=new CallGraph(state);
+             if (state.PREFETCH) {
+                 //speed up prefetch generation using locality analysis results
+                 LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
+                 pa=new PrefetchAnalysis(state, callgraph, tu, la);
+             }
+
+             LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
+             GenerateConversions gc=new GenerateConversions(la, state);
+             BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa);
+             bc.buildCode();
+         } else {
+             BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa, pa);
+             bc.buildCode();
          }
-         LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
-         GenerateConversions gc=new GenerateConversions(la, state);
-         BuildCode bc=new BuildCode(state, bf.getMap(), tu, la);
-         bc.buildCode();
-      } else {
-         BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa);
-         bc.buildCode();
       }
 
       if (state.FLATIRGRAPH) {
@@ -406,7 +453,12 @@ public class Main {
       }
 
       if (state.OWNERSHIP) {
-         //      OwnershipAnalysis oa = new OwnershipAnalysis(state);
+         CallGraph callGraph  = new CallGraph( state );
+         int allocationDepth  = 3;
+         OwnershipAnalysis oa =
+             new OwnershipAnalysis( state, callGraph, allocationDepth );
+         //This was breaking the compile
+         //      oa.writeAllAliases( "identifiedAliases.txt" );
       }
 
       System.exit(0);