irop_flag_fragile flag added
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 29 Sep 2004 14:05:20 +0000 (14:05 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 29 Sep 2004 14:05:20 +0000 (14:05 +0000)
[r4001]

ir/ir/irop.c
ir/ir/irop_t.h
ir/ir/iropt.c

index 19fdec4..3567ead 100644 (file)
@@ -117,67 +117,69 @@ init_op(void)
 #define X   irop_flag_cfopcode
 #define I   irop_flag_ip_cfopcode
 #define F   irop_flag_fragile
-
-  op_Block     = new_ir_op(iro_Block,     "Block",     op_pin_state_pinned, L,   oparity_variable, -1, sizeof(block_attr));
-
-  op_Start     = new_ir_op(iro_Start,     "Start",     op_pin_state_pinned, X,   oparity_zero,     -1, sizeof(start_attr));
-  op_End       = new_ir_op(iro_End,       "End",       op_pin_state_pinned, X,   oparity_dynamic,  -1, 0);
-  op_Jmp       = new_ir_op(iro_Jmp,       "Jmp",       op_pin_state_pinned, X,   oparity_zero,     -1, 0);
-  op_Cond      = new_ir_op(iro_Cond,      "Cond",      op_pin_state_pinned, L|X, oparity_any,      -1, sizeof(cond_attr));
-  op_Return    = new_ir_op(iro_Return,    "Return",    op_pin_state_pinned, L|X, oparity_zero,     -1, 0);
-  op_Raise     = new_ir_op(iro_Raise,     "Raise",     op_pin_state_pinned, L|X, oparity_any,      -1, 0);
-
-  op_Const     = new_ir_op(iro_Const,     "Const",     op_pin_state_floats, 0,   oparity_zero,     -1, sizeof(const_attr));
-  op_SymConst  = new_ir_op(iro_SymConst,  "SymConst",  op_pin_state_floats, 0,   oparity_zero,     -1, sizeof(symconst_attr));
-
-  op_Sel       = new_ir_op(iro_Sel,       "Sel",       op_pin_state_floats, L,   oparity_any,      -1, sizeof(sel_attr));
-  op_InstOf    = new_ir_op(iro_InstOf,    "InstOf",    op_pin_state_floats, L,   oparity_any,      -1, sizeof(sel_attr));
-
-  op_Call      = new_ir_op(iro_Call,      "Call",      op_pin_state_pinned, L|F, oparity_variable, -1, sizeof(call_attr));
-  op_Add       = new_ir_op(iro_Add,       "Add",       op_pin_state_floats, C,   oparity_binary,    0, 0);
-  op_Minus     = new_ir_op(iro_Minus,     "Minus",     op_pin_state_floats, 0,   oparity_unary,     0, 0);
-  op_Sub       = new_ir_op(iro_Sub,       "Sub",       op_pin_state_floats, L,   oparity_binary,    0, 0);
-  op_Mul       = new_ir_op(iro_Mul,       "Mul",       op_pin_state_floats, C,   oparity_binary,    0, 0);
-  op_Quot      = new_ir_op(iro_Quot,      "Quot",      op_pin_state_pinned, L|F, oparity_binary,    1, sizeof(except_attr));
-  op_DivMod    = new_ir_op(iro_DivMod,    "DivMod",    op_pin_state_pinned, L|F, oparity_binary,    1, sizeof(except_attr));
-  op_Div       = new_ir_op(iro_Div,       "Div",       op_pin_state_pinned, L|F, oparity_binary,    1, sizeof(except_attr));
-  op_Mod       = new_ir_op(iro_Mod,       "Mod",       op_pin_state_pinned, L|F, oparity_binary,    1, sizeof(except_attr));
-  op_Abs       = new_ir_op(iro_Abs,       "Abs",       op_pin_state_floats, 0,   oparity_unary,     0, 0);
-  op_And       = new_ir_op(iro_And,       "And",       op_pin_state_floats, C,   oparity_binary,    0, 0);
-  op_Or        = new_ir_op(iro_Or,        "Or",        op_pin_state_floats, C,   oparity_binary,    0, 0);
-  op_Eor       = new_ir_op(iro_Eor,       "Eor",       op_pin_state_floats, C,   oparity_binary,    0, 0);
-  op_Not       = new_ir_op(iro_Not,       "Not",       op_pin_state_floats, 0,   oparity_unary,     0, 0);
-  op_Cmp       = new_ir_op(iro_Cmp,       "Cmp",       op_pin_state_floats, L,   oparity_binary,    0, 0);
-  op_Shl       = new_ir_op(iro_Shl,       "Shl",       op_pin_state_floats, L,   oparity_binary,    0, 0);
-  op_Shr       = new_ir_op(iro_Shr,       "Shr",       op_pin_state_floats, L,   oparity_binary,    0, 0);
-  op_Shrs      = new_ir_op(iro_Shrs,      "Shrs",      op_pin_state_floats, L,   oparity_binary,    0, 0);
-  op_Rot       = new_ir_op(iro_Rot,       "Rot",       op_pin_state_floats, L,   oparity_binary,    0, 0);
-  op_Conv      = new_ir_op(iro_Conv,      "Conv",      op_pin_state_floats, 0,   oparity_unary,     0, 0);
-  op_Cast      = new_ir_op(iro_Cast,      "Cast",      op_pin_state_floats, 0,   oparity_unary,     0, sizeof(cast_attr));
-
-  op_Phi       = new_ir_op(iro_Phi,       "Phi",       op_pin_state_pinned, L,   oparity_variable, -1, sizeof(int));
-
-  op_Load      = new_ir_op(iro_Load,      "Load",      op_pin_state_pinned, L|F, oparity_any,      -1, sizeof(load_attr));
-  op_Store     = new_ir_op(iro_Store,     "Store",     op_pin_state_pinned, L|F, oparity_any,      -1, sizeof(store_attr));
-  op_Alloc     = new_ir_op(iro_Alloc,     "Alloc",     op_pin_state_pinned, L|F, oparity_any,      -1, sizeof(alloc_attr));
-  op_Free      = new_ir_op(iro_Free,      "Free",      op_pin_state_pinned, L,   oparity_any,      -1, sizeof(type *));
-  op_Sync      = new_ir_op(iro_Sync,      "Sync",      op_pin_state_pinned, 0,   oparity_any,      -1, 0);
-
-  op_Proj      = new_ir_op(iro_Proj,      "Proj",      op_pin_state_floats, 0,   oparity_any,      -1, sizeof(long));
-  op_Tuple     = new_ir_op(iro_Tuple,     "Tuple",     op_pin_state_floats, L,   oparity_variable, -1, 0);
-  op_Id        = new_ir_op(iro_Id,        "Id",        op_pin_state_floats, 0,   oparity_any,      -1, 0);
-  op_Bad       = new_ir_op(iro_Bad,       "Bad",       op_pin_state_pinned, X|F, oparity_zero,     -1, 0);
-  op_Confirm   = new_ir_op(iro_Confirm,   "Confirm",   op_pin_state_floats, L,   oparity_any,      -1, sizeof(confirm_attr));
-
-  op_Unknown   = new_ir_op(iro_Unknown,   "Unknown",   op_pin_state_pinned, X|F, oparity_zero,     -1, 0);
-  op_Filter    = new_ir_op(iro_Filter,    "Filter",    op_pin_state_pinned, L,   oparity_variable, -1, sizeof(filter_attr));
-  op_Break     = new_ir_op(iro_Break,     "Break",     op_pin_state_pinned, X,   oparity_zero,     -1, 0);
-  op_CallBegin = new_ir_op(iro_CallBegin, "CallBegin", op_pin_state_pinned, X|I, oparity_any,      -1, sizeof(callbegin_attr));
-  op_EndReg    = new_ir_op(iro_EndReg,    "EndReg",    op_pin_state_pinned, X|I, oparity_any,      -1, sizeof(end_attr));
-  op_EndExcept = new_ir_op(iro_EndExcept, "EndExcept", op_pin_state_pinned, X|I, oparity_any,      -1, sizeof(end_attr));
-
-  op_FuncCall  = new_ir_op(iro_FuncCall,  "FuncCall",  op_pin_state_floats, L,   oparity_any,      -1, sizeof(call_attr));
-
+#define Y   irop_flag_forking
+
+  op_Block     = new_ir_op(iro_Block,     "Block",     op_pin_state_pinned, L,     oparity_variable, -1, sizeof(block_attr));
+
+  op_Start     = new_ir_op(iro_Start,     "Start",     op_pin_state_pinned, X,     oparity_zero,     -1, sizeof(start_attr));
+  op_End       = new_ir_op(iro_End,       "End",       op_pin_state_pinned, X,     oparity_dynamic,  -1, 0);
+  op_Jmp       = new_ir_op(iro_Jmp,       "Jmp",       op_pin_state_pinned, X,     oparity_zero,     -1, 0);
+  op_Cond      = new_ir_op(iro_Cond,      "Cond",      op_pin_state_pinned, L|X|Y, oparity_any,      -1, sizeof(cond_attr));
+  op_Return    = new_ir_op(iro_Return,    "Return",    op_pin_state_pinned, L|X,   oparity_zero,     -1, 0);
+  op_Raise     = new_ir_op(iro_Raise,     "Raise",     op_pin_state_pinned, L|X,   oparity_any,      -1, 0);
+
+  op_Const     = new_ir_op(iro_Const,     "Const",     op_pin_state_floats, 0,     oparity_zero,     -1, sizeof(const_attr));
+  op_SymConst  = new_ir_op(iro_SymConst,  "SymConst",  op_pin_state_floats, 0,     oparity_zero,     -1, sizeof(symconst_attr));
+
+  op_Sel       = new_ir_op(iro_Sel,       "Sel",       op_pin_state_floats, L,     oparity_any,      -1, sizeof(sel_attr));
+  op_InstOf    = new_ir_op(iro_InstOf,    "InstOf",    op_pin_state_floats, L,     oparity_any,      -1, sizeof(sel_attr));
+
+  op_Call      = new_ir_op(iro_Call,      "Call",      op_pin_state_pinned, L|F,   oparity_variable, -1, sizeof(call_attr));
+  op_Add       = new_ir_op(iro_Add,       "Add",       op_pin_state_floats, C,     oparity_binary,    0, 0);
+  op_Minus     = new_ir_op(iro_Minus,     "Minus",     op_pin_state_floats, 0,     oparity_unary,     0, 0);
+  op_Sub       = new_ir_op(iro_Sub,       "Sub",       op_pin_state_floats, L,     oparity_binary,    0, 0);
+  op_Mul       = new_ir_op(iro_Mul,       "Mul",       op_pin_state_floats, C,     oparity_binary,    0, 0);
+  op_Quot      = new_ir_op(iro_Quot,      "Quot",      op_pin_state_pinned, L|F,   oparity_binary,    1, sizeof(except_attr));
+  op_DivMod    = new_ir_op(iro_DivMod,    "DivMod",    op_pin_state_pinned, L|F,   oparity_binary,    1, sizeof(except_attr));
+  op_Div       = new_ir_op(iro_Div,       "Div",       op_pin_state_pinned, L|F,   oparity_binary,    1, sizeof(except_attr));
+  op_Mod       = new_ir_op(iro_Mod,       "Mod",       op_pin_state_pinned, L|F,   oparity_binary,    1, sizeof(except_attr));
+  op_Abs       = new_ir_op(iro_Abs,       "Abs",       op_pin_state_floats, 0,     oparity_unary,     0, 0);
+  op_And       = new_ir_op(iro_And,       "And",       op_pin_state_floats, C,     oparity_binary,    0, 0);
+  op_Or        = new_ir_op(iro_Or,        "Or",        op_pin_state_floats, C,     oparity_binary,    0, 0);
+  op_Eor       = new_ir_op(iro_Eor,       "Eor",       op_pin_state_floats, C,     oparity_binary,    0, 0);
+  op_Not       = new_ir_op(iro_Not,       "Not",       op_pin_state_floats, 0,     oparity_unary,     0, 0);
+  op_Cmp       = new_ir_op(iro_Cmp,       "Cmp",       op_pin_state_floats, L,     oparity_binary,    0, 0);
+  op_Shl       = new_ir_op(iro_Shl,       "Shl",       op_pin_state_floats, L,     oparity_binary,    0, 0);
+  op_Shr       = new_ir_op(iro_Shr,       "Shr",       op_pin_state_floats, L,     oparity_binary,    0, 0);
+  op_Shrs      = new_ir_op(iro_Shrs,      "Shrs",      op_pin_state_floats, L,     oparity_binary,    0, 0);
+  op_Rot       = new_ir_op(iro_Rot,       "Rot",       op_pin_state_floats, L,     oparity_binary,    0, 0);
+  op_Conv      = new_ir_op(iro_Conv,      "Conv",      op_pin_state_floats, 0,     oparity_unary,     0, 0);
+  op_Cast      = new_ir_op(iro_Cast,      "Cast",      op_pin_state_floats, 0,     oparity_unary,     0, sizeof(cast_attr));
+
+  op_Phi       = new_ir_op(iro_Phi,       "Phi",       op_pin_state_pinned, L,     oparity_variable, -1, sizeof(int));
+
+  op_Load      = new_ir_op(iro_Load,      "Load",      op_pin_state_pinned, L|F,   oparity_any,      -1, sizeof(load_attr));
+  op_Store     = new_ir_op(iro_Store,     "Store",     op_pin_state_pinned, L|F,   oparity_any,      -1, sizeof(store_attr));
+  op_Alloc     = new_ir_op(iro_Alloc,     "Alloc",     op_pin_state_pinned, L|F,   oparity_any,      -1, sizeof(alloc_attr));
+  op_Free      = new_ir_op(iro_Free,      "Free",      op_pin_state_pinned, L,     oparity_any,      -1, sizeof(type *));
+  op_Sync      = new_ir_op(iro_Sync,      "Sync",      op_pin_state_pinned, 0,     oparity_any,      -1, 0);
+
+  op_Proj      = new_ir_op(iro_Proj,      "Proj",      op_pin_state_floats, 0,     oparity_any,      -1, sizeof(long));
+  op_Tuple     = new_ir_op(iro_Tuple,     "Tuple",     op_pin_state_floats, L,     oparity_variable, -1, 0);
+  op_Id        = new_ir_op(iro_Id,        "Id",        op_pin_state_floats, 0,     oparity_any,      -1, 0);
+  op_Bad       = new_ir_op(iro_Bad,       "Bad",       op_pin_state_pinned, X|F,   oparity_zero,     -1, 0);
+  op_Confirm   = new_ir_op(iro_Confirm,   "Confirm",   op_pin_state_floats, L,     oparity_any,      -1, sizeof(confirm_attr));
+
+  op_Unknown   = new_ir_op(iro_Unknown,   "Unknown",   op_pin_state_pinned, X|F,   oparity_zero,     -1, 0);
+  op_Filter    = new_ir_op(iro_Filter,    "Filter",    op_pin_state_pinned, L,     oparity_variable, -1, sizeof(filter_attr));
+  op_Break     = new_ir_op(iro_Break,     "Break",     op_pin_state_pinned, X,     oparity_zero,     -1, 0);
+  op_CallBegin = new_ir_op(iro_CallBegin, "CallBegin", op_pin_state_pinned, X|I,   oparity_any,      -1, sizeof(callbegin_attr));
+  op_EndReg    = new_ir_op(iro_EndReg,    "EndReg",    op_pin_state_pinned, X|I,   oparity_any,      -1, sizeof(end_attr));
+  op_EndExcept = new_ir_op(iro_EndExcept, "EndExcept", op_pin_state_pinned, X|I,   oparity_any,      -1, sizeof(end_attr));
+
+  op_FuncCall  = new_ir_op(iro_FuncCall,  "FuncCall",  op_pin_state_floats, L,     oparity_any,      -1, sizeof(call_attr));
+
+#undef Y
 #undef F
 #undef I
 #undef X
@@ -254,16 +256,16 @@ const char *get_op_name (const ir_op *op) {
   return get_id_str(op->name);
 }
 
-opcode get_op_code (const ir_op *op){
-  return op->code;
+opcode (get_op_code)(const ir_op *op){
+  return __get_op_code(op);
 }
 
-ident *get_op_ident(ir_op *op){
-  return op->name;
+ident *(get_op_ident)(ir_op *op){
+  return __get_op_ident(op);
 }
 
-op_pin_state get_op_pinned (const ir_op *op){
-  return op->op_pin_state_pinned;
+op_pin_state (get_op_pinned)(const ir_op *op){
+  return __get_op_pinned(op);
 }
 
 /* Sets op_pin_state_pinned in the opcode.  Setting it to floating has no effect
index 2dedc1d..b5e5c70 100644 (file)
@@ -41,6 +41,7 @@ typedef enum {
   irop_flag_ip_cfopcode = 0x00000008,  /**< operation manipulates interprocedural control flow */
   irop_flag_fragile     = 0x00000010,  /**< set if the operation can change the control flow because
                                              of an exception */
+  irop_flag_forking     = 0x00000020,   /**< the operation is a forking control flow */
 } irop_flags;
 
 
@@ -150,4 +151,27 @@ static INLINE int is_op_fragile(const ir_op *op) {
   return op->flags & irop_flag_fragile;
 }
 
+/* Returns non-zero if operation is forking control flow */
+static INLINE int is_op_forking(const ir_op *op) {
+  return op->flags & irop_flag_forking;
+}
+
+static INLINE opcode __get_op_code(const ir_op *op) {
+  return op->code;
+}
+
+static INLINE ident *__get_op_ident(ir_op *op){
+  return op->name;
+}
+
+static INLINE op_pin_state __get_op_pinned(const ir_op *op) {
+  return op->op_pin_state_pinned;
+}
+
+
+#define get_op_code(op)         __get_op_code(op)
+#define get_op_ident(op)        __get_op_ident(op)
+#define get_op_pinned(op)       __get_op_pinned(op)
+
+
 #endif /* _IROP_T_H_ */
index 0218ecc..a516ec5 100644 (file)
@@ -92,9 +92,15 @@ static tarval *computed_value_Sub(ir_node *n)
 {
   ir_node *a = get_Sub_left(n);
   ir_node *b = get_Sub_right(n);
+  tarval *ta;
+  tarval *tb;
 
-  tarval *ta = value_of(a);
-  tarval *tb = value_of(b);
+  /* a - a */
+  if (a == b)
+    return get_tarval_null(get_irn_mode(n));
+
+  ta = value_of(a);
+  tb = value_of(b);
 
   if ((ta != tarval_bad) && (tb != tarval_bad)
         && (get_irn_mode(a) == get_irn_mode(b))
@@ -186,6 +192,7 @@ static tarval *computed_value_Mod(ir_node *n)
     if (tb != get_mode_null(get_tarval_mode(tb)))   /* div by zero: return tarval_bad */
       return tarval_mod(ta, tb);
   }
+
   return tarval_bad;
 }
 
@@ -1203,37 +1210,63 @@ static ir_node *transform_node_Proj(ir_node *proj)
   ir_node *n = get_Proj_pred(proj);
   ir_node *b;
   tarval *tb;
+  long proj_nr;
 
   switch (get_irn_opcode(n)) {
   case iro_Div:
-    if (get_Proj_proj(proj) == pn_Div_X_except) {
-      b  = get_Div_right(n);
-      tb = computed_value(b);
+    b  = get_Div_right(n);
+    tb = computed_value(b);
+
+    if (tb != tarval_bad && classify_tarval(tb) != TV_CLASSIFY_NULL) { /* div(x, c) && c != 0 */
+      proj_nr = get_Proj_proj(proj);
 
-      /* we found an exception handler, see if we can remove it */
-      if (tb != tarval_bad && classify_tarval(tb) != TV_CLASSIFY_NULL) { /* div(x, c) && c != 0 */
+      if (proj_nr == pn_Div_X_except) {
+        /* we found an exception handler, remove it */
         return new_Bad();
       }
+      else if (proj_nr == pn_Div_M) {
+       /* the memory Proj can be removed */
+        ir_node *res = get_Div_mem(n);
+        set_Div_mem(n, get_irg_initial_mem(current_ir_graph));
+       return res;
+      }
     }
     break;
   case iro_Mod:
-    if (get_Proj_proj(proj) == pn_Mod_X_except) {
-      b  = get_Mod_right(n);
-      tb = computed_value(b);
+    b  = get_Mod_right(n);
+    tb = computed_value(b);
 
-      if (tb != tarval_bad && classify_tarval(tb) != TV_CLASSIFY_NULL) { /* mod(x, c) && c != 0 */
+    if (tb != tarval_bad && classify_tarval(tb) != TV_CLASSIFY_NULL) { /* mod(x, c) && c != 0 */
+      proj_nr = get_Proj_proj(proj);
+
+      if (proj_nr == pn_Mod_X_except) {
+        /* we found an exception handler, remove it */
         return new_Bad();
       }
+      else if (proj_nr == pn_Mod_M) {
+       /* the memory Proj can be removed */
+        ir_node *res = get_Mod_mem(n);
+        set_Mod_mem(n, get_irg_initial_mem(current_ir_graph));
+       return res;
+      }
     }
     break;
   case iro_DivMod:
-    if (get_Proj_proj(proj) == pn_DivMod_X_except) {
-      b  = get_DivMod_right(n);
-      tb = computed_value(b);
+    b  = get_DivMod_right(n);
+    tb = computed_value(b);
+
+    if (tb != tarval_bad && classify_tarval(tb) != TV_CLASSIFY_NULL) { /* DivMod(x, c) && c != 0 */
+      proj_nr = get_Proj_proj(proj);
 
-      if (tb != tarval_bad && classify_tarval(tb) != TV_CLASSIFY_NULL) { /* DivMod(x, c) && c != 0 */
+      if (proj_nr == pn_DivMod_X_except) {
         return new_Bad();
       }
+      else if (proj_nr == pn_DivMod_M) {
+       /* the memory Proj can be removed */
+        ir_node *res = get_DivMod_mem(n);
+        set_DivMod_mem(n, get_irg_initial_mem(current_ir_graph));
+       return res;
+      }
     }
     break;
 
@@ -1260,7 +1293,7 @@ static ir_node *transform_node_Proj(ir_node *proj)
     return proj;
 
   case iro_Tuple:
-    /* should not happen, but if it does will optimize */
+    /* should not happen, but if it does will be optimized away */
     break;
 
   default: