aboutsummaryrefslogtreecommitdiffstats
path: root/src/hls/PipelineOp.v
blob: 0783e4ea6634e74fad80d071d06413b4b1b1746b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(*
 * Vericert: Verified high-level synthesis.
 * Copyright (C) 2021 Yann Herklotz <yann@yannherklotz.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *)

Require Import compcert.common.AST.
Require Import compcert.common.Errors.
Require Import compcert.common.Globalenvs.
Require Import compcert.lib.Integers.
Require Import compcert.lib.Maps.
Require Import compcert.verilog.Op.

Require Import vericert.common.Vericertlib.
Require Import vericert.hls.RTLBlockInstr.
Require Import vericert.hls.RTLPar.
Require Import vericert.hls.FunctionalUnits.

Definition state : Type := code * funct_units.

Definition div_pos (il: nat * list nat) x :=
  let (i, l) := il in
  match x with
  | RBop _ Odiv _ _ => (S i, i :: l)
  | RBop _ Odivu _ _ => (S i, i :: l)
  | RBop _ Omod _ _ => (S i, i :: l)
  | RBop _ Omodu _ _ => (S i, i :: l)
  | _ => (S i, l)
  end.

Definition find_divs (bb: bblock) : list nat :=
  snd (List.fold_left div_pos bb.(bb_body) (1%nat, nil)).

Definition transf_code (i: state) (bbn: node * bblock) : state :=
  let (c, fu) := i in
  let (n, bb) := bbn in
  (PTree.set n bb c, fu).

Definition transf_function (f: function) : function :=
  let (c, fu) := List.fold_left transf_code
                                (PTree.elements f.(fn_code))
                                (PTree.empty bblock, f.(fn_funct_units)) in
  mkfunction
    f.(fn_sig)
    f.(fn_params)
    f.(fn_stacksize)
    c
    fu
    f.(fn_entrypoint).

Definition transf_fundef (fd: fundef) : fundef :=
  transf_fundef transf_function fd.

Definition transf_program (p: program) : program :=
  transform_program transf_fundef p.