From: bdemsky Date: Sat, 20 Jun 2009 10:02:59 +0000 (+0000) Subject: check in Inliner class X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=070ca5872365d88c3aaf424655a235f1594aa30b;p=IRC.git check in Inliner class --- diff --git a/Robust/src/IR/Flat/Inliner.java b/Robust/src/IR/Flat/Inliner.java new file mode 100644 index 00000000..a70d4890 --- /dev/null +++ b/Robust/src/IR/Flat/Inliner.java @@ -0,0 +1,111 @@ +package IR.Flat; +import java.util.Hashtable; +import java.util.Set; +import java.util.Iterator; +import IR.ClassDescriptor; +import IR.Operation; +import IR.State; +import IR.TypeUtil; +import IR.MethodDescriptor; + +public class Inliner { + public static boolean inline(FlatCall fc, TypeUtil typeutil, State state) { + MethodDescriptor md=fc.getMethod(); + /* Do we need to do virtual dispatch? */ + if (md.isStatic()||md.getReturnType()==null||singleCall(typeutil, fc.getThis().getType().getClassDesc(),md)) { + //just reuse temps...makes problem with inlining recursion + TempMap clonemap=new TempMap(); + Hashtable flatmap=new Hashtable(); + TempDescriptor rettmp=fc.getReturnTemp(); + FlatNode aftercallnode=fc.getNext(0); + aftercallnode.removePrev(fc); + + FlatMethod fm=state.getMethodFlat(md); + //Clone nodes + Set nodeset=fm.getNodeSet(); + nodeset.remove(fm); + + //Build the clones + for(Iterator fnit=nodeset.iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + if (fn.kind()==FKind.FlatReturnNode) { + //Convert FlatReturn node into move + TempDescriptor rtmp=((FlatReturnNode)fn).getReturnTemp(); + if (rtmp!=null) { + FlatOpNode fon=new FlatOpNode(rettmp, rtmp, null, new Operation(Operation.ASSIGN)); + flatmap.put(fn, fon); + } else { + flatmap.put(fn, aftercallnode); + } + } else { + FlatNode clone=fn.clone(clonemap); + flatmap.put(fn,clone); + } + } + //Build the move chain + FlatNode first=new FlatNop();; + FlatNode last=first; + { + int i=0; + if (fc.getThis()!=null) { + FlatOpNode fon=new FlatOpNode(fm.getParameter(i++), fc.getThis(), null, new Operation(Operation.ASSIGN)); + last.addNext(fon); + last=fon; + } + for(int j=0;j fnit=nodeset.iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + FlatNode fnclone=flatmap.get(fn); + + if (fn.kind()!=FKind.FlatReturnNode) { + //don't build old edges out of a flat return node + for(int i=0;i