1*38fd1498Szrj /* DDG - Data Dependence Graph - interface. 2*38fd1498Szrj Copyright (C) 2004-2018 Free Software Foundation, Inc. 3*38fd1498Szrj Contributed by Ayal Zaks and Mustafa Hagog <zaks,mustafa@il.ibm.com> 4*38fd1498Szrj 5*38fd1498Szrj This file is part of GCC. 6*38fd1498Szrj 7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under 8*38fd1498Szrj the terms of the GNU General Public License as published by the Free 9*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later 10*38fd1498Szrj version. 11*38fd1498Szrj 12*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or 14*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15*38fd1498Szrj for more details. 16*38fd1498Szrj 17*38fd1498Szrj You should have received a copy of the GNU General Public License 18*38fd1498Szrj along with GCC; see the file COPYING3. If not see 19*38fd1498Szrj <http://www.gnu.org/licenses/>. */ 20*38fd1498Szrj 21*38fd1498Szrj #ifndef GCC_DDG_H 22*38fd1498Szrj #define GCC_DDG_H 23*38fd1498Szrj 24*38fd1498Szrj /* For sbitmap. */ 25*38fd1498Szrj 26*38fd1498Szrj typedef struct ddg_node *ddg_node_ptr; 27*38fd1498Szrj typedef struct ddg_edge *ddg_edge_ptr; 28*38fd1498Szrj typedef struct ddg *ddg_ptr; 29*38fd1498Szrj typedef struct ddg_scc *ddg_scc_ptr; 30*38fd1498Szrj typedef struct ddg_all_sccs *ddg_all_sccs_ptr; 31*38fd1498Szrj 32*38fd1498Szrj enum dep_type {TRUE_DEP, OUTPUT_DEP, ANTI_DEP}; 33*38fd1498Szrj enum dep_data_type {REG_OR_MEM_DEP, REG_DEP, MEM_DEP, REG_AND_MEM_DEP}; 34*38fd1498Szrj 35*38fd1498Szrj /* The following two macros enables direct access to the successors and 36*38fd1498Szrj predecessors bitmaps held in each ddg_node. Do not make changes to 37*38fd1498Szrj these bitmaps, unless you want to change the DDG. */ 38*38fd1498Szrj #define NODE_SUCCESSORS(x) ((x)->successors) 39*38fd1498Szrj #define NODE_PREDECESSORS(x) ((x)->predecessors) 40*38fd1498Szrj 41*38fd1498Szrj /* A structure that represents a node in the DDG. */ 42*38fd1498Szrj struct ddg_node 43*38fd1498Szrj { 44*38fd1498Szrj /* Each node has a unique CUID index. These indices increase monotonically 45*38fd1498Szrj (according to the order of the corresponding INSN in the BB), starting 46*38fd1498Szrj from 0 with no gaps. */ 47*38fd1498Szrj int cuid; 48*38fd1498Szrj 49*38fd1498Szrj /* The insn represented by the node. */ 50*38fd1498Szrj rtx_insn *insn; 51*38fd1498Szrj 52*38fd1498Szrj /* A note preceding INSN (or INSN itself), such that all insns linked 53*38fd1498Szrj from FIRST_NOTE until INSN (inclusive of both) are moved together 54*38fd1498Szrj when reordering the insns. This takes care of notes that should 55*38fd1498Szrj continue to precede INSN. */ 56*38fd1498Szrj rtx_insn *first_note; 57*38fd1498Szrj 58*38fd1498Szrj /* Incoming and outgoing dependency edges. */ 59*38fd1498Szrj ddg_edge_ptr in; 60*38fd1498Szrj ddg_edge_ptr out; 61*38fd1498Szrj 62*38fd1498Szrj /* Each bit corresponds to a ddg_node according to its cuid, and is 63*38fd1498Szrj set iff the node is a successor/predecessor of "this" node. */ 64*38fd1498Szrj sbitmap successors; 65*38fd1498Szrj sbitmap predecessors; 66*38fd1498Szrj 67*38fd1498Szrj /* For general use by algorithms manipulating the ddg. */ 68*38fd1498Szrj union { 69*38fd1498Szrj int count; 70*38fd1498Szrj void *info; 71*38fd1498Szrj } aux; 72*38fd1498Szrj }; 73*38fd1498Szrj 74*38fd1498Szrj /* A structure that represents an edge in the DDG. */ 75*38fd1498Szrj struct ddg_edge 76*38fd1498Szrj { 77*38fd1498Szrj /* The source and destination nodes of the dependency edge. */ 78*38fd1498Szrj ddg_node_ptr src; 79*38fd1498Szrj ddg_node_ptr dest; 80*38fd1498Szrj 81*38fd1498Szrj /* TRUE, OUTPUT or ANTI dependency. */ 82*38fd1498Szrj dep_type type; 83*38fd1498Szrj 84*38fd1498Szrj /* REG or MEM dependency. */ 85*38fd1498Szrj dep_data_type data_type; 86*38fd1498Szrj 87*38fd1498Szrj /* Latency of the dependency. */ 88*38fd1498Szrj int latency; 89*38fd1498Szrj 90*38fd1498Szrj /* The distance: number of loop iterations the dependency crosses. */ 91*38fd1498Szrj int distance; 92*38fd1498Szrj 93*38fd1498Szrj /* The following two fields are used to form a linked list of the in/out 94*38fd1498Szrj going edges to/from each node. */ 95*38fd1498Szrj ddg_edge_ptr next_in; 96*38fd1498Szrj ddg_edge_ptr next_out; 97*38fd1498Szrj 98*38fd1498Szrj /* For general use by algorithms manipulating the ddg. */ 99*38fd1498Szrj union { 100*38fd1498Szrj int count; 101*38fd1498Szrj void *info; 102*38fd1498Szrj } aux; 103*38fd1498Szrj }; 104*38fd1498Szrj 105*38fd1498Szrj /* This structure holds the Data Dependence Graph for a basic block. */ 106*38fd1498Szrj struct ddg 107*38fd1498Szrj { 108*38fd1498Szrj /* The basic block for which this DDG is built. */ 109*38fd1498Szrj basic_block bb; 110*38fd1498Szrj 111*38fd1498Szrj /* Number of instructions in the basic block. */ 112*38fd1498Szrj int num_nodes; 113*38fd1498Szrj 114*38fd1498Szrj /* Number of load/store instructions in the BB - statistics. */ 115*38fd1498Szrj int num_loads; 116*38fd1498Szrj int num_stores; 117*38fd1498Szrj 118*38fd1498Szrj /* Number of debug instructions in the BB. */ 119*38fd1498Szrj int num_debug; 120*38fd1498Szrj 121*38fd1498Szrj /* This array holds the nodes in the graph; it is indexed by the node 122*38fd1498Szrj cuid, which follows the order of the instructions in the BB. */ 123*38fd1498Szrj ddg_node_ptr nodes; 124*38fd1498Szrj 125*38fd1498Szrj /* The branch closing the loop. */ 126*38fd1498Szrj ddg_node_ptr closing_branch; 127*38fd1498Szrj 128*38fd1498Szrj /* Build dependence edges for closing_branch, when set. In certain cases, 129*38fd1498Szrj the closing branch can be dealt with separately from the insns of the 130*38fd1498Szrj loop, and then no such deps are needed. */ 131*38fd1498Szrj int closing_branch_deps; 132*38fd1498Szrj 133*38fd1498Szrj /* Array and number of backarcs (edges with distance > 0) in the DDG. */ 134*38fd1498Szrj int num_backarcs; 135*38fd1498Szrj ddg_edge_ptr *backarcs; 136*38fd1498Szrj }; 137*38fd1498Szrj 138*38fd1498Szrj 139*38fd1498Szrj /* Holds information on an SCC (Strongly Connected Component) of the DDG. */ 140*38fd1498Szrj struct ddg_scc 141*38fd1498Szrj { 142*38fd1498Szrj /* A bitmap that represents the nodes of the DDG that are in the SCC. */ 143*38fd1498Szrj sbitmap nodes; 144*38fd1498Szrj 145*38fd1498Szrj /* Array and number of backarcs (edges with distance > 0) in the SCC. */ 146*38fd1498Szrj ddg_edge_ptr *backarcs; 147*38fd1498Szrj int num_backarcs; 148*38fd1498Szrj 149*38fd1498Szrj /* The maximum of (total_latency/total_distance) over all cycles in SCC. */ 150*38fd1498Szrj int recurrence_length; 151*38fd1498Szrj }; 152*38fd1498Szrj 153*38fd1498Szrj /* This structure holds the SCCs of the DDG. */ 154*38fd1498Szrj struct ddg_all_sccs 155*38fd1498Szrj { 156*38fd1498Szrj /* Array that holds the SCCs in the DDG, and their number. */ 157*38fd1498Szrj ddg_scc_ptr *sccs; 158*38fd1498Szrj int num_sccs; 159*38fd1498Szrj 160*38fd1498Szrj ddg_ptr ddg; 161*38fd1498Szrj }; 162*38fd1498Szrj 163*38fd1498Szrj 164*38fd1498Szrj ddg_ptr create_ddg (basic_block, int closing_branch_deps); 165*38fd1498Szrj void free_ddg (ddg_ptr); 166*38fd1498Szrj 167*38fd1498Szrj void print_ddg (FILE *, ddg_ptr); 168*38fd1498Szrj void vcg_print_ddg (FILE *, ddg_ptr); 169*38fd1498Szrj void print_ddg_edge (FILE *, ddg_edge_ptr); 170*38fd1498Szrj void print_sccs (FILE *, ddg_all_sccs_ptr, ddg_ptr); 171*38fd1498Szrj 172*38fd1498Szrj ddg_node_ptr get_node_of_insn (ddg_ptr, rtx_insn *); 173*38fd1498Szrj 174*38fd1498Szrj void find_successors (sbitmap result, ddg_ptr, sbitmap); 175*38fd1498Szrj void find_predecessors (sbitmap result, ddg_ptr, sbitmap); 176*38fd1498Szrj 177*38fd1498Szrj ddg_all_sccs_ptr create_ddg_all_sccs (ddg_ptr); 178*38fd1498Szrj void free_ddg_all_sccs (ddg_all_sccs_ptr); 179*38fd1498Szrj 180*38fd1498Szrj int find_nodes_on_paths (sbitmap result, ddg_ptr, sbitmap from, sbitmap to); 181*38fd1498Szrj int longest_simple_path (ddg_ptr, int from, int to, sbitmap via); 182*38fd1498Szrj 183*38fd1498Szrj bool autoinc_var_is_used_p (rtx_insn *, rtx_insn *); 184*38fd1498Szrj 185*38fd1498Szrj #endif /* GCC_DDG_H */ 186