(** Maximum pseudo-register mentioned in a function.  All results or arguments of an instruction of [f], as well as all parameters of [f], are between 1 and [max_reg_function] (inclusive). *)
Definition max_reg_instr (m: positive) (pc: node) (i: instruction) :=
match i with
| Inop s => m
| Iop op args res s => fold_left Pos.max args (Pos.max res m)
| Iload chunk addr args dst s => fold_left Pos.max args (Pos.max dst m)
| Istore chunk addr args src s => fold_left Pos.max args (Pos.max src m)
| Icall sig (inl r) args res s => fold_left Pos.max args (Pos.max r (Pos.max res m))
| Icall sig (inr id) args res s => fold_left Pos.max args (Pos.max res m)
| Itailcall sig (inl r) args => fold_left Pos.max args (Pos.max r m)
| Itailcall sig (inr id) args => fold_left Pos.max args m
| Ibuiltin ef args res s =>
fold_left Pos.max (params_of_builtin_args args)
(fold_left Pos.max (params_of_builtin_res res) m)
| Icond cond args ifso ifnot => fold_left Pos.max args m
| Ijumptable arg tbl => Pos.max arg m
| Ireturn None => m
| Ireturn (Some arg) => Pos.max arg m
end.
Definition max_reg_function (f: function) :=
Pos.max
(PTree.fold max_reg_instr f.(fn_code) 1%positive)
(fold_left Pos.max f.(fn_params) 1%positive).
Remark max_reg_instr_ge:
forall m pc i, Ple m (max_reg_instr m pc i).
Remark max_reg_instr_def:
forall m pc i r, instr_defs i = Some r -> Ple r (max_reg_instr m pc i).
Remark max_reg_instr_uses:
forall m pc i r, In r (instr_uses i) -> Ple r (max_reg_instr m pc i).

Lemma max_reg_function_params:
forall f r, In r f.(fn_params) -> Ple r (max_reg_function f).