package IR.Flat;
import java.util.Hashtable;
import java.util.Set;
+import java.util.HashSet;
+import java.util.Stack;
import java.util.Iterator;
import IR.ClassDescriptor;
import IR.Operation;
import IR.MethodDescriptor;
public class Inliner {
+ public static void inlineAtomic(State state, TypeUtil typeutil, FlatMethod fm, int depth) {
+ Stack<FlatNode> toprocess=new Stack<FlatNode>();
+ HashSet<FlatNode> visited=new HashSet<FlatNode>();
+ Hashtable<FlatNode, Integer> atomictable=new Hashtable<FlatNode, Integer>();
+ HashSet<FlatNode> atomicset=new HashSet<FlatNode>();
+
+ toprocess.push(fm);
+ visited.add(fm);
+ atomictable.put(fm, new Integer(0));
+ while(!toprocess.isEmpty()) {
+ FlatNode fn=toprocess.pop();
+ int atomicval=atomictable.get(fn).intValue();
+ if (fn.kind()==FKind.FlatAtomicEnterNode)
+ atomicval++;
+ else if(fn.kind()==FKind.FlatAtomicExitNode)
+ atomicval--;
+ for(int i=0;i<fn.numNext();i++) {
+ FlatNode fnext=fn.getNext(i);
+ if (!visited.contains(fnext)) {
+ atomictable.put(fnext, new Integer(atomicval));
+ if (atomicval>0)
+ atomicset.add(fnext);
+ visited.add(fnext);
+ toprocess.push(fnext);
+ }
+ }
+ }
+ //make depth 0 be depth infinity
+ if (depth==0)
+ depth=10000000;
+ recursive(state, typeutil, atomicset, depth, new Stack<MethodDescriptor>());
+ }
+
+
+ public static void recursive(State state, TypeUtil typeutil, Set<FlatNode> fnset, int depth, Stack<MethodDescriptor> toexclude) {
+ for(Iterator<FlatNode> fnit=fnset.iterator();fnit.hasNext();) {
+ FlatNode fn=fnit.next();
+ if (fn.kind()==FKind.FlatCall) {
+ FlatCall fc=(FlatCall)fn;
+ MethodDescriptor md=fc.getMethod();
+
+ if (toexclude.contains(md))
+ continue;
+
+ Set<FlatNode> inlinefnset=inline(fc, typeutil, state);
+ toexclude.push(md);
+ if (depth>1)
+ recursive(state, typeutil, inlinefnset, depth-1, toexclude);
+ toexclude.pop();
+ }
+ }
+ }
+
public static Set<FlatNode> inline(FlatCall fc, TypeUtil typeutil, State state) {
MethodDescriptor md=fc.getMethod();
/* Do we need to do virtual dispatch? */
import IR.Flat.BuildCodeMultiCore;
import IR.Flat.BuildFlat;
import IR.Flat.BuildCode;
+import IR.Flat.Inliner;
import IR.ClassDescriptor;
import IR.State;
import IR.TaskDescriptor;
state.excprefetch.add(args[++i]);
else if (option.equals("-classlibrary"))
state.classpath.add(args[++i]);
- else if(option.equals("-numcore")) {
+ else if (option.equals("-inlineatomic")) {
+ state.INLINEATOMIC=true;
+ state.inlineatomicdepth=Integer.parseInt(args[++i]);
+ } else if(option.equals("-numcore")) {
++i;
state.CORENUM = Integer.parseInt(args[i]);
} else if (option.equals("-mainclass"))
SafetyAnalysis sa=null;
PrefetchAnalysis pa=null;
MLPAnalysis mlpa=null;
+ if (state.INLINEATOMIC) {
+ Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
+ while(classit.hasNext()) {
+ ClassDescriptor cn=(ClassDescriptor)classit.next();
+ Iterator methodit=cn.getMethods();
+ while(methodit.hasNext()) {
+ // do inlining
+ MethodDescriptor md=(MethodDescriptor)methodit.next();
+ FlatMethod fm=state.getMethodFlat(md);
+ Inliner.inlineAtomic(state, tu, fm, state.inlineatomicdepth);
+ }
+ }
+ }
+
if (state.OPTIMIZE) {
CallGraph callgraph=new CallGraph(state);
echo -garbagestats Print garbage collection statistics
echo -webinterface enable web interface
echo -runtimedebug printout runtime debug messages
+echo -inlineatomic depth inline methods inside of transactions to specified depth
echo "-thread use support for multiple threads"
echo "-optimize call gcc with -O9 (optimize)"
echo "-nooptimize call gcc with -O0 (do not optimize)"
then
JAVAOPTS="$JAVAOPTS -trueprob $2"
shift
+elif [[ $1 = '-inlineatomic' ]]
+then
+JAVAOPTS="$JAVAOPTS -inlineatomic $2"
+shift
elif [[ $1 = '-mac' ]]
then
EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"