Typo fixed.
[libfirm] / ir / ir / ircons.h
index 9e52da2..0cec21f 100644 (file)
@@ -1,30 +1,27 @@
 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
 * All rights reserved.
-*
-* Authors: Martin Trapp, Christian Schaefer,
-*          Goetz Lindenmaier
-*
-* ircons.h ir node construction
 */
 
 /* $Id$ */
 
 /**
-* Ideas for imrovement:
-*
- Handle construction of exceptions more comfortable:
- Add new constructors that pass the exception region (or better the
- Phi for the memories, the ex. region can be found from there) as parameter,
- constructor then adds all Proj nodes and returns the pointer
- to the Proj node that selects the result of the arithmetic operation.
-
- Maybe hide the exception region in a global variable, especially if
- it is always unambiguous.
-**/
+ @todo
+ Ideas for imrovement:
+ -# Handle construction of exceptions more comfortable:
+    Add new constructors that pass the exception region (or better the
+    Phi for the memories, the ex. region can be found from there) as parameter,
+    constructor then adds all Proj nodes and returns the pointer
+    to the Proj node that selects the result of the arithmetic operation.
+ -# Maybe hide the exception region in a global variable, especially if
+    it is always unambiguous.
+*/
 
 /**
+ *  @file ircons.h
  *
- *   file ircons.h
+ *  ir node construction.
+ *
+ *  @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier
  *
  *    This file documents all datatypes and constructors needed to
  *    build a FIRM representation of a pocedure.  The constructors are
  *    ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode);
  *    ir_node *new_Cmp    (ir_node *op1, ir_node *op2);
  *    ir_node *new_Conv   (ir_node *op, ir_mode *mode);
+ *    ir_node *new_Cast   (ir_node *op, type *to_tp);
  *    ir_node *new_Load   (ir_node *store, ir_node *addr);
  *    ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val);
  *    ir_node *new_Alloc  (ir_node *store, ir_node *size, type *alloc_type,
  *    --------------------------------------------
  *
  *    Creates a new Block with the given list of predecessors.  This block
- *    is mature.
+ *    is mature.  As other constructors calls optimization and vrfy for the
+ *    block.  If one of the predecessors is Unknown (as it has to be filled in
+ *    later) optimizations are skipped.  This is necessary to
+ *    construct Blocks in loops.  Leaving Unknown in the Block after finishing
+ *    the construction may have strange effects, especially for interprocedural
+ *    representation and analyses.
  *
  *
  *    CONTROL FLOW OPERATIONS
  *    datastructure don't use
  *      new_SymConst((type_or_id*)get_entity_ld_ident(ent), linkage_ptr_info);.
  *    Use a real const instead:
- *      new_Const(mode_P, tarval_p_from_entity(ent));
+ *      new_Const(mode_P_mach, tarval_p_from_entity(ent));
  *    This makes the Constant independent of name changes of the entity due to
  *    mangling.
  *
  *      attr.i.*type,    a pointer to a type_class.  The mode of the node is mode_Is.
  *        if it is linkage_ptr_info it contains
  *      attr.i.*ptrinfo,  an ident holding information for the linker.  The mode
- *        of the node is mode_P.
+ *        of the node is mode_P_mach.
  *
  *    ---------------
  *
  *
  *    Creates a Phi node. The in's order has to correspond to the order
  *    of in's of current_block.  This is not checked by the library!
+ *    If one of the predecessors is Unknown (as it has to be filled in
+ *    later) optimizations are skipped.  This is necessary to
+ *    construct Phi nodes in loops.  Leaving Unknown in the Phi after finishing
+ *    the construction may have strange effects, especially for interprocedural
+ *    representation and analyses.
  *
  *    Parameter
  *      arity            number of predecessors
 # include "type.h"
 # include "dbginfo.h"
 
-/***************************************************************************/
+/*-------------------------------------------------------------------------*/
 /* The raw interface                                                       */
-/***************************************************************************/
+/*-------------------------------------------------------------------------*/
 
 /* Constructs a Block with a fixed number of predecessors.
    Does not set current_block.  Can not be used with automatic
@@ -1139,6 +1147,8 @@ ir_node *new_rd_Rot    (dbg_info *db, ir_graph *irg, ir_node *block,
                       ir_node *op, ir_node *k, ir_mode *mode);
 ir_node *new_rd_Conv   (dbg_info *db, ir_graph *irg, ir_node *block,
                       ir_node *op, ir_mode *mode);
+ir_node *new_rd_Cast   (dbg_info* db, ir_graph *irg, ir_node *block,
+                      ir_node *op, type *to_tp);
 ir_node *new_rd_Phi    (dbg_info *db, ir_graph *irg, ir_node *block, int arity,
                       ir_node *in[], ir_mode *mode);
 ir_node *new_rd_Load   (dbg_info *db, ir_graph *irg, ir_node *block,
@@ -1158,8 +1168,8 @@ ir_node *new_rd_Tuple  (dbg_info *db, ir_graph *irg, ir_node *block,
                       int arity, ir_node *in[]);
 ir_node *new_rd_Id     (dbg_info *db, ir_graph *irg, ir_node *block,
                       ir_node *val, ir_mode *mode);
-ir_node *new_rd_Bad    ();
-ir_node *new_rd_Unknown();
+ir_node *new_rd_Bad    (ir_graph *irg);
+ir_node *new_rd_Unknown(ir_graph *irg);
 ir_node *new_rd_CallBegin(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *callee);
 ir_node *new_rd_EndReg (dbg_info *db, ir_graph *irg, ir_node *block);
 ir_node *new_rd_EndExcept(dbg_info *db, ir_graph *irg, ir_node *block);
@@ -1167,9 +1177,9 @@ ir_node *new_rd_Break  (dbg_info *db, ir_graph *irg, ir_node *block);
 ir_node *new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
                       ir_mode *mode, long proj);
 
-/***************************************************************************/
+/*-------------------------------------------------------------------------*/
 /* The raw interface without debug support                                 */
-/***************************************************************************/
+/*-------------------------------------------------------------------------*/
 
 /* Constructs a Block with a fixed number of predecessors.
    Does not set current_block.  Can not be used with automatic
@@ -1231,6 +1241,8 @@ ir_node *new_r_Rot    (ir_graph *irg, ir_node *block,
                       ir_node *op, ir_node *k, ir_mode *mode);
 ir_node *new_r_Conv   (ir_graph *irg, ir_node *block,
                       ir_node *op, ir_mode *mode);
+ir_node *new_r_Cast   (ir_graph *irg, ir_node *block,
+                      ir_node *op, type *to_tp);
 ir_node *new_r_Phi    (ir_graph *irg, ir_node *block, int arity,
                       ir_node *in[], ir_mode *mode);
 ir_node *new_r_Load   (ir_graph *irg, ir_node *block,
@@ -1250,8 +1262,8 @@ ir_node *new_r_Tuple  (ir_graph *irg, ir_node *block,
                       int arity, ir_node *in[]);
 ir_node *new_r_Id     (ir_graph *irg, ir_node *block,
                       ir_node *val, ir_mode *mode);
-ir_node *new_r_Bad    ();
-ir_node *new_r_Unknown();
+ir_node *new_r_Bad    (ir_graph *irg);
+ir_node *new_r_Unknown(ir_graph *irg);
 ir_node *new_r_CallBegin(ir_graph *irg, ir_node *block, ir_node *callee);
 ir_node *new_r_EndReg (ir_graph *irg, ir_node *block);
 ir_node *new_r_EndExcept(ir_graph *irg, ir_node *block);
@@ -1259,11 +1271,11 @@ ir_node *new_r_Break  (ir_graph *irg, ir_node *block);
 ir_node *new_r_Filter (ir_graph *irg, ir_node *block, ir_node *arg,
                       ir_mode *mode, long proj);
 
-/*************************************************************************/
+/*-----------------------------------------------------------------------*/
 /* The block oriented interface                                          */
-/*************************************************************************/
+/*-----------------------------------------------------------------------*/
 
-/* Sets the current block in which the following constructors place the
+/** Sets the current block in which the following constructors place the
    nodes they construct. */
 void switch_block (ir_node *target);
 
@@ -1305,6 +1317,7 @@ ir_node *new_d_Shrs   (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
 ir_node *new_d_Rot    (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
 ir_node *new_d_Cmp    (dbg_info* db, ir_node *op1, ir_node *op2);
 ir_node *new_d_Conv   (dbg_info* db, ir_node *op, ir_mode *mode);
+ir_node *new_d_Cast   (dbg_info* db, ir_node *op, type *to_tp);
 ir_node *new_d_Phi    (dbg_info* db, int arity, ir_node *in[], ir_mode *mode);
 ir_node *new_d_Load   (dbg_info* db, ir_node *store, ir_node *addr);
 ir_node *new_d_Store  (dbg_info* db, ir_node *store, ir_node *addr, ir_node *val);
@@ -1325,9 +1338,9 @@ ir_node *new_d_EndExcept(dbg_info *db);
 ir_node *new_d_Break (dbg_info *db);
 ir_node *new_d_Filter (dbg_info *db, ir_node *arg, ir_mode *mode, long proj);
 
-/*************************************************************************/
+/*-----------------------------------------------------------------------*/
 /* The block oriented interface without debug support                    */
-/*************************************************************************/
+/*-----------------------------------------------------------------------*/
 
 /* Needed from the interfase with debug support:
 void switch_block (ir_node *target);   */
@@ -1373,6 +1386,7 @@ ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode);
 ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode);
 ir_node *new_Cmp    (ir_node *op1, ir_node *op2);
 ir_node *new_Conv   (ir_node *op, ir_mode *mode);
+ir_node *new_Cast   (ir_node *op, type *to_tp);
 ir_node *new_Phi    (int arity, ir_node *in[], ir_mode *mode);
 ir_node *new_Load   (ir_node *store, ir_node *addr);
 ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val);
@@ -1389,62 +1403,82 @@ ir_node *new_Id     (ir_node *val, ir_mode *mode);
 ir_node *new_Bad    (void);
 ir_node *new_Unknown(void);
 
-/***********************************************************************/
+/*---------------------------------------------------------------------*/
 /* The comfortable interface.                                          */
 /* Supports automatic Phi node construction.                           */
 /* All routines of the block oriented interface except new_Block are   */
 /* needed also.                                                        */
-/***********************************************************************/
+/*---------------------------------------------------------------------*/
 
-/** Block construction **/
+/* --- Block construction --- */
 /* immature Block without predecessors */
 ir_node *new_d_immBlock (dbg_info* db);
 ir_node *new_immBlock (void);
 
-/* Add a control flow edge to an immature block. */
+/** Add a control flow edge to an immature block. */
 void add_in_edge (ir_node *immblock, ir_node *jmp);
 
-/* fixes the number of predecessors of a block. */
+/** fixes the number of predecessors of a block. */
 void mature_block (ir_node *block);
 
-/** Parameter administration **/
+/* --- Parameter administration --- */
 /* Read a value from the array with the local variables.  Use this
    function to obtain the last definition of the value associated with
    pos.  Pos may not exceed the value passed as n_loc to new_ir_graph. */
 ir_node *get_d_value (dbg_info* db, int pos, ir_mode *mode);
 ir_node *get_value (int pos, ir_mode *mode);
 
-/* Write a value in the array with the local variables. Use this function
+/** Write a value in the array with the local variables. Use this function
    to remember a new definition of the value associated with pos. Pos may
    not exceed the value passed as n_loc to new_ir_graph. */
 void set_value (int pos, ir_node *value);
 
-/* Read a store.
+/** Read a store.
    Use this function to get the most recent version of the store (type M).
    Internally it does the same as get_value. */
 ir_node *get_store (void);
 
-/* Write a store. */
+/** Write a store. */
 void set_store (ir_node *store);
 
-/* keep this node alive even if End is not control-reachable from it */
+/** keep this node alive even if End is not control-reachable from it */
 void keep_alive (ir_node *ka);
 
-/** Useful access routines **/
-/* Returns the current block of the current graph.  To set the current
+/* --- Useful access routines --- */
+/** Returns the current block of the current graph.  To set the current
    block use switch_block(). */
-ir_node *get_cur_block();
+ir_node *get_cur_block(void);
 
-/* Returns the frame type of the current graph */
-type *get_cur_frame_type();
+/** Returns the frame type of the current graph */
+type *get_cur_frame_type(void);
 
 
-/***********************************************************************/
-/* initialize and finalize ir construction                             */
-/***********************************************************************/
+/* --- initialize and finalize ir construction --- */
 
-/* Puts the graph into state "phase_high" */
+/** Puts the graph into state "phase_high" */
 void finalize_cons (ir_graph *irg);
 
+/* --- Initialization --- */
+
+/**
+ * This function is called, whenever a local variable is used before definition
+ *
+ * @parameter mode      the mode of the local var
+ * @pos                 position choosen be the frontend for this var
+ *
+ * @return a firm node of mode @p mode that initialises the var at position pos
+ *
+ * @note
+ *      Do not return NULL
+ *      If this function is not set, FIRM will create a const node with tarval BAD
+ */
+typedef ir_node *default_initialize_local_variable_func_t(ir_mode *mode, int pos);
+
+/**
+ * Initializes the graph construction.
+ *
+ * @param func  @see default_initialize_local_variable_func_t
+ */
+void init_cons (default_initialize_local_variable_func_t *func);
 
 # endif /* _IRCONS_H_ */