1 kkz      1.1.2.1 // WriteBarrierPostPass.java, created Fri Aug 17 19:15:38 2001 by kkz
 2 kkz      1.1.2.1 // Copyright (C) 2000 Karen Zee <kkz@tmi.lcs.mit.edu>
 3 kkz      1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 kkz      1.1.2.1 package harpoon.Analysis.PreciseGC;
 5 kkz      1.1.2.1 
 6 kkz      1.1.2.1 import harpoon.Backend.Generic.Frame;
 7 kkz      1.1.2.1 import harpoon.ClassFile.HClass;
 8 kkz      1.1.2.1 import harpoon.ClassFile.HCodeFactory;
 9 kkz      1.1.2.1 import harpoon.ClassFile.HMethod;
10 kkz      1.1.2.1 import harpoon.IR.Tree.CALL;
11 kkz      1.1.2.1 import harpoon.IR.Tree.DerivationGenerator;
12 kkz      1.1.2.1 import harpoon.IR.Tree.Exp;
13 kkz      1.1.2.1 import harpoon.IR.Tree.ExpList;
14 kkz      1.1.2.1 import harpoon.IR.Tree.NAME;
15 kkz      1.1.2.1 import harpoon.IR.Tree.NATIVECALL;
16 kkz      1.1.2.1 import harpoon.IR.Tree.Stm;
17 kkz      1.1.2.1 import harpoon.IR.Tree.TreeFactory;
18 kkz      1.1.2.1 import harpoon.Temp.Label;
19 kkz      1.1.2.1 import harpoon.Util.Util;
20 kkz      1.1.2.1 
21 kkz      1.1.2.1 import java.util.ArrayList;
22 kkz      1.1.2.1 import java.util.List;
23 kkz      1.1.2.1 
24 kkz      1.1.2.1 /**
25 kkz      1.1.2.1  * <code>WriteBarrierPostPass</code> performs some low-level 
26 kkz      1.1.2.1  * transformations to the output of <code>WriteBarrierPrePass</code> 
27 kkz      1.1.2.1  * which cannot be done in the quad form on which 
28 kkz      1.1.2.1  * <code>WriteBarrierPrePass</code> operates. 
29 kkz      1.1.2.1  * <code>>WriteBarrierPostPass</code> works on tree form.
30 kkz      1.1.2.1  * <p>
31 kkz      1.1.2.1  * This pass is invoked by 
32 kkz      1.1.2.1  * <code>WriteBarrierPrePass.treeCodeFactory()</code>.
33 kkz      1.1.2.1  * 
34 kkz      1.1.2.1  * @author  Karen Zee <kkz@tmi.lcs.mit.edu>
35 cananian 1.4      * @version $Id: WriteBarrierPostPass.java,v 1.4 2002/04/10 03:00:53 cananian Exp $
36 kkz      1.1.2.1  */
37 kkz      1.1.2.1 public class WriteBarrierPostPass extends 
38 kkz      1.1.2.1     harpoon.Analysis.Tree.Simplification {
39 kkz      1.1.2.1     private final List RULES = new ArrayList();
40 kkz      1.1.2.1     
41 kkz      1.1.2.1     /** Creates a <code>WriteBarrierPostPass</code>. */
42 kkz      1.1.2.1     WriteBarrierPostPass(final Frame f, HMethod hm) {
43 kkz      1.1.2.1         final Label Lhm = f.getRuntime().getNameMap().label(hm);
44 kkz      1.1.2.1 
45 kkz      1.1.2.1         // add rule
46 kkz      1.1.2.1         RULES.add(new Rule("replaceCall") {
47 kkz      1.1.2.1             public boolean match(Stm stm) {
48 kkz      1.1.2.1                 if (!contains(_KIND(stm), _CALL)) return false;
49 kkz      1.1.2.1                 CALL call = (CALL) stm;
50 kkz      1.1.2.1                 if (!contains(_KIND(call.getFunc()), _NAME)) return false;
51 kkz      1.1.2.1                 return ((NAME) call.getFunc()).label.equals(Lhm);
52 kkz      1.1.2.1             }
53 kkz      1.1.2.1             public Stm apply(TreeFactory tf, Stm stm, DerivationGenerator dg) {
54 kkz      1.1.2.1                 final NAME func =
55 kkz      1.1.2.1                     new NAME(tf, stm, 
56 kkz      1.1.2.1                              new Label(tf.getFrame().getRuntime().
57 kkz      1.1.2.1                                        getNameMap().c_function_name
58 kkz      1.1.2.1                                        ("generational_write_barrier")));
59 kkz      1.1.2.1                 if (dg != null) dg.putType(func, HClass.Void);
60 kkz      1.1.2.1                 ExpList explist = ((CALL) stm).getArgs();
61 cananian 1.3.2.1                 assert explist.tail == null;
62 kkz      1.1.2.1                 return new NATIVECALL(tf, stm, null, func, explist);
63 kkz      1.1.2.1             }
64 kkz      1.1.2.1         });
65 kkz      1.1.2.1     }
66 kkz      1.1.2.1 
67 kkz      1.1.2.1     /** Code factory for applying the post pass to the given tree
68 kkz      1.1.2.1      *  form.  Clones the tree before processing it in-place. */
69 kkz      1.1.2.1     public HCodeFactory codeFactory(final HCodeFactory parent) {
70 kkz      1.1.2.1         return codeFactory(parent, RULES);
71 kkz      1.1.2.1     }    
72 cananian 1.2     }