aboutsummaryrefslogtreecommitdiffstats
path: root/src/pipelining/SoftwarePipelining.ml
blob: 0ba6d9d5582a8b280706598bc3df506c9ad0b0be (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
68
69
70
71
72
73
74
(***********************************************************************)
(*                                                                     *)
(*                        Compcert Extensions                          *)
(*                                                                     *)
(*                       Jean-Baptiste Tristan                         *)
(*                                                                     *)
(*  All rights reserved.  This file is distributed under the terms     *)
(*  described in file ../../LICENSE.                                   *)
(*                                                                     *)
(***********************************************************************)


open SPBasic
open SPIMS
open SPMVE
open RTL

let clean t = 

  let rec clean_rec i =
    match i with 
    | 0 -> []
    | n ->
      begin
        match t.(i - 1) with
        | None -> clean_rec (i - 1)
        | Some inst -> inst :: clean_rec (i - 1)
      end
  in
  let l = List.rev (clean_rec (Array.length t)) in
  List.hd l :: (List.filter (fun e -> not (is_cond e)) (List.tl l))

let print_nodes = List.iter (fun n -> Printf.printf "%s \n" (string_of_node n))  

(* random heuristic *)

let find node schedule opt =
  try NI.find node schedule with
  | Not_found -> opt

(* A random heuristic is used to pick the next instruction to be scheduled from the unscheduled
 * instructions.  The scheduled instructions are given to the function, and the unscheduled
 * instructions are created by taking all the instructions that are not in the scheduled list.
 *)
let random ddg schedule = 
  let unscheduled = G.fold_vertex (fun node l ->
      match find node schedule None with
      | Some v -> l
      | None -> node :: l
    ) ddg [] in
  let bound = List.length unscheduled in 
  Random.self_init (); 
  List.nth unscheduled (Random.int bound)

(* tought heuristics *)

module Topo = Graph.Topological.Make (G)
module Scc = Graph.Components.Make (G)

let order = ref []

let pipeliner ddg =
  order := List.flatten (Scc.scc_list ddg);
  let (sched,ii) = SPIMS.pipeliner ddg random in
  let (steady,prolog,epilog,min,unroll,entrance,way_out) = SPMVE.mve ddg sched ii in
  let steady_state = clean steady in
  if min <= 0 then None 
  else
    Some {steady_state = steady_state; prolog = prolog; epilog = epilog; min = min; unrolling = unroll;
          ramp_up = entrance; ramp_down = way_out}


let pipeline f =
  SPBasic.apply_pipeliner f pipeliner ~debug:false