compiler.cfg.linear-scan.live-intervals: better way to write insn>sync-point

locals-and-roots
Björn Lindqvist 2016-04-02 18:58:18 +02:00
parent 3fd1d80b83
commit 54d7b50d1b
3 changed files with 21 additions and 17 deletions

View File

@ -8,7 +8,8 @@ HELP: <live-interval>
{ "vreg" "virtual register" }
{ "live-interval" live-interval-state }
}
{ $description "Creates a new live interval for a virtual register. Initially the range is empty." } ;
{ $description "Creates a new live interval for a virtual register. Initially the ranges are empty and it has no uses." }
{ $see-also vreg>live-interval } ;
HELP: block-from
{ $values { "bb" basic-block } { "n" integer } }
@ -36,9 +37,9 @@ HELP: find-use
}
{ $description "Finds the live intervals " { $link vreg-use } " at the given instruction number, if it has one." } ;
HELP: finish-live-intervals
{ $values { "live-intervals" sequence } }
{ $description "Since live intervals are computed in a backward order, we have to reverse some sequences, and compute the start and end." } ;
HELP: finish-live-interval
{ $values { "live-interval" live-interval-state } }
{ $description "Reverses the 'ranges' and 'uses' of the live-interval since those are computed in the reverse order." } ;
HELP: from
{ $var-description "An integer representing a sequence number one lower than all numbers in the currently processed block." } ;
@ -51,6 +52,10 @@ HELP: intervals-intersect?
}
{ $description "Checks if two live intervals intersect each other." } ;
HELP: last-use?
{ $values { "insn#" integer } { "uses" sequence } { "use/f" $maybe vreg-use } }
{ $description "Maybe gets the last " { $link vreg-use } " of a " { $link live-interval-state } "." } ;
HELP: live-interval-state
{ $class-description "A class encoding the \"liveness\" of a virtual register. It has the following slots:"
{ $table
@ -90,13 +95,13 @@ HELP: record-temp
{ $description "Assigns the interval [n,n] to vreg:s live interval." } ;
HELP: sync-point
{ $class-description "A location where all registers have to be spilled. For example when garbage collection is run or an alien ffi call is invoked. Figuring out where in the " { $link cfg } " the sync points are is done in the " { $link compute-live-intervals } " step. The tuple has the following slots:"
{ $class-description "A location where all live registers have to be spilled. For example when garbage collection is run or an alien ffi call is invoked. Figuring out where in the " { $link cfg } " the sync points are is done in the " { $link compute-live-intervals } " step. The tuple has the following slots:"
{ $table
{ { $slot "n" } { "Set from an instructions sequence number." } }
{ { $slot "keep-dst?" } { "Boolean that determines whether registers are spilled around this sync point." } }
}
}
{ $see-also insn } ;
{ $see-also cfg>sync-points insn } ;
HELP: to
{ $var-description "An integer representing a sequence number equal to the highest number in the currently processed block." } ;

View File

@ -33,6 +33,13 @@ IN: compiler.cfg.linear-scan.live-intervals.tests
dup finish-live-interval ranges>>
] unit-test
! insn>sync-point
{ f f t } [
T{ ##call-gc } insn>sync-point keep-dst?>>
T{ ##callback-outputs } insn>sync-point keep-dst?>>
T{ ##unbox } insn>sync-point keep-dst?>>
] unit-test
! intervals-intersect?
{ t f f } [
{ { 4 20 } } <live-interval-for-ranges>

View File

@ -134,22 +134,14 @@ ERROR: bad-live-interval live-interval ;
dup live-interval-start -1 = [ bad-live-interval ] [ drop ] if ;
: finish-live-interval ( live-interval -- )
[ ranges>> reverse! drop ] [ uses>> reverse! drop ] [ check-start ] tri ;
: finish-live-intervals ( live-intervals -- )
[ finish-live-interval ] each ;
[ ranges>> reverse! ] [ uses>> reverse! ] [ check-start ] tri 2drop ;
TUPLE: sync-point n keep-dst? ;
C: <sync-point> sync-point
GENERIC: insn>sync-point ( insn -- sync-point/f )
M: hairy-clobber-insn insn>sync-point
insn#>> f <sync-point> ;
M: clobber-insn insn>sync-point
insn#>> t <sync-point> ;
[ insn#>> ] [ hairy-clobber-insn? not ] bi sync-point boa ;
M: insn insn>sync-point drop f ;
@ -159,7 +151,7 @@ M: insn insn>sync-point drop f ;
: cfg>live-intervals ( cfg -- live-intervals )
H{ } clone live-intervals set
linearization-order <reversed> [ compute-live-intervals-step ] each
live-intervals get values dup finish-live-intervals ;
live-intervals get values dup [ finish-live-interval ] each ;
: compute-live-intervals ( cfg -- intervals/sync-points )
[ cfg>live-intervals ] [ cfg>sync-points ] bi append ;