1 cananian 1.1.2.1 // NiftyAllocationStrategy.java, created Mon Apr 3 20:09:00 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.Runtime1;
 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.Exp;
12 cananian 1.1.2.1 import harpoon.IR.Tree.ExpList;
13 cananian 1.1.2.1 import harpoon.IR.Tree.TreeFactory;
14 cananian 1.1.2.1 import harpoon.IR.Tree.ESEQ;
15 cananian 1.1.2.1 import harpoon.IR.Tree.NAME;
16 cananian 1.1.2.1 import harpoon.IR.Tree.TEMP;
17 cananian 1.1.2.1 import harpoon.IR.Tree.Type;
18 cananian 1.1.2.1 import harpoon.Temp.Label;
19 cananian 1.1.2.1 import harpoon.Temp.Temp;
20 cananian 1.1.2.7 import harpoon.Util.Util;
21 cananian 1.1.2.1 /**
22 cananian 1.1.2.1  * <code>NiftyAllocationStrategy</code> implements stack- and
23 cananian 1.1.2.1  * thread-clustered-allocation strategies.
24 cananian 1.1.2.1  * 
25 cananian 1.1.2.1  * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
26 cananian 1.4      * @version $Id: NiftyAllocationStrategy.java,v 1.4 2002/04/10 03:03:20 cananian Exp $
27 cananian 1.1.2.1  */
28 cananian 1.1.2.1 public class NiftyAllocationStrategy extends MallocAllocationStrategy {
29 cananian 1.1.2.1 
30 cananian 1.1.2.1     /** Creates a <code>NiftyAllocationStrategy</code>.
31 cananian 1.1.2.1      */
32 cananian 1.1.2.1     public NiftyAllocationStrategy(Frame f) { super(f, "GC_malloc"); }
33 cananian 1.1.2.1 
34 cananian 1.1.2.1     public Exp memAlloc(TreeFactory tf, HCodeElement source,
35 cananian 1.1.2.1                         DerivationGenerator dg,
36 cananian 1.1.2.1                         AllocationProperties ap,
37 cananian 1.1.2.1                         Exp length) {
38 cananian 1.1.2.1         String funcname = "NGBL_malloc";
39 cananian 1.1.2.1         ExpList addlArgs = null;
40 bdemsky  1.1.2.3         if (!ap.hasInteriorPointers()) funcname = "NGBL_malloc_atomic";
41 cananian 1.1.2.1         if (ap.canBeStackAllocated()) funcname = "NSTK_malloc";
42 cananian 1.1.2.1         if (ap.canBeThreadAllocated())funcname = "NTHR_malloc";
43 cananian 1.1.2.5         if (ap.makeHeap())
44 cananian 1.1.2.4             funcname = ap.canBeThreadAllocated() ?
45 cananian 1.1.2.4                 "NTHR_malloc_with_heap" : "NGBL_malloc_with_heap";
46 cananian 1.1.2.1         if (ap.allocationHeap()!=null) {
47 cananian 1.1.2.6             // from the AllocationProperties interface specification...
48 cananian 1.3.2.1             assert ap.canBeThreadAllocated() && !ap.makeHeap();
49 cananian 1.1.2.2             funcname = "NTHR_malloc_other";
50 cananian 1.1.2.1             // this is somewhat bogus, since the heap-association object is
51 cananian 1.1.2.1             // most certainly an *object*, *not* Void -- but it can't hurt
52 cananian 1.1.2.1             // since the association object will be kept live by other means
53 cananian 1.1.2.1             // anyway.
54 cananian 1.1.2.1             Temp aht = ap.allocationHeap();
55 cananian 1.1.2.1             TEMP ahT = new TEMP(tf, source, Type.POINTER, aht);
56 cananian 1.1.2.1             if (dg!=null) dg.putTypeAndTemp(ahT, HClass.Void, aht);
57 cananian 1.1.2.1             addlArgs = new ExpList(ahT, addlArgs);
58 cananian 1.1.2.1         }
59 cananian 1.1.2.1         return buildAllocCall(tf, source, dg, ap, funcname, length, addlArgs);
60 cananian 1.1.2.1     }
61 cananian 1.2     }