(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)
(** Recognition of tail calls: correctness proof *)
(** * Syntactic properties of the code transformation *)
(** ** Measuring the number of instructions eliminated *)
(** The [return_measure c pc] function counts the number of instructions eliminated by the code transformation, where [pc] is the successor of a call turned into a tailcall.  This is the length of the move/nop/return sequence recognized by the [is_return] boolean function. *)
Fixpoint return_measure_rec (n: nat) (c: code) (pc: node)
{struct n}: nat :=
match n with
| O => O
| S n' =>
match c!pc with
| Some(Inop s) => S(return_measure_rec n' c s)
| Some(Iop op args dst s) => S(return_measure_rec n' c s)
| _ => O
end
end.
Definition return_measure (c: code) (pc: node) :=
return_measure_rec niter c pc.

(* Specifications: *)
Lemma return_measure_bounds:
forall f pc, (return_measure f pc <= niter)%nat.