String mlperrstr = "if(status != 0) { "+
"sprintf(errmsg, \"MLP error at %s:%d\", __FILE__, __LINE__); "+
"perror(errmsg); exit(-1); }";
- Hashtable<FlatSESEEnterNode, FlatMethod> sese2bogusFlatMeth;
boolean nonSESEpass=true;
WriteBarrier wb;
DiscoverConflicts dc;
recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true, null);
recorddc.doAnalysis();
}
-
- if(state.MLP) {
- sese2bogusFlatMeth = new Hashtable<FlatSESEEnterNode, FlatMethod>();
- }
}
/** The buildCode method outputs C code for all the methods. The Flat
outmethod.println("pthread_exit(NULL);");
if (state.MLP) {
- outmethod.println(" mlpInit( "+state.MLP_NUMCORES+", "+
- "invokeSESEmethod, "+
- "argc, "+
- "argv, "+
- state.MLP_MAXSESEAGE+" );");
+ outmethod.println(" workScheduleInit( "+state.MLP_NUMCORES+", invokeSESEmethod );");
+ // issue root SESE
+ outmethod.println(" workScheduleBegin();");
}
outmethod.println("}");
output.println("}\n\n");
}
- // when a new mlp thread is created for an issued SESE, it is started
- // by running this method which blocks on a cond variable until
- // it is allowed to transition to execute. Then a case statement
- // allows it to invoke the method with the proper SESE body, and after
- // exiting the SESE method, executes proper SESE exit code before the
- // thread can be destroyed
- private void generateSESEinvocationMethod(PrintWriter outmethodheader,
- PrintWriter outmethod
- ) {
-
- outmethodheader.println("void invokeSESEmethod( void* seseRecord );");
- outmethod.println( "void invokeSESEmethod( void* seseRecord ) {");
- outmethod.println( " int status;");
- outmethod.println( " char errmsg[128];");
- outmethod.println( " SESErecord* rec = (SESErecord*) seseRecord;");
-
- // generate a case for each SESE class that can be invoked
- outmethod.println( " switch( rec->classID ) {");
- outmethod.println( " ");
- for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
- FlatSESEEnterNode fsen = seseit.next();
- outmethod.println( " /* "+fsen.getPrettyIdentifier()+" */");
- outmethod.println( " case "+fsen.getIdentifier()+":");
- generateSESEinvocation(fsen, outmethod);
- outmethod.println( " break;");
- outmethod.println( "");
- }
-
- // default case should never be taken, error out
- outmethod.println( " default:");
- outmethod.println( " printf(\"Error: unknown SESE class ID in invoke method.\\n\");");
- outmethod.println( " exit(-30);");
- outmethod.println( " break;");
- outmethod.println( " }");
- outmethod.println( "}\n\n");
- }
-
- private void generateSESEinvocation(FlatSESEEnterNode fsen,
- PrintWriter output
- ) {
- /*
- FlatMethod fm = fsen.getEnclosingFlatMeth();
- MethodDescriptor md = fm.getMethod();
- ClassDescriptor cn = md.getClassDesc();
-
- FlatMethod bogusfm = sese2bogusFlatMeth.get(fsen);
- MethodDescriptor bogusmd = bogusfm.getMethod();
- ParamsObject objectparams = (ParamsObject)paramstable.get(bogusmd);
-
- // first copy SESE record into param structure
-
-
- // then invoke the sese's method
- output.print(" "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor());
- output.print("( args->invokee, ");
-
- // first argument is parameter structure
- output.print("(struct "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"__params*)");
- output.print("&(args->invokee->paramStruct)");
-
- // other arguments are primitive parameters
- for(int i=0; i<objectparams.numPrimitives(); i++) {
- TempDescriptor td=objectparams.getPrimitive(i);
- TypeDescriptor type=td.getType();
- assert type.isPrimitive();
- output.print( ", (("+fsen.namespaceStructNameString()+
- "*)args->invokee->namespace)->"+td );
- }
-
- output.println(");");
- */
- }
protected void generateMethodSESE(FlatSESEEnterNode fsen,
LocalityBinding lb,
PrintWriter outputMethHead,
PrintWriter outputMethods
) {
-
- FlatMethod fm = fsen.getEnclosingFlatMeth();
+
+ FlatMethod fm = fsen.getfmEnclosing();
MethodDescriptor md = fm.getMethod();
ClassDescriptor cn = md.getClassDesc();
// Creates bogus method descriptor to index into tables
- Modifiers bogusmod=new Modifiers();
- MethodDescriptor bogusmd=new MethodDescriptor(bogusmod,
- new TypeDescriptor(TypeDescriptor.VOID),
- "sese_"+fsen.getPrettyIdentifier()+fsen.getIdentifier());
- bogusmd.setClassDesc(cn);
- FlatMethod bogusfm=new FlatMethod(bogusmd, null);
- sese2bogusFlatMeth.put(fsen, bogusfm);
+ Modifiers modBogus = new Modifiers();
+ MethodDescriptor mdBogus =
+ new MethodDescriptor( modBogus,
+ new TypeDescriptor( TypeDescriptor.VOID ),
+ "sese_"+fsen.getPrettyIdentifier()+fsen.getIdentifier()
+ );
+
+ mdBogus.setClassDesc( fsen.getcdEnclosing() );
+ FlatMethod fmBogus = new FlatMethod( mdBogus, null );
+ fsen.setfmBogus( fmBogus );
+ fsen.setmdBogus( mdBogus );
// Build paramsobj for bogus method descriptor
- ParamsObject objectparams=new ParamsObject(bogusmd, tag++);
- paramstable.put(bogusmd, objectparams);
+ ParamsObject objectparams = new ParamsObject( mdBogus, tag++ );
+ paramstable.put( mdBogus, objectparams );
- for(int i=0; i<fsen.numParameters(); i++) {
- TempDescriptor temp=fsen.getParameter(i);
- TypeDescriptor type=temp.getType();
- if (type.isPtr()&&GENERATEPRECISEGC) {
- objectparams.addPtr(temp);
+ Set<TempDescriptor> inSetAndOutSet = new HashSet<TempDescriptor>();
+ inSetAndOutSet.addAll( fsen.getInVarSet() );
+ inSetAndOutSet.addAll( fsen.getOutVarSet() );
+
+ Set<TempDescriptor> inSetAndOutSetPrims = new HashSet<TempDescriptor>();
+
+ Iterator<TempDescriptor> itr = inSetAndOutSet.iterator();
+ while( itr.hasNext() ) {
+ TempDescriptor temp = itr.next();
+ TypeDescriptor type = temp.getType();
+ if( type.isPtr() ) {
+ objectparams.addPtr( temp );
} else {
- objectparams.addPrim(temp);
+ inSetAndOutSetPrims.add( temp );
}
}
// Build normal temp object for bogus method descriptor
- TempObject objecttemps=new TempObject(objectparams,bogusmd,tag++);
- tempstable.put(bogusmd, objecttemps);
+ TempObject objecttemps = new TempObject( objectparams, mdBogus, tag++ );
+ tempstable.put( mdBogus, objecttemps );
for(Iterator nodeit=fsen.getNodeSet().iterator(); nodeit.hasNext();) {
FlatNode fn=(FlatNode)nodeit.next();
}
}
- // declare namespace struct
- outputStructs.println(fsen.namespaceStructDeclarationString());
+ // generate the SESE record structure
+ outputStructs.println(fsen.getSESErecordName()+" {");
- // Generate code for parameters structure
- generateMethodParam(cn, bogusmd, null, outputStructs);
+ // class ID comes first
+ outputStructs.println(" int classID;");
- // Generate code for locals structure
- outputStructs.println("struct "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor()+"_locals {");
+ // then garbage list stuff
+ outputStructs.println(" INTPTR size;");
+ outputStructs.println(" void * next;");
+
+ for(int i=0; i<objectparams.numPointers(); i++) {
+ TempDescriptor temp=objectparams.getPointer(i);
+ if (temp.getType().isNull())
+ outputStructs.println(" void * "+temp.getSafeSymbol()+";");
+ else
+ outputStructs.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
+ }
+
+ // then other SESE runtime data
+ Iterator<TempDescriptor> itrPrims = inSetAndOutSetPrims.iterator();
+ while( itrPrims.hasNext() ) {
+ TempDescriptor temp = itrPrims.next();
+ TypeDescriptor type = temp.getType();
+ outputStructs.println(" "+temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol()+";");
+ }
+
+ outputStructs.println("};\n");
+
+ // generate locals structure
+ outputStructs.println("struct "+cn.getSafeSymbol()+mdBogus.getSafeSymbol()+"_"+mdBogus.getSafeMethodDescriptor()+"_locals {");
outputStructs.println(" INTPTR size;");
outputStructs.println(" void * next;");
for(int i=0; i<objecttemps.numPointers(); i++) {
// write method declaration to header file
outputMethHead.print("void ");
- outputMethHead.print(cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor()+"(");
- outputMethHead.print("SESErecord* currentSESE, ");
+ outputMethHead.print(fsen.getSESEmethodName()+"(");
+ outputMethHead.print(fsen.getSESErecordName()+"* currentSESE ");
+
+ /*
boolean printcomma=false;
if (GENERATEPRECISEGC) {
outputMethHead.print("struct "+cn.getSafeSymbol()+
else
outputMethHead.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
}
- outputMethHead.println(");\n");
+ */
+ outputMethHead.println(");\n");
- generateFlatMethodSESE(bogusfm, cn, fsen, fsen.getFlatExit(), outputMethods);
+ generateFlatMethodSESE(fmBogus, cn, fsen, fsen.getFlatExit(), outputMethods);
}
private void generateFlatMethodSESE(FlatMethod fm,
ClassDescriptor cn,
- FlatSESEEnterNode seseEnter,
+ FlatSESEEnterNode fsen,
FlatSESEExitNode seseExit,
PrintWriter output
) {
MethodDescriptor md=fm.getMethod();
- ParamsObject objectparams=(ParamsObject)paramstable.get(md);
- generateHeader(fm, null, md, output, true);
- TempObject objecttemp=(TempObject) tempstable.get(md);
+ //generateHeader(fm, null, md, output, true);
+
+ output.print("void ");
+ output.print(fsen.getSESEmethodName()+"(");
+ output.print(fsen.getSESErecordName()+"* currentSESE ");
+ output.println("){\n");
+
+ TempObject objecttemp=(TempObject) tempstable.get(md);
if (GENERATEPRECISEGC) {
output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
output.print(objecttemp.numPointers()+",");
- output.print(paramsprefix);
+ output.print("(void*) &(currentSESE->size)");
for(int j=0; j<objecttemp.numPointers(); j++)
output.print(", NULL");
output.println("};");
// declare variables for naming SESE's
- Iterator<SESEandAgePair> pItr = seseEnter.getNeededStaticNames().iterator();
+ /*
+ Iterator<SESEandAgePair> pItr = fsen.getNeededStaticNames().iterator();
while( pItr.hasNext() ) {
SESEandAgePair p = pItr.next();
output.println(" SESErecord* "+p+";");
}
-
+ */
// Check to see if we need to do a GC if this is a
// multi-threaded program...
HashSet<FlatNode> exitset=new HashSet<FlatNode>();
exitset.add(seseExit);
- generateCode(seseEnter.getNext(0), fm, null, exitset, output, true);
+ generateCode(fsen.getNext(0), fm, null, exitset, output, true);
output.println("}\n\n");
}
+
+ // when a new mlp thread is created for an issued SESE, it is started
+ // by running this method which blocks on a cond variable until
+ // it is allowed to transition to execute. Then a case statement
+ // allows it to invoke the method with the proper SESE body, and after
+ // exiting the SESE method, executes proper SESE exit code before the
+ // thread can be destroyed
+ private void generateSESEinvocationMethod(PrintWriter outmethodheader,
+ PrintWriter outmethod
+ ) {
+
+ outmethodheader.println("void* invokeSESEmethod( void* seseRecord );");
+ outmethod.println( "void* invokeSESEmethod( void* seseRecord ) {");
+ outmethod.println( " int status;");
+ outmethod.println( " char errmsg[128];");
+
+ // generate a case for each SESE class that can be invoked
+ outmethod.println( " switch( *((int*)seseRecord) ) {");
+ outmethod.println( " ");
+ for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
+ FlatSESEEnterNode fsen = seseit.next();
+
+ outmethod.println( " /* "+fsen.getPrettyIdentifier()+" */");
+ outmethod.println( " case "+fsen.getIdentifier()+":");
+ outmethod.println( " "+fsen.getSESEmethodName()+"( seseRecord );");
+ outmethod.println( " break;");
+ outmethod.println( "");
+ }
+
+ // default case should never be taken, error out
+ outmethod.println( " default:");
+ outmethod.println( " printf(\"Error: unknown SESE class ID in invoke method.\\n\");");
+ outmethod.println( " exit(-30);");
+ outmethod.println( " break;");
+ outmethod.println( " }");
+ outmethod.println( " return NULL;");
+ outmethod.println( "}\n\n");
+ }
+
+
protected void generateCode(FlatNode first,
FlatMethod fm,
LocalityBinding lb,
// SESE nodes can be parsed for normal compilation, just skip over them
return;
}
-
- // output.println("\n /* SESE "+fsen.getPrettyIdentifier()+" issue */");
-
- /*
- output.println(" tempSESE = mlpCreateSESErecord( "+
- fsen.getIdentifier()+", "+
- "malloc( sizeof( "+fsen.namespaceStructNameString()+") ), "+
- "NULL );");
-
- for( int i = 0; i < fsen.numParameters(); ++i ) {
- TempDescriptor td = fsen.getParameter( i );
- output.println(" (("+fsen.namespaceStructNameString()+
- "*)tempSESE->namespace)->"+td+" = "+td+";");
- }
-
- output.println(" mlpIssue( tempSESE );");
- //output.println(" tempSESE = mlpSchedule();");
+
+ output.println( " {" );
- // do a pthread_create wit invokeSESE as the argument
- // and pack all args into a single void*
- output.println(" tempSESEargs = malloc( sizeof( invokeSESEargs ) );");
- output.println(" tempSESEargs->classID = "+fsen.getIdentifier()+";");
- output.println(" tempSESEargs->invokee = mlpSchedule();");
+ output.println( " ");
+ output.println( " ");
+ output.println( " ");
+ output.println( " ");
- if( fsen.getParent() == null ) {
- output.println(" tempSESEargs->parent = NULL;");
- } else {
- output.println(" tempSESEargs->parent = currentSESE;");
- }
+ output.println( " ");
- output.println(" invokeSESEmethod( (void*) tempSESEargs );");
- output.println("\n");
- */
+ output.println( " }" );
}
public void generateFlatSESEExitNode(FlatMethod fm, LocalityBinding lb, FlatSESEExitNode fsen, PrintWriter output) {
output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
} else
output.print(task.getSafeSymbol()+"(");
-
+
if (addSESErecord) {
output.print("SESErecord* currentSESE, ");
}
package IR.Flat;
import Analysis.MLP.VariableSourceToken;
import Analysis.MLP.SESEandAgePair;
+import IR.MethodDescriptor;
+import IR.ClassDescriptor;
import IR.TypeDescriptor;
import IR.Tree.SESENode;
import java.util.*;
protected Set<TempDescriptor> inVars;
protected Set<TempDescriptor> outVars;
protected Set<SESEandAgePair> needStaticNameInCode;
- protected FlatMethod enclosing;
+
+ // scope info for this SESE
+ protected FlatMethod fmEnclosing;
+ protected MethodDescriptor mdEnclosing;
+ protected ClassDescriptor cdEnclosing;
+
+ // structures that allow SESE to appear as
+ // a normal method to code generation
+ protected FlatMethod fmBogus;
+ protected MethodDescriptor mdBogus;
+
public FlatSESEEnterNode( SESENode sn ) {
this.id = identifier++;
public void rewriteDef() {
}
+ public void setFlatExit( FlatSESEExitNode fsexn ) {
+ exit = fsexn;
+ }
+
+ public FlatSESEExitNode getFlatExit() {
+ return exit;
+ }
+
+ public int kind() {
+ return FKind.FlatSESEEnterNode;
+ }
+
+ public SESENode getTreeNode() {
+ return treeNode;
+ }
+
+ public int getIdentifier() {
+ return id;
+ }
+
+ public String getPrettyIdentifier() {
+ if( treeNode.getID() != null ) {
+ return treeNode.getID();
+ }
+ return ""+id;
+ }
+
+ public String toString() {
+ return "sese "+getPrettyIdentifier()+" enter";
+ }
+
public void setParent( FlatSESEEnterNode parent ) {
this.parent = parent;
}
return vecinVars.size();
}
+ /*
public String namespaceStructNameString() {
return "struct SESE_"+getPrettyIdentifier()+"_namespace";
}
public String namespaceStructAccessString( TempDescriptor td ) {
return "SESE_"+getPrettyIdentifier()+"_namespace."+td;
}
+ */
public Set<FlatNode> getNodeSet() {
HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
return needStaticNameInCode;
}
- public void setEnclosingFlatMeth( FlatMethod fm ) {
- enclosing = fm;
- }
+ public void setfmEnclosing( FlatMethod fm ) { fmEnclosing = fm; }
+ public FlatMethod getfmEnclosing() { return fmEnclosing; }
- public FlatMethod getEnclosingFlatMeth() {
- return enclosing;
- }
+ public void setmdEnclosing( MethodDescriptor md ) { mdEnclosing = md; }
+ public MethodDescriptor getmdEnclosing() { return mdEnclosing; }
- public SESENode getTreeNode() {
- return treeNode;
- }
-
- public int getIdentifier() {
- return id;
- }
-
- public String getPrettyIdentifier() {
- if( treeNode.getID() != null ) {
- return treeNode.getID();
- }
- return ""+id;
- }
+ public void setcdEnclosing( ClassDescriptor cd ) { cdEnclosing = cd; }
+ public ClassDescriptor getcdEnclosing() { return cdEnclosing; }
- public String toString() {
- return "sese "+getPrettyIdentifier()+" enter";
- }
+ public void setfmBogus( FlatMethod fm ) { fmBogus = fm; }
+ public FlatMethod getfmBogus() { return fmBogus; }
- public void setFlatExit( FlatSESEExitNode fsexn ) {
- exit = fsexn;
- }
+ public void setmdBogus( MethodDescriptor md ) { mdBogus = md; }
+ public MethodDescriptor getmdBogus() { return mdBogus; }
- public FlatSESEExitNode getFlatExit() {
- return exit;
+ public String getSESEmethodName() {
+ return
+ cdEnclosing.getSafeSymbol()+
+ mdBogus.getSafeSymbol()+
+ "_"+
+ mdBogus.getSafeMethodDescriptor();
}
- public int kind() {
- return FKind.FlatSESEEnterNode;
+ public String getSESErecordName() {
+ return
+ "struct "+
+ cdEnclosing.getSafeSymbol()+
+ mdBogus.getSafeSymbol()+
+ "_"+
+ mdBogus.getSafeMethodDescriptor()+
+ "_SESErec";
}
}