2012-05-08 02:44:16 +00:00
|
|
|
/*
|
|
|
|
dags.h
|
|
|
|
|
|
|
|
DAG representation of basic blocks
|
|
|
|
|
|
|
|
Copyright (C) 2012 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2012/05/08
|
|
|
|
|
|
|
|
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 2
|
|
|
|
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, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifndef dags_h
|
|
|
|
#define dags_h
|
|
|
|
|
2012-07-15 12:08:20 +00:00
|
|
|
/** \defgroup qfcc_dags DAG building
|
|
|
|
\ingroup qfcc
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2012-07-15 12:08:20 +00:00
|
|
|
|
2022-01-08 15:26:52 +00:00
|
|
|
#include "QF/progs/pr_comp.h"
|
2012-11-15 06:53:51 +00:00
|
|
|
|
2012-11-16 13:09:49 +00:00
|
|
|
#include "statements.h"
|
|
|
|
|
2012-11-07 05:11:26 +00:00
|
|
|
struct dstring_s;
|
|
|
|
struct flownode_s;
|
|
|
|
|
2012-05-08 02:44:16 +00:00
|
|
|
typedef struct daglabel_s {
|
|
|
|
struct daglabel_s *next;
|
2012-07-19 02:38:02 +00:00
|
|
|
struct daglabel_s *daglabel_chain; ///< all labels created for a dag
|
2012-12-11 10:52:58 +00:00
|
|
|
int number; ///< index into array of labels in dag_t
|
2019-06-16 10:24:19 +00:00
|
|
|
unsigned live:1; ///< accessed via an alias FIXME redundant?
|
2012-05-08 02:44:16 +00:00
|
|
|
const char *opcode; ///< not if op
|
|
|
|
struct operand_s *op; ///< not if opcode;
|
2012-05-08 23:43:48 +00:00
|
|
|
struct dagnode_s *dagnode; ///< node with which this label is associated
|
2012-11-17 03:07:27 +00:00
|
|
|
struct expr_s *expr; ///< expression associated with this label
|
2012-05-08 02:44:16 +00:00
|
|
|
} daglabel_t;
|
|
|
|
|
|
|
|
typedef struct dagnode_s {
|
|
|
|
struct dagnode_s *next;
|
2012-11-17 12:14:42 +00:00
|
|
|
int number; ///< index into array of nodes in dag_t
|
2012-11-18 00:23:01 +00:00
|
|
|
int topo; ///< topological sort order
|
2012-11-17 12:14:42 +00:00
|
|
|
struct set_s *parents; ///< empty if root node
|
2012-11-07 05:11:26 +00:00
|
|
|
int cost; ///< cost of this node in temp vars
|
2020-04-01 07:05:26 +00:00
|
|
|
struct dagnode_s *killed; ///< node is unavailable for cse (by node)
|
2018-08-23 11:04:51 +00:00
|
|
|
st_type_t type; ///< type of node (st_none = leaf)
|
2012-05-08 02:44:16 +00:00
|
|
|
daglabel_t *label; ///< ident/const if leaf node, or operator
|
2019-06-17 14:38:34 +00:00
|
|
|
struct type_s *tl;
|
2012-11-18 04:10:19 +00:00
|
|
|
struct operand_s *value; ///< operand holding the value of this node
|
2012-05-08 13:05:14 +00:00
|
|
|
/// \name child nodes
|
2012-11-17 12:14:42 +00:00
|
|
|
/// if \a children[0] is null, the rest must be null as well. Similar for
|
|
|
|
/// \a children[1].
|
|
|
|
///
|
|
|
|
/// \a edges is the set of all nodes upon which this node depends. ie,
|
|
|
|
/// they must be evaluated before this node is evaluted. So while nodes
|
|
|
|
/// in \a edges may not be true children of this node, they are effective
|
|
|
|
/// children in the DAG. That is, \a edges is for producing a correct
|
|
|
|
/// topological sort of the DAG.
|
2012-05-08 13:05:14 +00:00
|
|
|
//@{
|
2012-11-17 12:14:42 +00:00
|
|
|
struct dagnode_s *children[3];
|
2019-06-17 14:38:34 +00:00
|
|
|
struct type_s *types[3]; ///< desired type of each operand (to alias)
|
2012-11-17 12:14:42 +00:00
|
|
|
struct set_s *edges; ///< includes nodes pointed to by \a children
|
2012-05-08 13:05:14 +00:00
|
|
|
//@}
|
2012-11-17 12:14:42 +00:00
|
|
|
struct set_s *identifiers; ///< set of identifiers attached to this node
|
2021-06-29 00:41:03 +00:00
|
|
|
struct set_s *reachable; ///< set of nodes reachable via edges (not
|
|
|
|
///< parents) for ensuring cycles are not
|
|
|
|
///< created
|
2012-05-08 02:44:16 +00:00
|
|
|
} dagnode_t;
|
|
|
|
|
2012-11-17 12:14:42 +00:00
|
|
|
typedef struct dag_s {
|
|
|
|
struct dag_s *next;
|
|
|
|
dagnode_t **nodes; ///< array of all dagnodes in this dag
|
|
|
|
int num_nodes;
|
2012-11-18 00:23:01 +00:00
|
|
|
int *topo; ///< nodes in topological sort order
|
2012-12-25 08:07:58 +00:00
|
|
|
int num_topo; ///< number of nodes in topo (may be <
|
|
|
|
///< num_nodes after dead node removal)
|
2012-11-17 12:14:42 +00:00
|
|
|
daglabel_t **labels; ///< array of all daglabels in this dag
|
2021-01-09 11:42:23 +00:00
|
|
|
int num_labels;
|
2012-11-17 12:14:42 +00:00
|
|
|
struct set_s *roots; ///< set of root nodes
|
|
|
|
struct flownode_s *flownode;///< flow node this dag represents
|
|
|
|
} dag_t;
|
|
|
|
|
2012-05-08 02:44:16 +00:00
|
|
|
const char *daglabel_string (daglabel_t *label);
|
2012-11-21 04:43:03 +00:00
|
|
|
void print_dag (struct dstring_s *dstr, dag_t *dag, const char *label);
|
2012-11-21 06:03:44 +00:00
|
|
|
void dot_dump_dag (void *_dag, const char *filename);
|
2012-05-08 23:43:48 +00:00
|
|
|
|
|
|
|
/** Make a dag for a single basic block.
|
|
|
|
|
2012-11-30 04:57:08 +00:00
|
|
|
\param flownode The flow graph node representing the basic block for which
|
2012-11-07 02:28:33 +00:00
|
|
|
the dag will be created. The node should have its live
|
|
|
|
variable information already computed.
|
2012-05-08 23:43:48 +00:00
|
|
|
\return The dag representing the basic block.
|
|
|
|
*/
|
2012-11-18 00:23:01 +00:00
|
|
|
dag_t *dag_create (struct flownode_s *flownode);
|
2012-11-07 05:11:26 +00:00
|
|
|
|
2012-12-25 08:07:58 +00:00
|
|
|
void dag_remove_dead_nodes (dag_t *dag);
|
2012-11-17 12:14:42 +00:00
|
|
|
void dag_generate (dag_t *dag, sblock_t *block);
|
2012-05-08 02:44:16 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2012-07-15 12:08:20 +00:00
|
|
|
|
2012-05-08 02:44:16 +00:00
|
|
|
#endif//dags_h
|