1 USING: assocs compiler.cfg compiler.cfg.instructions
2 compiler.cfg.linear-scan.allocation
3 compiler.cfg.linear-scan.allocation.state
4 compiler.cfg.linear-scan.live-intervals compiler.cfg.liveness
5 compiler.cfg.registers heaps help.markup help.syntax math quotations
7 IN: compiler.cfg.linear-scan.assignment
10 { $values { "live-interval" live-interval-state } }
11 { $description "Adds a live interval to the pending interval set." } ;
13 HELP: assign-registers-in-block
14 { $values { "bb" basic-block } }
15 { $description "Assigns registers to vregs and also inserts " { $link ##reload } " and " { $link ##spill } " instructions." } ;
17 HELP: assign-registers
18 { $values { "cfg" cfg } { "live-intervals" sequence } }
19 { $description "Uses the live intervals in the sequence to assign physical registers to all instructions in the cfg. The live intervals must first have had their physical registers assigned by " { $link allocate-registers } "." } ;
21 HELP: assign-all-registers
22 { $values { "insn" insn } }
23 { $description "Assigns physical registers for the virtual registers used and defined by the instruction." } ;
25 HELP: change-insn-gc-roots
26 { $values { "gc-map-insn" gc-map-insn } { "quot" quotation } }
27 { $description "Applies the quotation to all vregs in the instructions " { $link gc-map } "." } ;
30 { $values { "bb" basic-block } }
31 { $description "Computes the live in registers for a basic block." }
32 { $see-also machine-live-ins } ;
35 { $values { "insn" ##call-gc } }
36 { $description "Emits a " { $link ##call-gc } " instruction and the " { $link ##reload } " and " { $link ##spill } " instructions it requires. ##call-gc aren't counted as sync points, so the instruction requires special handling." } ;
38 HELP: expire-old-intervals
39 { $values { "n" integer } { "pending-heap" min-heap } }
40 { $description "Expires all intervals older than the cutoff point. First they are removed from the 'pending-heap' and " { $link pending-interval-assoc } ". Then " { $link ##spill } " instructions are inserted for each interval that was removed." } ;
43 { $values { "live-interval" live-interval-state } }
44 { $description "Inserts a " { $link ##reload } " instruction for a live interval." }
45 { $see-also handle-reload insert-spill } ;
48 { $values { "live-interval" live-interval-state } }
49 { $description "Inserts a " { $link ##spill } " instruction for a live interval." }
50 { $see-also insert-reload } ;
52 HELP: machine-edge-live-ins
53 { $var-description "Mapping from basic blocks to predecessors to values which are live on a particular incoming edge." } ;
55 HELP: machine-live-ins
56 { $var-description "Mapping from basic blocks to values which are live at the start on all incoming CFG edges. Each value is a sequence of 2-tuples where the first element is the vreg and the second the register or " { $link spill-slot } " which contains its value. It's like " { $link live-ins } " except the registers are physical instead of virtual." } ;
58 HELP: machine-live-outs
59 { $var-description "Mapping from " { $link basic-block } " to an " { $link assoc } " of pairs which are the values that are live at the end. The keys of the pairs are virtual registers and the values are either real registers or spill slots." } ;
62 { $values { "live-interval" live-interval-state } }
63 { $description "Removes a pending live interval." } ;
65 HELP: unhandled-intervals
66 { $var-description { $link min-heap } " of live intervals which still need a register allocation." } ;
69 { $values { "vreg" "virtual register" } { "reg/spill-slot" "a register or a spill slot" } }
70 { $description "Translates a virtual register to a physical one. If the vreg is not in the pending set, then it must have been spilled and its spill slot is returned." }
71 { $errors "Can throw a " { $link bad-vreg } " error if the vreg is not in the " { $link pending-interval-assoc } " and also doesn't have a spill slot registered." }
72 { $see-also lookup-spill-slot pending-interval-assoc } ;
75 { $values { "assoc" "an " { $link assoc } " (set) of virtual registers" } { "assoc'" assoc } }
76 { $description "Creates a mapping of virtual registers to registers." } ;
79 { $values { "vreg" integer } { "spill-slot" spill-slot } }
80 { $description "Converts a vreg number to a spill slot." } ;
82 ARTICLE: "compiler.cfg.linear-scan.assignment" "Assigning registers to live intervals"
83 "The " { $vocab-link "compiler.cfg.linear-scan.assignment" } " assigns registers to live intervals. Before this compiler pass, all values in the " { $link cfg } " were represented as simple integers called \"virtual registers\" or vregs. In this pass, using the live interval data computed in the register allocation pass (" { $vocab-link "compiler.cfg.linear-scan.allocation" } "), those vregs are translated into physical registers."
85 "Since there is an infinite number of vregs but the number of physical registers is limited, some values must be spilled. So this pass also handles spilling decisions and inserts " { $link ##spill } " and " { $link ##reload } " instructions where needed."
96 pending-interval-assoc
100 "Spilling & reloading:"
105 "Vreg transformations:"
112 ABOUT: "compiler.cfg.linear-scan.assignment"