Loads do not remove any nodes from the exec after sets. Also fix a 'node leak'.
[libfirm] / ir / tv / tv.h
index accdad8..80525f2 100644 (file)
@@ -1,72 +1,57 @@
 /*
- * Project:     libFIRM
- * File name:   ir/tv/tv.h
- * Purpose:     Representation of and static computations on target machine
- *              values.
- * Author:      Mathias Heil
- * Modified by:
- * Created:
- * CVS-ID:      $Id$
- * Copyright:   (c) 2003 Universität Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
- */
-
-/**
- * @file tv.h
+ * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
  *
- * Declarations for Target Values.
- */
-
-#ifndef _TV_H_
-#define _TV_H_
-
-# include "irmode.h"
-/* # include "entity.h" */
-# include "irnode.h"    /* for pnc_number enum */
-
-
-/****h* libfirm/tv
+ * This file is part of libFirm.
  *
- * NAME
- *    tv -- TargetValue, short tarval.
- *   Internal representation for machine values.
+ * 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.
  *
- * AUTHORS
- *    Matthias Heil
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
  *
- * DESCRIPTION
- *    Tarvals represent target machine values.  They are typed by modes.
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+/**
+ * @file
+ * @brief    Representation of and static computations on target machine
+ *           values.
+ * @date     2003
+ * @author   Mathias Heil
+ * @version  $Id$
+ * @summary
+ *   Tarvals represent target machine values.  They are typed by modes.
  *   Tarvals only represent values of mode_sort:
- *     int_number,
- *     float_number,
- *     boolean,
- *     reference,
- *     character
+ *    - int_number,
+ *    - float_number,
+ *    - boolean,
+ *    - reference,
+ *    - character
  *
  *   In case of references the module accepts an entity to represent the
  *   value.
- *    Furthermore, computations and conversions of these values can
+ *   Furthermore, computations and conversions of these values can
  *   be performed.
  *
- * USES
- *    This module is closely related to the irmode module, as the modes
- *   defined there are thoroughly used throughout the whole module.
- *    Also, the comparison functions rely on the definition of comparison
- *   values in the irnode module.
- *
  * HISTORY
  *    The original tv module originated in the fiasco compiler written ...
  *    This is the new version, described in the tech report 1999-14 by ...
  *
- * SEE ALSO
+ * @sa
  *    Techreport 1999-14
  *    irmode.h for the modes definitions
- *    irnode.h for the pnc_numbers table
- *
- *    tarval_init1 and tarval_init2 for initialization of the
- *   module
- *
- ******/
+ *    irnode.h for the pn_Cmp table
+ */
+#ifndef FIRM_TV_TV_H
+#define FIRM_TV_TV_H
+
+#include "firm_types.h"
+#include "irnode.h"
 
 #ifndef _TARVAL_TYPEDEF_
 #define _TARVAL_TYPEDEF_
@@ -164,7 +149,7 @@ tarval *new_tarval_from_long(long l, ir_mode *mode);
 long get_tarval_long(tarval *tv);
 
 /**
- * This validates if tarval_to_long() will return a satisfying
+ * This validates if get_tarval_long() will return a satisfying
  * result. I.e. if tv is an int_number and between min, max
  * of long int (signed!)
  */
@@ -242,7 +227,7 @@ int tarval_is_double(tarval *tv);
  */
 
 /** Returns the mode of the tarval. */
-ir_mode *get_tarval_mode (tarval *tv);
+ir_mode *get_tarval_mode (const tarval *tv);
 
 /** Returns the contents of the 'link' field of the tarval */
 /* void *get_tarval_link (tarval*); */
@@ -282,6 +267,7 @@ tarval *get_tarval_undefined(void);
 
 /** The mode_b tarval 'false'. */
 extern tarval *tarval_b_false;
+
 /** Returns the mode_b tarval 'false'. */
 tarval *get_tarval_b_false(void);
 
@@ -290,16 +276,11 @@ extern tarval *tarval_b_true;
 /** Returns the mode_b tarval 'true'. */
 tarval *get_tarval_b_true(void);
 
-/** The 'void' pointer tarval. */
-extern tarval *tarval_P_void;
-/** Returns the 'void' pointer tarval. */
-tarval *get_tarval_P_void(void);
-
 /* These functions calculate and return a tarval representing the requested
  * value.
  * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
  * functions, but these are stored on initialization of the irmode module and
- * therefore the irmode functions should be prefered to the functions below. */
+ * therefore the irmode functions should be preferred to the functions below. */
 
 /** Returns the maximum value of a given mode. */
 tarval *get_tarval_max(ir_mode *mode);
@@ -307,12 +288,17 @@ tarval *get_tarval_max(ir_mode *mode);
 /** Returns the minimum value of a given mode. */
 tarval *get_tarval_min(ir_mode *mode);
 
-/** Returns the 0 value (additive neutral) of a given mode. */
+/** Returns the 0 value (additive neutral) of a given mode.
+    For reference modes, the NULL value is returned (old tarval_P_void) */
 tarval *get_tarval_null(ir_mode *mode);
 
 /** Returns the 1 value (multiplicative neutral) of a given mode. */
 tarval *get_tarval_one(ir_mode *mode);
 
+/** Returns the -1 value (multiplicative neutral) of a given mode.
+ *  Returns tarval bad for unsigned modes */
+tarval *get_tarval_minus_one(ir_mode *mode);
+
 /** Return quite nan for float_number modes. */
 tarval *get_tarval_nan(ir_mode *mode);
 
@@ -343,28 +329,28 @@ tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void);
 /**
  * Compares two tarvals
  *
- * Compare a with b and return a pnc_number describing the relation
- * between a and b.  This is either Uo, Lt, Eq, Gt, or False if a or b
- * are symbolic pointers which can not be compared at all.
+ * Compare a with b and return a pn_Cmp describing the relation
+ * between a and b.  This is either pn_Cmp_Uo, pn_Cmp_Lt, pn_Cmp_Eq, pn_Cmp_Gt,
+ * or pn_Cmp_False if a or b are symbolic pointers which can not be compared at all.
  *
  * @param a   A tarval to be compared
  * @param b   A tarval to be compared
  *
  * @return
- *   The pnc_number best describing the relation between a and b is returned.
+ *   The pn_Cmp best describing the relation between a and b is returned.
  *   This means the mode with the least bits set is returned, e.g. if the
- *   tarvals are equal the pnc_number 'Eq' is returned, not 'Ge' which
+ *   tarvals are equal the pn_Cmp 'pn_Cmp_Eq' is returned, not 'pn_Cmp_Ge' which
  *   indicates 'greater or equal'
  *
  * @sa
- *    irnode.h for the definition of pnc_numbers
+ *    irnode.h for the definition of pn_Cmp
  */
-pnc_number tarval_cmp(tarval *a, tarval *b);
+pn_Cmp tarval_cmp(tarval *a, tarval *b);
 
 /**
  * Converts a tarval to another mode.
  *
- * Convert tarval 'src' to mode 'mode', this will suceed if and only if mode
+ * Convert tarval 'src' to mode 'mode', this will succeed if and only if mode
  * 'mode' is wider than the mode of src, as defined in the firm documentation
  * and as returned by the function mode_is_smaller defined in irmode.h.
  *
@@ -383,7 +369,7 @@ pnc_number tarval_cmp(tarval *a, tarval *b);
  *    FIRM documentation for conversion rules
  *    mode_is_smaller defined in irmode.h
  */
-tarval *tarval_convert_to(tarval *src, ir_mode *m);
+tarval *tarval_convert_to(tarval *src, ir_mode *mode);
 
 /*
  * These function implement basic computations representable as opcodes
@@ -394,12 +380,12 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m);
  *    traval_abs:
  *      a - the tarval to operate on
  *
- *    all oters:
+ *    all others:
  *      a - the first operand tarval
  *      b - the second operand tarval
  *
  * RESULT
- *    If neccessary a new tarval is constructed for the resulting value,
+ *    If necessary a new tarval is constructed for the resulting value,
  *   or the one already carrying the computation result is retrieved and
  *   returned as result.
  *
@@ -469,16 +455,16 @@ int tarval_carry(void);
  * Some modes allow more that one representation, for instance integers
  * can be represented hex or decimal. Of course it would be enough to have
  * one and let every backend convert it into the 'right' one.
- * However, we can do this in the tarval much simplier...
+ * However, we can do this in the tarval much simpler...
  */
 typedef enum {
-  TVO_NATIVE,           /**< the default output mode, depends on the mode */
+  TVO_NATIVE,       /**< the default output mode, depends on the mode */
   TVO_HEX,          /**< use hex representation, always possible */
-  TVO_DECIMAL,          /**< use decimal representation */
-  TVO_OCTAL,            /**< use octal representation */
-  TVO_BINARY,           /**< use binary representation */
-  TVO_FLOAT,            /**< use floating point representation (i.e 1.342e-2)*/
-  TVO_HEXFLOAT                  /**< use hexadecimal floating point representation (i.e 0x1.ea32p-12)*/
+  TVO_DECIMAL,      /**< use decimal representation */
+  TVO_OCTAL,        /**< use octal representation */
+  TVO_BINARY,       /**< use binary representation */
+  TVO_FLOAT,        /**< use floating point representation (i.e 1.342e-2)*/
+  TVO_HEXFLOAT      /**< use hexadecimal floating point representation (i.e 0x1.ea32p-12)*/
 } tv_output_mode;
 
 /**
@@ -486,17 +472,17 @@ typedef enum {
  * of a tarval of a mode.
  */
 typedef struct tarval_mode_info {
-    tv_output_mode mode_output;         /**< if != TVO_NATIVE select a special mode */
-    const char *mode_prefix;        /**< if set, this prefix will be printed
-                         before a value of this mode */
-    const char *mode_suffix;        /**< if set, this suffix will be printed
-                         after a value of this mode */
+  tv_output_mode mode_output;  /**< if != TVO_NATIVE select a special mode */
+  const char *mode_prefix;     /**< if set, this prefix will be printed
+                                    before a value of this mode */
+  const char *mode_suffix;     /**< if set, this suffix will be printed
+                                    after a value of this mode */
 } tarval_mode_info;
 
 /**
  * Specify the output options of one mode.
  *
- * This functions stores the modinfo, so DO NOT DESTROY it.
+ * This functions stores the modinfo, so DO NOT DESTROY it.
  *
  * @param mode      a ir_mode that should be associated
  * @param modeinfo  the output format info
@@ -508,7 +494,7 @@ int  set_tarval_mode_output_option(ir_mode *mode, const tarval_mode_info *modein
 /**
  * Returns the output options of one mode.
  *
- * This functions returns the modinfo of a given mode.
+ * This functions returns the modinfo of a given mode.
  *
  * @param mode      a ir_mode that should be associated
  *
@@ -532,7 +518,7 @@ const tarval_mode_info *get_tarval_mode_output_option(ir_mode *mode);
  * @note
  *   The string is allocated using malloc() and is free()ed on the next call
  *   of this function.
- *   The string consists of the ascii characters '0' and '1' and is
+ *   The string consists of the ASCII characters '0' and '1' and is
  *   null terminated
  *
  * @sa
@@ -557,14 +543,14 @@ char *get_tarval_bitpattern(tarval *tv);
  * Because this is the bit representation of the target machine, only the following
  * operations are legal on the result:
  *
- * - concatenation (endian dependance MUST be handled by the CALLER)
+ * - concatenation (endian dependence MUST be handled by the CALLER)
  * - bitwise logical operations to select/mask bits
  *
  * @param tv        the tarval
  * @param byte_ofs  the byte offset
  *
  * @note
- *   The result of this funcion is undefined if the mode is neither integer nor float.
+ *   The result of this function is undefined if the mode is neither integer nor float.
  */
 unsigned char get_tarval_sub_bits(tarval *tv, unsigned byte_ofs);
 
@@ -580,16 +566,22 @@ typedef enum _tarval_classification_t {
 
 /**
  * Identifying tarvals values for algebraic simplifications.
- * @param tv
+ *
+ * @param tv        the tarval
+ *
  * @return
- *   - TV_CLASSIFY_NULL    for additive neutral,
+ *   - TV_CLASSIFY_NULL    for additive neutral or the NULL tarval for reference modes,
  *   - TV_CLASSIFY_ONE     for multiplicative neutral,
  *   - TV_CLASSIFY_ALL_ONE for bitwise-and neutral
  *   - TV_CLASSIFY_OTHER   else
  */
 tarval_classification_t classify_tarval(tarval *tv);
 
-
+/**
+ * Returns non-zero if a given (integer) tarval has only one single bit
+ * set.
+ */
+int is_single_bit_tarval(tarval *tv);
 
 /**
  * Output of tarvals to a buffer.
@@ -601,4 +593,4 @@ int tarval_snprintf(char *buf, size_t buflen, tarval *tv);
  */
 int tarval_printf(tarval *tv);
 
-#endif  /* _TV_H_ */
+#endif  /* FIRM_TV_TV_H */