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
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
2012-11-15 06:53:51 +00:00
|
|
|
#include "QF/pr_comp.h"
|
|
|
|
|
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-11-17 12:14:42 +00:00
|
|
|
int number; ///< index into array of labels in dag_t
|
2012-07-19 02:38:02 +00:00
|
|
|
struct daglabel_s *daglabel_chain; ///< all labels created for a dag
|
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
|
2012-11-20 05:30:42 +00:00
|
|
|
unsigned killed:1; ///< node is unavailable for cse
|
2012-11-16 13:09:49 +00:00
|
|
|
st_type_t type; ///< type of node (st_node = leaf)
|
2012-05-08 02:44:16 +00:00
|
|
|
daglabel_t *label; ///< ident/const if leaf node, or operator
|
2012-11-15 08:58:33 +00:00
|
|
|
etype_t 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];
|
|
|
|
etype_t types[3]; ///< desired type of each operand (to alias)
|
|
|
|
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
|
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-11-17 12:14:42 +00:00
|
|
|
daglabel_t **labels; ///< array of all daglabels in this dag
|
|
|
|
int num_labels;;
|
|
|
|
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-17 12:14:42 +00:00
|
|
|
void print_dag (struct dstring_s *dstr, dag_t *dag);
|
2012-05-08 23:43:48 +00:00
|
|
|
|
|
|
|
/** Make a dag for a single basic block.
|
|
|
|
|
2012-11-07 02:28:33 +00:00
|
|
|
\param node The flow graph node representing the basic block for which
|
|
|
|
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-11-17 12:14:42 +00:00
|
|
|
void dag_generate (dag_t *dag, sblock_t *block);
|
2012-05-08 02:44:16 +00:00
|
|
|
|
2012-07-15 12:08:20 +00:00
|
|
|
//@}
|
|
|
|
|
2012-05-08 02:44:16 +00:00
|
|
|
#endif//dags_h
|