Introduce flip-flopping normalisations
[libfirm] / include / libfirm / lowering.h
index 0d590b5..149a6c7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -26,6 +26,8 @@
 #ifndef FIRM_LOWERING_H
 #define FIRM_LOWERING_H
 
+#include <stddef.h>
+
 #include "firm_types.h"
 
 #include "begin.h"
@@ -160,58 +162,12 @@ FIRM_API void lower_CopyB(ir_graph *irg, unsigned max_size,
  * @param irg        The ir graph to be lowered.
  * @param spare_size Allowed spare size for table switches in machine words.
  *                   (Default in edgfe: 128)
+ * @param allow_out_of_bounds   backend can handle out-of-bounds values
+ *                              (values bigger than minimum and maximum proj
+ *                               number)
  */
-FIRM_API void lower_switch(ir_graph *irg, unsigned spare_size);
-
-/**
- * Creates an ir_graph pass for lower_switch().
- *
- * @param name       the name of this pass or NULL
- * @param spare_size Allowed spare size for table switches in machine words.
- *                   (Default in edgfe: 128)
- *
- * @return  the newly created ir_graph pass
- */
-FIRM_API ir_graph_pass_t *lower_switch_pass(const char *name,
-                                            unsigned spare_size);
-
-/**
- * A callback type for creating an intrinsic entity for a given opcode.
- *
- * @param method   the method type of the emulation function entity
- * @param op       the emulated ir_op
- * @param imode    the input mode of the emulated opcode
- * @param omode    the output mode of the emulated opcode
- * @param context  the context parameter
- */
-typedef ir_entity *(create_intrinsic_fkt)(ir_type *method, const ir_op *op,
-                                          const ir_mode *imode,
-                                          const ir_mode *omode, void *context);
-
-/**
- * The lowering parameter description.
- */
-typedef struct lwrdw_param_t {
-       unsigned              little_endian : 1; /**< if true should be lowered for little endian, else big endian */
-       unsigned              doubleword_size;   /**< bitsize of the doubleword mode */
-       create_intrinsic_fkt *create_intrinsic;  /**< callback that creates the intrinsic entity */
-       void                 *ctx;               /**< context parameter for the creator function */
-} lwrdw_param_t;
-
-/**
- * Lower all double word operations.
- *
- * @param param  parameter for lowering
- */
-FIRM_API void lower_dw_ops(const lwrdw_param_t *param);
-
-/**
- * Default implementation. Context is unused.
- */
-FIRM_API ir_entity *def_create_intrinsic_fkt(ir_type *method, const ir_op *op,
-                                             const ir_mode *imode,
-                                             const ir_mode *omode,
-                                             void *context);
+FIRM_API void lower_switch(ir_graph *irg, unsigned spare_size,
+                           int allow_out_of_bounds);
 
 /**
  * Replaces SymConsts by a real constant if possible.
@@ -264,12 +220,32 @@ FIRM_API void lower_const_code(void);
  */
 FIRM_API ir_prog_pass_t *lower_const_code_pass(const char *name);
 
+/**
+ * Function which creates a "set" instraction. A "set" instruction takes a
+ * condition value (a value with mode_b) as input and produces a value in a
+ * general purpose integer mode.
+ * Most architectures have special intrinsics for this. But if all else fails
+ * you can just produces the an if-like construct.
+ */
+typedef ir_node* (*create_set_func)(ir_node *cond);
+
+/**
+ * implementation of create_set_func which produces a Mux node with 0/1 input
+ */
+ir_node *ir_create_mux_set(ir_node *cond, ir_mode *dest_mode);
+
+/**
+ * implementation of create_set_func which produces a cond with control
+ * flow
+ */
+ir_node *ir_create_cond_set(ir_node *cond, ir_mode *dest_mode);
+
 typedef struct lower_mode_b_config_t {
        /* mode that is used to transport 0/1 values */
        ir_mode *lowered_mode;
-       /* preferred mode for the "set" operations (a psi that produces a 0 or 1) */
-       ir_mode *lowered_set_mode;
-       /* whether direct Cond -> Cmps should also be lowered */
+       /* callback for creating set-like instructions */
+       create_set_func create_set;
+       /* whether direct Cond(Cmp) should also be lowered */
        int lower_direct_cmp;
 } lower_mode_b_config_t;
 
@@ -286,17 +262,6 @@ typedef struct lower_mode_b_config_t {
 FIRM_API void ir_lower_mode_b(ir_graph *irg,
                               const lower_mode_b_config_t *config);
 
-/**
- * Creates an ir_graph pass for ir_lower_mode_b().
- *
- * @param name     the name of this pass or NULL
- * @param config   configuration for mode_b lowerer
- *
- * @return  the newly created ir_graph pass
- */
-FIRM_API ir_graph_pass_t *ir_lower_mode_b_pass(const char *name,
-                                           const lower_mode_b_config_t *config);
-
 /**
  * Used as callback, whenever a lowerable mux is found. The return value
  * indicates, whether the mux should be lowered. This may be used, to lower
@@ -388,7 +353,7 @@ typedef union i_record {
  *
  * @return number of found intrinsics.
  */
-FIRM_API unsigned lower_intrinsics(i_record *list, int length,
+FIRM_API size_t lower_intrinsics(i_record *list, size_t length,
                                    int part_block_used);
 
 /**
@@ -400,7 +365,7 @@ FIRM_API unsigned lower_intrinsics(i_record *list, int length,
  * @param part_block_used  set to true if part_block() must be using during lowering
  */
 FIRM_API ir_prog_pass_t *lower_intrinsics_pass(const char *name, i_record *list,
-                                               int length, int part_block_used);
+                                               size_t length, int part_block_used);
 
 /**
  * A mapper for the integer/float absolute value: type abs(type v).