USING: compiler.cfg.instructions compiler.cfg.rpo
-compiler.cfg.stack-frame compiler.tree help.markup help.syntax kernel
-math namespaces sequences vectors words ;
+compiler.cfg.stack-frame compiler.tree cpu.x86.assembler.operands
+help.markup help.syntax kernel math namespaces sequences vectors words
+;
IN: compiler.cfg
HELP: basic-block
{ { $slot "word" } { "The " { $link word } " the cfg is produced from." } }
{ { $slot "post-order" } { "The blocks of the cfg in a post order traversal " { $link sequence } "." } }
{ { $slot "stack-frame" } { { $link stack-frame } " of the cfg." } }
- { { $slot "frame-pointer?" } { "Whether the cfg needs a frame pointer. Only cfgs generated for " { $link #alien-callback } " nodes does need it." } }
+ { { $slot "frame-pointer?" } { "Whether the cfg needs a frame pointer. Only cfgs generated for " { $link #alien-callback } " nodes does need it. If the slot is " { $link t } ", then the frame pointer register (" { $link RBP } " on x86.64 archs) will not be clobbered by register allocation. See " { $vocab-link "compiler.cfg.linear-scan" } " for details." } }
}
}
{ $see-also <cfg> post-order } ;
-USING: assocs compiler.cfg compiler.cfg.instructions
-compiler.cfg.linear-scan.allocation compiler.cfg.linear-scan.allocation.state
-compiler.cfg.linear-scan.live-intervals cpu.architecture hashtables help.markup
-help.syntax kernel sequences ;
+USING: assocs compiler.cfg.instructions
+compiler.cfg.linear-scan.allocation.state
+compiler.cfg.linear-scan.live-intervals cpu.architecture hashtables
+help.markup help.syntax kernel sequences ;
IN: compiler.cfg.linear-scan.allocation
HELP: (allocate-registers)
{ $description "Assigns a processor register to the live interval." } ;
HELP: free-positions
-{ $values { "registers" assoc } { "reg-class" { $or int-regs float-regs } } { "avail-registers" assoc } }
+{ $values
+ { "registers" assoc }
+ { "reg-class" { $or int-regs float-regs } }
+ { "avail-registers" assoc }
+}
{ $description "Creates an alist mapping registers to their desirability for allocation. 'avail-registers' is an alist and not a " { $link hashtable } " because the register allocation order is significant." }
{ $see-also register-status } ;
{ $description "Creates a new " { $link spill-slot } " of the given size and also allocates space in the " { $link cfg } " in the cfg for it." } ;
HELP: progress
-{ $var-description "Start index of current live interval. We ensure that all live intervals added to the unhandled set have a start index strictly greater than this one. This ensures that we can catch infinite loop situations. We also ensure that all live intervals added to the handled set have an end index strictly smaller than this one. This helps catch bugs." }
+{ $var-description "Start index of current live interval. We ensure that all live intervals added to the unhandled set have a start index greater than or equal to this one. This ensures that we can catch infinite loop situations. We also ensure that all live intervals added to the handled set have an end index strictly smaller than this one. This helps catch bugs." }
{ $see-also check-handled check-unhandled } ;
HELP: register-available?
HELP: linear-scan
{ $values { "cfg" cfg } }
-{ $description "Entry point for the linear scan register alloation pass." } ;
+{ $description "Entry point for the linear scan register allocation pass." } ;
ARTICLE: "compiler.cfg.linear-scan" "Linear-scan register allocation"
"Linear scan to assign physical registers. SSA liveness must have been computed already. It also spills registers that are live during gc calls."
{ $description "Computes the live intervals and sync points of a cfg." }
{ $notes "The instructions must be numbered." } ;
-HELP: hairy-clobber-insn
-{ $class-description "Instructions that clobber registers. They receive inputs and produce outputs in spill slots." } ;
-
HELP: find-use
{ $values
{ "insn#" integer }
HELP: from
{ $var-description "An integer representing a sequence number one lower than all numbers in the currently processed block." } ;
+HELP: hairy-clobber-insn
+{ $class-description "Instructions that clobber registers. They receive inputs and produce outputs in spill slots." } ;
+
+HELP: insn>sync-point
+{ $values { "insn" insn } { "sync-point/f" { $maybe sync-point } } }
+{ $description "If the instruction clobbers arbitrary registers, then a sync point for it is emitted. Most instructions don't so then " { $link f } " is returned instead." } ;
+
HELP: intervals-intersect?
{ $values
{ "interval1" live-interval-state }
record-def
record-use
record-temp
+}
+"Sync point handling:"
+{ $subsections
+ cfg>sync-points
+ insn>sync-point
} ;
-USING: assocs compiler.cfg compiler.cfg.def-use compiler.cfg.instructions
-compiler.cfg.representations hash-sets help.markup help.syntax kernel
+USING: assocs compiler.cfg compiler.cfg.def-use
+compiler.cfg.instructions compiler.cfg.representations
+cpu.architecture hash-sets help.markup help.syntax kernel math
sequences ;
IN: compiler.cfg.liveness
{ $description "Main entry point for vocab. Pass must only be run after representation selection. In this pass " { $slot "gc-roots" } " are set." } ;
HELP: edge-live-ins
-{ $var-description "Assoc mapping basic blocks to sequences of sets of vregs; each sequence is in correspondence with a predecessor." } ;
+{ $var-description { $link assoc } " mapping basic blocks to sequences of sets of vregs; each sequence is in correspondence with a predecessor." } ;
HELP: fill-gc-map
{ $values { "live-set" assoc } { "gc-map" gc-map } }
{ $description "Tries to figure out what the base pointer for a vreg is. Can't use cache here because of infinite recursion inside the quotation passed to cache" }
{ $see-also base-pointers } ;
+HELP: visit-gc-root
+{ $values
+ { "vreg" integer }
+ { "derived-roots" assoc }
+ { "gc-roots" sequence }
+}
+{ $description "Handles a vreg that is live at a gc point. The vreg is handled in three ways depending on its representation:"
+ { $list
+ { "If it is " { $link tagged-rep } ", then the vreg contains a pointer to an object and it is added to the 'gc-roots' sequence." }
+ { "If it is " { $link int-rep } " and the vreg has a base pointer, then it is added to the 'derived-roots' assoc along with that base pointer." }
+ "Otherwise the vreg does not contain an object reference and nothing is done with it."
+ }
+}
+{ $see-also lookup-base-pointer } ;
+
ARTICLE: "compiler.cfg.liveness" "Liveness analysis"
"Similar to http://en.wikipedia.org/wiki/Liveness_analysis, with three additions:"
$nl
{ $subsections
live-in live-in? live-ins
live-out live-out? live-outs
+}
+"Filling GC maps:"
+{ $subsections
+ lookup-base-pointer
+ visit-gc-root
} ;
ABOUT: "compiler.cfg.liveness"
{ $description "Main entry point for the SSA destruction compiler pass." } ;
ARTICLE: "compiler.cfg.ssa.destruction" "SSA Destruction"
+"SSA destruction compiler pass. It is preceeded by " { $vocab-link "compiler.cfg.save-contexts" } " and followed by " { $vocab-link "compiler.cfg.linear-scan" } "."
+$nl
"Because of the design of the register allocator, this pass has three peculiar properties."
{ $list
{ "Instead of renaming vreg usages in the CFG, a map from vregs to canonical representatives is computed. This allows the register allocator to use the original SSA names to get reaching definitions. See " { $link leader-map } "." }