change register allocator and related interfaces to use ir_graph* instead of be_irg_t*
[libfirm] / ir / be / bechordal_t.h
index 071990d..e4ff678 100644 (file)
+/*
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
 
 /**
- * Internal datastructures for the chordal register allocator.
- * @author Sebastian Hack
- * @date 25.1.2005
+ * @file
+ * @brief       Internal data structures for the chordal register allocator.
+ * @author      Sebastian Hack
+ * @date        25.01.2005
+ * @version     $Id$
  */
+#ifndef FIRM_BE_BECHORDAL_T_H
+#define FIRM_BE_BECHORDAL_T_H
 
-#ifndef _BECHORDAL_T_H
-#define _BECHORDAL_T_H
-
-#include <stdlib.h>
-
-#include "bitset.h"
+#include "firm_types.h"
 #include "list.h"
-#include "obst.h"
-#include "pset.h"
 #include "pmap.h"
-#include "set.h"
-
-#include "irnode.h"
-#include "irgraph.h"
+#include "bitset.h"
+#include "obst.h"
+#include "debug.h"
 
-#include "be_t.h"
-#include "bearch.h"
+#include "bechordal.h"
+#include "beirg.h"
+#include "beifg.h"
 
 /** Defines an invalid register index. */
 #define NO_COLOR (-1)
 
-#define BUILD_GRAPH
-
-#define DBG_CHORDAL "firm.be.ra.chordal"
-
 /**
  * A liveness interval border.
  */
-typedef struct _border_t {
-       unsigned magic;                                                         /**< A magic number for checking. */
-       struct list_head list;                          /**< list head for queuing. */
-       struct _border_t *other_end;    /**< The other end of the border. */
-       ir_node *irn;                                                 /**< The node. */
-       unsigned step;                                                          /**< The number equal to the interval border. */
-       unsigned pressure;                                              /**< The pressure at this interval border.
-                                                                                                                                       (The border itself is counting). */
-       unsigned is_def : 1;                                    /**< Does this border denote a use or a def. */
-       unsigned is_real : 1;                                   /**< Is the def/use real? Or is it just inserted
-                                                                                                                                       at block beginnings or ends to ensure that inside
-                                                                                                                                       a block, each value has one begin and one end. */
-} border_t;
+struct border_t {
+       DEBUG_ONLY(unsigned magic;)     /**< A magic number for checking. */
+       struct list_head  list;         /**< list head for queuing. */
+       border_t         *other_end;    /**< The other end of the border. */
+       ir_node          *irn;          /**< The node. */
+       unsigned         step;          /**< The number equal to the interval border. */
+       unsigned         pressure;      /**< The pressure at this interval border. (The border itself is counting). */
+       unsigned         is_def  : 1;   /**< Does this border denote a use or a def. */
+       unsigned         is_real : 1;   /**< Is the def/use real? Or is it just
+                                            inserted at block beginnings or ends
+                                            to ensure that inside a block, each
+                                            value has one begin and one end. */
+};
 
 /**
  * Environment for each of the chordal register allocator phases
  */
-struct _be_chordal_env_t {
-       struct obstack obst;    /**< An obstack for temporary storage. */
-       const be_main_session_env_t *session_env; /**< The current session. */
-       pmap *border_heads;   /**< Maps blocks to border heads. */
-
-#ifdef BUILD_GRAPH
-       set *nodes;                                             /**< The interference graph nodes. */
-       set *edges;                                             /**< The interference graph edges. */
-#endif
-
-       bitset_t *live;                         /**< A liveness bitset. */
-       bitset_t *colors;                       /**< The color mask. */
-       bitset_t *in_colors;    /**< Colors used by live in values. */
-       int colors_n;                                   /**< The number of colors. */
+struct be_chordal_env_t {
+       struct obstack       *obst;         /**< An obstack for temporary storage. */
+       be_ra_chordal_opts_t *opts;         /**< A pointer to the chordal ra options. */
+       ir_graph             *irg;          /**< The graph under examination. */
        const arch_register_class_t *cls;   /**< The current register class. */
-       void *data;           /**< Some pointer, to which different
-                          phases can attach data to. */
+       pmap                 *border_heads; /**< Maps blocks to border heads. */
+       be_ifg_t             *ifg;          /**< The interference graph. */
+       bitset_t             *ignore_colors;/**< A set of colors which shall be ignored in register allocation. */
 };
 
-typedef struct _be_chordal_env_t be_chordal_env_t;
-
-static INLINE struct list_head *_get_block_border_head(const be_chordal_env_t *inf, ir_node *bl) {
+static inline struct list_head *_get_block_border_head(const be_chordal_env_t *inf, ir_node *bl) {
   return pmap_get(inf->border_heads, bl);
 }
 
 #define get_block_border_head(info, bl)     _get_block_border_head(info, bl)
 
-int nodes_interfere(const be_chordal_env_t *env, const ir_node *a, const ir_node *b);
-
-#ifdef BUILD_GRAPH
-typedef struct _if_node_t {
-       int nnr;
-       pset *neighb;
-} if_node_t;
-
-typedef struct _if_edge_t {
-       int src, tgt;
-} if_edge_t;
-
-set *be_ra_get_ifg_edges(const be_chordal_env_t *env);
-set *be_ra_get_ifg_nodes(const be_chordal_env_t *env);
-
-int ifg_has_edge(const be_chordal_env_t *env, const if_node_t *n1, const if_node_t* n2);
-
-#define ifn_get_degree(ifnode) pset_count(ifnode->neighb)
-#define foreach_neighb(ifnode, curr) \
-                       for(curr=pset_first(ifnode->neighb); curr; curr=pset_next(ifnode->neighb))
-#endif
-
-extern void be_ra_chordal_spill(be_chordal_env_t *env);
-
-/**
- * Allocate registers for an ir graph.
- * @param irg The graph.
- * @return Some internal data to be freed with be_ra_chordal_done().
- */
-be_chordal_env_t *be_ra_chordal(
-    const be_main_session_env_t *env,
-    const arch_register_class_t *cls);
-
-/**
- * Check current register allocation for correctness.
- * Interfering nodes have different colors
- * Register constraints
- * O(n^2)
- */
-void be_ra_chordal_check(be_chordal_env_t *chordal_env);
-
-/**
- * Free data from the chordal register allocation.
- * @param irg The graph.
- */
-void be_ra_chordal_done(be_chordal_env_t *info);
+#define foreach_border_head(head, pos)         list_for_each_entry_reverse(border_t, pos, head, list)
+#define border_next(b)                      (list_entry((b)->list.next, border_t, list))
+#define border_prev(b)                      (list_entry((b)->list.prev, border_t, list))
+
+#define chordal_has_class(chordal_env, irn) \
+       arch_irn_consider_in_reg_alloc(chordal_env->cls, irn)
+
+void be_ra_chordal_color(be_chordal_env_t *chordal_env);
+
+enum {
+       /* Dump flags */
+       BE_CH_DUMP_NONE       = (1 << 0),
+       BE_CH_DUMP_SPILL      = (1 << 1),
+       BE_CH_DUMP_LIVE       = (1 << 2),
+       BE_CH_DUMP_COLOR      = (1 << 3),
+       BE_CH_DUMP_COPYMIN    = (1 << 4),
+       BE_CH_DUMP_SSADESTR   = (1 << 5),
+       BE_CH_DUMP_TREE_INTV  = (1 << 6),
+       BE_CH_DUMP_CONSTR     = (1 << 7),
+       BE_CH_DUMP_SPILLSLOTS = (1 << 8),
+       BE_CH_DUMP_LOWER      = (1 << 9),
+       BE_CH_DUMP_APPEL      = (1 << 10),
+       BE_CH_DUMP_ALL        = 2 * BE_CH_DUMP_APPEL - 1,
+
+       /* lower perm options */
+       BE_CH_LOWER_PERM_SWAP   = 1,
+       BE_CH_LOWER_PERM_COPY   = 2,
+
+       /* verify options */
+       BE_CH_VRFY_OFF    = 1,
+       BE_CH_VRFY_WARN   = 2,
+       BE_CH_VRFY_ASSERT = 3,
+};
 
-/**
- * Init some things for the chordal register allocator.
- * This must be called before Firm is inited.
- */
-void be_ra_chordal_init(void);
+struct be_ra_chordal_opts_t {
+       int dump_flags;
+       int lower_perm_opt;
+       int vrfy_option;
 
-/**
- * Check the register pressure in a graph.
- * @param env The sesion env.
- * @param cls The register class to consider.
- */
-void be_check_pressure(const be_main_session_env_t *env, const arch_register_class_t *cls);
+       char ilp_server[128];
+       char ilp_solver[128];
+};
 
+void check_for_memory_operands(ir_graph *irg);
 
-#endif /* _BECHORDAL_T_H */
+#endif /* FIRM_BE_BECHORDAL_T_H */