@@ -7682,7 +7682,6 @@ module Std : sig
7682
7682
val is_barrier : jump -> bool
7683
7683
end
7684
7684
7685
-
7686
7685
(* * A set of subroutines.
7687
7686
7688
7687
A partition of a whole program control-flow graph into a
@@ -8040,6 +8039,151 @@ module Std : sig
8040
8039
include Regular. S with type t := t
8041
8040
end
8042
8041
8042
+ (* * Live Variables.
8043
+
8044
+ Computes the set of live variables for each block in a
8045
+ subroutine, taking into account subroutine arguments.
8046
+
8047
+ A variable [v] is {i live} at a program point [x] if there exists a
8048
+ path from [x] to a use of [v] that doesn't go through a
8049
+ definition of [v].
8050
+
8051
+ This module computes liveness on the block granularity, which
8052
+ gives rise to the following notions.
8053
+
8054
+ A variable is {i live-in} at a basic block [x] if it is live at the
8055
+ begining of the block [x].
8056
+
8057
+ A variable is {i live-out} at a basic block [x] if it is live on
8058
+ any of the outcoming edges of [x].
8059
+
8060
+ A variable is {i live-through} at a basic block [x] if it is
8061
+ both live-in and live-out at it.
8062
+
8063
+ {3 Liveness in the SSA form}
8064
+
8065
+ The algorithm works with the SSA form. From the perspective of
8066
+ liveness, the phi-nodes define their right-hand sides on the
8067
+ edges incoming from the corresponding blocks. More formally, for
8068
+ a phi-node at block [b0], [x0 := phi([b1,x1; b2,x2;...;bN,xN])],
8069
+ the defined variable [x0] is considered to be defined at blocks
8070
+ [bi] and the variable [xi] live-out of basic block [bi], for
8071
+ [0 < i <= N].
8072
+
8073
+ Intuitively, this can be visualized as if the following program,
8074
+
8075
+ {v
8076
+
8077
+ b1:
8078
+ x.1 := 1
8079
+ goto b3
8080
+
8081
+ b2:
8082
+ x.2 := 2
8083
+ goto b3
8084
+
8085
+ b3:
8086
+ x.3 <- phi([b1,x1]; [b2, x2])
8087
+ ...
8088
+ v}
8089
+
8090
+ is rewritten to an equivalent (but not in SSA) program,
8091
+
8092
+ {v
8093
+
8094
+ b1:
8095
+ x.1 := 1
8096
+ x.3 := x1
8097
+ goto b3
8098
+
8099
+ b2:
8100
+ x.2 := 2
8101
+ x.3 := x2
8102
+ goto b3
8103
+
8104
+ b3:
8105
+ ...
8106
+ v}
8107
+
8108
+ That means that a variable defined by a phi-node in a block [x]
8109
+ could be live-in at the block [x].
8110
+
8111
+ The {!Live.defs} and {!Live.uses} includes the variables from
8112
+ the corresponding phi-nodes, e.g., [Live.defs b1] will is
8113
+ [{x1,x3}] and [Live.uses b1] is [{x1}].
8114
+
8115
+ @since 2.5.0
8116
+ @before 2.5.0 see {!Sub.compute_liveness} *)
8117
+ module Live : sig
8118
+ type t
8119
+
8120
+ (* * [compute sub] computes the subroutine liveness information.
8121
+
8122
+ Variables specified by [keep] will be kept live at the exit
8123
+ from the function. In addition to the variables in [keep],
8124
+ all free variables used by in and in/out arguments of the
8125
+ subroutine will be kept alive at the exit.*)
8126
+ val compute : ?keep : Var.Set .t -> sub term -> t
8127
+
8128
+ (* * [vars live] the variables that are live in the subroutine.
8129
+
8130
+ The set of variables that are live-in on the entry block of
8131
+ the subroutine that was used to compute [live]. The live
8132
+ variables of the subroutine also called free variables or
8133
+ upper-exposed variables. They may be used in the subroutine
8134
+ before they are assigned. *)
8135
+ val vars : t -> Var.Set .t
8136
+
8137
+ (* * [ins live blk] the set of live-in variables at [blk].
8138
+
8139
+ The set of variables that are live at the entry to the basic
8140
+ block [blk].
8141
+
8142
+ Returns an empty set if [blk] doesn't belong to the [sub] graph.
8143
+ *)
8144
+ val ins : t -> tid -> Var.Set .t
8145
+
8146
+ (* * [outs live blk] the set of live-outs variables at [blk].
8147
+
8148
+ The set of variables that are live at the exist from the basic
8149
+ block [blk].
8150
+
8151
+ Returns an empty set if [blk] doesn't belong to the [sub] graph.*)
8152
+ val outs : t -> tid -> Var.Set .t
8153
+
8154
+ (* * [blks live var] the set of blks where [var] is live-in. *)
8155
+ val blks : t -> var -> Set .M (Tid ).t
8156
+
8157
+ (* * [defs live blk] the set of variables defined by [blk].
8158
+
8159
+ Aka the {i KILL} set, i.e., the set of variables whose
8160
+ liveness is killed in the block [blk]. *)
8161
+ val defs : t -> tid -> Var.Set .t
8162
+
8163
+ (* * [uses live blk] the set of variables used by [blk].
8164
+
8165
+ Aka the {i GEN} set, i.e., the set of variables generated by
8166
+ the block [blk]. *)
8167
+ val uses : t -> tid -> Var.Set .t
8168
+
8169
+ (* * [fold live ~init ~f] folds over live-ins of blocks.
8170
+
8171
+ Applies [f] to live-in set of variables of each block of the
8172
+ subroutine.
8173
+
8174
+ Note, pseudo start and exit nodes are not folded over. *)
8175
+ val fold : t -> init :'a -> f :('a -> tid -> Var.Set .t -> 'a ) -> 'a
8176
+
8177
+ (* * [solution live] returns the fixed point solution.
8178
+
8179
+ The solution is the mapping from blocks to their live-outs.*)
8180
+ val solution : t -> (tid , Var.Set .t ) Solution .t
8181
+
8182
+
8183
+ (* * [pp ppf live] prints the live-in sets of each basic block. *)
8184
+ val pp : Format .formatter -> t -> unit
8185
+ end
8186
+
8043
8187
(* * IR language term.
8044
8188
8045
8189
Term is a building block of the
@@ -8530,22 +8674,17 @@ module Std : sig
8530
8674
[Graphs.Tid.start] node.
8531
8675
8532
8676
When the subroutine is in the SSA form then the phi-nodes have
8533
- the following semantics. For a phi-node at block [b0],
8534
- [x0 := phi([b1,x1; b2,x2;...;bN,xN])], the defined variable
8535
- [x0] is considered to be at the entry of [b0], i.e., [x0] is
8536
- live-in of [b0], and the variable [xi] is live-out of basic
8537
- block [bi], for [i > 0].
8677
+ the following semantics.
8538
8678
8539
8679
Informally, a phi-node defines the values on the corresponding
8540
8680
edges of the predecessors.
8541
8681
8542
-
8543
8682
@since 2.1
8544
8683
@since 2.5.0 supports SSA
8545
8684
@before 2.5.0 the subroutine must not be in the SSA form
8546
8685
*)
8547
8686
val compute_liveness : t -> (tid , Var.Set .t ) Solution .t
8548
-
8687
+ [ @@ deprecated "[since 2022-03] use Live.compute" ]
8549
8688
8550
8689
(* * [flatten sub] returns [sub] in flattened form in which all
8551
8690
operands are trivial.
0 commit comments