annotate src/fftw-3.3.5/genfft/dag.ml @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 7867fa7e1b6b
children
rev   line source
cannam@127 1 (*
cannam@127 2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
cannam@127 3 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@127 4 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@127 5 *
cannam@127 6 * This program is free software; you can redistribute it and/or modify
cannam@127 7 * it under the terms of the GNU General Public License as published by
cannam@127 8 * the Free Software Foundation; either version 2 of the License, or
cannam@127 9 * (at your option) any later version.
cannam@127 10 *
cannam@127 11 * This program is distributed in the hope that it will be useful,
cannam@127 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@127 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@127 14 * GNU General Public License for more details.
cannam@127 15 *
cannam@127 16 * You should have received a copy of the GNU General Public License
cannam@127 17 * along with this program; if not, write to the Free Software
cannam@127 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@127 19 *
cannam@127 20 *)
cannam@127 21
cannam@127 22 open Util
cannam@127 23
cannam@127 24 (* Here, we have functions to transform a sequence of assignments
cannam@127 25 (variable = expression) into a DAG (a directed, acyclic graph).
cannam@127 26 The nodes of the DAG are the assignments, and the edges indicate
cannam@127 27 dependencies. (The DAG is analyzed in the scheduler to find an
cannam@127 28 efficient ordering of the assignments.)
cannam@127 29
cannam@127 30 This file also contains utilities to manipulate the DAG in various
cannam@127 31 ways. *)
cannam@127 32
cannam@127 33 (********************************************
cannam@127 34 * Dag structure
cannam@127 35 ********************************************)
cannam@127 36 type color = RED | BLUE | BLACK | YELLOW
cannam@127 37
cannam@127 38 type dagnode =
cannam@127 39 { assigned: Variable.variable;
cannam@127 40 mutable expression: Expr.expr;
cannam@127 41 input_variables: Variable.variable list;
cannam@127 42 mutable successors: dagnode list;
cannam@127 43 mutable predecessors: dagnode list;
cannam@127 44 mutable label: int;
cannam@127 45 mutable color: color}
cannam@127 46
cannam@127 47 type dag = Dag of (dagnode list)
cannam@127 48
cannam@127 49 (* true if node uses v *)
cannam@127 50 let node_uses v node =
cannam@127 51 List.exists (Variable.same v) node.input_variables
cannam@127 52
cannam@127 53 (* true if assignment of v clobbers any input of node *)
cannam@127 54 let node_clobbers node v =
cannam@127 55 List.exists (Variable.same_location v) node.input_variables
cannam@127 56
cannam@127 57 (* true if nodeb depends on nodea *)
cannam@127 58 let depends_on nodea nodeb =
cannam@127 59 node_uses nodea.assigned nodeb ||
cannam@127 60 node_clobbers nodea nodeb.assigned
cannam@127 61
cannam@127 62 (* transform an assignment list into a dag *)
cannam@127 63 let makedag alist =
cannam@127 64 let dag = List.map
cannam@127 65 (fun assignment ->
cannam@127 66 let (v, x) = assignment in
cannam@127 67 { assigned = v;
cannam@127 68 expression = x;
cannam@127 69 input_variables = Expr.find_vars x;
cannam@127 70 successors = [];
cannam@127 71 predecessors = [];
cannam@127 72 label = 0;
cannam@127 73 color = BLACK })
cannam@127 74 alist
cannam@127 75 in begin
cannam@127 76 for_list dag (fun i ->
cannam@127 77 for_list dag (fun j ->
cannam@127 78 if depends_on i j then begin
cannam@127 79 i.successors <- j :: i.successors;
cannam@127 80 j.predecessors <- i :: j.predecessors;
cannam@127 81 end));
cannam@127 82 Dag dag;
cannam@127 83 end
cannam@127 84
cannam@127 85 let map f (Dag dag) = Dag (List.map f dag)
cannam@127 86 let for_all (Dag dag) f =
cannam@127 87 (* type system loophole *)
cannam@127 88 let make_unit _ = () in
cannam@127 89 make_unit (List.map f dag)
cannam@127 90 let to_list (Dag dag) = dag
cannam@127 91
cannam@127 92 let find_node f (Dag dag) = Util.find_elem f dag
cannam@127 93
cannam@127 94 (* breadth-first search *)
cannam@127 95 let rec bfs (Dag dag) node init_label =
cannam@127 96 let _ = node.label <- init_label in
cannam@127 97 let rec loop = function
cannam@127 98 [] -> ()
cannam@127 99 | node :: rest ->
cannam@127 100 let neighbors = node.predecessors @ node.successors in
cannam@127 101 let m = min_list (List.map (fun node -> node.label) neighbors) in
cannam@127 102 if (node.label > m + 1) then begin
cannam@127 103 node.label <- m + 1;
cannam@127 104 loop (rest @ neighbors);
cannam@127 105 end else
cannam@127 106 loop rest
cannam@127 107 in let neighbors = node.predecessors @ node.successors in
cannam@127 108 loop neighbors
cannam@127 109