From 003979e6f8a15a2e380407134af0092268ce2bbc Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 17 Jun 2003 15:03:38 +0000 Subject: [PATCH] Added two new modes: mode_BAD the mode of tarval_bad and mode_ANY, the mode of tarval_undefined this fixed tarval_snprintf/tarval_printf of these tarvals Fixed equivalent_node. compute_value() has changed its semantic to return tarval_bad instead of NULL. [r1361] --- ir/ir/irgopt.c | 7 +++++-- ir/ir/irmode.c | 24 ++++++++++++++++++++++++ ir/ir/irmode.h | 10 +++++++++- ir/ir/iropt.c | 6 +++--- ir/tv/strcalc.c | 5 +++-- ir/tv/tv.c | 4 ++-- 6 files changed, 46 insertions(+), 10 deletions(-) diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index f2b0dc589..2116345fa 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -46,10 +46,13 @@ static void init_link (ir_node *n, void *env) { static void optimize_in_place_wrapper (ir_node *n, void *env) { int i; - ir_node *optimized; + ir_node *optimized, *old; for (i = 0; i < get_irn_arity(n); i++) { - optimized = optimize_in_place_2(get_irn_n(n, i)); + /* get?irn_n skips Id nodes, so comparison old != optimized does not + show all optimizations. Therefore always set new predecessor. */ + old = get_irn_n(n, i); + optimized = optimize_in_place_2(old); set_irn_n(n, i, optimized); } diff --git a/ir/ir/irmode.c b/ir/ir/irmode.c index b5a47da9c..a09ffbd3a 100644 --- a/ir/ir/irmode.c +++ b/ir/ir/irmode.c @@ -100,6 +100,8 @@ ir_mode *mode_T; ir_mode *mode_X; ir_mode *mode_M; ir_mode *mode_BB; +ir_mode *mode_ANY; +ir_mode *mode_BAD; /* predefined numerical modes: */ ir_mode *mode_F; /* float */ @@ -144,6 +146,8 @@ INLINE ir_mode *get_modeP(void) { ANNOUNCE(); return mode_P; } INLINE ir_mode *get_modeX(void) { ANNOUNCE(); return mode_X; } INLINE ir_mode *get_modeM(void) { ANNOUNCE(); return mode_M; } INLINE ir_mode *get_modeBB(void) { ANNOUNCE(); return mode_BB; } +INLINE ir_mode *get_modeANY(void) { ANNOUNCE(); return mode_ANY; } +INLINE ir_mode *get_modeBAD(void) { ANNOUNCE(); return mode_BAD; } /** * Registers a new mode if not defined yet, else returns @@ -584,6 +588,26 @@ init_mode (void) mode_T->sign = 0; mode_T->tv_priv = NULL; + /* ANY */ + mode_ANY = &modes[irm_ANY]; + mode_ANY->name = id_from_str("ANY", 3); + mode_ANY->code = irm_ANY; + mode_ANY->sort = irms_auxiliary; + mode_ANY->sign = 0; + mode_ANY->align = 0; + mode_ANY->size = 0; + mode_ANY->tv_priv = NULL; + + /* BAD */ + mode_BAD = &modes[irm_BAD]; + mode_BAD->name = id_from_str("BAD", 3); + mode_BAD->code = irm_BAD; + mode_BAD->sort = irms_auxiliary; + mode_BAD->sign = 0; + mode_BAD->align = 0; + mode_BAD->size = 0; + mode_BAD->tv_priv = NULL; + /* boolean */ mode_b = &modes[irm_b]; mode_b->name = id_from_str("b", 1); diff --git a/ir/ir/irmode.h b/ir/ir/irmode.h index 8dca33dbd..c97345e77 100644 --- a/ir/ir/irmode.h +++ b/ir/ir/irmode.h @@ -75,6 +75,8 @@ typedef enum { /* irm is short for `ir mode' */ irm_M, /**< memory */ irm_T, /**< tuple */ irm_U, /**< unicode character */ + irm_ANY, /**< undefined mode */ + irm_BAD, /**< bad mode */ irm_max /**< maximum value for modecode */ } modecode; @@ -82,7 +84,7 @@ typedef enum { /* irm is short for `ir mode' */ */ typedef enum { /* Predefined sorts of modes */ - irms_auxiliary, /**< Only for Firm use. Not extensible. (irm_T) */ + irms_auxiliary, /**< Only for Firm use. Not extensible. (irm_T, irm_ANY, irm_BAD) */ /* irms_control_flow **< Marks all control flow modes. Not extensible. (irm_BB, irm_X) */ /* irms_memory **< Marks the memory mode. Not extensible. (irm_M) */ irms_internal_boolean, /**< Internal boolean representation. @@ -249,6 +251,9 @@ extern ir_mode *mode_C; /**< 8 bit char */ extern ir_mode *mode_U; /**< 16 bit unicode char */ extern ir_mode *mode_P; /**< pointer */ +extern ir_mode *mode_ANY;/**< undefined mode */ +extern ir_mode *mode_BAD;/**< bad mode */ + /*@{*/ /** Access routines for JNI Interface */ ir_mode *get_modeT(void); @@ -270,6 +275,8 @@ ir_mode *get_modeb(void); ir_mode *get_modeX(void); ir_mode *get_modeM(void); ir_mode *get_modeBB(void); +ir_mode *get_modeANY(void); +ir_mode *get_modeBAD(void); /** Functions to check, whether a modecode is signed, float, int, num, data, @@ -315,6 +322,7 @@ int mode_is_num (const ir_mode *mode); int mode_is_data (const ir_mode *mode); int mode_is_datab (const ir_mode *mode); int mode_is_dataM (const ir_mode *mode); + /** Returns true if sm can be converted to lm without loss according to firm definiton */ int smaller_mode(const ir_mode *sm, const ir_mode *lm); diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 8f2875c1f..4ce8c62cd 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -44,7 +44,7 @@ value_of (ir_node *n) return tarval_bad; } -/* if n can be computed, return the value, else NULL. Performs +/* if n can be computed, return the value, else tarval_bad. Performs constant folding. GL: Only if n is arithmetic operator? */ tarval * computed_value (ir_node *n) @@ -389,9 +389,9 @@ equivalent_node (ir_node *n) ir_node *on; /* After running compute_node there is only one constant predecessor. Find this predecessors value and remember the other node: */ - if ((tv = computed_value (a))) { + if ((tv = computed_value (a)) != tarval_bad) { on = b; - } else if ((tv = computed_value (b))) { + } else if ((tv = computed_value (b)) != tarval_bad) { on = a; } else break; diff --git a/ir/tv/strcalc.c b/ir/tv/strcalc.c index 6107e4e06..c9d1b8aae 100644 --- a/ir/tv/strcalc.c +++ b/ir/tv/strcalc.c @@ -607,11 +607,12 @@ static void _divmod(const char *dividend, const char *divisor, char *quot, char memset(quot, SC_0, CALC_BUFFER_SIZE); memset(rem, SC_0, CALC_BUFFER_SIZE); + /* if the divisor is zero this won't work (quot is zero) */ + if (sc_comp(divisor, quot) == 0) assert(0 && "division by zero!"); + /* if the dividend is zero result is zero (quot is zero)*/ if (sc_comp(dividend, quot) == 0) return; - /* if the divisor is zero this won't work (quot is zero) */ - if (sc_comp(divisor, quot) == 0) assert(0 && "division by zero!"); if (_sign(dividend) == -1) { diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 84ff0bb27..f9cea8730 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -1205,10 +1205,10 @@ void init_tarval_2(void) ANNOUNCE(); tarval_bad = (tarval*)malloc(sizeof(tarval)); - tarval_bad->mode = NULL; + tarval_bad->mode = mode_BAD; tarval_undefined = (tarval*)malloc(sizeof(tarval)); - tarval_undefined->mode = NULL; + tarval_undefined->mode = mode_ANY; tarval_b_true = (tarval*)malloc(sizeof(tarval)); tarval_b_true->mode = mode_b; -- 2.20.1