1 cananian 1.1.2.1 // PGCNiftyAllocationStrategyWithStats.java, created Sat Nov 11 22:43:51 2000 by cananian 2 cananian 1.1.2.1 // Copyright (C) 2000 C. Scott Ananian <cananian@alumni.princeton.edu> 3 cananian 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 cananian 1.1.2.1 package harpoon.Backend.PreciseC; 5 cananian 1.1.2.1 6 cananian 1.1.2.1 import harpoon.Analysis.Maps.AllocationInformation.AllocationProperties; 7 cananian 1.1.2.1 import harpoon.Backend.Generic.Frame; 8 cananian 1.1.2.1 import harpoon.ClassFile.HClass; 9 cananian 1.1.2.1 import harpoon.ClassFile.HCodeElement; 10 cananian 1.1.2.1 import harpoon.IR.Tree.DerivationGenerator; 11 cananian 1.1.2.1 import harpoon.IR.Tree.ESEQ; 12 cananian 1.1.2.1 import harpoon.IR.Tree.Exp; 13 cananian 1.1.2.1 import harpoon.IR.Tree.ExpList; 14 cananian 1.1.2.1 import harpoon.IR.Tree.MOVE; 15 cananian 1.1.2.1 import harpoon.IR.Tree.NAME; 16 cananian 1.1.2.1 import harpoon.IR.Tree.NATIVECALL; 17 cananian 1.1.2.1 import harpoon.IR.Tree.SEQ; 18 cananian 1.1.2.1 import harpoon.IR.Tree.TEMP; 19 cananian 1.1.2.1 import harpoon.IR.Tree.TreeFactory; 20 cananian 1.1.2.1 import harpoon.IR.Tree.Type; 21 cananian 1.1.2.1 import harpoon.Temp.Label; 22 cananian 1.1.2.1 import harpoon.Temp.Temp; 23 cananian 1.1.2.1 /** 24 cananian 1.1.2.1 * <code>PGCNiftyAllocationStrategyWithStats</code> adds a callback 25 cananian 1.1.2.1 * to properly update statistics after stack allocation. This is 26 cananian 1.1.2.1 * pretty pointless, because you could just fake the stack allocation 27 cananian 1.1.2.1 * to get the statistics, but... Martin apparently wants it this way. 28 cananian 1.1.2.1 * <p> 29 cananian 1.1.2.1 * This code originally written by Brian; Scott rearranged it. 30 cananian 1.1.2.1 * 31 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 32 cananian 1.1.2.2 * @author Brian Demsky <bdemsky@mit.edu> 33 cananian 1.2 * @version $Id: PGCNiftyAllocationStrategyWithStats.java,v 1.2 2002/02/25 21:02:09 cananian Exp $ 34 cananian 1.1.2.1 */ 35 cananian 1.1.2.1 public class PGCNiftyAllocationStrategyWithStats 36 cananian 1.1.2.1 extends PGCNiftyAllocationStrategy { 37 cananian 1.1.2.1 38 cananian 1.1.2.1 /** Creates a <code>PGCNiftyAllocationStrategyWithStats</code>. */ 39 cananian 1.1.2.1 public PGCNiftyAllocationStrategyWithStats(Frame f) { super(f); } 40 cananian 1.1.2.1 public Exp memAlloc(TreeFactory tf, HCodeElement source, 41 cananian 1.1.2.1 DerivationGenerator dg, 42 cananian 1.1.2.1 AllocationProperties ap, 43 cananian 1.1.2.1 Exp length) { 44 cananian 1.1.2.1 if (ap.canBeStackAllocated()) { 45 cananian 1.1.2.3 Label func = new Label(frame.getRuntime().getNameMap() 46 cananian 1.1.2.1 .c_function_name("NSTK_update_stats")); 47 cananian 1.1.2.1 Temp Tlen = new Temp(tf.tempFactory(), "len"); 48 cananian 1.1.2.1 return new ESEQ 49 cananian 1.1.2.1 (tf, source, 50 cananian 1.1.2.1 new SEQ 51 cananian 1.1.2.1 (tf, source, 52 cananian 1.1.2.1 new MOVE 53 cananian 1.1.2.1 (tf, source, 54 cananian 1.1.2.1 new TEMP(tf, source, Type.INT, Tlen), 55 cananian 1.1.2.1 length), 56 cananian 1.1.2.1 new NATIVECALL 57 cananian 1.1.2.1 (tf, source, 58 cananian 1.1.2.1 null/*no retval*/, 59 cananian 1.1.2.1 (NAME) 60 cananian 1.1.2.1 DECLARE(dg, HClass.Void/*some random c function*/, 61 cananian 1.1.2.1 new NAME(tf, source, func)), 62 cananian 1.1.2.1 new ExpList(new TEMP(tf, source, Type.INT, Tlen), null))), 63 cananian 1.1.2.1 super.memAlloc(tf, source, dg, ap, 64 cananian 1.1.2.1 new TEMP(tf, source, Type.INT, Tlen))); 65 cananian 1.1.2.1 } else 66 cananian 1.1.2.1 return super.memAlloc(tf, source, dg, ap, length); 67 cananian 1.1.2.1 } 68 cananian 1.2 }