Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /MLRISC/trunk/staged-allocation/staged-allocation-sig.sml
ViewVC logotype

Diff of /MLRISC/trunk/staged-allocation/staged-allocation-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2985, Sun Apr 13 21:40:17 2008 UTC revision 2986, Mon Apr 14 07:03:16 2008 UTC
# Line 3  Line 3 
3   * This code implements the Staged Allocation technique for calling conventions.   * This code implements the Staged Allocation technique for calling conventions.
4   * You can find the POPL06 paper describing this technique at   * You can find the POPL06 paper describing this technique at
5   * http://www.eecs.harvard.edu/~nr/pubs/staged-abstract.html   * http://www.eecs.harvard.edu/~nr/pubs/staged-abstract.html
6     *
7     * Mike Rainey (mrainey@cs.uchicago.edu)
8     *
9     *
10     * Terminology for staged allocation (see the paper for more details):
11     *   counter - stores of current the number of bits allocated to the call
12     *   location - a mechanism for passing a parameter, e.g., machine registers, stack locations, etc.
13     *   slot - a parameter
14     *   alignment - alignment in bits for a location
15     *   width - width in bits for a location
16     *   stage - one rule for specifying calling conventions
17     *
18   *)   *)
19    
20  (* the target language, e.g., C, implements this signature *)  (* Specify the language that we wish to call. *)
21  signature TARGET_LANG = sig  signature TARGET_LANG = sig
22      (* the type of values in the target language *)      type location_kind     (* kind of location for passing arguments, e.g., general-purpose register,
23      type location_kind                              * floating-point register, memory, etc. *)
24  end (* TARGET_LANG *)  end (* TARGET_LANG *)
25    
26  signature STAGED_ALLOCATION = sig  signature STAGED_ALLOCATION =
27      sig
28    
29      structure T : MLTREE      structure T : MLTREE
30      structure TL : TARGET_LANG      structure TL : TARGET_LANG
# Line 19  Line 32 
32      type width = int     (* bit width *)      type width = int     (* bit width *)
33      type counter         (* abstract counter for a convention *)      type counter         (* abstract counter for a convention *)
34      type str             (* counter -> "bit offset" *)      type str             (* counter -> "bit offset" *)
35      datatype block_direction = UP | DOWN      datatype block_direction = UP | DOWN               (* direction in which the overflow block grows *)
36      (* A slot is a target-language argument. It contains bit width, location kind,      type slot = (width * TL.location_kind * int)       (* the last field is the alignment *)
      * and bit alignment. *)  
     type slot = (width * TL.location_kind * int)  
37      type reg = (width * T.reg)      type reg = (width * T.reg)
38    
39        (* locations consist of machine registers, offsets in to overflow blocks, combinations of
40         * locations, and narrowed locations.
41         *)
42      datatype location =      datatype location =
43               REG of reg    (* machine register *)               REG of reg
44             | BLOCK_OFFSET of int     (* slot in the overflow block *)             | BLOCK_OFFSET of int
            (* a location that occupies two other locations*)  
45             | COMBINE of (location * location)             | COMBINE of (location * location)
            (* a location that loses bits *)  
46             | NARROW of (location * width * TL.location_kind)             | NARROW of (location * width * TL.location_kind)
47    
48      (* information about a location's width and target-language type *)      (* metadata assocated with a location *)
49      type location_info = (width * location * TL.location_kind)      type location_info = (width * location * TL.location_kind)
50    
51      (* mini language for defining calling conventions (see the paper for      (* language for specifying calling conventions *)
      * a explanations of the operators, and their formal semantics). *)  
52      datatype stage =      datatype stage =
53               OVERFLOW of { counter : counter,               OVERFLOW of {
54                     counter : counter,
55                             blockDirection : block_direction,                             blockDirection : block_direction,
56                             maxAlign : int }                   maxAlign : int
57                 }
58             | WIDEN of (width -> width)             | WIDEN of (width -> width)
59               (* choose the first stage whose corresponding predicate is true. *)
60             | CHOICE of ( (slot -> bool) * stage) list             | CHOICE of ( (slot -> bool) * stage) list
61               (* the first n arguments go into the first n registers *)
62             | REGS_BY_ARGS of (counter * reg list)             | REGS_BY_ARGS of (counter * reg list)
63               | ARGCOUNTER of counter
64               (* the first n bits arguments go into the first n bits of registers *)
65             | REGS_BY_BITS of (counter * reg list)             | REGS_BY_BITS of (counter * reg list)
66             | BITCOUNTER of counter             | BITCOUNTER of counter
67             | ARGCOUNTER of counter             (* sequence of stages *)
68             | SEQ of stage list             | SEQ of stage list
69               (* specifies an alignment (this rule applies even for registers) *)
70             | PAD of counter             | PAD of counter
71               (* specifies an alignment *)
72             | ALIGN_TO of (width -> width)             | ALIGN_TO of (width -> width)
73    
74        (* indicates that the call-generation process has encountered an error *)
75      exception StagedAlloc      exception StagedAlloc
76    
77      (* A stepper function takes a store and a target-language argument,      (* stepper functions take a store and an argument, and return a new store and
78       * and returns a new store and a location for the argument. *)       * a location for passing the argument.
79         *)
80      type stepper_fn = (str * slot) -> (str * location_info)      type stepper_fn = (str * slot) -> (str * location_info)
81      (* Create a counter. *)      (* Create a counter. *)
82      val freshCounter : unit -> counter      val freshCounter : unit -> counter
83      (* Helper function that creates a counter c, and returns the sequence:      (* helper function that creates a counter c, and returns the sequence:
84       * [BITCOUNTER c, REGS_BY_BITS (c, regs)] (this function is taken from       * [BITCOUNTER c, REGS_BY_BITS (c, regs)] (this function is taken from
85       * the paper). *)       * the paper).
86         *)
87      val useRegs : reg list -> (counter * stage)      val useRegs : reg list -> (counter * stage)
88      (* Retrieve a counter value from the store. *)      (* find the value stored at a counter. *)
89      val find : (str * counter) -> int      val find : (str * counter) -> int
90      (* Initialize a list of counters for a calling convention. *)      (* initialize a list of counters for a calling convention. *)
91      val init : counter list -> str      val init : counter list -> str
92      (* Take a calling convention, and return a stepper function for it. *)      (* take a calling convention, and return a stepper function for it. *)
93      val mkStep : stage list -> stepper_fn      val mkStep : stage list -> stepper_fn
94    
95  end (* STAGED_ALLOCATION *)  end (* STAGED_ALLOCATION *)

Legend:
Removed from v.2985  
changed lines
  Added in v.2986

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0